septech-php / slack
一个简单、有意义的 Slack 客户端
v0.3.0
2021-04-08 06:06 UTC
Requires
- guzzlehttp/guzzle: ^6.0 | ^7.0
- illuminate/support: ^v5.8 | ^v6.0 | ^v7.0 | ^v8.0
This package is auto-updated.
Last update: 2024-09-08 13:12:43 UTC
README
这是一个简单的 Slack 客户端。感谢 Slack 团队努力工作,提供了一个简单明了的 API 文档。此外,我们还有一些库帮助我们更方便地与 Slack API 交互。
然而,有时候我并不能完全享受这些。在我自我成长的过程中,有时候需要更多。我需要一个库,它能让我知道可以向 Slack 发送的所有字段,同时还需要一个最小化的设置。这就是我决定自己创建一个库的原因。尝试创建一个干净、有意义的 API。希望你会喜欢它。
是的。目前,它还不够完美。
但是请相信我,它会越来越好。
示例
<?php use Slack\Block; use Slack\Message; use Slack\Client; use Slack\Markdown; use Slack\Block\Section; use Slack\Block\Actions; use Slack\Block\Button; use Illuminate\Support\Carbon; use Slack\File; $channel = '#your-channel-name'; // $channel = 'your-channel-name'; // $channel = 'CHANNEL_ID'; $client = new Client('your-client-id'); $message = new Message; $message->channel = $channel; $snipet = <<<SNIPPET <?php class File extends Element { public \$type = 'file'; public \$external_id; public \$source; public \$block_id; public function __construct(string \$external_id, string \$source, string \$block_id = null) { \$this->external_id = \$external_id; \$this->source = \$source; \$this->block_id = \$block_id; } } SNIPPET; $report = File::content($snipet); // File::fromPath('/some/file/path') $report->channels = $channel; // OPTIONAL: set a name for report file $report->filename = 'sippet'; $report->filetype = 'php'; $lines = [ 'Hi '. Markdown::here(), sprintf(':spiral_calendar_pad: *Running Time:* %s', Carbon::now()->format(Carbon::RFC822)), ':stopwatch: *Duration*: 10 mins 2 seconds', ':package: *Environment*: production' ]; $blocks[] = Section::markdown(Markdown::multiLines($lines)); if ($file = $client->uploadFile($report)) { $blocks[] = Section::markdown( Markdown::link($file->url_private, 'View logs on browser :google-chrome:') ); $blocks[] = Actions::actions( Button::primary('Download logs', $file->url_private_download) ); } $blocks[] = Section::markdown( Markdown::multiLines([ Markdown::quote(':ami-ok: *Success:* 10'), Markdown::quote(':ami-what3: *Failed:* 2'), Markdown::quote(':ami-what2: *Skipped:* 3'), Markdown::quote(':dollar: *Total amount:* $1.000'), ]) ); $blocks[] = Block::divider(); $blocks[] = Section::markdown( Markdown::multiLines([ Markdown::italic('italic'), Markdown::bold('bold'), Markdown::strike('strike'), Markdown::inlineCode('inline_code'), Markdown::codeBlock('some code block'), Markdown::bold('Characters: '), Markdown::lists([ 'Alice', 'Bob', 'Claura' ]), ]) ); $message->blocks($blocks); $client->postMessage($message);