Skip to content

Commit

Permalink
feat: webhook events
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Oct 30, 2024
1 parent 76b393a commit 897a753
Show file tree
Hide file tree
Showing 8 changed files with 544 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 { WebhookEventType } 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: ApplicationEventWebhookStatus;
/**
* List of Webhook event types the app subscribes to
*/
event_webhooks_types?: WebhookEventType[];
}

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 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,
}
106 changes: 105 additions & 1 deletion deno/payloads/v10/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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 { WebhookEventType } 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: ApplicationEventWebhookStatus;
/**
* List of Webhook event types the app subscribes to
*/
event_webhooks_types?: WebhookEventType[];
}

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 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,
}
106 changes: 105 additions & 1 deletion deno/payloads/v9/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions 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';
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
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: ApplicationEventWebhookStatus;
/**
* List of Webhook event types the app subscribes to
*/
event_webhooks_types?: WebhookEventType[];
}

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 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,
}
Loading

0 comments on commit 897a753

Please sign in to comment.