forked from labcoder/Twilio-Hackpack-for-Heroku-and-Sinatra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
49 lines (43 loc) · 1.36 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
require 'sinatra'
require 'twilio-ruby'
# A hack around multiple routes in Sinatra
def get_or_post(path, opts={}, &block)
get(path, opts, &block)
post(path, opts, &block)
end
# Home page and reference
get '/' do
@title = "Home"
erb :home
end
# Voice Request URL
get_or_post '/voice/?' do
response = Twilio::TwiML::Response.new do |r|
r.Say 'Congratulations! You\'ve successfully deployed ' \
'the Twilio HackPack for Heroku and Sinatra!', :voice => 'woman'
end
response.text
end
# SMS Request URL
get_or_post '/sms/?' do
response = Twilio::TwiML::Response.new do |r|
r.Sms 'Congratulations! You\'ve successfully deployed ' \
'the Twilio HackPack for Heroku and Sinatra!'
end
response.text
end
# Twilio Client URL
get_or_post '/client/?' do
TWILIO_ACCOUNT_SID = ENV['TWILIO_ACCOUNT_SID'] || TWILIO_ACCOUNT_SID
TWILIO_AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN'] || TWILIO_AUTH_TOKEN
TWILIO_APP_SID = ENV['TWILIO_APP_SID'] || TWILIO_APP_SID
if !(TWILIO_ACCOUNT_SID && TWILIO_AUTH_TOKEN && TWILIO_APP_SID)
return "Please run configure.rb before trying to do this!"
end
@title = "Twilio Client"
capability = Twilio::Util::Capability.new(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
capability.allow_client_outgoing(TWILIO_APP_SID)
capability.allow_client_incoming('twilioRubyHackpack')
@token = capability.generate
erb :client
end