grom/interaction

Types

pub type ButtonExecution {
  ButtonExecution(
    custom_id: String,
    resolved: option.Option(Resolved),
  )
}

Constructors

pub type ChannelSelectExecution {
  ChannelSelectExecution(
    custom_id: String,
    selected_channels_ids: List(String),
    resolved: option.Option(Resolved),
  )
}

Constructors

  • ChannelSelectExecution(
      custom_id: String,
      selected_channels_ids: List(String),
      resolved: option.Option(Resolved),
    )
pub type CheckboxGroupSubmission {
  CheckboxGroupSubmission(
    id: Int,
    custom_id: String,
    selected_values: List(String),
  )
}

Constructors

  • CheckboxGroupSubmission(
      id: Int,
      custom_id: String,
      selected_values: List(String),
    )
pub type CheckboxSubmission {
  CheckboxSubmission(
    id: Int,
    custom_id: String,
    is_selected: Bool,
  )
}

Constructors

  • CheckboxSubmission(id: Int, custom_id: String, is_selected: Bool)
pub type CommandExecution {
  SlashCommandExecuted(SlashCommandExecution)
  MessageCommandExecuted(MessageCommandExecution)
  UserCommandExecuted(UserCommandExecution)
}

Constructors

pub type Context {
  TriggeredInGuild
  TriggeredInBotDms
  TriggeredInPrivateChannel
}

Constructors

  • TriggeredInGuild
  • TriggeredInBotDms
  • TriggeredInPrivateChannel
pub type Data {
  CommandExecuted(CommandExecution)
  MessageComponentExecuted(MessageComponentExecution)
  ModalSubmitted(ModalSubmission)
}

Constructors

pub type FileUploadSubmission {
  FileUploadSubmission(
    id: Int,
    custom_id: String,
    uploaded_files_ids: List(String),
  )
}

Constructors

  • FileUploadSubmission(
      id: Int,
      custom_id: String,
      uploaded_files_ids: List(String),
    )
pub type Followup {
  Followup(
    content: option.Option(String),
    is_tts: Bool,
    embeds: option.Option(List(embed.Embed)),
    allowed_mentions: option.Option(
      allowed_mentions.AllowedMentions,
    ),
    components: option.Option(List(message.Component)),
    files: option.Option(List(file.File)),
    attachments: option.Option(List(attachment.Create)),
    flags: option.Option(List(FollowupFlag)),
    poll: option.Option(poll.Create),
  )
}

Constructors

pub type FollowupFlag {
  EphemeralFollowup
  FollowupWithSuppressedEmbeds
  FollowupWithSuppressedNotifications
  FollowupWithComponentsV2
}

Constructors

  • EphemeralFollowup
  • FollowupWithSuppressedEmbeds
  • FollowupWithSuppressedNotifications
  • FollowupWithComponentsV2
pub type HttpError {
  CouldNotParseInteraction(json.DecodeError)
  CouldNotValidateSecurityHeaders(HttpSecurityError)
}

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 422 unprocessable content response.

  • CouldNotValidateSecurityHeaders(HttpSecurityError)

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

    While some of these errors are to be expected, some are genuine bugs within your code.

    Check the inner field to check what error exactly happened.

pub type HttpSecurityError {
  PublicKeyNotValidHexadecimal
  PublicKeyHasImproperLength
  HttpRequestSignatureNotProvided
  HttpRequestTimestampNotProvided
  HttpRequestSignatureNotValidHexadecimal
  HttpRequestVerificationFailed
}

Constructors

  • PublicKeyNotValidHexadecimal

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

    This is not to be expected and results in a HTTP response with the status 500 - internal server error.

  • PublicKeyHasImproperLength

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

    This is not to be expected and results in a HTTP response with the status 500 - internal server error.

  • HttpRequestSignatureNotProvided

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

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

    Returns a 401 unauthorized response.

  • HttpRequestTimestampNotProvided

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

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

    Returns a 401 unauthorized response.

  • HttpRequestSignatureNotValidHexadecimal

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

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

    Returns a 401 unauthorized response.

  • 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

    Returns a 401 unauthorized response.

pub type Interaction {
  Interaction(
    id: String,
    application_id: String,
    data: Data,
    invokement_info: InvokementInfo,
    channel_id: String,
    token: String,
    message: option.Option(message.Message),
    application_permissions: List(permission.Permission),
    locale: String,
    entitlements: option.Option(List(entitlement.Entitlement)),
    authorizing_integration_owners_ids: dict.Dict(
      application.InstallationContext,
      String,
    ),
    context: option.Option(Context),
    attachment_size_limit_bytes: Int,
  )
}

