jeremykenedy / slack-laravel by jeremykenedy

Laravel integration for the jeremykenedy/slack package, including facades and service providers.
594,880
54
5
Package Data
Maintainer Username: jeremykenedy
Maintainer Contact: github@mak.geek.nz (maknz)
Package Create Date: 2017-07-21
Package Last Update: 2021-01-23
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-09 03:01:59
Package Statistics
Total Downloads: 594,880
Monthly Downloads: 8,097
Daily Downloads: 275
Total Stars: 54
Total Watchers: 5
Total Forks: 17
Total Open Issues: 2

Slack for Laravel

Total Downloads Latest Stable Version License: MIT

Laravel 5 integration for the Slack, including facades and service providers. This package allows you to use Slack for PHP easily and elegantly in your Laravel 5 app.

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.

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

  • In the controller file that you will use this be sure to include the `Slack class in the head of the file:
use Slack;

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 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

  • Full 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!