jeremykenedy / slack-laravel
Laravel integration for the jeremykenedy/slack package, including facades and service providers.
Fund package maintenance!
jeremykenedy
Patreon
Installs: 594 680
Dependents: 0
Suggesters: 1
Security: 0
Stars: 54
Watchers: 5
Forks: 17
Open Issues: 2
Requires
- php: >=5.6.4
- jeremykenedy/slack: ~2.0
This package is auto-updated.
Last update: 2024-10-20 03:12:08 UTC
README
Slack for Laravel
Laravel integration for the Slack, including facades and service providers. This package allows you to use Slack for PHP easily and elegantly in your Laravel app.
- Slack for Laravel
Requirements
Installation
1. From your projects root folder in terminal run:
composer require jeremykenedy/slack-laravel
2a. Register App (Laravel 5.5 +)
Uses package auto discovery feature, no need to edit the config/app.php
file.
- Skip to 4. Publish Assets
2b. Register App (Laravel 5.4 and below)
Register the package with laravel in config/app.php
under providers
with the following:
'providers' => [ jeremykenedy\Slack\Laravel\ServiceProvider::class, ];
3. Register App Alias (Laravel 5.4 and below)
Register the package with laravel in config/app.php
under aliases
with the following:
'aliases' => [ 'Slack' => jeremykenedy\Slack\Laravel\Facade::class, ];
4. Publish Assets (All)
Publish the config file from your projects root folder in terminal by running:
php artisan vendor:publish --tag=slacklaravel
5. Create Webhook (All)
Create an incoming webhook for each Slack team you'd like to send messages to. You'll need the webhook URL(s) in order to configure this package.
6. Configure .env
(All)
Configure Slack for Laravel in your .env
file by adding and editing the following:
DEFAULT_SLACK_WEBHOOK_ENDPOINT=https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX DEFAULT_SLACK_CHANNEL='#general' DEFAULT_SLACK_USERNAME=Robot DEFAULT_SLACK_ICON=':ghost:' DEFAULT_SLACK_LINKNAMES_CONVERTED=FALSE DEFAULT_SLACK_UNFURL_LINKS_STATUS=FALSE DEFAULT_SLACK_UNFURL_MEDIA_STATUS=TRUE DEFAULT_SLACK_ALLOW_MARKDOWN=TRUE DEFAULT_SLACK_MARKDOWN_FIELDS="'text','title'"
Configuration
The config file comes with defaults and placeholders. Configure at least one team and any defaults you'd like to change.
Default configurations are published into config/slack.php
and the values can be set in the .env
file like so:
DEFAULT_SLACK_WEBHOOK_ENDPOINT=https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXX
DEFAULT_SLACK_CHANNEL='#general'
DEFAULT_SLACK_USERNAME=Robot
DEFAULT_SLACK_ICON=':ghost:'
DEFAULT_SLACK_LINKNAMES_CONVERTED=FALSE
DEFAULT_SLACK_UNFURL_LINKS_STATUS=FALSE
DEFAULT_SLACK_UNFURL_MEDIA_STATUS=TRUE
DEFAULT_SLACK_ALLOW_MARKDOWN=TRUE
DEFAULT_SLACK_MARKDOWN_FIELDS="'text','title'"
Usage
1. Include Class
- Use the facade anywhere:
\Slack::send('Hey');
2. Trigging Slack Messages
Send to Default Channel
- Send a message to the default channel
Slack::send('Hi Slack, from the API :)');
Send to Different Channel
- Send a message to a different channel
Slack::to('#testing')->send('Hi Testing!');
Send to Private Message
- Send a message to a private channel
Slack::to('@jeremykenedy')->send('Hi Jeremy!');
Faking in tests
Use the fake
method on the Facade
Slack::fake()
This provides the following
Slack::assertMessageSent(function($messages) { // search in all messages }); Slack::assertMessageSentTo($channel, function($messages) { // search in all messages posted to $channel });
Credits
- Most development credit must go to maknz.
- This package was forked and improved. The original package states that it was no longer maintained.
- This package was forked and modified to be compliant with MIT licencing standards for production use.
License
Slack for Laravel is licensed under the MIT license for both personal and commercial products. Enjoy!