Skip to content

Instantly share code, notes, and snippets.

@kookoolib
Created September 6, 2012 07:18
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 kookoolib/3652506 to your computer and use it in GitHub Desktop.
Save kookoolib/3652506 to your computer and use it in GitHub Desktop.
Integrating KooKoo with Freshdesk for automated support management
<?php
session_start();
if($_REQUEST['event']=='NewCall')
{
echo '<response>';
$caller=get_user($_REQUEST['cid']);
if($caller != "")
echo '<playtext>Welcome '.$caller.'</playtext>';
else
echo '<playtext>Welcome</playtext>';
echo '<response><collectdtmf t="#"><playtext>Please enter your ticket I D and terminate with hash</playtext></collectdtmf></response>';
exit;
}
else if($_REQUEST['event']=='GotDTMF')
{
$ticket_id=$_REQUEST['data'];
if($ticket_id)
{
$agent_phone=get_agent_phone($ticket_id);
if($agent_phone != '-1')
{
echo '<response filler="yes"><playtext>Please wait, connecting to your agent</playtext><dial moh="default">'.$agent_phone.'</dial></response>';
exit;
}
else
{
echo '<response><collectdtmf t="#"><playtext>Sorry, did not get the agent.</playtext><playtext>Please enter your ticket I D</playtext></collectdtmf></response>';
exit;
}
}else
{
echo '<response><collectdtmf t="#"><playtext>Sorry, did not get the ticket I D</playtext><playtext>Please enter your ticket I D</playtext></collectdtmf></response>';
exit;
}
}
function get_user($phone_no)
{
$phone_no = substr($phone_no, -10);
$return = get_curl('http://yourcompany.freshdesk.com/contacts.xml');
$users = new SimpleXMLElement($return);
foreach($users->user as $user){
if($substr(user->mobile,-10) == $phone_no)
return $user->name;
}
return "";
}
function get_agent_phone($ticket_id)
{
//Replace with your company name
$return = get_curl('http://yourcompany.freshdesk.com/helpdesk/tickets/'.$ticket_id.'.xml');
$ticket = new SimpleXMLElement($return);
$responder=$ticket->{'responder-id'};
//echo 'test:'.$responder;
$return=get_curl('http://yourcompany.freshdesk.com/contacts/'.$responder.'.xml');
//echo $return;
$agent=new SimpleXMLElement($return);
$agent_no=$agent->{'phone'};
//echo 'agent:'.$agent_no;
if($agent_no)
return $agent_no;
else
return '-1';
}
function get_curl($url)
{
$process = curl_init($url);
curl_setopt($process, CURLOPT_HEADER, false);
//Replace with your credentials
curl_setopt($process, CURLOPT_USERPWD, "XXXXXXXXXXXXXXXXXXXX:YYYYYYY");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
//curl_setopt($process, CURLOPT_POST, 1);
//curl_setopt($process, CURLOPT_POSTFIELDS, $payloadName);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
return $return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment