right  Talk To Us!

simple run 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 Menu, Play, Redirect

    • {
          "actions" :
          [
              {
                  "run_menu":
                  {
                      "prompt" :
                      {
                          "play" :
                          {
                              "play_list" :
                              [
                                  {
                                      "text_to_say" : "Press 1 for a weather report for Belgium. Press 2 for Venezuela. Press 3 for Outer Mongolia. Or press 5 to listen to the options again."
                                  }
                              ]
                          }
                      },
                      "menu_options" :
                      [
                          {
                              "digit" : "1",
                              "next_page" :
                              {
                                  "url" : "WeatherReport"
                              }
                          },
                          {
                              "digit" : "2",
                              "next_page" :
                              {
                                  "url" : "WeatherReport"
                              }
                          },
                          {
                              "digit" : "3",
                              "next_page" :
                              {
                                  "url" : "WeatherInOuterMongolia"
                              }
                          }
                      ],
                      "help_digit" : "5",
                      "on_digit_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_digit_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 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" : "SimpleRunMenu"
                      }
                  }
              }
          ],
          "token" : "my run 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" : "SimpleRunMenu"
                      }
                  }
              }
          ],
          "token" : "my run 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" : "SimpleRunMenu"
                      }
                  }
              }
          ],
          "token" : "my run menu instance id",
          "api_version": "2.0"
      }
      
    • {
          [
          ],
          "token" : "Error for Action: xxxx  ActionIndex: xxxx  Result: xxxx"
      }
      
    • {
      }
      
    • Implementing this sample as an ASP.Net Web application:

      • // CSharp Wrapper 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.
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class SimpleRunMenu : 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("Press 1 for a weather report for Belgium. " + 
                                               "Press 2 for Venezuela. " + 
                                               "Press 3 for Outer Mongolia. " +
                                               "Or press 5 to listen to the options again.");
                List<MenuOption> menuOptions = new List<MenuOption>
                {
                    new MenuOption('1', new WebPageRequest("WeatherReport.aspx")),
                    new MenuOption('2', new WebPageRequest("WeatherReport.aspx")),
                    new MenuOption('3', new WebPageRequest("WeatherInOuterMongolia.aspx"))
                };
                RunMenu runMenuAction = new RunMenu(menuOptions, menuPrompt);
                runMenuAction.HelpDigit = '5';
        
                // Set up some new info messages for no entry and invalid entry
                runMenuAction.OnDigitTimeoutMessages = new List<Play>
                {
                    Play.SayText("I didn't catch your entry."),
                    Play.SayText("Please select a country."),
                    Play.PlayFile("oneMoreTime.wav")
                };
                runMenuAction.OnInvalidDigitMessages = new List<Play>
                {
                    Play.SayText("That wasn't one of the options. Please try again."),
                    Play.PlayFile("oneMoreTime.wav")
                };
        
                actions.Add(runMenuAction);
        
                // Respond
                String token = "my run 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 Core Web application:

      • // ASP.NET Core CSharp Wrapper 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.
        
        using System;
        using System.Net;
        using System.Collections.Generic;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        using System.Threading.Tasks;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            [Route("SimpleRunMenu")]
            public class SimpleRunMenuController : WeatherReportController
            {
                // Process the GET or POST request, set up the actions and construct the json response.
                [Route("FirstPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public async Task<IActionResult> SimpleRunMenu()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
        
                        // Setup the actions required
                        List<TelephonyAction> actions = new List<TelephonyAction>();
        
                        // Create the menu action
                        Play menuPrompt = Play.SayText("Press 1 for a weather report for Belgium. " +
                                                       "Press 2 for Venezuela. " +
                                                       "Press 3 for Outer Mongolia. " +
                                                       "Or press 5 to listen to the options again.");
                        List<MenuOption> menuOptions = new List<MenuOption>();
                        menuOptions.Add(new MenuOption('1', new WebPageRequest("SimpleRunMenu/WeatherReport")));
                        menuOptions.Add(new MenuOption('2', new WebPageRequest("SimpleRunMenu/WeatherReport")));
                        menuOptions.Add(new MenuOption('3', new WebPageRequest("SimpleRunMenu/WeatherInOuterMongolia")));
                        RunMenu runMenuAction = new RunMenu(menuOptions, menuPrompt)
                        {
                            HelpDigit = '5'
                        };
        
                        // Set up some new info messages for no entry and invalid entry
                        runMenuAction.OnDigitTimeoutMessages = new List<Play>()
                        {
                            Play.SayText("I didn't catch your entry."),
                            Play.SayText("Please select a country."),
                            Play.PlayFile("oneMoreTime.wav")
                        };
                        runMenuAction.OnInvalidDigitMessages = new List<Play>()
                        {
                            Play.SayText("That wasn't one of the options. Please try again."),
                            Play.PlayFile("oneMoreTime.wav")
                        };
                        actions.Add(runMenuAction);
        
                        // Create response
                        String token = "my run menu instance id";
                        TelephonyResponse ourResponse = new TelephonyResponse(actions, token);
                        return new OkObjectResult(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 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;
        using System.Threading.Tasks;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            [Route("SimpleRunMenu")]
            public class SimpleRunMenuController : WeatherReportController
            {
            }
        }
        
      • // ASP.NET Core CSharp Wrapper 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.
        
        using System;
        using System.Net;
        using System.Collections.Generic;
        using Microsoft.AspNetCore.Mvc;
        using Aculab.Cloud.RestAPIWrapper;
        using System.Threading.Tasks;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            [Route("SimpleRunMenu")]
            public class SimpleRunMenuController : WeatherReportController
            {
            }
        }
        
      • // 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;
        using System.Threading.Tasks;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            public class RESTSampleController : ControllerBase
            {
                // Process the GET or POST request for the Error condition
                [Route("ErrorPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public async Task<IActionResult> ErrorPage()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(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 new OkObjectResult(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;
        using System.Threading.Tasks;
        
        namespace Aculab.Cloud.RESTAPI.NETCoreCSharpSamples.Controllers
        {
            public class RESTSampleController : ControllerBase
            {
                // Process the GET or POST request for the Final Page
                [Route("FinalPage")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public async Task<IActionResult> FinalPage()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                        String token = telephonyRequest.InstanceInfo.Token;
        
                        // Create response
                        // Only very limited actions can be returned here
                        TelephonyResponse ourResponse = new TelephonyResponse(null, token);
                        return new OkObjectResult(ourResponse.ToJson(this));
                    }
                    catch (ArgumentException)
                    {
                        return BadRequest();
                    }
                    catch (Exception e)
                    {
                        return StatusCode((int)HttpStatusCode.InternalServerError, e.Message);
                    }
                }
            }
        }
        
  • Implemented as ASP.Net Web App:

    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' The first page for the Simple Run 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 SimpleRunMenu
          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("Press 1 for a weather report for Belgium. " + _
                                             "Press 2 for Venezuela. " + _
                                             "Press 3 for Outer Mongolia. " + _
                                             "Or press 5 to listen to the options again.")
              Dim menuOptions As List(Of MenuOption) = New List(Of MenuOption)
              menuOptions.Add(New MenuOption("1", New WebPageRequest("WeatherReport.aspx")))
              menuOptions.Add(New MenuOption("2", New WebPageRequest("WeatherReport.aspx")))
              menuOptions.Add(New MenuOption("3", New WebPageRequest("WeatherInOuterMongolia.aspx")))
              Dim runMenuAction As RunMenu = New RunMenu(menuOptions, menuPrompt)
              runMenuAction.HelpDigit = "5"
      
              ' Set up some new info messages for no entry and invalid entry
              runMenuAction.OnDigitTimeoutMessages = New List(Of Play)
              runMenuAction.OnDigitTimeoutMessages.Add(Play.SayText("I didn't catch your entry."))
              runMenuAction.OnDigitTimeoutMessages.Add(Play.SayText("Please select a country."))
              runMenuAction.OnDigitTimeoutMessages.Add(Play.PlayFile("oneMoreTime.wav"))
              runMenuAction.OnInvalidDigitMessages = New List(Of Play)
              runMenuAction.OnInvalidDigitMessages.Add(Play.SayText("That wasn't one of the options. Please try again."))
              runMenuAction.OnInvalidDigitMessages.Add(Play.PlayFile("oneMoreTime.wav"))
      
              actions.Add(runMenuAction)
      
              ' Respond
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, "my run menu instance id")
              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 SimpleRunMenu extends HttpServlet
      {
      	private static final long serialVersionUID = 265283615098267488L;
      
          @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("Press 1 for a weather report for Belgium. " + 
                                             "Press 2 for Venezuela. " + 
                                             "Press 3 for Outer Mongolia. " +
                                             "Or press 5 to listen to the options again.",
                                             "Paul");
              List<MenuOption> menuOptions = new ArrayList<MenuOption>();
              menuOptions.add(new MenuOption('1', new WebPageRequest("WeatherReport")));
              menuOptions.add(new MenuOption('2', new WebPageRequest("WeatherReport")));
              menuOptions.add(new MenuOption('3', new WebPageRequest("WeatherInOuterMongolia")));
              RunMenu runMenuAction = new RunMenu(menuPrompt, menuOptions);
              runMenuAction.setHelpDigit('5');
              
              // Set up some new info messages for no entry and invalid entry
              List<Play> onDigitTimeoutMessages = new ArrayList<Play>();
              onDigitTimeoutMessages.add(Play.sayText("I didn't catch your entry."));
              onDigitTimeoutMessages.add(Play.sayText("Please select a country."));
              onDigitTimeoutMessages.add(Play.playFile("oneMoreTime.wav"));
              runMenuAction.setOnDigitTimeoutMessages(onDigitTimeoutMessages);
              
              List<Play> onInvalidDigitMessages = new ArrayList<Play>();
              onInvalidDigitMessages.add(Play.sayText("That wasn't one of the options. Please try again."));
              onInvalidDigitMessages.add(Play.playFile("oneMoreTime.wav"));
              runMenuAction.setOnInvalidDigitMessages(onInvalidDigitMessages);
              
              actions.add(runMenuAction);
      
              // Respond
              TelephonyResponse ourResponse = new TelephonyResponse(actions, "my run 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('/SimpleRunMenu', methods=['GET','POST'])
      def handle_SimpleRunMenu():
      
          my_request = TelephonyRequest(request)
          app_inst_id = my_request.get_application_instance_id()
          print("SimpleRunMenu: app_inst_id='{}'".format(app_inst_id))
      
          # set up the dtmf responses
          menu_options = []
          menu_options.append(MenuOption('1', WebPage(url='WeatherReport')))
          menu_options.append(MenuOption('2', WebPage(url='WeatherReport')))
          menu_options.append(MenuOption('3', WebPage(url='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 = RunMenu(menu_options)
          # set up the menu
          play_action = Play(text_to_say = ("Press 1 for a weather report for Belgium. "
                                            "Press 2 for Venezuela. "
                                            "Press 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)
          
          # set on silence timeout and invalid digit messages
          my_menu.set_on_digit_timeout_messages(digit_timeout_messages)
          my_menu.set_on_invalid_digit_messages(invalid_digit_messages)
          
          list_of_actions = []
          list_of_actions.append(my_menu)
          my_response = TelephonyResponse(list_of_actions, token='my run 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/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
          
      
    • <?php
      header("Content-Type: application/json; charset=UTF-8");
      
      require __DIR__ . "/../../autoload.php";
      
      use \Aculab\TelephonyRestAPI\Response;
      use \Aculab\TelephonyRestAPI\Play;
      use \Aculab\TelephonyRestAPI\RunMenu;
      use \Aculab\TelephonyRestAPI\MessageList;
      use \Aculab\TelephonyRestAPI\WebPageRequest;
      
      $response = new Response();
      $response->setToken('my run menu instance id');
      
      // Create the menu action
      $menuPrompt = Play::sayText(
          "Press 1 for a weather report for Belgium. " .  
          "Press 2 for Venezuela. " . 
          "Press 3 for Outer Mongolia. " . 
          "Or press 5 to listen to the options again."
      );
      
      // Set up some new info messages for digit timeout and invalid digit
      $onDigitTimeoutMessages = new MessageList();
      $onDigitTimeoutMessages->addMessage(Play::sayText("I didn't catch your entry."))
          ->addMessage(Play::sayText("Please select a country."))
          ->addMessage(Play::playFile("oneMoreTime.wav"));
      
      $onInvalidDigitMessages = new MessageList();
      $onInvalidDigitMessages->addMessage(Play::sayText("That wasn't one of the options. Please try again."))
          ->addMessage(Play::playFile("oneMoreTime.wav"));
      
      $menu = new RunMenu();
      $menu->setPrompt($menuPrompt)
          ->addMenuOption('1', new WebPageRequest('WeatherReport.php', 'GET'))
          ->addMenuOption('2', 'WeatherReport.php', 'GET')
          ->addMenuOption('3', 'WeatherInOuterMongolia.php')
          ->setHelpDigit('5')
          ->setOnDigitTimeoutMessages($onDigitTimeoutMessages)
          ->setOnInvalidDigitMessages($onInvalidDigitMessages);
      
      $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_menu action
      $result = $info->getActionResult();
      $selection = $result->getSelectedDigit();
              
      // Set up the actions
      $actions = new Response();
      $playAction = new Play(); 
      if ($selection === '1') {
          $playAction->addText("The weather for Belgium is quite often good but sometimes is appalling.");
      } else {
          $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."
          );
      }
      $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;
      use \Aculab\TelephonyRestAPI\WebPageRequest;
      
      $info = InstanceInfo::getInstanceInfo();
      
      // Set up the actions
      $response = new Response();
      $response->setToken($info->getToken());
      
      $play = Play::sayText("The weather in Outer Mongolia is just right for Outer Mongolians.");
      $response->addAction($play);
      $response->addAction(new Redirect(new WebPageRequest("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);