Extensible, PHP-based bot for Slack, using Slack's Real-Time Messaging API, using Yii 2.0. Work in progress.
- PHP >5.6.8 OR PHP >5.5.20 (untested.. but it should work)
- PHP Modules: mbstring, pdo, mysql, xml
- OpenSSL development headers (openssl-devel on centos)
- libevent2 compiled and installed AFTER openssl headers installed: http://libevent.org/
- pecl
eventmodule installed with SSL support
- import
schema.sqlinto a new database - move
config/db.php.exampletoconfig/db.phpand update it with your database info. INSERT INTO config VALUES ('slack.apikey', 'YOUR_SLACK_XOP_KEY');at minimum. Other keys are needed for some commands to function.- run
composer update bin/bot start
In order for some commands to work, you will need to set the following in the config table:
- For WolframAlpha,
INSERT INTO config VALUES ('wa.appid','YOUR_WOLFRAM_APP_ID'); - For Imgur,
INSERT INTO config VALUES ('imgur.client_id','YOUR_IMGUR_CLIENT_ID'), ('imgur.client_secret','YOUR_IMGUR_CLIENT_SECRET');
Slackbot comes with a number of built in commands. You can inspect the files in components/Slack/Event/Message/ for more details, but here's a short list. Note that most of these commands need the bot's name in front of them (i.e. bot: roll 1d20)
- roll: roll dice. syntax
bot: roll [number of dice]d[die side count][, ...] - reaction: paste a reaction gif based on your text. requires imgur configuration. example
bot: reaction deal with it - ping: make the bot respond with pong and the time it took to respond in ms (from the bot's perspective).
bot: ping - WolframAlpha questions. This one is a bit freeform, but asking the bot 'what is' 'how is' etc questions should generate a response from W|A. you need W|A config in your config table. example:
bot: what is the square root of pi? - wa: get a more detailed response from Woldfram, or ask something without having to form it into a question. example:
bot: wa 192.168.0.0/21 - asl: print a randomized silly A/S/L response.
bot: asl? - password generator. ask the bot to generate you one or more passwords, which will be IMed to you. examples:
bot: give me a password,bot: give me 5 passwords
eatpl is a small tool for creating new EventAction classes from a TemPLate. (hence e-a-tpl). The syntax is like so:
./eatpl event_name[:subtype_name] nameforyouraction
For example, if you wanted to make a new action for the Message event, with the subtype being bot_message (i.e. an integration's message), you would do:
./eatpl message:bot_message nameofaction
This would create a new file, protected/components/Slack/Event/Message/Bot_messgae/NameofactionEventAction.php, from the highest-level Template.phpt it can find - in this case, in protected/components/Slack/Event/Message/