PHPackages                             jclg/php-slack-bot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jclg/php-slack-bot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jclg/php-slack-bot
==================

Slack bot user written in PHP

0.0.7(7y ago)16825.5k60[7 issues](https://github.com/jclg/php-slack-bot/issues)[1 PRs](https://github.com/jclg/php-slack-bot/pulls)1MITPHP

Since Sep 5Pushed 3y ago11 watchersCompare

[ Source](https://github.com/jclg/php-slack-bot)[ Packagist](https://packagist.org/packages/jclg/php-slack-bot)[ Docs](https://github.com/jclg/php-slack-bot)[ RSS](/packages/jclg-php-slack-bot/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (8)Used By (1)

PHP Slack Bot
=============

[](#php-slack-bot)

A simple bot user written in PHP using the Slack Real Time Messaging API

Installation
------------

[](#installation)

With Composer

```
composer require jclg/php-slack-bot

```

Usage
-----

[](#usage)

Create a php file called `bot.php` with the following content

```
require 'vendor/autoload.php';
use PhpSlackBot\Bot;

// Custom command
class MyCommand extends \PhpSlackBot\Command\BaseCommand {

    protected function configure() {
        $this->setName('mycommand');
    }

    protected function execute($message, $context) {
        $this->send($this->getCurrentChannel(), null, 'Hello !');
    }

}

$bot = new Bot();
$bot->setToken('TOKEN'); // Get your token here https://my.slack.com/services/new/bot
$bot->loadCommand(new MyCommand());
$bot->loadInternalCommands(); // This loads example commands
$bot->run();
```

Then run `php bot.php` from the command line (terminal).

Example commands
----------------

[](#example-commands)

Example commands are located in `src/PhpSlackBot/Command/` and can be loaded with `$bot->loadInternalCommands();`

##### Ping Pong Command

[](#ping-pong-command)

Type `ping` in a channel and the bot should answer "Pong" to you.

##### Count Command

[](#count-command)

Type `count` several times in a channel and the bot should answer with 1 then 2...

##### Date Command

[](#date-command)

Type `date` in a channel and the current date.

##### Planning Poker Command

[](#planning-poker-command)

[https://en.wikipedia.org/wiki/Planning\_poker](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
----------------------

[](#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
-------------------

[](#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.

```
require 'vendor/autoload.php';
use PhpSlackBot\Bot;

// This special command executes on all events
class SuperCommand extends \PhpSlackBot\Command\BaseCommand {

    protected function configure() {
        // We don't have to configure a command name in this case
    }

    protected function execute($data, $context) {
        if ($data['type'] == 'message') {
            $channel = $this->getChannelNameFromChannelId($data['channel']);
            $username = $this->getUserNameFromUserId($data['user']);
            echo $username.' from '.($channel ? $channel : 'DIRECT MESSAGE').' : '.$data['text'].PHP_EOL;
        }
    }

}

$bot = new Bot();
$bot->setToken('TOKEN'); // Get your token here https://my.slack.com/services/new/bot
$bot->loadCatchAllCommand(new SuperCommand());
$bot->run();
```

Incoming webhooks
-----------------

[](#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

To enable webhooks, use the enableWebserver method before the run method.

You can also set a secret token to prevent unauthorized requests.

```
$bot->loadInternalWebhooks(); // Load the internal "output" webhook
$bot->enableWebserver(8080, 'secret'); // This will listen on port 8080
$bot->run();
```

Then, use the parameter "name" to trigger the corresponding webhook :

```
curl -X POST --data-urlencode 'auth=secret' --data-urlencode 'name=output' --data-urlencode 'payload={"type" : "message", "text": "This is a message", "channel": "#general"}' http://localhost:8080

```

Active Messaging
----------------

[](#active-messaging)

The example provided in the *usage section* above sets the bot to be reactive. The reactive bot is not capable of sending messages to any user on its own. It must be given an input to get a response from. In other words, the bot can only **react** to inputs given to it.

*Active Messaging* means that as a developer, you would be able to **send messages to your users without them sending a message to the bot first**. It is useful when you have to notify your users about something e.g. a bot which can check a user's birthday and wish them, or tell them weather outside every 2 hours without them having to type in a command everytime. There can be many other uses.

You can use active messaging this way:

```
$bot = new Bot();
$bot->setToken('TOKEN'); // Get your token here https://my.slack.com/services/new/bot
$bot->loadInternalCommands(); // This loads example commands
$bot->loadPushNotifier(function () {
	return [
		'channel' => '#general',
		'username' => '@slacker',
		'message' => "Happy Birthday!! Make sure you have fun today. :-)"
	];
});

$bot->loadPushNotifier(function () {
	return [
		'channel' => '@slacker',
		'username' => null,
		'message' => "Current UNIX timestamp is: " . time()
	];
}, 1800);
$bot->run();
```

In the example above, we have set two active messages.

**First message** will send the following message in the '#general' channel:

```
@slacker Happy Birthday!! Make sure you have fun today. :-)

```

It will be triggered only **once**, 10 seconds after launching the script. Slack servers normally establish the connection by then.

**Second message** is a periodic message. It will be sent to the user having the username *slacker* in the team. It won't mention anyone and will be repeated every 30 minutes (1800 seconds). The message should appear as:

```
Current UNIX timestamp is: 1489145707
Current UNIX timestamp is: 1489147507

```

That should happen within 1 hour of launching.

*NOTE*: The first message would appear 30 minutes after launching.

The function you add using `loadPushNotifier` must return an array containing the following keys:

- **channel**: Name of the channel or user to whom the message is to be sent. Channel names should have the `#` prefix while usernames must have the `@` prefix. If you do not set a prefix, the name is assumed to be a channel name. Using prefixes is recommended here.
- **username**: Any username to be mentioned ahead of the message. You can specify the name without the `@` prefix here, though you might want to use the prefix to maintain uniformity within the code.
- **message**: The actual message to be sent.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Recently: every ~165 days

Total

7

Last Release

2787d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf400986300022ded493efdf85830c82d73192bef1cf1dae377e54ee2bcd1a7c?d=identicon)[jclg](/maintainers/jclg)

---

Top Contributors

[![jclg](https://avatars.githubusercontent.com/u/645802?v=4)](https://github.com/jclg "jclg (52 commits)")[![schnabear](https://avatars.githubusercontent.com/u/2335968?v=4)](https://github.com/schnabear "schnabear (2 commits)")[![bomoko](https://avatars.githubusercontent.com/u/297936?v=4)](https://github.com/bomoko "bomoko (2 commits)")[![mrbase](https://avatars.githubusercontent.com/u/304661?v=4)](https://github.com/mrbase "mrbase (2 commits)")[![BR0kEN-](https://avatars.githubusercontent.com/u/2760616?v=4)](https://github.com/BR0kEN- "BR0kEN- (2 commits)")[![bryangruneberg](https://avatars.githubusercontent.com/u/383346?v=4)](https://github.com/bryangruneberg "bryangruneberg (2 commits)")[![djdevin](https://avatars.githubusercontent.com/u/418136?v=4)](https://github.com/djdevin "djdevin (2 commits)")[![vaibhav-kaushal](https://avatars.githubusercontent.com/u/2824682?v=4)](https://github.com/vaibhav-kaushal "vaibhav-kaushal (1 commits)")[![lira92](https://avatars.githubusercontent.com/u/10679262?v=4)](https://github.com/lira92 "lira92 (1 commits)")[![medliii](https://avatars.githubusercontent.com/u/1991105?v=4)](https://github.com/medliii "medliii (1 commits)")

---

Tags

botslackslack-botslack-commands

### Embed Badge

![Health badge](/badges/jclg-php-slack-bot/health.svg)

```
[![Health](https://phpackages.com/badges/jclg-php-slack-bot/health.svg)](https://phpackages.com/packages/jclg-php-slack-bot)
```

###  Alternatives

[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.6M63](/packages/react-react)[sculpin/sculpin

Static Site Generator

1.5k102.8k12](/packages/sculpin-sculpin)[llm/mcp-server

PHP SDK for building MCP servers

431.1k](/packages/llm-mcp-server)[runtime/react

ReactPHP runtime

185.3k1](/packages/runtime-react)[octopoda/octopus

PHP Sitemap crawler

114.8k](/packages/octopoda-octopus)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
