Skip to content

Instantly share code, notes, and snippets.

@humannus
Last active March 22, 2024 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humannus/de8e95f13865d4f7cde9062c2bbe9105 to your computer and use it in GitHub Desktop.
Save humannus/de8e95f13865d4f7cde9062c2bbe9105 to your computer and use it in GitHub Desktop.
<?php
$token = 'secret';
// check token in every request
if (!isset($_GET['token']) || $_GET['token'] !== $token) {
header('HTTP/1.0 401 Unauthorized');
exit();
}
// verification request
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
exit($_GET['challenge']);
}
// access the body of a POST request
$data = json_decode(file_get_contents('php://input'));
header('Content-Type: application/json');
$response = array(
// return custom attributes object
'attributes' => array(
'name' => 'John',
'surname' => 'Example'
),
// return responses
'responses' => array(
array(
'type' => 'text',
'message' => 'Message from webhook'
)
)
);
echo json_encode($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment