我正在使用 WebAPI 构建一个 Twilio IVR 并遇到了一些障碍。我正在尝试循环播放录音,并在每个录音结束时提供按 1 删除录音的选项。
我在 C# WebAPI 实现中的任何地方都找不到任何示例,并且以下内容不起作用,我不知道该怎么做。
我知道的;
- 需要收集输入的数字
- 不知何故将录音 sid 传回给 api 以知道要删除哪个录音。
这是我到目前为止编写的代码:
public HttpResponseMessage Messages() {
string baseUrl = Url.Request.RequestUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
var twilio = new TwilioRestClient(_accountSid, _authToken);
var recordings = twilio.ListRecordings(null, DateTime.Today, null, null);
var twilioResponse = new TwilioResponse();
if (recordings != null && recordings.Recordings.Count > 0)
{
var msgCount = 1;
var msgTotal = recordings.Recordings.Count();
foreach (var recording in recordings.Recordings)
{
var caller = twilio.GetCall(recording.CallSid);
var callerNumber = Regex.Replace(caller.From, @"([0-9]{1})", "$1,");
var callDate = recording.DateCreated.ToString("dddd MMMM d");
var callTime = recording.DateCreated.ToString("h m t");
twilioResponse.Say(string.Format("Playing message {0} of {1}, from {2} on {3} at {4} M.", msgCount, msgTotal, callerNumber, callDate, callTime),
new { voice = "woman" });
var voiceFile = string.Format("{0}2010-04-01/Accounts/{1}/Recordings/{2}.mp3", twilio.BaseUrl, _accountSid, recording.Sid);
twilioResponse.Play(voiceFile);
//twilioResponse.BeginGather(new
// {
// action = baseUrl + "/api/Recording/Delete",
// numDigits = 1,
// });
//twilioResponse.Say("TO DELETE THIS MESSAGE PRESS 1");
//twilioResponse.EndGather();
msgCount++;
}
}
return Request.CreateResponse(HttpStatusCode.OK, twilioResponse.Element, Configuration.Formatters.XmlFormatter);
}
我以前使用过 Twilio 的 API,但这对我来说是一个新的,我真的不知道这是否可能。他们拥有的 PHP 示例正在这样做,所以也许我只是错过了标记,因为我应该对此采取不同的方式。