我有 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
“连接代理进行调用”按钮不应该调用我自己的端点进行连接。以下是更改后的内容:
Twilio.Device.connect({ To: 'Support', From: 'Agent' });
然后,通过我的“Call” 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/