Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hmsk
Created October 21, 2013 21:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmsk/7091673 to your computer and use it in GitHub Desktop.
Save hmsk/7091673 to your computer and use it in GitHub Desktop.
get '/' do
content_type 'text/xml'
Twilio::TwiML::Response.new do |r|
r.Play WELCOME_MESSAGE_FILE
r.Redirect '/record', method: 'get'
end.text
end
get '/record' do
content_type 'text/xml'
Twilio::TwiML::Response.new do |r|
r.Play INTRODUCTION_MESSAGE_FILE
r.Record maxLength: 60, action: '/recorded', method: 'post'
end.text
end
post '/recorded' do
begin
raise ArgumentError unless params[:RecordingSid]
rec = Record.create(
sid: params[:RecordingSid],
recording_url: params[:RecordingUrl],
from: params[:From],
note: 'Created'
)
redirect "/confirm/#{rec.sid}"
rescue Exception => e
redirect '/confirmed'
end
end
get '/confirm/:sid' do
content_type 'text/xml'
rec = Record.where(sid: params[:sid]).first
Twilio::TwiML::Response.new do |r|
r.Gather action: "/respond_to_confirm/#{rec.sid}", method: 'post', numDigits: 1, timeout: 10 do |g|
g.Play PLAY_RECORDED_MESSAGE_FILE
g.Play rec.recording_url
g.Play CONFIRMATION_MESSAGE_FILE
end
r.Redirect "/confirm/#{params[:sid]}", method: 'get'
end.text
end
post '/respond_to_confirm/:sid' do
rec = Record.where(sid: params[:sid]).first
case params[:Digits]
when '3','2'
rec.note = 'Rejected'
rec.save
redirect '/record'
when '1'
rec.note = 'Confirmed'
rec.save
redirect '/confirmed'
else
redirect "/confirm/#{rec.sid}"
end
end
get '/confirmed' do
content_type 'text/xml'
Twilio::TwiML::Response.new { |r| r.Play THANKS_MESSAGE_FILE }.text
end
get '/admin' do
# よしなに管理画面をつくった
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment