threadmeup/slack-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

threadmeup/slack-sdk

最新稳定版本:1.1.3

Composer 安装命令:

composer require threadmeup/slack-sdk

包简介

Slack SDK for PHP

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Simple SDK for interacting with Slack.com via the API and webhooks.

Install

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

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

$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)
{
    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.

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

统计信息

  • 总下载量: 89.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 34
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 34
  • Watchers: 8
  • Forks: 20
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-12