Typically you will find that your applications have two types of users, the regular user and the casual user.  The difference are based on experience, some users know how to interact with the application because they are regular users, others needs some instructions.  This is especially evident in a Text channel application, such as Instant Message or SMS., whereas the regular user may message with the expected value right away, for example providing a zip code, or the answer to the expected question, before you actually asked the question:

In this scenario we can save ourselves, and the user, the trouble of sending them instructions, they dont need it. However the uneducated user may send a “hi, or hello, or any number of initial responses to your application, and you will need to guard handle each type of user appropriately in your application.

Doing so is pretty simple, you just need to use the $currentCall object’s initalText parameter, and check the value to see if it’s what your looking for. I have fashioned a quick example below that may help get you started!

fruit_list = "apples, oranges, pears"

log "@"*10   " "   $currentCall.initialText

    if fruit_list.include?($currentCall.initialText)
        result = ask "What's your favorite fruit? apples, oranges, or pears?", {:choices => fruit_list}
    else
        ask "",{:choices=>'[ANY]'}
        say "Hello and welcome to the fruit guessing game"
        result = ask "What's your favorite fruit? apples, oranges, or pears?", {:choices => fruit_list}
    end
        say "I like #{result.value} to"
        say "see ya later!"

All we do here is check the value in initialText to determine if we need to handle the initial text value as an acceptable utterance against our choice / grammar. Maybe we jsut check if its numeric for a zipcode? You could get as complicated, or as simple as you want here, the choice is really entirly up to you. I do hope this helps!

-John

Originally from Voxeo Blogs