【问题标题】:Tropo C# JSON Example?Tropo C# JSON 示例?
【发布时间】:2013-09-13 03:31:58
【问题描述】:

我正在尝试在我的 MVC4 应用程序中实现 Tropo。我有一个简单的网关,它创建一个对号码的呼叫并说出一条消息。我似乎无法让它工作,所发生的只是 Tropo 拨打号码并在对方接听时挂断。

这是我的网关代码:

public void SendAppointmentNotification()
        {
            var httpWReq =
                (HttpWebRequest)WebRequest.Create("https://api.tropo.com/v1/sessions");

            var encoding = new ASCIIEncoding();
            var postDataTemplate = "<session>" +
                                   "<token>{0}</token>" +
                                   "<var name=\"numberToDial\" value=\"{1}\"></var>" +
                                   "<var name=\"msg\" value=\"{2}\"></var>" +
                                   "</session>";

            var tokenToUse = [APIKEY]-Removed;
            var numberToDial = "XXXXXXXXXX";
            var message = "Greetings. This is a reminder that you have a service call appointment scheduled.";

            var postData = string.Format(postDataTemplate, tokenToUse, numberToDial, message);

            var data = encoding.GetBytes(postData);

            httpWReq.Method = "POST";
            httpWReq.Accept = "text/xml";
            httpWReq.ContentType = "text/xml";
            httpWReq.ContentLength = data.Length;

            var newStream = httpWReq.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            var response = (HttpWebResponse) httpWReq.GetResponse();
            byte[] buffer = new byte[response.ContentLength];
            using (var stream = response.GetResponseStream())
            {
                stream.Read(buffer, 0, (int) response.ContentLength);
            }
            var bufferAsString = buffer.Aggregate("", (current, t) => current + (char) t);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Did not get status OK 200 from POST");
            }
            newStream.Close();
        }

Tropo 的网站似乎对除 C# 之外的所有语言都表现出极大的喜爱,而且他们拥有的 Github 存储库相当陈旧且缺乏文档。

我只是想打电话给一个人并说一个消息...有没有人走这条路,可以给我一些他们实施的例子吗?

【问题讨论】:

    标签: c# json asp.net-mvc-4 tropo


    【解决方案1】:

    此问题并未具体说明您在尝试运行此应用程序时遇到的问题类型。但要检查的一件事是,您已被授予拨打外线电话的权利。除非情况发生变化,否则您必须向 Tropo 支持请求此功能。

    在 MVC 4 上运行以开发 Tropo 应用程序的良好 C# 框架是 VoiceModel。它在 Apache 许可下是开源的,简化了语音应用程序的开发。您开发您的应用程序一次,它将在 Tropo 和任何 VoiceXML 兼容系统上运行。这是article on using VoiceModel to create outbound applications

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 2011-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多