glyde/api/webhook

A webhook’s id and token together are one major parameter, so two webhooks never share a bucket. They are one credential too, which is why they come in here as a single Credential. That credential is in the path, so these calls send no Authorization header whatever the rest.Config holds: a 401 means the webhook was deleted or its token rotated, never that the bot token is bad. error.is_path_token_dead is the predicate for that, and error.is_token_fatal answers False for it.

glyde/api/interaction is these same seven routes with the application id and the interaction token in place of the webhook’s.

thread means two things. On execute and execute_and_wait it is the thread to post into; on the six message routes it says which thread the target message is in. Either way the thread must be on the webhook’s channel: Discord ignores it off a text channel, and answers 404 for a thread anywhere else.

Types

A webhook’s id and its token. One value, so the id of one webhook cannot go out with the token of another. A closure, not a field, because echo and string.inspect read straight through an opaque record.

pub opaque type Credential

Values

pub fn application_credential(
  application: id.Id(id.Application),
  token: String,
) -> Credential

Interaction follow-ups are these routes with the application id where the webhook id belongs. That is Discord’s own spelling, so the retag lives here rather than at each call site.

pub fn credential(
  webhook_id: id.Id(id.Webhook),
  token: String,
) -> Credential
pub fn delete_message(
  credential: Credential,
  message: id.Id(id.Message),
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(Nil)
pub fn delete_original_message(
  credential: Credential,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(Nil)
pub fn edit_message(
  credential: Credential,
  message: id.Id(id.Message),
  body: body.Body,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(message.Message)
pub fn edit_original_message(
  credential: Credential,
  body: body.Body,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(message.Message)

PATCH /webhooks/{webhook.id}/{webhook.token}/messages/@original. An attachments array is the complete list of files to keep.

pub fn execute(
  credential: Credential,
  body: body.Body,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(Nil)

POST /webhooks/{webhook.id}/{webhook.token}. Answers 204 with no body: use execute_and_wait to get the message back.

pub fn execute_and_wait(
  credential: Credential,
  body: body.Body,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(message.Message)

POST /webhooks/{webhook.id}/{webhook.token}?wait=true, which answers 200 with the message instead of 204 with nothing.

pub fn get_message(
  credential: Credential,
  message: id.Id(id.Message),
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(message.Message)
pub fn get_original_message(
  credential: Credential,
  thread thread: option.Option(id.Id(id.Channel)),
) -> rest.Call(message.Message)
Search Document