Download the PHP package alex-equity/php-slack-bot without Composer
On this page you can find all versions of the php package alex-equity/php-slack-bot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alex-equity/php-slack-bot
More information about alex-equity/php-slack-bot
Files in alex-equity/php-slack-bot
Package php-slack-bot
Short Description Slack bot user written in PHP
License MIT
Homepage https://github.com/jclg/php-slack-bot
Informations about the package php-slack-bot
PHP Slack Bot
A simple bot user written in PHP using the Slack Real Time Messaging API https://api.slack.com/rtm
Installation
With Composer
Create a new composer.json file and add the following
{
"minimum-stability" : "dev",
"require": {
"jclg/php-slack-bot": "dev-master"
}
}
Then run
composer install
Usage
Create a php file called bot.php
with the following content
Then run php bot.php
from the command line (terminal).
Example commands
Example commands are located in src/PhpSlackBot/Command/
and can be loaded with $bot->loadInternalCommands();
Ping Pong Command
Type ping
in a channel and the bot should answer "Pong" to you.
Count Command
Type count
several times in a channel and the bot should answer with 1 then 2...
Date Command
Type date
in a channel and the current date.
Planning Poker Command
https://en.wikipedia.org/wiki/Planning_poker
Type pokerp start
in a public channel with your team in order to start a planning poker session.
Direct message the bot with pokerp vote number
. The bot will record your vote.
Type pokerp status
to see the current status of the session (who has voted).
Type pokerp end
in a public channel and the bot will output each vote.
Load your own commands
You can load your own commands by implementing the \PhpSlackBot\Command\BaseCommand.
Then call PhpSlackBot\Bot::loadCommand method for each command you have to load.
"Catch All" command
If you need to execute a command when an event occurs, you can set up a "catch all" command.
This special command will be triggered on all events.
Incoming webhooks
The bot can also listen for incoming webhooks.
Commands are triggered from users messages inside Slack and webhooks are triggered from web post requests.
Custom webhooks can be loaded using the PhpSlackBot\Bot::loadWebhook method.
This is useful if you need to control the bot from an external service. For example, with IFTTT https://ifttt.com/maker
To enable webhooks, use the enableWebserver method before the run method.
You can also set a secret token to prevent unauthorized requests.
Altered in this fork:
Use the parameter "webhook" to trigger the corresponding webhook. In the example case above, the "webhook" value is "output".
The input format can be either JSON or a POST with a json encoded payload, as described here in https://api.slack.com/incoming-webhooks. The webserver differentiates between the two using the Content-Type header.
JSON:
POST Fields (json encoded payload):
Also, the response from a webhook is now json encoded. The return value from your custom webhook's execute() method will be inside the "data" property of a successful request. Otherwise, an "error" property will be populated.