telegram-bot-api-nodejs 1.0.2 โ 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +12 -10
- package/index.js +29 -14
- package/package.json +11 -4
- package/index.ts +0 -1617
- package/tsconfig.json +0 -8
package/index.ts
DELETED
|
@@ -1,1617 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common headers for API calls
|
|
3
|
-
*/
|
|
4
|
-
const headers = {
|
|
5
|
-
"Accept": "application/json",
|
|
6
|
-
"Content-Type": "application/json",
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type ChatType = "private"
|
|
10
|
-
| "group"
|
|
11
|
-
| "supergroup"
|
|
12
|
-
| "channel";
|
|
13
|
-
|
|
14
|
-
export type ChatAction = "typing"
|
|
15
|
-
| "upload_photo"
|
|
16
|
-
| "record_video"
|
|
17
|
-
| "upload_video"
|
|
18
|
-
| "record_audio"
|
|
19
|
-
| "upload_audio"
|
|
20
|
-
| "upload_document"
|
|
21
|
-
| "find_location"
|
|
22
|
-
| "record_video_note"
|
|
23
|
-
| "upload_video_note";
|
|
24
|
-
|
|
25
|
-
export type ChatMemberStatus = "creator"
|
|
26
|
-
| "administrator"
|
|
27
|
-
| "member"
|
|
28
|
-
| "restricted"
|
|
29
|
-
| "left"
|
|
30
|
-
| "kicked";
|
|
31
|
-
|
|
32
|
-
export type DocumentMimeType = "application/pdf" | "application/zip";
|
|
33
|
-
|
|
34
|
-
export type MessageType =
|
|
35
|
-
| "text"
|
|
36
|
-
| "animation"
|
|
37
|
-
| "audio"
|
|
38
|
-
| "channel_chat_created"
|
|
39
|
-
| "contact"
|
|
40
|
-
| "delete_chat_photo"
|
|
41
|
-
| "document"
|
|
42
|
-
| "game"
|
|
43
|
-
| "group_chat_created"
|
|
44
|
-
| "invoice"
|
|
45
|
-
| "left_chat_member"
|
|
46
|
-
| "location"
|
|
47
|
-
| "migrate_from_chat_id"
|
|
48
|
-
| "migrate_to_chat_id"
|
|
49
|
-
| "new_chat_members"
|
|
50
|
-
| "new_chat_photo"
|
|
51
|
-
| "new_chat_title"
|
|
52
|
-
| "passport_data"
|
|
53
|
-
| "photo"
|
|
54
|
-
| "pinned_message"
|
|
55
|
-
| "sticker"
|
|
56
|
-
| "successful_payment"
|
|
57
|
-
| "supergroup_chat_created"
|
|
58
|
-
| "video"
|
|
59
|
-
| "video_note"
|
|
60
|
-
| "voice";
|
|
61
|
-
|
|
62
|
-
type MessageEntityType = "mention"
|
|
63
|
-
| "hashtag"
|
|
64
|
-
| "bot_command"
|
|
65
|
-
| "url"
|
|
66
|
-
| "email"
|
|
67
|
-
| "bold"
|
|
68
|
-
| "italic"
|
|
69
|
-
| "code"
|
|
70
|
-
| "pre"
|
|
71
|
-
| "text_link"
|
|
72
|
-
| "text_mention"
|
|
73
|
-
|
|
74
|
-
type ParseMode = "Markdown"
|
|
75
|
-
| "MarkdownV2"
|
|
76
|
-
| "HTML";
|
|
77
|
-
|
|
78
|
-
export type AllowedUpdates = keyof (Omit<Update, "update_id">)
|
|
79
|
-
|
|
80
|
-
export interface SetWebHookOptions {
|
|
81
|
-
url: string;
|
|
82
|
-
max_connections?: number;
|
|
83
|
-
allowed_updates?: AllowedUpdates[]
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface SendBasicOptions {
|
|
87
|
-
chat_id: number | string
|
|
88
|
-
disable_notification?: boolean;
|
|
89
|
-
reply_to_message_id?: number | string;
|
|
90
|
-
reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface SendMessageOptions extends SendBasicOptions {
|
|
94
|
-
text: string
|
|
95
|
-
parse_mode?: ParseMode;
|
|
96
|
-
disable_web_page_preview?: boolean;
|
|
97
|
-
entities?: MessageEntity[]
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
interface AnswerInlineQueryOptions {
|
|
101
|
-
cache_time?: number;
|
|
102
|
-
is_personal?: boolean;
|
|
103
|
-
next_offset?: string;
|
|
104
|
-
switch_pm_text?: string;
|
|
105
|
-
switch_pm_parameter?: string;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
interface ForwardMessageOptions {
|
|
109
|
-
disable_notification?: boolean;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface SendPhotoOptions extends SendBasicOptions {
|
|
113
|
-
photo: string
|
|
114
|
-
parse_mode?: ParseMode;
|
|
115
|
-
caption?: string;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface SendAnimationOptions extends SendBasicOptions {
|
|
119
|
-
animation: string
|
|
120
|
-
parse_mode?: ParseMode;
|
|
121
|
-
caption?: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface SendAudioOptions extends SendBasicOptions {
|
|
125
|
-
parse_mode?: ParseMode;
|
|
126
|
-
caption?: string;
|
|
127
|
-
duration?: number;
|
|
128
|
-
performer?: string;
|
|
129
|
-
title?: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
interface SendDocumentOptions extends SendBasicOptions {
|
|
133
|
-
document: string
|
|
134
|
-
parse_mode?: ParseMode;
|
|
135
|
-
caption?: string;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
interface SendMediaGroupOptions {
|
|
139
|
-
disable_notification?: boolean;
|
|
140
|
-
reply_to_message_id?: number;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
type SendStickerOptions = SendBasicOptions;
|
|
144
|
-
|
|
145
|
-
interface SendVideoOptions extends SendBasicOptions {
|
|
146
|
-
parse_mode?: ParseMode;
|
|
147
|
-
duration?: number;
|
|
148
|
-
width?: number;
|
|
149
|
-
height?: number;
|
|
150
|
-
caption?: string;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
interface SendVoiceOptions extends SendBasicOptions {
|
|
154
|
-
parse_mode?: ParseMode;
|
|
155
|
-
caption?: string;
|
|
156
|
-
duration?: number;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
interface SendVideoNoteOptions extends SendBasicOptions {
|
|
160
|
-
duration?: number;
|
|
161
|
-
length?: number;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
type SendLocationOptions = SendBasicOptions;
|
|
165
|
-
|
|
166
|
-
type EditMessageLiveLocationOptions = EditMessageCaptionOptions;
|
|
167
|
-
|
|
168
|
-
type StopMessageLiveLocationOptions = EditMessageCaptionOptions;
|
|
169
|
-
|
|
170
|
-
interface SendVenueOptions extends SendBasicOptions {
|
|
171
|
-
foursquare_id?: string;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
interface SendContactOptions extends SendBasicOptions {
|
|
175
|
-
last_name?: string;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
type SendGameOptions = SendBasicOptions;
|
|
179
|
-
|
|
180
|
-
interface SendInvoiceOptions extends SendBasicOptions {
|
|
181
|
-
provider_data?: string;
|
|
182
|
-
photo_url?: string;
|
|
183
|
-
photo_size?: number;
|
|
184
|
-
photo_width?: number;
|
|
185
|
-
photo_height?: number;
|
|
186
|
-
need_name?: boolean;
|
|
187
|
-
need_phone_number?: boolean;
|
|
188
|
-
need_email?: boolean;
|
|
189
|
-
need_shipping_address?: boolean;
|
|
190
|
-
is_flexible?: boolean;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
interface RestrictChatMemberOptions {
|
|
194
|
-
until_date?: number;
|
|
195
|
-
can_send_messages?: boolean;
|
|
196
|
-
can_send_media_messages?: boolean;
|
|
197
|
-
can_send_other_messages?: boolean;
|
|
198
|
-
can_add_web_page_previews?: boolean;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
interface PromoteChatMemberOptions {
|
|
202
|
-
can_change_info?: boolean
|
|
203
|
-
can_post_messages?: boolean
|
|
204
|
-
can_edit_messages?: boolean
|
|
205
|
-
can_delete_messages?: boolean
|
|
206
|
-
can_invite_users?: boolean
|
|
207
|
-
can_restrict_members?: boolean
|
|
208
|
-
can_pin_messages?: boolean
|
|
209
|
-
can_promote_members?: boolean
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export interface AnswerCallbackQueryOptions {
|
|
213
|
-
callback_query_id: string
|
|
214
|
-
text?: string
|
|
215
|
-
show_alert?: boolean
|
|
216
|
-
url?: string
|
|
217
|
-
cache_time?: number
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
interface SetMyCommandsOptions {
|
|
221
|
-
commands: BotCommand[]
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
interface DeleteMyCommandsOptions { }
|
|
225
|
-
|
|
226
|
-
interface EditMessageTextOptions extends EditMessageReplyMarkupOptions {
|
|
227
|
-
parse_mode?: ParseMode;
|
|
228
|
-
disable_web_page_preview?: boolean;
|
|
229
|
-
text: string
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
interface EditMessageCaptionOptions extends EditMessageReplyMarkupOptions {
|
|
233
|
-
reply_markup?: InlineKeyboardMarkup;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
interface EditMessageReplyMarkupOptions {
|
|
237
|
-
chat_id?: number | string;
|
|
238
|
-
message_id?: number | string;
|
|
239
|
-
inline_message_id?: string;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
interface SetGameScoreOptions {
|
|
243
|
-
force?: boolean;
|
|
244
|
-
disable_edit_message?: boolean;
|
|
245
|
-
chat_id?: number;
|
|
246
|
-
message_id?: number;
|
|
247
|
-
inline_message_id?: string;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
interface GetGameHighScoresOptions {
|
|
251
|
-
chat_id?: number;
|
|
252
|
-
message_id?: number;
|
|
253
|
-
inline_message_id?: string;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
interface AnswerShippingQueryOptions {
|
|
257
|
-
shipping_options?: ShippingOption[];
|
|
258
|
-
error_message?: string;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
interface AnswerPreCheckoutQueryOptions {
|
|
262
|
-
error_message?: string;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/// TELEGRAM TYPES ///
|
|
266
|
-
interface PassportFile {
|
|
267
|
-
file_id: string;
|
|
268
|
-
file_size: number;
|
|
269
|
-
file_date: number;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
interface EncryptedPassportElement {
|
|
273
|
-
type: string;
|
|
274
|
-
data?: string;
|
|
275
|
-
phone_number?: string;
|
|
276
|
-
email?: string;
|
|
277
|
-
files?: PassportFile[];
|
|
278
|
-
front_side?: PassportFile;
|
|
279
|
-
reverse_side?: PassportFile;
|
|
280
|
-
selfie?: PassportFile;
|
|
281
|
-
translation?: PassportFile[];
|
|
282
|
-
hash: string;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
interface EncryptedCredentials {
|
|
286
|
-
data: string;
|
|
287
|
-
hash: string;
|
|
288
|
-
secret: string;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
interface PassportData {
|
|
292
|
-
data: EncryptedPassportElement[];
|
|
293
|
-
credentials: EncryptedCredentials;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export interface Update {
|
|
297
|
-
update_id: number;
|
|
298
|
-
message?: Message;
|
|
299
|
-
edited_message?: Message;
|
|
300
|
-
channel_post?: Message;
|
|
301
|
-
edited_channel_post?: Message
|
|
302
|
-
message_reaction?: MessageReactionUpdated
|
|
303
|
-
message_reaction_count?: MessageReactionCountUpdated
|
|
304
|
-
inline_query?: InlineQuery;
|
|
305
|
-
chosen_inline_result?: ChosenInlineResult;
|
|
306
|
-
callback_query?: CallbackQuery;
|
|
307
|
-
shipping_query?: ShippingQuery;
|
|
308
|
-
pre_checkout_query?: PreCheckoutQuery;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export interface WebhookInfo {
|
|
312
|
-
url: string;
|
|
313
|
-
has_custom_certificate: boolean;
|
|
314
|
-
pending_update_count: number;
|
|
315
|
-
last_error_date?: number;
|
|
316
|
-
last_error_message?: string;
|
|
317
|
-
max_connections?: number;
|
|
318
|
-
allowed_updates?: AllowedUpdates[]
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export interface User {
|
|
322
|
-
id: string;
|
|
323
|
-
is_bot: boolean;
|
|
324
|
-
first_name: string;
|
|
325
|
-
last_name?: string;
|
|
326
|
-
username?: string;
|
|
327
|
-
language_code?: string;
|
|
328
|
-
can_join_groups?: boolean
|
|
329
|
-
supports_inline_queries?: boolean
|
|
330
|
-
can_read_all_group_messages?: boolean
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export interface Chat {
|
|
334
|
-
id: number;
|
|
335
|
-
type: ChatType;
|
|
336
|
-
title?: string;
|
|
337
|
-
username?: string;
|
|
338
|
-
first_name?: string;
|
|
339
|
-
last_name?: string;
|
|
340
|
-
photo?: ChatPhoto;
|
|
341
|
-
description?: string;
|
|
342
|
-
invite_link?: string;
|
|
343
|
-
pinned_message?: Message;
|
|
344
|
-
permissions?: ChatPermissions;
|
|
345
|
-
can_set_sticker_set?: boolean;
|
|
346
|
-
sticker_set_name?: string;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
export interface Message {
|
|
350
|
-
message_id: number;
|
|
351
|
-
from?: User;
|
|
352
|
-
date: number;
|
|
353
|
-
chat: Chat;
|
|
354
|
-
forward_from?: User;
|
|
355
|
-
forward_from_chat?: Chat;
|
|
356
|
-
forward_from_message_id?: number;
|
|
357
|
-
forward_signature?: string;
|
|
358
|
-
forward_sender_name?: string;
|
|
359
|
-
forward_date?: number;
|
|
360
|
-
reply_to_message?: Message;
|
|
361
|
-
edit_date?: number;
|
|
362
|
-
media_group_id?: string;
|
|
363
|
-
author_signature?: string;
|
|
364
|
-
text?: string;
|
|
365
|
-
entities?: MessageEntity[];
|
|
366
|
-
caption_entities?: MessageEntity[];
|
|
367
|
-
audio?: Audio;
|
|
368
|
-
document?: Document;
|
|
369
|
-
animation?: Animation;
|
|
370
|
-
game?: Game;
|
|
371
|
-
photo?: PhotoSize[];
|
|
372
|
-
sticker?: Sticker;
|
|
373
|
-
video?: Video;
|
|
374
|
-
voice?: Voice;
|
|
375
|
-
video_note?: VideoNote;
|
|
376
|
-
caption?: string;
|
|
377
|
-
contact?: Contact;
|
|
378
|
-
location?: Location;
|
|
379
|
-
venue?: Venue;
|
|
380
|
-
poll?: Poll;
|
|
381
|
-
new_chat_members?: User[];
|
|
382
|
-
left_chat_member?: User;
|
|
383
|
-
new_chat_title?: string;
|
|
384
|
-
new_chat_photo?: PhotoSize[];
|
|
385
|
-
delete_chat_photo?: boolean;
|
|
386
|
-
group_chat_created?: boolean;
|
|
387
|
-
supergroup_chat_created?: boolean;
|
|
388
|
-
channel_chat_created?: boolean;
|
|
389
|
-
migrate_to_chat_id?: number;
|
|
390
|
-
migrate_from_chat_id?: number;
|
|
391
|
-
pinned_message?: Message;
|
|
392
|
-
invoice?: Invoice;
|
|
393
|
-
successful_payment?: SuccessfulPayment;
|
|
394
|
-
connected_website?: string;
|
|
395
|
-
passport_data?: PassportData;
|
|
396
|
-
reply_markup?: InlineKeyboardMarkup;
|
|
397
|
-
sender_chat?: Chat
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
export interface MessageReactionUpdated {
|
|
401
|
-
chat: Chat
|
|
402
|
-
message_id: number
|
|
403
|
-
user?: User
|
|
404
|
-
actor_chat?: Chat
|
|
405
|
-
date: number
|
|
406
|
-
old_reaction: ReactionType[]
|
|
407
|
-
new_reaction: ReactionType[]
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* @see https://core.telegram.org/bots/api#reactiontype
|
|
412
|
-
*/
|
|
413
|
-
export type ReactionType = ReactionTypeEmoji
|
|
414
|
-
| ReactionTypeCustomEmoji
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* @see https://core.telegram.org/bots/api#reactiontypeemoji
|
|
418
|
-
*/
|
|
419
|
-
export interface ReactionTypeEmoji {
|
|
420
|
-
type: "emoji"
|
|
421
|
-
emoji: string
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* @see https://core.telegram.org/bots/api#reactiontypecustomemoji
|
|
426
|
-
*/
|
|
427
|
-
export interface ReactionTypeCustomEmoji {
|
|
428
|
-
type: "custom_emoji"
|
|
429
|
-
custom_emoji_id: string
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* @see https://core.telegram.org/bots/api#messagereactioncountupdated
|
|
434
|
-
*/
|
|
435
|
-
export interface MessageReactionCountUpdated {
|
|
436
|
-
chat: Chat
|
|
437
|
-
message_id: number
|
|
438
|
-
date: number
|
|
439
|
-
reactions: ReactionCount[]
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* @see https://core.telegram.org/bots/api#reactioncount
|
|
444
|
-
*/
|
|
445
|
-
export interface ReactionCount {
|
|
446
|
-
type: ReactionType
|
|
447
|
-
total_count: number
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export interface MessageEntity {
|
|
451
|
-
type: MessageEntityType;
|
|
452
|
-
offset: number;
|
|
453
|
-
length: number;
|
|
454
|
-
url?: string;
|
|
455
|
-
user?: User;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
interface FileBase {
|
|
459
|
-
file_id: string;
|
|
460
|
-
file_size?: number;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
export interface PhotoSize extends FileBase {
|
|
464
|
-
width: number;
|
|
465
|
-
height: number;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
export interface Audio extends FileBase {
|
|
469
|
-
duration: number;
|
|
470
|
-
performer?: string;
|
|
471
|
-
title?: string;
|
|
472
|
-
file_name?: string;
|
|
473
|
-
mime_type?: string;
|
|
474
|
-
thumb?: PhotoSize;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
export interface Document extends FileBase {
|
|
478
|
-
thumb?: PhotoSize;
|
|
479
|
-
file_name?: string;
|
|
480
|
-
mime_type?: string;
|
|
481
|
-
file_size?: number;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
export interface Video extends FileBase {
|
|
485
|
-
width: number;
|
|
486
|
-
height: number;
|
|
487
|
-
duration: number;
|
|
488
|
-
thumb?: PhotoSize;
|
|
489
|
-
mime_type?: string;
|
|
490
|
-
file_name?: string;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
export interface Voice extends FileBase {
|
|
494
|
-
duration: number;
|
|
495
|
-
mime_type?: string;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
interface InputMediaBase {
|
|
499
|
-
media: string;
|
|
500
|
-
caption?: string;
|
|
501
|
-
parse_mode?: ParseMode;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
interface InputMediaPhoto extends InputMediaBase {
|
|
505
|
-
type: "photo";
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
interface InputMediaVideo extends InputMediaBase {
|
|
509
|
-
type: "video";
|
|
510
|
-
width?: number;
|
|
511
|
-
height?: number;
|
|
512
|
-
duration?: number;
|
|
513
|
-
supports_streaming?: boolean;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
type InputMedia = InputMediaPhoto | InputMediaVideo;
|
|
517
|
-
|
|
518
|
-
export interface VideoNote extends FileBase {
|
|
519
|
-
length: number;
|
|
520
|
-
duration: number;
|
|
521
|
-
thumb?: PhotoSize;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
export interface Contact {
|
|
525
|
-
phone_number: string;
|
|
526
|
-
first_name: string;
|
|
527
|
-
last_name?: string;
|
|
528
|
-
user_id?: number;
|
|
529
|
-
vcard?: string;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
export interface Location {
|
|
533
|
-
longitude: number;
|
|
534
|
-
latitude: number;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
export interface Venue {
|
|
538
|
-
location: Location;
|
|
539
|
-
title: string;
|
|
540
|
-
address: string;
|
|
541
|
-
foursquare_id?: string;
|
|
542
|
-
foursquare_type?: string;
|
|
543
|
-
google_place_id?: string;
|
|
544
|
-
google_place_type?: string;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
export interface PollOption {
|
|
548
|
-
text: string;
|
|
549
|
-
voter_count: number;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
export interface Poll {
|
|
553
|
-
id: string;
|
|
554
|
-
question: string;
|
|
555
|
-
options: PollOption[];
|
|
556
|
-
is_closed: boolean;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
export interface UserProfilePhotos {
|
|
560
|
-
total_count: number;
|
|
561
|
-
photos: PhotoSize[][];
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
export interface File extends FileBase {
|
|
565
|
-
file_path?: string;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
interface ReplyKeyboardMarkup {
|
|
569
|
-
keyboard: KeyboardButton[][];
|
|
570
|
-
resize_keyboard?: boolean;
|
|
571
|
-
one_time_keyboard?: boolean;
|
|
572
|
-
selective?: boolean;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
interface KeyboardButton {
|
|
576
|
-
text: string;
|
|
577
|
-
request_contact?: boolean;
|
|
578
|
-
request_location?: boolean;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
interface ReplyKeyboardRemove {
|
|
582
|
-
remove_keyboard: boolean;
|
|
583
|
-
selective?: boolean;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
export interface InlineKeyboardMarkup {
|
|
587
|
-
inline_keyboard: InlineKeyboardButton[][];
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
export interface InlineKeyboardButton {
|
|
591
|
-
text: string;
|
|
592
|
-
url?: string;
|
|
593
|
-
login_url?: LoginUrl;
|
|
594
|
-
callback_data?: string;
|
|
595
|
-
switch_inline_query?: string;
|
|
596
|
-
switch_inline_query_current_chat?: string;
|
|
597
|
-
callback_game?: CallbackGame;
|
|
598
|
-
pay?: boolean;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
interface LoginUrl {
|
|
602
|
-
url: string;
|
|
603
|
-
forward_text?: string;
|
|
604
|
-
bot_username?: string;
|
|
605
|
-
request_write_acces?: boolean;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
export interface CallbackQuery {
|
|
609
|
-
id: string;
|
|
610
|
-
from: User;
|
|
611
|
-
message?: Message;
|
|
612
|
-
inline_message_id?: string;
|
|
613
|
-
chat_instance: string;
|
|
614
|
-
data?: string;
|
|
615
|
-
game_short_name?: string;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
interface ForceReply {
|
|
619
|
-
force_reply: boolean;
|
|
620
|
-
selective?: boolean;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
interface ChatPhoto {
|
|
624
|
-
small_file_id: string
|
|
625
|
-
small_file_unique_id: string
|
|
626
|
-
big_file_id: string
|
|
627
|
-
big_file_unique_id: string
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
interface ChatMember {
|
|
631
|
-
user: User;
|
|
632
|
-
status: ChatMemberStatus;
|
|
633
|
-
until_date?: number;
|
|
634
|
-
can_be_edited?: boolean;
|
|
635
|
-
can_post_messages?: boolean;
|
|
636
|
-
can_edit_messages?: boolean;
|
|
637
|
-
can_delete_messages?: boolean;
|
|
638
|
-
can_restrict_members?: boolean;
|
|
639
|
-
can_promote_members?: boolean;
|
|
640
|
-
can_change_info?: boolean;
|
|
641
|
-
can_invite_users?: boolean;
|
|
642
|
-
can_pin_messages?: boolean;
|
|
643
|
-
is_member?: boolean;
|
|
644
|
-
can_send_messages?: boolean;
|
|
645
|
-
can_send_media_messages?: boolean;
|
|
646
|
-
can_send_polls: boolean;
|
|
647
|
-
can_send_other_messages?: boolean;
|
|
648
|
-
can_add_web_page_previews?: boolean;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
interface ChatPermissions {
|
|
652
|
-
can_send_messages?: boolean;
|
|
653
|
-
can_send_media_messages?: boolean;
|
|
654
|
-
can_send_polls?: boolean;
|
|
655
|
-
can_send_other_messages?: boolean;
|
|
656
|
-
can_add_web_page_previews?: boolean;
|
|
657
|
-
can_change_info?: boolean;
|
|
658
|
-
can_invite_users?: boolean;
|
|
659
|
-
can_pin_messages?: boolean;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
export interface Sticker {
|
|
663
|
-
file_id: string;
|
|
664
|
-
width: number;
|
|
665
|
-
height: number;
|
|
666
|
-
thumb?: PhotoSize;
|
|
667
|
-
emoji?: string;
|
|
668
|
-
set_name?: string;
|
|
669
|
-
mask_position?: MaskPosition;
|
|
670
|
-
file_size?: number;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
interface StickerSet {
|
|
674
|
-
name: string;
|
|
675
|
-
title: string;
|
|
676
|
-
contains_masks: boolean;
|
|
677
|
-
stickers: Sticker[];
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
interface MaskPosition {
|
|
681
|
-
point: string;
|
|
682
|
-
x_shift: number;
|
|
683
|
-
y_shift: number;
|
|
684
|
-
scale: number;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
interface InlineQuery {
|
|
688
|
-
id: string;
|
|
689
|
-
from: User;
|
|
690
|
-
location?: Location;
|
|
691
|
-
query: string;
|
|
692
|
-
offset: string;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
interface InlineQueryResultBase {
|
|
696
|
-
id: string;
|
|
697
|
-
reply_markup?: InlineKeyboardMarkup;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
interface InlineQueryResultArticle extends InlineQueryResultBase {
|
|
701
|
-
type: "article";
|
|
702
|
-
title: string;
|
|
703
|
-
input_message_content: InputMessageContent;
|
|
704
|
-
url?: string;
|
|
705
|
-
hide_url?: boolean;
|
|
706
|
-
description?: string;
|
|
707
|
-
thumb_url?: string;
|
|
708
|
-
thumb_width?: number;
|
|
709
|
-
thumb_height?: number;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
interface InlineQueryResultPhoto extends InlineQueryResultBase {
|
|
713
|
-
type: "photo";
|
|
714
|
-
photo_url: string;
|
|
715
|
-
thumb_url: string;
|
|
716
|
-
photo_width?: number;
|
|
717
|
-
photo_height?: number;
|
|
718
|
-
title?: string;
|
|
719
|
-
description?: string;
|
|
720
|
-
caption?: string;
|
|
721
|
-
input_message_content?: InputMessageContent;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
interface InlineQueryResultGif extends InlineQueryResultBase {
|
|
725
|
-
type: "gif";
|
|
726
|
-
gif_url: string;
|
|
727
|
-
gif_width?: number;
|
|
728
|
-
gif_height?: number;
|
|
729
|
-
gif_duration?: number;
|
|
730
|
-
thumb_url?: string;
|
|
731
|
-
title?: string;
|
|
732
|
-
caption?: string;
|
|
733
|
-
input_message_content?: InputMessageContent;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
interface InlineQueryResultMpeg4Gif extends InlineQueryResultBase {
|
|
737
|
-
type: "mpeg4_gif";
|
|
738
|
-
mpeg4_url: string;
|
|
739
|
-
mpeg4_width?: number;
|
|
740
|
-
mpeg4_height?: number;
|
|
741
|
-
mpeg4_duration?: number;
|
|
742
|
-
thumb_url?: string;
|
|
743
|
-
title?: string;
|
|
744
|
-
caption?: string;
|
|
745
|
-
input_message_content?: InputMessageContent;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
interface InlineQueryResultVideo extends InlineQueryResultBase {
|
|
749
|
-
type: "video";
|
|
750
|
-
video_url: string;
|
|
751
|
-
mime_type: string;
|
|
752
|
-
thumb_url: string;
|
|
753
|
-
title: string;
|
|
754
|
-
caption?: string;
|
|
755
|
-
video_width?: number;
|
|
756
|
-
video_height?: number;
|
|
757
|
-
video_duration?: number;
|
|
758
|
-
description?: string;
|
|
759
|
-
input_message_content?: InputMessageContent;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
interface InlineQueryResultAudio extends InlineQueryResultBase {
|
|
763
|
-
type: "audio";
|
|
764
|
-
audio_url: string;
|
|
765
|
-
title: string;
|
|
766
|
-
caption?: string;
|
|
767
|
-
performer?: string;
|
|
768
|
-
audio_duration?: number;
|
|
769
|
-
input_message_content?: InputMessageContent;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
interface InlineQueryResultVoice extends InlineQueryResultBase {
|
|
773
|
-
type: "voice";
|
|
774
|
-
voice_url: string;
|
|
775
|
-
title: string;
|
|
776
|
-
caption?: string;
|
|
777
|
-
voice_duration?: number;
|
|
778
|
-
input_message_content?: InputMessageContent;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
interface InlineQueryResultDocument extends InlineQueryResultBase {
|
|
782
|
-
type: "document";
|
|
783
|
-
title: string;
|
|
784
|
-
caption?: string;
|
|
785
|
-
document_url: string;
|
|
786
|
-
mime_type: string;
|
|
787
|
-
description?: string;
|
|
788
|
-
input_message_content?: InputMessageContent;
|
|
789
|
-
thumb_url?: string;
|
|
790
|
-
thumb_width?: number;
|
|
791
|
-
thumb_height?: number;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
interface InlineQueryResultLocationBase extends InlineQueryResultBase {
|
|
795
|
-
latitude: number;
|
|
796
|
-
longitude: number;
|
|
797
|
-
title: string;
|
|
798
|
-
input_message_content?: InputMessageContent;
|
|
799
|
-
thumb_url?: string;
|
|
800
|
-
thumb_width?: number;
|
|
801
|
-
thumb_height?: number;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
interface InlineQueryResultLocation extends InlineQueryResultLocationBase {
|
|
805
|
-
type: "location";
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
interface InlineQueryResultVenue extends InlineQueryResultLocationBase {
|
|
809
|
-
type: "venue";
|
|
810
|
-
address: string;
|
|
811
|
-
foursquare_id?: string;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
interface InlineQueryResultContact extends InlineQueryResultBase {
|
|
815
|
-
type: "contact";
|
|
816
|
-
phone_number: string;
|
|
817
|
-
first_name: string;
|
|
818
|
-
last_name?: string;
|
|
819
|
-
input_message_content?: InputMessageContent;
|
|
820
|
-
thumb_url?: string;
|
|
821
|
-
thumb_width?: number;
|
|
822
|
-
thumb_height?: number;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
interface InlineQueryResultGame extends InlineQueryResultBase {
|
|
826
|
-
type: "game";
|
|
827
|
-
game_short_name: string;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
interface InlineQueryResultCachedPhoto extends InlineQueryResultBase {
|
|
831
|
-
type: "photo";
|
|
832
|
-
photo_file_id: string;
|
|
833
|
-
title?: string;
|
|
834
|
-
description?: string;
|
|
835
|
-
caption?: string;
|
|
836
|
-
input_message_content?: InputMessageContent;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
interface InlineQueryResultCachedGif extends InlineQueryResultBase {
|
|
840
|
-
type: "gif";
|
|
841
|
-
gif_file_id: string;
|
|
842
|
-
title?: string;
|
|
843
|
-
caption?: string;
|
|
844
|
-
input_message_content?: InputMessageContent;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
interface InlineQueryResultCachedMpeg4Gif extends InlineQueryResultBase {
|
|
848
|
-
type: "mpeg4_gif";
|
|
849
|
-
mpeg4_file_id: string;
|
|
850
|
-
title?: string;
|
|
851
|
-
caption?: string;
|
|
852
|
-
input_message_content?: InputMessageContent;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
interface InlineQueryResultCachedSticker extends InlineQueryResultBase {
|
|
856
|
-
type: "sticker";
|
|
857
|
-
sticker_file_id: string;
|
|
858
|
-
input_message_content?: InputMessageContent;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
interface InlineQueryResultCachedDocument extends InlineQueryResultBase {
|
|
862
|
-
type: "document";
|
|
863
|
-
title: string;
|
|
864
|
-
document_file_id: string;
|
|
865
|
-
description?: string;
|
|
866
|
-
caption?: string;
|
|
867
|
-
input_message_content?: InputMessageContent;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
interface InlineQueryResultCachedVideo extends InlineQueryResultBase {
|
|
871
|
-
type: "video";
|
|
872
|
-
video_file_id: string;
|
|
873
|
-
title: string;
|
|
874
|
-
description?: string;
|
|
875
|
-
caption?: string;
|
|
876
|
-
input_message_content?: InputMessageContent;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
interface InlineQueryResultCachedVoice extends InlineQueryResultBase {
|
|
880
|
-
type: "voice";
|
|
881
|
-
voice_file_id: string;
|
|
882
|
-
title: string;
|
|
883
|
-
caption?: string;
|
|
884
|
-
input_message_content?: InputMessageContent;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
interface InlineQueryResultCachedAudio extends InlineQueryResultBase {
|
|
888
|
-
type: "audio";
|
|
889
|
-
audio_file_id: string;
|
|
890
|
-
caption?: string;
|
|
891
|
-
input_message_content?: InputMessageContent;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
type InlineQueryResult =
|
|
895
|
-
InlineQueryResultCachedAudio |
|
|
896
|
-
InlineQueryResultCachedDocument |
|
|
897
|
-
InlineQueryResultCachedGif |
|
|
898
|
-
InlineQueryResultCachedMpeg4Gif |
|
|
899
|
-
InlineQueryResultCachedPhoto |
|
|
900
|
-
InlineQueryResultCachedSticker |
|
|
901
|
-
InlineQueryResultCachedVideo |
|
|
902
|
-
InlineQueryResultCachedVoice |
|
|
903
|
-
InlineQueryResultArticle |
|
|
904
|
-
InlineQueryResultAudio |
|
|
905
|
-
InlineQueryResultContact |
|
|
906
|
-
InlineQueryResultGame |
|
|
907
|
-
InlineQueryResultDocument |
|
|
908
|
-
InlineQueryResultGif |
|
|
909
|
-
InlineQueryResultLocation |
|
|
910
|
-
InlineQueryResultMpeg4Gif |
|
|
911
|
-
InlineQueryResultPhoto |
|
|
912
|
-
InlineQueryResultVenue |
|
|
913
|
-
InlineQueryResultVideo |
|
|
914
|
-
InlineQueryResultVoice;
|
|
915
|
-
|
|
916
|
-
type InputMessageContent = object;
|
|
917
|
-
|
|
918
|
-
interface InputTextMessageContent extends InputMessageContent {
|
|
919
|
-
message_text: string;
|
|
920
|
-
parse_mode?: ParseMode;
|
|
921
|
-
disable_web_page_preview?: boolean;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
interface InputLocationMessageContent extends InputMessageContent {
|
|
925
|
-
latitude: number;
|
|
926
|
-
longitude: number;
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
interface InputVenueMessageContent extends InputLocationMessageContent {
|
|
930
|
-
title: string;
|
|
931
|
-
address: string;
|
|
932
|
-
foursquare_id?: string;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
interface InputContactMessageContent extends InputMessageContent {
|
|
936
|
-
phone_number: string;
|
|
937
|
-
first_name: string;
|
|
938
|
-
last_name?: string;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
interface ChosenInlineResult {
|
|
942
|
-
result_id: string;
|
|
943
|
-
from: User;
|
|
944
|
-
location?: Location;
|
|
945
|
-
inline_message_id?: string;
|
|
946
|
-
query: string;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
interface ResponseParameters {
|
|
950
|
-
migrate_to_chat_id?: number;
|
|
951
|
-
retry_after?: number;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
interface LabeledPrice {
|
|
955
|
-
label: string;
|
|
956
|
-
amount: number;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
interface Invoice {
|
|
960
|
-
title: string;
|
|
961
|
-
description: string;
|
|
962
|
-
start_parameter: string;
|
|
963
|
-
currency: string;
|
|
964
|
-
total_amount: number;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
interface ShippingAddress {
|
|
968
|
-
country_code: string;
|
|
969
|
-
state: string;
|
|
970
|
-
city: string;
|
|
971
|
-
street_line1: string;
|
|
972
|
-
street_line2: string;
|
|
973
|
-
post_code: string;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
interface OrderInfo {
|
|
977
|
-
name?: string;
|
|
978
|
-
phone_number?: string;
|
|
979
|
-
email?: string;
|
|
980
|
-
shipping_address?: ShippingAddress;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
interface ShippingOption {
|
|
984
|
-
id: string;
|
|
985
|
-
title: string;
|
|
986
|
-
prices: LabeledPrice[];
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
interface SuccessfulPayment {
|
|
990
|
-
currency: string;
|
|
991
|
-
total_amount: number;
|
|
992
|
-
invoice_payload: string;
|
|
993
|
-
shipping_option_id?: string;
|
|
994
|
-
order_info?: OrderInfo;
|
|
995
|
-
telegram_payment_charge_id: string;
|
|
996
|
-
provider_payment_charge_id: string;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
interface ShippingQuery {
|
|
1000
|
-
id: string;
|
|
1001
|
-
from: User;
|
|
1002
|
-
invoice_payload: string;
|
|
1003
|
-
shipping_address: ShippingAddress;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
interface PreCheckoutQuery {
|
|
1007
|
-
id: string;
|
|
1008
|
-
from: User;
|
|
1009
|
-
currency: string;
|
|
1010
|
-
total_amount: number;
|
|
1011
|
-
invoice_payload: string;
|
|
1012
|
-
shipping_option_id?: string;
|
|
1013
|
-
order_info?: OrderInfo;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
interface Game {
|
|
1017
|
-
title: string;
|
|
1018
|
-
description: string;
|
|
1019
|
-
photo: PhotoSize[];
|
|
1020
|
-
text?: string;
|
|
1021
|
-
text_entities?: MessageEntity[];
|
|
1022
|
-
animation?: Animation;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
export interface Animation extends FileBase {
|
|
1026
|
-
width: number;
|
|
1027
|
-
height: number;
|
|
1028
|
-
duration: number;
|
|
1029
|
-
thumb?: PhotoSize;
|
|
1030
|
-
file_name?: string;
|
|
1031
|
-
mime_type?: string;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
type CallbackGame = object;
|
|
1035
|
-
|
|
1036
|
-
interface GameHighScore {
|
|
1037
|
-
position: number;
|
|
1038
|
-
user: User;
|
|
1039
|
-
score: number;
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
interface Metadata {
|
|
1043
|
-
type?: MessageType;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
interface BotCommand {
|
|
1047
|
-
command: string
|
|
1048
|
-
description: string
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* Methods
|
|
1053
|
-
*/
|
|
1054
|
-
|
|
1055
|
-
export function setWebhook(token: string, body: SetWebHookOptions, signal: AbortSignal) {
|
|
1056
|
-
return fetch(`https://api.telegram.org/bot${token}/setWebhook`, {
|
|
1057
|
-
method: "POST",
|
|
1058
|
-
body: JSON.stringify(body),
|
|
1059
|
-
headers,
|
|
1060
|
-
signal
|
|
1061
|
-
}).then(parseResponse<Boolean>)
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
export function deleteWebhook(token: string, signal: AbortSignal) {
|
|
1065
|
-
return fetch(`https://api.telegram.org/bot${token}/deleteWebhook`, {
|
|
1066
|
-
method: "POST",
|
|
1067
|
-
body: JSON.stringify({}),
|
|
1068
|
-
headers,
|
|
1069
|
-
signal
|
|
1070
|
-
}).then(parseResponse<Boolean>)
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
/** @todo cehck if response is the same as in typings */
|
|
1074
|
-
export function getWebhookInfo(token: string, signal: AbortSignal) {
|
|
1075
|
-
return fetch(`https://api.telegram.org/bot${token}/getWebhookInfo`, {
|
|
1076
|
-
method: "POST",
|
|
1077
|
-
body: JSON.stringify({}),
|
|
1078
|
-
headers,
|
|
1079
|
-
signal
|
|
1080
|
-
}).then(parseResponse<WebhookInfo>)
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
export function getMe(token: string, signal: AbortSignal) {
|
|
1084
|
-
return fetch(`https://api.telegram.org/bot${token}/getMe`, {
|
|
1085
|
-
method: "POST",
|
|
1086
|
-
body: JSON.stringify({}),
|
|
1087
|
-
headers,
|
|
1088
|
-
signal
|
|
1089
|
-
}).then(parseResponse<User>)
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
export function sendMessage(token: string, payload: SendMessageOptions, signal: AbortSignal) {
|
|
1093
|
-
return fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
1094
|
-
method: "POST",
|
|
1095
|
-
body: JSON.stringify(payload),
|
|
1096
|
-
headers,
|
|
1097
|
-
signal
|
|
1098
|
-
}).then(parseResponse<Message>)
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
export function editMessageText(token: string, payload: EditMessageTextOptions, signal: AbortSignal) {
|
|
1102
|
-
return fetch(`https://api.telegram.org/bot${token}/editMessageText`, {
|
|
1103
|
-
method: "POST",
|
|
1104
|
-
body: JSON.stringify(payload),
|
|
1105
|
-
headers,
|
|
1106
|
-
signal
|
|
1107
|
-
}).then(parseResponse<Message>)
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
export function sendPhoto(token: string, payload: SendPhotoOptions, signal: AbortSignal) {
|
|
1111
|
-
return fetch(`https://api.telegram.org/bot${token}/sendPhoto`, {
|
|
1112
|
-
method: "POST",
|
|
1113
|
-
body: JSON.stringify(payload),
|
|
1114
|
-
headers,
|
|
1115
|
-
signal
|
|
1116
|
-
}).then(parseResponse<Message>)
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
export function sendAnimation(token: string, payload: SendAnimationOptions, signal: AbortSignal) {
|
|
1120
|
-
return fetch(`https://api.telegram.org/bot${token}/sendAnimation`, {
|
|
1121
|
-
method: "POST",
|
|
1122
|
-
body: JSON.stringify(payload),
|
|
1123
|
-
headers,
|
|
1124
|
-
signal
|
|
1125
|
-
}).then(parseResponse<Message>)
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
export function sendDocument(token: string, payload: SendDocumentOptions, signal: AbortSignal) {
|
|
1129
|
-
return fetch(`https://api.telegram.org/bot${token}/sendDocument`, {
|
|
1130
|
-
method: "POST",
|
|
1131
|
-
body: JSON.stringify(payload),
|
|
1132
|
-
headers,
|
|
1133
|
-
signal
|
|
1134
|
-
}).then(parseResponse<Message>)
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
export function setMessageReaction(token: string, payload: {
|
|
1138
|
-
chat_id: string | number
|
|
1139
|
-
message_id: number
|
|
1140
|
-
reaction?: ReactionType[]
|
|
1141
|
-
is_big?: boolean
|
|
1142
|
-
}, signal: AbortSignal) {
|
|
1143
|
-
return fetch(`https://api.telegram.org/bot${token}/setMessageReaction`, {
|
|
1144
|
-
method: "POST",
|
|
1145
|
-
body: JSON.stringify(payload),
|
|
1146
|
-
headers,
|
|
1147
|
-
signal
|
|
1148
|
-
}).then(parseResponse<Boolean>)
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
export function getUserProfilePhotos(token: string, payload: {
|
|
1152
|
-
user_id: number | string
|
|
1153
|
-
offset?: number;
|
|
1154
|
-
limit?: number;
|
|
1155
|
-
}, signal: AbortSignal) {
|
|
1156
|
-
return fetch(`https://api.telegram.org/bot${token}/getUserProfilePhotos`, {
|
|
1157
|
-
method: "POST",
|
|
1158
|
-
body: JSON.stringify(payload),
|
|
1159
|
-
headers,
|
|
1160
|
-
signal
|
|
1161
|
-
}).then(parseResponse<UserProfilePhotos>)
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
export function getFile(token: string, payload: {
|
|
1165
|
-
file_id: string
|
|
1166
|
-
}, signal: AbortSignal) {
|
|
1167
|
-
return fetch(`https://api.telegram.org/bot${token}/getFile`, {
|
|
1168
|
-
method: "POST",
|
|
1169
|
-
body: JSON.stringify(payload),
|
|
1170
|
-
headers,
|
|
1171
|
-
signal
|
|
1172
|
-
}).then(parseResponse<File>)
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
export function answerCallbackQuery(token: string, payload: AnswerCallbackQueryOptions, signal: AbortSignal) {
|
|
1176
|
-
return fetch(`https://api.telegram.org/bot${token}/answerCallbackQuery`, {
|
|
1177
|
-
method: "POST",
|
|
1178
|
-
body: JSON.stringify(payload),
|
|
1179
|
-
headers,
|
|
1180
|
-
signal
|
|
1181
|
-
}).then(parseResponse<File>)
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
export function getChat(token: string, payload: {
|
|
1185
|
-
chat_id: string
|
|
1186
|
-
}, signal: AbortSignal) {
|
|
1187
|
-
return fetch(`https://api.telegram.org/bot${token}/getChat`, {
|
|
1188
|
-
method: "POST",
|
|
1189
|
-
body: JSON.stringify(payload),
|
|
1190
|
-
headers,
|
|
1191
|
-
signal
|
|
1192
|
-
}).then(parseResponse<Chat>)
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
export function getChatMember(token: string, payload: { chat_id: string, user_id: string }, signal?: AbortSignal) {
|
|
1196
|
-
return fetch(`https://api.telegram.org/bot${token}/getChatMember`, {
|
|
1197
|
-
method: "POST",
|
|
1198
|
-
body: JSON.stringify(payload),
|
|
1199
|
-
headers,
|
|
1200
|
-
signal: signal
|
|
1201
|
-
}).then(parseResponse<ChatMember>)
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
export function setMyCommands(token: string, payload: SetMyCommandsOptions, signal?: AbortSignal) {
|
|
1205
|
-
return fetch(`https://api.telegram.org/bot${token}/setMyCommands`, {
|
|
1206
|
-
method: "POST",
|
|
1207
|
-
body: JSON.stringify(payload),
|
|
1208
|
-
headers,
|
|
1209
|
-
signal
|
|
1210
|
-
}).then(parseResponse<Chat>)
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
export function deleteMyCommands(token: string, payload: DeleteMyCommandsOptions, signal: AbortSignal): Promise<Chat> {
|
|
1214
|
-
return fetch(`https://api.telegram.org/bot${token}/deleteMyCommands`, {
|
|
1215
|
-
method: "POST",
|
|
1216
|
-
body: JSON.stringify(payload),
|
|
1217
|
-
headers,
|
|
1218
|
-
signal
|
|
1219
|
-
}).then(parseResponse<Chat>)
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
/**
|
|
1223
|
-
* Parsers
|
|
1224
|
-
*/
|
|
1225
|
-
|
|
1226
|
-
export function parseUpdate(update: any): Update {
|
|
1227
|
-
const u: Update = {
|
|
1228
|
-
update_id: Number(update.update_id)
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
if (update.message) {
|
|
1232
|
-
u.message = parseMessage(update.message)
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
if (update.edited_message) {
|
|
1236
|
-
u.edited_message = parseMessage(update.edited_message)
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
if (update.callback_query) {
|
|
1240
|
-
u.callback_query = parseCallbackQuery(update.callback_query)
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
if (update.message_reaction) {
|
|
1244
|
-
u.message_reaction = parseMessageReaction(update.message_reaction)
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
if (update.message_reaction_count) {
|
|
1248
|
-
u.message_reaction_count = parseMessageReactionCount(update.message_reaction_count)
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
return u
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
export function parseMessage(m: any): Message {
|
|
1255
|
-
return {
|
|
1256
|
-
message_id: Number(m.message_id),
|
|
1257
|
-
from: m.from ? parseUser(m.from) : void 0,
|
|
1258
|
-
date: Number(m.date),
|
|
1259
|
-
chat: parseChat(m.chat),
|
|
1260
|
-
text: String(m.text ?? ""),
|
|
1261
|
-
forward_from: m.forward_from ? parseUser(m.forward_from) : void 0, // User;
|
|
1262
|
-
forward_from_chat: m.forward_from_chat ? parseChat(m.forward_from_chat) : void 0, // Chat;
|
|
1263
|
-
forward_from_message_id: m.forward_from_message_id ? Number(m.forward_from_message_id) : void 0, // number;
|
|
1264
|
-
forward_signature: m.forward_signature ? String(m.forward_signature) : void 0, // string;
|
|
1265
|
-
forward_sender_name: m.forward_sender_name ? String(m.forward_sender_name) : void 0, // string;
|
|
1266
|
-
forward_date: m.forward_date ? Number(m.forward_date) : void 0, // number;
|
|
1267
|
-
// reply_to_message: m.reply_to_message ? parseMessage(m.reply_to_message) : void 0, // Message;
|
|
1268
|
-
edit_date: m.edit_date ? Number(m.edit_date) : void 0, // number;
|
|
1269
|
-
media_group_id: m.media_group_id ? String(m.media_group_id) : void 0, // string;
|
|
1270
|
-
author_signature: m.author_signature ? String(m.author_signature) : void 0, // string;
|
|
1271
|
-
entities: m.entities ? parseEntities(m.entities) : void 0, // MessageEntity[];
|
|
1272
|
-
// caption_entities: m.caption_entities ? parseSometh(m.caption_entities) : void 0, // MessageEntity[];
|
|
1273
|
-
audio: m.audio ? parseAudio(m.audio) : void 0,
|
|
1274
|
-
document: m.document ? parseDocument(m.document) : void 0,
|
|
1275
|
-
animation: m.animation ? parseAnimation(m.animation) : void 0,
|
|
1276
|
-
// game?: Game;
|
|
1277
|
-
photo: m.photo ? parsePhotoSizes(m.photo) : void 0,
|
|
1278
|
-
sticker: m.sticker ? parseSticker(m.sticker) : void 0,
|
|
1279
|
-
video: m.video ? parseVideo(m.video) : void 0,
|
|
1280
|
-
voice: m.voice ? parseVoice(m.voice) : void 0,
|
|
1281
|
-
video_note: m.video_note ? parseVideoNote(m.video_note) : void 0,
|
|
1282
|
-
caption: m.caption ? String(m.caption) : void 0,
|
|
1283
|
-
contact: m.contact ? parseContact(m.contact) : void 0,
|
|
1284
|
-
location: m.location ? parseLocation(m.location) : void 0,
|
|
1285
|
-
venue: m.venue ? parseVenue(m.venue) : void 0,
|
|
1286
|
-
poll: m.poll ? parsePoll(m.poll) : void 0,
|
|
1287
|
-
// new_chat_members?: User[];
|
|
1288
|
-
// left_chat_member?: User;
|
|
1289
|
-
// new_chat_title?: string;
|
|
1290
|
-
// new_chat_photo?: PhotoSize[];
|
|
1291
|
-
// delete_chat_photo?: boolean;
|
|
1292
|
-
// group_chat_created?: boolean;
|
|
1293
|
-
// supergroup_chat_created?: boolean;
|
|
1294
|
-
// channel_chat_created?: boolean;
|
|
1295
|
-
// migrate_to_chat_id?: number;
|
|
1296
|
-
// migrate_from_chat_id?: number;
|
|
1297
|
-
// pinned_message?: Message;
|
|
1298
|
-
// invoice?: Invoice;
|
|
1299
|
-
// successful_payment?: SuccessfulPayment;
|
|
1300
|
-
// connected_website?: string;
|
|
1301
|
-
// passport_data?: PassportData;
|
|
1302
|
-
// reply_markup?: InlineKeyboardMarkup;
|
|
1303
|
-
sender_chat: m.sender_chat ? parseChat(m.sender_chat) : void 0,
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
export function parseUser(u: User) {
|
|
1308
|
-
return {
|
|
1309
|
-
id: String(u.id),
|
|
1310
|
-
is_bot: Boolean(u.is_bot),
|
|
1311
|
-
first_name: String(u.first_name),
|
|
1312
|
-
last_name: String(u.last_name ?? ""),
|
|
1313
|
-
username: String(u.username ?? ""),
|
|
1314
|
-
language_code: String(u.language_code ?? ""),
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
export function parseChat(c: Chat) {
|
|
1319
|
-
return {
|
|
1320
|
-
id: Number(c.id),
|
|
1321
|
-
type: c.type,
|
|
1322
|
-
title: String(c.title ?? ""),
|
|
1323
|
-
username: String(c.username ?? ""),
|
|
1324
|
-
first_name: String(c.first_name ?? ""),
|
|
1325
|
-
last_name: String(c.last_name ?? ""),
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
export function parsePhotoSizes(p: PhotoSize[]) {
|
|
1330
|
-
if (!Array.isArray(p)) {
|
|
1331
|
-
return void 0
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
return p.map(parsePhotoSize)
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
export function parsePhotoSize(p: PhotoSize) {
|
|
1338
|
-
return {
|
|
1339
|
-
file_id: String(p.file_id),
|
|
1340
|
-
file_size: Number(p.file_size),
|
|
1341
|
-
width: Number(p.width),
|
|
1342
|
-
height: Number(p.height),
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
export function parseSticker(v: Sticker): Sticker {
|
|
1347
|
-
return {
|
|
1348
|
-
file_id: String(v.file_id),
|
|
1349
|
-
width: Number(v.width),
|
|
1350
|
-
height: Number(v.height),
|
|
1351
|
-
thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
|
|
1352
|
-
emoji: String(v.emoji),
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
export function parseVideo(v: Video): Video {
|
|
1357
|
-
return {
|
|
1358
|
-
file_id: String(v.file_id),
|
|
1359
|
-
width: Number(v.width),
|
|
1360
|
-
height: Number(v.height),
|
|
1361
|
-
duration: Number(v.duration),
|
|
1362
|
-
thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
|
|
1363
|
-
mime_type: String(v.mime_type ?? ""),
|
|
1364
|
-
file_name: String(v.file_name ?? ""),
|
|
1365
|
-
file_size: Number(v.file_size ?? ""),
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
export function parseVoice(v: Voice): Voice {
|
|
1370
|
-
return {
|
|
1371
|
-
file_id: String(v.file_id),
|
|
1372
|
-
file_size: Number(v.file_size),
|
|
1373
|
-
duration: Number(v.duration),
|
|
1374
|
-
mime_type: String(v.mime_type)
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
export function parseVideoNote(v: VideoNote): VideoNote {
|
|
1379
|
-
return {
|
|
1380
|
-
file_id: String(v.file_id),
|
|
1381
|
-
length: Number(v.length),
|
|
1382
|
-
duration: Number(v.duration),
|
|
1383
|
-
thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
export function parseEntities(v: MessageEntity[]): MessageEntity[] {
|
|
1388
|
-
if (!Array.isArray(v)) {
|
|
1389
|
-
return []
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
return v.map(function (entity) {
|
|
1393
|
-
return {
|
|
1394
|
-
type: entity.type,
|
|
1395
|
-
offset: entity.offset,
|
|
1396
|
-
length: entity.length,
|
|
1397
|
-
url: String(entity.url ?? ""),
|
|
1398
|
-
user: entity.user ? parseUser(entity.user) : void 0,
|
|
1399
|
-
}
|
|
1400
|
-
})
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
export function parseAudio(v: Audio): Audio {
|
|
1404
|
-
return {
|
|
1405
|
-
file_id: String(v.file_id),
|
|
1406
|
-
duration: Number(v.duration),
|
|
1407
|
-
title: String(v.title ?? ""),
|
|
1408
|
-
performer: String(v.performer ?? ""),
|
|
1409
|
-
file_name: String(v.file_name ?? ""),
|
|
1410
|
-
mime_type: String(v.mime_type ?? ""),
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
export function parseDocument(v: Document): Document {
|
|
1415
|
-
return {
|
|
1416
|
-
file_id: String(v.file_id),
|
|
1417
|
-
file_name: String(v.file_name || ""),
|
|
1418
|
-
mime_type: String(v.mime_type || ""),
|
|
1419
|
-
file_size: Number(v.file_size || 0),
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
export function parseAnimation(v: Animation) {
|
|
1424
|
-
return {
|
|
1425
|
-
file_id: String(v.file_id),
|
|
1426
|
-
width: Number(v.width),
|
|
1427
|
-
height: Number(v.height),
|
|
1428
|
-
duration: Number(v.duration),
|
|
1429
|
-
file_name: String(v.file_name),
|
|
1430
|
-
mime_type: String(v.mime_type || ""),
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
export function parseContact(v: Contact) {
|
|
1435
|
-
return {
|
|
1436
|
-
phone_number: String(v.phone_number),
|
|
1437
|
-
first_name: String(v.first_name),
|
|
1438
|
-
last_name: String(v.last_name ?? ""),
|
|
1439
|
-
user_id: Number(v.user_id ?? ""),
|
|
1440
|
-
vcard: String(v.vcard ?? ""),
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
export function parseLocation(v: Location) {
|
|
1445
|
-
return {
|
|
1446
|
-
longitude: Number(v.longitude),
|
|
1447
|
-
latitude: Number(v.latitude),
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
export function parseVenue(v: Venue) {
|
|
1452
|
-
return {
|
|
1453
|
-
location: parseLocation(v.location),
|
|
1454
|
-
title: String(v.title),
|
|
1455
|
-
address: String(v.address),
|
|
1456
|
-
foursquare_id: String(v.foursquare_id ?? ""),
|
|
1457
|
-
foursquare_type: String(v.foursquare_type ?? ""),
|
|
1458
|
-
google_place_id: String(v.google_place_id ?? ""),
|
|
1459
|
-
google_place_type: String(v.google_place_type ?? ""),
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
export function parsePoll(v: Poll) {
|
|
1464
|
-
return {
|
|
1465
|
-
id: String(v.id),
|
|
1466
|
-
question: String(v.question),
|
|
1467
|
-
options: parsePollOptions(v.options),
|
|
1468
|
-
is_closed: Boolean(v.is_closed),
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
export function parsePollOptions(v: PollOption[]) {
|
|
1473
|
-
return Array.isArray(v) ? v.map(parsePollOption) : []
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
export function parsePollOption(v: PollOption) {
|
|
1477
|
-
return {
|
|
1478
|
-
text: String(v.text),
|
|
1479
|
-
voter_count: Number(v.voter_count),
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
/**
|
|
1484
|
-
* @see https://core.telegram.org/bots/api#callbackquery
|
|
1485
|
-
*/
|
|
1486
|
-
export function parseCallbackQuery(v?: CallbackQuery): CallbackQuery | undefined {
|
|
1487
|
-
if (!v) {
|
|
1488
|
-
return
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
return {
|
|
1492
|
-
id: String(v.id),
|
|
1493
|
-
from: parseUser(v.from),
|
|
1494
|
-
data: String(v.data ?? ""),
|
|
1495
|
-
message: parseMessage(v.message),
|
|
1496
|
-
chat_instance: String(v.chat_instance ?? ""),
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
function parseMessageReaction(d?: MessageReactionUpdated): MessageReactionUpdated | undefined {
|
|
1501
|
-
if (!d) {
|
|
1502
|
-
return
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
return {
|
|
1506
|
-
chat: parseChat(d.chat),
|
|
1507
|
-
message_id: Number(d.message_id),
|
|
1508
|
-
user: d.user ? parseUser(d.user) : void 0,
|
|
1509
|
-
actor_chat: d.actor_chat ? parseChat(d.actor_chat) : void 0,
|
|
1510
|
-
date: Number(d.date),
|
|
1511
|
-
old_reaction: parseReactions(d.old_reaction),
|
|
1512
|
-
new_reaction: parseReactions(d.new_reaction),
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
function parseReactions(reactions: ReactionType[]): ReactionType[] {
|
|
1517
|
-
if (!Array.isArray(reactions)) {
|
|
1518
|
-
return []
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
return reactions.map(parseReaction)
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
function parseReaction(reaction: ReactionType): ReactionType {
|
|
1525
|
-
if (reaction.type === "emoji") {
|
|
1526
|
-
return {
|
|
1527
|
-
type: "emoji",
|
|
1528
|
-
emoji: String(reaction.emoji),
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
if (reaction.type === "custom_emoji") {
|
|
1533
|
-
return {
|
|
1534
|
-
type: "custom_emoji",
|
|
1535
|
-
custom_emoji_id: String(reaction.custom_emoji_id),
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
throw new RangeError(`Unknown type of reaction: ${JSON.stringify(reaction)}`)
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
function parseMessageReactionCount(d?: MessageReactionCountUpdated): MessageReactionCountUpdated | undefined {
|
|
1543
|
-
if (!d) {
|
|
1544
|
-
return d
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
return {
|
|
1548
|
-
chat: parseChat(d.chat),
|
|
1549
|
-
message_id: Number(d.message_id),
|
|
1550
|
-
date: Number(d.date),
|
|
1551
|
-
reactions: parseReactionsCount(d.reactions)
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
function parseReactionsCount(reactions?: ReactionCount[]): ReactionCount[] {
|
|
1556
|
-
if (!Array.isArray(reactions)) {
|
|
1557
|
-
return []
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
return reactions.map(parseReactionCount)
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
function parseReactionCount(reaction: ReactionCount): ReactionCount {
|
|
1564
|
-
return {
|
|
1565
|
-
type: parseReaction(reaction.type),
|
|
1566
|
-
total_count: Number(reaction.total_count),
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
export function parseResponse<T>(response: Response) {
|
|
1571
|
-
return response.text().then(function (text) {
|
|
1572
|
-
let data: any
|
|
1573
|
-
|
|
1574
|
-
try {
|
|
1575
|
-
data = JSON.parse(text)
|
|
1576
|
-
}
|
|
1577
|
-
catch (err) {
|
|
1578
|
-
throw new TelegramError(`Invalid response: ${text}`, response.status)
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
const ok = Boolean(data.ok)
|
|
1582
|
-
|
|
1583
|
-
if (ok) {
|
|
1584
|
-
return data.result as T
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
const error_code = Number(data.error_code ?? 0)
|
|
1588
|
-
const description = String(data.description ?? "")
|
|
1589
|
-
const parameters = data.parameters || {}
|
|
1590
|
-
|
|
1591
|
-
throw new TelegramError(description, error_code, parameters)
|
|
1592
|
-
})
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
export class TelegramError extends Error {
|
|
1596
|
-
error_code: number
|
|
1597
|
-
parameters: Record<string, any>
|
|
1598
|
-
|
|
1599
|
-
constructor(message: string, error_code: number, parameters: Record<string, any> = {}) {
|
|
1600
|
-
super(message)
|
|
1601
|
-
|
|
1602
|
-
this.error_code = error_code
|
|
1603
|
-
this.parameters = parameters
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
/**
|
|
1608
|
-
* Helpers
|
|
1609
|
-
*/
|
|
1610
|
-
export const SUPPORTED_REACTION_EMOJI = ["๐", "๐", "\u2764\ufe0f" // red heart
|
|
1611
|
-
, "๐ฅ", "๐ฅฐ", "๐", "๐", "๐ค", "๐คฏ", "๐ฑ", "๐คฌ", "๐ข"
|
|
1612
|
-
, "๐", "๐คฉ", "๐คฎ", "๐ฉ", "๐", "๐", "๐", "๐คก", "๐ฅฑ", "๐ฅด", "๐", "๐ณ", "โคโ๐ฅ"
|
|
1613
|
-
, "๐", "๐ญ", "๐ฏ", "๐คฃ", "โก", "๐", "๐", "๐", "๐คจ", "๐", "๐", "๐พ", "๐"
|
|
1614
|
-
, "๐", "๐", "๐ด", "๐ญ", "๐ค", "๐ป", "๐จโ๐ป", "๐", "๐", "๐", "๐", "๐จ", "๐ค"
|
|
1615
|
-
, "โ", "๐ค", "๐ซก", "๐
", "๐", "โ", "๐
", "๐คช", "๐ฟ", "๐", "๐", "๐", "๐ฆ"
|
|
1616
|
-
, "๐", "๐", "๐", "๐", "๐พ", "๐คทโโ", "๐คท", "๐คทโโ", "๐ก"
|
|
1617
|
-
]
|