From a94fcd52a89b85fe8315e3ffd437edfe7fbd32db Mon Sep 17 00:00:00 2001 From: fhoffmann Date: Thu, 17 Sep 2026 00:53:43 +0200 Subject: [PATCH] get original interaction response endpoint --- src/grom.gleam | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/grom.gleam b/src/grom.gleam index fb14e6f..356d8c4 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -3699,6 +3699,7 @@ pub fn interaction_decoder() -> Decoder(Interaction) { ), channel_id: Snowflake(0), token: CommandInteractionToken(""), + interaction_token: InteractionToken(""), application_permissions: [], invoking_user_locale: EnglishUsLocale, invoking_user_entitlements: [], @@ -4224,6 +4225,7 @@ pub type CommandInteraction { /// The ID of the channel where the command was executed. channel_id: Snowflake(Channel), token: CommandInteractionToken, + interaction_token: InteractionToken, /// The permissions the bot has in the invoking context. application_permissions: List(Permission), invoking_user_locale: Locale, @@ -4240,6 +4242,7 @@ pub fn command_interaction_decoder() -> Decoder(CommandInteraction) { use invokement_data <- decode.then(interaction_invokement_data_decoder()) use channel_id <- decode.field("channel_id", snowflake_decoder()) use token <- decode.field("token", command_interaction_token_decoder()) + use interaction_token <- decode.field("token", interaction_token_decoder()) use application_permissions <- decode.field( "app_permissions", flags_string_decoder(bits_permissions()), @@ -4261,6 +4264,7 @@ pub fn command_interaction_decoder() -> Decoder(CommandInteraction) { invokement_data:, channel_id:, token:, + interaction_token:, application_permissions:, invoking_user_locale:, invoking_user_entitlements:, @@ -4505,6 +4509,7 @@ pub type MessageComponentInteraction { /// The ID of the channel where the component was executed. channel_id: Snowflake(Channel), token: MessageComponentInteractionToken, + interaction_token: InteractionToken, /// The component's appropriate message. message: Message, /// The permissions the bot has in the invoking context. @@ -4528,6 +4533,7 @@ pub fn message_component_interaction_decoder() -> Decoder( "token", message_component_interaction_token_decoder(), ) + use interaction_token <- decode.field("token", interaction_token_decoder()) use message <- decode.field("message", message_decoder()) use application_permissions <- decode.field( "app_permissions", @@ -4550,6 +4556,7 @@ pub fn message_component_interaction_decoder() -> Decoder( invokement_data:, channel_id:, token:, + interaction_token:, application_permissions:, invoking_user_locale:, invoking_user_entitlements:, @@ -4919,6 +4926,7 @@ pub type ModalInteraction { application_id: Snowflake(Application), invokement_data: InteractionInvokementData, token: ModalInteractionToken, + interaction_token: InteractionToken, /// If the modal was created as a result of a previous message component interaction, /// this is the message belonging to the original component. message: Option(Message), @@ -4937,6 +4945,7 @@ pub fn modal_interaction_decoder() -> Decoder(ModalInteraction) { use application_id <- decode.field("application_id", snowflake_decoder()) use invokement_data <- decode.then(interaction_invokement_data_decoder()) use token <- decode.field("token", modal_interaction_token_decoder()) + use interaction_token <- decode.field("token", interaction_token_decoder()) use message <- decode.optional_field( "message", None, @@ -4962,6 +4971,7 @@ pub fn modal_interaction_decoder() -> Decoder(ModalInteraction) { application_id:, invokement_data:, token:, + interaction_token:, application_permissions:, invoking_user_locale:, invoking_user_entitlements:, @@ -4991,6 +5001,14 @@ pub fn interaction_context_decoder() -> Decoder(InteractionContext) { } } +pub opaque type InteractionToken { + InteractionToken(token: String) +} + +pub fn interaction_token_decoder() -> Decoder(InteractionToken) { + decode.map(decode.string, InteractionToken) +} + pub opaque type CommandInteractionToken { CommandInteractionToken(token: String) } @@ -26546,3 +26564,25 @@ pub fn respond_to_modal_interaction_response( ) -> Result(Nil, RestError) { handle_no_content_response_bits(response) } + +pub fn get_original_interaction_response_request( + token token: Token, + current_application_id application_id: Snowflake(Application), + interaction_token interaction_token: InteractionToken, +) -> Request(String) { + new_request( + token:, + to: "/webhooks/" + <> snowflake_to_string(application_id) + <> "/" + <> interaction_token.token + <> "/messages/@original", + method: http.Get, + ) +} + +pub fn get_original_interaction_response_response( + response: Response(String), +) -> Result(Message, RestError) { + handle_response(response:, decode_with: message_decoder()) +} -- 2.51.2