我到底如何通过Twilio使用增强型AMD?我知道它只能通过REST API(没有TwiML)完成,但我很难看到标准呼叫和应答机检测之间的连接。我看过this page几次,但我还是不明白。所以在这里是通过REST API发出呼叫的标准的C#代码:Twilio增强型应答机检测c#
TwilioClient.Init(AccountSid, AuthToken);
var to = new PhoneNumber("+14155551212");
var from = new PhoneNumber("+15017250604");
var call = CallResource.Create(to, from, url: new Uri("http://demo.twilio.com/docs/voice.xml"));
,这里是我的C#从上述链接转换代码:
using (var client = new HttpClient())
{
var byteArray = Encoding.ASCII.GetBytes([email protected]"{AccountSid}:{AuthToken}");
var header = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
client.DefaultRequestHeaders.Authorization = header;
var requestContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("To", "+15017250604"),
new KeyValuePair<string, string>("From", "+15017250604"),
new KeyValuePair<string, string>("MachineDetection", "DetectMessageEnd"),
new KeyValuePair<string, string>("Url", Url.Action("PostTransfer"))
});
var response = client.PostAsync(_amdRequest, requestContent);
var responseContent = response.Result.Content;
}
所以我缺少什么?我相信这很简单,但我没有看到增强型AMD知道如何呼叫,以及这里的事件顺序应该是什么。最后,我该如何看待结果?
编辑:
所以要一清二楚,这里是我的代码,因为它目前是:
TwilioClient.Init(AccountSid, AuthToken);
var toPhone = new PhoneNumber(to);
var fromPhone = new PhoneNumber(from);
var call = CallResource.Create(toPhone, fromPhone, url: new Uri("http://demo.twilio.com/docs/voice.xml"));
using (var client = new HttpClient())
{
var byteArray = Encoding.ASCII.GetBytes([email protected]"{AccountSid}:{AuthToken}");
var header = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
client.DefaultRequestHeaders.Authorization = header;
var requestContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("To", to),
new KeyValuePair<string, string>("From", from),
new KeyValuePair<string, string>("MachineDetection", "DetectMessageEnd"),
new KeyValuePair<string, string>("Url", Url.Action("PostTransfer"))
});
var response = client.PostAsync(_amdRequest, requestContent);
var responseContent = response.Result.Content;
}
在我的代码的其他地方是一个叫做“PostTransfer”功能,获得了“作答”参数并在通话结束后执行一些操作。这应该工作吗?因为它不是。通话过程中,我可以听到Twilio的示例文件播放,但它永远不会进入“PostTransfer”功能。
我编辑了一些原始问题。我无法知道应答机检测是否出现问题,因为它从未到达我提供的网址末尾的功能。 – bkmo
啊,我相信,从检查[文档](https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.action(v = vs.118).aspx),那'URL.Action'返回一个路径,Twilio需要一个完整的URL和域名等。 – philnash
这样做。我以前只能获得部分网址。 – bkmo