diff --git a/README.md b/README.md index b7754ce..b02953b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ cwslack.php and cwslack-activities.php were designed to be independent, but both 1. Download the cwslack.php file and config.php file. 2. Place on a compatible web server -3. Create a new slack slash command integration at hhttps://SLACK TEAM.slack.com/apps/A0F82E8CA-slash-commands +3. Create a new slack slash command integration at https://SLACK TEAM.slack.com/apps/A0F82E8CA-slash-commands 4. Set command to /t (or other if you prefer) 5. Set the URL to http://domain.tld/cwslack.php 6. Set Method to GET @@ -25,7 +25,7 @@ cwslack.php and cwslack-activities.php were designed to be independent, but both 1. Download the cwslack.php file and config.php file. 2. Place on a compatible web server -3. Create a new slack slash command integration at hhttps://SLACK TEAM.slack.com/apps/A0F82E8CA-slash-commands +3. Create a new slack slash command integration at https://SLACK TEAM.slack.com/apps/A0F82E8CA-slash-commands 4. Set command to /act (or other if you prefer) 5. Set the URL to http://domain.tld/cwslack-activities.php 6. Set Method to GET @@ -34,6 +34,24 @@ cwslack.php and cwslack-activities.php were designed to be independent, but both 9. Modify the config.php file with your companies values, make sure to set the specific $slackactivitiestoken to the one for the activities slash command. 10. Test it in Slack! +## cwslack-incoming.php + +1. Download the cwslack-incoming.php file and config.php file. +2. Place on a compatible web server +3. Create a new slack incoming webhook integration at https://my.slack.com/services/new/incoming-webhook/ +4. Set a name, icon, and if wanted. +5. Set channel that you want to post to and copy the Webhook URL +6. Create a new integrator login in ConnectWise: + - Go to System > Setup Tables in the client + - Type "int" in the table field and select Integrator Login + - Create a new login with whatever username/password, we don't need this. + - Set Access Level to "All Records" + - Enable "Service Ticket API" and select the board(s) you want this to run on. + - Enter http://domain.tld/cwslack-incoming.php?id= for the callback URL (do not enable legacy format) +7. Modify the config.php file with your companies values, make sure to set the specific $webhookurl to the value copied in step 5. +8. Change the $postupdated and $postadded to what you prefer. Enabling $postupdated can get spammy. +9. Test it in Slack by creating a new ticket on the board you selected in step 6! + # Command Usage * denotes required diff --git a/config.php b/config.php index 0ffc9db..034d1c9 100644 --- a/config.php +++ b/config.php @@ -11,5 +11,8 @@ $slacktoken = "Slack Token Here"; //Set token from the Slack slash command screen. $slackactivitiestoken = "Slack Token Here"; //Set your token for the activities slash command, if you're using cwslack-activities.php $helpurl = "https://companyknowledgebase.com/document"; //Set your help article URL here. +$webhookurl = "https://hooks.slack.com/services/tokens" //Change this if you intend to use cwslack-incoming.php +$postadded = 1; //Set this to post new tickets to slack. +$postupdated = 0; //Set this to post updated tickets to slack. Defaults to off to avoid spam ?> \ No newline at end of file diff --git a/cwslack-incoming.php b/cwslack-incoming.php new file mode 100644 index 0000000..d5ee01c --- /dev/null +++ b/cwslack-incoming.php @@ -0,0 +1,82 @@ +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); + +?>