threadmeup/slack-sdk SDK

Installs: 1 838

Dependents: 0

Stars: 22

Watchers: 9

Forks: 10

Open Issues: 1

Language: PHP

1.1.3 2014-07-30 20:50 UTC


Latest Stable Version Total Downloads Latest Unstable Version License

Simple SDK for interacting with via the API and webhooks.


You can install slack-sdk by using composer require threadmeup/slack-sdk dev-master.


include 'vendor/autoload.php';

use ThreadMeUp\Slack\Client;

$config = [
    'token' => 'USER-API-TOKEN',
    'team' => 'YOUR-TEAM',
    'username' => 'BOT-NAME',
    'icon' => 'ICON', // Auto detects if it's an icon_url or icon_emoji
    'parse' => '', // __construct function in Client.php calls for the parse parameter 

$slack = new Client($config);


What we're doing here is sending the message Hello World! to the #general channel

$chat = $slack->chat('#general');
$chat->send('Hello World!');

We can also list all users in the team

$users = $slack->users();
foreach ($users as $user)
    echo ($user->isAdmin() ? 'Admin' : 'User').': '.$user->name().' <'.$user->email().'>'.PHP_EOL;

Or even listen to outgoing webhooks from Slack themselves.

$incoming = $slack->listen();
if ($incoming)
        case "What time is it?":
            $incoming->respond("It is currently ".date('g:m A T'));
            $incoming->respond("I don't understand what you're asking.");

For testing reasons you can pass Client::listen() an array of the payload to simulate which will then ignore any $_POST values and use the $payload you supplied instead.

$payload = [
    'token' => 'YNgeXsCXyWgAMfCvjc7NUUpz',
    'team_id' => 'T0001',
    'channel_id' => 'C2147483705',
    'channel_name' => 'test',
    'timestamp' => '1355517523.000005',
    'user_id' => 'U2147483697',
    'user_name' => 'Steve',
    'text' => 'googlebot: What is the air-speed velocity of an unladen swallow?'
$incoming = $slack->listen($payload);