Collect Response


In the previous example you were able to identify the caller and greet them by name. Now lets take it to next level. Our caller has been greeted by name and is now prompted by the system to make a choice from provided options.

Example:-

Hello Bob!
Press 1 to speak with support
Press 2 to record your message

We start of by the code we wrote for “Identify caller by name”. We will add gather keyword to it. After greeting the caller, gather keyword is triggered and it prompts the caller to make a choice by pressing the assigned keys from their phone. In our example “1″ is to speak to Support and “2″ is to record the message. As soon as the user makes a choice by pressing either one of the keys we call:-

hello-world-handle-key.php

This files job is to handle and respond to the user input. We pass the key to post/get data with name “Digits” This will check what Digit the caller has pressed.

  • If the caller did not press either 1 or 2, then we redirect to the URL hello-world.php.
  • If they pressed 1, then we will forward the call to 19499300360 and disconnect the call.
  • If they pressed 2, then the Record API will ask them to record their Name and Message.
    • Once the recording if complete the Record API will call hello-world-handle-recording.php URL.
      This file will play back the message to the caller and hang up.

The example below will help you understand how we handle this in the code

If the caller had Pressed 2 then the code above call’s :

hello-world-handle-recording.php

The output of this code is to Play the recorded message to the caller and hangup.

By following these steps:-

  1. We have successfully greeted the caller by name.
  2. Prompted them to indicated their choice by pressing either 1 or 2.
  3. Based on their choice the call was either connected to support or they were prompted to record a message.
  4. Recorded message is played back to the caller and the call is completed.

Key words used in the above code are:

Say Reads the text and convert’s that to audio and play to the caller.
Dial Connect the existing call to another party
Gather
Collect the digits pressed by the caller
Play Play a mp3/wav audio file from the web server.
Record Caller is given the option to record the message