This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.rb
57 lines (48 loc) · 1.61 KB
/
app.rb
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
require 'rubygems'
require 'sinatra'
require 'twilio-ruby'
# Load configuration from system environment variables - see the README for more
# on these variables.
TWILIO_ACCOUNT_SID = ENV['TWILIO_ACCOUNT_SID']
TWILIO_AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN']
TWILIO_NUMBER = ENV['TWILIO_NUMBER']
# Create an authenticated client to call Twilio's REST API
client = Twilio::REST::Client.new TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN
# Sinatra route for your app's home page at "http://localhost:4567/" or your
# public web server
get '/' do
erb :index
end
# Handle a form POST to send a message
post '/message' do
# Use the REST API client to send a text message
client.account.sms.messages.create(
:from => TWILIO_NUMBER,
:to => params[:to],
:body => 'Good luck on your Twilio quest!'
)
# Send back a message indicating the text is inbound
'Message on the way!'
end
# Handle a form POST to make a call
post '/call' do
# Use the REST API client to make an outbound call
client.account.calls.create(
:from => TWILIO_NUMBER,
:to => params[:to],
:url => 'http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3'
)
# Send back a text string with just a "hooray" message
'Call is inbound!'
end
# Render a TwiML document that will say a message back to the user
get '/hello' do
# Build a TwiML response
response = Twilio::TwiML::Response.new do |r|
r.Say 'Hello there! You have successfully configured a web hook.'
r.Say 'Good luck on your Twilio quest!', :voice => 'woman'
end
# Render an XML (TwiML) document
content_type 'text/xml'
response.text
end