Slink.API (Slink v0.1.0)

Copy Markdown View Source

A thin Slack Web API client built on Req.

Slack Web API methods are POSTs to https://slack.com/api/<method> with a bearer token. Note that Slack returns HTTP 200 even on logical failures — the real status is in the "ok" field of the JSON body, which the helpers here surface as {:error, reason}.

Tokens:

  • apps.connections.open needs an app-level token (xapp-…).
  • Everything else (e.g. chat.postMessage) needs a bot token (xoxb-…).

Summary

Functions

Add an emoji reaction (name, no colons) to the message at channel/timestamp via reactions.add. Needs the reactions:write scope.

Call any Web API method. Returns {:ok, body} when Slack replies ok: true, otherwise {:error, reason} (the Slack error string, or a transport error).

Open a Socket Mode WebSocket URL via apps.connections.open.

Post a message with chat.postMessage.

Remove a reaction added with add_reaction/4, via reactions.remove.

Functions

add_reaction(bot_token, channel, timestamp, name)

@spec add_reaction(String.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, term()}

Add an emoji reaction (name, no colons) to the message at channel/timestamp via reactions.add. Needs the reactions:write scope.

call(token, method, params)

@spec call(String.t(), String.t(), map()) :: {:ok, map()} | {:error, term()}

Call any Web API method. Returns {:ok, body} when Slack replies ok: true, otherwise {:error, reason} (the Slack error string, or a transport error).

open_connection(app_token)

@spec open_connection(String.t()) :: {:ok, String.t()} | {:error, term()}

Open a Socket Mode WebSocket URL via apps.connections.open.

Pass an app-level token (xapp-…) with the connections:write scope.

post_message(bot_token, channel, text, opts \\ %{})

@spec post_message(String.t(), String.t(), String.t(), map()) ::
  {:ok, map()} | {:error, term()}

Post a message with chat.postMessage.

opts is merged into the request body (e.g. %{thread_ts: ..., blocks: ...}).

remove_reaction(bot_token, channel, timestamp, name)

@spec remove_reaction(String.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, term()}

Remove a reaction added with add_reaction/4, via reactions.remove.