Created
August 6, 2009 21:44
-
-
Save cloudvoxcode/163583 to your computer and use it in GitHub Desktop.
Place phone call with Perl
This file contains 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
#!/usr/bin/perl | |
# Cloudvox - place an outgoing call using Perl | |
# Place and receive phone calls via open API: http://cloudvox.com/ | |
# Learn about call scripting, Asterisk/AGI, voice apps: http://help.cloudvox.com/ | |
use Asterisk::Manager; | |
# Number to call (10 digits, no leading 1 or 9) | |
my $call = '12065551234'; | |
# Cloudvox outgoing settings. If you don't have these, create a free account | |
# and add an app at cloudvox.com. | |
my %cloudvox = ( | |
username => 'manager'; | |
password => 'MANAGER_PASSWORD'; # 's3kr3t' | |
server => 'ami.cloudvox.com'; | |
port => '5038'; | |
outgoing_context => 'OUTGOING_CONTEXT'; # 'outgoing-4242' | |
); | |
my %callparam = (); | |
# What should happen when the call is answered? | |
# Send it to an Asterisk script (AGI, like CGI) that can reside anywhere: | |
# $callparam{"Application"} = "AGI"; | |
# $callparam{"Data"} = "agi://my.computer.com/testapp_handler"; | |
# | |
# .. or to a specific single pre-made application (Swift text-to-speech): | |
$callparam{"Application"} = "Swift"; | |
$callparam{"Data"} = "I'm calling from Cloudvox to wish you a very happy birthday. This could say anything, interact with the caller, play sounds, MP3s, text-to-speech voices, connect them to another call, phone number, or SIP softphone, or start or join a conference bridge."; | |
# Call Options | |
# Caller ID as a Cloudvox number | |
$callparam{"CallerID"} = "2063576220"; | |
# Set variables that a script can access when the phone call is answered, such as | |
# a user or message ID, tracking code, or other state | |
$callparam{"Variable"} = "ExampleState=1234|other_example_flag=abcd"; | |
# Return immediately (true) or wait for Timeout after dialing | |
$callparam{"Async"} = true; | |
# If the call is Async, block for this long (milliseconds). | |
$callparam{"Timeout"} = 30000; | |
$|++; | |
my $astman = new Asterisk::Manager; | |
$astman->user($cloudvox{"username"}); | |
$astman->secret($cloudvox{"password"}); | |
$astman->host($cloudvox{"server"}); | |
$astman->port($cloudvox{"port"}); | |
$astman->connect || die $astman->error . "\n"; | |
# handle or ignore events | |
$astman->setcallback('Hangup', \&hangup_callback); | |
$astman->setcallback('DEFAULT', \&default_callback); | |
# format the number for dialing | |
# channel example: Local/2065551234@outgoing-42 | |
$callparam{"Channel"} = "Local/${call}@" . $cloudvox{'outgoing_context'}; | |
print $callparam{"Channel"}; | |
# place the call | |
$callparam{"Action"} = "Originate"; | |
print $callparam{"Action"}; | |
print STDERR $astman->sendcommand($callparam); | |
$astman->eventloop; | |
$astman->disconnect; | |
sub hangup_callback { | |
print STDERR "The recipient hung up\n"; | |
} | |
sub default_callback { | |
my (%new_event) = @_; | |
foreach (keys %new_event) { | |
print STDERR "$_: ". $new_event{$_} . "\n"; | |
} | |
print STDERR "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment