telegram-bot-api-nodejs 1.0.0

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 ADDED
@@ -0,0 +1,581 @@
1
+ export type ChatType = "private" | "group" | "supergroup" | "channel";
2
+ export type ChatAction = "typing" | "upload_photo" | "record_video" | "upload_video" | "record_audio" | "upload_audio" | "upload_document" | "find_location" | "record_video_note" | "upload_video_note";
3
+ export type ChatMemberStatus = "creator" | "administrator" | "member" | "restricted" | "left" | "kicked";
4
+ export type DocumentMimeType = "application/pdf" | "application/zip";
5
+ export type MessageType = "text" | "animation" | "audio" | "channel_chat_created" | "contact" | "delete_chat_photo" | "document" | "game" | "group_chat_created" | "invoice" | "left_chat_member" | "location" | "migrate_from_chat_id" | "migrate_to_chat_id" | "new_chat_members" | "new_chat_photo" | "new_chat_title" | "passport_data" | "photo" | "pinned_message" | "sticker" | "successful_payment" | "supergroup_chat_created" | "video" | "video_note" | "voice";
6
+ type MessageEntityType = "mention" | "hashtag" | "bot_command" | "url" | "email" | "bold" | "italic" | "code" | "pre" | "text_link" | "text_mention";
7
+ type ParseMode = "Markdown" | "MarkdownV2" | "HTML";
8
+ export interface SetWebHookOptions {
9
+ url?: string;
10
+ max_connections?: number;
11
+ allowed_updates?: string[];
12
+ }
13
+ interface SendBasicOptions {
14
+ chat_id: number | string;
15
+ disable_notification?: boolean;
16
+ reply_to_message_id?: number | string;
17
+ reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
18
+ }
19
+ export interface SendMessageOptions extends SendBasicOptions {
20
+ text: string;
21
+ parse_mode?: ParseMode;
22
+ disable_web_page_preview?: boolean;
23
+ entities?: MessageEntity[];
24
+ }
25
+ export interface SendPhotoOptions extends SendBasicOptions {
26
+ photo: string;
27
+ parse_mode?: ParseMode;
28
+ caption?: string;
29
+ }
30
+ export interface SendAnimationOptions extends SendBasicOptions {
31
+ animation: string;
32
+ parse_mode?: ParseMode;
33
+ caption?: string;
34
+ }
35
+ interface SendDocumentOptions extends SendBasicOptions {
36
+ document: string;
37
+ parse_mode?: ParseMode;
38
+ caption?: string;
39
+ }
40
+ interface SendDocumentStreamOptions extends SendBasicOptions {
41
+ document: Blob;
42
+ documentName: string;
43
+ parse_mode?: ParseMode;
44
+ caption?: string;
45
+ }
46
+ export interface AnswerCallbackQueryOptions {
47
+ callback_query_id: string;
48
+ text?: string;
49
+ show_alert?: boolean;
50
+ url?: string;
51
+ cache_time?: number;
52
+ }
53
+ export interface GetChatOptions {
54
+ chat_id: string;
55
+ }
56
+ interface SetMyCommandsOptions {
57
+ commands: BotCommand[];
58
+ }
59
+ interface DeleteMyCommandsOptions {
60
+ }
61
+ interface EditMessageTextOptions extends EditMessageReplyMarkupOptions {
62
+ parse_mode?: ParseMode;
63
+ disable_web_page_preview?: boolean;
64
+ text: string;
65
+ }
66
+ interface EditMessageReplyMarkupOptions {
67
+ chat_id?: number | string;
68
+ message_id?: number | string;
69
+ inline_message_id?: string;
70
+ }
71
+ export interface GetUserProfilePhotosOptions {
72
+ user_id: number | string;
73
+ offset?: number;
74
+ limit?: number;
75
+ }
76
+ interface PassportFile {
77
+ file_id: string;
78
+ file_size: number;
79
+ file_date: number;
80
+ }
81
+ interface EncryptedPassportElement {
82
+ type: string;
83
+ data?: string;
84
+ phone_number?: string;
85
+ email?: string;
86
+ files?: PassportFile[];
87
+ front_side?: PassportFile;
88
+ reverse_side?: PassportFile;
89
+ selfie?: PassportFile;
90
+ translation?: PassportFile[];
91
+ hash: string;
92
+ }
93
+ interface EncryptedCredentials {
94
+ data: string;
95
+ hash: string;
96
+ secret: string;
97
+ }
98
+ interface PassportData {
99
+ data: EncryptedPassportElement[];
100
+ credentials: EncryptedCredentials;
101
+ }
102
+ export interface Update {
103
+ update_id: number;
104
+ message?: Message;
105
+ edited_message?: Message;
106
+ channel_post?: Message;
107
+ edited_channel_post?: Message;
108
+ inline_query?: InlineQuery;
109
+ chosen_inline_result?: ChosenInlineResult;
110
+ callback_query?: CallbackQuery;
111
+ shipping_query?: ShippingQuery;
112
+ pre_checkout_query?: PreCheckoutQuery;
113
+ }
114
+ export interface WebhookInfo {
115
+ url: string;
116
+ has_custom_certificate: boolean;
117
+ pending_update_count: number;
118
+ last_error_date?: number;
119
+ last_error_message?: string;
120
+ max_connections?: number;
121
+ allowed_updates?: string[];
122
+ }
123
+ export interface User {
124
+ id: string;
125
+ is_bot: boolean;
126
+ first_name: string;
127
+ last_name?: string;
128
+ username?: string;
129
+ language_code?: string;
130
+ can_join_groups?: boolean;
131
+ supports_inline_queries?: boolean;
132
+ can_read_all_group_messages?: boolean;
133
+ }
134
+ export interface Chat {
135
+ id: number;
136
+ type: ChatType;
137
+ title?: string;
138
+ username?: string;
139
+ first_name?: string;
140
+ last_name?: string;
141
+ photo?: ChatPhoto;
142
+ description?: string;
143
+ invite_link?: string;
144
+ pinned_message?: Message;
145
+ permissions?: ChatPermissions;
146
+ can_set_sticker_set?: boolean;
147
+ sticker_set_name?: string;
148
+ }
149
+ export interface Message {
150
+ message_id: number;
151
+ from?: User;
152
+ date: number;
153
+ chat: Chat;
154
+ forward_from?: User;
155
+ forward_from_chat?: Chat;
156
+ forward_from_message_id?: number;
157
+ forward_signature?: string;
158
+ forward_sender_name?: string;
159
+ forward_date?: number;
160
+ reply_to_message?: Message;
161
+ edit_date?: number;
162
+ media_group_id?: string;
163
+ author_signature?: string;
164
+ text?: string;
165
+ entities?: MessageEntity[];
166
+ caption_entities?: MessageEntity[];
167
+ audio?: Audio;
168
+ document?: Document;
169
+ animation?: Animation;
170
+ game?: Game;
171
+ photo?: PhotoSize[];
172
+ sticker?: Sticker;
173
+ video?: Video;
174
+ voice?: Voice;
175
+ video_note?: VideoNote;
176
+ caption?: string;
177
+ contact?: Contact;
178
+ location?: Location;
179
+ venue?: Venue;
180
+ poll?: Poll;
181
+ new_chat_members?: User[];
182
+ left_chat_member?: User;
183
+ new_chat_title?: string;
184
+ new_chat_photo?: PhotoSize[];
185
+ delete_chat_photo?: boolean;
186
+ group_chat_created?: boolean;
187
+ supergroup_chat_created?: boolean;
188
+ channel_chat_created?: boolean;
189
+ migrate_to_chat_id?: number;
190
+ migrate_from_chat_id?: number;
191
+ pinned_message?: Message;
192
+ invoice?: Invoice;
193
+ successful_payment?: SuccessfulPayment;
194
+ connected_website?: string;
195
+ passport_data?: PassportData;
196
+ reply_markup?: InlineKeyboardMarkup;
197
+ sender_chat?: Chat;
198
+ }
199
+ export interface MessageEntity {
200
+ type: MessageEntityType;
201
+ offset: number;
202
+ length: number;
203
+ url?: string;
204
+ user?: User;
205
+ }
206
+ interface FileBase {
207
+ file_id: string;
208
+ file_size?: number;
209
+ }
210
+ export interface PhotoSize extends FileBase {
211
+ width: number;
212
+ height: number;
213
+ }
214
+ export interface Audio extends FileBase {
215
+ duration: number;
216
+ performer?: string;
217
+ title?: string;
218
+ file_name?: string;
219
+ mime_type?: string;
220
+ thumb?: PhotoSize;
221
+ }
222
+ export interface Document extends FileBase {
223
+ thumb?: PhotoSize;
224
+ file_name?: string;
225
+ mime_type?: string;
226
+ file_size?: number;
227
+ }
228
+ export interface Video extends FileBase {
229
+ width: number;
230
+ height: number;
231
+ duration: number;
232
+ thumb?: PhotoSize;
233
+ mime_type?: string;
234
+ file_name?: string;
235
+ }
236
+ export interface Voice extends FileBase {
237
+ duration: number;
238
+ mime_type?: string;
239
+ }
240
+ export interface VideoNote extends FileBase {
241
+ length: number;
242
+ duration: number;
243
+ thumb?: PhotoSize;
244
+ }
245
+ export interface Contact {
246
+ phone_number: string;
247
+ first_name: string;
248
+ last_name?: string;
249
+ user_id?: number;
250
+ vcard?: string;
251
+ }
252
+ export interface Location {
253
+ longitude: number;
254
+ latitude: number;
255
+ }
256
+ export interface Venue {
257
+ location: Location;
258
+ title: string;
259
+ address: string;
260
+ foursquare_id?: string;
261
+ foursquare_type?: string;
262
+ google_place_id?: string;
263
+ google_place_type?: string;
264
+ }
265
+ export interface PollOption {
266
+ text: string;
267
+ voter_count: number;
268
+ }
269
+ export interface Poll {
270
+ id: string;
271
+ question: string;
272
+ options: PollOption[];
273
+ is_closed: boolean;
274
+ }
275
+ export interface UserProfilePhotos {
276
+ total_count: number;
277
+ photos: PhotoSize[][];
278
+ }
279
+ export interface File extends FileBase {
280
+ file_path?: string;
281
+ }
282
+ interface ReplyKeyboardMarkup {
283
+ keyboard: KeyboardButton[][];
284
+ resize_keyboard?: boolean;
285
+ one_time_keyboard?: boolean;
286
+ selective?: boolean;
287
+ }
288
+ interface KeyboardButton {
289
+ text: string;
290
+ request_contact?: boolean;
291
+ request_location?: boolean;
292
+ }
293
+ interface ReplyKeyboardRemove {
294
+ remove_keyboard: boolean;
295
+ selective?: boolean;
296
+ }
297
+ export interface InlineKeyboardMarkup {
298
+ inline_keyboard: InlineKeyboardButton[][];
299
+ }
300
+ export interface InlineKeyboardButton {
301
+ text: string;
302
+ url?: string;
303
+ login_url?: LoginUrl;
304
+ callback_data?: string;
305
+ switch_inline_query?: string;
306
+ switch_inline_query_current_chat?: string;
307
+ callback_game?: CallbackGame;
308
+ pay?: boolean;
309
+ }
310
+ interface LoginUrl {
311
+ url: string;
312
+ forward_text?: string;
313
+ bot_username?: string;
314
+ request_write_acces?: boolean;
315
+ }
316
+ export interface CallbackQuery {
317
+ id: string;
318
+ from: User;
319
+ message?: Message;
320
+ inline_message_id?: string;
321
+ chat_instance: string;
322
+ data?: string;
323
+ game_short_name?: string;
324
+ }
325
+ interface ForceReply {
326
+ force_reply: boolean;
327
+ selective?: boolean;
328
+ }
329
+ interface ChatPhoto {
330
+ small_file_id: string;
331
+ small_file_unique_id: string;
332
+ big_file_id: string;
333
+ big_file_unique_id: string;
334
+ }
335
+ interface ChatMember {
336
+ user: User;
337
+ status: ChatMemberStatus;
338
+ until_date?: number;
339
+ can_be_edited?: boolean;
340
+ can_post_messages?: boolean;
341
+ can_edit_messages?: boolean;
342
+ can_delete_messages?: boolean;
343
+ can_restrict_members?: boolean;
344
+ can_promote_members?: boolean;
345
+ can_change_info?: boolean;
346
+ can_invite_users?: boolean;
347
+ can_pin_messages?: boolean;
348
+ is_member?: boolean;
349
+ can_send_messages?: boolean;
350
+ can_send_media_messages?: boolean;
351
+ can_send_polls: boolean;
352
+ can_send_other_messages?: boolean;
353
+ can_add_web_page_previews?: boolean;
354
+ }
355
+ interface ChatPermissions {
356
+ can_send_messages?: boolean;
357
+ can_send_media_messages?: boolean;
358
+ can_send_polls?: boolean;
359
+ can_send_other_messages?: boolean;
360
+ can_add_web_page_previews?: boolean;
361
+ can_change_info?: boolean;
362
+ can_invite_users?: boolean;
363
+ can_pin_messages?: boolean;
364
+ }
365
+ export interface Sticker {
366
+ file_id: string;
367
+ width: number;
368
+ height: number;
369
+ thumb?: PhotoSize;
370
+ emoji?: string;
371
+ set_name?: string;
372
+ mask_position?: MaskPosition;
373
+ file_size?: number;
374
+ }
375
+ interface MaskPosition {
376
+ point: string;
377
+ x_shift: number;
378
+ y_shift: number;
379
+ scale: number;
380
+ }
381
+ interface InlineQuery {
382
+ id: string;
383
+ from: User;
384
+ location?: Location;
385
+ query: string;
386
+ offset: string;
387
+ }
388
+ interface ChosenInlineResult {
389
+ result_id: string;
390
+ from: User;
391
+ location?: Location;
392
+ inline_message_id?: string;
393
+ query: string;
394
+ }
395
+ interface Invoice {
396
+ title: string;
397
+ description: string;
398
+ start_parameter: string;
399
+ currency: string;
400
+ total_amount: number;
401
+ }
402
+ interface ShippingAddress {
403
+ country_code: string;
404
+ state: string;
405
+ city: string;
406
+ street_line1: string;
407
+ street_line2: string;
408
+ post_code: string;
409
+ }
410
+ interface OrderInfo {
411
+ name?: string;
412
+ phone_number?: string;
413
+ email?: string;
414
+ shipping_address?: ShippingAddress;
415
+ }
416
+ interface SuccessfulPayment {
417
+ currency: string;
418
+ total_amount: number;
419
+ invoice_payload: string;
420
+ shipping_option_id?: string;
421
+ order_info?: OrderInfo;
422
+ telegram_payment_charge_id: string;
423
+ provider_payment_charge_id: string;
424
+ }
425
+ interface ShippingQuery {
426
+ id: string;
427
+ from: User;
428
+ invoice_payload: string;
429
+ shipping_address: ShippingAddress;
430
+ }
431
+ interface PreCheckoutQuery {
432
+ id: string;
433
+ from: User;
434
+ currency: string;
435
+ total_amount: number;
436
+ invoice_payload: string;
437
+ shipping_option_id?: string;
438
+ order_info?: OrderInfo;
439
+ }
440
+ interface Game {
441
+ title: string;
442
+ description: string;
443
+ photo: PhotoSize[];
444
+ text?: string;
445
+ text_entities?: MessageEntity[];
446
+ animation?: Animation;
447
+ }
448
+ export interface Animation extends FileBase {
449
+ width: number;
450
+ height: number;
451
+ duration: number;
452
+ thumb?: PhotoSize;
453
+ file_name?: string;
454
+ mime_type?: string;
455
+ }
456
+ type CallbackGame = object;
457
+ interface BotCommand {
458
+ command: string;
459
+ description: string;
460
+ }
461
+ /**
462
+ * Methods
463
+ */
464
+ export declare function setWebhook(token: string, body: SetWebHookOptions, signal: any): Promise<any>;
465
+ export declare function deleteWebhook(token: string, signal: any): Promise<any>;
466
+ /** @todo cehck if response is the same as in typings */
467
+ export declare function getWebhookInfo(token: string, signal: any): Promise<WebhookInfo>;
468
+ export declare function getMe(token: string, signal: any): Promise<User>;
469
+ export declare function sendMessage(token: string, payload: SendMessageOptions, signal: any): Promise<Message>;
470
+ export declare function editMessageText(token: string, payload: EditMessageTextOptions, signal: any): Promise<Message>;
471
+ export declare function sendPhoto(token: string, payload: SendPhotoOptions, signal: any): Promise<Message>;
472
+ export declare function sendAnimation(token: string, payload: SendAnimationOptions, signal: any): Promise<Message>;
473
+ export declare function sendDocument(token: string, payload: SendDocumentOptions, signal: any): Promise<Message>;
474
+ export declare function sendDocumentStream(token: string, payload: SendDocumentStreamOptions, signal: any): Promise<Message>;
475
+ export declare function getUserProfilePhotos(token: string, payload: GetUserProfilePhotosOptions, signal: any): Promise<UserProfilePhotos>;
476
+ export declare function getFile(token: string, file_id: string, signal: any): Promise<File>;
477
+ export declare function answerCallbackQuery(token: string, payload: AnswerCallbackQueryOptions, signal: any): Promise<File>;
478
+ export declare function getChat(token: string, payload: GetChatOptions, signal: any): Promise<Chat>;
479
+ export declare function getChatMember(token: string, payload: {
480
+ chat_id: string;
481
+ user_id: string;
482
+ }, signal: AbortSignal): Promise<ChatMember>;
483
+ export declare function setMyCommands(token: string, payload: SetMyCommandsOptions, signal: any): Promise<Chat>;
484
+ export declare function deleteMyCommands(token: string, payload: DeleteMyCommandsOptions, signal: any): Promise<Chat>;
485
+ /**
486
+ * Parsers
487
+ */
488
+ export declare function parseUpdate(update: any): Update;
489
+ export declare function parseMessage(m?: any): Message | undefined;
490
+ export declare function parseUser(u: User): {
491
+ id: string;
492
+ is_bot: boolean;
493
+ first_name: string;
494
+ last_name: string;
495
+ username: string;
496
+ language_code: string;
497
+ };
498
+ export declare function parseChat(c: Chat): {
499
+ id: number;
500
+ type: ChatType;
501
+ title: string;
502
+ username: string;
503
+ first_name: string;
504
+ last_name: string;
505
+ };
506
+ export declare function parsePhotoSizes(p: PhotoSize[]): {
507
+ file_id: string;
508
+ file_size: number;
509
+ width: number;
510
+ height: number;
511
+ }[] | undefined;
512
+ export declare function parsePhotoSize(p: PhotoSize): {
513
+ file_id: string;
514
+ file_size: number;
515
+ width: number;
516
+ height: number;
517
+ };
518
+ export declare function parseSticker(v: Sticker): Sticker;
519
+ export declare function parseVideo(v: Video): Video;
520
+ export declare function parseVoice(v: Voice): Voice;
521
+ export declare function parseVideoNote(v: VideoNote): VideoNote;
522
+ export declare function parseEntities(v: MessageEntity[]): MessageEntity[];
523
+ export declare function parseAudio(v: Audio): Audio;
524
+ export declare function parseDocument(v: Document): Document;
525
+ export declare function parseAnimation(v: Animation): {
526
+ file_id: string;
527
+ width: number;
528
+ height: number;
529
+ duration: number;
530
+ file_name: string;
531
+ mime_type: string;
532
+ };
533
+ export declare function parseContact(v: Contact): {
534
+ phone_number: string;
535
+ first_name: string;
536
+ last_name: string;
537
+ user_id: number;
538
+ vcard: string;
539
+ };
540
+ export declare function parseLocation(v: Location): {
541
+ longitude: number;
542
+ latitude: number;
543
+ };
544
+ export declare function parseVenue(v: Venue): {
545
+ location: {
546
+ longitude: number;
547
+ latitude: number;
548
+ };
549
+ title: string;
550
+ address: string;
551
+ foursquare_id: string;
552
+ foursquare_type: string;
553
+ google_place_id: string;
554
+ google_place_type: string;
555
+ };
556
+ export declare function parsePoll(v: Poll): {
557
+ id: string;
558
+ question: string;
559
+ options: {
560
+ text: string;
561
+ voter_count: number;
562
+ }[];
563
+ is_closed: boolean;
564
+ };
565
+ export declare function parsePollOptions(v: PollOption[]): {
566
+ text: string;
567
+ voter_count: number;
568
+ }[];
569
+ export declare function parsePollOption(v: PollOption): {
570
+ text: string;
571
+ voter_count: number;
572
+ };
573
+ /**
574
+ * @see https://core.telegram.org/bots/api#callbackquery
575
+ */
576
+ export declare function parseCallbackQuery(v?: CallbackQuery): CallbackQuery | undefined;
577
+ export declare class TelegramError extends Error {
578
+ status: number;
579
+ constructor(message: string, status: number);
580
+ }
581
+ export {};