Skip to content

Instantly share code, notes, and snippets.

@DaltonWebDev
Last active January 10, 2019 03:30
Show Gist options
  • Save DaltonWebDev/2ff17e71dd1ce8cd26346306ea932d8b to your computer and use it in GitHub Desktop.
Save DaltonWebDev/2ff17e71dd1ce8cd26346306ea932d8b to your computer and use it in GitHub Desktop.
<?php
header("Content-type: application/json; charset=utf-8");
$username = !empty($_POST["username"]) ? strtolower($_POST["username"]) : false;
$message = !empty($_POST["message"]) ? $_POST["message"] : false;
$messageExploded = explode(" ", $message);
if ($messageExploded[0] === "text") {
$outputArray[] = [
"type" => "text",
"message" => "Your username is " . $username
];
$outputArray[] = [
"type" => "text",
"message" => "Your username is " . $username
];
} else if ($messageExploded[0] === "image") {
$outputArray[] = [
"type" => "image",
"message" => "https://media3.giphy.com/media/3o7aDalHF4hE9Et8AM/giphy.gif"
];
$outputArray[] = [
"type" => "text",
"message" => "Happy Wednesday!"
];
$outputArray[] = [
"type" => "image",
"message" => "https://media3.giphy.com/media/3o7aDalHF4hE9Et8AM/giphy.gif"
];
// bots must respond to blank @mentions.. either show an error asking for required parameter or auto fill with default ones
} else {
$outputArray = [
"type" => "text",
"message" => "Send a parameter"
];
}
echo json_encode($outputArray);
?>

Bot Instructions

Once you're done setting up your script go to any group and message @bot with a direct link to your webhook script. (Example: @bot https://your.domain/webhook.php)

Warning: Bot accounts can't respond through the site they can only message through webhooks. It's advised not to use a personal account.

Send @bot /remove to make your account not a bot again :)

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