-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.jade
169 lines (125 loc) · 6.53 KB
/
index.jade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
.chapter(data-title='IVR Phone Tree')
.step(data-file='config/routes.rb')
:markdown
## About This Application
![Extra Terrestrial Phone Home
Service](//howtodocs.s3.amazonaws.com/logo-et-phone2.png)
This [Ruby on Rails](http://rubyonrails.org/) sample application is
modeled after a typical call center experience but with more [Reese's
Pieces](//en.wikipedia.org/wiki/Reese%27s_Pieces#ET:_The_Extra-
Terrestrial).
Stranded aliens can call a phone number and receive instructions on how
to get out of earth safely or, call their home planet
directly[.](//bit.ly/asogi) On this tutorial we'll show you the
key bits of code to make this work.
To run this sample app yourself, [download the code and follow the
instructions on GitHub](//github.com/TwilioDevEd/ivr-phone-tree-
rails).
Let's get started! Click the right arrow above to move to the next step
of the tutorial.
---
**See Also:**
* [Getting Started with Ruby on Rails](//guides.rubyonrails.org/getting_started.html)
* [Getting Started with the Twilio Ruby Gem](//twilio-ruby.readthedocs.org/en/latest/index.html#getting-started)
.step(data-file='config/routes.rb')
:markdown
## Answering a Phone Call
To initiate the phone tree, we need to configure one of our Twilio
numbers to send our web application an HTTP request when we
get an incoming call.
[Click on one of your numbers](//www.twilio.com/user/account/phone-numbers/incoming)
and configure the Voice URL to point to our app. In our code the route
will be `/ivr/welcome`.
![Configuring a Twilio Number](//s3.amazonaws.com/howtodocs/number-
config.png)
---
**See Also:**
* [Configuring Twilio Numbers for Voice](//www.twilio.com/help/faq/voice/how-do-i-assign-my-twilio-number-to-my-voice-application)
* [Rails Routing Guide](//guides.rubyonrails.org/routing.html)
* [Using Ngrok to Test Your Twilio Webhooks Locally](//www.twilio.com/blog/2013/10/test-your-webhooks-locally-with-ngrok.html)
.step(
data-file='app/controllers/twilio_controller.rb',
data-highlight='6-15')
:markdown
## Responding to the Twilio Request with TwiML
Our Twilio number is now configured to [send HTTP
requests](//www.twilio.com/docs/api/twiml/twilio_request) to this
controller method on any incoming voice calls. Our app responds with
[TwiML](//www.twilio.com/docs/api/twiml) to tell Twilio what to do
in response to the message.
In this case we tell Twilio to
[`Gather`](//www.twilio.com/docs/api/twiml/gather) the input from
the caller and we [`Play`](//www.twilio.com/docs/api/twiml/play) a
welcome message.
---
**See Also:**
* [Gather Attributes](//www.twilio.com/docs/api/twiml/gather#attributes)
* [Play 'loop' Attribute](//www.twilio.com/docs/api/twiml/play#attributes-loop)
.step(
data-file='app/controllers/twilio_controller.rb',
data-highlight='9')
:markdown
## Where to Send the Caller's Input
The *gather's* `action` parameter takes an absolute or relative URL as a
value - in our case, the `menu` route.
When the caller has finished entering digits Twilio will make a
GET or POST request to this URL including a
[`Digits`](//www.twilio.com/docs/api/twiml/gather#attributes-
action-parameters) parameter with the number our caller chose.
After making this request, Twilio will continue the current call using
the TwiML received in your response. Any TwiML verbs occurring after a
`<Gather>` are unreachable, unless the caller doesn't enter digits.
---
**See Also:**
* [Twilio Request parameters](//www.twilio.com/docs/api/twiml/twilio_request#synchronous-request-parameters)
.step(
data-file='app/controllers/twilio_controller.rb',
data-highlight='17-33, 68-83')
:markdown
## The Main Menu: Processing the Caller's Selection
If our caller chooses '1' for directions, we use a helper method defined
below, `twiml_say`, to respond with TwiML that will
[`Say`](//www.twilio.com/docs/api/twiml/say) directions to our
caller's extraction point.
If the caller chooses '2' to call her home planet, then we need to
gather more input from him/her. We'll cover this in the next step.
If the caller enters anything else we respond with a TwiML
[`Redirect`](//www.twilio.com/docs/api/twiml/redirect) to the main
menu.
---
**See Also:**
* [Ruby Switch Statment](//www.codecademy.com/glossary/ruby/switch-statement)
* [The TwiML Hangup Verb](//www.twilio.com/docs/api/twiml/hangup)
* [TwiMl Say: Language Options](//www.twilio.com/docs/api/twiml/say#attributes-alice)
.step(
data-file='app/controllers/twilio_controller.rb',
data-highlight='35-66, 85-91')
:markdown
## The Planet Directory: Collecting More Input from the Caller
If our caller chooses to call her home planet we will tell her the planet
directory. This is similar to a typical "company directory" feature of
most IVRs.
In our TwiML response we use a `Gather` verb again to receive our caller's
input. The `action` verb points this time to the `planets` route, which
will switch our response based on what the caller chooses.
The TwiML response we return for that route uses a
[`Dial`](https://www.twilio.com/docs/api/twiml/dial) verb with the
appropriate phone number to connect our caller to her home planet. We set those
numbers using environment variables.
.step
:markdown
## Where to Next?
That's it! We've just implemented an IVR phone tree that will delight
and serve your customers.
If you're a Ruby developer working with Twilio, you might enjoy these
other tutorials:
[**Automated Survey**](//www.twilio.com/docs/howto/walkthrough/automated-survey/ruby/rails)
Instantly collect structured data from your users with a survey
conducted over a voice call or SMS text messages.
[**Click-to-call**](//www.twilio.com/docs/howto/walkthrough/click-to-call/ruby/rails)
Click-to-call enables your company to convert web traffic into phone calls
with the click of a button.
### Did this help?
Thanks for checking out this tutorial! If you have any feedback to share with
us, we'd love to hear it. [Contact the Twilio Developer Education
Team](mailto:deved-oss@twilio.com) to let us know what you think.