https://github.com/hampel/slack-message
Standalone implementation of Laravel's SlackMessage classes from illuminate/notifications
https://github.com/hampel/slack-message
laravel notifications slack
Last synced: about 2 months ago
JSON representation
Standalone implementation of Laravel's SlackMessage classes from illuminate/notifications
- Host: GitHub
- URL: https://github.com/hampel/slack-message
- Owner: hampel
- License: mit
- Created: 2023-06-09T08:00:10.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-10T02:06:46.000Z (about 3 years ago)
- Last Synced: 2025-03-09T20:02:26.703Z (over 1 year ago)
- Topics: laravel, notifications, slack
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Slack Message Builder
=====================
[](https://packagist.org/packages/hampel/slack-message)
[](https://packagist.org/packages/hampel/slack-message)
[](https://github.com/hampel/slack-message/issues)
[](https://packagist.org/packages/hampel/slack-message)
Standalone implementation of Laravel's SlackMessage classes from
[illuminate/notifications](https://github.com/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](https://api.slack.com/incoming-webhooks), but can also be used with API
calls.
By [Simon Hampel](mailto:simon@hampelgroup.com) based on code by [Taylor Otwell](mailto:taylor@laravel.com) and licensed
under the [MIT license](https://opensource.org/licenses/MIT).
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](https://laravel.com/docs/6.x/notifications#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.
```php
use Carbon\Carbon;
use GuzzleHttp\Client;
use Hampel\SlackMessage\SlackMessage;
use Hampel\SlackMessage\SlackWebhook;
$url = 'https://hooks.slack.com/services/';
$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
----------
* [Slack API documentation](https://api.slack.com/)
* Slack API: [An introduction to messages](https://api.slack.com/docs/messages)
* Laravel: [Slack Notifications](https://laravel.com/docs/6.x/notifications#slack-notifications)
* Laravel Package: [laravel/slack-notification-channel](https://github.com/laravel/slack-notification-channel)