ambikuk/yii2-slack

Yii2 slack client based library

Maintainers

Details

github.com/ambikuk/yii2-slack

Installs: 5 024

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Type:yii2-extension

0.1.0 2017-07-27 08:50 UTC

This package is not auto-updated.

Last update: 2020-11-28 07:44:51 UTC


README

Installation

add

"ambikuk/yii2-slack": "*"

to the require section of your composer.json file.

this extension just wrapper to https://github.com/maknz/slack

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

Usage

Configure component:

...
    'components' => [
        'slack' => [
            'class' => 'ambikuk\yiislack\Slack',
            'url' => '<slack incoming webhook url here>',
            'username' => 'Slack Bot',
            'channel' => '#channel'
        ],
    ],
...

Now you can send messages right into slack channel via next command:

Yii::$app->slack->send('New alert from the monitoring system', [
    'fallback' => 'Current server stats',
    'text' => 'Current server stats',
    'color' => 'danger',
    'fields' => [
        [
          'title' => 'CPU usage',
          'value' => '90%',
          'short' => true // whether the field is short enough to sit side-by-side other fields, defaults to false
        ],
        [
          'title' => 'RAM usage',
          'value' => '2.5GB of 4GB',
          'short' => true
        ]
    ]
]);

Use custom settings

$slack = Yii::$app->slack;
$slack->setSetting([
    'username' => 'Jack',
    'channel' => '#mychannel'
]);
$slack->send('Are we rich yet?');

Use Maknz\Slack\Client functions

$slack = Yii::$app->slack->getClient();
$slack->to('@username')->send('Yo!');