gpt4 book ai didi

javascript - Twilio 将代理连接到队列中的调用

转载 作者:行者123 更新时间:2023-11-29 23:18:45 25 4
gpt4 key购买 nike

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

运行我的应用程序时,我会通过 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 到达该端点,传入客户端“我”的名称。

这是 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 函数。

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

感谢任何帮助!

编辑:

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

所以,我已经为此配置了我这边的服务,所以这是更新的 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 传递什么,在此处:

    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“Connect Agent to Call”按钮不应该调用我自己的端点进行连接。这是它更改为:

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

然后,通过我的“调用” Controller 将调用路由回来,我必须在其中添加以下逻辑:

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

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

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

关于javascript - Twilio 将代理连接到队列中的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51565109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com