我到底如何通過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