Skip to content

Commit

Permalink
feat: webhook events
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Nov 5, 2024
1 parent 76b393a commit 74a6b5a
Show file tree
Hide file tree
Showing 8 changed files with 704 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 due to inactivity
*/
DisabledByDiscord,
}
151 changes: 150 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 } from '../v9.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 +71,147 @@ export interface APIWebhook {
url?: string;
}

/**
* https://discord.com/developers/docs/events/webhook-events#payload-structure
*/
export interface APIEventWebhookEventBase<EventType extends WebhookEventType, Data> {
/**
* 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?: APIEventWebhookEventBodyBase<EventType, Data>;
}

export type APIEventWebhookEvent =
| APIEventWebhookApplicationAuthorized
| APIEventWebhookEntitlementCreated
| APIEventWebhookQuestUserEnrollment;

/**
* https://discord.com/developers/docs/events/webhook-events#event-body-object
*/
export interface APIEventWebhookEventBodyBase<EventType extends WebhookEventType, Data> {
/**
* Event type
*/
type: EventType;
/**
* Timestamp of when the event occurred in ISO8601 format
*/
timestamp: string;
/**
* Data for the event. The shape depends on the event type
*/
data?: Data;
}

export type APIEventWebhookEventBody =
| APIEventWebhookApplicationAuthorizedData
| APIEventWebhookEntitlementCreatedData
| APIEventWebhookQuestUserEnrollmentData;

/**
* https://discord.com/developers/docs/events/webhook-events#application-authorized-application-authorized-structure
*/
export interface APIEventWebhookApplicationAuthorizedData {
/**
* 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#application-authorized
*/
export type APIEventWebhookApplicationAuthorized = APIEventWebhookEventBase<
WebhookEventType.ApplicationAuthorized,
APIEventWebhookApplicationAuthorizedData
>;

/**
* https://discord.com/developers/docs/events/webhook-events#entitlement-create-entitlement-create-structure
*/
export type APIEventWebhookEntitlementCreatedData = APIEntitlement;

/**
* https://discord.com/developers/docs/events/webhook-events#entitlement-create
*/
export type APIEventWebhookEntitlementCreated = APIEventWebhookEventBase<
WebhookEventType.EntitlementCreate,
APIEventWebhookEntitlementCreatedData
>;

/**
* https://discord.com/developers/docs/events/webhook-events#quest-user-enrollment
*/
export type APIEventWebhookQuestUserEnrollmentData = never;

/**
* https://discord.com/developers/docs/events/webhook-events#quest-user-enrollment
*/
export type APIEventWebhookQuestUserEnrollment = APIEventWebhookEventBase<
WebhookEventType.QuestUserEnrollment,
APIEventWebhookQuestUserEnrollmentData
>;

/**
* 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 due to inactivity
*/
DisabledByDiscord,
}
Loading

0 comments on commit 74a6b5a

Please sign in to comment.