PHP code example of septech-php / slack

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

    

septech-php / slack example snippets




use Slack\Block;
use Slack\Message;
use Slack\Client;
use Slack\Markdown;
use Slack\Block\Section;
use Slack\Block\Actions;
use Slack\Block\Button;
use Illuminate\Support\Carbon;
use Slack\File;

$channel = '#your-channel-name';
// $channel = 'your-channel-name';
// $channel = 'CHANNEL_ID';

$client = new Client('your-client-id');

$message = new Message;
$message->channel = $channel;

$snipet = <<<SNIPPET


class File extends Element
{
    public \$type = 'file';

    public \$external_id;

    public \$source;

    public \$block_id;

    public function __construct(string \$external_id, string \$source, string \$block_id = null)
    {
        \$this->external_id = \$external_id;
        \$this->source = \$source;
        \$this->block_id = \$block_id;
    }
}
SNIPPET;

$report = File::content($snipet);
// File::fromPath('/some/file/path')
$report->channels = $channel;

// OPTIONAL: set a name for report file
$report->filename = 'sippet';
$report->filetype = 'php';

$lines = [
    'Hi '. Markdown::here(),
    sprintf(':spiral_calendar_pad: *Running Time:* %s', Carbon::now()->format(Carbon::RFC822)),
    ':stopwatch: *Duration*: 10 mins 2 seconds',
    ':package: *Environment*: production'
];

$blocks[] = Section::markdown(Markdown::multiLines($lines));

if ($file = $client->uploadFile($report)) {
    $blocks[] = Section::markdown(
        Markdown::link($file->url_private, 'View logs on browser :google-chrome:')
    );
    $blocks[] = Actions::actions(
        Button::primary('Download logs', $file->url_private_download)
    );
}

$blocks[] = Section::markdown(
    Markdown::multiLines([
        Markdown::quote(':ami-ok: *Success:* 10'),
        Markdown::quote(':ami-what3: *Failed:* 2'),
        Markdown::quote(':ami-what2: *Skipped:* 3'),
        Markdown::quote(':dollar: *Total amount:* $1.000'),
    ])
);

$blocks[] = Block::divider();

$blocks[] = Section::markdown(
    Markdown::multiLines([
        Markdown::italic('italic'),
        Markdown::bold('bold'),
        Markdown::strike('strike'),
        Markdown::inlineCode('inline_code'),
        Markdown::codeBlock('some code block'),
        Markdown::bold('Characters: '),
        Markdown::lists([
            'Alice',
            'Bob',
            'Claura'
        ]),
    ])
);

$message->blocks($blocks);

$client->postMessage($message);