{"id":23003741,"url":"https://github.com/stechstudio/slack-laravel-api","last_synced_at":"2025-06-18T03:33:37.430Z","repository":{"id":49478613,"uuid":"171558542","full_name":"stechstudio/slack-laravel-api","owner":"stechstudio","description":"Laravelized Slack PHP Api","archived":false,"fork":false,"pushed_at":"2021-06-18T13:40:03.000Z","size":108,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-06T08:38:52.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/stechstudio.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":"2019-02-19T22:14:46.000Z","updated_at":"2022-04-30T17:19:47.000Z","dependencies_parsed_at":"2022-08-24T07:30:38.489Z","dependency_job_id":null,"html_url":"https://github.com/stechstudio/slack-laravel-api","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/stechstudio/slack-laravel-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Fslack-laravel-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Fslack-laravel-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Fslack-laravel-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Fslack-laravel-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stechstudio","download_url":"https://codeload.github.com/stechstudio/slack-laravel-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Fslack-laravel-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260481995,"owners_count":23015846,"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":[],"created_at":"2024-12-15T07:15:12.351Z","updated_at":"2025-06-18T03:33:32.418Z","avatar_url":"https://github.com/stechstudio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slack Laravel API\n\nEasily 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.\n\n## Versions and compatibility\n\n- **PHP Version**: _\u003e=8.0_\n- **Laravel**: _^7.0|^8.0_\n\n## Installation\n\n#### Composer\n\n```bash\ncomposer require stechstudio/slack-laravel-api\n```\n\n## Configuration\n\n#### .env\n\nOn 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.\n\nIt is this signing secret that is used by the middleware to authenticate the request:\n\n```ini\nSLACK_SIGNING_SECRET=\"slacksecretestringhere\"\n```\n\n#### Publish Slack Routes\n\n```bash\nartisan vendor:publish --provider=slack-routes\n```\n\n## Usage\n\nAfter publishing the Slack Routes you can look in `base('routes/slack.php')` to find the API route and some working examples of Slack routes.\n\n#### Web Route\n\n```php\n/*\n|--------------------------------------------------------------------------\n| Slack Webhook Routes\n|--------------------------------------------------------------------------\n|\n| Here is where you can register Slack routes for your application. These\n| routes are loaded by the RouteServiceProvider within a group which\n| is assigned the \"slack\" middleware group. Enjoy building your API!\n|\n*/\n\nRoute::middleware('slack')-\u003ematch(['get', 'post'], '/slack/api', 'STS\\Slack\\Http\\Controllers\\Slack@webhook');\n```\n\nBy 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.\n\nYou may modify the URI or even add addition routes for other endpoints.\n\n#### Slack Command Routes\n\n```php\nuse STS\\Slack\\Facades\\SlackRoute;\nuse STS\\Slack\\SlashCommands\\Echoes;\n\n/*\n|--------------------------------------------------------------------------\n| Slack Command Routes\n|--------------------------------------------------------------------------\n|\n| Here is where you can register Slack commands for your application.\n|\n*/\nSlackRoute::handles('/hello', function (SlashCommand $slashCommand) {\n    return 'Hello World';\n});\n\nSlackRoute::handles('/echo', Echoes::class);\n```\n\nThese 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.\n\nThe `SlackRoute::handles()` expects you to provide a command that matches the slash command in Slack, along with a Callable to handle the command.\n\nThis is best demonstrated in the Echo command sample.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace STS\\Slack\\SlashCommands;\n\nuse Illuminate\\Support\\Facades\\Log;\nuse STS\\Slack\\Contracts\\Messaging\\Message as SlackMessage;\nuse STS\\Slack\\Contracts\\SlashCommands\\ControllerI;\nuse STS\\Slack\\Messaging\\LayoutBlocks\\Context;\nuse STS\\Slack\\Messaging\\LayoutBlocks\\Section;\nuse STS\\Slack\\Messaging\\Message;\nuse STS\\Slack\\Models\\SlashCommand;\nuse function json_encode;\n\nclass Echoes implements ControllerI\n{\n\n    public function handle(SlashCommand $slashCommand): SlackMessage\n    {\n        return $slashCommand-\u003ecreateMessage('*Echo:*  ' . $slashCommand-\u003egetText())\n            -\u003eaddImage(\n                'https://cdn.cp.adobe.io/content/2/dcx/9ed8e319-b714-4c8d-b9d5-7a6d419e50b3/rendition/preview.jpg/version/0/format/jpg/dimension/width/size/1200',\n                'Echo Hacker'\n            )\n            -\u003eaddSection('*Slack Parameters* ', function(Section $section) use($slashCommand) {\n                $section\n                    -\u003eaddText(\"*Team ID*: {$slashCommand-\u003egetTeamId()}\")\n                    -\u003eaddText(\"*Team Domain*: {$slashCommand-\u003egetTeamDomain()}\")\n                    -\u003eaddText(\"*Channel ID*: {$slashCommand-\u003egetChannelId()}\")\n                    -\u003eaddText(\"*Channel Name*: {$slashCommand-\u003egetChannelName()}\")\n                    -\u003eaddText(\"*User ID*: {$slashCommand-\u003egetUserId()}\")\n                    -\u003eaddText(\"*User Name*: {$slashCommand-\u003egetUserName()}\")\n                    -\u003eaddText(\"*Command*: {$slashCommand-\u003egetCommand()}\");\n            })\n            -\u003eaddSection(\"*Your Text*\\n{$slashCommand-\u003egetText()}\")\n            -\u003eaddDivider()\n            -\u003eaddContext(function(Context $context) {\n                $context\n                    -\u003eaddImage(\n                        'https://avatars.slack-edge.com/2019-02-19/556373803382_e2c54afedc2a4fb73ccd_512.png',\n                        'The Commander Logo'\n                    )\n                    -\u003eaddText('slack-laravel-api echo handler');\n            })\n            -\u003etap(function(Message $message) {\n                Log::warning(json_encode($message-\u003etoSlackObjectArray()));\n            });\n    }\n}\n```\n\nFirst note that your Command must implement `STS\\Slack\\Contracts\\SlashCommands\\ControllerI` in order to be valid. This ensures that we have a `handle()` that takes a **SlashCommand** and returns a **SlackMessage.**\n\nAs you can see, the **SlashCommand** provides access to everything that Slack sends you. The two most commonly used will be:\n\n- `$slashCommand-\u003egetCommand()`\n- `$slashCommand-\u003egetText()`\n\nAssume the user typed `/echo yoodle ay e who` into Slack to trigger this. Then `getCommand()` would return `/echo` and `getText()` returns `yoodle ay e who`. We often then parse the text for sub-commands.\n\nThe `SlackMessage` class is a fairly powerful wrapper around the [Building Block message layout format specified by the Slack API](https://api.slack.com/messaging/composing/layouts). Anything you can do with the blocks, you can do with this class.\n\n## Conclusion\n\nThat's it, handle your command and return a Slack-formatted message with Laravel middleware authenticating each Slack call for you and some handy classes to make handling these things easier.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Fslack-laravel-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstechstudio%2Fslack-laravel-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Fslack-laravel-api/lists"}