From caa7833ffbdf17a4d937d5561cd53dd3be59c350 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:11:18 +0600 Subject: [PATCH] feat(interactions): add launchActivity method (#10646) * feat(interactions): add launchActivity method * chore: suggestion Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * chore: suggestion Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: overload and add tests * chore: wording * chore: wording * chore: spacing --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/src/api/interactions.ts | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 56f358315..94e61eff2 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -528,7 +528,7 @@ export class InteractionsAPI { } /** - * Sends a premium required response to an interaction + * Launches an activity and returns an interaction callback object * * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @param interactionId - The id of the interaction @@ -549,4 +549,70 @@ export class InteractionsAPI { signal, }); } + + /** + * Launches an activity and returns an interaction callback object + * + * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} + * @param interactionId - The id of the interaction + * @param interactionToken - The token of the interaction + * @param body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body: RESTPostAPIInteractionCallbackQuery & { with_response: true }, + options?: Pick, + ): Promise; + + /** + * Launches an activity + * + * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} + * @param interactionId - The id of the interaction + * @param interactionToken - The token of the interaction + * @param body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false }, + options?: Pick, + ): Promise; + + /** + * Launches an activity + * + * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} + * @param interactionId - The id of the interaction + * @param interactionToken - The token of the interaction + * @param body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body?: RESTPostAPIInteractionCallbackQuery, + options?: Pick, + ): Promise; + + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + { with_response }: RESTPostAPIInteractionCallbackQuery = {}, + { signal }: Pick = {}, + ) { + const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { + query: makeURLSearchParams({ with_response }), + auth: false, + body: { + type: InteractionResponseType.LaunchActivity, + }, + signal, + }); + + return with_response ? response : undefined; + } }