Here's exactly what we did:
1) Create a callflow/pivot to react to *8 + 4-digit extension:
curl -v -X PUT -H "X-Auth-Token: " -d '{"data":{"flow":{"data":{"method":"GET","req_timeout":"5","req_format":"kazoo","voice_url":"http://pivot.server/path/to/getGrpExtension.php","debug":false},"module":"pivot","children":{}},"numbers":[],"patterns":["^\\*8([0-9]*)$"],"featurecode":{"name":"Group Pickup","number":"8"},"contact_list":{"exclude":true}}}' http://{KAZOO_SERVER}/v2/accounts/{ACCOUNT_ID}/callflows
The script getGrpExtension.php looks like:
<code>
<?php
foreach ($_REQUEST as $key=>$value) {
$$key = $value;
}
$accountID = $_REQUEST['Account-ID'];
if(preg_match('/^\\*8/', $To)) {
// Strip off the Feature Code (*8) from $To
$extension = str_replace('*8','',$To);
}
header('content-type:application/json');
?>
{
"module": "pivot",
"data": {
"voice_url": "http:/{SERVER}/path/to/verifyExtension.php?extension=<?php echo($extension); ?>&accountID=<?php echo($accountID); ?>"
},
"children": {}
}
</code>
As you can see, this script sends the Extension and {ACCOUNT_ID} to the next script.
The code in verifyExtension.php looks like this:
<code>
<?php
require_once('/path/to/getAuthToken.php');
$user_id = "";
foreach($_GET as $key=>$value) {$$key = $value;}
$extension = $_GET['extension'];
$accountID = $_GET['accountID'];
$token = authenticateUser();
function fetchUserIDs($token, $accountID, $extension) {
// We're checking for the extension (stored as "presdence_id") that was dialed, among the users of this account. If/when we find a match, we save the userID to put in the JSON message going back to Kazoo.
$userID = "";
$PID = "";
$service_url = "http://{KAZOO_SERVER}/v2/accounts/$accountID/users";
$ch = curl_init($service_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Auth-Token: $token"));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
$info = curl_getinfo($ch);
curl_close($ch);
die('error occured during curl exec. Additional info: ' . var_export($info));
}
$decoded = json_decode($response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
$value = get_object_vars($decoded);
$data = $value['data'];
foreach($data as $obj) {
$PID = $obj->presence_id;
if($PID == $extension) {
$userID = $obj->id;
break;
}
}
curl_close($ch);
return($userID);
}
$user_id = fetchUserIDs($token, $accountID, $extension);
header('content-type:application/json');
function valid($user_id){
// Is it -> "group_id":"$user_id" OR "user_id":"$user_id" ??
?>
{"module":"group_pickup_feature",
"data":{"type":"extension","user_id": "<?php echo($user_id); ?>"}
}
<?php
}
if(strlen($user_id) > 1) {valid($user_id);}
// If we didn't get a valid userID, just quit.
?>
</code>
We've tested this and it works perfectly.