-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created incoming webhook integration to post new tickets to Slack.
- Loading branch information
Showing
3 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
//Receive connector for Connectwise Callbacks | ||
die; | ||
ini_set('display_errors', 1); //Display errors in case something occurs | ||
header('Content-Type: application/json'); //Set the header to return JSON, required by Slack | ||
require_once 'config.php'; //Require the config file. | ||
|
||
$data = json_decode(file_get_contents('php://input')); //Decode incoming body from connectwise callback. | ||
$info = json_decode(stripslashes($data->Entity)); //Decode the entity field which contains the JSON data we want. | ||
|
||
if(empty($_GET['id']) || empty($_GET['action']) || strtolower($_GET['memberId'])=="zadmin" || $_GET['isInternalAnalysis']=="True" || empty($info)) die; //If anything we need doesn't exist, kill connection. | ||
|
||
$ticketurl = $connectwise . "/v4_6_release/services/system_io/Service/fv_sr100_request.rails?service_recid="; | ||
$header_data =array( | ||
"Content-Type: application/json" | ||
); | ||
|
||
$date=strtotime($info->EnteredDateUTC); //Convert date entered JSON result to time. | ||
$dateformat=date('m-d-Y g:i:sa',$date); //Convert previously converted time to a better time string. | ||
$ticket=$_GET['id']; | ||
|
||
$ch = curl_init(); | ||
|
||
if($_GET['action'] == "added" && $postadded == 1) | ||
{ | ||
$postfieldspre = array( | ||
"attachments"=>array(array( | ||
"title" => "<" . $ticketurl . $ticket . "&companyName=" . $companyname . "|#" . $ticket . ">: ". $info->Summary, | ||
"pretext" => "Ticket #" . $ticket . " has been created by " . $info->UpdatedBy . ".", | ||
"text" => $info->CompanyName . " / " . $info->ContactName . //Return "Company / Contact" string | ||
"\n" . "Priority: " . $info->Priority . " | " . $info->StatusName . //Return "Date Entered / Status" string | ||
"\n" . $info->Resources, //Return assigned resources | ||
"mrkdwn_in" => array( | ||
"text", | ||
"pretext", | ||
"title" | ||
) | ||
)) | ||
); | ||
} | ||
else if($_GET['action'] == "updated" && $postupdated == 1) | ||
{ | ||
$postfieldspre = array( | ||
"attachments"=>array(array( | ||
"title" => "<" . $ticketurl . $ticket . "&companyName=" . $companyname . "|#" . $ticket . ">: ". $info->Summary, | ||
"pretext" => "Ticket #" . $ticket . " has been updated by " . $info->UpdatedBy . ".", | ||
"text" => $info->CompanyName . " / " . $info->ContactName . //Return "Company / Contact" string | ||
"\n" . $dateformat . " | " . $info->StatusName . //Return "Date Entered / Status" string | ||
"\n" . $info->Resources, //Return assigned resources | ||
"mrkdwn_in" => array( | ||
"text", | ||
"pretext" | ||
) | ||
)) | ||
); | ||
} | ||
else | ||
{ | ||
die; | ||
} | ||
|
||
$postfields = json_encode($postfieldspre); | ||
|
||
$curlOpts = array( | ||
CURLOPT_URL => $webhookurl, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_HTTPHEADER => $header_data, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_POSTFIELDS => $postfields, | ||
CURLOPT_POST => 1, | ||
CURLOPT_HEADER => 1, | ||
); | ||
curl_setopt_array($ch, $curlOpts); | ||
$answer = curl_exec($ch); | ||
|
||
// If there was an error, show it | ||
if (curl_error($ch)) { | ||
die(curl_error($ch)); | ||
} | ||
curl_close($ch); | ||
|
||
?> |