ambikuk/yii2-slack

Yii2 slack client based library

Installs: 9 129

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

0.1.0 2017-07-27 08:50 UTC

This package is not auto-updated.

Last update: 2024-04-14 01:36:10 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!');