我有 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 函数)。
我已经能够成功地拨打和接听电话。现在我只想把电话从我的队列中删除......
任何帮助表示赞赏!
EDIT:
好的,我记得在上面的过程中忘记做的一件事...实际上对 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"
);
}