Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-06-10T02:06:46.000Z (over 1 year ago)
- Last Synced: 2024-11-24T09:46:51.444Z (2 months 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
=====================[![Latest Version on Packagist](https://img.shields.io/packagist/v/hampel/slack-message.svg?style=flat-square)](https://packagist.org/packages/hampel/slack-message)
[![Total Downloads](https://img.shields.io/packagist/dt/hampel/slack-message.svg?style=flat-square)](https://packagist.org/packages/hampel/slack-message)
[![Open Issues](https://img.shields.io/github/issues-raw/hampel/slack-message.svg?style=flat-square)](https://github.com/hampel/slack-message/issues)
[![License](https://img.shields.io/packagist/l/hampel/slack-message.svg?style=flat-square)](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:[email protected]) based on code by [Taylor Otwell](mailto:[email protected]) 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)