Create an instance of the Tropo Session object.
        protected void Page_Load(object sender, EventArgs e)
        {
            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                // Get the JSON submitted from Tropo.
                string sessionJSON = GetJSON(sr);

                try
                {
                    // Create a new Session object and pass in the JSON submitted from Tropo.
                    Session tropoSession = new Session(sessionJSON);

                    // A simple example showing how to access parameters on the Session object.
                    Response.Write("Parameters-Action:  " + tropoSession.Parameters["action"]);
                }

                catch (JsonReaderException ex)
                {
                    Response.Write("An error occured. " + ex.Message);
                }

                catch (Exception ex)
                {
                    Response.Write("An error occured. " + ex.Message);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                // Get the JSON submitted from Tropo.
                string sessionJSON = GetJSON(sr);

                try
                {
                    // Create a new Session object and pass in the JSON submitted from Tropo.
                    Session tropoSession = new Session(sessionJSON);

                    // A simple example showing how to access properties of the Session object.
                    Response.Write("ID:  " + tropoSession.Id + "\n");
                    Response.Write("To-Channel: " + tropoSession.To.channel+ "\n");
                    Response.Write("From-Channel: " + tropoSession.From.channel+ "\n");
                    Response.Write("Initial Text: " + tropoSession.InitialText + "\n");
                }

                catch (JsonReaderException ex)
                {
                    Response.Write("An error occured. " + ex.Message);
                }

                catch (Exception ex)
                {
                    Response.Write("An error occured. " + ex.Message);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Must be used from an endpoint URL. 
        /// This will parse the active session and send the specified messages. 
        /// As of now, it only supports sending through the MSN Network IM
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public static string ExecuteSession(StreamReader reader, Dictionary<string, List<string>> messages)
        {
            string sessionJSON = reader.ReadToEnd();
            Tropo tropo = new Tropo();
            try
            {
                Session tropoSession = new Session(sessionJSON);

                foreach (var kvp in messages)
                {
                    string to = kvp.Key;
                    string from = "*****@*****.**";

                    foreach (string msg in kvp.Value)
                    {
                        tropo.Message(new Say(msg), new List<string>() { to }, false, Channel.Text, from, from, Network.Msn, false, 30);
                    }
                }

            }
            catch
            {
            }
            return 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 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());
                }
            }
        }
 public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     try
     {
         var request = controllerContext.RequestContext.HttpContext.Request;
         var json = InputStreamToString(request);
         var session = new Session(json);
         return session;
     }
     catch (Exception)
     {
         return null;
     }
 }
        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, "#");
                    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."));
                }

                // Render the JSON for Tropo to consume.
                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 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 sr = new StreamReader(Request.InputStream))
            {
                // Get the JSON submitted from Tropo.
                string sessionJSON = GetJSON(sr);

                // Create a new Session object and pass in the JSON submitted from Tropo.
                Session tropoSession = new Session(sessionJSON);

                // Create a new instance of the Tropo object.
                Tropo tropo = new Tropo();

                // Call an outbound number and create a conference.
                tropo.Call(tropoSession.Parameters["callToNumber"]);
                tropo.Say("Welcome to the conference.");
                tropo.Conference(tropoSession.Parameters["conferenceID"], false, "testConference", false, true, "#");
                tropo.Say("Thanks for joining our conference. Goodbye.");
                tropo.Hangup();

                // Render the JSON for Tropo to consume.
                Response.Write(tropo.RenderJSON());
            }
        }