<html>
<head>
<title>Bomgar Zendesk Ticket Updater</title>
</head>
<body>
<?php
// zendesk-update.php
//
// This sample PHP script can be used with Bomgar "outbound events" configured
// via the administrative interface on the appliance (/login URL).
// See Management / Outbound Events...
// Create an event called "Update ZenDesk Ticket"
// Enter the complete URL of this PHP script
// Check "Events to Send" as "Support Session End"
// Be sure to enable the XML API in Management / Security.
// CUSTOMIZE THESE VARIABLES FOR YOUR SPECIFIC ENVIRONMENT...
//Bomgar Info...
$BomgarURL = 'https://support.company.com/api/reporting.ns'; //path to the reporting API URL of your Bomgar support portal
//Zendesk Login Info...
$zenurl = "http://yoursite.zendesk.com";
$zenemail = "your-email@company.com";
$zenpassword = "zendeskpassword";
// Create a header for the comment update...
$message = "BOMGAR Remote Support Session". "\r\n";
date_default_timezone_set('America/Chicago');
function add_comment($ticket_location, $value, $is_public, $token = '')
{
global $zenurl,
$zenemail,
$zenpassword;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ticket_location);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt
($ch, CURLOPT_HTTPHEADER,
array("Content-type: text/xml"));
$xml = "<ticket><comment><value>$value</value><is_public>$is_public</is_public></comment><uploads>$token</uploads></ticket>";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$zenemail:$zenpassword");
curl_exec($ch);
curl_close($ch);
}
// Post the necessary info to query Bomgar for the session details using the Bomgar Reporting API...
(
'username' => "apiuser", //account with admin access to the Bomgar portal
'password' => "testtest", //password for this account
'generate_report' => "SupportDesk", //this give us a report of sessions
'lsid' => $_REQUEST['lsid'] //this is the session ID for the request that just entered the queue
);
// Use curl to invoke the Bomgar Reporting API to retrieve session details...
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $BomgarURL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Assign the output from the URL to $output.
$output = curl_exec($curl);
// close curl resource, and free up system resources
curl_close($curl);
// Use DOM to parse the XML output of the reporting API to query the necessary information
$dom = new DOMDocument();
$dom->loadXML($output);
if (!$dom)
{
// Handle the error
return;
}
//Load returned XML for this session into the $xml varialble.
$xml = simplexml_import_dom($dom);
// Loop through the "customer" object(s) and get the values desired. Note, there should be only
// one Customer in typical support sessions.
// ................
// Or, we could directly get the specific instance of customer from customer_list using...
// $Customer = $xml->session->customer_list[0]->customer;
//extract the Zendesk incident number from the "external_key" field in the Bomgar session details...
$external_key = $xml->session->external_key;
foreach ($xml->session->customer_list->customer as $Customer)
{
//Get the appropriate elements from this customer to include
$CustName = $Customer->username;
$company = $Customer->info->company;
$issue = $Customer->info->issue;
$details = $Customer->info->details;
$public_ip = $Customer->public_ip;
$private_ip = $Customer->private_ip;
$company_code = $Customer->info->company_code;
}
// Append desired session details to the message for the ticket comment...
$message .= "\r\n";
$message .= "Summary Info...\r\n";
$message .= "Rep Name: ". $xml->session->primary_rep. "\r\n";
$message .= "Customer Name: ". $xml->session->primary_customer. "\r\n";
$message .= "Customer's Public IP: " . $public_ip . "\r\n";
$message .= "Customer's Private IP: " . $private_ip . "\r\n";
$start_timestamp = $xml->session->start_time["timestamp"];
$message .=
"Session Start Time: " .
date("m/d/Y : H:i:s",
intval($start_timestamp)) .
"\r\n";
$end_timestamp = $xml->session->end_time["timestamp"];
$message .=
"Session End Time: " .
date("m/d/Y : H:i:s",
intval($end_timestamp)) .
"\r\n";
$message .= "Duration: ". $xml->session->duration . "\r\n";
$message .= "# Files Transfered: ". $xml->session->file_transfer_count . "\r\n";
$message .= "\r\n";
$notes = ''; //var for gathering session notes entered by the Rep
$chat = ''; //var for capturing all interactive chat messages
foreach ($xml->session->session_details->event as $Event)
{
//Get the appropriate elements from this customer to include
$Timestamp = $Event["timestamp"];
$EventType = $Event["event_type"];
if ($EventType == "Session Note Added")
{
$notes =
$notes .
date("m/d/Y : H:i:s",
intval($Timestamp)) .
" ".
$Event->
performed_by .
" added the following note...\r\n" .
$Event->
body.
"\r\n";
} elseif ($EventType == "Chat Message")
{
if ($Event->performed_by != "Bomgar") //exclude system generated chat messages
{
$chat =
$chat .
date("m/d/Y : H:i:s",
intval($Timestamp)) .
" ".
"From: ".
$Event->
performed_by .
" - " .
$Event->
body.
"\r\n";
}
}
}
$message = $message . $notes ."\r\n";
$message = $message . "Chat Transcript...\r\n";
$message = $message . $chat;
// Echo the body of the message to the browser (useful for testing)
// Replace line breaks with html breaks for better viewing in the browser.
// Clean up ampersands in comments & chats... not valid in XML
// Example URL for testing manually...
// Ex. https://support.yoursite.com/api/reporting.ns?username=yourAPIuser&password=yourpassword&generate_report=SupportDesk&lsid=410
// Adding a public comment to the ticket
add_comment($zenurl."/tickets/".$external_key . ".xml", $message, true);
echo "Comment added to ticket: ".
$external_key;
?>
</body>
</html>