Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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:
- Host: GitHub
- URL: https://github.com/pingcheng/slack-slash-command
- Owner: pingcheng
- License: mit
- Created: 2018-12-27T10:31:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T13:39:16.000Z (over 5 years ago)
- Last Synced: 2024-04-25T12:21:10.714Z (8 months ago)
- Topics: slack, slack-api, slack-slash-command, slack-slash-commands, slash-command
- Language: PHP
- Homepage:
- Size: 50.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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: