Skip to content

Commit

Permalink
feat: webhook events (#1128)
Browse files Browse the repository at this point in the history
* feat: webhook events

* chore: fix naming because someone was high at Discord

* chore: fix build errors

* chore: woops

* chore: and now consistent

* docs: remove `.`

---------

Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 8659ac8 commit ced86e4
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 4 deletions.
31 changes: 31 additions & 0 deletions deno/payloads/v10/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ApplicationWebhookEventType } from './webhook.ts';

/**
* https://discord.com/developers/docs/resources/application#application-object
Expand Down Expand Up @@ -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: ApplicationWebhookEventStatus;
/**
* List of webhook event types the app subscribes to
*/
event_webhooks_types?: ApplicationWebhookEventType[];
}

export interface APIApplicationInstallParams {
Expand Down Expand Up @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType {
*/
BooleanNotEqual,
}

/**
* https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status
*/
export enum ApplicationWebhookEventStatus {
/**
* Webhook events are disabled by developer
*/
Disabled = 1,
/**
* Webhook events are enabled by developer
*/
Enabled,
/**
* Webhook events are disabled by Discord, usually due to inactivity
*/
DisabledByDiscord,
}
120 changes: 119 additions & 1 deletion deno/payloads/v10/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*/

import type { Snowflake } from '../../globals.ts';
import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts';
import type {
APIEntitlement,
APIGuild,
APIPartialChannel,
APIPartialGuild,
APIUser,
ApplicationIntegrationType,
OAuth2Scopes,
} from './mod.ts';

/**
* https://discord.com/developers/docs/resources/webhook#webhook-object
Expand Down Expand Up @@ -63,6 +71,116 @@ export interface APIWebhook {
url?: string;
}

/**
* https://discord.com/developers/docs/events/webhook-events#webhook-event-payloads
*/
export type APIWebhookEvent =
| APIWebhookEventBase<ApplicationWebhookType.Event, APIWebhookEventBody>
| APIWebhookEventBase<ApplicationWebhookType.Ping, never>;

/**
* https://discord.com/developers/docs/events/webhook-events#event-body-object
*/
export type APIWebhookEventBody =
| APIWebhookEventEventBase<
ApplicationWebhookEventType.ApplicationAuthorized,
APIWebhookEventApplicationAuthorizedData
>
| APIWebhookEventEventBase<ApplicationWebhookEventType.EntitlementCreate, APIWebhookEventEntitlementCreateData>
| APIWebhookEventEventBase<ApplicationWebhookEventType.QuestUserEnrollment, APIWebhookEventQuestUserEnrollmentData>;

export interface APIWebhookEventApplicationAuthorizedData {
/**
* Installation context for the authorization. Either guild (`0`) if installed to a server or user (`1`) if installed to a user's account
*/
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;
}

export type APIWebhookEventEntitlementCreateData = APIEntitlement;

export type APIWebhookEventQuestUserEnrollmentData = never;

interface APIWebhookEventBase<Type extends ApplicationWebhookType, Event> {
/**
* Version scheme for the webhook event. Currently always `1`
*/
version: 1;
/**
* ID of your app
*/
application_id: Snowflake;
/**
* Type of webhook
*/
type: Type;
/**
* Event data payload
*/
event: Event;
}

/**
* https://discord.com/developers/docs/events/webhook-events#webhook-types
*/
export enum ApplicationWebhookType {
/**
* PING event sent to verify your Webhook Event URL is active
*/
Ping,
/**
* Webhook event (details for event in event body object)
*/
Event,
}

interface APIWebhookEventEventBase<Type extends ApplicationWebhookEventType, Data> {
/**
* Event type
*/
type: Type;
/**
* Timestamp of when the event occurred in ISO8601 format
*/
timestamp: string;
/**
* Data for the event. The shape depends on the event type
*/
data: Data;
}

/**
* https://discord.com/developers/docs/events/webhook-events#event-types
*/
export enum ApplicationWebhookEventType {
/**
* 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
Expand Down
31 changes: 31 additions & 0 deletions deno/payloads/v9/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ApplicationWebhookEventType } from './webhook.ts';

/**
* https://discord.com/developers/docs/resources/application#application-object
Expand Down Expand Up @@ -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: ApplicationWebhookEventStatus;
/**
* List of webhook event types the app subscribes to
*/
event_webhooks_types?: ApplicationWebhookEventType[];
}

export interface APIApplicationInstallParams {
Expand Down Expand Up @@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType {
*/
BooleanNotEqual,
}

/**
* https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status
*/
export enum ApplicationWebhookEventStatus {
/**
* Webhook events are disabled by developer
*/
Disabled = 1,
/**
* Webhook events are enabled by developer
*/
Enabled,
/**
* Webhook events are disabled by Discord, usually due to inactivity
*/
DisabledByDiscord,
}
120 changes: 119 additions & 1 deletion deno/payloads/v9/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*/

import type { Snowflake } from '../../globals.ts';
import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts';
import type {
APIEntitlement,
APIGuild,
APIPartialChannel,
APIPartialGuild,
APIUser,
ApplicationIntegrationType,
OAuth2Scopes,
} from './mod.ts';

/**
* https://discord.com/developers/docs/resources/webhook#webhook-object
Expand Down Expand Up @@ -63,6 +71,116 @@ export interface APIWebhook {
url?: string;
}

/**
* https://discord.com/developers/docs/events/webhook-events#webhook-event-payloads
*/
export type APIWebhookEvent =
| APIWebhookEventBase<ApplicationWebhookType.Event, APIWebhookEventBody>
| APIWebhookEventBase<ApplicationWebhookType.Ping, never>;

/**
* https://discord.com/developers/docs/events/webhook-events#event-body-object
*/
export type APIWebhookEventBody =
| APIWebhookEventEventBase<
ApplicationWebhookEventType.ApplicationAuthorized,
APIWebhookEventApplicationAuthorizedData
>
| APIWebhookEventEventBase<ApplicationWebhookEventType.EntitlementCreate, APIWebhookEventEntitlementCreateData>
| APIWebhookEventEventBase<ApplicationWebhookEventType.QuestUserEnrollment, APIWebhookEventQuestUserEnrollmentData>;

export interface APIWebhookEventApplicationAuthorizedData {
/**
* Installation context for the authorization. Either guild (`0`) if installed to a server or user (`1`) if installed to a user's account
*/
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;
}

export type APIWebhookEventEntitlementCreateData = APIEntitlement;

export type APIWebhookEventQuestUserEnrollmentData = never;

interface APIWebhookEventBase<Type extends ApplicationWebhookType, Event> {
/**
* Version scheme for the webhook event. Currently always `1`
*/
version: 1;
/**
* ID of your app
*/
application_id: Snowflake;
/**
* Type of webhook
*/
type: Type;
/**
* Event data payload
*/
event: Event;
}

/**
* https://discord.com/developers/docs/events/webhook-events#webhook-types
*/
export enum ApplicationWebhookType {
/**
* PING event sent to verify your Webhook Event URL is active
*/
Ping,
/**
* Webhook event (details for event in event body object)
*/
Event,
}

interface APIWebhookEventEventBase<Type extends ApplicationWebhookEventType, Data> {
/**
* Event type
*/
type: Type;
/**
* Timestamp of when the event occurred in ISO8601 format
*/
timestamp: string;
/**
* Data for the event. The shape depends on the event type
*/
data: Data;
}

/**
* https://discord.com/developers/docs/events/webhook-events#event-types
*/
export enum ApplicationWebhookEventType {
/**
* 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
Expand Down
Loading

0 comments on commit ced86e4

Please sign in to comment.