aranyasen/laravel-slack is a Laravel package for a package to send messages to slack.
It currently has 0 GitHub stars and 1.379 downloads on Packagist (latest version 1.1.1).
Install it with composer require aranyasen/laravel-slack.
Discover more Laravel packages by aranyasen
or browse all Laravel packages to compare alternatives.
Last updated
This package allows you to easily compose and send Slack messages from Laravel applications
Step-1:
composer require aranyasen/laravel-slack
Step-2: Publish the config:
php artisan vendor:publish --provider=Aranyasen\\LaravelSlack\\SlackServiceProvider
It creates config/laravel-slack.php.
Step-3:
Add parameters SLACK_WORKSPACE and SLACK_TOKEN in .env
(See reference below on how to generate a Slack API token)
// Send a simple message to a channel, say "some-channel"
(new SlackNotification())
->channel('some-channel')
->text("Hello!")
->send();
// Send a section (Ref: https://api.slack.com/reference/block-kit/blocks#section)
(new SlackNotification())
->channel('some-channel')
->section() // Starts a section
->fields() // Starts a field in this section
->markdown(":fire: @here This is an emergency :fire:")
->endFields()
->endSection()
->send();
// Send a raw JSON block (example from https://api.slack.com/block-kit/building#block_basics)
(new SlackNotification())
->channel('some-channel')
->block([
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "New Paid Time Off request from <example.com|Fred Enriquez>\n\n<https://example.com|View request>",
],
])
->send();
// Compose a message and dump the JSON that'll be sent to Slack. Useful for debugging.
(new SlackNotification())
->channel('some-channel')
->text("Hello!")
->dump();
// Upload a file
(new SlackNotification())
->channel('some-channel')
->file($filePath, 'Some filename')
->upload();
// Optionally, a title, or an accompanying message can be added with a file
(new SlackNotification())
->channel('some-channel')
->file($filePath, 'Some filename')
->withInitialComment('some comment')
->withTitle('some title')
->upload();
channel() -> Channel
header() -> Create a header section
context() -> A small footer text
divider() -> A horizontal line
section() / endSection() --> A section block
lists() -> List of items
field() / endfield() --> Inside section
markdown() -> A markdown block, allowed only inside a section
block() -> Pre-composed block
send() -> Send to Slack
dump() -> Dump the final JSON that'd be sent to Slack API
file() -> Upload a file
withInitialComment() -> Add a message with a file upload
withTitle() -> Add a title with file upload
Invoke SlackNotification::fake() to ensure HTTP requests to Slack are mocked. Internally it uses Laravel's Http::fake(),
so all available Http::assert* methods can be used for assertions.
Example:
SlackNotification::fake();
(new SlackNotification())
->channel('channel-1')
->send();
Http::assertSent(static fn(Request $request) => $request['channel'] === 'channel-1');
chat.write and chat.write.public.channels.read, users.read may be needed in future versions of this package, but not now)