Noizu.Discord.Webhooks (Noizu.Discord v0.1.0)

Copy Markdown View Source

Webhook endpoints.

execute/3 needs no bot token — the webhook token in the URL is the credential. Treat webhook URLs as secrets.

Summary

Functions

POST /channels/{channel.id}/webhooks — create a webhook. params: %{name, avatar}. Accepts :reason (audit log).

POST /webhooks/{webhook.id}/{webhook.token} — execute a webhook.

GET /channels/{channel.id}/webhooks — the channel's webhooks.

Parses a webhook URL or {id, token} into {:ok, {id, token}}.

Types

target()

@type target() :: String.t() | {String.t(), String.t()}

Functions

create(client, channel_id, params, opts \\ [])

POST /channels/{channel.id}/webhooks — create a webhook. params: %{name, avatar}. Accepts :reason (audit log).

execute(target, params, opts \\ [])

@spec execute(target(), map(), keyword()) :: Noizu.Discord.Request.result()

POST /webhooks/{webhook.id}/{webhook.token} — execute a webhook.

target is a full webhook URL (https://discord.com/api/webhooks/<id>/<token>) or an {id, token} tuple. params: %{content, embeds, username, avatar_url, thread_id, allowed_mentions, components, thread_name, flags} — thread_id is sent as a query parameter as Discord requires.

Opts:

  • :wait — default true (Discord returns the created message); false returns {:ok, nil}.
  • :client — a Noizu.Discord.Client whose base_url, user_agent, req_options and retry are used (its token is never sent). Without it a client is built from :base_url / :req_options / :retry opts.
  • :meta.

The request always goes to the client's base_url; only id + token are taken from a URL target.

list_channel(client, channel_id, opts \\ [])

GET /channels/{channel.id}/webhooks — the channel's webhooks.

parse_target(url)

@spec parse_target(target()) ::
  {:ok, {String.t(), String.t()}} | {:error, Noizu.Discord.Error.t()}

Parses a webhook URL or {id, token} into {:ok, {id, token}}.