yiier/yii2-slack

Yii2 slack client based library

Installs: 15 853

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

v1.1.0 2016-07-22 03:25 UTC

This package is auto-updated.

Last update: 2024-12-26 00:42:54 UTC


README

Designed to send messages to slack messenger

How it looks

Installation

php composer.phar require --prefer-dist yiier/yii2-slack "*"

Also, you should configure incoming webhook inside your Slack team.

Usage

Configure component:

...
    'components' => [
        'slack' => [
            'httpClient' => ['class' => 'Curl\Curl'],
            'class' => 'yiier\slack\Client',
            '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:', [
    [
        // attachment object
        'text' => 'text of attachment',
        'pretext' => 'pretext here',
    ],
]);

To learn more about attachments, read Slack documentation

Also you can use slack as a log target:

...
'components' => [
    'log' => [
        'traceLevel' => 3,
        'targets' => [
            [
                'class' => 'yiier\slack\LogTarget',
                'categories' => ['commandBus'],
                'exportInterval' => 1, // Send logs on every message
                'logVars' => [],
            ],
        ],
    ],
],
...

or

...
'components' => [
    'log' => [
        'traceLevel' => 3,
        [
            'class' => 'yiier\slack\LogTarget',
            'levels' => ['error'],
            'enabled' => true,
            'emoji' => ':beetle:',
            'logMessage' => '错误信息',
            'categories' => [
                'yii\db\*',
                'yii\web\HttpException:*',
                'error',
            ],
            'except' => [
                'yii\web\HttpException:404', // 除了404错误
            ],
            'exportInterval' => 1, // Send logs on every message
            'logVars' => [],
        ],
    ],
],
...

Credits

Understeam/yii2-slack