teh-bot 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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +560 -0
  3. package/index.d.ts +566 -0
  4. package/index.js +962 -0
  5. package/package.json +36 -0
package/index.d.ts ADDED
@@ -0,0 +1,566 @@
1
+ import { EventEmitter } from "events"
2
+ import type { ReadableStream } from "stream"
3
+
4
+ export interface BotOptions {
5
+ polling?: boolean
6
+ pollingInterval?: number
7
+ pollingTimeout?: number
8
+ webhook?: boolean
9
+ webhookPort?: number
10
+ webhookPath?: string
11
+ requestTimeout?: number
12
+ maxConnections?: number
13
+ allowedUpdates?: string[]
14
+ baseApiUrl?: string
15
+ }
16
+
17
+ export interface User {
18
+ id: number
19
+ is_bot: boolean
20
+ first_name: string
21
+ last_name?: string
22
+ username?: string
23
+ language_code?: string
24
+ }
25
+
26
+ export interface Chat {
27
+ id: number
28
+ type: "private" | "group" | "supergroup" | "channel"
29
+ title?: string
30
+ username?: string
31
+ first_name?: string
32
+ last_name?: string
33
+ }
34
+
35
+ export interface Message {
36
+ message_id: number
37
+ from?: User
38
+ sender_chat?: Chat
39
+ date: number
40
+ chat: Chat
41
+ forward_from?: User
42
+ forward_from_chat?: Chat
43
+ forward_from_message_id?: number
44
+ forward_signature?: string
45
+ forward_sender_name?: string
46
+ forward_date?: number
47
+ reply_to_message?: Message
48
+ via_bot?: User
49
+ edit_date?: number
50
+ text?: string
51
+ entities?: MessageEntity[]
52
+ caption?: string
53
+ caption_entities?: MessageEntity[]
54
+ photo?: PhotoSize[]
55
+ audio?: Audio
56
+ document?: Document
57
+ animation?: Animation
58
+ video?: Video
59
+ voice?: Voice
60
+ video_note?: VideoNote
61
+ sticker?: Sticker
62
+ location?: Location
63
+ venue?: Venue
64
+ contact?: Contact
65
+ poll?: Poll
66
+ dice?: Dice
67
+ new_chat_members?: User[]
68
+ left_chat_member?: User
69
+ new_chat_title?: string
70
+ new_chat_photo?: PhotoSize[]
71
+ delete_chat_photo?: boolean
72
+ group_chat_created?: boolean
73
+ supergroup_chat_created?: boolean
74
+ channel_chat_created?: boolean
75
+ migrate_to_chat_id?: number
76
+ migrate_from_chat_id?: number
77
+ pinned_message?: Message
78
+ }
79
+
80
+ export interface MessageEntity {
81
+ type: string
82
+ offset: number
83
+ length: number
84
+ url?: string
85
+ user?: User
86
+ language?: string
87
+ }
88
+
89
+ export interface PhotoSize {
90
+ file_id: string
91
+ file_unique_id: string
92
+ width: number
93
+ height: number
94
+ file_size?: number
95
+ }
96
+
97
+ export interface Audio {
98
+ file_id: string
99
+ file_unique_id: string
100
+ duration: number
101
+ performer?: string
102
+ title?: string
103
+ mime_type?: string
104
+ file_size?: number
105
+ thumb?: PhotoSize
106
+ }
107
+
108
+ export interface Document {
109
+ file_id: string
110
+ file_unique_id: string
111
+ thumb?: PhotoSize
112
+ file_name?: string
113
+ mime_type?: string
114
+ file_size?: number
115
+ }
116
+
117
+ export interface Video {
118
+ file_id: string
119
+ file_unique_id: string
120
+ width: number
121
+ height: number
122
+ duration: number
123
+ thumb?: PhotoSize
124
+ mime_type?: string
125
+ file_size?: number
126
+ }
127
+
128
+ export interface Animation {
129
+ file_id: string
130
+ file_unique_id: string
131
+ width: number
132
+ height: number
133
+ duration: number
134
+ thumb?: PhotoSize
135
+ file_name?: string
136
+ mime_type?: string
137
+ file_size?: number
138
+ }
139
+
140
+ export interface Voice {
141
+ file_id: string
142
+ file_unique_id: string
143
+ duration: number
144
+ mime_type?: string
145
+ file_size?: number
146
+ }
147
+
148
+ export interface VideoNote {
149
+ file_id: string
150
+ file_unique_id: string
151
+ length: number
152
+ duration: number
153
+ thumb?: PhotoSize
154
+ file_size?: number
155
+ }
156
+
157
+ export interface Sticker {
158
+ file_id: string
159
+ file_unique_id: string
160
+ width: number
161
+ height: number
162
+ is_animated: boolean
163
+ is_video: boolean
164
+ thumb?: PhotoSize
165
+ emoji?: string
166
+ set_name?: string
167
+ mask_position?: MaskPosition
168
+ file_size?: number
169
+ }
170
+
171
+ export interface MaskPosition {
172
+ point: string
173
+ x_shift: number
174
+ y_shift: number
175
+ scale: number
176
+ }
177
+
178
+ export interface Location {
179
+ longitude: number
180
+ latitude: number
181
+ horizontal_accuracy?: number
182
+ live_period?: number
183
+ heading?: number
184
+ proximity_alert_radius?: number
185
+ }
186
+
187
+ export interface Venue {
188
+ location: Location
189
+ title: string
190
+ address: string
191
+ foursquare_id?: string
192
+ foursquare_type?: string
193
+ }
194
+
195
+ export interface Contact {
196
+ phone_number: string
197
+ first_name: string
198
+ last_name?: string
199
+ user_id?: number
200
+ vcard?: string
201
+ }
202
+
203
+ export interface Poll {
204
+ id: string
205
+ question: string
206
+ options: PollOption[]
207
+ total_voter_count: number
208
+ is_closed: boolean
209
+ is_anonymous: boolean
210
+ type: string
211
+ allows_multiple_answers: boolean
212
+ }
213
+
214
+ export interface PollOption {
215
+ text: string
216
+ voter_count: number
217
+ }
218
+
219
+ export interface Dice {
220
+ emoji: string
221
+ value: number
222
+ }
223
+
224
+ export interface Update {
225
+ update_id: number
226
+ message?: Message
227
+ edited_message?: Message
228
+ channel_post?: Message
229
+ edited_channel_post?: Message
230
+ inline_query?: InlineQuery
231
+ chosen_inline_result?: ChosenInlineResult
232
+ callback_query?: CallbackQuery
233
+ poll?: Poll
234
+ poll_answer?: PollAnswer
235
+ my_chat_member?: ChatMemberUpdated
236
+ chat_member?: ChatMemberUpdated
237
+ }
238
+
239
+ export interface InlineQuery {
240
+ id: string
241
+ from: User
242
+ query: string
243
+ offset: string
244
+ chat_type?: string
245
+ location?: Location
246
+ }
247
+
248
+ export interface ChosenInlineResult {
249
+ result_id: string
250
+ from: User
251
+ location?: Location
252
+ inline_message_id?: string
253
+ query: string
254
+ }
255
+
256
+ export interface CallbackQuery {
257
+ id: string
258
+ from: User
259
+ message?: Message
260
+ inline_message_id?: string
261
+ chat_instance: string
262
+ data?: string
263
+ game_short_name?: string
264
+ }
265
+
266
+ export interface PollAnswer {
267
+ poll_id: string
268
+ user: User
269
+ option_ids: number[]
270
+ }
271
+
272
+ export interface ChatMemberUpdated {
273
+ chat: Chat
274
+ from: User
275
+ date: number
276
+ old_chat_member: ChatMember
277
+ new_chat_member: ChatMember
278
+ invite_link?: ChatInviteLink
279
+ }
280
+
281
+ export interface ChatMember {
282
+ user: User
283
+ status: string
284
+ custom_title?: string
285
+ is_anonymous?: boolean
286
+ can_be_edited?: boolean
287
+ can_manage_chat?: boolean
288
+ can_post_messages?: boolean
289
+ can_edit_messages?: boolean
290
+ can_delete_messages?: boolean
291
+ can_manage_video_chats?: boolean
292
+ can_restrict_members?: boolean
293
+ can_promote_members?: boolean
294
+ can_change_info?: boolean
295
+ can_invite_users?: boolean
296
+ can_pin_messages?: boolean
297
+ is_member?: boolean
298
+ can_send_messages?: boolean
299
+ can_send_media_messages?: boolean
300
+ can_send_polls?: boolean
301
+ can_send_other_messages?: boolean
302
+ can_add_web_page_previews?: boolean
303
+ until_date?: number
304
+ }
305
+
306
+ export interface ChatInviteLink {
307
+ invite_link: string
308
+ creator: User
309
+ creates_join_request: boolean
310
+ is_primary: boolean
311
+ is_revoked: boolean
312
+ name?: string
313
+ expire_date?: number
314
+ member_limit?: number
315
+ pending_join_request_count?: number
316
+ }
317
+
318
+ export interface InlineKeyboardMarkup {
319
+ inline_keyboard: InlineKeyboardButton[][]
320
+ }
321
+
322
+ export interface InlineKeyboardButton {
323
+ text: string
324
+ url?: string
325
+ callback_data?: string
326
+ switch_inline_query?: string
327
+ switch_inline_query_current_chat?: string
328
+ callback_game?: any
329
+ pay?: boolean
330
+ login_url?: any
331
+ }
332
+
333
+ export interface ReplyKeyboardMarkup {
334
+ keyboard: KeyboardButton[][]
335
+ resize_keyboard?: boolean
336
+ one_time_keyboard?: boolean
337
+ selective?: boolean
338
+ input_field_placeholder?: string
339
+ }
340
+
341
+ export interface KeyboardButton {
342
+ text: string
343
+ request_contact?: boolean
344
+ request_location?: boolean
345
+ request_poll?: KeyboardButtonPollType
346
+ }
347
+
348
+ export interface KeyboardButtonPollType {
349
+ type?: string
350
+ }
351
+
352
+ export interface ReplyKeyboardRemove {
353
+ remove_keyboard: true
354
+ selective?: boolean
355
+ }
356
+
357
+ export interface ForceReply {
358
+ force_reply: true
359
+ selective?: boolean
360
+ input_field_placeholder?: string
361
+ }
362
+
363
+ export interface SendMessageOptions {
364
+ parse_mode?: "Markdown" | "MarkdownV2" | "HTML"
365
+ entities?: MessageEntity[]
366
+ disable_web_page_preview?: boolean
367
+ disable_notification?: boolean
368
+ protect_content?: boolean
369
+ reply_to_message_id?: number
370
+ allow_sending_without_reply?: boolean
371
+ reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply
372
+ }
373
+
374
+ export interface SendPhotoOptions extends SendMessageOptions {
375
+ caption?: string
376
+ caption_entities?: MessageEntity[]
377
+ }
378
+
379
+ export interface SendDocumentOptions extends SendMessageOptions {
380
+ caption?: string
381
+ caption_entities?: MessageEntity[]
382
+ disable_content_type_detection?: boolean
383
+ }
384
+
385
+ export interface SendMediaContent {
386
+ text?: string
387
+ image?: string | Buffer | ReadableStream
388
+ video?: string | Buffer | ReadableStream
389
+ audio?: string | Buffer | ReadableStream
390
+ document?: string | Buffer | ReadableStream
391
+ sticker?: string | Buffer | ReadableStream
392
+ caption?: string
393
+ [key: string]: any
394
+ }
395
+
396
+ export interface Context {
397
+ update: Update
398
+ bot: TelegramBot
399
+ message?: Message
400
+ callbackQuery?: CallbackQuery
401
+ inlineQuery?: InlineQuery
402
+ chosenInlineResult?: ChosenInlineResult
403
+ poll?: Poll
404
+ pollAnswer?: PollAnswer
405
+ myChatMember?: ChatMemberUpdated
406
+ chatMember?: ChatMemberUpdated
407
+ chat?: Chat
408
+ from?: User
409
+ chatId?: number
410
+ send: (content: string | SendMediaContent, options?: any) => Promise<Message>
411
+ reply: (text: string, options?: any) => Promise<Message>
412
+ replyWithPhoto: (photo: string | Buffer, options?: SendPhotoOptions) => Promise<Message>
413
+ replyWithVideo: (video: string | Buffer, options?: any) => Promise<Message>
414
+ replyWithAudio: (audio: string | Buffer, options?: any) => Promise<Message>
415
+ replyWithDocument: (document: string | Buffer, options?: SendDocumentOptions) => Promise<Message>
416
+ editMessageText: (text: string, options?: any) => Promise<Message | boolean>
417
+ answerCallbackQuery: (options?: any) => Promise<boolean>
418
+ }
419
+
420
+ export type Middleware = (ctx: Context, next: () => Promise<void>) => Promise<void> | void
421
+ export type CommandHandler = (ctx: Context) => Promise<void> | void
422
+
423
+ export class InlineKeyboardBuilder {
424
+ constructor()
425
+ text(text: string, callbackData: string): this
426
+ url(text: string, url: string): this
427
+ login(text: string, loginUrl: any): this
428
+ switchInline(text: string, query?: string): this
429
+ switchInlineCurrent(text: string, query?: string): this
430
+ game(text: string): this
431
+ pay(text: string): this
432
+ row(): this
433
+ build(): InlineKeyboardMarkup
434
+ }
435
+
436
+ export class ReplyKeyboardBuilder {
437
+ constructor()
438
+ text(text: string): this
439
+ requestContact(text: string): this
440
+ requestLocation(text: string): this
441
+ requestPoll(text: string, type?: string): this
442
+ row(): this
443
+ resize(resize?: boolean): this
444
+ oneTime(oneTime?: boolean): this
445
+ selective(selective?: boolean): this
446
+ placeholder(text: string): this
447
+ build(): ReplyKeyboardMarkup
448
+ }
449
+
450
+ export class TelegramBot extends EventEmitter {
451
+ constructor(token: string, options?: BotOptions)
452
+
453
+ request(method: string, params?: any, formData?: any): Promise<any>
454
+ queuedRequest(method: string, params?: any, formData?: any): Promise<any>
455
+
456
+ getMe(): Promise<User>
457
+ getUpdates(params?: any): Promise<Update[]>
458
+ setWebhook(url: string, params?: any): Promise<boolean>
459
+ deleteWebhook(params?: any): Promise<boolean>
460
+ getWebhookInfo(): Promise<any>
461
+
462
+ sendMessage(chatId: number | string, content: string | SendMediaContent, options?: any): Promise<Message>
463
+ sendPhoto(chatId: number | string, photo: string | Buffer, options?: SendPhotoOptions): Promise<Message>
464
+ sendAudio(chatId: number | string, audio: string | Buffer, options?: any): Promise<Message>
465
+ sendDocument(chatId: number | string, document: string | Buffer, options?: SendDocumentOptions): Promise<Message>
466
+ sendVideo(chatId: number | string, video: string | Buffer, options?: any): Promise<Message>
467
+ sendAnimation(chatId: number | string, animation: string | Buffer, options?: any): Promise<Message>
468
+ sendVoice(chatId: number | string, voice: string | Buffer, options?: any): Promise<Message>
469
+ sendVideoNote(chatId: number | string, videoNote: string | Buffer, options?: any): Promise<Message>
470
+ sendSticker(chatId: number | string, sticker: string | Buffer, options?: any): Promise<Message>
471
+ sendLocation(chatId: number | string, latitude: number, longitude: number, options?: any): Promise<Message>
472
+ sendVenue(
473
+ chatId: number | string,
474
+ latitude: number,
475
+ longitude: number,
476
+ title: string,
477
+ address: string,
478
+ options?: any,
479
+ ): Promise<Message>
480
+ sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: any): Promise<Message>
481
+ sendPoll(chatId: number | string, question: string, options: string[], params?: any): Promise<Message>
482
+ sendDice(chatId: number | string, options?: any): Promise<Message>
483
+ sendChatAction(chatId: number | string, action: string): Promise<boolean>
484
+
485
+ forwardMessage(
486
+ chatId: number | string,
487
+ fromChatId: number | string,
488
+ messageId: number,
489
+ options?: any,
490
+ ): Promise<Message>
491
+ copyMessage(chatId: number | string, fromChatId: number | string, messageId: number, options?: any): Promise<any>
492
+
493
+ editMessageText(text: string, options?: any): Promise<Message | boolean>
494
+ editMessageCaption(options?: any): Promise<Message | boolean>
495
+ editMessageReplyMarkup(options?: any): Promise<Message | boolean>
496
+ deleteMessage(chatId: number | string, messageId: number): Promise<boolean>
497
+
498
+ answerCallbackQuery(callbackQueryId: string, options?: any): Promise<boolean>
499
+ answerInlineQuery(inlineQueryId: string, results: any[], options?: any): Promise<boolean>
500
+
501
+ getChat(chatId: number | string): Promise<Chat>
502
+ getChatAdministrators(chatId: number | string): Promise<ChatMember[]>
503
+ getChatMemberCount(chatId: number | string): Promise<number>
504
+ getChatMember(chatId: number | string, userId: number): Promise<ChatMember>
505
+
506
+ setChatTitle(chatId: number | string, title: string): Promise<boolean>
507
+ setChatDescription(chatId: number | string, description: string): Promise<boolean>
508
+
509
+ pinChatMessage(chatId: number | string, messageId: number, options?: any): Promise<boolean>
510
+ unpinChatMessage(chatId: number | string, options?: any): Promise<boolean>
511
+ unpinAllChatMessages(chatId: number | string): Promise<boolean>
512
+
513
+ leaveChat(chatId: number | string): Promise<boolean>
514
+ banChatMember(chatId: number | string, userId: number, options?: any): Promise<boolean>
515
+ unbanChatMember(chatId: number | string, userId: number, options?: any): Promise<boolean>
516
+ restrictChatMember(chatId: number | string, userId: number, permissions: any, options?: any): Promise<boolean>
517
+ promoteChatMember(chatId: number | string, userId: number, options?: any): Promise<boolean>
518
+
519
+ getFile(fileId: string): Promise<any>
520
+ downloadFile(fileId: string, destination: string): Promise<string>
521
+
522
+ use(middleware: Middleware): this
523
+ command(cmd: string | string[], handler: CommandHandler): this
524
+
525
+ startPolling(): Promise<void>
526
+ stopPolling(): void
527
+ startWebhook(): Promise<void>
528
+ stopWebhook(): void
529
+
530
+ on(event: "update", listener: (update: Update) => void): this
531
+ on(event: "message", listener: (message: Message, ctx: Context) => void): this
532
+ on(event: "text", listener: (message: Message, ctx: Context) => void): this
533
+ on(event: "photo", listener: (message: Message, ctx: Context) => void): this
534
+ on(event: "document", listener: (message: Message, ctx: Context) => void): this
535
+ on(event: "video", listener: (message: Message, ctx: Context) => void): this
536
+ on(event: "audio", listener: (message: Message, ctx: Context) => void): this
537
+ on(event: "voice", listener: (message: Message, ctx: Context) => void): this
538
+ on(event: "sticker", listener: (message: Message, ctx: Context) => void): this
539
+ on(event: "location", listener: (message: Message, ctx: Context) => void): this
540
+ on(event: "contact", listener: (message: Message, ctx: Context) => void): this
541
+ on(event: "edited_message", listener: (message: Message, ctx: Context) => void): this
542
+ on(event: "channel_post", listener: (message: Message, ctx: Context) => void): this
543
+ on(event: "edited_channel_post", listener: (message: Message, ctx: Context) => void): this
544
+ on(event: "callback_query", listener: (query: CallbackQuery, ctx: Context) => void): this
545
+ on(event: "inline_query", listener: (query: InlineQuery, ctx: Context) => void): this
546
+ on(event: "chosen_inline_result", listener: (result: ChosenInlineResult, ctx: Context) => void): this
547
+ on(event: "poll", listener: (poll: Poll, ctx: Context) => void): this
548
+ on(event: "poll_answer", listener: (answer: PollAnswer, ctx: Context) => void): this
549
+ on(event: "my_chat_member", listener: (member: ChatMemberUpdated, ctx: Context) => void): this
550
+ on(event: "chat_member", listener: (member: ChatMemberUpdated, ctx: Context) => void): this
551
+ on(event: "polling_start", listener: () => void): this
552
+ on(event: "polling_stop", listener: () => void): this
553
+ on(event: "polling_error", listener: (error: Error) => void): this
554
+ on(event: "webhook_start", listener: (port: number) => void): this
555
+ on(event: "webhook_stop", listener: () => void): this
556
+ on(event: "webhook_error", listener: (error: Error) => void): this
557
+ on(event: "error", listener: (error: Error) => void): this
558
+ on(event: string, listener: (...args: any[]) => void): this
559
+
560
+ static InlineKeyboard(): InlineKeyboardBuilder
561
+ static ReplyKeyboard(): ReplyKeyboardBuilder
562
+ static RemoveKeyboard(): ReplyKeyboardRemove
563
+ static ForceReply(): ForceReply
564
+ }
565
+
566
+ export default TelegramBot