nexylan / slack-bundle
nextylan/slack 库的 Symfony 扩展包集成
v2.3.0
2021-03-31 13:25 UTC
Requires
- php: ^7.4 || ^8.0
- nexylan/slack: ^3.0
- php-http/discovery: ^1.6
- php-http/httplug: ^2.0
- php-http/httplug-bundle: ^1.17
- symfony/http-kernel: ^3.4 || ^4.0 || ^5.0
Requires (Dev)
- http-interop/http-factory-guzzle: ^1.0
- matthiasnoback/symfony-dependency-injection-test: ^4.0
- php-http/guzzle6-adapter: ^1.1.1 || ^2.0
- php-http/mock-client: ^1.1
- phpunit/phpunit: ^8.4
- symfony/framework-bundle: ^3.4 || ^4.4 || ^5.0
Suggests
- eightpoints/guzzle-bundle: Make a custom Guzzle instance for Slack with ease
README
nextylan/slack 库的 Symfony 扩展包集成(旧流行 maknz/slack
)。
文档
所有的安装和使用说明都位于本 README 中。请查看特定版本
先决条件
本项目版本需要
- PHP 7.1+
- Symfony 3.4+
安装
首先,您需要通过 composer 引入此库
$ composer require nexylan/slack-bundle php-http/guzzle6-adapter
为什么是 php-http/guzzle6-adapter
? 我们通过 HTTPlug 与任何 HTTP 消息客户端解耦。
然后,在 AppKernel
类中启用此扩展包
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Http\HttplugBundle\HttplugBundle(), new Nexy\SlackBundle\NexySlackBundle(), ); // ... return $bundles }
配置
如果尚未完成,您必须首先配置 httplug-bundle。请参阅此处的官方文档。
根据您的需求配置此扩展包(示例使用默认值)
nexy_slack: # If you want to use an another httplug client service. http: client: httplug.client # The Slack API Incoming WebHooks URL. endpoint: ~ # Required channel: null username: null icon: null link_names: false unfurl_links: false unfurl_media: true allow_markdown: true markdown_in_attachments: []
除 endpoint
外,所有其他配置键都与 Slack 客户端默认设置相关。
所有这些设置在 nexylan/slack 文档 中都有描述。
用法
可以从 nexy_slack.client
服务获取 Slack 客户端实例。
以下是一个示例
<?php namespace AppBundle\Controller; use Nexy\Slack\Attachment; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { $slack = $this->get('nexy_slack.client'); $message = $slack->createMessage(); $message ->to('#test') ->from('John Doe') ->withIcon(':ghost:') ->setText('This is an amazing message!') ; $message->attach((new Attachment()) ->setFallback('Some fallback text') ->setText('The attachment text') ); $slack->sendMessage($message); } }
有关如何操作 Slack 客户端的更多信息,请参阅 nexylan/slack 文档。