我正在使用Twilio可编程语音,我的目标是让主叫方在等待座席接听电话时收听待机音乐。
我相信Enqueue方法是可行的方法,因为我们在数据库中管理我们的代理并且它们可能会发生变化(因此Task Worker不适合)。我清楚知道如何将呼叫者放入队列(见下文)。但是,我需要拨打一个外部电话号码,让电话中的代理人将该呼叫从队列中取出,我无法找到关于如何实现这一目标的C#语法。
我的计划是让每个调用者都在他们自己唯一标识的队列中。但是,如果这让我更加困难,那么我打算将呼叫者放入同一个队列中。
public ActionResult Index()
{
var response = new TwilioResponse();
response.Enqueue("Queue 23123412414124", new
{
action = Url.Action("LeaveQueue"), //url to call when the call is dequeued
waitUrl = Url.Action("WaitInQueue") //url to call while the call waits
});
return TwiML(response);
}
谢谢!
[更新1] 这是我在一个TestController中使用ngrok在本地进行测试的内容。我不知道我是否得到一个干净的挂断,但它确实有效!
public ActionResult Index()
{
var response = new TwilioResponse();
var Twil = new TwilioRestClient("TWILIO_SID", "TWILIO_PWD");
Twil.InitiateOutboundCall(new CallOptions
{
To = "+17205551212",
From = "+17205551212",
Url = "http://701cfc2f.ngrok.io/Test/ContactAgent"
});
response.Enqueue("Demo Queue", new
{
action = Url.Action("LeaveQueue"), //url to call when the call is dequeued
waitUrl = Url.Action("WaitInQueue") //url to call while the call waits
});
return TwiML(response);
}
public ActionResult ContactAgent()
{
var response = new TwilioResponse();
Twilio.TwiML.Queue q = new Twilio.TwiML.Queue("Demo Queue");
response.Dial(q);
return TwiML(response);
}
public ActionResult WaitInQueue(string CurrentQueueSize, string QueuePosition)
{
var response = new TwilioResponse();
response.Say(string.Format("You are number {0} in the queue. Please hold.", QueuePosition));
response.Say("Play Background Music Here with Play Verb and loop it!");
return TwiML(response);
}
public ActionResult LeaveQueue(string QueueSid)
{
var response = new TwilioResponse();
var Twil = new TwilioRestClient("TWILIO_SID", "TWILIO_PWD");
Twil.HangupCall(QueueSid, HangupStyle.Completed);
return TwiML(response);
}
答案 0 :(得分:1)
我怀疑您已经根据上面的代码段了解到,如果您的座席连接到呼叫,这将会容易得多。
https://www.twilio.com/docs/api/twiml/guides/queues#agent
如果您在呼叫代理时需要播放等待音乐,则可以结合使用TwiML和REST API。请参阅以下示例和refer to syntax here。
1)main.cs - 您需要将此文件的URL分配给您的Twilio电话号码。此功能会将来电排队,然后通过Rest API启动新的呼叫支路,以呼叫您的座席,并将两个呼叫支路加入一个对话中。
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string AuthToken = "your_auth_token";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var options = new CallOptions();
options.Url = "http://URL/contactAgent.cs?queueid=NAME_YOUR_QUEUE";
options.To = "+1415XXXXXXX"; // Agent phone
options.From = "+1415XXXXXXX";// Twilio phone
var call = twilio.InitiateOutboundCall(options);
var response = new TwilioResponse();
response.Enqueue("Queue 23123412414124", new { action="http://URL/terminate_childcall.php?childsid=YOUR_CALL_SID_IN_QUEUE_ID", waitURL="wait.xml"})
}
}
2)contactAgent.cs - 此文件包含等效的TwiML,当接听来电时,将在您的代理电话上执行。然后它会将两个呼叫支路连接成一个对话。
<Response>
<Say>You will be connected to an incoming call</Say>
<Dial><Queue>YOUR_QUEUE_ID</Queue></Dial>
3)terminate_childcall.cs - 由于通过Rest API发起的呼叫支路是完全独立的呼叫支路,我们需要在发起呼入呼叫的客户将是终止呼叫的第一个呼叫支路时终止它。
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
string AuthToken = "your_auth_token";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
twilio.HangupCall("CALL_SID", HangupStyle.Completed);
}
}
如果有帮助,请告诉我。