Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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