简体   繁体   English

Tropo C#JSON示例?

[英]Tropo C# JSON Example?

I am trying to implement Tropo into my MVC4 application. 我正在尝试在我的MVC4应用程序中实现Tropo。 I have a simple Gateway that creates a call to a number and says a message. 我有一个简单的网关,可以拨打电话并说一条消息。 I can't seem to get it working, all that happens is Tropo dials the number and hangs up when the person answers. 我似乎无法正常工作,所有发生的事情是Tropo拨打电话并在对方接听时挂断电话。

Here is my Gateway code: 这是我的网关代码:

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's site seems to show much love to all languages other than C# and the Github repository they have is quite old and lacks documentation. Tropo的站点似乎对除C#和它们所拥有的Github存储库之外的所有其他语言都表现出极大的热爱,并且缺少文档。

I just want to call a person and say a message... has anyone been down this road and can offer me some example of their implementation? 我只想打个电话说一个消息……这条路上有人吗,可以为我提供一些实施示例吗?

This question is not specific on what types of issues you are hitting when trying to run this application. 对于尝试运行此应用程序时遇到的问题类型,此问题并不特定。 But one thing to check is that you have been given the rights to make outbound calls. 但是要检查的一件事是,您已获得拨出电话的权利。 Unless things have changed, you have to request this functionality from Tropo support. 除非情况有所变化,否则您必须向Tropo支持部门请求此功能。

A good C# framework that runs on MVC 4 for developing Tropo applications is VoiceModel . VoiceModel是在MVC 4上运行的用于开发Tropo应用程序的良好C#框架。 It is open source under the Apache license and simplifies voice application development. 它是Apache许可下的开源软件,可简化语音应用程序的开发。 You develop your application once and it will run on Tropo and any VoiceXML compatible system. 您只需开发应用程序一次,它将在Tropo和任何与VoiceXML兼容的系统上运行。 Here is an article on using VoiceModel to create outbound applications . 这是有关使用VoiceModel创建出站应用程序文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM