PHP code example of ambikuk / yii2-slack

1. Go to this page and download the library: Download ambikuk/yii2-slack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ambikuk / yii2-slack example snippets


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

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
        ]
    ]
]);

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

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