Twilio 将座席连接到队列中的呼叫 [英] Twilio connecting an agent to a call in a queue

查看:20
本文介绍了Twilio 将座席连接到队列中的呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a trial version of Twilio (only 1 phone number allowed).

运行我的应用时,我通过 Twilio 进行了身份验证.

When running my app, I get authenticated with Twilio.

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

Then, using my personal phone, I call my Twilio number where I have it automatically get added to my "Support" queue. Works great, can hear the hold music.

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

Now, In my app, I want to connect to the call in the queue. I created a button above my queue listbox that says "Connect To Caller". When clicked, it executes this 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));
        });
}

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

That calls an endpoint on my site, which is here:

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 到达该端点,并传入客户端的名称我".

I thought that having the redirect url would tell Twilio to hit that endpoint, passing in the name of the client "me".

这是 CallController:

Here's that 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);
    }
}

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

But, when all of this is executed, it never hits the /call/index endpoint that would connect the call from Twilio, to me (and subsequently never hits the Twilio.Device.incoming function in the javascript.

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

I've been able to successfully do outgoing calls, as well as incoming. Now I just want to pull calls off my queue...

感谢任何帮助!

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

Ok, one thing I remembered that I forgot to do in the process above...actually make an API call to Twilio to tell it to connect to the member.

所以,我已经为此配置了服务,所以这是更新的Controller action:

So, I already had the service on my side configured for this, so here's the updated Controller action:

    [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 传递什么,这里是:

But, I don't know where to put this MemberResource that is returned, in the response. Also, I'm not sure what to pass for the Uri for the MemberResource.UpdateAsync call that the service makes, which is here:

    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"
        );
    }

推荐答案

所以,经过更多的研究,我现在有了这个工作.由于我已经开始赏金,我将更新对我有用的答案...

So, after some more research, I have this working now. Since I already started a bounty, I'll update with the answer that worked for me...

我的javascript连接代理呼叫"按钮不应该呼叫我自己的端点进行连接.这是它更改为:

My javascript "Connect Agent to Call" button should NOT have been calling my own endpoint to connect. Here's what it changed to:

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

然后,通过我的Call"控制器路由回调用,我必须在其中添加以下逻辑:

Then, that routes the call back through my "Call" controller, where I had to add this logic:

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

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

That immediately connected me to my personal cell phone that was in the support queue.

顺便说一下,为了让按钮调用客户端支持,我必须将我的Twiml App"名称保存到支持.

By the way, in order to have the button call the client Support, I had to save my "Twiml App" name to Support.

这篇关于Twilio 将座席连接到队列中的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