walkboy/yii2-slack

Yii2 slack client

Installs: 49

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 10

Type:extension

1.0.1 2022-11-08 05:09 UTC

This package is auto-updated.

Last update: 2024-05-08 08:34:37 UTC


README

Designed to send messages to slack messenger

How it looks

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' => [],
            ],
        ],
    ],
],
...