Constructors

pub type InvokementInfo {
  InvokedInGuild(
    guild_id: String,
    member: guild_member.GuildMember,
    guild_locale: String,
  )
  InvokedInDm(user: user.User)
}

Constructors

pub type LabelSubmission {
  LabelSubmission(id: Int, component: SubmittedLabelComponent)
}

Constructors

pub type MentionableSelectExecution {
  MentionableSelectExecution(
    custom_id: String,
    selected_mentionables_ids: List(String),
    resolved: option.Option(Resolved),
  )
}

Constructors

  • MentionableSelectExecution(
      custom_id: String,
      selected_mentionables_ids: List(String),
      resolved: option.Option(Resolved),
    )
pub type MessageCommandExecution {
  MessageCommandExecution(
    id: String,
    name: String,
    resolved: option.Option(Resolved),
    registered_to_guild_id: option.Option(String),
    message_id: String,
  )
}

Constructors

pub type MessageComponentExecution {
  ButtonExecuted(ButtonExecution)
  StringSelectExecuted(StringSelectExecution)
  UserSelectExecuted(UserSelectExecution)
  RoleSelectExecuted(RoleSelectExecution)
  MentionableSelectExecuted(MentionableSelectExecution)
  ChannelSelectExecuted(ChannelSelectExecution)
}

Constructors

pub type ModalResponse {
  ModalResponse(
    custom_id: String,
    title: String,
    components: List(modal.Component),
  )
}

Constructors

  • ModalResponse(
      custom_id: String,
      title: String,
      components: List(modal.Component),
    )
pub type ModalSubmission {
  ModalSubmission(
    custom_id: String,
    components: List(SubmittedModalComponent),
    resolved: option.Option(Resolved),
  )
}

Constructors

pub type ModifyFollowupFlag {
  ModifyFollowupWithSuppressedEmbeds
}

Constructors

  • ModifyFollowupWithSuppressedEmbeds
pub type ModifyOriginalResponseFlag {
  ModifyResponseWithSuppressedEmbeds
  ModifyResponseWithComponentsV2
}

Constructors

  • ModifyResponseWithSuppressedEmbeds
  • ModifyResponseWithComponentsV2
pub type RadioGroupSubmission {
  RadioGroupSubmission(
    id: Int,
    custom_id: String,
    value: option.Option(String),
  )
}

Constructors

  • RadioGroupSubmission(
      id: Int,
      custom_id: String,
      value: option.Option(String),
    )
pub type Resolved {
  Resolved(
    users: option.Option(dict.Dict(String, user.User)),
    members: option.Option(
      dict.Dict(String, guild_member.GuildMember),
    ),
    roles: option.Option(dict.Dict(String, role.Role)),
    channels: option.Option(dict.Dict(String, ResolvedChannel)),
    messages: option.Option(dict.Dict(String, message.Message)),
    attachments: option.Option(
      dict.Dict(String, attachment.Attachment),
    ),
  )
}

Constructors

pub type ResolvedChannel {
  ResolvedTextChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedVoiceChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedCategoryChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedAnnouncementChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedAnnouncementThread(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
    metadata: thread.Metadata,
    parent_id: String,
  )
  ResolvedPublicThread(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
    metadata: thread.Metadata,
    parent_id: String,
  )
  ResolvedPrivateThread(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
    metadata: thread.Metadata,
    parent_id: String,
  )
  ResolvedStageChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedForumChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
  ResolvedMediaChannel(
    id: String,
    name: String,
    current_user_permissions: List(permission.Permission),
  )
}

Constructors

pub type Response {
  RespondWithChannelMessageWithSource(ResponseMessage)
  RespondWithDeferredChannelMessageWithSource(ResponseMessage)
  RespondWithDeferredUpdateMessage
  RespondWithUpdateMessage(ResponseMessage)
  RespondWithModal(ModalResponse)
}

Constructors

