tiagomichaelsousa / slack-client
用于PHP的Slack SDK
v0.3.0
2023-07-03 22:02 UTC
Requires
- php: ^8.1.0
- nesbot/carbon: ^2.67
- nyholm/psr7: ^1.8
- php-http/discovery: ^1.18.1
- php-http/multipart-stream-builder: ^1.3.0
- psr/http-client: ^1.0.2
- psr/http-client-implementation: ^1.0.1
- psr/http-factory-implementation: *
- psr/http-message: ^1.1.0|^2.0.0
- symfony/http-client: ^6.2
Requires (Dev)
- guzzlehttp/guzzle: ^7.6.1
- guzzlehttp/psr7: ^2.5.0
- laravel/pint: ^1.10.0
- nunomaduro/collision: ^7.5.2
- pestphp/pest: ^2.6.1
- pestphp/pest-plugin-arch: ^2.1.2
- pestphp/pest-plugin-mock: ^2.0.0
- phpstan/phpstan: ^1.10.15
- rector/rector: ^0.17.0
- symfony/var-dumper: ^6.2.10
This package is auto-updated.
Last update: 2024-09-02 01:59:40 UTC
README
Slack Client 是一个非官方的PHP API客户端,允许您与 Slack API ⚡️ 交互
此包仍在开发中。 可能还有尚未实现的方法。
开始使用
Slack Client的官方文档将很快可用。 👀
在此期间,您仍可以使用 users()
、conversations()
和 reminders()
方法探索SDK开发体验 🚀
需要 PHP 8.1+
首先,通过 Composer 包管理器安装Slack Client
composer require tiagomichaelsousa/slack-client
之后,您就可以与Slack的API进行交互
$client = Slack::client($token); $conversations = $client->conversations()->create('foo'); echo $conversations->channel->name;
如有必要,您可以配置和创建一个独立的客户端。
$client = Slack::factory() ->withApiKey($token) ->withBaseUri('slack.com/api/v2') // default: slack.com/api ->withHttpClient($client = new \GuzzleHttp\Client([])) // default: HTTP client found using PSR-18 HTTP Client ->withHttpHeader('X-My-Header', 'foo') ->withQueryParam('foo', 'bar') ->withStreamHandler(fn (RequestInterface $request): ResponseInterface => $client->send($request, [ 'stream' => true // Allows to provide a custom stream handler for the http client. ])) ->make();
测试
此客户端通过 Slack\Client
类提供了一种轻松伪造API响应的方式。
在使用此功能之前,请确保在您的测试用例中将 Slack\Client
替换为 Slack\Testing\ClientFake
。
除了这个有用的测试类之外,您还可以根据您的用例轻松生成响应对象并提供相关信息。所有响应都有 fake()
方法来轻松覆盖对象。
use Slack\Testing\ClientFake; use Slack\Responses\Conversation\CreateConversationResponse; $client = new ClientFake([ CreateConversationResponse::fake([ 'channel' => [ 'name' => 'foo', ], ]); ]); $conversations = $client->conversations()->create('foo'); expect($conversations->channel)->name->toBe('foo');
Slack Client的官方文档将很快可用。 👀
Slack Client是一个开源软件,许可协议为 MIT许可。