Download the PHP package aranyasen/laravel-slack without Composer
On this page you can find all versions of the php package aranyasen/laravel-slack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aranyasen/laravel-slack
More information about aranyasen/laravel-slack
Files in aranyasen/laravel-slack
Package laravel-slack
Short Description A package to send messages to Slack
License MIT
Informations about the package laravel-slack
Laravel Slack
This package allows you to easily compose and send Slack messages from Laravel applications
Installation
Step-1:
Step-2: Publish the config:
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)
Usage
APIs:
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
Testing:
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:
References:
To create a Slack API token
- Visit https://api.slack.com/apps
- If no app is present, create an app (you may select "from scratch")
- If the app was created earlier, select the app under App Name
- On the left pane, under "Features" click "OAuth & Permissions"
- Under Scopes > Bot Token Scopes, click Add an OAuth Scope
- Add these scopes:
chat.write
andchat.write.public
.
(note:channels.read
,users.read
may be needed in future versions of this package, but not now) - Click "reinstall your app" in the yellow bar that appears above
- In the dropdown "Search for a channel", select a channel. Any channel would do - won't matter now.
- Allow it
- Copy the "Bot User OAuth Token" and share
Links:
- Slack Block reference docs: https://api.slack.com/block-kit
- Emoji cheat-sheet: https://github.com/ikatyang/emoji-cheat-sheet
- Color bar not supported in block kits yet (ref: https://stackoverflow.com/a/74826061/2014868)