Tropo and the Holidays

January 5, 2017

My son has gotten to the age where he doesn’t know that he wants for Christmas and is resorting to just asking for money (he’s saving up for a new computer).  I’ve never really liked just giving money to the kids, but I wanted to give some money to go towards that new computer, so instead of just giving it to him I created a scavenger hunt.  And because we are both nerds, I had to integrate some technology into the scavenger hunt, so for two of the legs of the hunt I wrote a couple of simple Tropo scripts that both he and his brother could interact with through SMS and voice calling.  I thought I would do a simple write-up just to kind of show you what you could do with a very short development time to write an application that could be more business relevant than your kids’ scavenger hunt.

What the Script Does

As I said before, I wanted to integrate this into two points of the hunt.  The first clue that they found related to Tropo just had a phone number on it.  My guess was that, despite being in the text messaging generation, they would probably call the number first (I was right).  When they call the number the script should play a message like “Who calls people anymore, maybe text me hello instead?”

When they text hello to the number, it will respond with a riddle.  If they answer the riddle correctly it will send a text with the next clue (someplace in the house that the next clue is found).

Lastly, for the final clue, they will be told to call into the number and listen to the messaging about people not calling anymore and they will then need to say a phrase.  After saying the correct phrase, the script will send them a text message that has the final instructions (for my purposes, I wanted them to say some embarrassing phrase to a room full of their relatives).

That’s it!  For the explanation of how it worked, I will break out the scripts into voice (where the interaction is started by placing a voice call) and SMS (where the interaction is started by sending an SMS)

Keep in mind, that in order to do this, you will need to create a free account on tropo.com and then you will need to create a new application and assign a number to it.  (You will also need to request SMS access if you don’t have it already).

Voice

For this portion of the script we need to start with prompting the caller and give them a clue to send in a text message.  As you can see below, telling Tropo to play that message is as simple as putting in a single command:

result = ask("Who calls phone numbers anymore?  Maybe
text me hello instead?", { "choices":"I fart rainbows,
I love to dab"})

If we didn’t need to wait for input in the second part of the hunt, we could change “ask” to “say” and remove the choices section.  For the first portion of the hunt, that’s all that is needed.  From here they would send a text in and it would be taken from there.  The rest of the script is for the final part of the hunt.

Next, we check if they said one of the choices with a simple if statement:

if result.value == "I fart rainbows":

If they say that, the system will say (say command) a response message to them over the phone and send them a text message (message command) with the final instructions (phone number changed to protect the innocent):

 say("I know you fart rainbows, but it doesn't help 
  with the smell")
 message("Go into the room where dad is and say: 
  Attention please! Attention please! I fart 
  rainbows!", {
 "to":"+15125550000",
 "network":"SMS"})

And finally, if the appropriate phrase is not mentioned, just hang up:

 else:
 hangup()

And generally speaking, that gets the voice piece working.

SMS

The SMS logic is pretty straightforward and is just a series of if statements that look for certain text in the message.  If it doesn’t see anything that it is looking for then there is no response.  Both of my kids’ stuff is in there, but all of the appropriate information is gathered under “Joe” and “Sammy”.

if currentCall.initialText == "Hello" :
    say("Oh hello, is this Joe or Sammy?")
if currentCall.initialText == "Sammy" :
    say("What can you hold in your left hand that 
    you can't hold in your right hand?")
if currentCall.initialText == "Right hand" or 
currentCall.initialText == "Your right hand" :
    say("Good job, your next clue is: I need you 
    to scan something for me")
if currentCall.initialText == "Joe" :
    say("A boat has a ladder with six rungs, each 
    one foot apart. The bottom rung is one foot 
    from the water. The tide rises at 12 inches 
    every 15 minutes. High tide peaks in one hour. 
    When the tide is at it's highest how many rungs 
    are in the water?")
if currentCall.initialText == "0" or 
currentCall.initialText == "None" :
    say("Thats right. Your next clue is: Jupiter's 
    most wide")

Each if currentCall.initialText just compares what was sent in the initial text to a string.  If it matches, then it replies (still via SMS) to the person with the response that is right under the if statement.

That’s my simple script.  It was done in 30 minutes or less.  Had I more time, I would have done some identity checking via their cell number.  But just for two people to use in a simple fashion this did the trick.

No Comments

Comments are closed.