right  Talk To Us!

simple get input Sample

A simple application to use the get input action to obtain speech or keypresses from an answered inbound or outbound call.

The application prompts the caller to say a four digit number. It then waits for 20 seconds for the caller to say four digits or to enter four digits on the telephone keypad. Once four digits have been recognised (either speech or keypresses) they are sent to a page that reads them back to the caller.

Uses actions: Get Input, Play

    • {
          "actions" :
          [
              {
                  "get_input":
                  {
                      "prompt" :
                      {
                          "play" :
                          {
                              "play_list" :
                              [
                                  {
                                      "text_to_say" : "Please say anything you want or enter a number of digits."
                                  }
                              ]
                          }
                      },
                      "next_page" :
                      {
                          "url" : "ReadInput"
                      },
                      "seconds_timeout" : 20,
                      "digit_input_options" : {
                          "digit_count" : 4
                      }
                  }
              }
          ],
          "token" : "my get input instance id",
          "api_version": "2.0"
      }
      
    • {
          "actions" :
          [
              {
                  "play" :
                  {
                      "play_list" :
                      [
                          {
                              "text_to_say" : "You said four two six nine."
                          }
                      ]
                  }
              }
          ],
          "token" : "my get input 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 Get Input:
        // A simple application to use the get input action to obtain a four-digit number from an answered inbound call. 
        // The digits can be any of 0-9 and either spoken or via keypresses. Valid input
        // is sent to the next page that reads the input back to the caller.
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class SimpleGetInput : 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 get input action
                // Specify a prompt and next page otherwise use all the defaults
                Play prompt = Play.SayText("Please say anything you want or " +
                                           "enter a number of digits.");
                WebPageRequest nextPage = new WebPageRequest("ReadInput.aspx");
                GetInput getInputAction = new GetInput(nextPage, prompt)
                {
                    SecondsTimeout = 20,
                    DigitInputOptions = new DigitInputOptions(4)
                };
                actions.Add(getInputAction);
        
                // Respond
                TelephonyResponse ourResponse = new TelephonyResponse(actions, "my get input instance id");
                ourResponse.ToHttpResponse(Response);
            }
        }
        
        
      • // CSharp Wrapper sample for the Aculab Telephony REST API.
        //
        // Simple Get Input:
        // ReadInput page
        
        using System;
        using System.Collections.Generic;
        using Aculab.Cloud.RestAPIWrapper;
        
        public partial class ReadInput : 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 get input action
                GetInputResult result = (GetInputResult)ourRequest.InstanceInfo.ActionResult;
                String input = result.InputType;
        
                // Setup the actions
                List<TelephonyAction> actions = new List<TelephonyAction>();
        
                // Create the play action
                Play playInput = new Play();
                if (result.InputType.Equals("speech"))
                {
                    playInput = Play.SayText("You said");
                    foreach (Phrase phrase in result.SpeechInput)
                    {
                        playInput.AddText(phrase.Alternatives[0].Text);
                    }
                }
                else
                {
                    playInput = Play.SayText(String.Format(
                        "You entered the digits <say-as interpret-as='characters'>{0}</say-as>.", input));
                }
                actions.Add(playInput);
        
                // 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 Get Input:
        // A simple application to use the get input action to obtain a four-digit number from an answered inbound call. 
        // The digits can be any of 0-9 and either spoken or via keypresses. Valid input
        // is sent to the next page that reads the input back to the caller.
        
        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("SimpleGetInput")]
            public class SimpleGetInputController : ControllerBase
            {
                // 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> SimpleGetInput()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
        
                        // Setup the actions required
                        List<TelephonyAction> actions = new List<TelephonyAction>();
        
                        // Create the get input action
                        // Specify a prompt and next page otherwise use all the defaults
                        var prompt = Play.SayText("Please say anything you want or " +
                                                   "enter a number of digits.");
                        var nextPage = new WebPageRequest("SimpleGetInput/ReadInput");
                        GetInput getInputAction = new GetInput(nextPage, prompt)
                        {
                            SecondsTimeout = 20,
                            DigitInputOptions = new DigitInputOptions(4)
                        };
                        actions.Add(getInputAction);
        
                        // Create response
                        TelephonyResponse ourResponse = new TelephonyResponse(actions, "my get input instance id");
                        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 Get Input:
        // A simple application to use the get input action to obtain a four-digit number from an answered inbound call. 
        // The digits can be any of 0-9 and either spoken or via keypresses. Valid input
        // is sent to the next page that reads the input back to the caller.
        
        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("SimpleGetInput")]
            public class SimpleGetInputController : ControllerBase
            {
                // Process the GET or POST request, set up the actions and construct the json response.
                [Route("ReadInput")]
                [HttpGet]
                [HttpPost]
                [ProducesResponseType(200)]
                [ProducesResponseType(400)]
                [ProducesResponseType(500)]
                public async Task<IActionResult> ReadInput()
                {
                    try
                    {
                        // Unpack the request
                        var telephonyRequest = await TelephonyRequest.UnpackRequestAsync(Request);
                        String token = telephonyRequest.InstanceInfo.Token;
        
                        // Get the result of the get input action
                        GetInputResult result = (GetInputResult)telephonyRequest.InstanceInfo.ActionResult;
        
                        // Setup the actions required
                        List<TelephonyAction> actions = new List<TelephonyAction>();
                        // Create the play action
                        Play playInput = new Play();
                        if (result.InputType.Equals("speech"))
                        {
                            foreach (var phrase in result.SpeechInput)
                            {
                                playInput.AddText(String.Format(
                                    "You said {0}.", phrase.Alternatives[0].Text));
                            }
                        }
                        else
                        {
                            playInput.AddText(String.Format(
                                "You entered the digits <say-as interpret-as='characters'>{0}</say-as>.", result.DigitsInput));
                        }
                        actions.Add(playInput);
        
                        // Create response
                        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.
        
        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 Get Number sample:
      ' A simple application to use the get_number action to obtain a number from an answered inbound call. 
      ' A 5 digit number is required containing only digits 1-6. The help digit is set to 7. A valid entry 
      ' is sent to the final page that reads the entered number back to the caller.
      Imports System.Collections.Generic
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class SimpleGetNumber
          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 get number action
              Dim prompt As Play = Play.SayText("Enter your 5 digit number using digits 1 to 6. " + _
                                         "Press 7 to listen to this message again.")
              Dim getNumberAction As GetNumber = New GetNumber(New WebPageRequest("ReadEnteredDigits.aspx"), prompt)
              getNumberAction.DigitCount = 5
              getNumberAction.HelpDigit = "7"
              getNumberAction.ValidDigits = "123456"
      
              actions.Add(getNumberAction)
      
              ' Respond
              Dim ourResponse As TelephonyResponse = New TelephonyResponse(actions, "my get number instance id")
              ourResponse.ToHttpResponse(Response)
          End Sub
      End Class
      
      
    • ' Visual Basic Wrapper sample for the Aculab Telephony REST API.
      '
      ' Simple Get Input:
      ' ReadInput page
      Imports System.Collections.Generic
      Imports Aculab.Cloud.RestAPIWrapper
      
      Partial Class ReadInput
          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 get_input action
              Dim result As GetInputResult = ourRequest.InstanceInfo.ActionResult
              Dim input As String = result.InputType
      
              ' Setup the actions
              Dim actions As List(Of TelephonyAction) = New List(Of TelephonyAction)
      
              ' Create the play action
              Dim playInput As Play
              If result.InputType.Equals("speech") Then
                  playInput = Play.SayText("You said")
                  For Each phrase As Phrase In result.SpeechInput
                      playInput.AddText(phrase.Alternatives(0).Text)
                  Next
              Else
                  playInput = Play.SayText(String.Format(
                      "You entered the digits <say-as interpret-as='characters'>{0}</say-as>.", input))
              End If
      
              actions.Add(playInput)
      
              ' 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 Get Number:
      // A simple application to use the get_number action to obtain a number from an answered inbound call. 
      // A 5 digit number is required containing only digits 1-6. The help digit is set to 7. A valid entry 
      // is sent to the final page that reads the entered number back to the caller.
      
      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 SimpleGetInput extends HttpServlet
      {
      	private static final long serialVersionUID = 434710728081646283L;
      
      	@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 prompt object
          Play prompt = Play.sayText("Please say anything you want or enter a number of digits."); 
      
          GetInput getInputAction = new GetInput(new WebPageRequest("ReadInput"));
          
          getInputAction.setPrompt(prompt);
          
          actions.add(getInputAction);
          
          // Respond
          TelephonyResponse ourResponse = new TelephonyResponse(actions, "my get input instance id");
          ourResponse.setHttpServletResponse(response);
          }
      }
      
      
      
      
      
      
    • 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 ReadInput extends HttpServlet
      {
      	private static final long serialVersionUID = -6948346570255777073L;
      
      	@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 get input action
              GetInputResult result = (GetInputResult)ourRequest.getInstanceInfo().getActionResult();
                             
              String inputType = result.getInputType();
      
              // Set up the actions
              List<TelephonyAction> actions = new ArrayList<TelephonyAction>();
      
              // Create the play action
              Play playInput;
              if (inputType.equals("speech"))
              {
                  // Get the array of Phrase objects
                  List<Phrase> phrase_list = result.getSpeechInput();
                  
                  // Get the array of Speech objects
                  List<Speech> speech_list = phrase_list.get(0).getAlternatives();
                  
                  // Get the Speech object that we are most confident in
                  Speech alternative = speech_list.get(0);
      
                  playInput = Play.sayText(String.format("You said %s.", alternative.getText()));
              }
              else //digits
              {
                  playInput = Play.sayText(String.format(
                      "You entered the digits <say-as interpret-as='characters'>%s</say-as>.", result.getDigitsInput()));
              }
              actions.add(playInput);
      
              // 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('/SimpleGetInput', methods=['GET','POST'])
      def handle_SimpleGetInput():
      
          my_request = TelephonyRequest(request)
          print("SimpleGetInput: app_inst_id='{}'".format(my_request.get_application_instance_id()))
      
          my_number = GetInput(WebPage(url='ReadInput'))
          play_action = Play(text_to_say=('Please say anything you want or enter a number of digits.'))
          my_number.set_prompt(play_action)
      
          list_of_actions = []
          list_of_actions.append(my_number)
          my_response = TelephonyResponse(list_of_actions, 'my get input instance id')
          return my_response.get_json()
      
      
    • @app.route('/ReadInput', methods=['GET','POST'])
      def handle_ReadInput():
      
          my_request = TelephonyRequest(request)
          my_token = my_request.get_token()
          action_result = my_request.get_action_result()
          
          input_type = action_result.get('result').get('input_type')
          
          list_of_actions = []
          digits = ""
          if input_type == "digits":
              digits = action_result.get('result').get('digits_input')
              list_of_actions.append(Play(text_to_say="You entered, <say-as interpret-as='characters'>{0}</say-as>".format(digits)))
          else:
              phrases = action_result.get('result').get('speech_input')
      
              # Repeat the first phrase back to the caller
              phrase = phrases[0]
              alternatives = phrase.get("alternatives")
              speech = alternatives[0]
      
              list_of_actions.append(Play(text_to_say="You said, {}".format(speech.get("text"))))
      
          print("Digits entered: {0}".format(digits))
      
          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\GetInput;
      use \Aculab\TelephonyRestAPI\DigitInputOptions;
      use \Aculab\TelephonyRestAPI\WebPageRequest;
      use \Aculab\TelephonyRestAPI\SpeechRecognitionOptions;
      
      $response = new Response();
      $response->setToken('my get input instance id');
      
      // Create the get input action
      $prompt = Play::sayText("Please say anything you want or enter a number of digits."
      );
      
      $sro = new SpeechRecognitionOptions();
      $sro->setLanguage('en-US')
          ->setEnableProfanityFiltering(true);
      
      $getInputAction = new GetInput(new WebPageRequest("ReadInput.php"));
      
      $getInputAction->setPrompt($prompt)
          ->setSpeechRecognitionOptions($sro)
          ->setSecondsTimeout(20)
          ->setDigitInputOptions( (new DigitInputOptions())->setDigitCount(4) );
      
      $response->addAction($getInputAction);
      
      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;
      
      $info = InstanceInfo::getInstanceInfo();
      
      $response = new Response();
      $response->setToken($info->getToken());
      // Get the result of the get_input action
      $result = $info->getActionResult();
      $inputType = $result->getInputType();
      
      // Create the play action
      if ($inputType === 'speech') {
          $input = array();
          foreach($result->getSpeechInput() as $phrase) {
              $alt = $phrase->getAlternatives();
              $speech = array_shift($alt);
              if (!is_null($speech)) {
                  $input[] = $speech->getText();
              }
          }
          $playInput = Play::sayText("You said, " . implode(' . ', $input)); 
      } else {
          $playInput = Play::sayText("You entered the digits <say-as interpret-as='digits'>" . $result->getDigitsInput() . "</say-as>."); 
      }
      $response->addAction($playInput);
      
      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);