pub type ResponseMessage {
  ResponseMessage(
    is_tts: option.Option(Bool),
    content: option.Option(String),
    embeds: option.Option(List(embed.Embed)),
    allowed_mentions: option.Option(
      allowed_mentions.AllowedMentions,
    ),
    flags: option.Option(List(ResponseMessageFlag)),
    components: option.Option(List(message.Component)),
    attachments: option.Option(List(attachment.Create)),
    files: option.Option(List(file.File)),
    poll: option.Option(poll.Create),
  )
}

Constructors

pub type ResponseMessageFlag {
  ResponseMessageWithSuppressedEmbeds
  EphemeralResponseMessage
  ResponseMessageWithComponentsV2
  VoiceResponseMessage
  ResponseMessageWithSuppressedNotifications
}

Constructors

  • ResponseMessageWithSuppressedEmbeds
  • EphemeralResponseMessage
  • ResponseMessageWithComponentsV2
  • VoiceResponseMessage
  • ResponseMessageWithSuppressedNotifications
pub type RoleSelectExecution {
  RoleSelectExecution(
    custom_id: String,
    selected_roles_ids: List(String),
    resolved: option.Option(Resolved),
  )
}

Constructors

  • RoleSelectExecution(
      custom_id: String,
      selected_roles_ids: List(String),
      resolved: option.Option(Resolved),
    )
pub type SlashCommandExecution {
  SlashCommandExecution(
    id: String,
    name: String,
    resolved: option.Option(Resolved),
    options: List(SlashCommandOption),
    registered_to_guild_id: option.Option(String),
  )
}

Constructors

pub type SlashCommandOption {
  StringSlashCommandOption(
    name: String,
    value: String,
    is_focused: Bool,
  )
  IntegerSlashCommandOption(
    name: String,
    value: Int,
    is_focused: Bool,
  )
  NumberSlashCommandOption(
    name: String,
    value: Float,
    is_focused: Bool,
  )
  BoolSlashCommandOption(
    name: String,
    value: Bool,
    is_focused: Bool,
  )
  UserSlashCommandOption(
    name: String,
    user_id: String,
    is_focused: Bool,
  )
  ChannelSlashCommandOption(
    name: String,
    channel_id: String,
    is_focused: Bool,
  )
  RoleSlashCommandOption(
    name: String,
    role_id: String,
    is_focused: Bool,
  )
  MentionableSlashCommandOption(
    name: String,
    mentionable_id: String,
    is_focused: Bool,
  )
  AttachmentSlashCommandOption(
    name: String,
    attachment_id: String,
    is_focused: Bool,
  )
  SubCommandSlashCommandOption(
    name: String,
    options: List(SlashCommandOption),
  )
  SubCommandGroupSlashCommandOption(
    name: String,
    options: List(SlashCommandOption),
  )
}

Constructors

  • StringSlashCommandOption(
      name: String,
      value: String,
      is_focused: Bool,
    )

    Arguments

    is_focused

    For autocomplete.

  • IntegerSlashCommandOption(
      name: String,
      value: Int,
      is_focused: Bool,
    )

    Arguments

    is_focused

    For autocomplete.

  • NumberSlashCommandOption(
      name: String,
      value: Float,
      is_focused: Bool,
    )

    Arguments

    is_focused

    For autocomplete.

  • BoolSlashCommandOption(
      name: String,
      value: Bool,
      is_focused: Bool,
    )

    Arguments

    is_focused

    For autocomplete.

  • UserSlashCommandOption(
      name: String,
      user_id: String,
      is_focused: Bool,
    )

    Arguments

    name

    Name of the option, NOT of the user.

    is_focused

    For autocomplete.

  • ChannelSlashCommandOption(
      name: String,
      channel_id: String,
      is_focused: Bool,
    )

    Arguments

    name

    Name of the option, NOT of the channel.

    is_focused

    For autocomplete.

  • RoleSlashCommandOption(
      name: String,
      role_id: String,
      is_focused: Bool,
    )

    Arguments

    name

    Name of the option, NOT of the role.

    is_focused

    For autocomplete.

  • MentionableSlashCommandOption(
      name: String,
      mentionable_id: String,
      is_focused: Bool,
    )

    Arguments

    name

    Name of the option, NOT of the mentionable.

    is_focused

    For autocomplete.

  • AttachmentSlashCommandOption(
      name: String,
      attachment_id: String,
      is_focused: Bool,
    )

    Arguments

    name

    Name of the option, NOT of the attachment.

    attachment_id

    You likely want to search for this in resolved.

    is_focused

    For autocomplete.

  • SubCommandSlashCommandOption(
      name: String,
      options: List(SlashCommandOption),
    )
  • SubCommandGroupSlashCommandOption(
      name: String,
      options: List(SlashCommandOption),
    )
