From 3a99a7e085b67b4bbdce13899ce22eef4488f46e Mon Sep 17 00:00:00 2001 From: Fleny Date: Mon, 15 Sep 2025 12:15:11 +0200 Subject: [PATCH] api-docs: Social SDK webhook events (#4459) --- packages/types/src/discord/webhookEvents.ts | 116 +++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/packages/types/src/discord/webhookEvents.ts b/packages/types/src/discord/webhookEvents.ts index 0bdb93de2..c0860e2c6 100644 --- a/packages/types/src/discord/webhookEvents.ts +++ b/packages/types/src/discord/webhookEvents.ts @@ -1,8 +1,10 @@ /** Types for: https://discord.com/developers/docs/events/webhook-events */ import type { DiscordApplicationIntegrationType } from './application.js' +import type { DiscordChannel } from './channel.js' import type { DiscordEntitlement } from './entitlement.js' import type { DiscordGuild } from './guild.js' +import type { DiscordMessage, MessageFlags, MessageTypes } from './message.js' import type { OAuth2Scope } from './oauth2.js' import type { DiscordUser } from './user.js' @@ -33,7 +35,16 @@ export interface DiscordEventWebhookEventBody { /** Timestamp of when the event occurred in ISO8601 format */ timestamp: string /** Data for the event. The shape depends on the event type */ - data?: DiscordEventWebhookApplicationAuthorizedBody | DiscordEventWebhookApplicationDeauthorizedBody | DiscordEntitlement + data?: + | DiscordEventWebhookApplicationAuthorizedBody + | DiscordEventWebhookApplicationDeauthorizedBody + | DiscordEventWebhookEntitlementCreateBody + | DiscordEventWebhookLobbyMessageCreateBody + | DiscordEventWebhookLobbyMessageUpdateBody + | DiscordEventWebhookLobbyMessageDeleteBody + | DiscordEventWebhookGameDirectMessageCreateBody + | DiscordEventWebhookGameDirectMessageUpdateBody + | DiscordEventWebhookGameDirectMessageDeleteBody } /** https://discord.com/developers/docs/events/webhook-events#event-types */ @@ -46,6 +57,18 @@ export enum DiscordWebhookEventType { EntitlementCreate = 'ENTITLEMENT_CREATE', /** User was added to a Quest (currently unavailable) */ QuestUserEnrollment = 'QUEST_USER_ENROLLMENT', + /** Sent when a message is created in a lobby */ + LobbyMessageCreate = 'LOBBY_MESSAGE_CREATE', + /** Sent when a message is updated in a lobby */ + LobbyMessageUpdate = 'LOBBY_MESSAGE_UPDATE', + /** Sent when a message is deleted from a lobby */ + LobbyMessageDelete = 'LOBBY_MESSAGE_DELETE', + /** Sent when a direct message is created during an active Social SDK session */ + GameDirectMessageCreate = 'GAME_DIRECT_MESSAGE_CREATE', + /** Sent when a direct message is updated during an active Social SDK session */ + GameDirectMessageUpdate = 'GAME_DIRECT_MESSAGE_UPDATE', + /** Sent when a direct message is deleted during an active Social SDK session */ + GameDirectMessageDelete = 'GAME_DIRECT_MESSAGE_DELETE', } /** https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure */ @@ -65,3 +88,94 @@ export interface DiscordEventWebhookApplicationDeauthorizedBody { /** User who deauthorized the app */ user: DiscordUser } + +/** https://discord.com/developers/docs/events/webhook-events#entitlement-create-entitlement-create-structure */ +export type DiscordEventWebhookEntitlementCreateBody = DiscordEntitlement + +/** https://discord.com/developers/docs/events/webhook-events#lobby-message-create-lobby-message-create-structure */ +export type DiscordEventWebhookLobbyMessageCreateBody = DiscordSocialSDKLobbyMessage + +// Discord does not explicitly says what "with additional fields for message updates" means, so we rely on the example and the DiscordMessage structure +/** https://discord.com/developers/docs/events/webhook-events#lobby-message-update-lobby-message-update-structure */ +export interface DiscordEventWebhookLobbyMessageUpdateBody extends DiscordSocialSDKLobbyMessage { + /** ISO8601 timestamp of when the message was last edited */ + edited_timestamp: string | null + /** ISO8601 timestamp of when the message was created */ + timestamp: string +} + +/** https://discord.com/developers/docs/events/webhook-events#lobby-message-delete-lobby-message-delete-structure */ +export interface DiscordEventWebhookLobbyMessageDeleteBody { + /** ID of the deleted message */ + id: string + /** ID of the lobby where the message was deleted */ + lobby_id: string +} + +/** https://discord.com/developers/docs/events/webhook-events#game-direct-message-create-game-direct-message-create-structure */ +export type DiscordEventWebhookGameDirectMessageCreateBody = DiscordSocialSDKMessage | DiscordSocialSDKPassthroughMessage + +/** https://discord.com/developers/docs/events/webhook-events#game-direct-message-update-game-direct-message-update-structure */ +export type DiscordEventWebhookGameDirectMessageUpdateBody = DiscordSocialSDKMessage | DiscordSocialSDKPassthroughMessage + +/** https://discord.com/developers/docs/events/webhook-events#game-direct-message-delete-game-direct-message-delete-structure */ +export type DiscordEventWebhookGameDirectMessageDeleteBody = DiscordSocialSDKMessage | DiscordSocialSDKPassthroughMessage + +/** https://discord.com/developers/docs/events/webhook-events#lobby-message-object-lobby-message-structure */ +export interface DiscordSocialSDKLobbyMessage { + /** ID of the message */ + id: string + /** Type of message */ + type: MessageTypes + /** Contents of the message */ + content: string + /** ID of the lobby where the message was sent */ + lobby_id: string + /** ID of the channel the message was sent in */ + channel_id: string + /** Author of the message */ + author: DiscordUser + /** Additional metadata for the message (key-value pairs) */ + metadata?: Record + /** + * Message flags combined as a bitfield + * + * @see {@link MessageFlags} + */ + flags: number + /** ID of the application (only present during active Social SDK sessions) */ + application_id?: string +} + +/** https://discord.com/developers/docs/events/webhook-events#message-object */ +export interface DiscordSocialSDKMessage extends DiscordMessage { + /** ID of the lobby where the message was created (only present in Linked Channel messages) */ + lobby_id?: string + /** Channel object with recipient information */ + channel: DiscordChannel +} + +/** https://discord.com/developers/docs/events/webhook-events#passthrough-message-object-passthrough-message-structure */ +export interface DiscordSocialSDKPassthroughMessage { + /** ID of the message */ + id: string + /** Type of message */ + type: MessageTypes + /** Contents of the message */ + content: string + /** ID of the channel the message was sent in */ + channel_id: string + /** ID of the message recipient */ + recipient_id: string + /** Author of the message */ + author: DiscordUser + /** Message flags combined as a bitfield + * + * @see {@link MessageFlags} + */ + flags: MessageFlags + /** ID of the application that created the message */ + application_id: string + /** Channel object with recipient information */ + channel: DiscordChannel +}