Mixing Tropo's Voice and SMS


In this lab, you will learn to mix Tropo Voice and SMS capabilities in a single application. You'll build an application that will prompt a caller for a phone number, and send a SMS containing a randomly selected quote to the targeted phone.


This lab assumes you’re familiar with Tropo Voice and SMS features, or have gone through one of the introductory labs: “Create a Voice Machine” or “Outbound SMS Dialer”.

You’ll need a Tropo account that has been enabled for Outbound SMS to test the application.

  • If you’re attending a Cisco event, reach to your instructor to get activated.
  • If you’re running this lab offline, reach to Tropo support by email and ask for the procedure to activate your Tropo account.

Finally, you will need a mobile phone capable of placing a call and receiving SMS messages in order to test the Tropo functionality; alternatively you can use a softphone/service capable of receiving SMS messages, like Google Voice or Skype.

Step 1: Create a Voice application that asks for user Input

From your Tropo dashboard, log into your account and click Create New App.

Name your app 'Mixing Voice and SMS', select Scripting API under the Type of Application, and open the script editor by clicking the pencil icon titled New script.

Let's start with a welcome message that will be played when someone calls your application.

say("Thank you for calling the random message hotline");

Next, create a function that will choose a random message from a list:

function pickRandomQuote() {
    var quotes = [
        "Speech was given to man to disguise his thoughts.",
        "The adjective is the banana peel of the parts of speech."
    return quotes[Math.floor(Math.random() * quotes.length)];

Add code in order to ask the caller to enter its phone number (from 9 to 13 digits long) followed by the “#” key.

ask("Please enter your phone number followed by the pound sign", {
    choices: "[9-13 DIGITS]",
    terminator: "#",
    mode: "dtmf",
    onChoice: function(event) {
      var quote = pickRandomQuote();

      // Filled in step 2

Give the script a name and save your work. Do not close the window since we will need it in the next step.

Note: The filename should have a .js extension. This indicates to Tropo that it should use the JavaScript language interpreter to run the script.

Awesome! You have written the first section of the application which prompts a caller for a phone number. In the next step, we will add code to send a random quote to the target number.