Skip to content

Instantly share code, notes, and snippets.

@samwize
Created October 22, 2012 09:04
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 samwize/3930503 to your computer and use it in GitHub Desktop.
Save samwize/3930503 to your computer and use it in GitHub Desktop.
Hoiio API Example: Conference Incoming
<?php
/* Instructions:
* In Hoiio Developer Portal under Hoiio Number section, configure the Forwarding URL to this script.
*/
/* Hoiio developer credentials */
$appId = "YOUR_APP_ID_HERE";
$accessToken = "YOUR_ACCESS_TOKEN_HERE";
/* Replace with YOUR SERVER ADDRESS here for incoming call notifications */
$myUrl = "http://YOUR_SERVER_ADDRESS_HERE/incoming-conf.php";
$transferBlockURL = "https://secure.hoiio.com/open/ivr/end/transfer";
if (!isset($_POST['call_state'])) {
return;
}
// incoming call, do transfer to conference room
if ($_POST['call_state'] == "ringing") {
transfer();
}
function transfer() {
$data = http_build_query(
array( "app_id" => $GLOBALS['appId'],
"access_token" => $GLOBALS['accessToken'],
"dest" => "room:HoiioConferenceRoom", // all incoming call go to same room
"session" => $_POST['session'],
"msg" => "Welcome to Hoiio Conference Room.",
"notify_url" => $GLOBALS['myUrl']));
$response = do_post_request($GLOBALS['transferBlockURL'], $data);
$result = json_decode($response);
}
// Source adapted from http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl
// This function will do the http post to the server, feel free to use different function of your desire
function do_post_request($url, $data) {
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment