commandos

Types

pub type InteractionError {
  CouldNotParseInteraction(json.DecodeError)
  CouldNotValidateSecurityHeaders(SecurityError)
}

Constructors

  • CouldNotParseInteraction(json.DecodeError)

    A properly validated request was made, but it couldn’t be parsed as an interaction.

    This isn’t to be expected too often.

    Returns a 400 “bad request” response.

  • CouldNotValidateSecurityHeaders(SecurityError)

    An error has happened while trying to verify the request’s security headers.

    This is to be expected - discord often does “tests”, verifying that your webhook validates security headers properly.

    Returns a 401 “unauthorized” response.

pub opaque type PublicKey
pub type PublicKeyValidationError {
  PublicKeyNotValidHexadecimal
  PublicKeyHasImproperLength
}

Constructors

  • PublicKeyNotValidHexadecimal

    The public key you provided is not a valid hexadecimal number.

  • PublicKeyHasImproperLength

    Your public key’s length as a number is not 32 bytes.

pub type SecurityError {
  HttpRequestSignatureNotProvided
  HttpRequestTimestampNotProvided
  HttpRequestSignatureNotValidHexadecimal
  HttpRequestVerificationFailed
}

Constructors

  • HttpRequestSignatureNotProvided

    A request was made without a x-signature-ed25519 header.

  • HttpRequestTimestampNotProvided

    A request was made without a x-signature-timestamp header.

  • HttpRequestSignatureNotValidHexadecimal

    A request was made where the x-signature-ed25519 was not a valid hexadecimal number.

  • HttpRequestVerificationFailed

    A request was made with the correct headers, however verifying that the message:

    • was intended for your app
    • was sent from Discord has failed.

    This could happen for several reasons:

    • an automated test was performed by Discord, verifying whether your app validates security headers (most common)
    • you provided an inappropriate public key (for example, another app’s)
    • there was a forgery attempt

Values

pub fn handle_interaction_request(
  request: request.Request(String),
  public_key public_key: PublicKey,
  handler next: fn(Result(grom.Interaction, InteractionError)) -> Nil,
) -> response.Response(String)
pub fn public_key_from_string(
  key: String,
) -> Result(PublicKey, PublicKeyValidationError)
✨ Search Document