Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(interactions): add launchActivity method #10646

Merged
merged 16 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(interactions): add launchActivity method
imnaiyar committed Dec 8, 2024
commit 90178f976cf5da6c081c1e54d5dc3c0d078a8392
50 changes: 50 additions & 0 deletions packages/core/src/api/interactions.ts
Original file line number Diff line number Diff line change
@@ -450,4 +450,54 @@ export class InteractionsAPI {
signal,
});
}

/**
* Launches activity and returns an interaction callback object
imnaiyar marked this conversation as resolved.
Show resolved Hide resolved
*
* @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<RequestData, 'signal'>,
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;

/**
* Launches activity
imnaiyar marked this conversation as resolved.
Show resolved Hide resolved
*
* @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<RequestData, 'signal'>,
): Promise<undefined>;
imnaiyar marked this conversation as resolved.
Show resolved Hide resolved

public async launchActivity(
interactionId: Snowflake,
interactionToken: string,
{ with_response }: RESTPostAPIInteractionCallbackQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
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;
}
}