Hoiio Open API

This example shows you how to make use of ivr/transfer to connect incoming calls to a Hoiio Number into a conference call.

Instructions In your Hoiio Developer Portal under Hoiio Number section, configure the Forwarding URL of the Hoiio Number to the location of this script.

Requirements

<?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 = "https://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);
}

// 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;
}
?>

Download the source code.