Informizely customer feedback surveys
By using the Aculab site, you agree with our use of cookies.

simple run speech menu Sample

A simple application that presents an audio menu to an answered inbound or outbound call.

Options 1 and 2 direct to a page that reads out a weather report for the selected country (Belgium or Venezuala). Option 3 directs to a page that read out a weather report for Outer Mongolia. Each page then returns to the menu page.

If no selection or an invalid selection is made the caller is prompted to re-select. After several attempts the caller will be played an audio file (oneMoreTime.wav) prompting for a final go.

This application requires the wav file oneMoreTime.wav to be available in the cloud media store.

Uses actions: Run Speech Menu, Play, Redirect

    • {
          "actions" :
          [
              {
                  "run_speech_menu":
                  {
                      "prompt" :
                      {
                          "play" :
                          {
                              "play_list" :
                              [
                                  {
                                      "text_to_say" : "Say the country for which you want a weather report, Belgium, Venezuela or Outer Mongolia. Or press 1 for Belgium, 2 for Venezuela, 3 for Outer Mongolia. Or press 5 to listen to the options again."
                                  }
                              ]
                          }
                      },
                      "menu_options" :
                      [
                          {
                              "speech" : "belgium",
                              "digit" : "1",
                              "next_page" :
                              {
                                  "url" : "WeatherReport"
                              }
                          },
                          {
                              "speech" : "venezuela",
                              "digit" : "2",
                              "next_page" :
                              {
                                  "url" : "WeatherReport"
                              }
                          },
                          {
                              "speech" : "outer mongolia",
                              "digit" : "3",
                              "next_page" :
                              {
                                  "url" : "WeatherInOuterMongolia"
                              }
                          }
                      ],
                      "help_digit" : "5",
                      "help_word" : "help",
                      "on_input_timeout_messages":
                      [
                          {
                              "play" :
                              {
                                  "play_list" :
                                  [
                                      {
                                          "text_to_say" : "I didn't catch your entry."
                                      }
                                  ]
                              }
                          },
                          {
                              "play" :
                              {
                                  "play_list" :
                                  [
                                      {
                                          "text_to_say" : "Please select a country."
                                      }
                                  ]
                              }
                          },
                          {
                              "play" :
                              {
                                  "play_list" :
                                  [
                                      {
                                          "file_to_play" : "oneMoreTime.wav"
                                      }
                                  ]
                              }
                          }
                      ],
                      "on_invalid_input_messages" :
                      [
                          {
                              "play" :
                              {
                                  "play_list" :
                                  [
                                      {
                                          "text_to_say" : "That wasn't one of the options. Please try again."
                                      }
                                  ]
                              }
                          },
                          {
                              "play" :
                              {
                                  "play_list" :
                                  [
                                      {
                                          "file_to_play" : "oneMoreTime.wav"
                                      }
                                  ]
                              }
                          }
                      ]
                  }
              }
          ],
          "token" : "my run speech menu instance id",
          "api_version": "2.0"
      }
      
    • {
          "actions" :
          [
              {
                  "play" :
                  {
                      "play_list" :
                      [
                          {
                              "text_to_say" : "The weather for Belgium is quite often good but sometimes is appalling."
                          }
                      ]
                  }
              },
              {
                  "redirect" :
                  {
                      "next_page" :
                      {
                          "url" : "SimpleRunSpeechMenu"
                      }
                  }
              }
          ],
          "token" : "my run speech menu instance id",
          "api_version": "2.0"
      }
      
    • {
          "actions" :
          [
              {
                  "play" :
                  {
                      "play_list" :
                      [
                          {
                              "text_to_say" : "The weather for Venezuela is dry from about November to May and considerably wetter for the rest of the year. It is close to the equator, so average temperatures below 1000 metres are between 70 and 85 degrees Fahrenheit in most places."
                          }
                      ]
                  }
              },
              {
                  "redirect" :
                  {
                      "next_page" :
                      {
                          "url" : "SimpleRunSpeechMenu"
                      }
                  }
              }
          ],
          "token" : "my run speech menu instance id",
          "api_version": "2.0"
      }
      
    • {
          "actions" :
          [
              {
                  "play" :
                  {
                      "play_list" :
                      [
                          {
                              "text_to_say" : "The weather in Outer Mongolia is just right for Outer Mongolians."
                          }
                      ]
                  }
              },
              {
                  "redirect" :
                  {
                      "next_page" :
                      {
                          "url" : "SimpleRunSpeechMenu"
                      }
                  }
              }
          ],
          "token" : "my run speech menu instance id",
          "api_version": "2.0"
      }
      
    • {
          [
          ],
          "token" : "Error for Action: xxxx  ActionIndex: xxxx  Result: xxxx"
      }
      
    • {
      }
      
    • Implementing this sample as an ASP.Net Web Form application:

      • // CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Speech Menu:
        // A simple application that presents an audio menu to an answered inbound call.
        // Options 1 and 2 direct to a page that reads out a weather report for the selected
        // country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
        // report for Outer Mongolia. Each page then returns to the menu page.
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class SimpleRunSpeechMenu : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Unpack the request
                TelephonyRequest ourRequest = new TelephonyRequest(Request);
        
                // Setup the actions
                List<TelephonyAction> actions = new List<TelephonyAction>();
        
                // Create the menu action
                Play menuPrompt = Play.SayText("Say the country for which you want a weather report, " +
                                               "Belgium, Venezuela or Outer Mongolia. " +
                                               "Or press 1 for Belgium, " +
                                               "2 for Venezuela, " +
                                               "3 for Outer Mongolia. " +
                                               "Or press 5 to listen to the options again.");
                List<SpeechMenuOption> menuOptions = new List<SpeechMenuOption>
                {
                    new SpeechMenuOption("belgium", '1', new WebPageRequest("WeatherReport.aspx")),
                    new SpeechMenuOption("venezuela", '2', new WebPageRequest("WeatherReport.aspx")),
                    new SpeechMenuOption("outer mongolia", '3', new WebPageRequest("WeatherInOuterMongolia.aspx"))
                };
                RunSpeechMenu runSpeechMenuAction = new RunSpeechMenu(menuOptions, menuPrompt);
                runSpeechMenuAction.HelpDigit = '5';
                runSpeechMenuAction.HelpWord = "help";
        
                // Set up some new info messages for no entry and invalid entry
                runSpeechMenuAction.OnInputTimeoutMessages = new List<Play>
                {
                    Play.SayText("I didn't catch your entry."),
                    Play.SayText("Please select a country."),
                    Play.PlayFile("oneMoreTime.wav")
                };
                runSpeechMenuAction.OnInvalidInputMessages = new List<Play>
                {
                    Play.SayText("That wasn't one of the options. Please try again."),
                    Play.PlayFile("oneMoreTime.wav")
                };
        
                actions.Add(runSpeechMenuAction);
        
                // Respond
                String token = "my run speech menu instance id";
                TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                ourResponse.ToHttpResponse(Response);
            }
        }
        
        
      • // CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Menu:
        // WeatherReport page
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class WeatherReport : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Unpack the request
                TelephonyRequest ourRequest = new TelephonyRequest(Request);
                String token = ourRequest.InstanceInfo.Token;
        
                // Get the result of the run_menu or run_speech_menu action
                char selectedDigit;
                String nextPage;
                ActionResult actionResult = ourRequest.InstanceInfo.ActionResult;
                if (actionResult.Action.Equals("run_menu"))
                {
                    selectedDigit = ((RunMenuResult)actionResult).SelectedDigit;
                    nextPage = "SimpleRunMenu.aspx";
                }
                else
                {
                    selectedDigit = ((RunSpeechMenuResult)actionResult).SelectedDigit;
                    nextPage = "SimpleRunSpeechMenu.aspx";
                }
        
                // Setup the actions
                List<TelephonyAction> actions = new List<TelephonyAction>();
                Play playAction = new Play(); 
                switch (selectedDigit)
                {
                    case '1':
                        playAction.AddText("The weather for Belgium is quite often good but sometimes is appalling.");
                        break;
                    case '2':
                        playAction.AddText("The weather for Venezuela is dry from about November to May " +
                                           "and considerably wetter for the rest of the year. " +
                                           "It is close to the equator, so average temperatures below 1000 metres " +
                                           "are between 70 and 85 degrees Fahrenheit in most places.");
                        break;
                }
                actions.Add(playAction);
                actions.Add(new Redirect(new WebPageRequest(nextPage)));
        
                // Respond
                TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                ourResponse.ToHttpResponse(Response);
            }
        }
        
        
      • // CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Menu:
        // WeatherInOuterMongolia page
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class WeatherInOuterMongolia : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Unpack the request
                TelephonyRequest ourRequest = new TelephonyRequest(Request);
                String token = ourRequest.InstanceInfo.Token;
        
                // Did we get here as the result of the run_menu or run_speech_menu action?
                String nextPage;
                ActionResult actionResult = ourRequest.InstanceInfo.ActionResult;
                if (actionResult.Action.Equals("run_menu"))
                {
                    nextPage = "SimpleRunMenu.aspx";
                }
                else
                {
                    nextPage = "SimpleRunSpeechMenu.aspx";
                }
        
                // Setup the actions
                List<TelephonyAction> actions = new List<TelephonyAction>
                {
                    Play.SayText("The weather in Outer Mongolia is just right for Outer Mongolians."),
                    new Redirect(new WebPageRequest(nextPage))
                };
        
                // Respond
                TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                ourResponse.ToHttpResponse(Response);
            }
        }
        
        
      • using System;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class ErrorPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Unpack the request
                TelephonyRequest ourRequest = new TelephonyRequest(Request);
                ErrorResult result = ourRequest.InstanceInfo.ErrorResult;
        
                String token = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}",
                    result.Action, result.ActionIndex, result.Result);
        
                // Respond
                TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                ourResponse.ToHttpResponse(Response);
            }
        }
        
        
      • using System;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class FinalPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // Unpack the request
                TelephonyRequest ourRequest = new TelephonyRequest(Request);
            }
        }
        
        
    • Implementing this sample as an ASP.Net Mvc application:

      • // ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Speech Menu:
        // A simple application that presents an audio menu to an answered inbound call.
        // Options 1 and 2 direct to a page that reads out a weather report for the selected
        // country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
        // report for Outer Mongolia. Each page then returns to the menu page.
        
        using System;
        using System.Net;
        using System.Collections.Generic;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            [Route("SimpleRunSpeechMenu")]
            public class SimpleRunSpeechMenuController : WeatherReportController
            {
                [Route("FirstPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public IActionResult SimpleRunSpeechMenu()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = new TelephonyRequest(Request);
        
                        // Setup the actions required
                        List<TelephonyAction> actions = new List<TelephonyAction>();
        
                        // Create the menu action
                        Play menuPrompt = Play.SayText("Say the country for which you want a weather report, " +
                                                       "Belgium, Venezuela or Outer Mongolia. " +
                                                       "Or press 1 for Belgium, " +
                                                       "2 for Venezuela, " +
                                                       "3 for Outer Mongolia. " +
                                                       "Or press 5 to listen to the options again.");
                        List<SpeechMenuOption> menuOptions = new List<SpeechMenuOption>();
                        menuOptions.Add(new SpeechMenuOption("belgium", '1', new WebPageRequest("SimpleRunSpeechMenu/WeatherReport")));
                        menuOptions.Add(new SpeechMenuOption("venezuela", '2', new WebPageRequest("SimpleRunSpeechMenu/WeatherReport")));
                        menuOptions.Add(new SpeechMenuOption("outer mongolia", '3', new WebPageRequest("SimpleRunSpeechMenu/WeatherInOuterMongolia")));
                        RunSpeechMenu runSpeechMenuAction = new RunSpeechMenu(menuOptions, menuPrompt)
                        {
                            HelpDigit = '5',
                            HelpWord = "help"
                        };
        
                        // Set up some new info messages for no entry and invalid entry
                        runSpeechMenuAction.OnInputTimeoutMessages = new List<Play>()
                        {
                            Play.SayText("I didn't catch your entry."),
                            Play.SayText("Please select a country."),
                            Play.PlayFile("oneMoreTime.wav")
                        };
                        runSpeechMenuAction.OnInvalidInputMessages = new List<Play>()
                        {
                            Play.SayText("That wasn't one of the options. Please try again."),
                            Play.PlayFile("oneMoreTime.wav")
                        };
        
                        actions.Add(runSpeechMenuAction);
        
                        // Create response
                        String token = "my run speech menu instance id";
                        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                        return ourResponse.ToJson(this);
                    }
                    catch (ArgumentException)
                    {
                        return BadRequest();
                    }
                    catch (Exception e)
                    {
                        return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
                    }
                }
            }
        }
        
      • // ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Speech Menu:
        // A simple application that presents an audio menu to an answered inbound call.
        // Options 1 and 2 direct to a page that reads out a weather report for the selected
        // country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
        // report for Outer Mongolia. Each page then returns to the menu page.
        
        using System;
        using System.Net;
        using System.Collections.Generic;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        }
        
      • // ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Run Speech Menu:
        // A simple application that presents an audio menu to an answered inbound call.
        // Options 1 and 2 direct to a page that reads out a weather report for the selected
        // country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
        // report for Outer Mongolia. Each page then returns to the menu page.
        
        using System;
        using System.Net;
        using System.Collections.Generic;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        }
        
      • // ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
        
        using System;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        using System.Net;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            public class RESTSampleController : Controller
            {
                // Process the GET or POST request for the Error condition
                [Route("ErrorPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public IActionResult ErrorPage()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = new TelephonyRequest(Request);
                        ErrorResult result = telephonyRequest.InstanceInfo.ErrorResult;
        
                        String token = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}",
                            result.Action, result.ActionIndex, result.Result);
        
                        // Create response
                        TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                        return ourResponse.ToJson(this);
                    }
                    catch (ArgumentException)
                    {
                        return BadRequest();
                    }
                    catch (Exception e)
                    {
                        return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
                    }
                }
            }
        }
        
      • // ASP.NET Core CSharp Wrapper sample for the Aculab Telephony REST API.
        
        using System;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        using System.Net;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            public class RESTSampleController : Controller
            {
                // Process the GET or POST request for the Final Page
                [Route("FinalPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public IActionResult FinalPage()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = new TelephonyRequest(Request);
                        String token = telephonyRequest.InstanceInfo.Token;
        
                        // Create response
                        // Only very limited actions can be returned here
                        TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                        return ourResponse.ToJson(this);
                    }
                    catch (ArgumentException)
                    {
                        return BadRequest();
                    }
                    catch (Exception e)
                    {
                        return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
                    }
                }
            }
        }
        
  • Implemented as ASP.Net Web Forms:

    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' The first page for the Simple Run Speech Menu sample:
      ' A simple application that presents an audio menu to an answered inbound call.
      ' Options 1 and 2 direct to a page that reads out a weather report for the selected
      ' country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
      ' report for Outer Mongolia. Each page then returns to the menu page.
      Imports System.Collections.Generic
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class SimpleRunSpeechMenu
          Inherits System.Web.UI.Page
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
              ' Unpack the request
              Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
      
              ' Setup the actions
              Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
      
              ' Create the menu action
              Dim menuPrompt As Play = Play.SayText("Say the country for which you want a weather report, " +
                                             "Belgium, Venezuela or Outer Mongolia. " +
                                             "Or press 1 for Belgium, " +
                                             "2 for Venezuela, " +
                                             "3 for Outer Mongolia. " +
                                             "Or press 5 to listen to the options again.")
              Dim menuOptions As List(Of SpeechMenuOption) = New List(Of SpeechMenuOption)
              menuOptions.Add(New SpeechMenuOption("belgium", "1", New WebPageRequest("WeatherReport.aspx")))
              menuOptions.Add(New SpeechMenuOption("venezuela", "2", New WebPageRequest("WeatherReport.aspx")))
              menuOptions.Add(New SpeechMenuOption("outer mongolia", "3", New WebPageRequest("WeatherInOuterMongolia.aspx")))
              Dim runSpeechMenuAction As RunSpeechMenu = New RunSpeechMenu(menuOptions, menuPrompt)
              runSpeechMenuAction.HelpDigit = "5"
              runSpeechMenuAction.HelpWord = "help"
      
              ' Set up some new info messages for no entry and invalid entry
              runSpeechMenuAction.OnInputTimeoutMessages = New List(Of Play) From {
                  Play.SayText("I didn't catch your entry."),
                  Play.SayText("Please select a country."),
                  Play.PlayFile("oneMoreTime.wav")
              }
              runSpeechMenuAction.OnInvalidInputMessages = New List(Of Play) From {
                  Play.SayText("That wasn't one of the options. Please try again."),
                  Play.PlayFile("oneMoreTime.wav")
              }
      
              actions.Add(runSpeechMenuAction)
      
              ' Respond
              Dim token As String = "my run speech menu instance id"
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, token)
              ourResponse.ToHttpResponse(Response)
          End Sub
      End Class
      
      
    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' A page from the Simple Run Menu sample:
      ' It plays some text depeding on what option was selected and redirects back to the menu.
      Imports System.Collections.Generic
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class WeatherReport
          Inherits System.Web.UI.Page
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
              ' Unpack the request
              Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
              Dim token As String = ourRequest.InstanceInfo.Token
      
              ' Get the result of the run_menu or run_speech_menu action
              Dim selectedDigit As Char
              Dim nextPage As String
              Dim actionResult As ActionResult = ourRequest.InstanceInfo.ActionResult
              If actionResult.Action.Equals("run_menu") Then
                  Dim menuResult As RunMenuResult = actionResult
                  selectedDigit = menuResult.SelectedDigit
                  nextPage = "SimpleRunMenu.aspx"
              Else
                  Dim speechMenuResult As RunSpeechMenuResult = actionResult
                  selectedDigit = speechMenuResult.SelectedDigit
                  nextPage = "SimpleRunSpeechMenu.aspx"
              End If
      
              ' Setup the actions
              Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
              Dim playAction As Play = New Play()
              Select Case (selectedDigit)
                  Case "1"
                      playAction.AddText("The weather for Belgium is quite often good but sometimes is appalling.")
                  Case "2"
                      playAction.AddText("The weather for Venezuela is dry from about November to May " +
                                         "and considerably wetter for the rest of the year. " +
                                         "It is close to the equator, so average temperatures below 1000 metres " +
                                         "are between 70 and 85 degrees Fahrenheit in most places.")
              End Select
      
              actions.Add(playAction)
              actions.Add(New Redirect(New WebPageRequest(nextPage)))
      
              ' Respond
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, token)
              ourResponse.ToHttpResponse(Response)
          End Sub
      End Class
      
      
    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' A page from the Simple Run Menu sample:
      ' It plays some text and redirects back to the menu.
      Imports System.Collections.Generic
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class WeatherInOuterMongolia
          Inherits System.Web.UI.Page
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
              ' Unpack the request
              Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
              Dim token As String = ourRequest.InstanceInfo.Token
      
              ' Did we get here as the result of the run_menu or run_speech_menu action
              Dim nextPage As String
              Dim actionResult As ActionResult = ourRequest.InstanceInfo.ActionResult
              If actionResult.Action.Equals("run_menu") Then
                  Dim menuResult As RunMenuResult = actionResult
                  nextPage = "SimpleRunMenu.aspx"
              Else
                  Dim speechMenuResult As RunSpeechMenuResult = actionResult
                  nextPage = "SimpleRunSpeechMenu.aspx"
              End If
      
              ' Setup the actions
              Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
              actions.Add(Play.SayText("The weather in Outer Mongolia is just right for Outer Mongolians."))
              actions.Add(New Redirect(New WebPageRequest(nextPage)))
      
              ' Respond
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, token)
              ourResponse.ToHttpResponse(Response)
          End Sub
      End Class
      
      
    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' A generic error page for all the samples.
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class ErrorPage
          Inherits System.Web.UI.Page
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
              ' Unpack the request
              Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
              Dim result As ErrorResult = ourRequest.InstanceInfo.ErrorResult
      
              Dim token As String = String.Format("Action: {0}\nActionIndex: {1}\nResult: {2}", _
                  result.Action, result.ActionIndex, result.Result)
      
              ' Respond
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(token)
              ourResponse.ToHttpResponse(Response)
          End Sub
      End Class
      
      
    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' A generic final page for all the samples:
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class FinalPage
          Inherits System.Web.UI.Page
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      
              ' Unpack the request
              Dim ourRequest As TelephonyRequest = New TelephonyRequest(Request)
      
              ' Do application tidying up
              ' ...
          End Sub
      End Class
      
      
  • Implemented as Java Servlets:

    • // Java Servlet sample for the Aculab Telephony REST API.
      //
      // Simple Run Menu:
      // A simple application that presents an audio menu to an answered inbound call.
      // Options 1 and 2 direct to a page that reads out a weather report for the selected
      // country (Belgium or Venezuala). Option 3 directs to a page that read out a weather 
      // report for Outer Mongolia. Each page then returns to the menu page.
      
      package com.aculab.telephonyrestapi.samples;
      
      import javax.servlet.http.*;
      import javax.servlet.ServletException;
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.List;
      
      import com.aculab.telephonyrestapi.*;
      
      public class SimpleRunSpeechMenu extends HttpServlet
      {
      	private static final long serialVersionUID = 9117010142594490000L;
      
      	@Override
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response)
              throws IOException, ServletException
          {
             	handleRequest(request, response);
          }
          
          @Override
          public void doPost(HttpServletRequest request,
                  HttpServletResponse response)
                          throws IOException, ServletException
          {
          	handleRequest(request, response);
          }
          
          private void handleRequest(HttpServletRequest request,
                                     HttpServletResponse response) throws IOException
          {
              // Unpack the request
              TelephonyRequest ourRequest = new TelephonyRequest(request);
      
              // Set up the actions
              List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
      
              // Create the menu action
              Play menuPrompt = Play.sayText("Say the country for which you want a weather report, " +
                      "Belgium, Venezuela or Outer Mongolia. " +
                      "Or press 1 for Belgium, " +
                      "2 for Venezuela, " +
                      "3 for Outer Mongolia. " +
                      "Or press 5 to listen to the options again.",
                      "Paul");
      
              List<SpeechMenuOption> menuOptions = new ArrayList<SpeechMenuOption>();
              menuOptions.add(new SpeechMenuOption("belgium", '1', new WebPageRequest("WeatherReport")));
              menuOptions.add(new SpeechMenuOption("venezuela", '2', new WebPageRequest("WeatherReport")));
              menuOptions.add(new SpeechMenuOption("outer mongolia", '3', new WebPageRequest("WeatherInOuterMongolia")));
              RunSpeechMenu runSpeechMenuAction = new RunSpeechMenu(menuPrompt, menuOptions);
              runSpeechMenuAction.setHelpDigit('5');
              runSpeechMenuAction.setHelpWord("help");
              
              // Set up some new info messages for no entry and invalid entry
              List<Play> onInputTimeoutMessages = new ArrayList<Play>();
              onInputTimeoutMessages.add(Play.sayText("I didn't catch your entry."));
              onInputTimeoutMessages.add(Play.sayText("Please select a country."));
              onInputTimeoutMessages.add(Play.playFile("oneMoreTime.wav"));
              runSpeechMenuAction.setOnInputTimeoutMessages(onInputTimeoutMessages);
      
              List<Play> onInvalidInputMessages = new ArrayList<Play>();
              onInvalidInputMessages.add(Play.sayText("That wasn't one of the options. Please try again."));
              onInvalidInputMessages.add(Play.playFile("oneMoreTime.wav"));
              runSpeechMenuAction.setOnInvalidInputMessages(onInvalidInputMessages);
              
              actions.add(runSpeechMenuAction);
      
              // Respond
              TelephonyResponse ourResponse = new TelephonyResponse(actions, "my run speech menu instance id");
              ourResponse.setHttpServletResponse(response);
          }
      }
      
      
    • // Java Servlet sample for the Aculab Telephony REST API.
      //
      
      package com.aculab.telephonyrestapi.samples;
      
      import javax.servlet.http.*;
      import javax.servlet.ServletException;
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.List;
      
      import com.aculab.telephonyrestapi.*;
      
      public class WeatherReport extends HttpServlet
      {
      	private static final long serialVersionUID = 7363471490017269263L;
      
          @Override
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response)
              throws IOException, ServletException
          {
             	handleRequest(request, response);
          }
          
          @Override
          public void doPost(HttpServletRequest request,
                  HttpServletResponse response)
                          throws IOException, ServletException
          {
          	handleRequest(request, response);
          }
          
          private void handleRequest(HttpServletRequest request,
                                     HttpServletResponse response) throws IOException
          {
              // Unpack the request
              TelephonyRequest ourRequest = new TelephonyRequest(request);
      
              String token = ourRequest.getInstanceInfo().getToken();
      
              // Get the result of the run_menu or run_speech_menu action
              char selectedDigit;
              String nextPage;
              ActionResult actionResult = ourRequest.getInstanceInfo().getActionResult();
              if (actionResult.getAction().equals("run_menu"))
              {
                  selectedDigit = ((RunMenuResult)actionResult).getSelectedDigit();
                  nextPage = "SimpleRunMenu";
              }
              else
              {
                  selectedDigit = ((RunSpeechMenuResult)actionResult).getSelectedDigit();
                  nextPage = "SimpleRunSpeechMenu";
              }
              
              // Set up the actions
              List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
              Play playAction = new Play(); 
              switch (selectedDigit)
              {
                  case '1':
                      playAction.addText("The weather for Belgium is quite often good but sometimes is appalling.",
                                         "Paul");
                      break;
                  case '2':
                      playAction.addText("The weather for Venezuela is dry from about November to May " +
                                         "and considerably wetter for the rest of the year. " +
                                         "It is close to the equator, so average temperatures below 1000 metres " +
                                         "are between 70 and 85 degrees Fahrenheit in most places.",
                                         "Paul");
                      break;
              }
              actions.add(playAction);
              actions.add(new Redirect(new WebPageRequest(nextPage)));
      
              // Respond
              TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
              ourResponse.setHttpServletResponse(response);
          }
      }
      
      
    • // Java Servlet sample for the Aculab Telephony REST API.
      //
      
      package com.aculab.telephonyrestapi.samples;
      
      import javax.servlet.http.*;
      import javax.servlet.ServletException;
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.List;
      
      import com.aculab.telephonyrestapi.*;
      
      public class WeatherInOuterMongolia extends HttpServlet
      {
      	private static final long serialVersionUID = 1954950916030490560L;
      
          @Override
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response)
              throws IOException, ServletException
          {
             	handleRequest(request, response);
          }
          
          @Override
          public void doPost(HttpServletRequest request,
                  HttpServletResponse response)
                          throws IOException, ServletException
          {
          	handleRequest(request, response);
          }
          
          private void handleRequest(HttpServletRequest request,
                                     HttpServletResponse response) throws IOException
          {
              // Unpack the request
              TelephonyRequest ourRequest = new TelephonyRequest(request);
      
              String token = ourRequest.getInstanceInfo().getToken();
      
              // Get the result of the run_menu or run_speech_menu action
              String nextPage;
              ActionResult actionResult = ourRequest.getInstanceInfo().getActionResult();
              if (actionResult.getAction().equals("run_menu"))
              {
                  nextPage = "SimpleRunMenu";
              }
              else
              {
                  nextPage = "SimpleRunSpeechMenu";
              }
              
              // Set up the actions
              List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
              actions.add(Play.sayText("The weather in Outer Mongolia is just right for Outer Mongolians.",
                                       "Paul"));
              actions.add(new Redirect(new WebPageRequest(nextPage)));
      
              // Respond
              TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
              ourResponse.setHttpServletResponse(response);
          }
      }
      
      
    • // Java Servlet sample for the Aculab Telephony REST API.
      //
      
      package com.aculab.telephonyrestapi.samples;
      
      import javax.servlet.http.*;
      import javax.servlet.ServletException;
      import java.io.IOException;
      import java.util.ArrayList;
      import java.util.List;
      
      import com.aculab.telephonyrestapi.*;
      
      public class ErrorPage extends HttpServlet
      {
          private static final long serialVersionUID = -4842873371047361437L;
      
          @Override
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response)
              throws IOException, ServletException
          {
             	handleRequest(request, response);
          }
          
          @Override
          public void doPost(HttpServletRequest request,
                  HttpServletResponse response)
                          throws IOException, ServletException
          {
          	handleRequest(request, response);
          }
          
          private void handleRequest(HttpServletRequest request,
                                     HttpServletResponse response) throws IOException
          {
              // Unpack the request
              TelephonyRequest ourRequest = new TelephonyRequest(request);
      
              ErrorResult result = ourRequest.getInstanceInfo().getErrorResult();
      
              String token = String.format("Action: %s\nActionIndex: %d\nResult: %s", result.getAction(), result.getActionIndex(), result.getResult());
              
              // Respond
              List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
              TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
              ourResponse.setHttpServletResponse(response);
          }
      }
      
      
    • // Java Servlet sample for the Aculab Telephony REST API.
      //
      
      package com.aculab.telephonyrestapi.samples;
      
      import javax.servlet.http.*;
      import javax.servlet.ServletException;
      import java.io.IOException;
      import com.aculab.telephonyrestapi.*;
      
      public class FinalPage extends HttpServlet
      {
          private static final long serialVersionUID = 5940620014313056844L;
      
          @Override
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response)
              throws IOException, ServletException
          {
             	handleRequest(request, response);
          }
          
          @Override
          public void doPost(HttpServletRequest request,
                  HttpServletResponse response)
                          throws IOException, ServletException
          {
          	handleRequest(request, response);
          }
          
          private void handleRequest(HttpServletRequest request,
                                     HttpServletResponse response) throws IOException
          {
              // Unpack the request
              TelephonyRequest ourRequest = new TelephonyRequest(request);
          }
      }
      
      
  • Implemented as a Flask web application:

    • @app.route('/SimpleRunSpeechMenu', methods=['GET','POST'])
      def handle_SimpleRunSpeechMenu():
      
          my_request = TelephonyRequest(request)
          app_inst_id = my_request.get_application_instance_id()
          print("SimpleRunSpeechMenu: app_inst_id='{}'".format(app_inst_id))
      
          speech_menu_options = []
          speech_menu_options.append(SpeechMenuOption('belgium', '1', WebPage('WeatherReport')))
          speech_menu_options.append(SpeechMenuOption('venezuela', '2', WebPage('WeatherReport')))
          speech_menu_options.append(SpeechMenuOption('outer mongolia', '3', WebPage('WeatherInOuterMongolia')))
      
          digit_timeout_messages = []
          digit_timeout_messages.append(Play(text_to_say="I didn't catch your entry."))
          digit_timeout_messages.append(Play(text_to_say="Please select a country."))
          digit_timeout_messages.append(Play(file_to_play="oneMoreTime.wav"))
      
          invalid_digit_messages = []
          invalid_digit_messages.append(Play(text_to_say="That wasn't one of the options. Please try again."))
          invalid_digit_messages.append(Play(file_to_play="oneMoreTime.wav"))
      
          my_menu = RunSpeechMenu(speech_menu_options)
          # set up the menu
          play_action = Play(text_to_say = ('Say the country for which you want a weather report,'
                                            ' Belgium, Venezuela or Outer Mongolia.'
                                            ' Or press 1 for Belgium,'
                                            ' 2 for Venezuela,'
                                            ' 3 for Outer Mongolia.'
                                            ' Or press 5 to listen to the options again.'))
          my_menu.set_prompt(play_action)
          my_menu.set_help_digit('5')
          my_menu.set_help_word('help')
      
          # set on silence timeout and invalid digit messages
          my_menu.set_on_input_timeout_messages(digit_timeout_messages)
          my_menu.set_on_invalid_input_messages(invalid_digit_messages)   
      
          list_of_actions = []
          list_of_actions.append(my_menu)
          my_response = TelephonyResponse(list_of_actions, token='my run speech menu instance id')
          return my_response.get_json()
      
    • @app.route('/WeatherReport', methods=['GET','POST'])
      def handle_WeatherReport():
      
          belgium_report = "The weather for Belgium is quite often good but sometimes is appalling."
          venezuela_report = ("The weather for Venezuela is dry from about November to May "
                              "and considerably wetter for the rest of the year. "
                              "It is close to the equator, so average temperatures below 1000 metres "
                              "are between 70 and 85 degrees Fahrenheit in most places.")
      
          my_request = TelephonyRequest(request)
          my_token = my_request.get_token()
          action_result = my_request.get_action_result()
      
          selected_digit = action_result.get('result').get('selected_digit')
      
          list_of_actions = []
          if selected_digit == '1':
              list_of_actions.append(Play(text_to_say = belgium_report))
          elif selected_digit == '2':
              list_of_actions.append(Play(text_to_say = venezuela_report))
      
          if(action_result.get('action') == 'run_menu'):
              list_of_actions.append(Redirect(next_page=WebPage(url='SimpleRunMenu')))
          else: # Must have been called by RunSpeechMenu
              list_of_actions.append(Redirect(next_page=WebPage(url='SimpleRunSpeechMenu')))
      
          my_response = TelephonyResponse(list_of_actions, my_token)
          return my_response.get_json()
      
      
    • @app.route('/WeatherInOuterMongolia', methods=['GET','POST'])
      def handle_WeatherInOuterMongolia():
      
          my_request = TelephonyRequest(request)
          my_token = my_request.get_token()
          action_result = my_request.get_action_result()
      
          outer_mongolia_report = "The weather in Outer Mongolia is just right for Outer Mongolians."
      
          list_of_actions = []
          list_of_actions.append(Play(text_to_say = outer_mongolia_report))
      
          if(action_result.get('action') == 'run_menu'):
              list_of_actions.append(Redirect(next_page=WebPage(url='SimpleRunMenu')))
          else: # Must have been called by RunSpeechMenu
              list_of_actions.append(Redirect(next_page=WebPage(url='SimpleRunSpeechMenu')))
      
          my_response = TelephonyResponse(list_of_actions, my_token)
          return my_response.get_json()
      
    • @app.route('/ErrorPage', methods=['GET','POST'])
      def handle_ErrorPage():
          
          my_request = TelephonyRequest(request)
          token = my_request.get_token()
          app_inst_id = my_request.get_application_instance_id()
          error_result_dict = my_request.get_error_result()
          action_string = error_result_dict.get('action', "?")
          result_string = error_result_dict.get('result', "?")
          print("ErrorPage: app_inst_id='{}' token='{}' action='{}' result='{}'".format(app_inst_id, token, action_string, result_string))
          
          my_response = TelephonyResponse([Play(text_to_say='An error has occurred')])
          return my_response.get_json()
      
      
    • @app.route('/FinalPage', methods=['GET','POST'])
      def handle_FinalPage():
          # The FinalPage handler follows the guidelines on:
          # https://www.aculab.com/cloud/voice-and-fax-apis/rest-api/rest-api-version-2/writing-a-rest-application
          # The guidelines are:
          #   "Your final page should return an empty response, a 204 is preferable, but empty JSON is acceptable."
          my_request = TelephonyRequest(request)
          token = my_request.get_token()
          app_inst_id = my_request.get_application_instance_id()
          print("FinalPage: app_inst_id='{}' token='{}'".format(app_inst_id, token))
          empty_json = '{}'.encode('utf-8')
          return empty_json, 204
          
      
    • <?php
      header("Content-Type: application/json; charset=UTF-8");
      
      require __DIR__ . "/../../autoload.php";
      
      use \Aculab\TelephonyRestAPI\Response;
      use \Aculab\TelephonyRestAPI\Play;
      use \Aculab\TelephonyRestAPI\RunSpeechMenu;
      use \Aculab\TelephonyRestAPI\MessageList;
      
      $response = new Response();
      $response->setToken('my run speech menu instance id');
      
      // Create the menu action
      $menuPrompt = Play::sayText(
          "Say the country for which you want a weather report, " .
          "Belgium, Venezuela or Outer Mongolia. " .
          "Or press 1 for Belgium, " .
          "2 for Venezuela, " .
          "3 for Outer Mongolia. " .
          "Or press 5 to listen to the options again."
      );
      $menu = new RunSpeechMenu();
      $menu->setPrompt($menuPrompt)
          ->setLanguage('en-GB')
          ->addSpeechMenuOption('belgium', '1', 'WeatherReport.php')
          ->addSpeechMenuOption('venezuela', '2', 'WeatherReport.php')
          ->addSpeechMenuOption('outer mongolia', '3', 'WeatherInOuterMongolia.php')
          ->setHelpDigit('5')
          ->setHelpWord('help');
      
      // Set up some new info messages for input timeout and invalid input
      $onInputTimeoutMessages = new MessageList();
      $onInputTimeoutMessages->addMessage(Play::sayText("I didn't catch your entry."))
          ->addMessage(Play::sayText("Please select a country."))
          ->addMessage(Play::playFile("oneMoreTime.wav"));
      $menu->setOnInputTimeoutMessages($onInputTimeoutMessages);
      
      $onInvalidInputMessages = new MessageList();
      $onInvalidInputMessages->addMessage(Play::sayText("That wasn't one of the options. Please try again."));
      $onInvalidInputMessages->addMessage(Play::playFile("oneMoreTime.wav"));
      $menu->setOnInvalidInputMessages($onInvalidInputMessages);
      
      $response->addAction($menu);
      
      print $response;
      
      
    • <?php
      header("Content-Type: application/json; charset=UTF-8");
      
      require __DIR__ . "/../../autoload.php";
      
      use \Aculab\TelephonyRestAPI\InstanceInfo;
      use \Aculab\TelephonyRestAPI\Response;
      use \Aculab\TelephonyRestAPI\Play;
      use \Aculab\TelephonyRestAPI\Redirect;
      
      $info = InstanceInfo::getInstanceInfo();
      
      $response = new Response();
      $response->setToken($info->getToken());
      // Get the result of the run_speech_menu action
      $result = $info->getActionResult();
      $selection = $result->getSelectedSpeech();
              
      // Set up the actions
      $actions = new Response();
      $playAction = new Play(); 
      if ($selection === 'belgium') {
          $playAction->addText("The weather for Belgium is quite often good but sometimes is appalling.");
      } else if ($selection === 'venezuela') {
          $playAction->addText("The weather for Venezuela is dry from about November to May " .
              "and considerably wetter for the rest of the year. " .
              "It is close to the equator, so average temperatures below 1000 metres " .
              "are between 70 and 85 degrees Fahrenheit in most places."
          );
      } else {
          $playAction->addText("Something has gone wrong.");
      }
      $response->addAction($playAction);
      $response->addAction(new Redirect("First.php"));
      
      print $response;
      
      
    • <?php
      header("Content-Type: application/json; charset=UTF-8");
      
      require __DIR__ . "/../../autoload.php";
      
      use \Aculab\TelephonyRestAPI\InstanceInfo;
      use \Aculab\TelephonyRestAPI\Response;
      use \Aculab\TelephonyRestAPI\Play;
      use \Aculab\TelephonyRestAPI\Redirect;
      
      $info = InstanceInfo::getInstanceInfo();
      
      $response = new Response();
      $response->setToken($info->getToken());
      
      // Set up the actions
      $playAction = new Play(); 
      $playAction->addText("The weather in Outer Mongolia is just right for Outer Mongolians.");
      $response->addAction($playAction);
      $response->addAction(new Redirect("First.php"));
      
      print $response;
      
      
    • <?php
      header("Content-Type: application/json; charset=UTF-8");
      
      require __DIR__ . "/../../autoload.php";
      
      use Aculab\TelephonyRestAPI\Play;
      use Aculab\TelephonyRestAPI\Response;
      use Aculab\TelephonyRestAPI\InstanceInfo;
      
      $info = InstanceInfo::getInstanceInfo();
      
      $error = $info->getErrorResult();
      $action = $error->getAction();
      $desc = $error->getResult();
      if (!is_null($action)) {
          error_log("Error from action \"$action\" with result:" . PHP_EOL . "$desc" . PHP_EOL);
      } else {
          error_log("Error result:" . PHP_EOL . "$desc" . PHP_EOL);
      }
      
      $response = new Response();
      $response->setToken('Error');
      
      $play = new Play();
      $play->addText('An error has occurred.');
      $response->addAction($play);
      
      print $response;
      
      
    • <?php
      require __DIR__ . "/../../autoload.php";
      
      http_response_code(204);
      header("Content-Type: application/json; charset=UTF-8");
      
      use Aculab\TelephonyRestAPI\InstanceInfo;
      
      $info = InstanceInfo::getInstanceInfo();
      $call = $info->getThisCallInfo();
      $callid = $call->getCallId();
      $duration = $call->getSecondsCallDuration();
      error_log("This call id: $callid" . PHP_EOL . "This call duration: $duration" . PHP_EOL);