Skip to content

Commit ced86e4

Browse files
sdanialrazavladfranguJiralite
authored
feat: webhook events (#1128)
* 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 <[email protected]> Co-authored-by: Jiralite <[email protected]>
1 parent 8659ac8 commit ced86e4

File tree

8 files changed

+600
-4
lines changed

8 files changed

+600
-4
lines changed

deno/payloads/v10/application.ts

+31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions.ts';
99
import type { OAuth2Scopes } from './oauth2.ts';
1010
import type { APITeam } from './teams.ts';
1111
import type { APIUser } from './user.ts';
12+
import type { ApplicationWebhookEventType } from './webhook.ts';
1213

1314
/**
1415
* https://discord.com/developers/docs/resources/application#application-object
@@ -142,6 +143,18 @@ export interface APIApplication {
142143
* The application's default custom authorization link, if enabled
143144
*/
144145
custom_install_url?: string;
146+
/**
147+
* Event webhook URL for the app to receive webhook events
148+
*/
149+
event_webhooks_url?: string | null;
150+
/**
151+
* If webhook events are enabled for the app
152+
*/
153+
event_webhooks_status: ApplicationWebhookEventStatus;
154+
/**
155+
* List of webhook event types the app subscribes to
156+
*/
157+
event_webhooks_types?: ApplicationWebhookEventType[];
145158
}
146159

