Skip to content

Instantly share code, notes, and snippets.

@Seklfreak
Last active November 28, 2023 14:47
Show Gist options
  • Select an option

  • Save Seklfreak/f392eaa140ef51c103e4e401d73f7479 to your computer and use it in GitHub Desktop.

Select an option

Save Seklfreak/f392eaa140ef51c103e4e401d73f7479 to your computer and use it in GitHub Desktop.
statuspage.io webhooks to discord
<?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);

ghost commented Nov 12, 2020

Copy link
Copy Markdown

How do you make it post?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment