From 90178f976cf5da6c081c1e54d5dc3c0d078a8392 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Sun, 8 Dec 2024 21:45:28 +0000 Subject: [PATCH 1/7] feat(interactions): add launchActivity method --- packages/core/src/api/interactions.ts | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index bc485a76200d..c50491129f45 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -450,4 +450,54 @@ export class InteractionsAPI { signal, }); } + + /** + * Launches 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 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; + + 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; + } } From 1fff273109772803ea918e9a0b9845909b135790 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:05:57 +0600 Subject: [PATCH 2/7] chore: suggestion Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/core/src/api/interactions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index a8e3f5fa87bd..04f6cd53d8cf 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -431,7 +431,7 @@ export class InteractionsAPI { } /** - * Launches activity and returns an interaction callback object + * 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 From 71e1722222a2a93c394e0e0be07f619e0b1ddf89 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Fri, 3 Jan 2025 19:06:13 +0600 Subject: [PATCH 3/7] chore: suggestion Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/core/src/api/interactions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 04f6cd53d8cf..b3fc0c0d4dd7 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -447,7 +447,7 @@ export class InteractionsAPI { ): Promise; /** - * Launches activity + * Launches an activity * * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @param interactionId - The id of the interaction From 61a97bb6c5f64a26185b01a6e1551915023cfccc Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:35:34 +0530 Subject: [PATCH 4/7] fix: overload and add tests --- packages/core/__tests__/types.test.ts | 16 ++++++++++++++++ packages/core/src/api/interactions.ts | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts index 104b5882be20..b7ee25012e5e 100644 --- a/packages/core/__tests__/types.test.ts +++ b/packages/core/__tests__/types.test.ts @@ -12,6 +12,7 @@ const api = new API(rest); const SNOWFLAKE = '123456789012345678' as const; const TOKEN = 'token' as const; const MODAL_COMPONENTS: APIActionRowComponent[] = [] as const; +const boolValue = true as boolean; describe('Interaction with_response overloads.', () => { test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () => @@ -67,4 +68,19 @@ describe('Interaction with_response overloads.', () => { assertType>( api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }), )); + + test('Launch activity returns undefined.', () => { + assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: false })); + assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN)); + }); + + test('Launch activity returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Launch activity returns both RESTPostAPIInteractionCallbackWithResponseResult and undefined.', () => + assertType>( + api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue }), + )); }); diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 58d8834187d8..3eb312d63ad8 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -442,7 +442,7 @@ export class InteractionsAPI { public async launchActivity( interactionId: Snowflake, interactionToken: string, - body?: RESTPostAPIInteractionCallbackQuery & { with_response: true }, + body: RESTPostAPIInteractionCallbackQuery & { with_response: true }, options?: Pick, ): Promise; @@ -462,6 +462,22 @@ export class InteractionsAPI { 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, From ede8eeaaa5a7a22100c875bfb08b2fda3e9467e3 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:41:58 +0530 Subject: [PATCH 5/7] chore: wording --- packages/core/__tests__/types.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts index b7ee25012e5e..71353cc6a37a 100644 --- a/packages/core/__tests__/types.test.ts +++ b/packages/core/__tests__/types.test.ts @@ -79,7 +79,7 @@ describe('Interaction with_response overloads.', () => { api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true }), )); - test('Launch activity returns both RESTPostAPIInteractionCallbackWithResponseResult and undefined.', () => + test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult and undefined.', () => assertType>( api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue }), )); From 5cb9b341b4ddd2f592a58fbfbd656ddca64e2cd6 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:43:45 +0530 Subject: [PATCH 6/7] chore: wording --- packages/core/__tests__/types.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts index 71353cc6a37a..463fab61c286 100644 --- a/packages/core/__tests__/types.test.ts +++ b/packages/core/__tests__/types.test.ts @@ -79,7 +79,7 @@ describe('Interaction with_response overloads.', () => { api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true }), )); - test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult and undefined.', () => + test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => assertType>( api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue }), )); From b0b8eba286f401e222e14685ac50e15b46f0c1a6 Mon Sep 17 00:00:00 2001 From: Naiyar <137700126+imnaiyar@users.noreply.github.com> Date: Sun, 19 Jan 2025 15:01:20 +0530 Subject: [PATCH 7/7] chore: spacing --- packages/core/__tests__/types.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts index ca7fa4cd078e..11c086d4838f 100644 --- a/packages/core/__tests__/types.test.ts +++ b/packages/core/__tests__/types.test.ts @@ -131,8 +131,8 @@ describe('Interaction with_response overloads.', () => { }), ); }); - - test('Launch activity returns undefined.', () => { + + test('Launch activity returns undefined.', () => { assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: false })); assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN)); });