PHPackages                             olarewaju/slack-client - 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. [API Development](/categories/api)
4. /
5. olarewaju/slack-client

ActiveLibrary[API Development](/categories/api)

olarewaju/slack-client
======================

A better Slack client, with RTM API support

1.2.0(7y ago)018MITPHPPHP &gt;=5.5

Since Jun 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Olarewaju/slack-client)[ Packagist](https://packagist.org/packages/olarewaju/slack-client)[ RSS](/packages/olarewaju-slack-client/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (9)Versions (22)Used By (0)

PHP Slack API Client
====================

[](#php-slack-api-client)

[![Build](https://camo.githubusercontent.com/3d3fd3fc21ad6019c0df4298a2f3c30326e697c1f40016cc33f43ca624eac6dd/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f7361676562696e642f736c61636b2d636c69656e742e737667)](https://scrutinizer-ci.com/g/sagebind/slack-client)[![Version](https://camo.githubusercontent.com/d30c1fd36b6fc2075a1c25b7ddb18e528d0be098f27b50a7b36731727212ea2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6465727374657068656e2f736c61636b2d636c69656e742e737667)](https://packagist.org/packages/coderstephen/slack-client)[![License](https://camo.githubusercontent.com/67073ddf958a5398e47fde697c13236b9dd15691e8ded1197beb9af4b7c3b136/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f6465727374657068656e2f736c61636b2d636c69656e742e737667)](https://packagist.org/packages/coderstephen/slack-client)[![Code Coverage](https://camo.githubusercontent.com/0a85529a83847bdbc6fa0bf44bcb506a25dcc09a6f47c4136355f90de073fa55/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7361676562696e642f736c61636b2d636c69656e742e737667)](https://scrutinizer-ci.com/g/sagebind/slack-client)[![Code Quality](https://camo.githubusercontent.com/13581fd4c459a81096fc30935a804fff7a45f855d259e1c5cc0cae9e902d57f9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7361676562696e642f736c61636b2d636c69656e742e737667)](https://scrutinizer-ci.com/g/sagebind/slack-client)[![Downloads](https://camo.githubusercontent.com/5b967ee1ab1c7543e08f4e24c891264fefb2394d4a2cfd8d1d21eac22f29bd3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6465727374657068656e2f736c61636b2d636c69656e742e737667)](https://packagist.org/packages/coderstephen/slack-client)

This is an API client for [Slack](http://slack.com) for PHP clients, with support for the [Real Time Messaging API](http://api.slack.com/rtm) (RTM API) using web sockets.

Overview
--------

[](#overview)

This library was created primarily for [Slackyboy](https://github.com/sagebind/slackyboy), but was branched off into its own codebase so it could be used in other projects as well. I created this client because existing clients were either too complicated to use, or buggy, or incomplete. This is also the first PHP client I am aware of to support Slack's RTM API.

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

[](#installation)

Install with [Composer](http://getcomposer.org), obviously:

```
$ composer require mpociot/slack-client
```

Please note that the current version has unstable dependencies.

In order to install those dependencies, you can set `"minimum-stability"` in your `composer.json`, and recommend that you set `"prefer-stable"`:

```
{
    "minimum-stability": "dev",
    "prefer-stable": true
}
```

Usage
-----

[](#usage)

First, you need to create a client object to connect to the Slack servers. You will need to acquire an API token for your app first from Slack, then pass the token to the client object for logging in. Since this library uses React, you must also pass in an event loop object:

```
$loop = \React\EventLoop\Factory::create();

$client = new \Slack\ApiClient($loop);
$client->setToken('YOUR-TOKEN-HERE');
// ...
$loop->run();
```

Assuming your token is valid, you are good to go! You can now use wrapper methods for accessing most of the [Slack API](http://api.slack.com). Below is an example of posting a message to a channel as the logged in user:

```
$client->getChannelById('C025YTX9D')->then(function (\Slack\Channel $channel) use ($client) {
    $client->send('Hello from PHP!', $channel);
});
```

### Advanced messages

[](#advanced-messages)

Slack supports messages much more rich than plain text through attachments. The easiest way to create a custom message is with a `MessageBuilder`:

```
use Slack\Message\{Attachment, AttachmentField};

$message = $client->getMessageBuilder()
    ->setText('Hello, all!')
    ->setChannel($someChannelObject)
    ->addAttachment(new Attachment('My Attachment', 'attachment text'))
    ->addAttachment(new Attachment('Build Status', 'Build failed! :/', 'build failed', 'danger')))
    ->addAttachment(new Attachment('Some Fields', 'fields', null, '#BADA55', [
        new AttachmentField('Title1', 'Text', false),
        new AttachmentField('Title2', 'Some other text', true)
    ]))
    ->create();

$client->postMessage($message);
```

Check the [API documentation](http://sagebind.github.io/slack-client/api) for a list of all methods and properties that messages, attachments, and fields support.

### Asynchronous requests and promises

[](#asynchronous-requests-and-promises)

All client requests are made asynchronous using [React promises](https://github.com/reactphp/promise). As a result, most of the client methods return promises. This lets you easily compose request orders and handle them as you need them. Since it uses React, be sure to call `$loop->run()` or none of the requests will be sent.

React allows the client to perform well and prevent blocking the entire thread while making requests. This is especially useful when writing real-time apps, like Slack chat bots.

### Real Time Messaging API

[](#real-time-messaging-api)

You can also connect to Slack using the [Real Time Messaging API](http://api.slack.com/rtm). This is often useful for creating Slack bots or message clients. The real-time client is like the regular client, but it enables real-time incoming events. First, you need to create the client:

```
$client = new \Slack\RealTimeClient();
$client->setToken('YOUR-TOKEN-HERE');
$client->connect();
```

Then you can use the client as normal; `RealTimeClient` extends `ApiClient`, and has the same API for sending requests. You can attach a callback to handle incoming Slack events using `RealTimeClient::on()`:

```
$client->on('file_created', function($data) {
    echo 'A file was created called ' . $data['file']['name'] . '!\n';
});
```

Below is a very simple, complete example:

```
$loop = React\EventLoop\Factory::create();

$client = new Slack\RealTimeClient($loop);
$client->setToken('YOUR-TOKEN-HERE');

// disconnect after first message
$client->on('message', function ($data) use ($client) {
    echo "Someone typed a message: ".$data['text']."\n";
    $client->disconnect();
});

$client->connect()->then(function () {
    echo "Connected!\n";
});

$loop->run();
```

See the [Slack API documentation](http://api.slack.com/events) for a list of possible events.

Documentation
-------------

[](#documentation)

You can view the complete API documentation [here](http://sagebind.github.io/slack-client/api).

Running tests
-------------

[](#running-tests)

You can run automated unit tests using [PHPUnit](http://phpunit.de) after installing dependencies:

```
$ vendor/bin/phpunit
```

Where to get help
-----------------

[](#where-to-get-help)

Need help? Just [send me an email](mailto:me@stephencoakley.com) with your questions. Be sure to add "Slack client" to the message subject line so I know how I can help you out.

License
-------

[](#license)

This library is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 80.9% 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 ~61 days

Recently: every ~101 days

Total

21

Last Release

2760d ago

Major Versions

0.3.4 → 1.02017-12-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/a70e774d94df008b7753236ac9612a2f3516a7edc905db09f5e94faf85a65331?d=identicon)[3plekode](/maintainers/3plekode)

---

Top Contributors

[![sagebind](https://avatars.githubusercontent.com/u/2192863?v=4)](https://github.com/sagebind "sagebind (110 commits)")[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (9 commits)")[![orottier](https://avatars.githubusercontent.com/u/5442615?v=4)](https://github.com/orottier "orottier (2 commits)")[![iGusev](https://avatars.githubusercontent.com/u/1555767?v=4)](https://github.com/iGusev "iGusev (2 commits)")[![baopham](https://avatars.githubusercontent.com/u/783410?v=4)](https://github.com/baopham "baopham (2 commits)")[![jmleroux](https://avatars.githubusercontent.com/u/1516770?v=4)](https://github.com/jmleroux "jmleroux (1 commits)")[![Lisennk](https://avatars.githubusercontent.com/u/8103985?v=4)](https://github.com/Lisennk "Lisennk (1 commits)")[![MrHash](https://avatars.githubusercontent.com/u/390925?v=4)](https://github.com/MrHash "MrHash (1 commits)")[![TRManderson](https://avatars.githubusercontent.com/u/2503403?v=4)](https://github.com/TRManderson "TRManderson (1 commits)")[![UbiquitousBear](https://avatars.githubusercontent.com/u/5007497?v=4)](https://github.com/UbiquitousBear "UbiquitousBear (1 commits)")[![arronwoods](https://avatars.githubusercontent.com/u/778702?v=4)](https://github.com/arronwoods "arronwoods (1 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (1 commits)")[![crocodele](https://avatars.githubusercontent.com/u/1522694?v=4)](https://github.com/crocodele "crocodele (1 commits)")[![david-duncan](https://avatars.githubusercontent.com/u/5995221?v=4)](https://github.com/david-duncan "david-duncan (1 commits)")[![ekrembk](https://avatars.githubusercontent.com/u/1821107?v=4)](https://github.com/ekrembk "ekrembk (1 commits)")[![iamwavecut](https://avatars.githubusercontent.com/u/239034?v=4)](https://github.com/iamwavecut "iamwavecut (1 commits)")

---

Tags

apislackrealtime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/olarewaju-slack-client/health.svg)

```
[![Health](https://phpackages.com/badges/olarewaju-slack-client/health.svg)](https://phpackages.com/packages/olarewaju-slack-client)
```

###  Alternatives

[mpociot/slack-client

A better Slack client, with RTM API support

51263.6k1](/packages/mpociot-slack-client)[ccxt/ccxt

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

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

Library to fetch and parse realtime Forex quotes and convert currencies

7212.5k](/packages/oneforge-forexquotes)

PHPackages © 2026

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