From 897a753c6ba4dcb3fc035622a425b90996decac4 Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Wed, 30 Oct 2024 17:37:28 +0100 Subject: [PATCH] feat: webhook events --- deno/payloads/v10/application.ts | 31 +++++++++ deno/payloads/v10/webhook.ts | 106 ++++++++++++++++++++++++++++++- deno/payloads/v9/application.ts | 31 +++++++++ deno/payloads/v9/webhook.ts | 106 ++++++++++++++++++++++++++++++- payloads/v10/application.ts | 31 +++++++++ payloads/v10/webhook.ts | 106 ++++++++++++++++++++++++++++++- payloads/v9/application.ts | 31 +++++++++ payloads/v9/webhook.ts | 106 ++++++++++++++++++++++++++++++- 8 files changed, 544 insertions(+), 4 deletions(-) diff --git a/deno/payloads/v10/application.ts b/deno/payloads/v10/application.ts index 8dfc67517..4e3f51492 100644 --- a/deno/payloads/v10/application.ts +++ b/deno/payloads/v10/application.ts @@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions.ts'; import type { OAuth2Scopes } from './oauth2.ts'; import type { APITeam } from './teams.ts'; import type { APIUser } from './user.ts'; +import type { WebhookEventType } from './webhook.ts'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -142,6 +143,18 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * Event webhook URL for the app to receive webhook events + */ + event_webhooks_url?: string | null; + /** + * If webhook events are enabled for the app. + */ + event_webhooks_status: ApplicationEventWebhookStatus; + /** + * List of Webhook event types the app subscribes to + */ + event_webhooks_types?: WebhookEventType[]; } export interface APIApplicationInstallParams { @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType { */ BooleanNotEqual, } + +/** + * https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status + */ +export enum ApplicationEventWebhookStatus { + /** + * Webhook events are disabled by developer + */ + Disabled = 1, + /** + * Webhook events are enabled by developer + */ + Enabled, + /** + * Webhook events are disabled by Discord, usually do to inactivity + */ + DisabledByDiscord, +} diff --git a/deno/payloads/v10/webhook.ts b/deno/payloads/v10/webhook.ts index 7062a47ce..91d56dc2c 100644 --- a/deno/payloads/v10/webhook.ts +++ b/deno/payloads/v10/webhook.ts @@ -3,7 +3,14 @@ */ import type { Snowflake } from '../../globals.ts'; -import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts'; +import type { + APIGuild, + APIPartialChannel, + APIPartialGuild, + APIUser, + ApplicationIntegrationType, + OAuth2Scopes, +} from './mod.ts'; /** * https://discord.com/developers/docs/resources/webhook#webhook-object @@ -63,6 +70,103 @@ export interface APIWebhook { url?: string; } +/** + * https://discord.com/developers/docs/events/webhook-events#payload-structure + */ +export interface APIEventWebhookEvent { + /** + * Version scheme for the webhook event. Currently always 1 + */ + version: 1; + /** + * ID of your app + */ + application_id: string; + /** + * Type of webhook, either 0 for PING or 1 for webhook events + */ + type: EventWebhookType; + /** + * Event data payload + */ + event?: APIEventWebhookEventBody; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-body-object + */ +export interface APIEventWebhookEventBody { + /** + * Event type + */ + type: WebhookEventType; + /** + * Timestamp of when the event occurred in ISO8601 format + */ + timestamp: string; + /** + * Data for the event. The shape depends on the event type + */ + data?: unknown; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure + */ +export interface APIEventWebhookApplicationAuthorizedBody { + /** + * Installation context for the authorization. + */ + integration_type?: ApplicationIntegrationType; + /** + * User who authorized the app + */ + user: APIUser; + /** + * List of scopes the user authorized + */ + scopes: OAuth2Scopes[]; + /** + * Server which app was authorized for (when integration type is 0) + */ + guild?: APIGuild; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#webhook-types + */ +export enum EventWebhookType { + /** + * PING event sent to verify your Webhook Event URL is active + */ + Ping, + /** + * Webhook event (details for event in event body object) + */ + Event, +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-types + */ +export enum WebhookEventType { + /** + * Sent when an app was authorized by a user to a server or their account + */ + ApplicationAuthorized = 'APPLICATION_AUTHORIZED', + /** + * Entitlement was created + */ + EntitlementCreate = 'ENTITLEMENT_CREATE', + /** + * User was added to a Quest (currently unavailable) + */ + QuestUserEnrollment = 'QUEST_USER_ENROLLMENT', +} + +/** + * https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types + */ export enum WebhookType { /** * Incoming Webhooks can post messages to channels with a generated token diff --git a/deno/payloads/v9/application.ts b/deno/payloads/v9/application.ts index 8dfc67517..4e3f51492 100644 --- a/deno/payloads/v9/application.ts +++ b/deno/payloads/v9/application.ts @@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions.ts'; import type { OAuth2Scopes } from './oauth2.ts'; import type { APITeam } from './teams.ts'; import type { APIUser } from './user.ts'; +import type { WebhookEventType } from './webhook.ts'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -142,6 +143,18 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * Event webhook URL for the app to receive webhook events + */ + event_webhooks_url?: string | null; + /** + * If webhook events are enabled for the app. + */ + event_webhooks_status: ApplicationEventWebhookStatus; + /** + * List of Webhook event types the app subscribes to + */ + event_webhooks_types?: WebhookEventType[]; } export interface APIApplicationInstallParams { @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType { */ BooleanNotEqual, } + +/** + * https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status + */ +export enum ApplicationEventWebhookStatus { + /** + * Webhook events are disabled by developer + */ + Disabled = 1, + /** + * Webhook events are enabled by developer + */ + Enabled, + /** + * Webhook events are disabled by Discord, usually do to inactivity + */ + DisabledByDiscord, +} diff --git a/deno/payloads/v9/webhook.ts b/deno/payloads/v9/webhook.ts index 7062a47ce..91d56dc2c 100644 --- a/deno/payloads/v9/webhook.ts +++ b/deno/payloads/v9/webhook.ts @@ -3,7 +3,14 @@ */ import type { Snowflake } from '../../globals.ts'; -import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts'; +import type { + APIGuild, + APIPartialChannel, + APIPartialGuild, + APIUser, + ApplicationIntegrationType, + OAuth2Scopes, +} from './mod.ts'; /** * https://discord.com/developers/docs/resources/webhook#webhook-object @@ -63,6 +70,103 @@ export interface APIWebhook { url?: string; } +/** + * https://discord.com/developers/docs/events/webhook-events#payload-structure + */ +export interface APIEventWebhookEvent { + /** + * Version scheme for the webhook event. Currently always 1 + */ + version: 1; + /** + * ID of your app + */ + application_id: string; + /** + * Type of webhook, either 0 for PING or 1 for webhook events + */ + type: EventWebhookType; + /** + * Event data payload + */ + event?: APIEventWebhookEventBody; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-body-object + */ +export interface APIEventWebhookEventBody { + /** + * Event type + */ + type: WebhookEventType; + /** + * Timestamp of when the event occurred in ISO8601 format + */ + timestamp: string; + /** + * Data for the event. The shape depends on the event type + */ + data?: unknown; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure + */ +export interface APIEventWebhookApplicationAuthorizedBody { + /** + * Installation context for the authorization. + */ + integration_type?: ApplicationIntegrationType; + /** + * User who authorized the app + */ + user: APIUser; + /** + * List of scopes the user authorized + */ + scopes: OAuth2Scopes[]; + /** + * Server which app was authorized for (when integration type is 0) + */ + guild?: APIGuild; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#webhook-types + */ +export enum EventWebhookType { + /** + * PING event sent to verify your Webhook Event URL is active + */ + Ping, + /** + * Webhook event (details for event in event body object) + */ + Event, +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-types + */ +export enum WebhookEventType { + /** + * Sent when an app was authorized by a user to a server or their account + */ + ApplicationAuthorized = 'APPLICATION_AUTHORIZED', + /** + * Entitlement was created + */ + EntitlementCreate = 'ENTITLEMENT_CREATE', + /** + * User was added to a Quest (currently unavailable) + */ + QuestUserEnrollment = 'QUEST_USER_ENROLLMENT', +} + +/** + * https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types + */ export enum WebhookType { /** * Incoming Webhooks can post messages to channels with a generated token diff --git a/payloads/v10/application.ts b/payloads/v10/application.ts index d168dac3f..4f6aa5f76 100644 --- a/payloads/v10/application.ts +++ b/payloads/v10/application.ts @@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions'; import type { OAuth2Scopes } from './oauth2'; import type { APITeam } from './teams'; import type { APIUser } from './user'; +import type { WebhookEventType } from './webhook'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -142,6 +143,18 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * Event webhook URL for the app to receive webhook events + */ + event_webhooks_url?: string | null; + /** + * If webhook events are enabled for the app. + */ + event_webhooks_status: ApplicationEventWebhookStatus; + /** + * List of Webhook event types the app subscribes to + */ + event_webhooks_types?: WebhookEventType[]; } export interface APIApplicationInstallParams { @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType { */ BooleanNotEqual, } + +/** + * https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status + */ +export enum ApplicationEventWebhookStatus { + /** + * Webhook events are disabled by developer + */ + Disabled = 1, + /** + * Webhook events are enabled by developer + */ + Enabled, + /** + * Webhook events are disabled by Discord, usually do to inactivity + */ + DisabledByDiscord, +} diff --git a/payloads/v10/webhook.ts b/payloads/v10/webhook.ts index 4886b987a..de46decb1 100644 --- a/payloads/v10/webhook.ts +++ b/payloads/v10/webhook.ts @@ -3,7 +3,14 @@ */ import type { Snowflake } from '../../globals'; -import type { APIPartialChannel, APIPartialGuild, APIUser } from './index'; +import type { + APIGuild, + APIPartialChannel, + APIPartialGuild, + APIUser, + ApplicationIntegrationType, + OAuth2Scopes, +} from './index'; /** * https://discord.com/developers/docs/resources/webhook#webhook-object @@ -63,6 +70,103 @@ export interface APIWebhook { url?: string; } +/** + * https://discord.com/developers/docs/events/webhook-events#payload-structure + */ +export interface APIEventWebhookEvent { + /** + * Version scheme for the webhook event. Currently always 1 + */ + version: 1; + /** + * ID of your app + */ + application_id: string; + /** + * Type of webhook, either 0 for PING or 1 for webhook events + */ + type: EventWebhookType; + /** + * Event data payload + */ + event?: APIEventWebhookEventBody; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-body-object + */ +export interface APIEventWebhookEventBody { + /** + * Event type + */ + type: WebhookEventType; + /** + * Timestamp of when the event occurred in ISO8601 format + */ + timestamp: string; + /** + * Data for the event. The shape depends on the event type + */ + data?: unknown; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure + */ +export interface APIEventWebhookApplicationAuthorizedBody { + /** + * Installation context for the authorization. + */ + integration_type?: ApplicationIntegrationType; + /** + * User who authorized the app + */ + user: APIUser; + /** + * List of scopes the user authorized + */ + scopes: OAuth2Scopes[]; + /** + * Server which app was authorized for (when integration type is 0) + */ + guild?: APIGuild; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#webhook-types + */ +export enum EventWebhookType { + /** + * PING event sent to verify your Webhook Event URL is active + */ + Ping, + /** + * Webhook event (details for event in event body object) + */ + Event, +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-types + */ +export enum WebhookEventType { + /** + * Sent when an app was authorized by a user to a server or their account + */ + ApplicationAuthorized = 'APPLICATION_AUTHORIZED', + /** + * Entitlement was created + */ + EntitlementCreate = 'ENTITLEMENT_CREATE', + /** + * User was added to a Quest (currently unavailable) + */ + QuestUserEnrollment = 'QUEST_USER_ENROLLMENT', +} + +/** + * https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types + */ export enum WebhookType { /** * Incoming Webhooks can post messages to channels with a generated token diff --git a/payloads/v9/application.ts b/payloads/v9/application.ts index d168dac3f..4f6aa5f76 100644 --- a/payloads/v9/application.ts +++ b/payloads/v9/application.ts @@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions'; import type { OAuth2Scopes } from './oauth2'; import type { APITeam } from './teams'; import type { APIUser } from './user'; +import type { WebhookEventType } from './webhook'; /** * https://discord.com/developers/docs/resources/application#application-object @@ -142,6 +143,18 @@ export interface APIApplication { * The application's default custom authorization link, if enabled */ custom_install_url?: string; + /** + * Event webhook URL for the app to receive webhook events + */ + event_webhooks_url?: string | null; + /** + * If webhook events are enabled for the app. + */ + event_webhooks_status: ApplicationEventWebhookStatus; + /** + * List of Webhook event types the app subscribes to + */ + event_webhooks_types?: WebhookEventType[]; } export interface APIApplicationInstallParams { @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType { */ BooleanNotEqual, } + +/** + * https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status + */ +export enum ApplicationEventWebhookStatus { + /** + * Webhook events are disabled by developer + */ + Disabled = 1, + /** + * Webhook events are enabled by developer + */ + Enabled, + /** + * Webhook events are disabled by Discord, usually do to inactivity + */ + DisabledByDiscord, +} diff --git a/payloads/v9/webhook.ts b/payloads/v9/webhook.ts index 4886b987a..de46decb1 100644 --- a/payloads/v9/webhook.ts +++ b/payloads/v9/webhook.ts @@ -3,7 +3,14 @@ */ import type { Snowflake } from '../../globals'; -import type { APIPartialChannel, APIPartialGuild, APIUser } from './index'; +import type { + APIGuild, + APIPartialChannel, + APIPartialGuild, + APIUser, + ApplicationIntegrationType, + OAuth2Scopes, +} from './index'; /** * https://discord.com/developers/docs/resources/webhook#webhook-object @@ -63,6 +70,103 @@ export interface APIWebhook { url?: string; } +/** + * https://discord.com/developers/docs/events/webhook-events#payload-structure + */ +export interface APIEventWebhookEvent { + /** + * Version scheme for the webhook event. Currently always 1 + */ + version: 1; + /** + * ID of your app + */ + application_id: string; + /** + * Type of webhook, either 0 for PING or 1 for webhook events + */ + type: EventWebhookType; + /** + * Event data payload + */ + event?: APIEventWebhookEventBody; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-body-object + */ +export interface APIEventWebhookEventBody { + /** + * Event type + */ + type: WebhookEventType; + /** + * Timestamp of when the event occurred in ISO8601 format + */ + timestamp: string; + /** + * Data for the event. The shape depends on the event type + */ + data?: unknown; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure + */ +export interface APIEventWebhookApplicationAuthorizedBody { + /** + * Installation context for the authorization. + */ + integration_type?: ApplicationIntegrationType; + /** + * User who authorized the app + */ + user: APIUser; + /** + * List of scopes the user authorized + */ + scopes: OAuth2Scopes[]; + /** + * Server which app was authorized for (when integration type is 0) + */ + guild?: APIGuild; +} + +/** + * https://discord.com/developers/docs/events/webhook-events#webhook-types + */ +export enum EventWebhookType { + /** + * PING event sent to verify your Webhook Event URL is active + */ + Ping, + /** + * Webhook event (details for event in event body object) + */ + Event, +} + +/** + * https://discord.com/developers/docs/events/webhook-events#event-types + */ +export enum WebhookEventType { + /** + * Sent when an app was authorized by a user to a server or their account + */ + ApplicationAuthorized = 'APPLICATION_AUTHORIZED', + /** + * Entitlement was created + */ + EntitlementCreate = 'ENTITLEMENT_CREATE', + /** + * User was added to a Quest (currently unavailable) + */ + QuestUserEnrollment = 'QUEST_USER_ENROLLMENT', +} + +/** + * https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types + */ export enum WebhookType { /** * Incoming Webhooks can post messages to channels with a generated token