{"id":18457430,"url":"https://github.com/pingcheng/slack-slash-command","last_synced_at":"2025-04-22T23:18:12.258Z","repository":{"id":57041696,"uuid":"163281423","full_name":"pingcheng/slack-slash-command","owner":"pingcheng","description":"Easy and fast Slack slash command for Laravel :postbox:","archived":false,"fork":false,"pushed_at":"2019-04-25T13:39:16.000Z","size":52,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T23:18:08.627Z","etag":null,"topics":["slack","slack-api","slack-slash-command","slack-slash-commands","slash-command"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pingcheng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T10:31:45.000Z","updated_at":"2019-04-12T00:52:50.000Z","dependencies_parsed_at":"2022-08-24T00:51:24.787Z","dependency_job_id":null,"html_url":"https://github.com/pingcheng/slack-slash-command","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pingcheng%2Fslack-slash-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pingcheng%2Fslack-slash-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pingcheng%2Fslack-slash-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pingcheng%2Fslack-slash-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pingcheng","download_url":"https://codeload.github.com/pingcheng/slack-slash-command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337961,"owners_count":21414105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["slack","slack-api","slack-slash-command","slack-slash-commands","slash-command"],"created_at":"2024-11-06T08:14:20.154Z","updated_at":"2025-04-22T23:18:12.241Z","avatar_url":"https://github.com/pingcheng.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/pingcheng/slack-slash-command/gh-pages/images/logo.png\" width=478\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://travis-ci.org/pingcheng/slack-slash-command.svg?branch=master\"\u003e\n    \u003cimg src='https://coveralls.io/repos/github/pingcheng/slack-slash-command/badge.svg?branch=master' alt='Coverage Status'\u003e\n    \u003cimg src=\"https://poser.pugx.org/pingcheng/slack-slash-command/v/stable\"\u003e\n    \u003cimg src=\"https://poser.pugx.org/pingcheng/slack-slash-command/license\"\u003e\n\u003c/p\u003e\n\n## Introduction\n\nSlack 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.\n\n\n\n## Installation\n\n1. Slach Slash Command recommends using composer to handling the package control, use the following command to add this package to your project\n\n   ```bash\n   composer require pingcheng/slack-slash-command\n   ```\n\n2. Add service provider to ```config/app.php```\n\n   ```\n   PingCheng\\SlackSlashCommand\\SlackSlashCommandServiceProvider::class,\n   ```\n\n3. Publish config file\n\n   ```bash\n   php artisan vendor:publish --provider=\"PingCheng\\SlackSlashCommand\\SlackSlashCommandServiceProvider\" --tag=config\n   ```\n\n4. Define your ```.env``` \n\n   ```shell\n   SLACK_SIGNING_SECRET=*YOUR SLACK APP SIGNING SECRET*\n   ```\n\n\n\n## Your first slash command\n\n1. Create your command extends from ```PingCheng\\SlackSlashCommand\\SlackSlashCommand```\n\n   ```php\n   \u003c?php\n   \n   namespace App\\Slack\\Commands;\n   \n   use Illuminate\\Notifications\\Messages\\SlackMessage;\n   use PingCheng\\SlackSlashCommand\\SlackSlashCommand;\n   \n   class SampleCommand extends SlackSlashCommand\n   {\n       public function handle() {\n           // process your command logic here...\n   \n           // you can return plain text as the response\n           // return \"Hi, I received your slash command\";\n   \n           // or, you can return a Laravel Slack Message object\n           return (new SlackMessage)\n               -\u003esuccess()\n               -\u003econtent(\"Got your slash command! :smirk:\")\n               -\u003eattachment(function ($attachment) {\n                   $attachment-\u003etitle('Details')\n                       -\u003efields([\n                           'Username' =\u003e $this-\u003euser_name,\n                           'User ID' =\u003e $this-\u003euser_id,\n                           'Channel Name' =\u003e $this-\u003echannel_name,\n                           'Channel ID' =\u003e $this-\u003echannel_id,\n                       ]);\n               });\n       }\n   }\n   ```\n\n2. Edit config file ```config/slackslashcommand.php```\n\n   ```php\n   \u003c?php\n   \n   return [\n       \n       // the collection of your slack command\n       // the array key is the command name (defined in your slack app console)\n       'commands' =\u003e [\n           'greeting' =\u003e \\App\\Slack\\Commands\\SampleCommand::class,\n       ],\n   \n       'signing_secret' =\u003e env('SLACK_SIGNING_SECRET'),\n   ];\n   ```\n\n3. Create a controller for your slack slash command\n\n   ```php\n   \u003c?php\n   \n   namespace App\\Http\\Controllers;\n   \n   use PingCheng\\SlackSlashCommand\\CommandManager;\n   use PingCheng\\SlackSlashCommand\\Exceptions\\CommandNotFoundException;\n   use PingCheng\\SlackSlashCommand\\Exceptions\\InvalidHeadersException;\n   \n   class SlackController extends Controller\n   {\n       public function slashCommand() {\n           try {\n               // simple run CommandManager::run()\n               // the manager would check the command list\n               // and run the related command\n               return CommandManager::run();\n           } catch (CommandNotFoundException $e) {\n               // would trigger if the command is not found\n               return $e-\u003egetMessage();\n           } catch (InvalidHeadersException $e) {\n               // would trigger if the slack verfication is failed to meet\n               return $e-\u003egetMessage();\n           }\n       }\n   }\n   ```\n\n4. Add route to your ```routes/web.php``` or ```routes/api.php```\n\n   ```php\n   // You can define your own route\n   Route::post('slack/slashcommand', 'SlackController@slashCommand');\n   ```\n\n\n\n## Permission control\n\nYou can easily control your slash command accessibility\n\n### Via Channel ID\n\n```php\nclass SampleCommand extends SlackSlashCommand\n{\n    // accepts array, only defined channel ids are allowed to execute this command\n    protected $limit_on_channel_ids = ['channel_id_1', 'channel_id_2'];\n    \n    public function handle() {\n        // command handler\n    }\n}\n```\n\n### Via User ID\n\n```php\nclass SampleCommand extends SlackSlashCommand\n{\n    // accepts array, only defined user ids are allowed to execute this command\nprotected $limit_on_user_ids = ['user_id_1', 'user_id_2'];\n    \n    public function handle() {\n        // command handler\n    }\n}\n```\n\n\n\n## Questions?\n\nIf you have any questions, please email me ping.che@hotmail.com or leave an issue, I would respond as soon as possible :smile:","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpingcheng%2Fslack-slash-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpingcheng%2Fslack-slash-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpingcheng%2Fslack-slash-command/lists"}