PHP code example of howyi / slack-monitor

1. Go to this page and download the library: Download howyi/slack-monitor 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/ */

    

howyi / slack-monitor example snippets


// Return the greeting bot

$monitor = new \ServiceMonitor\Slack\SlackMonitor(getenv('SLACK_TOKEN'));

$event = new class extends \ServiceMonitor\Slack\SlackEvent
{
    public function isExecutable(array $value): bool
    {
        if (!isset($value['type']) or !isset($value['text'])) {
            return false;
        }
        return (('message' === $value['type']) and ('hello' === $value['text']));
    }

    public function execute(array $value): void
    {
        echo("User:{$value['user']} greeted :)" . PHP_EOL);

        $this->commander->execute('chat.postMessage', [
            'channel' => $value['channel'],
            'text'    => "Hello, {$value['user']}!"
        ]);
    }
};

$monitor->setEvent($event);
$monitor->start();