C# C语言中Twilio排队的语法#
我使用的是Twilio可编程语音,我的目标是让来电者在等待代理接听电话时收听暂停音乐 我相信排队方法是一种可行的方法,因为我们在数据库中管理代理,它们可能会发生变化(因此任务工作者并不适合)。我很清楚如何让呼叫者排队(见下文)。但是,我需要拨出一个外部号码,让电话上的代理将电话从队列中取出,我找不到如何实现这一点的C#语法 我的计划是让每个调用方都位于自己唯一标识的队列中。但如果这让事情变得更难的话,我想我愿意把呼叫者放在同一个队列中C# C语言中Twilio排队的语法#,c#,twilio,C#,Twilio,我使用的是Twilio可编程语音,我的目标是让来电者在等待代理接听电话时收听暂停音乐 我相信排队方法是一种可行的方法,因为我们在数据库中管理代理,它们可能会发生变化(因此任务工作者并不适合)。我很清楚如何让呼叫者排队(见下文)。但是,我需要拨出一个外部号码,让电话上的代理将电话从队列中取出,我找不到如何实现这一点的C#语法 我的计划是让每个调用方都位于自己唯一标识的队列中。但如果这让事情变得更难的话,我想我愿意把呼叫者放在同一个队列中 public ActionResult Index()
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);
}
我想你已经知道,根据你上面的片段,如果你的代理正在连接呼叫,那会容易得多
// 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);
}
}
如果在调用代理时需要播放等待音乐,可以使用TwiML和restapi的组合。请参见下面的示例和
1) main.cs-您需要将此文件的URL分配给您的Twilio电话号码。此功能将使传入呼叫排队,然后通过RESTAPI启动一个新的呼叫分支,以调用您的代理,并将两个呼叫分支加入到一个对话中
// 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"})
}
}
<Response>
<Say>You will be connected to an incoming call</Say>
<Dial><Queue>YOUR_QUEUE_ID</Queue></Dial>
2) contactAgent.cs-此文件包含当接听来电时将在代理的手机上执行的等效TwiML。然后,它将两个呼叫分支连接到一个对话中
// 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"})
}
}
<Response>
<Say>You will be connected to an incoming call</Say>
<Dial><Queue>YOUR_QUEUE_ID</Queue></Dial>
请务必让我知道这是否有帮助。我为问题添加了更新。你对这次大扫除有什么想法吗?