UNPKG

53.4 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.Telegram = void 0;
7const client_1 = __importDefault(require("./core/network/client"));
8const path_1 = require("path");
9const url_1 = require("url");
10const format_1 = require("./format");
11const util_1 = require("./core/helpers/util");
12class Telegram extends client_1.default {
13 /**
14 * Get basic information about the bot
15 */
16 getMe() {
17 return this.callApi('getMe', {});
18 }
19 /**
20 * Get basic info about a file and prepare it for downloading.
21 * @param fileId Id of file to get link to
22 */
23 getFile(fileId) {
24 return this.callApi('getFile', { file_id: fileId });
25 }
26 /**
27 * Get download link to a file.
28 */
29 async getFileLink(fileId) {
30 if (typeof fileId === 'string') {
31 fileId = await this.getFile(fileId);
32 }
33 else if (fileId.file_path === undefined) {
34 fileId = await this.getFile(fileId.file_id);
35 }
36 // Local bot API instances return the absolute path to the file
37 if (fileId.file_path !== undefined && (0, path_1.isAbsolute)(fileId.file_path)) {
38 const url = new url_1.URL(this.options.apiRoot);
39 url.port = '';
40 url.pathname = fileId.file_path;
41 url.protocol = 'file:';
42 return url;
43 }
44 return new url_1.URL(
45 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46 `./file/${this.options.apiMode}${this.token}/${fileId.file_path}`, this.options.apiRoot);
47 }
48 /**
49 * Directly request incoming updates.
50 * You should probably use `Telegraf::launch` instead.
51 */
52 getUpdates(timeout, limit, offset, allowedUpdates) {
53 return this.callApi('getUpdates', {
54 allowed_updates: allowedUpdates,
55 limit,
56 offset,
57 timeout,
58 });
59 }
60 getWebhookInfo() {
61 return this.callApi('getWebhookInfo', {});
62 }
63 getGameHighScores(userId, inlineMessageId, chatId, messageId) {
64 return this.callApi('getGameHighScores', {
65 user_id: userId,
66 inline_message_id: inlineMessageId,
67 chat_id: chatId,
68 message_id: messageId,
69 });
70 }
71 setGameScore(userId, score, inlineMessageId, chatId, messageId, editMessage = true, force = false) {
72 return this.callApi('setGameScore', {
73 force,
74 score,
75 user_id: userId,
76 inline_message_id: inlineMessageId,
77 chat_id: chatId,
78 message_id: messageId,
79 disable_edit_message: !editMessage,
80 });
81 }
82 /**
83 * Specify a url to receive incoming updates via an outgoing webhook.
84 * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration
85 */
86 setWebhook(url, extra) {
87 return this.callApi('setWebhook', {
88 url,
89 ...extra,
90 });
91 }
92 /**
93 * Remove webhook integration.
94 */
95 deleteWebhook(extra) {
96 return this.callApi('deleteWebhook', {
97 ...extra,
98 });
99 }
100 /**
101 * Send a text message.
102 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
103 * @param text Text of the message to be sent
104 */
105 sendMessage(chatId, text, extra) {
106 const t = format_1.FmtString.normalise(text);
107 return this.callApi('sendMessage', { chat_id: chatId, ...extra, ...t });
108 }
109 /**
110 * Forward existing message.
111 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
112 * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
113 * @param messageId Message identifier in the chat specified in from_chat_id
114 */
115 forwardMessage(chatId, fromChatId, messageId, extra) {
116 return this.callApi('forwardMessage', {
117 chat_id: chatId,
118 from_chat_id: fromChatId,
119 message_id: messageId,
120 ...extra,
121 });
122 }
123 /**
124 * Use this method when you need to tell the user that something is happening on the bot's side.
125 * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
126 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
127 */
128 sendChatAction(chat_id, action, extra) {
129 return this.callApi('sendChatAction', { chat_id, action, ...extra });
130 }
131 getUserProfilePhotos(userId, offset, limit) {
132 return this.callApi('getUserProfilePhotos', {
133 user_id: userId,
134 offset,
135 limit,
136 });
137 }
138 /**
139 * Send point on the map.
140 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
141 */
142 sendLocation(chatId, latitude, longitude, extra) {
143 return this.callApi('sendLocation', {
144 chat_id: chatId,
145 latitude,
146 longitude,
147 ...extra,
148 });
149 }
150 sendVenue(chatId, latitude, longitude, title, address, extra) {
151 return this.callApi('sendVenue', {
152 latitude,
153 longitude,
154 title,
155 address,
156 chat_id: chatId,
157 ...extra,
158 });
159 }
160 /**
161 * @param chatId Unique identifier for the target private chat
162 */
163 sendInvoice(chatId, invoice, extra) {
164 return this.callApi('sendInvoice', {
165 chat_id: chatId,
166 ...invoice,
167 ...extra,
168 });
169 }
170 sendContact(chatId, phoneNumber, firstName, extra) {
171 return this.callApi('sendContact', {
172 chat_id: chatId,
173 phone_number: phoneNumber,
174 first_name: firstName,
175 ...extra,
176 });
177 }
178 /**
179 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
180 */
181 sendPhoto(chatId, photo, extra) {
182 return this.callApi('sendPhoto', {
183 chat_id: chatId,
184 photo,
185 ...(0, util_1.fmtCaption)(extra),
186 });
187 }
188 /**
189 * Send a dice, which will have a random value from 1 to 6.
190 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
191 */
192 sendDice(chatId, extra) {
193 return this.callApi('sendDice', { chat_id: chatId, ...extra });
194 }
195 /**
196 * 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.
197 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
198 */
199 sendDocument(chatId, document, extra) {
200 return this.callApi('sendDocument', {
201 chat_id: chatId,
202 document,
203 ...(0, util_1.fmtCaption)(extra),
204 });
205 }
206 /**
207 * Send audio files, if you want Telegram clients to display them in the music player.
208 * Your audio must be in the .mp3 format.
209 * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
210 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
211 */
212 sendAudio(chatId, audio, extra) {
213 return this.callApi('sendAudio', {
214 chat_id: chatId,
215 audio,
216 ...(0, util_1.fmtCaption)(extra),
217 });
218 }
219 /**
220 * Send .webp, animated .tgs, or video .webm stickers
221 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
222 */
223 sendSticker(chatId, sticker, extra) {
224 return this.callApi('sendSticker', { chat_id: chatId, sticker, ...extra });
225 }
226 /**
227 * Send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
228 * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
229 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
230 */
231 sendVideo(chatId, video, extra) {
232 return this.callApi('sendVideo', {
233 chat_id: chatId,
234 video,
235 ...(0, util_1.fmtCaption)(extra),
236 });
237 }
238 /**
239 * Send .gif animations.
240 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
241 */
242 sendAnimation(chatId, animation, extra) {
243 return this.callApi('sendAnimation', {
244 chat_id: chatId,
245 animation,
246 ...(0, util_1.fmtCaption)(extra),
247 });
248 }
249 /**
250 * Send video messages.
251 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
252 */
253 sendVideoNote(chatId, videoNote, extra) {
254 return this.callApi('sendVideoNote', {
255 chat_id: chatId,
256 video_note: videoNote,
257 ...extra,
258 });
259 }
260 /**
261 * 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.
262 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
263 */
264 sendVoice(chatId, voice, extra) {
265 return this.callApi('sendVoice', {
266 chat_id: chatId,
267 voice,
268 ...(0, util_1.fmtCaption)(extra),
269 });
270 }
271 /**
272 * @param chatId Unique identifier for the target chat
273 * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
274 */
275 sendGame(chatId, gameName, extra) {
276 return this.callApi('sendGame', {
277 chat_id: chatId,
278 game_short_name: gameName,
279 ...extra,
280 });
281 }
282 /**
283 * Send a group of photos or videos as an album.
284 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
285 * @param media A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
286 */
287 sendMediaGroup(chatId, media, extra) {
288 return this.callApi('sendMediaGroup', { chat_id: chatId, media, ...extra });
289 }
290 /**
291 * Send a native poll.
292 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
293 * @param question Poll question, 1-255 characters
294 * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
295 */
296 sendPoll(chatId, question, options, extra) {
297 return this.callApi('sendPoll', {
298 chat_id: chatId,
299 type: 'regular',
300 question,
301 options,
302 ...extra,
303 });
304 }
305 /**
306 * Send a native quiz.
307 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
308 * @param question Poll question, 1-255 characters
309 * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
310 */
311 sendQuiz(chatId, question, options, extra) {
312 return this.callApi('sendPoll', {
313 chat_id: chatId,
314 type: 'quiz',
315 question,
316 options,
317 ...extra,
318 });
319 }
320 /**
321 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
322 * @param messageId Identifier of the original message with the poll
323 */
324 stopPoll(chatId, messageId, extra) {
325 return this.callApi('stopPoll', {
326 chat_id: chatId,
327 message_id: messageId,
328 ...extra,
329 });
330 }
331 /**
332 * 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.).
333 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
334 */
335 getChat(chatId) {
336 return this.callApi('getChat', { chat_id: chatId });
337 }
338 /**
339 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
340 */
341 getChatAdministrators(chatId) {
342 return this.callApi('getChatAdministrators', { chat_id: chatId });
343 }
344 /**
345 * Get information about a member of a chat.
346 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
347 * @param userId Unique identifier of the target user
348 */
349 getChatMember(chatId, userId) {
350 return this.callApi('getChatMember', { chat_id: chatId, user_id: userId });
351 }
352 /**
353 * Get the number of members in a chat.
354 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
355 */
356 getChatMembersCount(chatId) {
357 return this.callApi('getChatMembersCount', { chat_id: chatId });
358 }
359 /**
360 * Send answers to an inline query.
361 * No more than 50 results per query are allowed.
362 */
363 answerInlineQuery(inlineQueryId, results, extra) {
364 return this.callApi('answerInlineQuery', {
365 inline_query_id: inlineQueryId,
366 results,
367 ...extra,
368 });
369 }
370 setChatPermissions(chatId, permissions, extra) {
371 return this.callApi('setChatPermissions', {
372 chat_id: chatId,
373 permissions,
374 ...extra,
375 });
376 }
377 /**
378 * 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.
379 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
380 * @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
381 */
382 banChatMember(chatId, userId, untilDate, extra) {
383 return this.callApi('banChatMember', {
384 chat_id: chatId,
385 user_id: userId,
386 until_date: untilDate,
387 ...extra,
388 });
389 }
390 /**
391 * 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.
392 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
393 * @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
394 * @deprecated since API 5.3. Use {@link Telegram.banChatMember}
395 */
396 get kickChatMember() {
397 return this.banChatMember;
398 }
399 /**
400 * 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.
401 * @param chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
402 */
403 promoteChatMember(chatId, userId, extra) {
404 return this.callApi('promoteChatMember', {
405 chat_id: chatId,
406 user_id: userId,
407 ...extra,
408 });
409 }
410 /**
411 * 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.
412 * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
413 */
414 restrictChatMember(chatId, userId, extra) {
415 return this.callApi('restrictChatMember', {
416 chat_id: chatId,
417 user_id: userId,
418 ...extra,
419 });
420 }
421 setChatAdministratorCustomTitle(chatId, userId, title) {
422 return this.callApi('setChatAdministratorCustomTitle', {
423 chat_id: chatId,
424 user_id: userId,
425 custom_title: title,
426 });
427 }
428 /**
429 * 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.
430 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
431 */
432 exportChatInviteLink(chatId) {
433 return this.callApi('exportChatInviteLink', { chat_id: chatId });
434 }
435 createChatInviteLink(chatId, extra) {
436 return this.callApi('createChatInviteLink', {
437 chat_id: chatId,
438 ...extra,
439 });
440 }
441 createInvoiceLink(invoice) {
442 return this.callApi('createInvoiceLink', {
443 ...invoice,
444 });
445 }
446 editChatInviteLink(chatId, inviteLink, extra) {
447 return this.callApi('editChatInviteLink', {
448 chat_id: chatId,
449 invite_link: inviteLink,
450 ...extra,
451 });
452 }
453 revokeChatInviteLink(chatId, inviteLink) {
454 return this.callApi('revokeChatInviteLink', {
455 chat_id: chatId,
456 invite_link: inviteLink,
457 });
458 }
459 setChatPhoto(chatId, photo) {
460 return this.callApi('setChatPhoto', { chat_id: chatId, photo });
461 }
462 deleteChatPhoto(chatId) {
463 return this.callApi('deleteChatPhoto', { chat_id: chatId });
464 }
465 /**
466 * 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.
467 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
468 * @param title New chat title, 1-255 characters
469 */
470 setChatTitle(chatId, title) {
471 return this.callApi('setChatTitle', { chat_id: chatId, title });
472 }
473 setChatDescription(chatId, description) {
474 return this.callApi('setChatDescription', { chat_id: chatId, description });
475 }
476 /**
477 * 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.
478 * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
479 */
480 pinChatMessage(chatId, messageId, extra) {
481 return this.callApi('pinChatMessage', {
482 chat_id: chatId,
483 message_id: messageId,
484 ...extra,
485 });
486 }
487 /**
488 * 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.
489 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
490 */
491 unpinChatMessage(chatId, messageId) {
492 return this.callApi('unpinChatMessage', {
493 chat_id: chatId,
494 message_id: messageId,
495 });
496 }
497 /**
498 * Clear the list of pinned messages in a chat.
499 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
500 */
501 unpinAllChatMessages(chatId) {
502 return this.callApi('unpinAllChatMessages', { chat_id: chatId });
503 }
504 /**
505 * Use this method for your bot to leave a group, supergroup or channel.
506 * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
507 */
508 leaveChat(chatId) {
509 return this.callApi('leaveChat', { chat_id: chatId });
510 }
511 /**
512 * 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.
513 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
514 * @param userId Unique identifier of the target user
515 */
516 unbanChatMember(chatId, userId, extra) {
517 return this.callApi('unbanChatMember', {
518 chat_id: chatId,
519 user_id: userId,
520 ...extra,
521 });
522 }
523 answerCbQuery(callbackQueryId, text, extra) {
524 return this.callApi('answerCallbackQuery', {
525 text,
526 callback_query_id: callbackQueryId,
527 ...extra,
528 });
529 }
530 answerGameQuery(callbackQueryId, url) {
531 return this.callApi('answerCallbackQuery', {
532 url,
533 callback_query_id: callbackQueryId,
534 });
535 }
536 /**
537 * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified,
538 * the Bot API will send an Update with a shipping_query field to the bot.
539 * Reply to shipping queries.
540 * @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)
541 * @param shippingOptions Required if ok is True. A JSON-serialized array of available shipping options.
542 * @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.
543 */
544 answerShippingQuery(shippingQueryId, ok, shippingOptions, errorMessage) {
545 return this.callApi('answerShippingQuery', {
546 ok,
547 shipping_query_id: shippingQueryId,
548 shipping_options: shippingOptions,
549 error_message: errorMessage,
550 });
551 }
552 /**
553 * 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.
554 * Respond to such pre-checkout queries. On success, True is returned.
555 * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
556 * @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.
557 * @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.
558 */
559 answerPreCheckoutQuery(preCheckoutQueryId, ok, errorMessage) {
560 return this.callApi('answerPreCheckoutQuery', {
561 ok,
562 pre_checkout_query_id: preCheckoutQueryId,
563 error_message: errorMessage,
564 });
565 }
566 answerWebAppQuery(webAppQueryId, result) {
567 return this.callApi('answerWebAppQuery', {
568 web_app_query_id: webAppQueryId,
569 result,
570 });
571 }
572 /**
573 * Edit text and game messages sent by the bot or via the bot (for inline bots).
574 * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
575 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
576 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
577 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
578 * @param text New text of the message
579 */
580 editMessageText(chatId, messageId, inlineMessageId, text, extra) {
581 const t = format_1.FmtString.normalise(text);
582 return this.callApi('editMessageText', {
583 chat_id: chatId,
584 message_id: messageId,
585 inline_message_id: inlineMessageId,
586 ...extra,
587 ...t,
588 });
589 }
590 /**
591 * Edit captions of messages sent by the bot or via the bot (for inline bots).
592 * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
593 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
594 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
595 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
596 * @param caption New caption of the message
597 * @param markup A JSON-serialized object for an inline keyboard.
598 */
599 editMessageCaption(chatId, messageId, inlineMessageId, caption, extra) {
600 return this.callApi('editMessageCaption', {
601 chat_id: chatId,
602 message_id: messageId,
603 inline_message_id: inlineMessageId,
604 ...extra,
605 ...(0, util_1.fmtCaption)({ caption }),
606 });
607 }
608 /**
609 * Edit animation, audio, document, photo, or video messages.
610 * If a message is a part of a message album, then it can be edited only to a photo or a video.
611 * Otherwise, message type can be changed arbitrarily.
612 * When inline message is edited, new file can't be uploaded.
613 * Use previously uploaded file via its file_id or specify a URL.
614 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
615 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
616 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
617 * @param media New media of message
618 * @param markup Markup of inline keyboard
619 */
620 editMessageMedia(chatId, messageId, inlineMessageId, media, extra) {
621 return this.callApi('editMessageMedia', {
622 chat_id: chatId,
623 message_id: messageId,
624 inline_message_id: inlineMessageId,
625 media: (0, util_1.fmtCaption)(media),
626 ...extra,
627 });
628 }
629 /**
630 * Edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
631 * @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
632 * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
633 * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
634 * @param markup A JSON-serialized object for an inline keyboard.
635 * @returns If edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
636 */
637 editMessageReplyMarkup(chatId, messageId, inlineMessageId, markup) {
638 return this.callApi('editMessageReplyMarkup', {
639 chat_id: chatId,
640 message_id: messageId,
641 inline_message_id: inlineMessageId,
642 reply_markup: markup,
643 });
644 }
645 editMessageLiveLocation(chatId, messageId, inlineMessageId, latitude, longitude, extra) {
646 return this.callApi('editMessageLiveLocation', {
647 latitude,
648 longitude,
649 chat_id: chatId,
650 message_id: messageId,
651 inline_message_id: inlineMessageId,
652 ...extra,
653 });
654 }
655 stopMessageLiveLocation(chatId, messageId, inlineMessageId, markup) {
656 return this.callApi('stopMessageLiveLocation', {
657 chat_id: chatId,
658 message_id: messageId,
659 inline_message_id: inlineMessageId,
660 reply_markup: markup,
661 });
662 }
663 /**
664 * Delete a message, including service messages, with the following limitations:
665 * - A message can only be deleted if it was sent less than 48 hours ago.
666 * - Bots can delete outgoing messages in groups and supergroups.
667 * - Bots granted can_post_messages permissions can delete outgoing messages in channels.
668 * - If the bot is an administrator of a group, it can delete any message there.
669 * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
670 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
671 */
672 deleteMessage(chatId, messageId) {
673 return this.callApi('deleteMessage', {
674 chat_id: chatId,
675 message_id: messageId,
676 });
677 }
678 setChatStickerSet(chatId, setName) {
679 return this.callApi('setChatStickerSet', {
680 chat_id: chatId,
681 sticker_set_name: setName,
682 });
683 }
684 deleteChatStickerSet(chatId) {
685 return this.callApi('deleteChatStickerSet', { chat_id: chatId });
686 }
687 /**
688 * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.
689 * Requires no parameters. Returns an Array of Sticker objects.
690 *
691 * @see https://core.telegram.org/bots/api#getforumtopiciconstickers
692 */
693 getForumTopicIconStickers() {
694 return this.callApi('getForumTopicIconStickers', {});
695 }
696 /**
697 * Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this
698 * to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a
699 * ForumTopic object.
700 *
701 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
702 * @param name Topic name, 1-128 characters
703 *
704 * @see https://core.telegram.org/bots/api#createforumtopic
705 */
706 createForumTopic(chat_id, name, extra) {
707 return this.callApi('createForumTopic', {
708 chat_id,
709 name,
710 ...extra,
711 });
712 }
713 /**
714 * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in
715 * the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the
716 * topic. Returns True on success.
717 *
718 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
719 * @param message_thread_id Unique identifier for the target message thread of the forum topic
720 *
721 * @see https://core.telegram.org/bots/api#editforumtopic
722 */
723 editForumTopic(chat_id, message_thread_id, extra) {
724 return this.callApi('editForumTopic', {
725 chat_id,
726 message_thread_id,
727 ...extra,
728 });
729 }
730 /**
731 * Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat
732 * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
733 * Returns True on success.
734 *
735 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
736 * @param message_thread_id Unique identifier for the target message thread of the forum topic
737 *
738 * @see https://core.telegram.org/bots/api#closeforumtopic
739 */
740 closeForumTopic(chat_id, message_thread_id) {
741 return this.callApi('closeForumTopic', {
742 chat_id,
743 message_thread_id,
744 });
745 }
746 /**
747 * Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat
748 * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
749 * Returns True on success.
750 *
751 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
752 * @param message_thread_id Unique identifier for the target message thread of the forum topic
753 *
754 * @see https://core.telegram.org/bots/api#reopenforumtopic
755 */
756 reopenForumTopic(chat_id, message_thread_id) {
757 return this.callApi('reopenForumTopic', {
758 chat_id,
759 message_thread_id,
760 });
761 }
762 /**
763 * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an
764 * administrator in the chat for this to work and must have the can_delete_messages administrator rights.
765 * Returns True on success.
766 *
767 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
768 * @param message_thread_id Unique identifier for the target message thread of the forum topic
769 *
770 * @see https://core.telegram.org/bots/api#deleteforumtopic
771 */
772 deleteForumTopic(chat_id, message_thread_id) {
773 return this.callApi('deleteForumTopic', {
774 chat_id,
775 message_thread_id,
776 });
777 }
778 /**
779 * Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat
780 * for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
781 *
782 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
783 * @param message_thread_id Unique identifier for the target message thread of the forum topic
784 *
785 * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
786 */
787 unpinAllForumTopicMessages(chat_id, message_thread_id) {
788 return this.callApi('unpinAllForumTopicMessages', {
789 chat_id,
790 message_thread_id,
791 });
792 }
793 /**
794 * Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator
795 * in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
796 *
797 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
798 * @param name New topic name, 1-128 characters
799 *
800 * @see https://core.telegram.org/bots/api#editgeneralforumtopic
801 */
802 editGeneralForumTopic(chat_id, name) {
803 return this.callApi('editGeneralForumTopic', { chat_id, name });
804 }
805 /**
806 * Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the
807 * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
808 *
809 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
810 *
811 * @see https://core.telegram.org/bots/api#closegeneralforumtopic
812 */
813 closeGeneralForumTopic(chat_id) {
814 return this.callApi('closeGeneralForumTopic', { chat_id });
815 }
816 /**
817 * Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in
818 * the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically
819 * unhidden if it was hidden. Returns True on success.
820 *
821 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
822 *
823 * @see https://core.telegram.org/bots/api#reopengeneralforumtopic
824 */
825 reopenGeneralForumTopic(chat_id) {
826 return this.callApi('reopenGeneralForumTopic', { chat_id });
827 }
828 /**
829 * Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat
830 * for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed
831 * if it was open. Returns True on success.
832 *
833 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
834 *
835 * @see https://core.telegram.org/bots/api#hidegeneralforumtopic
836 */
837 hideGeneralForumTopic(chat_id) {
838 return this.callApi('hideGeneralForumTopic', { chat_id });
839 }
840 /**
841 * Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the
842 * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
843 *
844 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
845 *
846 * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic
847 */
848 unhideGeneralForumTopic(chat_id) {
849 return this.callApi('unhideGeneralForumTopic', { chat_id });
850 }
851 /**
852 * Use this method to clear the list of pinned messages in a General forum topic.
853 * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator
854 * right in the supergroup.
855 *
856 * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
857 */
858 unpinAllGeneralForumTopicMessages(chat_id) {
859 return this.callApi('unpinAllGeneralForumTopicMessages', { chat_id });
860 }
861 getStickerSet(name) {
862 return this.callApi('getStickerSet', { name });
863 }
864 /**
865 * Upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).
866 * https://core.telegram.org/bots/api#sending-files
867 * @param ownerId User identifier of sticker file owner
868 * @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.
869 */
870 uploadStickerFile(ownerId, sticker, sticker_format) {
871 return this.callApi('uploadStickerFile', {
872 user_id: ownerId,
873 sticker_format,
874 sticker,
875 });
876 }
877 /**
878 * Create new sticker set owned by a user. The bot will be able to edit the created sticker set.
879 * @param ownerId User identifier of created sticker set owner
880 * @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.
881 * @param title Sticker set title, 1-64 characters
882 */
883 createNewStickerSet(ownerId, name, title, stickerData) {
884 return this.callApi('createNewStickerSet', {
885 name,
886 title,
887 user_id: ownerId,
888 ...stickerData,
889 });
890 }
891 /**
892 * Add a new sticker to a set created by the bot.
893 * @param ownerId User identifier of sticker set owner
894 * @param name Sticker set name
895 */
896 addStickerToSet(ownerId, name, stickerData) {
897 return this.callApi('addStickerToSet', {
898 name,
899 user_id: ownerId,
900 ...stickerData,
901 });
902 }
903 /**
904 * Move a sticker in a set created by the bot to a specific position.
905 * @param sticker File identifier of the sticker
906 * @param position New sticker position in the set, zero-based
907 */
908 setStickerPositionInSet(sticker, position) {
909 return this.callApi('setStickerPositionInSet', {
910 sticker,
911 position,
912 });
913 }
914 /**
915 * @deprecated since API 6.8. Use {@link Telegram.setStickerSetThumbnail}
916 */
917 get setStickerSetThumb() {
918 return this.setStickerSetThumbnail;
919 }
920 /**
921 * Use this method to set the thumbnail of a regular or mask sticker set.
922 * The format of the thumbnail file must match the format of the stickers in the set.
923 * @param name Sticker set name
924 * @param userId User identifier of the sticker set owner
925 * @param thumbnail A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size
926 * and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to
927 * 32 kilobytes in size (see
928 * [animated sticker technical requirements](https://core.telegram.org/stickers#animated-sticker-requirements)),
929 * or a WEBM video with the thumbnail up to 32 kilobytes in size; see
930 * [video sticker technical requirements](https://core.telegram.org/stickers#video-sticker-requirements).
931 * Pass a file_id as a String to send a file that already exists on the Telegram servers, pass a
932 * HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using
933 * Input helpers. Animated and video sticker set thumbnails can't be uploaded via HTTP URL.
934 * If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
935 */
936 setStickerSetThumbnail(name, userId, thumbnail) {
937 return this.callApi('setStickerSetThumbnail', {
938 name,
939 user_id: userId,
940 thumbnail,
941 });
942 }
943 setStickerMaskPosition(sticker, mask_position) {
944 return this.callApi('setStickerMaskPosition', { sticker, mask_position });
945 }
946 setStickerKeywords(sticker, keywords) {
947 return this.callApi('setStickerKeywords', { sticker, keywords });
948 }
949 setStickerEmojiList(sticker, emoji_list) {
950 return this.callApi('setStickerEmojiList', { sticker, emoji_list });
951 }
952 deleteStickerSet(name) {
953 return this.callApi('deleteStickerSet', { name });
954 }
955 setStickerSetTitle(name, title) {
956 return this.callApi('setStickerSetTitle', { name, title });
957 }
958 setCustomEmojiStickerSetThumbnail(name, custom_emoji_id) {
959 return this.callApi('setCustomEmojiStickerSetThumbnail', {
960 name,
961 custom_emoji_id,
962 });
963 }
964 /**
965 * Delete a sticker from a set created by the bot.
966 * @param sticker File identifier of the sticker
967 */
968 deleteStickerFromSet(sticker) {
969 return this.callApi('deleteStickerFromSet', { sticker });
970 }
971 getCustomEmojiStickers(custom_emoji_ids) {
972 return this.callApi('getCustomEmojiStickers', { custom_emoji_ids });
973 }
974 /**
975 * Change the list of the bot's commands.
976 * @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.
977 */
978 setMyCommands(commands, extra) {
979 return this.callApi('setMyCommands', { commands, ...extra });
980 }
981 deleteMyCommands(extra = {}) {
982 return this.callApi('deleteMyCommands', extra);
983 }
984 /**
985 * Get the current list of the bot's commands.
986 */
987 getMyCommands(extra = {}) {
988 return this.callApi('getMyCommands', extra);
989 }
990 /**
991 * Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
992 * @param description New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
993 * @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.
994 */
995 setMyDescription(description, language_code) {
996 return this.callApi('setMyDescription', { description, language_code });
997 }
998 /**
999 * Use this method to change the bot's name.
1000 * @param name New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
1001 * @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.
1002 */
1003 setMyName(name, language_code) {
1004 return this.callApi('setMyName', { name, language_code });
1005 }
1006 /**
1007 * Use this method to get the current bot name for the given user language.
1008 * @param language_code A two-letter ISO 639-1 language code or an empty string
1009 */
1010 getMyName(language_code) {
1011 return this.callApi('getMyName', { language_code });
1012 }
1013 /**
1014 * Use this method to get the current bot description for the given user language.
1015 * @param language_code A two-letter ISO 639-1 language code.
1016 */
1017 getMyDescription(language_code) {
1018 return this.callApi('getMyDescription', { language_code });
1019 }
1020 /**
1021 * 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.
1022 * @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.
1023 * @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.
1024 */
1025 setMyShortDescription(short_description, language_code) {
1026 return this.callApi('setMyShortDescription', {
1027 short_description,
1028 language_code,
1029 });
1030 }
1031 /**
1032 * Use this method to get the current bot short description for the given user language.
1033 * @param language_code A two-letter ISO 639-1 language code or an empty string
1034 */
1035 getMyShortDescription(language_code) {
1036 return this.callApi('getMyShortDescription', { language_code });
1037 }
1038 setPassportDataErrors(userId, errors) {
1039 return this.callApi('setPassportDataErrors', {
1040 user_id: userId,
1041 errors: errors,
1042 });
1043 }
1044 /**
1045 * Send copy of existing message.
1046 * @deprecated use `copyMessage` instead
1047 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1048 * @param message Received message object
1049 */
1050 sendCopy(chatId, message, extra) {
1051 return this.copyMessage(chatId, message.chat.id, message.message_id, extra);
1052 }
1053 /**
1054 * Send copy of existing message.
1055 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1056 * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
1057 * @param messageId Message identifier in the chat specified in from_chat_id
1058 */
1059 copyMessage(chatId, fromChatId, messageId, extra) {
1060 return this.callApi('copyMessage', {
1061 chat_id: chatId,
1062 from_chat_id: fromChatId,
1063 message_id: messageId,
1064 ...(0, util_1.fmtCaption)(extra),
1065 });
1066 }
1067 /**
1068 * Approve a chat join request.
1069 * The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
1070 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1071 * @param userId Unique identifier of the target user
1072 */
1073 approveChatJoinRequest(chatId, userId) {
1074 return this.callApi('approveChatJoinRequest', {
1075 chat_id: chatId,
1076 user_id: userId,
1077 });
1078 }
1079 /**
1080 * Decline a chat join request.
1081 * The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
1082 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1083 * @param userId Unique identifier of the target user
1084 */
1085 declineChatJoinRequest(chatId, userId) {
1086 return this.callApi('declineChatJoinRequest', {
1087 chat_id: chatId,
1088 user_id: userId,
1089 });
1090 }
1091 /**
1092 * 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.
1093 * The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
1094 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1095 * @param senderChatId Unique identifier of the target sender chat
1096 */
1097 banChatSenderChat(chatId, senderChatId, extra) {
1098 return this.callApi('banChatSenderChat', {
1099 chat_id: chatId,
1100 sender_chat_id: senderChatId,
1101 ...extra,
1102 });
1103 }
1104 /**
1105 * Unban a previously banned channel chat in a supergroup or channel.
1106 * The bot must be an administrator for this to work and must have the appropriate administrator rights.
1107 * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1108 * @param senderChatId Unique identifier of the target sender chat
1109 */
1110 unbanChatSenderChat(chatId, senderChatId) {
1111 return this.callApi('unbanChatSenderChat', {
1112 chat_id: chatId,
1113 sender_chat_id: senderChatId,
1114 });
1115 }
1116 /**
1117 * Use this method to change the bot's menu button in a private chat, or the default menu button. Returns true on success.
1118 * @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be changed.
1119 * @param menuButton An object for the bot's new menu button.
1120 */
1121 setChatMenuButton({ chatId, menuButton, } = {}) {
1122 return this.callApi('setChatMenuButton', {
1123 chat_id: chatId,
1124 menu_button: menuButton,
1125 });
1126 }
1127 /**
1128 * 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.
1129 * @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be returned.
1130 */
1131 getChatMenuButton({ chatId } = {}) {
1132 return this.callApi('getChatMenuButton', {
1133 chat_id: chatId,
1134 });
1135 }
1136 /**
1137 * Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
1138 * These rights will be suggested to users, but they are are free to modify the list before adding the bot.
1139 */
1140 setMyDefaultAdministratorRights({ rights, forChannels, } = {}) {
1141 return this.callApi('setMyDefaultAdministratorRights', {
1142 rights,
1143 for_channels: forChannels,
1144 });
1145 }
1146 /**
1147 * Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
1148 * @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.
1149 */
1150 getMyDefaultAdministratorRights({ forChannels, } = {}) {
1151 return this.callApi('getMyDefaultAdministratorRights', {
1152 for_channels: forChannels,
1153 });
1154 }
1155 /**
1156 * Log out from the cloud Bot API server before launching the bot locally.
1157 */
1158 logOut() {
1159 return this.callApi('logOut', {});
1160 }
1161 /**
1162 * Close the bot instance before moving it from one local server to another.
1163 */
1164 close() {
1165 return this.callApi('close', {});
1166 }
1167}
1168exports.Telegram = Telegram;
1169exports.default = Telegram;