Twilio makes it easy to create automated phone menus. This HowTo shows you how to write a simple menu that a caller can navigate using the keypad on almost any phone.
A user calls and is greeted with a list of choices. For example, "For location, press 1". The user enters his/her choice on the telephone keypad, and the next list of choices or information is read. Rinse, repeat.
This HowTo demonstrates creating TwiML call logic, with focus on the <Gather> verb.
The phone menu system relies on the use of nested <Say> verbs inside a <Gather> verb. This setup allows the caller to make a menu selection before listening to all of the options. For more information, see Example 2 in the <Gather> documentation.
Each menu list has a name and a certain number of connections to other menu lists. These connections are represented via arrays. The key press associated with the menu item represents the index of the node name in the menu node array. For example, pressing 2 in the default node selects the location node. We can see that "location" has an index of 2 in the default array.
The TwiML for each node lives in a large switch statement.
Unless otherwise specified, each menu item ends in TwiML that redirects back to the main menu, ensuring that the user does not leave the menu unless he or she hangs up the phone.