Skip to content

Instantly share code, notes, and snippets.

@fdstevex
Created March 19, 2016 13:02
Show Gist options
  • Save fdstevex/06b544aaade6d1de1854 to your computer and use it in GitHub Desktop.
Save fdstevex/06b544aaade6d1de1854 to your computer and use it in GitHub Desktop.
CheckFront Booking to Slack Notification PHP Script
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
function slack($message, $room = "general", $icon = ":bell:") {
$room = ($room) ? $room : "general";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,
"icon_emoji" => $icon
));
// You can get your webhook endpoint from your Slack settings
$ch = curl_init("https://hooks.slack.com/my_hook_url_from_slack");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$rawjson = file_get_contents('php://input');
$data = json_decode($rawjson, true);
$startdate = $data['booking']['start_date'];
$item = $data['booking']['order']['items']['item'];
$sku = $item['sku'];
$startdate = gmdate("Y-m-d", $startdate);
$custname = $data['booking']['customer']['name'];
$email = $data['booking']['customer']['email'];
slack("SKU: " . $sku . ", Customer: " . $custname . "<" . $email . ">, Date: " . $startdate . ", Status: " . $data['booking']['status'] . " $" . $data['booking']['order']['sub_total']);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment