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

1.0.3 2018-09-12 22:58 UTC


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.


You will need to supply a Guzzle client (v6.x) to send the Slack messages.


The recommended way of installing the Slack Message Builder package is through Composer:

Require the package via Composer in your composer.json

    "require": {
        "hampel/slack-message": "~1.0"

Run Composer to update the new requirement.

$ composer update


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) {
		->attachment(function ($attachment) {
				->title('Laravel', 'https://laravel.com')
				->content('Attachment Content')
				->fallback('Attachment Fallback')
					'Project' => 'Laravel',
				->author('Author', 'https://laravel.com/fake_author', 'https://laravel.com/fake_author.png')

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