Last active
August 29, 2015 13:56
-
-
Save ktoraskartwilio/23a573688fea202ecbbd to your computer and use it in GitHub Desktop.
Auto Dialer
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 'rubygems' | |
require 'twilio-ruby' | |
accountsid = "<Your AccountSid>" | |
authtoken = "<Your AuthToken>" | |
callerid = "<CallerId>" | |
#Hash of phone numbers to <Dial> out to | |
phonenumbers = { "1" => "+15555555555", | |
"2" => "+15555555555", | |
"3" => "+15555555555" } | |
dialcount = 0 | |
#This route begins the auto dialling process | |
#First leg of the call connects to Twilio Client | |
post '/auto-dial' do | |
#Set up a client to talk to the Twilio REST API | |
@client = Twilio::REST::Client.new accountsid, authtoken | |
@call = @client.account.calls.create( | |
:from => callerid, | |
:to => "<Agent Phone Number/ Client Name>", | |
:say => "Hello", | |
:url => "#{request.base_url}/call-customer" | |
) | |
end | |
#This route sequentially <Dial>'s out to the listed phone numbers | |
post '/call-customer' do | |
dialcount = params['callercount'] | |
dialcount = dialcount.to_i + 1 | |
#Extract the next phone number to <Dial> | |
dialphonenumber = phonenumbers[dialcount.to_s] | |
nextdialcount = dialcount.to_i | |
#TwiML response to <Dial> | |
response = Twilio::TwiML::Response.new do |r| | |
r.Say("Hello") | |
if !dialphonenumber.nil? | |
r.Dial :action => "#{request.base_url}/call-customer?callercount=#{nextdialcount}" do |d| | |
d.Number dialphonenumber | |
end | |
else | |
r.Say("No more calls to dial. Hanging up") | |
r.Hangup | |
end | |
end | |
response.text | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment