2017 © Pedro Peláez
 

library slack-sdk

Slack.com SDK

image

threadmeup/slack-sdk

Slack.com SDK

  • Monday, November 16, 2015
  • by killswitch
  • Repository
  • 10 Watchers
  • 34 Stars
  • 48,264 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

slack-sdk

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Simple SDK for interacting with Slack.com via the API and webhooks., (*2)

Install

You can install slack-sdk by using composer require threadmeup/slack-sdk dev-master., (*3)

Configure

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);

Examples

What we're doing here is sending the message Hello World! to the #general channel, (*4)

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

We can also list all users in the team, (*5)

$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., (*6)

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

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., (*7)

$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);

The Versions

16/11 2015

dev-master

9999999-dev https://github.com/threadmeup/slack-sdk

Slack.com SDK

  Sources   Download

MIT

The Requires

 

api sdk slack slack-sdk slack-api threadmeup

30/07 2014

1.1.3

1.1.3.0 https://github.com/threadmeup/slack-sdk

Slack.com SDK

  Sources   Download

MIT

The Requires

 

api sdk slack slack-sdk slack-api threadmeup

12/03 2014

1.1.2

1.1.2.0 https://github.com/threadmeup/slack-sdk

Slack.com SDK

  Sources   Download

MIT

The Requires

 

api sdk slack slack-sdk slack-api threadmeup

12/03 2014
12/03 2014
01/03 2014