【问题标题】:Twilio Gather/Play Recordings in loopTwilio 循环收集/播放录音
【发布时间】:2014-05-15 18:02:24
【问题描述】:

我正在使用 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,但对我来说这是一个新的 API,我真的不知道这是否可行。他们拥有的 PHP 示例正在这样做,所以也许我只是错过了标记,因为我应该对此采取不同的方式。

【问题讨论】:

    标签: c# asp.net-web-api twilio twilio-twiml


    【解决方案1】:

    Twilio 布道者在这里。

    您所拥有的看起来非常接近。让我们看看在用户按下一个的情况下传回 Recording SID,因为通过使用您在 Gather 动词上设置的操作 URL 来为您保存一些状态相对容易:

    action = baseUrl + "/api/Recording/Delete?recordingSid=" + recording.Sid;
    

    现在,当用户按下一个时,Twilio 将向包含recordingSid 参数的Action URL 发出请求。

    删除录音后,您只需重定向回您的消息端点以继续收听更多录音。为了跟踪您已经听过哪些录音,您可能需要在操作 URL 中传递一些额外的参数,这些参数可以通过您的删除工作流程并返回到收听工作流程。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多