Created
January 19, 2016 20:24
-
-
Save morozgrafix/c0c45278616f1a3ae57e to your computer and use it in GitHub Desktop.
Basic Slack Slash Command Bot Template in PHP
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 | |
// Authorized team tokens that you would need to get when creating a slash command. Same script can serve multiple teams, just keep adding tokens to the array below. | |
$valid_tokens = array( | |
"123asdzxcvasdfasdwasdfas", // key 1 | |
"234xdfqadfsdfasdfasfasdf" // key 2 | |
); | |
if (!in_array($_REQUEST['token'], $valid_tokens)) { | |
bot_respond(":no_good: *Unauthorized token!* Feel free to grab a copy of this script and host it yourself."); | |
break; | |
} | |
switch ($_REQUEST['text']) { | |
case 'help': | |
bot_respond("help message goes here"); | |
break; | |
case 'foo': | |
bot_respond("you asked me to do `foo`"); | |
break; | |
case 'bar': | |
bot_respond("you asked me to do `bar`"); | |
break; | |
default: | |
bot_respond("this is a default response"); | |
break; | |
} | |
// This can used for debugging | |
// dumper($_REQUEST); | |
/* | |
Helper Functions | |
*/ | |
// Send information back to slack | |
function bot_respond($output){ | |
echo $output; | |
} | |
function dumper($foo){ | |
echo "<pre style=\"text-align: left;\">"; | |
echo HtmlSpecialChars(var_export($foo, 1)); | |
echo "</pre>\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment