Skip to content

Instantly share code, notes, and snippets.

@dsjoerg
Created December 8, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsjoerg/18628fcb5b93ead9d870 to your computer and use it in GitHub Desktop.
Save dsjoerg/18628fcb5b93ead9d870 to your computer and use it in GitHub Desktop.
conf_call.rb
#!/usr/bin/env ruby
# Usage conf.rb <number>
#
# Will call the number, repeatedly if necessary, and join them to a conference call when they join.
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'
# put your own credentials here
account_sid = 'foo'
auth_token = 'bar'
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
def confcall(num)
@client.account.calls.create({
:to => num,
:from => '+14153673283',
:url => 'http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CDial%3E%0A%3CConference%20waitUrl%3D%22http%3A%2F%2Ftwimlets.com%2Fholdmusic%3FBucket%3Dcom.twilio.music.electronica%22%20waitMethod%3D%22GET%22%3Ed41d8cd98f00b204e9800998ecf8427e%3C%2FConference%3E%0A%3C%2FDial%3E%0A%3C%2FResponse%3E&#38;',
:method => 'GET',
:fallback_method => 'GET',
:status_callback_method => 'GET',
:record => 'false'
})
end
# call the given number repeatedly until its not busy (or ringing)
def repeatocall(num)
status = 'busy'
while ['busy', 'ringing'].include?(status)
$stdout.puts("#{Time.now}: Calling #{num}")
call = confcall(num)
$stdout.puts("Call is #{call.uri}")
sleep(1)
# wait until call is no longer ringing
loop do
status = @client.get(call.uri.gsub('.json',''))['status']
$stdout.puts("#{Time.now}: Call is #{status}")
break if status != 'ringing'
end
# if call is busy, hang up
if status == 'busy'
$stdout.puts("#{Time.now}: Hanging up.")
call.cancel
end
end
$stdout.puts "#{Time.now}: OMG something interesting happened. Status is #{status}"
end
call = repeatocall ARGV[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment