UNPKG

55.3 kBPlain TextView Raw
1import * as tg from './core/types/typegram'
2import * as tt from './telegram-types'
3import ApiClient from './core/network/client'
4import { isAbsolute } from 'path'
5import { URL } from 'url'
6import { FmtString } from './format'
7import { fmtCaption } from './core/helpers/util'
8
9export class Telegram extends ApiClient {
10 /**
11 * Get basic information about the bot
12 */
13 getMe() {
14 return this.callApi('getMe', {})
15 }
16
17 /**
18 * Get basic info about a file and prepare it for downloading.
19 * @param fileId Id of file to get link to
20 */
21 getFile(fileId: string) {
22 return this.callApi('getFile', { file_id: fileId })
23 }
24
25 /**
26 * Get download link to a file.
27 */
28 async getFileLink(fileId: string | tg.File) {
29 if (typeof fileId === 'string') {
30 fileId = await this.getFile(fileId)
31 } else if (fileId.file_path === undefined) {
32 fileId = await this.getFile(fileId.file_id)
33 }
34
35 // Local bot API instances return the absolute path to the file
36 if (fileId.file_path !== undefined && isAbsolute(fileId.file_path)) {
37 const url = new URL(this.options.apiRoot)
38 url.port = ''
39 url.pathname = fileId.file_path
40 url.protocol = 'file:'
41 return url
42 }
43
44 return new URL(
45 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46 `./file/${this.options.apiMode}${this.token}/${fileId.file_path!}`,
47 this.options.apiRoot
48 )
49 }
50
51 /**
52 * Directly request incoming updates.
53 * You should probably use `Telegraf::launch` instead.
54 */
55 getUpdates(
56 timeout: number,
57 limit: number,
58 offset: number,
59 allowedUpdates: readonly tt.UpdateType[] | undefined
60 ) {
61 return this.callApi('getUpdates', {
62 allowed_updates: allowedUpdates,
63 limit,
64 offset,
65 timeout,
66 })
67 }
68
69 getWebhookInfo() {
70 return this.callApi('getWebhookInfo', {})
71 }
72
73 getGameHighScores(
74 userId: number,
75 inlineMessageId: string | undefined,
76 chatId: number | undefined,
77 messageId: number | undefined
78 ) {
79 return this.callApi('getGameHighScores', {
80 user_id: userId,
81 inline_message_id: inlineMessageId,
82 chat_id: chatId,
83 message_id: messageId,
84 })
85 }
86
87 setGameScore(
88 userId: number,
89 score: number,
90 inlineMessageId: string | undefined,
91 chatId: number | undefined,
92 messageId: number | undefined,
93 editMessage = true,
94 force = false
95 ) {
96 return this.callApi('setGameScore', {
97 force,
98 score,
99 user_id: userId,
100 inline_message_id: inlineMessageId,
101 chat_id: chatId,
102 message_id: messageId,
103 disable_edit_message: !editMessage,
104 })
105 }
106
107 /**
108 * Specify a url to receive incoming updates via an outgoing webhook.
109 * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration
110 */
111 setWebhook(url: string, extra?: tt.ExtraSetWebhook) {
112 return this.callApi('setWebhook', {
113 url,
114 ...extra,
115 })
116 }
117
118 /**
119 * Remove webhook integration.
120 */
121 deleteWebhook(extra?: { drop_pending_updates?: boolean }) {
122 return this.callApi('deleteWebhook', {
123 ...extra,
124 })
125 }
126
127 /**
128 * Send a text message.
129 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
130 * @param text Text of the message to be sent
131 */
132 sendMessage(
133 chatId: number | string,
134 text: string | FmtString,
135 extra?: tt.ExtraReplyMessage
136 ) {
137 const t = FmtString.normalise(text)
138 return this.callApi('sendMessage', { chat_id: chatId, ...extra, ...t })
139 }
140
141 /**
142 * Forward existing message.
143 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
144 * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
145 * @param messageId Message identifier in the chat specified in from_chat_id
146 */
147 forwardMessage(
148 chatId: number | string,
149 fromChatId: number | string,
150 messageId: number,
151 extra?: tt.ExtraForwardMessage
152 ) {
153 return this.callApi('forwardMessage', {
154 chat_id: chatId,
155 from_chat_id: fromChatId,
156 message_id: messageId,
157 ...extra,
158 })
159 }
160
161 /**
162 * Use this method when you need to tell the user that something is happening on the bot's side.
163 * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
164 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
165 */
166 sendChatAction(
167 chat_id: number | string,
168 action: tt.ChatAction,
169 extra?: tt.ExtraSendChatAction
170 ) {
171 return this.callApi('sendChatAction', { chat_id, action, ...extra })
172 }
173
174 getUserProfilePhotos(userId: number, offset?: number, limit?: number) {
175 return this.callApi('getUserProfilePhotos', {
176 user_id: userId,
177 offset,
178 limit,
179 })
180 }
181
182 /**
183 * Send point on the map.
184 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
185 */
186 sendLocation(
187 chatId: number | string,
188 latitude: number,
189 longitude: number,
190 extra?: tt.ExtraLocation
191 ) {
192 return this.callApi('sendLocation', {
193 chat_id: chatId,
194 latitude,
195 longitude,
196 ...extra,
197 })
198 }
199
200 sendVenue(
201 chatId: number | string,
202 latitude: number,
203 longitude: number,
204 title: string,
205 address: string,
206 extra?: tt.ExtraVenue
207 ) {
208 return this.callApi('sendVenue', {
209 latitude,
210 longitude,
211 title,
212 address,
213 chat_id: chatId,
214 ...extra,
215 })
216 }
217
218 /**
219 * @param chatId Unique identifier for the target private chat
220 */
221 sendInvoice(
222 chatId: number | string,
223 invoice: tt.NewInvoiceParameters,
224 extra?: tt.ExtraInvoice
225 ) {
226 return this.callApi('sendInvoice', {
227 chat_id: chatId,
228 ...invoice,
229 ...extra,
230 })
231 }
232
233 sendContact(
234 chatId: number | string,
235 phoneNumber: string,
236 firstName: string,
237 extra?: tt.ExtraContact
238 ) {
239 return this.callApi('sendContact', {
240 chat_id: chatId,
241 phone_number: phoneNumber,
242 first_name: firstName,
243 ...extra,
244 })
245 }
246
247 /**
248 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
249 */
250 sendPhoto(
251 chatId: number | string,
252 photo: tg.Opts<'sendPhoto'>['photo'],
253 extra?: tt.ExtraPhoto
254 ) {
255 return this.callApi('sendPhoto', {
256 chat_id: chatId,
257 photo,
258 ...fmtCaption(extra),
259 })
260 }
261
262 /**
263 * Send a dice, which will have a random value from 1 to 6.
264 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
265 */
266 sendDice(chatId: number | string, extra?: tt.ExtraDice) {
267 return this.callApi('sendDice', { chat_id: chatId, ...extra })
268 }
269
270 /**
271 * Send general files. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
272 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
273 */
274 sendDocument(
275 chatId: number | string,
276 document: tg.Opts<'sendDocument'>['document'],
277 extra?: tt.ExtraDocument
278 ) {
279 return this.callApi('sendDocument', {
280 chat_id: chatId,
281 document,
282 ...fmtCaption(extra),
283 })
284 }
285
286 /**
287 * Send audio files, if you want Telegram clients to display them in the music player.
288 * Your audio must be in the .mp3 format.
289 * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
290 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
291 */
292 sendAudio(
293 chatId: number | string,
294 audio: tg.Opts<'sendAudio'>['audio'],
295 extra?: tt.ExtraAudio
296 ) {
297 return this.callApi('sendAudio', {
298 chat_id: chatId,
299 audio,
300 ...fmtCaption(extra),
301 })
302 }
303
304 /**
305 * Send .webp, animated .tgs, or video .webm stickers
306 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
307 */
308 sendSticker(
309 chatId: number | string,
310 sticker: tg.Opts<'sendSticker'>['sticker'],
311 extra?: tt.ExtraSticker
312 ) {
313 return this.callApi('sendSticker', { chat_id: chatId, sticker, ...extra })
314 }
315
316 /**
317 * Send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
318 * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
319 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
320 */
321 sendVideo(
322 chatId: number | string,
323 video: tg.Opts<'sendVideo'>['video'],
324 extra?: tt.ExtraVideo
325 ) {
326 return this.callApi('sendVideo', {
327 chat_id: chatId,
328 video,
329 ...fmtCaption(extra),
330 })
331 }
332
333 /**
334 * Send .gif animations.
335 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
336 */
337 sendAnimation(
338 chatId: number | string,
339 animation: tg.Opts<'sendAnimation'>['animation'],
340 extra?: tt.ExtraAnimation
341 ) {
342 return this.callApi('sendAnimation', {
343 chat_id: chatId,
344 animation,
345 ...fmtCaption(extra),
346 })
347 }
348
349 /**
350 * Send video messages.
351 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
352 */
353 sendVideoNote(
354 chatId: number | string,
355 videoNote: string | tg.InputFileVideoNote,
356 extra?: tt.ExtraVideoNote
357 ) {
358 return this.callApi('sendVideoNote', {
359 chat_id: chatId,
360 video_note: videoNote,
361 ...extra,
362 })
363 }
364
365 /**
366 * Send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
367 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
368 */
369 sendVoice(
370 chatId: number | string,
371 voice: tg.Opts<'sendVoice'>['voice'],
372 extra?: tt.ExtraVoice
373 ) {
374 return this.callApi('sendVoice', {
375 chat_id: chatId,
376 voice,
377 ...fmtCaption(extra),
378 })
379 }
380
381 /**
382 * @param chatId Unique identifier for the target chat
383 * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
384 */
385 sendGame(chatId: number, gameName: string, extra?: tt.ExtraGame) {
386 return this.callApi('sendGame', {
387 chat_id: chatId,
388 game_short_name: gameName,
389 ...extra,
390 })
391 }
392
393 /**
394 * Send a group of photos or videos as an album.
395 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
396 * @param media A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
397 */
398 sendMediaGroup(
399 chatId: number | string,
400 media: tt.MediaGroup,
401 extra?: tt.ExtraMediaGroup
402 ) {
403 return this.callApi('sendMediaGroup', { chat_id: chatId, media, ...extra })
404 }
405
406 /**
407 * Send a native poll.
408 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
409 * @param question Poll question, 1-255 characters
410 * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
411 */
412 sendPoll(
413 chatId: number | string,
414 question: string,
415 options: readonly string[],
416 extra?: tt.ExtraPoll
417 ) {
418 return this.callApi('sendPoll', {
419 chat_id: chatId,
420 type: 'regular',
421 question,
422 options,
423 ...extra,
424 })
425 }
426
427 /**
428 * Send a native quiz.
429 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
430 * @param question Poll question, 1-255 characters
431 * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
432 */
433 sendQuiz(
434 chatId: number | string,
435 question: string,
436 options: readonly string[],
437 extra: tt.ExtraPoll
438 ) {
439 return this.callApi('sendPoll', {
440 chat_id: chatId,
441 type: 'quiz',
442 question,
443 options,
444 ...extra,
445 })
446 }
447
448 /**
449 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
450 * @param messageId Identifier of the original message with the poll
451 */
452 stopPoll(
453 chatId: number | string,
454 messageId: number,
455 extra?: tt.ExtraStopPoll
456 ) {
457 return this.callApi('stopPoll', {
458 chat_id: chatId,
459 message_id: messageId,
460 ...extra,
461 })
462 }
463
464 /**
465 * Get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
466 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
467 */
468 getChat(chatId: number | string) {
469 return this.callApi('getChat', { chat_id: chatId })
470 }
471
472 /**
473 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
474 */
475 getChatAdministrators(chatId: number | string) {
476 return this.callApi('getChatAdministrators', { chat_id: chatId })
477 }
478
479 /**
480 * Get information about a member of a chat.
481 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
482 * @param userId Unique identifier of the target user
483 */
484 getChatMember(chatId: string | number, userId: number) {
485 return this.callApi('getChatMember', { chat_id: chatId, user_id: userId })
486 }
487
488 /**
489 * Get the number of members in a chat.
490 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
491 */
492 getChatMembersCount(chatId: string | number) {
493 return this.callApi('getChatMembersCount', { chat_id: chatId })
494 }
495
496 /**
497 * Send answers to an inline query.
498 * No more than 50 results per query are allowed.
499 */
500 answerInlineQuery(
501 inlineQueryId: string,
502 results: readonly tg.InlineQueryResult[],
503 extra?: tt.ExtraAnswerInlineQuery
504 ) {
505 return this.callApi('answerInlineQuery', {
506 inline_query_id: inlineQueryId,
507 results,
508 ...extra,
509 })
510 }
511
512 setChatPermissions(
513 chatId: number | string,
514 permissions: tg.ChatPermissions,
515 extra?: tt.ExtraSetChatPermissions
516 ) {
517 return this.callApi('setChatPermissions', {
518 chat_id: chatId,
519 permissions,
520 ...extra,
521 })
522 }
523
524 /**
525 * Kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
526 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
527 * @param untilDate Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
528 */
529 banChatMember(
530 chatId: number | string,
531 userId: number,
532 untilDate?: number,
533 extra?: tt.ExtraBanChatMember
534 ) {
535 return this.callApi('banChatMember', {
536 chat_id: chatId,
537 user_id: userId,
538 until_date: untilDate,
539 ...extra,
540 })
541 }
542
543 /**
544 * Kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
545 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
546 * @param untilDate Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
547 * @deprecated since API 5.3. Use {@link Telegram.banChatMember}
548 */
549 get kickChatMember() {
550 return this.banChatMember
551 }
552
553 /**
554 * Promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.
555 * @param chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
556 */
557 promoteChatMember(
558 chatId: number | string,
559 userId: number,
560 extra: tt.ExtraPromoteChatMember
561 ) {
562 return this.callApi('promoteChatMember', {
563 chat_id: chatId,
564 user_id: userId,
565 ...extra,
566 })
567 }
568
569 /**
570 * Restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.
571 * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
572 */
573 restrictChatMember(
574 chatId: string | number,
575 userId: number,
576 extra: tt.ExtraRestrictChatMember
577 ) {
578 return this.callApi('restrictChatMember', {
579 chat_id: chatId,
580 user_id: userId,
581 ...extra,
582 })
583 }
584
585 setChatAdministratorCustomTitle(
586 chatId: number | string,
587 userId: number,
588 title: string
589 ) {
590 return this.callApi('setChatAdministratorCustomTitle', {
591 chat_id: chatId,
592 user_id: userId,
593 custom_title: title,
594 })
595 }
596
597 /**
598 * Export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
599 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
600 */
601 exportChatInviteLink(chatId: number | string) {
602 return this.callApi('exportChatInviteLink', { chat_id: chatId })
603 }
604
605 createChatInviteLink(
606 chatId: number | string,
607 extra?: tt.ExtraCreateChatInviteLink
608 ) {
609 return this.callApi('createChatInviteLink', {
610 chat_id: chatId,
611 ...extra,
612 })
613 }
614
615 createInvoiceLink(invoice: tt.NewInvoiceLinkParameters) {
616 return this.callApi('createInvoiceLink', {
617 ...invoice,
618 })
619 }
620
621 editChatInviteLink(
622 chatId: number | string,
623 inviteLink: string,
624 extra?: tt.ExtraEditChatInviteLink
625 ) {
626 return this.callApi('editChatInviteLink', {
627 chat_id: chatId,
628 invite_link: inviteLink,
629 ...extra,
630 })
631 }
632
633 revokeChatInviteLink(chatId: number | string, inviteLink: string) {
634 return this.callApi('revokeChatInviteLink', {
635 chat_id: chatId,
636 invite_link: inviteLink,
637 })
638 }
639
640 setChatPhoto(
641 chatId: number | string,
642 photo: tg.Opts<'setChatPhoto'>['photo']
643 ) {
644 return this.callApi('setChatPhoto', { chat_id: chatId, photo })
645 }
646
647 deleteChatPhoto(chatId: number | string) {
648 return this.callApi('deleteChatPhoto', { chat_id: chatId })
649 }
650
651 /**
652 * Change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
653 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
654 * @param title New chat title, 1-255 characters
655 */
656 setChatTitle(chatId: number | string, title: string) {
657 return this.callApi('setChatTitle', { chat_id: chatId, title })
658 }
659
660 setChatDescription(chatId: number | string, description?: string) {
661 return this.callApi('setChatDescription', { chat_id: chatId, description })
662 }
663
664 /**
665 * Pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or 'can_edit_messages' admin right in the channel.
666 * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
667 */
668 pinChatMessage(
669 chatId: number | string,
670 messageId: number,
671 extra?: { disable_notification?: boolean }
672 ) {
673 return this.callApi('pinChatMessage', {
674 chat_id: chatId,
675 message_id: messageId,
676 ...extra,
677 })
678 }
679
680 /**
681 * Unpin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or 'can_edit_messages' admin right in the channel.
682 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
683 */
684 unpinChatMessage(chatId: number | string, messageId?: number) {
685 return this.callApi('unpinChatMessage', {
686 chat_id: chatId,
687 message_id: messageId,
688 })
689 }
690
691 /**
692 * Clear the list of pinned messages in a chat.
693 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
694 */
695 unpinAllChatMessages(chatId: number | string) {
696 return this.callApi('unpinAllChatMessages', { chat_id: chatId })
697 }
698
699 /**
700 * Use this method for your bot to leave a group, supergroup or channel.
701 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
702 */
703 leaveChat(chatId: number | string) {
704 return this.callApi('leaveChat', { chat_id: chatId })
705 }
706
707 /**
708 * Unban a user from a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
709 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
710 * @param userId Unique identifier of the target user
711 */
712 unbanChatMember(
713 chatId: number | string,
714 userId: number,
715 extra?: { only_if_banned?: boolean }
716 ) {
717 return this.callApi('unbanChatMember', {
718 chat_id: chatId,
719 user_id: userId,
720 ...extra,
721 })
722 }
723
724 answerCbQuery(
725 callbackQueryId: string,
726 text?: string,
727 extra?: tt.ExtraAnswerCbQuery
728 ) {
729 return this.callApi('answerCallbackQuery', {
730 text,
731 callback_query_id: callbackQueryId,
732 ...extra,
733 })
734 }
735
736 answerGameQuery(callbackQueryId: string, url: string) {
737 return this.callApi('answerCallbackQuery', {
738 url,
739 callback_query_id: callbackQueryId,
740 })
741 }
742
743 /**
744 * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified,
745 * the Bot API will send an Update with a shipping_query field to the bot.
746 * Reply to shipping queries.
747 * @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
748 * @param shippingOptions Required if ok is True. A JSON-serialized array of available shipping options.
749 * @param errorMessage Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
750 */
751 answerShippingQuery(
752 shippingQueryId: string,
753 ok: boolean,
754 shippingOptions: readonly tg.ShippingOption[] | undefined,
755 errorMessage: string | undefined
756 ) {
757 return this.callApi('answerShippingQuery', {
758 ok,
759 shipping_query_id: shippingQueryId,
760 shipping_options: shippingOptions,
761 error_message: errorMessage,
762 })
763 }
764
765 /**
766 * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query.
767 * Respond to such pre-checkout queries. On success, True is returned.
768 * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
769 * @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
770 * @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
771 */
772 answerPreCheckoutQuery(
773 preCheckoutQueryId: string,
774 ok: boolean,
775 errorMessage?: string
776 ) {
777 return this.callApi('answerPreCheckoutQuery', {
778 ok,
779 pre_checkout_query_id: preCheckoutQueryId,
780 error_message: errorMessage,
781 })
782 }
783
784 answerWebAppQuery(webAppQueryId: string, result: tg.InlineQueryResult) {
785 return this.callApi('answerWebAppQuery', {
786 web_app_query_id: webAppQueryId,
787 result,
788 })
789 }
790
791 /**
792 * Edit text and game messages sent by the bot or via the bot (for inline bots).
793 * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
794 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
795 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
796 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
797 * @param text New text of the message
798 */
799 editMessageText(
800 chatId: number | string | undefined,
801 messageId: number | undefined,
802 inlineMessageId: string | undefined,
803 text: string | FmtString,
804 extra?: tt.ExtraEditMessageText
805 ) {
806 const t = FmtString.normalise(text)
807 return this.callApi('editMessageText', {
808 chat_id: chatId,
809 message_id: messageId,
810 inline_message_id: inlineMessageId,
811 ...extra,
812 ...t,
813 })
814 }
815
816 /**
817 * Edit captions of messages sent by the bot or via the bot (for inline bots).
818 * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
819 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
820 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
821 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
822 * @param caption New caption of the message
823 * @param markup A JSON-serialized object for an inline keyboard.
824 */
825 editMessageCaption(
826 chatId: number | string | undefined,
827 messageId: number | undefined,
828 inlineMessageId: string | undefined,
829 caption: string | FmtString | undefined,
830 extra?: tt.ExtraEditMessageCaption
831 ) {
832 return this.callApi('editMessageCaption', {
833 chat_id: chatId,
834 message_id: messageId,
835 inline_message_id: inlineMessageId,
836 ...extra,
837 ...fmtCaption({ caption }),
838 })
839 }
840
841 /**
842 * Edit animation, audio, document, photo, or video messages.
843 * If a message is a part of a message album, then it can be edited only to a photo or a video.
844 * Otherwise, message type can be changed arbitrarily.
845 * When inline message is edited, new file can't be uploaded.
846 * Use previously uploaded file via its file_id or specify a URL.
847 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
848 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
849 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
850 * @param media New media of message
851 * @param markup Markup of inline keyboard
852 */
853 editMessageMedia(
854 chatId: number | string | undefined,
855 messageId: number | undefined,
856 inlineMessageId: string | undefined,
857 media: tt.WrapCaption<tg.InputMedia>,
858 extra?: tt.ExtraEditMessageMedia
859 ) {
860 return this.callApi('editMessageMedia', {
861 chat_id: chatId,
862 message_id: messageId,
863 inline_message_id: inlineMessageId,
864 media: fmtCaption(media),
865 ...extra,
866 })
867 }
868
869 /**
870 * Edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
871 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
872 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
873 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
874 * @param markup A JSON-serialized object for an inline keyboard.
875 * @returns If edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
876 */
877 editMessageReplyMarkup(
878 chatId: number | string | undefined,
879 messageId: number | undefined,
880 inlineMessageId: string | undefined,
881 markup: tg.InlineKeyboardMarkup | undefined
882 ) {
883 return this.callApi('editMessageReplyMarkup', {
884 chat_id: chatId,
885 message_id: messageId,
886 inline_message_id: inlineMessageId,
887 reply_markup: markup,
888 })
889 }
890
891 editMessageLiveLocation(
892 chatId: number | string | undefined,
893 messageId: number | undefined,
894 inlineMessageId: string | undefined,
895 latitude: number,
896 longitude: number,
897 extra?: tt.ExtraEditMessageLiveLocation
898 ) {
899 return this.callApi('editMessageLiveLocation', {
900 latitude,
901 longitude,
902 chat_id: chatId,
903 message_id: messageId,
904 inline_message_id: inlineMessageId,
905 ...extra,
906 })
907 }
908
909 stopMessageLiveLocation(
910 chatId: number | string | undefined,
911 messageId: number | undefined,
912 inlineMessageId: string | undefined,
913 markup?: tg.InlineKeyboardMarkup
914 ) {
915 return this.callApi('stopMessageLiveLocation', {
916 chat_id: chatId,
917 message_id: messageId,
918 inline_message_id: inlineMessageId,
919 reply_markup: markup,
920 })
921 }
922
923 /**
924 * Delete a message, including service messages, with the following limitations:
925 * - A message can only be deleted if it was sent less than 48 hours ago.
926 * - Bots can delete outgoing messages in groups and supergroups.
927 * - Bots granted can_post_messages permissions can delete outgoing messages in channels.
928 * - If the bot is an administrator of a group, it can delete any message there.
929 * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
930 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
931 */
932 deleteMessage(chatId: number | string, messageId: number) {
933 return this.callApi('deleteMessage', {
934 chat_id: chatId,
935 message_id: messageId,
936 })
937 }
938
939 setChatStickerSet(chatId: number | string, setName: string) {
940 return this.callApi('setChatStickerSet', {
941 chat_id: chatId,
942 sticker_set_name: setName,
943 })
944 }
945
946 deleteChatStickerSet(chatId: number | string) {
947 return this.callApi('deleteChatStickerSet', { chat_id: chatId })
948 }
949
950 /**
951 * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.
952 * Requires no parameters. Returns an Array of Sticker objects.
953 *
954 * @see https://core.telegram.org/bots/api#getforumtopiciconstickers
955 */
956 getForumTopicIconStickers() {
957 return this.callApi('getForumTopicIconStickers', {})
958 }
959
960 /**
961 * Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this
962 * to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a
963 * ForumTopic object.
964 *
965 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
966 * @param name Topic name, 1-128 characters
967 *
968 * @see https://core.telegram.org/bots/api#createforumtopic
969 */
970 createForumTopic(
971 chat_id: number | string,
972 name: string,
973 extra?: tt.ExtraCreateForumTopic
974 ) {
975 return this.callApi('createForumTopic', {
976 chat_id,
977 name,
978 ...extra,
979 })
980 }
981
982 /**
983 * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in
984 * the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the
985 * topic. Returns True on success.
986 *
987 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
988 * @param message_thread_id Unique identifier for the target message thread of the forum topic
989 *
990 * @see https://core.telegram.org/bots/api#editforumtopic
991 */
992 editForumTopic(
993 chat_id: number | string,
994 message_thread_id: number,
995 extra: tt.ExtraEditForumTopic
996 ) {
997 return this.callApi('editForumTopic', {
998 chat_id,
999 message_thread_id,
1000 ...extra,
1001 })
1002 }
1003
1004 /**
1005 * Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat
1006 * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
1007 * Returns True on success.
1008 *
1009 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1010 * @param message_thread_id Unique identifier for the target message thread of the forum topic
1011 *
1012 * @see https://core.telegram.org/bots/api#closeforumtopic
1013 */
1014 closeForumTopic(chat_id: number | string, message_thread_id: number) {
1015 return this.callApi('closeForumTopic', {
1016 chat_id,
1017 message_thread_id,
1018 })
1019 }
1020
1021 /**
1022 * Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat
1023 * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
1024 * Returns True on success.
1025 *
1026 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1027 * @param message_thread_id Unique identifier for the target message thread of the forum topic
1028 *
1029 * @see https://core.telegram.org/bots/api#reopenforumtopic
1030 */
1031 reopenForumTopic(chat_id: number | string, message_thread_id: number) {
1032 return this.callApi('reopenForumTopic', {
1033 chat_id,
1034 message_thread_id,
1035 })
1036 }
1037
1038 /**
1039 * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an
1040 * administrator in the chat for this to work and must have the can_delete_messages administrator rights.
1041 * Returns True on success.
1042 *
1043 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1044 * @param message_thread_id Unique identifier for the target message thread of the forum topic
1045 *
1046 * @see https://core.telegram.org/bots/api#deleteforumtopic
1047 */
1048 deleteForumTopic(chat_id: number | string, message_thread_id: number) {
1049 return this.callApi('deleteForumTopic', {
1050 chat_id,
1051 message_thread_id,
1052 })
1053 }
1054
1055 /**
1056 * Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat
1057 * for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
1058 *
1059 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1060 * @param message_thread_id Unique identifier for the target message thread of the forum topic
1061 *
1062 * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
1063 */
1064 unpinAllForumTopicMessages(
1065 chat_id: number | string,
1066 message_thread_id: number
1067 ) {
1068 return this.callApi('unpinAllForumTopicMessages', {
1069 chat_id,
1070 message_thread_id,
1071 })
1072 }
1073
1074 /**
1075 * Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator
1076 * in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
1077 *
1078 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1079 * @param name New topic name, 1-128 characters
1080 *
1081 * @see https://core.telegram.org/bots/api#editgeneralforumtopic
1082 */
1083 editGeneralForumTopic(chat_id: number | string, name: string) {
1084 return this.callApi('editGeneralForumTopic', { chat_id, name })
1085 }
1086
1087 /**
1088 * Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the
1089 * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
1090 *
1091 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1092 *
1093 * @see https://core.telegram.org/bots/api#closegeneralforumtopic
1094 */
1095 closeGeneralForumTopic(chat_id: number | string) {
1096 return this.callApi('closeGeneralForumTopic', { chat_id })
1097 }
1098
1099 /**
1100 * Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in
1101 * the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically
1102 * unhidden if it was hidden. Returns True on success.
1103 *
1104 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1105 *
1106 * @see https://core.telegram.org/bots/api#reopengeneralforumtopic
1107 */
1108 reopenGeneralForumTopic(chat_id: number | string) {
1109 return this.callApi('reopenGeneralForumTopic', { chat_id })
1110 }
1111
1112 /**
1113 * Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat
1114 * for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed
1115 * if it was open. Returns True on success.
1116 *
1117 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1118 *
1119 * @see https://core.telegram.org/bots/api#hidegeneralforumtopic
1120 */
1121 hideGeneralForumTopic(chat_id: number | string) {
1122 return this.callApi('hideGeneralForumTopic', { chat_id })
1123 }
1124
1125 /**
1126 * Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the
1127 * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
1128 *
1129 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1130 *
1131 * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic
1132 */
1133 unhideGeneralForumTopic(chat_id: number | string) {
1134 return this.callApi('unhideGeneralForumTopic', { chat_id })
1135 }
1136
1137 /**
1138 * Use this method to clear the list of pinned messages in a General forum topic.
1139 * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator
1140 * right in the supergroup.
1141 *
1142 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
1143 */
1144 unpinAllGeneralForumTopicMessages(chat_id: number | string) {
1145 return this.callApi('unpinAllGeneralForumTopicMessages', { chat_id })
1146 }
1147
1148 getStickerSet(name: string) {
1149 return this.callApi('getStickerSet', { name })
1150 }
1151
1152 /**
1153 * Upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).
1154 * https://core.telegram.org/bots/api#sending-files
1155 * @param ownerId User identifier of sticker file owner
1156 * @param stickerFile Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
1157 */
1158 uploadStickerFile(
1159 ownerId: number,
1160 sticker: tg.Opts<'uploadStickerFile'>['sticker'],
1161 sticker_format: tg.Opts<'uploadStickerFile'>['sticker_format']
1162 ) {
1163 return this.callApi('uploadStickerFile', {
1164 user_id: ownerId,
1165 sticker_format,
1166 sticker,
1167 })
1168 }
1169
1170 /**
1171 * Create new sticker set owned by a user. The bot will be able to edit the created sticker set.
1172 * @param ownerId User identifier of created sticker set owner
1173 * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
1174 * @param title Sticker set title, 1-64 characters
1175 */
1176 createNewStickerSet(
1177 ownerId: number,
1178 name: string,
1179 title: string,
1180 stickerData: tt.ExtraCreateNewStickerSet
1181 ) {
1182 return this.callApi('createNewStickerSet', {
1183 name,
1184 title,
1185 user_id: ownerId,
1186 ...stickerData,
1187 })
1188 }
1189
1190 /**
1191 * Add a new sticker to a set created by the bot.
1192 * @param ownerId User identifier of sticker set owner
1193 * @param name Sticker set name
1194 */
1195 addStickerToSet(
1196 ownerId: number,
1197 name: string,
1198 stickerData: tt.ExtraAddStickerToSet
1199 ) {
1200 return this.callApi('addStickerToSet', {
1201 name,
1202 user_id: ownerId,
1203 ...stickerData,
1204 })
1205 }
1206
1207 /**
1208 * Move a sticker in a set created by the bot to a specific position.
1209 * @param sticker File identifier of the sticker
1210 * @param position New sticker position in the set, zero-based
1211 */
1212 setStickerPositionInSet(sticker: string, position: number) {
1213 return this.callApi('setStickerPositionInSet', {
1214 sticker,
1215 position,
1216 })
1217 }
1218
1219 /**
1220 * @deprecated since API 6.8. Use {@link Telegram.setStickerSetThumbnail}
1221 */
1222 get setStickerSetThumb() {
1223 return this.setStickerSetThumbnail
1224 }
1225
1226 /**
1227 * Use this method to set the thumbnail of a regular or mask sticker set.
1228 * The format of the thumbnail file must match the format of the stickers in the set.
1229 * @param name Sticker set name
1230 * @param userId User identifier of the sticker set owner
1231 * @param thumbnail A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size
1232 * and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to
1233 * 32 kilobytes in size (see
1234 * [animated sticker technical requirements](https://core.telegram.org/stickers#animated-sticker-requirements)),
1235 * or a WEBM video with the thumbnail up to 32 kilobytes in size; see
1236 * [video sticker technical requirements](https://core.telegram.org/stickers#video-sticker-requirements).
1237 * Pass a file_id as a String to send a file that already exists on the Telegram servers, pass a
1238 * HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using
1239 * Input helpers. Animated and video sticker set thumbnails can't be uploaded via HTTP URL.
1240 * If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
1241 */
1242 setStickerSetThumbnail(
1243 name: string,
1244 userId: number,
1245 thumbnail?: tg.Opts<'setStickerSetThumbnail'>['thumbnail']
1246 ) {
1247 return this.callApi('setStickerSetThumbnail', {
1248 name,
1249 user_id: userId,
1250 thumbnail,
1251 })
1252 }
1253
1254 setStickerMaskPosition(sticker: string, mask_position?: tg.MaskPosition) {
1255 return this.callApi('setStickerMaskPosition', { sticker, mask_position })
1256 }
1257
1258 setStickerKeywords(sticker: string, keywords?: string[]) {
1259 return this.callApi('setStickerKeywords', { sticker, keywords })
1260 }
1261
1262 setStickerEmojiList(sticker: string, emoji_list: string[]) {
1263 return this.callApi('setStickerEmojiList', { sticker, emoji_list })
1264 }
1265
1266 deleteStickerSet(name: string) {
1267 return this.callApi('deleteStickerSet', { name })
1268 }
1269
1270 setStickerSetTitle(name: string, title: string) {
1271 return this.callApi('setStickerSetTitle', { name, title })
1272 }
1273
1274 setCustomEmojiStickerSetThumbnail(name: string, custom_emoji_id: string) {
1275 return this.callApi('setCustomEmojiStickerSetThumbnail', {
1276 name,
1277 custom_emoji_id,
1278 })
1279 }
1280
1281 /**
1282 * Delete a sticker from a set created by the bot.
1283 * @param sticker File identifier of the sticker
1284 */
1285 deleteStickerFromSet(sticker: string) {
1286 return this.callApi('deleteStickerFromSet', { sticker })
1287 }
1288
1289 getCustomEmojiStickers(custom_emoji_ids: string[]) {
1290 return this.callApi('getCustomEmojiStickers', { custom_emoji_ids })
1291 }
1292
1293 /**
1294 * Change the list of the bot's commands.
1295 * @param commands A list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
1296 */
1297 setMyCommands(
1298 commands: readonly tg.BotCommand[],
1299 extra?: tt.ExtraSetMyCommands
1300 ) {
1301 return this.callApi('setMyCommands', { commands, ...extra })
1302 }
1303
1304 deleteMyCommands(extra: tg.Opts<'deleteMyCommands'> = {}) {
1305 return this.callApi('deleteMyCommands', extra)
1306 }
1307
1308 /**
1309 * Get the current list of the bot's commands.
1310 */
1311 getMyCommands(extra: tg.Opts<'getMyCommands'> = {}) {
1312 return this.callApi('getMyCommands', extra)
1313 }
1314
1315 /**
1316 * Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
1317 * @param description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
1318 * @param language_code A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
1319 */
1320 setMyDescription(description: string, language_code?: string) {
1321 return this.callApi('setMyDescription', { description, language_code })
1322 }
1323
1324 /**
1325 * Use this method to change the bot's name.
1326 * @param name New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
1327 * @param language_code A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name.
1328 */
1329 setMyName(name: string, language_code?: string) {
1330 return this.callApi('setMyName', { name, language_code })
1331 }
1332
1333 /**
1334 * Use this method to get the current bot name for the given user language.
1335 * @param language_code A two-letter ISO 639-1 language code or an empty string
1336 */
1337 getMyName(language_code?: string) {
1338 return this.callApi('getMyName', { language_code })
1339 }
1340
1341 /**
1342 * Use this method to get the current bot description for the given user language.
1343 * @param language_code A two-letter ISO 639-1 language code.
1344 */
1345 getMyDescription(language_code?: string) {
1346 return this.callApi('getMyDescription', { language_code })
1347 }
1348
1349 /**
1350 * Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot.
1351 * @param description New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
1352 * @param language_code A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.
1353 */
1354 setMyShortDescription(short_description: string, language_code?: string) {
1355 return this.callApi('setMyShortDescription', {
1356 short_description,
1357 language_code,
1358 })
1359 }
1360
1361 /**
1362 * Use this method to get the current bot short description for the given user language.
1363 * @param language_code A two-letter ISO 639-1 language code or an empty string
1364 */
1365 getMyShortDescription(language_code?: string) {
1366 return this.callApi('getMyShortDescription', { language_code })
1367 }
1368
1369 setPassportDataErrors(
1370 userId: number,
1371 errors: readonly tg.PassportElementError[]
1372 ) {
1373 return this.callApi('setPassportDataErrors', {
1374 user_id: userId,
1375 errors: errors,
1376 })
1377 }
1378
1379 /**
1380 * Send copy of existing message.
1381 * @deprecated use `copyMessage` instead
1382 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1383 * @param message Received message object
1384 */
1385 sendCopy(
1386 chatId: number | string,
1387 message: tg.Message,
1388 extra?: tt.ExtraCopyMessage
1389 ): Promise<tg.MessageId> {
1390 return this.copyMessage(chatId, message.chat.id, message.message_id, extra)
1391 }
1392
1393 /**
1394 * Send copy of existing message.
1395 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1396 * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
1397 * @param messageId Message identifier in the chat specified in from_chat_id
1398 */
1399 copyMessage(
1400 chatId: number | string,
1401 fromChatId: number | string,
1402 messageId: number,
1403 extra?: tt.ExtraCopyMessage
1404 ) {
1405 return this.callApi('copyMessage', {
1406 chat_id: chatId,
1407 from_chat_id: fromChatId,
1408 message_id: messageId,
1409 ...fmtCaption(extra),
1410 })
1411 }
1412
1413 /**
1414 * Approve a chat join request.
1415 * The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
1416 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1417 * @param userId Unique identifier of the target user
1418 */
1419 approveChatJoinRequest(chatId: number | string, userId: number) {
1420 return this.callApi('approveChatJoinRequest', {
1421 chat_id: chatId,
1422 user_id: userId,
1423 })
1424 }
1425
1426 /**
1427 * Decline a chat join request.
1428 * The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
1429 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1430 * @param userId Unique identifier of the target user
1431 */
1432 declineChatJoinRequest(chatId: number | string, userId: number) {
1433 return this.callApi('declineChatJoinRequest', {
1434 chat_id: chatId,
1435 user_id: userId,
1436 })
1437 }
1438
1439 /**
1440 * Ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first.
1441 * The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
1442 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1443 * @param senderChatId Unique identifier of the target sender chat
1444 */
1445 banChatSenderChat(
1446 chatId: number | string,
1447 senderChatId: number,
1448 extra?: tt.ExtraBanChatSenderChat
1449 ) {
1450 return this.callApi('banChatSenderChat', {
1451 chat_id: chatId,
1452 sender_chat_id: senderChatId,
1453 ...extra,
1454 })
1455 }
1456
1457 /**
1458 * Unban a previously banned channel chat in a supergroup or channel.
1459 * The bot must be an administrator for this to work and must have the appropriate administrator rights.
1460 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1461 * @param senderChatId Unique identifier of the target sender chat
1462 */
1463 unbanChatSenderChat(chatId: number | string, senderChatId: number) {
1464 return this.callApi('unbanChatSenderChat', {
1465 chat_id: chatId,
1466 sender_chat_id: senderChatId,
1467 })
1468 }
1469
1470 /**
1471 * Use this method to change the bot's menu button in a private chat, or the default menu button. Returns true on success.
1472 * @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be changed.
1473 * @param menuButton An object for the bot's new menu button.
1474 */
1475 setChatMenuButton({
1476 chatId,
1477 menuButton,
1478 }: {
1479 chatId?: number | undefined
1480 menuButton?: tg.MenuButton | undefined
1481 } = {}) {
1482 return this.callApi('setChatMenuButton', {
1483 chat_id: chatId,
1484 menu_button: menuButton,
1485 })
1486 }
1487
1488 /**
1489 * Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.
1490 * @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be returned.
1491 */
1492 getChatMenuButton({ chatId }: { chatId?: number } = {}) {
1493 return this.callApi('getChatMenuButton', {
1494 chat_id: chatId,
1495 })
1496 }
1497
1498 /**
1499 * Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
1500 * These rights will be suggested to users, but they are are free to modify the list before adding the bot.
1501 */
1502 setMyDefaultAdministratorRights({
1503 rights,
1504 forChannels,
1505 }: {
1506 rights?: tg.ChatAdministratorRights
1507 forChannels?: boolean
1508 } = {}) {
1509 return this.callApi('setMyDefaultAdministratorRights', {
1510 rights,
1511 for_channels: forChannels,
1512 })
1513 }
1514
1515 /**
1516 * Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
1517 * @param forChannels Pass true to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned.
1518 */
1519 getMyDefaultAdministratorRights({
1520 forChannels,
1521 }: { forChannels?: boolean } = {}) {
1522 return this.callApi('getMyDefaultAdministratorRights', {
1523 for_channels: forChannels,
1524 })
1525 }
1526
1527 /**
1528 * Log out from the cloud Bot API server before launching the bot locally.
1529 */
1530 logOut() {
1531 return this.callApi('logOut', {})
1532 }
1533
1534 /**
1535 * Close the bot instance before moving it from one local server to another.
1536 */
1537 close() {
1538 return this.callApi('close', {})
1539 }
1540}
1541
1542export default Telegram