Skip to main content

Ruby: Phone Trees

I just finished building my first, fully-functional, non-trivial phone tree. This is exciting because it only took me two days. It has a bunch of submenus, it records and plays back content from the user, and it's even pretty friendly about confirmations.

I built it using Ruby on Rails and Twilio which is where I just started working. Building a telephone app using web technologies is very comfortable.

What's most amazing is that I used behavioral driven development using Cucumber in order to develop the app. In fact, I didn't even call my app until I had finished building it. It was mostly correct the first time I called it. Using Cucumber to walk through all the user-flows in the phone tree was a big win!

Note, I didn't use one assertion per test as I warned against here, but rather wrote very full integration tests that walked around the phone tree quite a bit. Here's an example test that actually interacts with the phone tree:
Scenario: delete a friend, but cancel
Given I already have 5 friends
When I enter "delete_friend" on the edit friend menu for the friend at position 3
Then I should get a valid TwiML response
And it should say "You are about to delete"
And it should play "name_3"

When I follow the redirect
Then I should get a valid TwiML response
And it should say "If this is correct"
And it should say "If this is incorrect"

When I enter "incorrect"
Then I should get a valid TwiML response
And it should say "The delete has been canceled."

When I follow the redirect
Then I should get a valid TwiML response
And it should say "Main menu."
Unfortunately, I can't share the entire source code for this application yet or the phone number since this is a commercial application I'm building for a customer. However, as soon as I finish my pet project that I'm building on the side, I'll post its phone number and its source code. I'm anxious to share a bunch of tricks that I came up with for making it easier to develop phone trees using Ruby on Rails and Cucumber.

Comments