Slink.EventsApi.Plug (Slink v0.1.0)

Copy Markdown View Source

Events API transport: a Plug that receives Slack's HTTP event callbacks.

It verifies Slack's request signature, answers the url_verification challenge, responds 200 immediately, and dispatches the event off-process (so your handler can't blow Slack's ~3s response budget).

Mount it in a router:

forward "/slack/events", to: Slink.EventsApi.Plug,
  init_opts: [
    module: MyBot,
    signing_secret: System.fetch_env!("SLACK_SIGNING_SECRET"),
    bot_token: System.fetch_env!("SLACK_BOT_TOKEN")
  ]

Or run it standalone with Bandit:

Bandit.start_link(
  plug: {Slink.EventsApi.Plug,
         module: MyBot,
         signing_secret: System.fetch_env!("SLACK_SIGNING_SECRET"),
         bot_token: System.fetch_env!("SLACK_BOT_TOKEN")},
  port: 4000
)

Options:

  • :module (required) — a module implementing the Slink behaviour.
  • :signing_secret (required) — the app's Signing Secret, for request verification.
  • :bot_token — bot token (xoxb-…) passed to handlers for Web API calls.

Slash commands & interactivity

Those payloads arrive application/x-www-form-urlencoded, not JSON. This plug handles the JSON Events API. Decode x-www-form-urlencoded bodies (the payload field holds JSON) before reaching here to support them.