コード例 #1
0
        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 = new Result(resultJSON);

                    // Parse the Actions object and get the value property.
                    JContainer Actions = TropoUtilities.parseActions(tropoResult.Actions);

                    // 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.
                    string answer = TropoUtilities.removeQuotes(Actions["value"].ToString());
                    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
                {
                    // Render JSON for Tropo to consume.
                    tropo.Hangup();
                    Response.Write(tropo.RenderJSON());
                }
            }
        }
コード例 #2
0
        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());
                }
            }
        }