Skip to content

Instantly share code, notes, and snippets.

@sanandnarayan
Created April 9, 2012 08:08
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 sanandnarayan/2342250 to your computer and use it in GitHub Desktop.
Save sanandnarayan/2342250 to your computer and use it in GitHub Desktop.
Plivo ruby make a call
require './plivohelper.rb'
#URL of the Plivo REST service
REST_API_URL = 'https://api.plivo.com/v1/'
# Sid and AuthToken
SID = 'MAJKMWIXMDQXZDCZNMEZ'
AUTH_TOKEN = 'YTNlNWI0MzZhNWQ0OGJlNmVkOTExZDgxYjIyMTU4'
#Define Channel Variable - http://wiki.freeswitch.org/wiki/Channel_Variables
extra_dial_string = "bridge_early_media=true,hangup_after_bridge=true"
# Create a REST object
plivo = Plivo::Rest.new(REST_API_URL, SID, AUTH_TOKEN)
# Initiate a new outbound call to user/1000 using a HTTP POST
call_params = {
'From'=> '919191919191', # Caller Id
'To' => '919686928486', # User Number to Call
'Gateways' => "user/", # Gateway string to try dialing our separated by comma. First in list will be tried first
'GatewayCodecs' => "'PCMA,PCMU'", # Codec string as needed by FS for each gateway separated by comma
'GatewayTimeouts' => "60", # Seconds to timeout in string for each gateway separated by comma
'GatewayRetries' => "1", # Retry String for Gateways separated by comma, on how many times each gateway should be retried
'ExtraDialString' => extra_dial_string,
'AnswerUrl' => "http://quickburp.com/phone/answered/192.xml"
}
request_uuid = ""
#Perform the Call on the Rest API
begin
result = plivo.call(call_params).body
rescue Exception=>e
print e
end
print result
if false
sleep(10)
# Hangup a call using a HTTP POST
hangup_call_params = {
'RequestUUID' => request_uuid.strip(), # Request UUID to hangup call
}
#Perform the Call on the Rest API
begin
print plivo.hangup_call(hangup_call_params)
rescue Exception=>e
print e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment