PHPackages                             alex-equity/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. alex-equity/php-slack-bot

ActiveLibrary

alex-equity/php-slack-bot
=========================

Slack bot user written in PHP

0.0.3(9y ago)034MITPHP

Since Sep 5Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (4)Used By (0)

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

[](#php-slack-bot)

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

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

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

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

Altered in this fork:
---------------------

[](#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 . The webserver differentiates between the two using the Content-Type header.

JSON:

```
curl -X POST -H 'Content-Type: application/json; charset=utf8' --data '{"webhook":
 "output", "type" : "message", "text": "This is a message", "channel": "#general"}' http://localhost:8080

```

POST Fields (json encoded payload):

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

```

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.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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 ~46 days

Total

3

Last Release

3442d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a7bc0b3bccbc7e5eb912d4c58ea872ae59b4b45319d25eb95059005cb4f91c9?d=identicon)[alex-equity](/maintainers/alex-equity)

---

Top Contributors

[![jclg](https://avatars.githubusercontent.com/u/645802?v=4)](https://github.com/jclg "jclg (45 commits)")[![alex-equity](https://avatars.githubusercontent.com/u/25552183?v=4)](https://github.com/alex-equity "alex-equity (4 commits)")[![djdevin](https://avatars.githubusercontent.com/u/418136?v=4)](https://github.com/djdevin "djdevin (2 commits)")[![mrbase](https://avatars.githubusercontent.com/u/304661?v=4)](https://github.com/mrbase "mrbase (2 commits)")[![lira92](https://avatars.githubusercontent.com/u/10679262?v=4)](https://github.com/lira92 "lira92 (1 commits)")[![schnabear](https://avatars.githubusercontent.com/u/2335968?v=4)](https://github.com/schnabear "schnabear (1 commits)")

### Embed Badge

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

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

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

41.5k328.9k1](/packages/ccxt-ccxt)[react/react

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

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

PHP-PM is a process manager, supercharger and load balancer for PHP applications.

6.6k441.3k8](/packages/php-pm-php-pm)[clue/framework-x

Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

936736.7k8](/packages/clue-framework-x)[web3p/web3.php

Ethereum web3 interface.

1.3k325.5k41](/packages/web3p-web3php)[atymic/twitter

Twitter API for PHP &amp; Laravel

945555.4k2](/packages/atymic-twitter)

PHPackages © 2026

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