walkboy / yii2-slack
Yii2 slack client
1.0.1
2022-11-08 05:09 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: >=2.0.0
- yiisoft/yii2-httpclient: ^2.0.0
This package is auto-updated.
Last update: 2025-05-08 10:43:54 UTC
README
Designed to send messages to slack messenger
Based on unmaintained https://github.com/Understeam/yii2-slack
Installation
composer require walkboy/yii2-slack:^1.0
Also, you should configure incoming webhook inside your Slack team.
Usage
First of all, configure yiisoft/yii2-httpclient component:
... 'components' => [ 'httpclient' => [ 'class' => 'yii\httpclient\Client', ], ], ...
Also you can set it up only inside of slack client:
... 'components' => [ 'slack' => [ 'httpclient' => [ 'class' => 'yii\httpclient\Client', ], ... ], ], ...
Configure component:
... 'components' => [ 'slack' => [ 'class' => 'walkboy\slack\Slack', 'url' => '<slack incoming webhook url here>', 'username' => 'My awesome application', ], ], ...
Now you can send messages right into slack channel via next command:
Yii::$app->slack->send('Hello', ':thumbs_up:', [ // block object 1 [ 'type' => 'context', 'elements' => [ [ 'type' => 'mrkdwn', 'text' => 'Your markdown text here', ] ], ], // block object 2 [ 'type' => 'divider', ] ]);
To learn more about blocks, read Slack documentation
Also you can use slack as a log target:
... 'components' => [ 'log' => [ 'traceLevel' => 3, 'targets' => [ [ 'class' => 'walkboy\slack\LogTarget', 'categories' => ['commandBus'], 'exportInterval' => 1, // Send logs on every message 'logVars' => [], ], ], ], ], ...