portlandlabs / slackbot
A Slackbot that uses the slack RTM API and the slack web API. Built on PSR components
Installs: 35
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.2
- ext-json: *
- ext-pcntl: *
- buttress/collecterator: ^1.0
- cache/filesystem-adapter: ^1.0
- cleentfaar/slack: ^0.20.1
- clue/arguments: ^2.0
- guzzlehttp/guzzle: ^6.3
- illuminate/config: ^5.4
- illuminate/container: ^5.7
- league/climate: ^3.2
- nunomaduro/collision: ^2.0
- ratchet/pawl: ^0.3.1
- react/promise: ^2.5
- textalk/websocket: ^1.2
- vlucas/phpdotenv: ^2.4
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-11-11 18:04:25 UTC
README
This SlackBot is a fully featured slack bot in the style of old IRC bots with the power of new fancy bots. You can react
to arbitrary messages like tracking emojis in a message like "Giving some ❤️ to @user", or build simple call and response style messages like @bot dosomething
Getting Started
Setup
First configure your slackbot by copying .env.dist
to .env
and configuring the required details
$ cp .env.dist > .env
Running the bot
The Slackbot is powered by a single PHP script, run it to get started:
$ php slackbot.php
Permissions and Roles
Slackbot actions are managed by roles
. The available roles are Bot
, User
, and Admin
Commands
Commands are triggered by events flowing through the RTM
API. Any event with the type message
will flow through the
command stack.
A basic command defines ->shouldHandle(Message $message)
and ->handle(Message $message)
, but SimpleCommand
makes
things a little easier to implement. Commands that extend SimpleCommand
work much the same as console commands.
Declare your $signature
property and a run(Message $message, ArgumentManager $manager)
method, and the super class
will manage hooking everything up.
Adding commands to the bot
You can add commands to the bot through the bot's command manager:
$bot->commands()->addCommand(CustomCommand::class);
Adding Default Commands:
We've wrapped the default commands in a simple provider:
(new \PortlandLabs\Slackbot\Command\DefaultProvider())->register($bot);
Sending messages to slack
There are a few ways to send messages to slack from a command:
-
RTM
API with Typing indicatorWhen using the
RTM
API you have the ability to trigger typing indicators (so that slack says the bot is typing)$this->bot->feignTyping($channel, $message)
The result of this method is a Promise that resolves when Slack acknowledges the sent message.
-
RTM
API without typingIf you don't want the (creepy) typing indicator and you want to be upfront with the fact that your bot doesn't type,
$this->bot->rtm()->sendMessage($channel, $message)
The result of this is also a Promise
-
Web
API with ability to UpdateThe
Web
API uses HTTP to send messages to slack and so can be a bit slower than using theRTM
API with the added benefit of a ton of added power.Simple Usage:
The simplest usage is with the Payload Builder:$api = $this->bot->api(); $api->getBuilder()->send($message)->to($channel)->withIcon($icon)->execute($api); // Update the previously sent message $api->getBuilder()->update()->withText($newText)->execute($api);
Complex Usage:
If you're looking for more power or for different endpoints, you can simply build payloads directly and send them with the API$payload = new ChatPostMessagePayload(); $this->prepare($payload); // Send the payload $payloadResponse = $this->bot->api()->send($payload);