147160
export interface APIApplicationInstallParams {
@@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType {
297310
*/
298311
BooleanNotEqual,
299312
}
313+
314+
/**
315+
* https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status
316+
*/
317+
export enum ApplicationWebhookEventStatus {
318+
/**
319+
* Webhook events are disabled by developer
320+
*/
321+
Disabled = 1,
322+
/**
323+
* Webhook events are enabled by developer
324+
*/
325+
Enabled,
326+
/**
327+
* Webhook events are disabled by Discord, usually due to inactivity
328+
*/
329+
DisabledByDiscord,
330+
}

deno/payloads/v10/webhook.ts

+119-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
*/
44

55
import type { Snowflake } from '../../globals.ts';
6-
import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts';
6+
import type {
7+
APIEntitlement,
8+
APIGuild,
9+
APIPartialChannel,
10+
APIPartialGuild,
11+
APIUser,
12+
ApplicationIntegrationType,
13+
OAuth2Scopes,
14+
} from './mod.ts';
715

816
/**
917
* https://discord.com/developers/docs/resources/webhook#webhook-object
@@ -63,6 +71,116 @@ export interface APIWebhook {
6371
url?: string;
6472
}
6573

74+
/**
75+
* https://discord.com/developers/docs/events/webhook-events#webhook-event-payloads
76+
*/
77+
export type APIWebhookEvent =
78+
| APIWebhookEventBase<ApplicationWebhookType.Event, APIWebhookEventBody>
79+
| APIWebhookEventBase<ApplicationWebhookType.Ping, never>;
80+
81+
/**
82+
* https://discord.com/developers/docs/events/webhook-events#event-body-object
83+
*/
84+
export type APIWebhookEventBody =
85+
| APIWebhookEventEventBase<
86+
ApplicationWebhookEventType.ApplicationAuthorized,
87+
APIWebhookEventApplicationAuthorizedData
88+
>
89+
| APIWebhookEventEventBase<ApplicationWebhookEventType.EntitlementCreate, APIWebhookEventEntitlementCreateData>
90+
| APIWebhookEventEventBase<ApplicationWebhookEventType.QuestUserEnrollment, APIWebhookEventQuestUserEnrollmentData>;
91+
92+
export interface APIWebhookEventApplicationAuthorizedData {
93+
/**
94+
* Installation context for the authorization. Either guild (`0`) if installed to a server or user (`1`) if installed to a user's account
95+
*/
96+
integration_type?: ApplicationIntegrationType;
97+
/**
98+
* User who authorized the app
99+
*/
100+
user: APIUser;
101+
/**
102+
* List of scopes the user authorized
103+
*/
104+
scopes: OAuth2Scopes[];
105+
/**
106+
* Server which app was authorized for (when integration type is `0`)
107+
*/
108+
guild?: APIGuild;
109+
}
110+
111+
export type APIWebhookEventEntitlementCreateData = APIEntitlement;
112+
113+
export type APIWebhookEventQuestUserEnrollmentData = never;
114+
115+
interface APIWebhookEventBase<Type extends ApplicationWebhookType, Event> {
116+
/**
117+
* Version scheme for the webhook event. Currently always `1`
118+
*/
119+
version: 1;
120+
/**
121+
* ID of your app
122+
*/
123+
application_id: Snowflake;
124+
/**
125+
* Type of webhook
126+
*/
127+
type: Type;
128+
/**
129+
* Event data payload
130+
*/
131+
event: Event;
132+
}
133+
134+
/**
135+
* https://discord.com/developers/docs/events/webhook-events#webhook-types
136+
*/
137+
export enum ApplicationWebhookType {
138+
/**
139+
* PING event sent to verify your Webhook Event URL is active
140+
*/
141+
Ping,
142+
/**
143+
* Webhook event (details for event in event body object)
144+
*/
145+
Event,
146+
}
147+
148+
interface APIWebhookEventEventBase<Type extends ApplicationWebhookEventType, Data> {
149+
/**
150+
* Event type
151+
*/
152+
type: Type;
153+
/**
154+
* Timestamp of when the event occurred in ISO8601 format
155+
*/
156+
timestamp: string;
157+
/**
158+
* Data for the event. The shape depends on the event type
159+
*/
160+
data: Data;
161+
}
162+
163+
/**
164+
* https://discord.com/developers/docs/events/webhook-events#event-types
165+
*/
166+
export enum ApplicationWebhookEventType {
167+
/**
168+
* Sent when an app was authorized by a user to a server or their account
169+
*/
170+
ApplicationAuthorized = 'APPLICATION_AUTHORIZED',
171+
/**
172+
* Entitlement was created
173+
*/
174+
EntitlementCreate = 'ENTITLEMENT_CREATE',
175+
/**
176+
* User was added to a Quest (currently unavailable)
177+
*/
178+
QuestUserEnrollment = 'QUEST_USER_ENROLLMENT',
179+
}
180+
181+
/**
182+
* https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types
183+
*/
66184
export enum WebhookType {
67185
/**
68186
* Incoming Webhooks can post messages to channels with a generated token

deno/payloads/v9/application.ts

+31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { ApplicationIntegrationType } from './interactions.ts';
99
import type { OAuth2Scopes } from './oauth2.ts';
1010
import type { APITeam } from './teams.ts';
1111
import type { APIUser } from './user.ts';
12+
import type { ApplicationWebhookEventType } from './webhook.ts';
1213

1314
/**
1415
* https://discord.com/developers/docs/resources/application#application-object
@@ -142,6 +143,18 @@ export interface APIApplication {
142143
* The application's default custom authorization link, if enabled
143144
*/
144145
custom_install_url?: string;
146+
/**
147+
* Event webhook URL for the app to receive webhook events
148+
*/
149+
event_webhooks_url?: string | null;
150+
/**
151+
* If webhook events are enabled for the app
152+
*/
153+
event_webhooks_status: ApplicationWebhookEventStatus;
154+
/**
155+
* List of webhook event types the app subscribes to
156+
*/
157+
event_webhooks_types?: ApplicationWebhookEventType[];
145158
}
146159

147160
export interface APIApplicationInstallParams {
@@ -297,3 +310,21 @@ export enum ApplicationRoleConnectionMetadataType {
297310
*/
298311
BooleanNotEqual,
299312
}
313+
314+
/**
315+
* https://discord.com/developers/docs/resources/application#application-object-application-event-webhook-status
316+
*/
317+
export enum ApplicationWebhookEventStatus {
318+
/**
319+
* Webhook events are disabled by developer
320+
*/
321+
Disabled = 1,
322+
/**
323+
* Webhook events are enabled by developer
324+
*/
325+
Enabled,
326+
/**
327+
* Webhook events are disabled by Discord, usually due to inactivity
328+
*/
329+
DisabledByDiscord,
330+
}

deno/payloads/v9/webhook.ts

+119-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
*/
44

55
import type { Snowflake } from '../../globals.ts';
6-
import type { APIPartialChannel, APIPartialGuild, APIUser } from './mod.ts';
6+
import type {
7+
APIEntitlement,
8+
APIGuild,
9+
APIPartialChannel,
10+
APIPartialGuild,
11+
APIUser,
12+
ApplicationIntegrationType,
13+
OAuth2Scopes,
14+
} from './mod.ts';
715

816
/**
917
* https://discord.com/developers/docs/resources/webhook#webhook-object
@@ -63,6 +71,116 @@ export interface APIWebhook {
6371
url?: string;
6472
}
6573

74+
/**
75+
* https://discord.com/developers/docs/events/webhook-events#webhook-event-payloads
76+
*/
77+
export type APIWebhookEvent =
78+
| APIWebhookEventBase<ApplicationWebhookType.Event, APIWebhookEventBody>
79+
| APIWebhookEventBase<ApplicationWebhookType.Ping, never>;
80+
81+
/**
82+
* https://discord.com/developers/docs/events/webhook-events#event-body-object
83+
*/
84+
export type APIWebhookEventBody =
85+
| APIWebhookEventEventBase<
86+
ApplicationWebhookEventType.ApplicationAuthorized,
87+
APIWebhookEventApplicationAuthorizedData
88+
>
89+
| APIWebhookEventEventBase<ApplicationWebhookEventType.EntitlementCreate, APIWebhookEventEntitlementCreateData>
90+
| APIWebhookEventEventBase<ApplicationWebhookEventType.QuestUserEnrollment, APIWebhookEventQuestUserEnrollmentData>;
91+
92+
export interface APIWebhookEventApplicationAuthorizedData {
93+
/**
94+
* Installation context for the authorization. Either guild (`0`) if installed to a server or user (`1`) if installed to a user's account
95+
*/
96+
integration_type?: ApplicationIntegrationType;
97+
/**
98+
* User who authorized the app
99+
*/
100+
user: APIUser;
101+
/**
102+
* List of scopes the user authorized
103+
*/
104+
scopes: OAuth2Scopes[];
105+
/**
106+
* Server which app was authorized for (when integration type is `0`)
107+
*/
108+
guild?: APIGuild;
109+
}
110+
111+
export type APIWebhookEventEntitlementCreateData = APIEntitlement;
112+
113+
export type APIWebhookEventQuestUserEnrollmentData = never;
114+
115+
interface APIWebhookEventBase<Type extends ApplicationWebhookType, Event> {
116+
/**
117+
* Version scheme for the webhook event. Currently always `1`
118+
*/
119+
version: 1;
120+
/**
121+
* ID of your app
122+
*/
123+
application_id: Snowflake;
124+
/**
125+
* Type of webhook
126+
*/
127+
type: Type;
128+
/**
129+
* Event data payload
130+
*/
131+
event: Event;
132+
}
133+
134+
/**
135+
* https://discord.com/developers/docs/events/webhook-events#webhook-types
136+
*/
137+
export enum ApplicationWebhookType {
138+
/**
139+
* PING event sent to verify your Webhook Event URL is active
140+
*/
141+
Ping,
142+
/**
143+
* Webhook event (details for event in event body object)
144+
*/
145+
Event,
146+
}
147+
148+
interface APIWebhookEventEventBase<Type extends ApplicationWebhookEventType, Data> {
149+
/**
150+
* Event type
151+
*/
152+
type: Type;
153+
/**
154+
* Timestamp of when the event occurred in ISO8601 format
155+
*/
156+
timestamp: string;
157+
/**
158+
* Data for the event. The shape depends on the event type
159+
*/
160+
data: Data;
161+
}
162+
163+
/**
164+
* https://discord.com/developers/docs/events/webhook-events#event-types
165+
*/
166+
export enum ApplicationWebhookEventType {
167+
/**
168+
* Sent when an app was authorized by a user to a server or their account
169+
*/
170+
ApplicationAuthorized = 'APPLICATION_AUTHORIZED',
171+
/**
172+
* Entitlement was created
173+
*/
174+
EntitlementCreate = 'ENTITLEMENT_CREATE',
175+
/**
176+
* User was added to a Quest (currently unavailable)
177+
*/
178+
QuestUserEnrollment = 'QUEST_USER_ENROLLMENT',
179+
}
180+
181+
/**
182+
* https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types
183+
*/
66184
export enum WebhookType {
67185
/**
68186
* Incoming Webhooks can post messages to channels with a generated token

0 commit comments

Comments
 (0)