PHP code example of cromwell / slacker

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

    

cromwell / slacker example snippets




tup with a configured Guzzle client
$slacker = new \Slacker\Slack(
    $config['webhook'],
    new \GuzzleHttp\Client()
);

// or with a default Guzzle client you need not pass it in
$slacker = new \Slacker\Slack($config['webhook']);

$slacker
    ->channel('#general')
    ->username('Slacker')
    ->message('Hello, #general')
    ->send();

// Or simpler, using the defaults chosen for the webook within Slack:
$slacker->message('Hello!')->send();




ig =  setup
$slackPoster = new \Slacker\SlackPoster(
    new \GuzzleHttp\Client(),
    $config['hookUri']
);

$payload = new \Slacker\Payload\Payload();
$payload->username = $config['username'];
$payload->channel = $config['channel'];

// specific message setup
$payload->text = 'General Message Text';

$attachment = new \Slacker\Payload\Attachment();
$attachment->color = 'good';
$attachment->fallback = 'some fallback message';

$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message';
$field->title = 'Field Title';
$field->value = 'Field Value';
$attachment->addField($field);

$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message 2';
$field->title = 'Field Title 2';
$field->value = 'Field Value 2';
$attachment->addField($field);

$field = new \Slacker\Payload\Field();
$field->short = 'Field Short Message 3';
$field->title = 'Field Title 3';
$field->value = 'Field Value 3';
$attachment->addField($field);

$payload->addAttachment($attachment);

// send the message
$slackPoster->send($payload);