Last active
November 28, 2023 14:47
-
-
Save Seklfreak/f392eaa140ef51c103e4e401d73f7479 to your computer and use it in GitHub Desktop.
statuspage.io webhooks to discord
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
<?php | |
$KEY = ''; // option key to prevent unauthenticated password, should be transfered as the get parameter "key" | |
$DISCORD_WEBHOOK_URL = ''; // the discord webhook | |
if ($_SERVER['REQUEST_METHOD'] != 'POST') { | |
header('HTTP/1.0 405 Method Not Allowed'); | |
echo "Only POST requests allowed\n"; | |
exit(); | |
} | |
if ($_SERVER['CONTENT_TYPE'] != 'application/json') { | |
header('HTTP/1.0 415 Unsupported Media Type'); | |
echo "I only accept application/json data\n"; | |
exit(); | |
} | |
if ($KEY != '') { | |
if (!array_key_exists('key', $_GET)) { | |
header('HTTP/1.0 401 Unauthorized'); | |
exit(); | |
} | |
if ($_GET['key'] != $KEY) { | |
header('HTTP/1.0 401 Unauthorized'); | |
exit(); | |
} | |
} | |
$data = json_decode(file_get_contents('php://input'), true); | |
if (!array_key_exists('incident', $data)) { | |
exit(); | |
} | |
$payload = array( | |
'embeds' => array( | |
array( | |
'title' => 'Status Update: ' . ucfirst($data['incident']['status']) . ' ' . $data['incident']['name'], | |
'url' => $data['incident']['shortlink'], | |
'timestmap' => $data['incident']['updated_at'] | |
) | |
) | |
); | |
if (count($data['incident']['incident_updates']) >= 1) { | |
$payload['embeds'][0]['description'] = $data['incident']['incident_updates'][0]['body']; | |
} | |
$context = stream_context_create(array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => 'Content-Type: application/json', | |
'content' => json_encode($payload) | |
) | |
)); | |
$response = file_get_contents($DISCORD_WEBHOOK_URL, false, $context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you make it post?