LaravelPackages.net
Acme Inc.
Toggle sidebar
hampel/slack-message

Standalone implementation of Laravel's SlackMessage classes from illuminate/notifications

141
0
1.1.0
About hampel/slack-message

hampel/slack-message is a Laravel package for standalone implementation of laravel's slackmessage classes from illuminate/notifications. It currently has 0 GitHub stars and 141 downloads on Packagist (latest version 1.1.0). Install it with composer require hampel/slack-message. Discover more Laravel packages by hampel or browse all Laravel packages to compare alternatives.

Last updated

Slack Message Builder

Latest Version on Packagist Total Downloads Open Issues License

Standalone implementation of Laravel's SlackMessage classes from illuminate/notifications.

This package provides a mechanism for generating correctly formatted Slack messages and sending them via Guzzle. Ideal for use with simple Slack inbound webhooks, but can also be used with API calls.

By Simon Hampel based on code by Taylor Otwell and licensed under the MIT license.

Prerequisites

You will need to supply a Guzzle client (^6.0|^7.0) to send the Slack messages.

Installation

To install using composer, run the following command:

composer require hampel/slack-message

Usage

Refer to Laravel's Slack Notifications documentation for information on generating Slack messages. The syntax is largely the same as that used by Laravel, but we do not need to use Notifiable classes - we can generate and send our Slack Messages directly.

use Carbon\Carbon;
use GuzzleHttp\Client;
use Hampel\SlackMessage\SlackMessage;
use Hampel\SlackMessage\SlackWebhook;

$url = 'https://hooks.slack.com/services/<Slack incoming webhook url>';
$slack = new SlackWebhook(new Client());

$message = $slack->message(function ($message) {
    $message
        ->content('Content')
        ->attachment(function ($attachment) {
            $attachment
                ->title('Laravel', 'https://laravel.com')
                ->content('Attachment Content')
                ->fallback('Attachment Fallback')
                ->fields([
                    'Project' => 'Laravel',
                ])
                ->footer('Laravel')
                ->footerIcon('https://laravel.com/fake.png')
                ->markdown(['text'])
                ->author('Author', 'https://laravel.com/fake_author', 'https://laravel.com/fake_author.png')
                ->timestamp(Carbon::now());
        });
});

$slack->send($url, $message);

References

Star History Chart