【问题标题】:Twilio connecting an agent to a call in a queueTwilio 将代理连接到队列中的呼叫
【发布时间】:2018-07-27 20:27:45
【问题描述】:

我有 Twilio 的试用版(只允许使用 1 个电话号码)。

在运行我的应用程序时,我通过 Twilio 进行了身份验证。

然后,我使用我的个人电话拨打我的 Twilio 号码,我的 Twilio 号码会自动添加到我的“支持”队列中。效果很好,可以听到保持音乐。

现在,在我的应用程序中,我想连接到队列中的呼叫。我在队列列表框上方创建了一个按钮,上面写着“连接到呼叫者”。单击时,它会执行此javascript:

document.getElementById('connect-to-queue-caller').onclick = function () {
    $.getJSON('/queue/connectagenttocall')
        .done(function (response) {
            log('Successfully connected to the first caller in the queue');
            log(response);
            log(JSON.stringify(response));
        })
        .fail(function (error) {
            log('Failed to connect to the first caller in the queue.');
            log(JSON.stringify(error));
        });
}

这会调用我网站上的一个端点,这里是:

public class QueueController : Controller
{
    public ActionResult ConnectAgentToCall()
    {
        var dial = new Dial();
        dial.Queue("Support");

        var response = new VoiceResponse();
        response.Say("You are being connected to the next caller in line.");
        response.Append(dial);

        var redirect = new Redirect(new Uri("http://localhost:54032/call?to=me"));
        response.Append(redirect);

        return Json(
            response,
            JsonRequestBehavior.AllowGet
        );
    }
}

我认为拥有重定向 url 会告诉 Twilio 到达该端点,并传入客户端“me”的名称。

这是 CallController:

public class CallController : Controller
{
    [HttpPost]
    public ActionResult Index(string to, string from)
    {
        var callerId = from;
        var response = new VoiceResponse();

        if (!string.IsNullOrEmpty(to))
        {
            var dial = new Dial(callerId: callerId);

            // wrap the phone number or client name in the appropriate TwiML verb
            // by checking if the number given has only digits and format symbols
            if (to.Contains("5551231234"))
            {
                //dial.Client("me");
                response.Say("You are being transferred to the support queue");
                response.Enqueue("Support");
            }
            else if (Regex.IsMatch(to, "^[\\d\\+\\-\\(\\) ]+$"))
            {
                dial.Number(to);
            }
            else
            {
                dial.Client(to);
            }

            response.Append(dial);
        }
        else
        {
            response.Say("Thanks for your call.");
        }

        return new TwiMLResult(response);
    }
}

但是,当所有这些都被执行时,它永远不会到达 /call/index 端点,该端点会将来自 Twilio 的调用连接到我(并且随后永远不会到达 javascript 中的 Twilio.Device.incoming 函数。

我已经能够成功地拨出电话和拨入电话。现在我只想把电话从我的队列中拉出来......

感谢任何帮助!

编辑:

好的,我记得在上面的过程中我忘了做一件事……实际上是对 Twilio 进行 API 调用,告诉它连接到成员。

所以,我已经为此配置了服务,所以这里是更新的Controlleraction

    [HttpGet]
    [Route("/queue/{queueSid}/dequeue/front")]
    public async Task<ActionResult> ConnectAgentToCall(string queueSid)
    {
        var frontMember = await _twilioQueueService.DequeueFirstMemberAsync(queueSid, "http://localhost:54032" + dequeueResponseXml);

        var dial = new Dial();
        dial.Queue("Support");

        var response = new VoiceResponse();
        response.Say("You are being connected to the next caller in line.");
        response.Append(dial);

        var redirect = new Redirect(new Uri("http://localhost:54032/call?to=me"));
        response.Append(redirect);

        return Json(
            response,
            JsonRequestBehavior.AllowGet
        );
    }

但是,我不知道在响应中将返回的 MemberResource 放在哪里。此外,我不确定该服务进行的 MemberResource.UpdateAsync 调用的 Uri 传递什么,这里是:

    public async Task<MemberResource> DequeueFirstMemberAsync(string queueSid, string url)
    {
        return await MemberResource.UpdateAsync(
            url: new Uri(url),
            method: Twilio.Http.HttpMethod.Post,
            pathQueueSid: queueSid,
            pathCallSid: "Front"
        );
    }

【问题讨论】:

  • 当然,在我打开赏金之后,我终于让它工作了......

标签: javascript c# twilio


【解决方案1】:

所以,经过更多研究,我现在可以使用它了。由于我已经开始赏金,我将更新对我有用的答案...

我的javascript“连接代理以呼叫”按钮不应该呼叫我自己的端点进行连接。下面是它的变化:

Twilio.Device.connect({ To: 'Support', From: 'Agent' });

然后,通过我的“呼叫”控制器将呼叫路由回,我必须在其中添加以下逻辑:

else if (to == "Support" && from == "Agent")
                {
                    response.Say("Connecting you to the first caller");
                    var queueDial = new Dial().Queue("Support");
                    response.Append(queueDial);
                }

这立即将我连接到支持队列中的个人手机。

顺便说一句,为了让按钮调用客户端支持,我必须将我的“Twiml 应用”名称保存到支持。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多