Slink.SocketMode (Slink v0.1.0)

Copy Markdown View Source

Socket Mode transport: a GenServer that keeps a WebSocket open to Slack.

It opens a connection URL via apps.connections.open, upgrades to a WebSocket with Mint.WebSocket, acknowledges every envelope immediately (Slack requires an ACK within 3 seconds), and dispatches the decoded event to your module off-process. Slack's periodic disconnect refreshes and dropped connections are handled by transparently reconnecting.

Add it to a supervision tree:

{Slink.SocketMode,
 module: MyBot,
 app_token: System.fetch_env!("SLACK_APP_TOKEN"),
 bot_token: System.fetch_env!("SLACK_BOT_TOKEN")}

Options:

  • :module (required) — a module implementing the Slink behaviour.
  • :app_token (required) — app-level token (xapp-…, connections:write).
  • :bot_token — bot token (xoxb-…) passed to handlers for Web API calls.
  • :name — process name (defaults to Slink.SocketMode; pass nil to run unregistered, e.g. to run several clients at once).
  • :join — a list of channel IDs to conversations.join once connected (requires the channels:join scope). Defaults to [].
  • :open_connection — a 0-arity function returning {:ok, ws_url} used to obtain the WebSocket URL. Defaults to calling apps.connections.open with :app_token. Primarily a testing seam.
  • :verbose — when true, log every incoming WebSocket frame at :info (raw text for text frames). Useful for debugging what Slack actually delivers. Defaults to false.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)