{"id":20746907,"url":"https://github.com/johnagan/slack-payload","last_synced_at":"2025-04-28T11:22:11.175Z","repository":{"id":57362750,"uuid":"82425927","full_name":"johnagan/slack-payload","owner":"johnagan","description":"A lightweight wrapper for Slack payloads to make working with events easier and consistent across schemas.","archived":false,"fork":false,"pushed_at":"2018-07-01T16:40:41.000Z","size":19,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T16:58:24.561Z","etag":null,"topics":["json","payload","slack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/johnagan.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":"2017-02-19T00:52:57.000Z","updated_at":"2023-03-04T18:21:47.000Z","dependencies_parsed_at":"2022-09-26T16:32:18.293Z","dependency_job_id":null,"html_url":"https://github.com/johnagan/slack-payload","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fslack-payload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fslack-payload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fslack-payload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnagan%2Fslack-payload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnagan","download_url":"https://codeload.github.com/johnagan/slack-payload/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225013991,"owners_count":17407157,"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":["json","payload","slack"],"created_at":"2024-11-17T08:09:50.335Z","updated_at":"2024-11-17T08:09:51.261Z","avatar_url":"https://github.com/johnagan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slack Payload Wrapper\n\nA lightweight wrapper for Slack payloads to make working with events easier and consistent across schemas.\n\n## Why?\n\nSlack has many events that POST to HTTPS endpoints, including [Slash Commands](https://api.slack.com/slash-commands), [Events API](https://api.slack.com/events-api), and [Interactive Messages](https://api.slack.com/docs/message-buttons). Each payload schema is slightly different and adds additional if/then logic to your endpoint functions.\n\nLet's use `user_id` as an example. If your endpoint needs this id, your logic might look something like this:\n\n```js\nfunction getUserId(payload) {\n  // Interactive Messages\n  if (payload.user) return payload.user.id\n\n  // Slash Commands\n  if (payload.user_id) return payload.user_id\n\n  // Events API\n  if (payload.event \u0026\u0026 payload.event.user) return payload.event.user\n  if (payload.event \u0026\u0026 payload.event.item) return payload.event.item.user\n}\n```\n\nSometimes even the payload itself requires work to use since it can be encoded then included in the `payload` field.\n```js\nif (event.payload)\n  payload = JSON.parse(event.payload)\n```\n\n## Example\n```js\nconst Payload = require('slack-payload'),\n\napp.post('/slack', (req, res) =\u003e {\n  let payload = new Payload(req.body)\n\n  // returns the message text no matter the event type\n  let text = payload.text\n\n  // check for the event type or values\n  let isCommand = payload.is('slash_command')\n  let isButtonClick = payload.is('message_button')\n  let isButtonValue = payload.is('my_button_value')\n\n  // perform regex on text messages\n  let match = payload.match(/lunch/i)\n\n  // determine if the event was caused by a bot\n  let bot_id = payload.bot_id\n\n})\n```\n\n## API\n\nProperty | Description\n---|---\n`text` | The message text associated with the event\n`team_id` | The team id the payload was sent from\n`channel_id` | The channel id the payload was sent from\n`user_id` | The user id that sent the payload (if available)\n`bot_id` | The bot id that sent the payload (if available)\n`selection` | The selected interactive message option\n`action` | The selected interactive message action\n`types` | An array of all types associated with this payload (includes a wildcard)\n\nFunction | Parameter | Description\n---|---|---\n`is` | event type [String] | Checks if the payload matches an event type. Get a full list of events [here](index.js#L197)\n`match` | regex | Matches the text with a regular expression\n\n## Install\n```\nnpm i slack-payload\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Fslack-payload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnagan%2Fslack-payload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnagan%2Fslack-payload/lists"}