PHPackages                             stechstudio/slack-laravel-api - 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. stechstudio/slack-laravel-api

ActiveLibrary[API Development](/categories/api)

stechstudio/slack-laravel-api
=============================

Slack SDK for writing our own Slack App integrations.

v4.0.0(4y ago)1635[1 issues](https://github.com/stechstudio/slack-laravel-api/issues)MITPHPCI failing

Since Mar 7Pushed 4y ago5 watchersCompare

[ Source](https://github.com/stechstudio/slack-laravel-api)[ Packagist](https://packagist.org/packages/stechstudio/slack-laravel-api)[ RSS](/packages/stechstudio-slack-laravel-api/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (12)Versions (11)Used By (0)

Slack Laravel API
=================

[](#slack-laravel-api)

Easily handle Slack web hook requests via Laravel style routing with Middleware authentication. If you have ever implemented a webhook for Slack, you're going to want to try this.

Versions and compatibility
--------------------------

[](#versions-and-compatibility)

- **PHP Version**: *&gt;=8.0*
- **Laravel**: *^7.0|^8.0*

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

[](#installation)

#### Composer

[](#composer)

```
composer require stechstudio/slack-laravel-api
```

Configuration
-------------

[](#configuration)

#### .env

[](#env)

On each HTTP request that Slack sends, they [add an X-Slack-Signature HTTP header](https://api.slack.com/docs/verifying-requests-from-slack#about). The signature is created by combining the signing secret with the body of the request we're sending using a standard HMAC-SHA256 keyed hash.

It is this signing secret that is used by the middleware to authenticate the request:

```
SLACK_SIGNING_SECRET="slacksecretestringhere"
```

#### Publish Slack Routes

[](#publish-slack-routes)

```
artisan vendor:publish --provider=slack-routes
```

Usage
-----

[](#usage)

After publishing the Slack Routes you can look in `base('routes/slack.php')` to find the API route and some working examples of Slack routes.

#### Web Route

[](#web-route)

```
/*
|--------------------------------------------------------------------------
| Slack Webhook Routes
|--------------------------------------------------------------------------
|
| Here is where you can register Slack routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "slack" middleware group. Enjoy building your API!
|
*/

Route::middleware('slack')->match(['get', 'post'], '/slack/api', 'STS\Slack\Http\Controllers\Slack@webhook');
```

By default, your application will have **GET|POST|HEAD** methods on the `slack/api` URI that will pass everything to `STS\Slack\Http\Controllers\Slack@webhook` via the **slack** middleware.

You may modify the URI or even add addition routes for other endpoints.

#### Slack Command Routes

[](#slack-command-routes)

```
use STS\Slack\Facades\SlackRoute;
use STS\Slack\SlashCommands\Echoes;

/*
|--------------------------------------------------------------------------
| Slack Command Routes
|--------------------------------------------------------------------------
|
| Here is where you can register Slack commands for your application.
|
*/
SlackRoute::handles('/hello', function (SlashCommand $slashCommand) {
    return 'Hello World';
});

SlackRoute::handles('/echo', Echoes::class);
```

These are working examples, and if you setup both Slack slash commands to use the configured URI, simply typing `/hello` or `/echo yoodle` will trigger the appropriate response.

The `SlackRoute::handles()` expects you to provide a command that matches the slash command in Slack, along with a Callable to handle the command.

This is best demonstrated in the Echo command sample.

```
