Noizu.Slack (Noizu.Slack v0.1.0)

Copy Markdown View Source

Slack Web API client for Elixir.

Req-based, explicit-client design (no global state): build a Noizu.Slack.Client and pass it as the first argument to every Web API call. Every call returns {:ok, map} or {:error, %Noizu.Slack.Error{}} — never raises (except *_stream enumeration, which raises the error mid-stream).

Quick start

# config/runtime.exs (optional — SLACK_BOT_TOKEN is read as a fallback)
config :noizu_slack, :client, token: System.get_env("SLACK_BOT_TOKEN")

client = Noizu.Slack.client()

{:ok, %{"user_id" => bot}} = Noizu.Slack.Auth.test(client)

{:ok, %{"ts" => ts}} =
  Noizu.Slack.Chat.post_message(client, "C0123456", "Deploy *finished*")

blocks = Noizu.Slack.Mrkdwn.to_blocks("# Release\n\n- **api** shipped\n- see [run](https://example.com)")
{:ok, _} = Noizu.Slack.Chat.post_message(client, "C0123456", %{text: "Release", blocks: blocks}, thread_ts: ts)

Noizu.Slack.Conversations.history_stream(client, "C0123456", limit: 200) |> Enum.take(1000)

{:ok, _} = Noizu.Slack.Files.upload(client, "C0123456", %{filename: "r.csv", content: csv})

:ok = Noizu.Slack.Signature.verify(signing_secret, ts_header, raw_body, sig_header)

Architecture

ModuleRole
Noizu.Slack.Clienttoken / base URL / user agent / Req passthrough / retry config
Noizu.Slack.RequestGET/POST engine, ok-envelope decoding, bounded 429 retry
Noizu.Slack.Paginationlazy response_metadata.next_cursor streams
Noizu.Slack.Errorstructured error (tag, reason, status, body)
Noizu.Slack.Authauth.test
Noizu.Slack.Chatchat.postMessage / update / delete / postEphemeral
Noizu.Slack.Conversationsconversations.list / info / history / replies / join / members
Noizu.Slack.Usersusers.list / info / lookupByEmail
Noizu.Slack.Searchsearch.messages (user token)
Noizu.Slack.Reactionsreactions.add / remove
Noizu.Slack.Pinspins.add
Noizu.Slack.Filesexternal upload flow (getUploadURLExternal → bytes → completeUploadExternal)
Noizu.Slack.Webhookincoming webhooks (no client)
Noizu.Slack.Signaturev0 request signature verification
Noizu.Slack.BlocksBlock Kit builders + limit validation
Noizu.Slack.MrkdwnGitHub markdown → mrkdwn / section blocks

Summary

Functions

Builds a client from options / application config / SLACK_BOT_TOKEN. See Noizu.Slack.Client.new/1.

Functions

client(opts \\ [])

@spec client(keyword()) :: Noizu.Slack.Client.t()

Builds a client from options / application config / SLACK_BOT_TOKEN. See Noizu.Slack.Client.new/1.