public virtual string Tropo(Result result) { _log.Debug("Recieved Tropo request: ", result); string vEvent; string vData; string vErrMsg; TropoUtilities.TropoResultToEventAndData(result, out vEvent, out vData, out vErrMsg); CallFlow.ICallFlow callFlow = GetCallFlow(result.sessionId); callFlow.FireEvent(vEvent, vData); VoiceModel doc = callFlow.CurrState.DataModel; if (isJson(callFlow.CurrState.jsonArgs)) { doc.json = callFlow.CurrState.jsonArgs; } if (doc.ViewName == "Call") { doc.nextUri = doc.nextUri + "/Tropo"; } else { doc.nextUri = TropoUri; } SetCallFlow(callFlow, result.sessionId); string recordingUri = TropoRecordingUri + "?vm_session_id=" + result.sessionId; string json = TropoUtilities.ConvertVoiceModelToWebApi(doc, recordingUri); _log.Debug("Sending Tropo response:[" + json + "]"); return(json); }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo class. Tropo tropo = new Tropo(); // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); string smsReceived = tropoSession.InitialText; // yu can do your business logic with smsReceived.... //.... //.... // Create an XML doc to hold the response from the Tropo Session API. XmlDocument doc = new XmlDocument(); string token = "6c48697670656858594b62704c62715358444e5a72744a794156715872656a66627a72464b7158626d58374"; // the app's voice token (app's url is SMSBusineessLogic.aspx) // A collection to hold the parameters we want to send to the Tropo Session API. IDictionary <string, string> parameters = new Dictionary <String, String>(); parameters.Add("numberToDial", "+8613466549249"); parameters.Add("textMessageBody", smsReceived); // Inintialized another application, here I just say the smsReceived to numberToDial doc.Load(tropo.CreateSession(token, parameters)); } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string resultJSON = TropoUtilities.parseJSON(reader); Console.WriteLine("resultJSONis:" + resultJSON); HttpContext.Current.Trace.Warn(DateTime.Now.ToString() + " I Made It HerresultJSONis" + resultJSON); // Create a new instance of the Tropo class. Tropo tropo = new Tropo(); try { // Create a new Result object and pass in the JSON submitted from Tropo. Result tropoResult = Result.getResult(resultJSON); // Get Actions container and parse. List <TropoCSharp.Tropo.Action> Actions = tropoResult.Actions; tropo.Say("session id is beijing " + tropoResult.SessionId); foreach (TropoCSharp.Tropo.Action item in Actions) { tropo.Say("action Name is: " + item.Name); tropo.Say("attempts is " + item.Attempts); tropo.Say("disposition is " + item.Disposition); tropo.Say("ConnectedDuration is " + item.ConnectedDuration); tropo.Say("Duration is " + item.Duration); tropo.Say("confidence is " + item.Confidence); tropo.Say("interpretation is " + item.Interpretation); tropo.Say("utterance is " + item.Utterance); tropo.Say("value is " + item.Value); tropo.Say("concept is: " + item.Concept); //tropo.Say("xml is " + item.xml); tropo.Say("uploadStatus is " + item.UploadStatus); tropo.Say("inner user type is " + item.UserType); } tropo.Say("user type is " + tropoResult.UserType); } catch (JsonReaderException) { tropo.Say("Sorry, an error occured. I choked on some JSON"); } catch (Exception ex) { tropo.Say("Sorry, an error occured. " + ex.Message); } finally { tropo.RenderJSON(Response); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo object. Tropo tropo = new Tropo(); try { // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); // Get parameters submitted with Session API call. string sendToNumber = tropoSession.Parameters.Get("sendToNumber"); string sendFromNumber = tropoSession.Parameters.Get("sendFromNumber"); string channel = tropoSession.Parameters.Get("channel"); string network = tropoSession.Parameters.Get("network"); string msg = tropoSession.Parameters.Get("msg"); // Send an outbound message. tropo.Call(sendToNumber, sendFromNumber, network, channel, true, 60, null, null); tropo.Say(msg); // Render the JSON for Tropo to consume. Response.Write(tropo.RenderJSON()); } catch (JsonReaderException ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application. Bad JSON"); } catch (Exception ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application."); } finally { Response.Write(tropo.RenderJSON()); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo object. Tropo tropo = new Tropo(); try { // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); // Get parameters submitted with Session API call. string numberToDial = tropoSession.Parameters.Get("numberToDial"); string textMessageBody = tropoSession.Parameters.Get("textMessageBody"); string sendFromNumber = "+17754641173"; string channel = "TEXT"; string network = "SMS"; // Send an outbound message. //tropo.Call(numberToDial, sendFromNumber, network, channel, true, 60, null); tropo.Call(numberToDial); tropo.Say("You will hear current time " + textMessageBody); tropo.Hangup(); } catch (JsonReaderException ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application. Bad JSON"); } catch (Exception ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application."); } finally { tropo.RenderJSON(Response); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Create a new instance of the Tropo object. Tropo tropo = new Tropo(); if (!String.IsNullOrEmpty(Request.QueryString["signal"])) { if (Request.QueryString["signal"] == "interruptConference") { tropo.Say(". Now, rejoin the conference. Press the pound key to exit without hanging up."); tropo.Conference(Request.QueryString["confid"], false, "testConference", false, true, "#"); tropo.Say("You have now left the conference."); tropo.Hangup(); } else { tropo.Say("The call is now over. Gooddbye."); tropo.Hangup(); } } else { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); // Create a signal to end the conference. string[] signals = new string[] { "interruptConference", "endCall" }; // Call an outbound number and create a conference. tropo.Call(tropoSession.Parameters["callToNumber"]); tropo.Say("Welcome to the conference."); //tropo.Conference(tropoSession.Parameters["conferenceID"], signals, false, "testConference", false, true, "#"); JoinPrompt joinPrompt = new JoinPrompt("somebody join the conference"); LeavePrompt leavePrompt = new LeavePrompt("some one leave the conference"); tropo.Conference(tropoSession.Parameters["conferenceID"], signals, 3, false, "testConference", false, true, "#", joinPrompt, leavePrompt, "none"); tropo.On("interruptConference", "Conference.aspx?signal=interruptConference&confid=" + tropoSession.Parameters["conferenceID"], new Say("You have left the conference.")); tropo.On("endCall", "Conference.aspx?signal=endCall", new Say("You have left the conference.")); } tropo.RenderJSON(Response); } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string resultJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo object. Tropo tropo = new Tropo(); try { // Create a new Result object and pass in the JSON submitted from Tropo. Result tropoResult = Result.getResult(resultJSON); // Parse the Actions object and get the value property. // Get the input submited by the user. // This value can be used to query a database, hit a web service, etc. // In the example, we'll simply read the number back to the caller. foreach (var item in tropoResult.Actions) { string answer = item.Value; tropo.Say("You entered, " + TropoUtilities.addSpaces(answer) + ". Goodbye"); } } // In the event of an error in rendering the page, play an error message to the caller. catch (JsonReaderException ex) { tropo.Say("An error occured. " + ex.Message); } catch (Exception ex) { tropo.Say("An error occured. " + ex.Message); } finally { tropo.Hangup(); tropo.RenderJSON(Response); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string resultJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo class. Tropo tropo = new Tropo(); try { // Create a new Result object and pass in the JSON submitted from Tropo. Result tropoResult = new Result(resultJSON); // Get Actions container and parse. JContainer Actions = TropoUtilities.parseActions(tropoResult.Actions); // A simple example showing how to access properties of the Result object. tropo.Say("The State of the current session is " + tropoResult.State); tropo.Say("The Sequence of this Result payload is " + tropoResult.Sequence); tropo.Say("The session ID for the current session is is " + TropoUtilities.addSpaces(tropoResult.SessionId)); tropo.Say("The value selected by the caller is " + TropoUtilities.removeQuotes(Actions["value"].ToString())); } catch (JsonReaderException) { tropo.Say("Sorry, an error occured. I choked on some JSON"); } catch (Exception ex) { tropo.Say("Sorry, an error occured. " + ex.Message); } finally { Response.Write(tropo.RenderJSON()); } } }
public virtual string StartTropo(string id, Session session) { _log.Debug("Recieved Tropo start request: ", session); string vEvent = ""; string vData = ""; CallFlow.CallFlow callFlow = BuildCallFlow(); if (string.IsNullOrEmpty(id)) { id = "unknown"; } callFlow["AppId"] = id; callFlow["ANI"] = session.from.id; callFlow["Channel"] = session.from.channel; callFlow["InitialText"] = session.initialText; callFlow.FireEvent(vEvent, vData); VoiceModel doc = callFlow.CurrState.DataModel; if (isJson(callFlow.CurrState.jsonArgs)) { doc.json = callFlow.CurrState.jsonArgs; } if (doc.ViewName == "Call") { doc.nextUri = doc.nextUri + "/Tropo"; } else { doc.nextUri = TropoUri; } SetCallFlow(callFlow, session.id); string recordingUri = TropoRecordingUri + "?vm_session_id=" + session.id; string json = TropoUtilities.ConvertVoiceModelToWebApi(doc, recordingUri); _log.Debug("Sending Tropo response:[" + json + "]"); return(json); }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo class. Tropo tropo = new Tropo(); try { // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); tropo.Say("The Tropo Session ID is " + tropoSession.Id); tropo.Say("The channnel of the called party is " + tropoSession.To.Channel); tropo.Say("The channel of the calling party is " + tropoSession.From.Channel); tropo.Say("This initial text sent with the call is " + tropoSession.InitialText); tropo.Say("The From SIP header on the call is " + TropoUtilities.removeQuotes(tropoSession.Headers["From"])); } catch (JsonReaderException) { tropo.Say("Sorry, an error occured. I choked on some JSON"); } catch (Exception ex) { tropo.Say("Sorry, an error occured. " + ex.Message); } finally { Response.Write(tropo.RenderJSON()); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo object. Tropo tropo = new Tropo(); try { // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); // Get parameters submitted with Session API call. string numberToDial = tropoSession.Parameters.Get("numberToDial"); //numberToDial = "5093176303"; string sendFromNumber = tropoSession.Parameters.Get("sendFromNumber"); //sendFromNumber = "14082041999"; string channel = tropoSession.Parameters.Get("channel"); string network = tropoSession.Parameters.Get("network"); string textMessageBody = tropoSession.Parameters.Get("textMessageBody"); string[] week = new string[4]; week[0] = "http://artifacts.voxeolabs.net.s3.amazonaws.com/test/test.png"; week[1] = "this is 这是第二行"; week[2] = "https://www.travelchinaguide.com/images/photogallery/2012/beijing-tiananmen-tower.jpg"; week[3] = "Today is 13 Aug"; //week[3] = "https://me888dia.giphy.com/media/LHZyixOnHwDDy/giphy.gif"; string currenT = DateTime.Now.ToString("yyyy/MM/dd HH:MM tt"); Say say = new Say(); say.Value = "this is MMS test for webapi Csharp SDk sent @ " + currenT; say.Media = week; // Send an outbound message. tropo.Call(numberToDial, sendFromNumber, network, channel, true, 60, null); // tropo.Say(textMessageBody); tropo.Say(say); //tropo.RenderJSON(Response); } catch (JsonReaderException ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application. Bad JSON"); } catch (Exception ex) { EventLog log = new EventLog(); log.Source = "TROPOWEBAPI"; log.WriteEntry("Tropo WebAPI Exception " + ex.Message, EventLogEntryType.Error); Response.StatusCode = 500; tropo.Say("An error occured in the application."); } finally { tropo.RenderJSON(Response); } } }
protected void Page_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader(Request.InputStream)) { // Get the JSON submitted from Tropo. string sessionJSON = TropoUtilities.parseJSON(reader); // Create a new instance of the Tropo class. Tropo tropo = new Tropo(); try { // Create a new Session object and pass in the JSON submitted from Tropo. Session tropoSession = new Session(sessionJSON); //tropo.Say("The Tropo Session ID is " + tropoSession.Id); //tropo.Say("The channnel of the called party is " + tropoSession.To.Channel); //tropo.Say("The channel of the calling party is " + tropoSession.From.Channel); //tropo.Say("This initial text sent with the call is " + tropoSession.InitialText); //tropo.Say("The From SIP header on the call is " + TropoUtilities.removeQuotes(tropoSession.Headers["From"])); string fromName = tropoSession.From.Name; string fromChannel = tropoSession.From.Channel; string toName = tropoSession.To.Name; string toE164Id = tropoSession.To.E164Id; string fromE164Id = tropoSession.From.E164Id; string accountId = tropoSession.AccountId; string callId = tropoSession.CallId; tropo.Say("from Name is " + fromName); tropo.Say("to E164 Id is " + toE164Id); tropo.Say("fro mE164Id is " + fromE164Id); tropo.Say("account Id is " + accountId); tropo.Say("call Id is " + callId); if (fromName.Contains("xiang")) { tropo.Say("Welcome frank"); tropo.Say("Just beep beep beep"); } else { // tropo.Say("Sorry Alex"); HttpContext.Current.Trace.Warn(fromName + " You had been rejected cruely "); tropo.Reject(); } } catch (JsonReaderException) { tropo.Say("Sorry, an error occured. I choked on some JSON"); } catch (Exception ex) { tropo.Say("Sorry, an error occured. " + ex.Message); } finally { tropo.RenderJSON(Response); //HttpContext.Current.Trace.Warn("tropo.JSONToTe666666xt() is" + tropo.JSONToText()); //Response.Write("{\"tropo\":[{ \"reject\":null}]}"); } } }