pub type StringSelectExecution {
  StringSelectExecution(
    custom_id: String,
    selected_values: List(String),
    resolved: option.Option(Resolved),
  )
}

Constructors

  • StringSelectExecution(
      custom_id: String,
      selected_values: List(String),
      resolved: option.Option(Resolved),
    )
pub type SubmittedLabelComponent {
  LabelTextInputSubmitted(TextInputSubmission)
  LabelStringSelectSubmitted(StringSelectExecution)
  LabelUserSelectSubmitted(UserSelectExecution)
  LabelRoleSelectSubmitted(RoleSelectExecution)
  LabelMentionableSelectSubmitted(MentionableSelectExecution)
  LabelChannelSelectSubmitted(ChannelSelectExecution)
  LabelFileUploadSubmitted(FileUploadSubmission)
  LabelRadioGroupSubmitted(RadioGroupSubmission)
  LabelCheckboxGroupSubmitted(CheckboxGroupSubmission)
  LabelCheckboxSubmitted(CheckboxSubmission)
}

Constructors

pub type SubmittedModalComponent {
  TextDisplaySubmitted(TextDisplaySubmission)
  LabelSubmitted(LabelSubmission)
}

Constructors

pub type TextDisplaySubmission {
  TextDisplaySubmission(id: Int)
}

Constructors

  • TextDisplaySubmission(id: Int)
pub type TextInputSubmission {
  TextInputSubmission(id: Int, custom_id: String, value: String)
}

Constructors

  • TextInputSubmission(id: Int, custom_id: String, value: String)
pub type UserCommandExecution {
  UserCommandExecution(
    id: String,
    name: String,
    resolved: option.Option(Resolved),
    registered_to_guild_id: option.Option(String),
    user_id: String,
  )
}

Constructors

pub type UserSelectExecution {
  UserSelectExecution(
    custom_id: String,
    selected_users_ids: List(String),
    resolved: option.Option(Resolved),
  )
}

Constructors

  • UserSelectExecution(
      custom_id: String,
      selected_users_ids: List(String),
      resolved: option.Option(Resolved),
    )

Values

pub fn delete_followup(
  client: grom.Client,
  of interaction: Interaction,
  id message_id: String,
) -> Result(Nil, grom.Error)
pub fn delete_original_response(
  client: grom.Client,
  of interaction: Interaction,
) -> Result(Nil, grom.Error)
pub fn followup(
  client: grom.Client,
  to interaction: Interaction,
  using followup: Followup,
) -> Result(message.Message, grom.Error)

Do not use this function to send a message after deferring it. Use modify_original_response instead.

pub fn get_followup(
  client: grom.Client,
  for interaction: Interaction,
  id message_id: String,
) -> Result(message.Message, grom.Error)
pub fn get_original_response(
  client: grom.Client,
  for interaction: Interaction,
) -> Result(Response, grom.Error)
pub fn handle_http_interaction_request(
  request: request.Request(String),
  public_key public_key: String,
  next next: fn(Result(Interaction, HttpError)) -> Nil,
) -> response.Response(String)

A HTTP request handler middleware that:

  • handles PING requests (which verify that your interaction endpoint is still up and secure)
  • gives you access to the interaction object, allowing you to handle your interactions
  • sends an HTTP response whenever you’re done with handling your interactions

Warning: Do not use long-running code to handle your interactions, as it could trigger an HTTP timeout.

See the http_interactions example to see how to set-up HTTP interactions and how to properly handle them.

pub fn modify_followup(
  client: grom.Client,
  for interaction: Interaction,
  id message_id: String,
  using modify: ModifyFollowup,
) -> Result(message.Message, grom.Error)
pub fn modify_original_response(
  client: grom.Client,
  of interaction: Interaction,
  using modify: ModifyOriginalResponse,
) -> Result(message.Message, grom.Error)
pub fn new_followup() -> Followup
pub fn new_modify_followup() -> ModifyFollowup
pub fn new_modify_original_response() -> ModifyOriginalResponse
pub fn new_response_message() -> ResponseMessage
pub fn respond(
  client: grom.Client,
  to interaction: Interaction,
  using response: Response,
) -> Result(Nil, grom.Error)
Search Document