From b4b70d8bdcdbc175497366e6bb74dd3bc22c6738 Mon Sep 17 00:00:00 2001 From: Almeida Date: Thu, 5 Sep 2024 16:29:23 +0100 Subject: [PATCH] feat: entry point commands and interaction callback response (#1077) --- .eslintrc.json | 3 + .../v10/_interactions/applicationCommands.ts | 35 +++++++ deno/payloads/v10/_interactions/responses.ts | 8 ++ .../v9/_interactions/applicationCommands.ts | 35 +++++++ deno/payloads/v9/_interactions/responses.ts | 8 ++ deno/rest/v10/interactions.ts | 98 +++++++++++++++++++ deno/rest/v9/interactions.ts | 98 +++++++++++++++++++ .../v10/_interactions/applicationCommands.ts | 35 +++++++ payloads/v10/_interactions/responses.ts | 8 ++ .../v9/_interactions/applicationCommands.ts | 35 +++++++ payloads/v9/_interactions/responses.ts | 8 ++ rest/v10/interactions.ts | 98 +++++++++++++++++++ rest/v9/interactions.ts | 98 +++++++++++++++++++ 13 files changed, 567 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index 6c47cc3f..1a0e1b2f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -35,6 +35,9 @@ "RESTAPIGuildCreateRole", "RESTAPIGuildOnboardingPrompt", "RESTAPIGuildOnboardingPromptOption", + "RESTAPIInteractionCallbackActivityInstanceResource", + "RESTAPIInteractionCallbackObject", + "RESTAPIInteractionCallbackResourceObject", "RESTAPIMessageReference", "RESTAPIPartialCurrentUserGuild", "RESTAPIPoll", diff --git a/deno/payloads/v10/_interactions/applicationCommands.ts b/deno/payloads/v10/_interactions/applicationCommands.ts index 52f84655..d0a945f2 100644 --- a/deno/payloads/v10/_interactions/applicationCommands.ts +++ b/deno/payloads/v10/_interactions/applicationCommands.ts @@ -102,15 +102,35 @@ export interface APIApplicationCommand { * Autoincrementing version identifier updated during substantial record changes */ version: Snowflake; + /** + * Determines whether the interaction is handled by the app's interactions handler or by Discord + * + * @remarks + * This is only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands + */ + handler?: EntryPointCommandHandlerType; } /** * https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types */ export enum ApplicationCommandType { + /** + * Slash commands; a text-based command that shows up when a user types `/` + */ ChatInput = 1, + /** + * A UI-based command that shows up when you right click or tap on a user + */ User, + /** + * A UI-based command that shows up when you right click or tap on a message + */ Message, + /** + * A UI-based command that represents the primary way to invoke an app's Activity + */ + PrimaryEntryPoint, } /** @@ -145,6 +165,21 @@ export enum InteractionContextType { PrivateChannel, } +/** + * https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types + */ +export enum EntryPointCommandHandlerType { + /** + * The app handles the interaction using an interaction token + */ + AppHandler = 1, + /** + * Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with + * the app + */ + DiscordLaunchActivity, +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data */ diff --git a/deno/payloads/v10/_interactions/responses.ts b/deno/payloads/v10/_interactions/responses.ts index aa35489c..155502c8 100644 --- a/deno/payloads/v10/_interactions/responses.ts +++ b/deno/payloads/v10/_interactions/responses.ts @@ -102,6 +102,14 @@ export enum InteractionResponseType { * @deprecated See https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes */ PremiumRequired, + + /** + * Launch the Activity associated with the app. + * + * @remarks + * Only available for apps with Activities enabled + */ + LaunchActivity = 12, } /** diff --git a/deno/payloads/v9/_interactions/applicationCommands.ts b/deno/payloads/v9/_interactions/applicationCommands.ts index 7ae5ce96..afb699e6 100644 --- a/deno/payloads/v9/_interactions/applicationCommands.ts +++ b/deno/payloads/v9/_interactions/applicationCommands.ts @@ -102,15 +102,35 @@ export interface APIApplicationCommand { * Autoincrementing version identifier updated during substantial record changes */ version: Snowflake; + /** + * Determines whether the interaction is handled by the app's interactions handler or by Discord + * + * @remarks + * This is only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands + */ + handler?: EntryPointCommandHandlerType; } /** * https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types */ export enum ApplicationCommandType { + /** + * Slash commands; a text-based command that shows up when a user types `/` + */ ChatInput = 1, + /** + * A UI-based command that shows up when you right click or tap on a user + */ User, + /** + * A UI-based command that shows up when you right click or tap on a message + */ Message, + /** + * A UI-based command that represents the primary way to invoke an app's Activity + */ + PrimaryEntryPoint, } /** @@ -145,6 +165,21 @@ export enum InteractionContextType { PrivateChannel, } +/** + * https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types + */ +export enum EntryPointCommandHandlerType { + /** + * The app handles the interaction using an interaction token + */ + AppHandler = 1, + /** + * Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with + * the app + */ + DiscordLaunchActivity, +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data */ diff --git a/deno/payloads/v9/_interactions/responses.ts b/deno/payloads/v9/_interactions/responses.ts index 7afdc928..72fb3df2 100644 --- a/deno/payloads/v9/_interactions/responses.ts +++ b/deno/payloads/v9/_interactions/responses.ts @@ -102,6 +102,14 @@ export enum InteractionResponseType { * @deprecated See https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes */ PremiumRequired, + + /** + * Launch the Activity associated with the app. + * + * @remarks + * Only available for apps with Activities enabled + */ + LaunchActivity = 12, } /** diff --git a/deno/rest/v10/interactions.ts b/deno/rest/v10/interactions.ts index 6a9e1466..acf24e09 100644 --- a/deno/rest/v10/interactions.ts +++ b/deno/rest/v10/interactions.ts @@ -1,3 +1,4 @@ +import type { Snowflake } from '../../globals.ts'; import type { APIApplicationCommand, APIApplicationCommandPermission, @@ -5,6 +6,9 @@ import type { APIInteractionResponse, APIInteractionResponseCallbackData, ApplicationCommandType, + InteractionResponseType, + APIMessage, + InteractionType, } from '../../payloads/v10/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, @@ -171,6 +175,16 @@ export type RESTPutAPIApplicationGuildCommandsResult = Omit & RESTPostAPIInteractionCallbackJSONBody); +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response + */ +export type RESTPostAPIInteractionCallbackResult = never; + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-response-object + */ +export interface RESTPostAPIInteractionCallbackWithResponseResult { + /** + * The interaction object associated with the interaction + */ + interaction: RESTAPIInteractionCallbackObject; + /** + * The resource that was created by the interaction response + */ + resource?: RESTAPIInteractionCallbackResourceObject; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-object + */ +export interface RESTAPIInteractionCallbackObject { + /** + * ID of the interaction + */ + id: Snowflake; + /** + * Interaction type + */ + type: InteractionType; + /** + * Instance ID of the Activity if one was launched or joined + */ + activity_instance_id?: string; + /** + * ID of the message that was created by the interaction + */ + response_message_id?: Snowflake; + /** + * Whether or not the message is in a loading state + */ + response_message_loading?: boolean; + /** + * Whether or not the response message was ephemeral + */ + response_message_ephemeral?: boolean; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-resource-object + */ +export interface RESTAPIInteractionCallbackResourceObject { + /** + * Interaction callback type + */ + type: InteractionResponseType; + /** + * Represents the Activity launched by this interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.LaunchActivity} + */ + activity_instance?: RESTAPIInteractionCallbackActivityInstanceResource; + /** + * Message created by the interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.ChannelMessageWithSource} + * or {@link InteractionResponseType.UpdateMessage} + */ + message?: APIMessage; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-activity-instance-resource + */ +export interface RESTAPIInteractionCallbackActivityInstanceResource { + /** + * Instance ID of the Activity if one was launched or joined. + */ + id: string; +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response */ diff --git a/deno/rest/v9/interactions.ts b/deno/rest/v9/interactions.ts index 1cd43f77..4d821126 100644 --- a/deno/rest/v9/interactions.ts +++ b/deno/rest/v9/interactions.ts @@ -1,3 +1,4 @@ +import type { Snowflake } from '../../globals.ts'; import type { APIApplicationCommand, APIApplicationCommandPermission, @@ -5,6 +6,9 @@ import type { APIInteractionResponse, APIInteractionResponseCallbackData, ApplicationCommandType, + InteractionResponseType, + APIMessage, + InteractionType, } from '../../payloads/v9/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, @@ -171,6 +175,16 @@ export type RESTPutAPIApplicationGuildCommandsResult = Omit & RESTPostAPIInteractionCallbackJSONBody); +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response + */ +export type RESTPostAPIInteractionCallbackResult = never; + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-response-object + */ +export interface RESTPostAPIInteractionCallbackWithResponseResult { + /** + * The interaction object associated with the interaction + */ + interaction: RESTAPIInteractionCallbackObject; + /** + * The resource that was created by the interaction response + */ + resource?: RESTAPIInteractionCallbackResourceObject; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-object + */ +export interface RESTAPIInteractionCallbackObject { + /** + * ID of the interaction + */ + id: Snowflake; + /** + * Interaction type + */ + type: InteractionType; + /** + * Instance ID of the Activity if one was launched or joined + */ + activity_instance_id?: string; + /** + * ID of the message that was created by the interaction + */ + response_message_id?: Snowflake; + /** + * Whether or not the message is in a loading state + */ + response_message_loading?: boolean; + /** + * Whether or not the response message was ephemeral + */ + response_message_ephemeral?: boolean; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-resource-object + */ +export interface RESTAPIInteractionCallbackResourceObject { + /** + * Interaction callback type + */ + type: InteractionResponseType; + /** + * Represents the Activity launched by this interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.LaunchActivity} + */ + activity_instance?: RESTAPIInteractionCallbackActivityInstanceResource; + /** + * Message created by the interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.ChannelMessageWithSource} + * or {@link InteractionResponseType.UpdateMessage} + */ + message?: APIMessage; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-activity-instance-resource + */ +export interface RESTAPIInteractionCallbackActivityInstanceResource { + /** + * Instance ID of the Activity if one was launched or joined. + */ + id: string; +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response */ diff --git a/payloads/v10/_interactions/applicationCommands.ts b/payloads/v10/_interactions/applicationCommands.ts index 0da3b734..d74429cb 100644 --- a/payloads/v10/_interactions/applicationCommands.ts +++ b/payloads/v10/_interactions/applicationCommands.ts @@ -102,15 +102,35 @@ export interface APIApplicationCommand { * Autoincrementing version identifier updated during substantial record changes */ version: Snowflake; + /** + * Determines whether the interaction is handled by the app's interactions handler or by Discord + * + * @remarks + * This is only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands + */ + handler?: EntryPointCommandHandlerType; } /** * https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types */ export enum ApplicationCommandType { + /** + * Slash commands; a text-based command that shows up when a user types `/` + */ ChatInput = 1, + /** + * A UI-based command that shows up when you right click or tap on a user + */ User, + /** + * A UI-based command that shows up when you right click or tap on a message + */ Message, + /** + * A UI-based command that represents the primary way to invoke an app's Activity + */ + PrimaryEntryPoint, } /** @@ -145,6 +165,21 @@ export enum InteractionContextType { PrivateChannel, } +/** + * https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types + */ +export enum EntryPointCommandHandlerType { + /** + * The app handles the interaction using an interaction token + */ + AppHandler = 1, + /** + * Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with + * the app + */ + DiscordLaunchActivity, +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data */ diff --git a/payloads/v10/_interactions/responses.ts b/payloads/v10/_interactions/responses.ts index baf3736b..61c55cb5 100644 --- a/payloads/v10/_interactions/responses.ts +++ b/payloads/v10/_interactions/responses.ts @@ -102,6 +102,14 @@ export enum InteractionResponseType { * @deprecated See https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes */ PremiumRequired, + + /** + * Launch the Activity associated with the app. + * + * @remarks + * Only available for apps with Activities enabled + */ + LaunchActivity = 12, } /** diff --git a/payloads/v9/_interactions/applicationCommands.ts b/payloads/v9/_interactions/applicationCommands.ts index 9be2f9b9..4963b289 100644 --- a/payloads/v9/_interactions/applicationCommands.ts +++ b/payloads/v9/_interactions/applicationCommands.ts @@ -102,15 +102,35 @@ export interface APIApplicationCommand { * Autoincrementing version identifier updated during substantial record changes */ version: Snowflake; + /** + * Determines whether the interaction is handled by the app's interactions handler or by Discord + * + * @remarks + * This is only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands + */ + handler?: EntryPointCommandHandlerType; } /** * https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types */ export enum ApplicationCommandType { + /** + * Slash commands; a text-based command that shows up when a user types `/` + */ ChatInput = 1, + /** + * A UI-based command that shows up when you right click or tap on a user + */ User, + /** + * A UI-based command that shows up when you right click or tap on a message + */ Message, + /** + * A UI-based command that represents the primary way to invoke an app's Activity + */ + PrimaryEntryPoint, } /** @@ -145,6 +165,21 @@ export enum InteractionContextType { PrivateChannel, } +/** + * https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types + */ +export enum EntryPointCommandHandlerType { + /** + * The app handles the interaction using an interaction token + */ + AppHandler = 1, + /** + * Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with + * the app + */ + DiscordLaunchActivity, +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data */ diff --git a/payloads/v9/_interactions/responses.ts b/payloads/v9/_interactions/responses.ts index 56900ae3..213b3960 100644 --- a/payloads/v9/_interactions/responses.ts +++ b/payloads/v9/_interactions/responses.ts @@ -102,6 +102,14 @@ export enum InteractionResponseType { * @deprecated See https://discord.com/developers/docs/change-log#premium-apps-new-premium-button-style-deep-linking-url-schemes */ PremiumRequired, + + /** + * Launch the Activity associated with the app. + * + * @remarks + * Only available for apps with Activities enabled + */ + LaunchActivity = 12, } /** diff --git a/rest/v10/interactions.ts b/rest/v10/interactions.ts index db791c46..4edc2a98 100644 --- a/rest/v10/interactions.ts +++ b/rest/v10/interactions.ts @@ -1,3 +1,4 @@ +import type { Snowflake } from '../../globals'; import type { APIApplicationCommand, APIApplicationCommandPermission, @@ -5,6 +6,9 @@ import type { APIInteractionResponse, APIInteractionResponseCallbackData, ApplicationCommandType, + InteractionResponseType, + APIMessage, + InteractionType, } from '../../payloads/v10/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, @@ -171,6 +175,16 @@ export type RESTPutAPIApplicationGuildCommandsResult = Omit & RESTPostAPIInteractionCallbackJSONBody); +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response + */ +export type RESTPostAPIInteractionCallbackResult = never; + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-response-object + */ +export interface RESTPostAPIInteractionCallbackWithResponseResult { + /** + * The interaction object associated with the interaction + */ + interaction: RESTAPIInteractionCallbackObject; + /** + * The resource that was created by the interaction response + */ + resource?: RESTAPIInteractionCallbackResourceObject; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-object + */ +export interface RESTAPIInteractionCallbackObject { + /** + * ID of the interaction + */ + id: Snowflake; + /** + * Interaction type + */ + type: InteractionType; + /** + * Instance ID of the Activity if one was launched or joined + */ + activity_instance_id?: string; + /** + * ID of the message that was created by the interaction + */ + response_message_id?: Snowflake; + /** + * Whether or not the message is in a loading state + */ + response_message_loading?: boolean; + /** + * Whether or not the response message was ephemeral + */ + response_message_ephemeral?: boolean; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-resource-object + */ +export interface RESTAPIInteractionCallbackResourceObject { + /** + * Interaction callback type + */ + type: InteractionResponseType; + /** + * Represents the Activity launched by this interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.LaunchActivity} + */ + activity_instance?: RESTAPIInteractionCallbackActivityInstanceResource; + /** + * Message created by the interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.ChannelMessageWithSource} + * or {@link InteractionResponseType.UpdateMessage} + */ + message?: APIMessage; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-activity-instance-resource + */ +export interface RESTAPIInteractionCallbackActivityInstanceResource { + /** + * Instance ID of the Activity if one was launched or joined. + */ + id: string; +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response */ diff --git a/rest/v9/interactions.ts b/rest/v9/interactions.ts index 527cfe87..ba9faf23 100644 --- a/rest/v9/interactions.ts +++ b/rest/v9/interactions.ts @@ -1,3 +1,4 @@ +import type { Snowflake } from '../../globals'; import type { APIApplicationCommand, APIApplicationCommandPermission, @@ -5,6 +6,9 @@ import type { APIInteractionResponse, APIInteractionResponseCallbackData, ApplicationCommandType, + InteractionResponseType, + APIMessage, + InteractionType, } from '../../payloads/v9/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, @@ -171,6 +175,16 @@ export type RESTPutAPIApplicationGuildCommandsResult = Omit & RESTPostAPIInteractionCallbackJSONBody); +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response + */ +export type RESTPostAPIInteractionCallbackResult = never; + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-response-object + */ +export interface RESTPostAPIInteractionCallbackWithResponseResult { + /** + * The interaction object associated with the interaction + */ + interaction: RESTAPIInteractionCallbackObject; + /** + * The resource that was created by the interaction response + */ + resource?: RESTAPIInteractionCallbackResourceObject; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-object + */ +export interface RESTAPIInteractionCallbackObject { + /** + * ID of the interaction + */ + id: Snowflake; + /** + * Interaction type + */ + type: InteractionType; + /** + * Instance ID of the Activity if one was launched or joined + */ + activity_instance_id?: string; + /** + * ID of the message that was created by the interaction + */ + response_message_id?: Snowflake; + /** + * Whether or not the message is in a loading state + */ + response_message_loading?: boolean; + /** + * Whether or not the response message was ephemeral + */ + response_message_ephemeral?: boolean; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-resource-object + */ +export interface RESTAPIInteractionCallbackResourceObject { + /** + * Interaction callback type + */ + type: InteractionResponseType; + /** + * Represents the Activity launched by this interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.LaunchActivity} + */ + activity_instance?: RESTAPIInteractionCallbackActivityInstanceResource; + /** + * Message created by the interaction + * + * @remarks + * Only present if `type` is {@link InteractionResponseType.ChannelMessageWithSource} + * or {@link InteractionResponseType.UpdateMessage} + */ + message?: APIMessage; +} + +/** + * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-activity-instance-resource + */ +export interface RESTAPIInteractionCallbackActivityInstanceResource { + /** + * Instance ID of the Activity if one was launched or joined. + */ + id: string; +} + /** * https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response */