insidieux / slack-api
此包已被弃用且不再维护。未建议替代包。
简单的 Slack API 客户端,带有预定义的方法
1.4.2
2021-02-08 12:38 UTC
Requires
- php: >=5.5.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- codacy/coverage: dev-master
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.*
- squizlabs/php_codesniffer: ~2.3
README
该项目非常过时,落后于当前实际的 PHP 版本以及 Slack API 的当前版本。我们强烈不建议您使用此库,并建议您切换到官方 Slack 文档中发布的任何包 - https://api.slack.com/community#php |
---|
一个简单的 PHP 包,用于向 Slack API 发送请求,侧重于易用性和优雅的语法。
要求
- PHP 5.5 或更高版本
- PHP 的 CURL 扩展
安装
您可以使用 Composer 包管理器安装此包。您可以在项目根目录中运行以下命令进行安装
composer require insidieux/slack-api
用法
创建 API 客户端
$client = new \SlackApi\Client('your-token-here');
发送请求
$client = new \SlackApi\Client('your-token-here'); $response = $client->request('module.method', ['argument' => 'value']); $response->toArray();
或者,您可以使用预定义的模块和方法
$client = new \SlackApi\Client('your-token-here'); $response = $client->users()->getList(); $response->toArray()
预定义模块
- [channels] (https://api.slack.com/methods#channels)
- [chat] (https://api.slack.com/methods#chat)
- [dnd] (https://api.slack.com/methods#dnd)
- [emoji] (https://api.slack.com/methods#emoji)
- [files] (https://api.slack.com/methods#files)
- [groups] (https://api.slack.com/methods#groups)
- [im] (https://api.slack.com/methods#im)
- [oauth] (https://api.slack.com/methods#oauth)
- [pins] (https://api.slack.com/methods#pins)
- [search] (https://api.slack.com/methods#search)
- [team] (https://api.slack.com/methods#team)
- [usergroups] (https://api.slack.com/methods#usergroups)
- [users] (https://api.slack.com/methods#users)
消息和附件对象
创建消息对象
$client = new \SlackApi\Client('your-token-here'); $message = new \SlackApi\Models\Message($client);
或者
$client = new \SlackApi\Client('your-token-here'); $message = $client->makeMessage();
从数组创建新的附件
$data = [ 'fallback' => 'Some fallback' 'pretext' => 'Some pretext', 'text' => 'good', 'text' => 'Some text' ]; $attachment1 = new \SlackApi\Models\Attachment($data);
或者使用设置方法
$attachment2 = new \SlackApi\Models\Attachment; $attachment2->setText('Some text') ->setColor(\SlackApi\Models\Attachment::COLOR_GOOD) ->setFallback('Some fallback');
向附件添加字段
$field = new \SlackApi\Models\AttachmentField; $field->setShort(false) ->setTitle('Field title') ->setValue('Field value'); $attachment->addField($field);
将对象附加到消息
$message->attach($attachment);
发送消息
$response = $message->send(); $response->toArray()