Skip to content

Instantly share code, notes, and snippets.

@domkirby
Created May 9, 2019 18:00
Show Gist options
  • Save domkirby/2d8d0c11d96fd0ad11ba1fb7e0e13ac7 to your computer and use it in GitHub Desktop.
Save domkirby/2d8d0c11d96fd0ad11ba1fb7e0e13ac7 to your computer and use it in GitHub Desktop.
Middle man webhook to send customer thermometer responses to a channel in MSTeams
<?php
/*
Use of this script assumes that you know how to create a webhook url in teams. Google is your friend.
STEPS IN THIS FILE:
-Create a random password with no special charcters, put it in the quotes after $postSecret=
-Create your teams webhook, put it in quotes after $teams_webhook_url = (look within the PostToTeams function)
-Upload it to a webhost with PHP 7 or better, and use HTTPS like a friggin grownup
STEPS IS CUSTOMER THERMOMETER:
-Login and go to https://app.customerthermometer.com/?template=webhooks
-Create a new webhook with these settings: https://i.imgur.com/jjAYciR.png
-Link your thermometers: https://i.imgur.com/Du2cSyJ.png
-THAT'S IT
*/
$postSecret = "create a unique secret right here";
$rt=time();
function CreateTeamsCard($input)
{
$thermometer_name = $input->thermometer_name;
$response = $input->response;
$first_name = $input->first_name;
$last_name = $input->last_name;
$company = $input->company;
$custom_one = $input->custom_1;
//prevents $schema in the teams card from generating an issue.
$schema = "\$schema";
$teams_card = <<< TEAMSCARD
{
"@context": "https://schema.org/extensions",
"@type": "MessageCard",
"themeColor": "e77817",
"title": "Customer Thermometer Response on {$thermometer_name}",
"text": "{$first_name} {$last_name} ({$company}) left a **{$response}** response!",
"potentialAction": [
{
"@type": "OpenUri",
"name": "View Ticket",
"targets": [
{ "os": "default", "uri": "https://bms.kaseya.com/MSP/TicketEdit.aspx?ID={$custom_one}" }
]
}
]
}
TEAMSCARD;
return $teams_card;
}
function PostToTeams($card) {
$teams_webhook_url = "enter your teams webhook URL here";
$ch = curl_init($teams_webhook_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $card);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($card)
));
$result = curl_exec($ch);
curl_close($ch);
return $response;
}
if($_SERVER['REQUEST_METHOD'] === 'POST') {
if($_GET['secret'] == $postSecret) {
$customer_thermometer_post_body = file_get_contents('php://input');
$customer_thermometer_decoded = json_decode($customer_thermometer_post_body);
$teams_card = CreateTeamsCard($customer_thermometer_decoded);
$api_result = PostToTeams($teams_card);
//exit($api_result);
header("Content-Type: application/json");
exit($teams_card);
} else {
error_log("CT TO TEAMS ACCESS DENIED $rt");
die("Access Denied");
}
} else {
error_log("CT TO TEAMS NON POST REQUEST $rt");
die("Invalid Request");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment