Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pingcheng/slack-slash-command

Easy and fast Slack slash command for Laravel :postbox:
https://github.com/pingcheng/slack-slash-command

slack slack-api slack-slash-command slack-slash-commands slash-command

Last synced: about 2 months ago
JSON representation

Easy and fast Slack slash command for Laravel :postbox:

Awesome Lists containing this project

README

        






Coverage Status


## Introduction

Slack Slash Command is a Laravel package that helps developer integrate the slash command to their Laravel applications. For more information about Slack slash command, please visit: https://api.slack.com/slash-commands.

## Installation

1. Slach Slash Command recommends using composer to handling the package control, use the following command to add this package to your project

```bash
composer require pingcheng/slack-slash-command
```

2. Add service provider to ```config/app.php```

```
PingCheng\SlackSlashCommand\SlackSlashCommandServiceProvider::class,
```

3. Publish config file

```bash
php artisan vendor:publish --provider="PingCheng\SlackSlashCommand\SlackSlashCommandServiceProvider" --tag=config
```

4. Define your ```.env```

```shell
SLACK_SIGNING_SECRET=*YOUR SLACK APP SIGNING SECRET*
```

## Your first slash command

1. Create your command extends from ```PingCheng\SlackSlashCommand\SlackSlashCommand```

```php
success()
->content("Got your slash command! :smirk:")
->attachment(function ($attachment) {
$attachment->title('Details')
->fields([
'Username' => $this->user_name,
'User ID' => $this->user_id,
'Channel Name' => $this->channel_name,
'Channel ID' => $this->channel_id,
]);
});
}
}
```

2. Edit config file ```config/slackslashcommand.php```

```php
[
'greeting' => \App\Slack\Commands\SampleCommand::class,
],

'signing_secret' => env('SLACK_SIGNING_SECRET'),
];
```

3. Create a controller for your slack slash command

```php
getMessage();
} catch (InvalidHeadersException $e) {
// would trigger if the slack verfication is failed to meet
return $e->getMessage();
}
}
}
```

4. Add route to your ```routes/web.php``` or ```routes/api.php```

```php
// You can define your own route
Route::post('slack/slashcommand', 'SlackController@slashCommand');
```

## Permission control

You can easily control your slash command accessibility

### Via Channel ID

```php
class SampleCommand extends SlackSlashCommand
{
// accepts array, only defined channel ids are allowed to execute this command
protected $limit_on_channel_ids = ['channel_id_1', 'channel_id_2'];

public function handle() {
// command handler
}
}
```

### Via User ID

```php
class SampleCommand extends SlackSlashCommand
{
// accepts array, only defined user ids are allowed to execute this command
protected $limit_on_user_ids = ['user_id_1', 'user_id_2'];

public function handle() {
// command handler
}
}
```

## Questions?

If you have any questions, please email me [email protected] or leave an issue, I would respond as soon as possible :smile: