/
webhook.ts
268 lines (241 loc) · 8.19 KB
/
webhook.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import type { Snowflake } from '../../globals.ts';
import type {
APIAllowedMentions,
APIActionRowComponent,
APIEmbed,
APIMessage,
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageActionRowComponent,
} from '../../payloads/v9/mod.ts';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals.ts';
/**
* https://discord.com/developers/docs/resources/webhook#create-webhook
*/
export type RESTPostAPIChannelWebhookJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
/**
* Name of the webhook (1-80 characters)
*/
name: string;
/**
* Image for the default webhook avatar
*
* See https://discord.com/developers/docs/reference#image-data
*/
avatar?: string | null;
}>;
/**
* https://discord.com/developers/docs/resources/webhook#create-webhook
*/
export type RESTPostAPIChannelWebhookResult = APIWebhook;
/**
* https://discord.com/developers/docs/resources/webhook#get-channel-webhooks
*/
export type RESTGetAPIChannelWebhooksResult = APIWebhook[];
/**
* https://discord.com/developers/docs/resources/webhook#get-guild-webhooks
*/
export type RESTGetAPIGuildWebhooksResult = APIWebhook[];
/**
* https://discord.com/developers/docs/resources/webhook#get-webhook
*/
export type RESTGetAPIWebhookResult = APIWebhook;
/**
* https://discord.com/developers/docs/resources/webhook#get-webhook-with-token
*/
export type RESTGetAPIWebhookWithTokenResult = Omit<APIWebhook, 'user'>;
/**
* https://discord.com/developers/docs/resources/webhook#modify-webhook
*/
export type RESTPatchAPIWebhookJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
/**
* The default name of the webhook
*/
name?: string;
/**
* Image for the default webhook avatar
*
* See https://discord.com/developers/docs/reference#image-data
*/
avatar?: string | null;
/**
* The new channel id this webhook should be moved to
*/
channel_id?: Snowflake;
}>;
/**
* https://discord.com/developers/docs/resources/webhook#modify-webhook
*/
export type RESTPatchAPIWebhookResult = APIWebhook;
/**
* https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token
*/
export type RESTPatchAPIWebhookWithTokenJSONBody = Omit<RESTPatchAPIWebhookJSONBody, 'channel_id'>;
/**
* https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token
*/
export type RESTPatchAPIWebhookWithTokenResult = RESTGetAPIWebhookWithTokenResult;
/**
* https://discord.com/developers/docs/resources/webhook#delete-webhook
*/
export type RESTDeleteAPIWebhookResult = never;
/**
* https://discord.com/developers/docs/resources/webhook#delete-webhook-with-token
*/
export type RESTDeleteAPIWebhookWithTokenResult = never;
/**
* https://discord.com/developers/docs/resources/webhook#execute-webhook
*/
export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
/**
* The message contents (up to 2000 characters)
*/
content?: string;
/**
* Override the default username of the webhook
*/
username?: string;
/**
* Override the default avatar of the webhook
*/
avatar_url?: string;
/**
* `true` if this is a TTS message
*/
tts?: boolean;
/**
* Embedded `rich` content
*
* See https://discord.com/developers/docs/resources/channel#embed-object
*/
embeds?: APIEmbed[];
/**
* Allowed mentions for the message
*
* See https://discord.com/developers/docs/resources/channel#allowed-mentions-object
*/
allowed_mentions?: APIAllowedMentions;
/**
* The components to include with the message
*
* Requires an application-owned webhook
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent<APIMessageActionRowComponent>[];
/**
* Attachment objects with filename and description
*/
attachments?: (Pick<APIAttachment, 'id' | 'description'> & Partial<Pick<APIAttachment, 'filename'>>)[];
/**
* Message flags combined as a bitfield
*/
flags?: MessageFlags;
}>;
/**
* https://discord.com/developers/docs/resources/webhook#execute-webhook
*/
export type RESTPostAPIWebhookWithTokenFormDataBody =
| ({
/**
* JSON stringified message body
*/
payload_json?: string;
} & Record<`files[${bigint}]`, unknown>)
| (RESTPostAPIWebhookWithTokenJSONBody & Record<`files[${bigint}]`, unknown>);
/**
* https://discord.com/developers/docs/resources/webhook#execute-webhook-querystring-params
*/
export interface RESTPostAPIWebhookWithTokenQuery {
/**
* Waits for server confirmation of message send before response, and returns the created message body
* (defaults to `false`; when `false` a message that is not saved does not return an error)
*
* @default false
*/
wait?: boolean;
/**
* Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived.
*/
thread_id?: Snowflake;
}
/**
* https://discord.com/developers/docs/resources/webhook#execute-webhook
*/
export type RESTPostAPIWebhookWithTokenResult = never;
/**
* Received when a call to https://discord.com/developers/docs/resources/webhook#execute-webhook receives
* the `wait` query parameter set to `true`
*
* See https://discord.com/developers/docs/resources/webhook#execute-webhook-querystring-params
*/
export type RESTPostAPIWebhookWithTokenWaitResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook-querystring-params
*/
export type RESTPostAPIWebhookWithTokenSlackQuery = RESTPostAPIWebhookWithTokenQuery;
/**
* https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook
*/
export type RESTPostAPIWebhookWithTokenSlackResult = never;
/**
* Received when a call to https://discord.com/developers/docs/resources/webhook#execute-webhook receives
* the `wait` query parameter set to `true`
*
* See https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook-querystring-params
*/
export type RESTPostAPIWebhookWithTokenSlackWaitResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook-querystring-params
*/
export type RESTPostAPIWebhookWithTokenGitHubQuery = RESTPostAPIWebhookWithTokenQuery;
/**
* https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook
*/
export type RESTPostAPIWebhookWithTokenGitHubResult = never;
/**
* Received when a call to https://discord.com/developers/docs/resources/webhook#execute-webhook receives
* the `wait` query parameter set to `true`
*
* See https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook-querystring-params
*/
export type RESTPostAPIWebhookWithTokenGitHubWaitResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/webhook#get-webhook-message
*/
export type RESTGetAPIWebhookWithTokenMessageResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/webhook#edit-webhook-message
*/
export type RESTPatchAPIWebhookWithTokenMessageJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<
Nullable<Pick<RESTPostAPIWebhookWithTokenJSONBody, 'content' | 'embeds' | 'allowed_mentions' | 'components'>> & {
/**
* Attached files to keep
*
* Starting with API v10, the `attachments` array must contain all attachments that should be present after edit, including **retained and new** attachments provided in the request body.
*
* See https://discord.com/developers/docs/resources/channel#attachment-object
*/
attachments?: (Pick<APIAttachment, 'id'> & Partial<Pick<APIAttachment, 'filename' | 'description'>>)[];
}
>;
/**
* https://discord.com/developers/docs/resources/webhook#edit-webhook-message
*/
export type RESTPatchAPIWebhookWithTokenMessageFormDataBody =
| ({
/**
* JSON stringified message body
*/
payload_json?: string;
} & Record<`files[${bigint}]`, unknown>)
| (RESTPatchAPIWebhookWithTokenMessageJSONBody & Record<`files[${bigint}]`, unknown>);
/**
* https://discord.com/developers/docs/resources/webhook#edit-webhook-message
*/
export type RESTPatchAPIWebhookWithTokenMessageResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/webhook#delete-webhook-message
*/
export type RESTDeleteAPIWebhookWithTokenMessageResult = never;