PHPackages                             meilleursbiens/laravel-slack-events - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. meilleursbiens/laravel-slack-events

ActiveLibrary[API Development](/categories/api)

meilleursbiens/laravel-slack-events
===================================

Handle Slack Events in Laravel easily

1.0.3(1y ago)13.8k↓35%1MITPHP

Since Oct 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MeilleursBiens/laravel-slack-events)[ Packagist](https://packagist.org/packages/meilleursbiens/laravel-slack-events)[ RSS](/packages/meilleursbiens-laravel-slack-events/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (3)Used By (0)

Slack Events API for Laravel
============================

[](#slack-events-api-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/0ec3d2f514be8b87fdd531ed200b9c1236b3416efab8707a487629f373101d4a/68747470733a2f2f706f7365722e707567782e6f72672f6d65696c6c657572736269656e732f6c61726176656c2d736c61636b2d6576656e74732f762f737461626c65)](https://packagist.org/packages/meilleursbiens/laravel-slack-events)[![License](https://camo.githubusercontent.com/633e45ad374f7d89b03924870911ca9aa2d7d4bc0fcc925709408b0ce5c09020/68747470733a2f2f706f7365722e707567782e6f72672f6d65696c6c657572736269656e732f6c61726176656c2d736c61636b2d6576656e74732f6c6963656e7365)](https://packagist.org/packages/meilleursbiens/laravel-slack-events)

*Work with Slack Events API as easily as with native Laravel 10 events and event listeners.*

### Reasons to use this package for the [Slack Events API](https://api.slack.com/events-api)

[](#reasons-to-use-this-package-for-the-slack-events-api)

- Based on native Laravel Events
- Supports all Slack Event types (including events for new Workspace Apps!)
- Supports token validation
- Supports URL verification and "challenge" requests
- PSR compatible code
- Full documentation
- Almost full test coverage
- Lots of emoji in the documentation (even cats! 🐈)

Installation
------------

[](#installation)

**1)** Require the package with Composer

```
composer require meilleursbiens/laravel-slack-events
```

**2)** If you're using Laravel version 5.5 or higher, the SlackEventsServiceProvider will be automatically discovered. Get started fast!

**3)** If you're using a version of Laravel lower than 5.5, you'll still have to register the service provider manually. Open `config/app.php` and add `\MeilleursBiens\LaravelSlackEvents\SlackEventsServiceProvider::class` to the `providers[]` array.

*For example:*

```
// ...

'providers' => [
// ...
// A whole bunch of providers
// ...

\MeilleursBiens\LaravelSlackEvents\SlackEventsServiceProvider::class,
],

// ...
```

If you are using Laravel 5.3 or higher, you will find a comment in `config/app.php` with text like `/* Package Service Providers... */`, which can help you find the right place.

**4)** Publish the config file

```
php artisan vendor:publish
```

Choose the option for the Service Provider, or find `slack-events` in the `Tag:` list at the bottom.

Next we'll configure some settings to use the [Slack API](https://api.slack.com).

**5)** Create an App or Open an Existing One If you want to work with Slack's new *Workspace Apps*, read over the information in the [Developer Preview](https://api.slack.com/workspace-apps-preview) for Workspace Apps, and create a new *workspace token* App to get started.

If you're not using a Workspace App, open the [Slack Apps](https://api.slack.com/apps) page and create a new *user token* App.

If you want to modify an existing app to use with Slack-Events, you can find both *Workspace Token* Apps and *User Token* Apps on the [Your Apps](https://api.slack.com/apps) page.

**6)** Once you've created or opened your app you should see the *Basic Information* page. Scroll down to the "App Credentials" section, and copy the *Verification Token* at the bottom.

[![verification_token](https://cloud.githubusercontent.com/assets/8103985/17901937/ebdbdb3e-696d-11e6-96b4-b0794d74ed9a.png)](https://cloud.githubusercontent.com/assets/8103985/17901937/ebdbdb3e-696d-11e6-96b4-b0794d74ed9a.png)

Open `.env` and paste your Verification Token under the `'SLACK_EVENT_TOKEN'` key:

```
SLACK_EVENT_TOKEN=your-token
```

**7)** Now open the "Event Subscriptions" page. Here you must enable events, add events you wish to listen for and set **Request URL**. Request URL is the `'route'` key in your `config/slackEvents.php` file:

```
return [
    /*
    |-------------------------------------------------------------
    | Your validation token from "App Credentials"
    |-------------------------------------------------------------
    */
    'token' => env('SLACK_EVENT_TOKEN', 'your-validation-token-here'),

    /*
    |-------------------------------------------------------------
    | Events Request URL — path, where events will be served
    |-------------------------------------------------------------
    */
    'route' => '/api/slack/event/fire', // data` instead of `$event->event`.public $type;This reflects the type of callback you're receiving.public $authed\_users;An array of string-based User IDs.For example, if you want to get the reaction name from [reaction\_added](https://api.slack.com/events/reaction_added) event, you can get it from the `ReactionAdded` event class like this:

```
$reactionAdded->event['reaction']; // reaction name, something like :thumbsup:
```

So, suppose we want to make a `reaction_added` Slack Event listener. What do we need to do?

### Example

[](#example)

**1)** Open the `App/Listeners` directory (or create it if it doesn't exist). Now create a new file and call it `ReactionAddedListener.php`. Paste in this code:

```
