Created
August 6, 2009 21:48
-
-
Save cloudvoxcode/163588 to your computer and use it in GitHub Desktop.
Place phone call with PHP
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/php -q | |
<?php | |
# Cloudvox - place an outgoing call using PHP | |
# Place and receive phone calls via open API: http://cloudvox.com/ | |
# Learn about call scripting, Asterisk/AGI, voice apps: http://help.cloudvox.com/ | |
require_once('/path/to/phpagi-asmanager.php'); | |
# Number to call (10 digits, no leading 1 or 9) | |
$call = "2065554141"; | |
# Cloudvox outgoing settings. If these aren't defined, create a free account | |
# and add an app at cloudvox.com. | |
$cloudvox["username"] = 'manager'; | |
$cloudvox["password"] = 'MANAGER_PASSWORD'; | |
$cloudvox["server"] = 'ami.cloudvox.com:5038'; | |
$cloudvox["outgoing_context"] = 'OUTGOING_CONTEXT'; | |
# What should happen when the recipient picks up the phone? | |
# Send it to an Asterisk script (AGI, like CGI) that can reside anywhere: | |
#$callparam["Application"] = "AGI"; | |
#$callparam["Data"] = "agi://my.computer.com/"; | |
# | |
# .. 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 below | |
$callparam["Async"] = true; | |
# If the call is Async, block for this long (milliseconds). | |
$callparam["Timeout"] = 30000; | |
$asm = new AGI_AsteriskManager(); | |
if ($asm->connect($cloudvox["server"], $cloudvox["username"], $cloudvox["password"])) { | |
# format the number for dialing | |
# example: Local/2065551234@outgoing-42 | |
$callparam["Channel"] = "Local/${call}@${cloudvox['outgoing_context']}"; | |
# Let's do this thing. Place the call. | |
$res = $asm->send_request ("Originate", $callparam); | |
# Print each message received when the outgoing call was queued or made. | |
foreach ($res as $r) { | |
if ($r == "Success") { | |
echo "Sucessfully originated call: $r\n"; | |
} else { | |
echo "Event: $r\n"; | |
} | |
} | |
$asm->disconnect(); | |
} else { | |
echo 'Could not connect to Cloudvox server.'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0534203863