Last active
December 25, 2015 21:49
-
-
Save bouzuya/7045058 to your computer and use it in GitHub Desktop.
2013/10/18 Twilio API 勉強会 in 大阪の PHP ハンズオンの Ruby 版。( イベント URL : http://atnd.org/event/E0020002 元ソース https://gist.github.com/shin1x1/7006593 ハッシュタグ #twilioapistudy )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'twilio-ruby' | |
get '/' do | |
<<-HTML | |
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>Twilio API</title> | |
<ul> | |
<li><a href="/sample">/sample</a></li> | |
<li><a href="/inbound">/inbound</a></li> | |
<li><a href="/outbound">/outbound</a></li> | |
</ul> | |
HTML | |
end | |
get '/sample' do | |
content_type 'text/xml' | |
Twilio::TwiML::Response.new {|r| r.Say 'Hello' }.text | |
end | |
get '/inbound' do | |
content_type 'text/xml' | |
Twilio::TwiML::Response.new {|r| r.Say 'こんにちは!', language: 'ja-jp' }.text | |
end | |
post '/inbound2' do | |
content_type 'text/xml' | |
Twilio::TwiML::Response.new {|r| | |
if params[:Digits] == '1' | |
r.Say '1を押しました。', language: 'ja-jp' | |
else | |
r.Say 'こんにちは!1を押して下さい。', language: 'ja-jp' | |
end | |
r.Gather numDigits: 1, timeout: 30 | |
}.text | |
end | |
get '/outbound' do | |
ACCOUNT_SID = ENV['TWILIO_ACCOUNT_SID'] | |
AUTH_TOKEN = ENV['TWILIO_AUTH_TOKEN'] | |
FROM_NUMBER = ENV['FROM_NUMBER'] | |
TO_NUMBER = ENV['TO_NUMBER'] | |
client = Twilio::REST::Client.new ACCOUNT_SID, AUTH_TOKEN | |
from = FROM_NUMBER | |
to = TO_NUMBER | |
url = 'http://demo.twilio.com/docs/voice.xml' | |
call = client.account.calls.create from: from, to: to, url: url | |
call.sid | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment