UNPKG

typescript-telegram-bot-api

Version:

Telegram Bot API wrapper for Node.js written in TypeScript

1,078 lines 73.8 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TelegramBot = exports.FileOptions = void 0; const events_1 = require("events"); const axios_1 = __importDefault(require("axios")); const form_data_1 = __importDefault(require("form-data")); const util_1 = require("util"); const stream_1 = require("stream"); const errors_1 = require("./errors"); const polling_1 = require("./polling"); const wait = (0, util_1.promisify)(setTimeout); /** * A class for serializing objects into JSON format. * Used to mark objects that need to be serialized in a special way, preserving nested files in a specific manner. */ class JSONSerialized { constructor(value) { this.value = value; } } /** * A class for wrapping files or buffers, intended for use when sending files in requests. * Allows you to specify additional file parameters. */ class FileOptions { constructor(file, options) { this.file = file; this.options = options; } } exports.FileOptions = FileOptions; class TelegramBot extends events_1.EventEmitter { constructor(options) { super(); this.testEnvironment = options.testEnvironment || false; this.botToken = options.botToken; this.baseURL = options.baseURL || 'https://api.telegram.org'; this.autoRetry = options.autoRetry ?? true; this.autoRetryLimit = options.autoRetryLimit || 0; this.allowedUpdates = options.allowedUpdates || []; this.pollingTimeout = options.pollingTimeout || 50; this.polling = new polling_1.Polling(this); } static isTelegramError(error) { return error instanceof errors_1.TelegramError; } async startPolling() { await this.polling.start(); } async stopPolling() { await this.polling.stop(); } async request(url, options, abortController) { const formData = this.createFormData(options); const response = await (0, axios_1.default)({ method: 'POST', url, data: formData, signal: abortController?.signal, responseType: 'text', transitional: { silentJSONParsing: false, forcedJSONParsing: false, }, validateStatus: () => true, }); try { return JSON.parse(response.data.toString()); } catch (error) { throw new Error(`Invalid response`); } } serializeJSON(value, formData) { if (value instanceof File || value instanceof Buffer || value instanceof stream_1.Readable || value instanceof FileOptions) { const name = Math.random().toString(36).substring(7); formData.append(name, value instanceof FileOptions ? value.file : value, value instanceof Buffer ? 'file' : value instanceof FileOptions ? value.options : undefined); return `attach://${name}`; } else if (Array.isArray(value)) { return value.map((item) => this.serializeJSON(item, formData)); } else if (typeof value === 'object' && value !== null) { const result = {}; for (const [key, val] of Object.entries(value)) { result[key] = this.serializeJSON(val, formData); } return result; } else { return value; } } handleObject(object, formData) { for (const [key, value] of Object.entries(object)) { if (value === undefined) { // Skip undefined values } else if (typeof value === 'boolean') { formData.append(key, String(value)); } else if (value instanceof JSONSerialized) { const json = JSON.stringify(this.serializeJSON(value.value, formData)); if (json !== undefined) formData.append(key, json); } else if (value instanceof FileOptions) { formData.append(key, value.file, value.options); } else if (value instanceof Buffer) { formData.append(key, value, 'file'); } else if (value instanceof File || value instanceof stream_1.Readable) { formData.append(key, value); } else if (typeof value === 'object' && value !== null && !(value instanceof Date)) { formData.append(key, JSON.stringify(this.serializeJSON(value, formData))); } else { formData.append(key, value); } } } createFormData(options) { const formData = new form_data_1.default(); if (options) { this.handleObject(options, formData); } else { formData.append('empty', 'empty'); } return formData; } async callApi(method, options, abortController) { const url = `${this.baseURL}/bot${this.botToken}${this.testEnvironment ? '/test' : ''}/${method}`; const response = await this.request(url, options, abortController); if (response.ok) { return response.result; } else { const error = response; if (this.autoRetry && error.parameters?.retry_after && error.parameters?.retry_after < this.autoRetryLimit) { await wait(error.parameters.retry_after * 1000); return await this.callApi(method, options); } else { throw new errors_1.TelegramError(error); } } } async processUpdate(update) { this.polling.emitUpdate(update); } /** * ## getUpdates * Use this method to receive incoming updates using long polling [wiki](https://en.wikipedia.org/wiki/Push_technology#Long_polling). Returns an Array of Update objects. * @see https://core.telegram.org/bots/api#getupdates */ async getUpdates(options, abortController) { return await this.callApi('getUpdates', { ...options, allowed_updates: new JSONSerialized(options?.allowed_updates), }, abortController); } /** * ## setWebhook * Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update * for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case * of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success. * * If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter * ```secret_token```. If specified, the request will contain a header ```“X-Telegram-Bot-Api-Secret-Token”``` with * the secret token as content. * @see https://core.telegram.org/bots/api#setwebhook */ async setWebhook(options) { return await this.callApi('setWebhook', { ...options, allowed_updates: new JSONSerialized(options?.allowed_updates), }); } /** * ## deleteWebhook * Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. * @see https://core.telegram.org/bots/api#deletewebhook */ async deleteWebhook(options) { return await this.callApi('deleteWebhook', options); } /** * ## getWebhookInfo * Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. * If the bot is using getUpdates, will return an object with the url field empty. * @see https://core.telegram.org/bots/api#getwebhookinfo */ async getWebhookInfo() { return await this.callApi('getWebhookInfo'); } /** * ## getMe * A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information * about the bot in form of a User object. * @see https://core.telegram.org/bots/api#getme */ async getMe() { return await this.callApi('getMe'); } /** * ## logOut * Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot * before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful * call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server * for 10 minutes. Returns True on success. Requires no parameters. * @see https://core.telegram.org/bots/api#logout */ async logOut() { return await this.callApi('logOut'); } /** * ## close * Use this method to close the bot instance before moving it from one local server to another. You need to delete the * webhook before calling this method to ensure that the bot isn't launched again after server restart. The method * will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no * parameters. * @see https://core.telegram.org/bots/api#close */ async close() { return await this.callApi('close'); } /** * ## sendMessage * Use this method to send text messages. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendmessage */ async sendMessage(options) { return await this.callApi('sendMessage', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## forwardMessage * Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or * forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album * grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned. * @see https://core.telegram.org/bots/api#forwardmessage */ async forwardMessage(options) { return await this.callApi('forwardMessage', options); } /** * ## forwardMessages * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are * skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages * can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. * The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original * message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is * returned. * @see https://core.telegram.org/bots/api#forwardmessages */ async forwardMessages(options) { return await this.callApi('forwardMessages', { ...options, message_ids: new JSONSerialized(options.message_ids), }); } /** * ## copyMessage * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway * winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field * correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message * doesn't have a link to the original message. Returns the MessageId of the sent message on success. * @see https://core.telegram.org/bots/api#copymessage */ async copyMessage(options) { return await this.callApi('copyMessage', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## copyMessages * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are * skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A * quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is * analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album * grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. * @see https://core.telegram.org/bots/api#copymessages */ async copyMessages(options) { return await this.callApi('copyMessages', { ...options, message_ids: new JSONSerialized(options.message_ids), }); } /** * ## sendPhoto * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are * skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A * quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is * analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album * grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. * @see https://core.telegram.org/bots/api#sendphoto */ async sendPhoto(options) { return await this.callApi('sendPhoto', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendAudio * Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio * must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files * of up to 50 MB in size, this limit may be changed in the future. * * For sending voice messages, use the sendVoice method instead. * @see https://core.telegram.org/bots/api#sendaudio */ async sendAudio(options) { return await this.callApi('sendAudio', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** ## sendDocument * Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of * any type of up to 50 MB in size, this limit may be changed in the future. * @see https://core.telegram.org/bots/api#senddocument */ async sendDocument(options) { return await this.callApi('sendDocument', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendVideo * Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). * On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit * may be changed in the future. * @see https://core.telegram.org/bots/api#sendvideo */ async sendVideo(options) { return await this.callApi('sendVideo', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendAnimation * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message * is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the * future. * @see https://core.telegram.org/bots/api#sendanimation */ async sendAnimation(options) { return await this.callApi('sendAnimation', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendVoice * Use this method to 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, or in .MP3 format, or in .M4A format (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. * @see https://core.telegram.org/bots/api#sendvoice */ async sendVoice(options) { return await this.callApi('sendVoice', { ...options, caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendVideoNote * As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send * video messages. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendvideonote */ async sendVideoNote(options) { return await this.callApi('sendVideoNote', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendPaidMedia * Use this method to send paid media to channel chats. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendpaidmedia */ async sendPaidMedia(options) { return await this.callApi('sendPaidMedia', { ...options, media: new JSONSerialized(options.media), caption_entities: new JSONSerialized(options.caption_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendMediaGroup * Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can * be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is * returned. * @see https://core.telegram.org/bots/api#sendmediagroup */ async sendMediaGroup(options) { return await this.callApi('sendMediaGroup', { ...options, media: new JSONSerialized(options.media), }); } /** * ## sendLocation * Use this method to send point on the map. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendlocation */ async sendLocation(options) { return await this.callApi('sendLocation', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendVenue * Use this method to send information about a venue. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendvenue */ async sendVenue(options) { return await this.callApi('sendVenue', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendContact * Use this method to send phone contacts. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendcontact */ async sendContact(options) { return await this.callApi('sendContact', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendPoll * se this method to send a native poll. On success, the sent Message is returned. * @see https://core.telegram.org/bots/api#sendpoll */ async sendPoll(options) { return await this.callApi('sendPoll', { ...options, options: new JSONSerialized(options.options), explanation_entities: new JSONSerialized(options.explanation_entities), reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendDice * Use this method to send an animated emoji that will display a random value. On success, the sent Message is * returned. * @see https://core.telegram.org/bots/api#senddice */ async sendDice(options) { return await this.callApi('sendDice', { ...options, reply_markup: new JSONSerialized(options.reply_markup), }); } /** * ## sendChatAction * Use this method when you need to tell the user that something is happening on the bot's side. The status is set for * 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on * success. * @see https://core.telegram.org/bots/api#sendchataction */ async sendChatAction(options) { return await this.callApi('sendChatAction', options); } /** * ## setMessageReaction * Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically * forwarded messages from a channel to its discussion group have the same available reactions as messages in the * channel. Returns True on success. * @see https://core.telegram.org/bots/api#setmessagereaction */ async setMessageReaction(options) { return await this.callApi('setMessageReaction', { ...options, reaction: new JSONSerialized(options.reaction), }); } /** * ## getUserProfilePhotos * Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. * @see https://core.telegram.org/bots/api#getuserprofilephotos */ async getUserProfilePhotos(options) { return await this.callApi('getUserProfilePhotos', options); } /** * ## setUserEmojiStatus * Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the * Mini App method requestEmojiStatusAccess. Returns True on success. * @see https://core.telegram.org/bots/api#setuseremojistatus */ async setUserEmojiStatus(options) { return await this.callApi('setUserEmojiStatus', options); } /** * ## getFile * Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can * download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via * the link ```https://api.telegram.org/file/bot<token>/<file_path>```, where ```<file_path>``` is taken from the * response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be * requested by calling getFile again. * @see https://core.telegram.org/bots/api#getfile */ async getFile(options) { return await this.callApi('getFile', options); } /** * ## banChatMember * Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the * user will not be able to return to the chat 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 administrator rights. Returns * True on success. * @see https://core.telegram.org/bots/api#banchatmember */ async banChatMember(options) { return await this.callApi('banChatMember', options); } /** * ## unbanChatMember * Use this method to unban a previously banned user in a supergroup or channel. The user will not return to the group * or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to * work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able * to join it. So if the user is a member of the chat they will also be removed from the chat. If you don't want this, * use the parameter only_if_banned. Returns True on success. * @see https://core.telegram.org/bots/api#unbanchatmember */ async unbanChatMember(options) { return await this.callApi('unbanChatMember', options); } /** * ## restrictChatMember * Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to * work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a * user. Returns True on success. * @see https://core.telegram.org/bots/api#restrictchatmember */ async restrictChatMember(options) { return await this.callApi('restrictChatMember', { ...options, permissions: new JSONSerialized(options.permissions), }); } /** * ## promoteChatMember * Use this method to 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 administrator rights. Pass False for all boolean parameters to * demote a user. Returns True on success. * @see https://core.telegram.org/bots/api#promotechatmember */ async promoteChatMember(options) { return await this.callApi('promoteChatMember', options); } /** * ## setChatAdministratorCustomTitle * Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on * success. * @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle */ async setChatAdministratorCustomTitle(options) { return await this.callApi('setChatAdministratorCustomTitle', options); } /** * ## banChatSenderChat * Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the * banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator * in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on * \success. * @see https://core.telegram.org/bots/api#banchatsenderchat */ async banChatSenderChat(options) { return await this.callApi('banChatSenderChat', options); } /** * ## unbanChatSenderChat * Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an * administrator for this to work and must have the appropriate administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#unbanchatsenderchat */ async unbanChatSenderChat(options) { return await this.callApi('unbanChatSenderChat', options); } /** * ## setChatPermissions * Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an * administrator for this to work and must have the appropriate administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#setchatpermissions */ async setChatPermissions(options) { return await this.callApi('setChatPermissions', { ...options, permissions: new JSONSerialized(options.permissions), }); } /** * ## exportChatInviteLink * Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. * Returns the new invite link as String on success. * @see https://core.telegram.org/bots/api#exportchatinvitelink */ async exportChatInviteLink(options) { return await this.callApi('exportChatInviteLink', options); } /** * ## createChatSubscriptionInviteLink * Use this method to create a subscription invite link for a channel chat. The bot must have the `can_invite_users` * administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the * method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object. */ async createChatSubscriptionInviteLink(options) { return await this.callApi('createChatSubscriptionInviteLink', options); } /** * ## editChatSubscriptionInviteLink * Use this method to edit a subscription invite link created by the bot. The bot must have the `can_invite_users` * administrator rights. Returns the edited invite link as a ChatInviteLink object. */ async editChatSubscriptionInviteLink(options) { return await this.callApi('editChatSubscriptionInviteLink', options); } /** * ## createChatInviteLink * Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for * this to work and must have the appropriate administrator rights. The link can be revoked using the method * revokeChatInviteLink. Returns the new invite link as ChatInviteLink object. * @see https://core.telegram.org/bots/api#createchatinvitelink */ async createChatInviteLink(options) { return await this.callApi('createChatInviteLink', options); } /** * ## editChatInviteLink * Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat * for this to work and must have the appropriate administrator rights. Returns the edited invite link as a * ChatInviteLink object. * @see https://core.telegram.org/bots/api#editchatinvitelink */ async editChatInviteLink(options) { return await this.callApi('editChatInviteLink', options); } /** * ## revokeChatInviteLink * Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is * automatically generated. The bot must be an administrator in the chat for this to work and must have the * appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object. * @see https://core.telegram.org/bots/api#revokechatinvitelink */ async revokeChatInviteLink(options) { return await this.callApi('revokeChatInviteLink', options); } /** * ## approveChatJoinRequest * Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and * must have the can_invite_users administrator right. Returns True on success. * @see https://core.telegram.org/bots/api#approvechatjoinrequest */ async approveChatJoinRequest(options) { return await this.callApi('approveChatJoinRequest', options); } /** * ## declineChatJoinRequest * Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and * must have the can_invite_users administrator right. Returns True on success. * @see https://core.telegram.org/bots/api#declinechatjoinrequest */ async declineChatJoinRequest(options) { return await this.callApi('declineChatJoinRequest', options); } /** * ## setChatPhoto * Use this method to set a new profile photo for the chat. Photos 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 administrator rights. Returns True on * success. * @see https://core.telegram.org/bots/api#setchatphoto */ async setChatPhoto(options) { return await this.callApi('setChatPhoto', options); } /** * ## deleteChatPhoto * Use this method to delete a chat photo. Photos 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 administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#deletechatphoto */ async deleteChatPhoto(options) { return await this.callApi('deleteChatPhoto', options); } /** * ## setChatTitle * Use this method to 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 administrator rights. Returns True on * success. * @see https://core.telegram.org/bots/api#setchattitle */ async setChatTitle(options) { return await this.callApi('setChatTitle', options); } /** * ## setChatDescription * Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator * in the chat for this to work and must have the appropriate administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#setchatdescription */ async setChatDescription(options) { return await this.callApi('setChatDescription', options); } /** * ## pinChatMessage * Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the * bot must be an administrator in the chat for this to work and must have the ```'can_pin_messages'``` administrator * right in a supergroup or ```'can_edit_messages'``` administrator right in a channel. Returns True on success. * @see https://core.telegram.org/bots/api#pinchatmessage */ async pinChatMessage(options) { return await this.callApi('pinChatMessage', options); } /** * ## unpinChatMessage * Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, * the bot must be an administrator in the chat for this to work and must have the ```'can_pin_messages'``` * administrator right in a supergroup or ```'can_edit_messages'``` administrator right in a channel. Returns True on * success. * @see https://core.telegram.org/bots/api#unpinchatmessage */ async unpinChatMessage(options) { return await this.callApi('unpinChatMessage', options); } /** * ## unpinAllChatMessages * Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be * an administrator in the chat for this to work and must have the ```'can_pin_messages'``` administrator right in a * supergroup or ```'can_edit_messages'``` administrator right in a channel. Returns True on success. * @see https://core.telegram.org/bots/api#unpinallchatmessages */ async unpinAllChatMessages(options) { return await this.callApi('unpinAllChatMessages', options); } /** * ## leaveChat * Use this method for your bot to leave a group, supergroup or channel. Returns True on success. * @see https://core.telegram.org/bots/api#leavechat */ async leaveChat(options) { return await this.callApi('leaveChat', options); } /** * ## getChat * Use this method to get up-to-date information about the chat. Returns a ChatFullInfo object on success. * @see https://core.telegram.org/bots/api#getchat */ async getChat(options) { return await this.callApi('getChat', options); } /** * ## getChatAdministrators * Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of ChatMember * objects. * @see https://core.telegram.org/bots/api#getchatadministrators */ async getChatAdministrators(options) { return await this.callApi('getChatAdministrators', options); } /** * ## getChatMemberCount * Use this method to get the number of members in a chat. Returns Int on success. * @see https://core.telegram.org/bots/api#getchatmembercount */ async getChatMemberCount(options) { return await this.callApi('getChatMemberCount', options); } /** * ## getChatMember * Use this method to get information about a member of a chat. The method is only guaranteed to work for other users * if the bot is an administrator in the chat. Returns a ChatMember object on success. * @see https://core.telegram.org/bots/api#getchatmember */ async getChatMember(options) { return await this.callApi('getChatMember', options); } /** * ## setChatStickerSet * Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for * this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally * returned in getChat requests to check if the bot can use this method. Returns True on success. * @see https://core.telegram.org/bots/api#setchatstickerset */ async setChatStickerSet(options) { return await this.callApi('setChatStickerSet', options); } /** * ## deleteChatStickerSet * Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for * this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally * returned in getChat requests to check if the bot can use this method. Returns True on success. * @see https://core.telegram.org/bots/api#deletechatstickerset */ async deleteChatStickerSet(options) { return await this.callApi('deleteChatStickerSet', options); } /** * ## getForumTopicIconStickers * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no * parameters. Returns an Array of Sticker objects. * @see https://core.telegram.org/bots/api#getforumtopiciconstickers */ async getForumTopicIconStickers() { return await this.callApi('getForumTopicIconStickers', {}); } /** * ## createForumTopic * Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this * to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a * ForumTopic object. * @see https://core.telegram.org/bots/api#createforumtopic */ async createForumTopic(options) { return await this.callApi('createForumTopic', options); } /** * ## editForumTopic * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in * the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the * topic. Returns True on success. * @see https://core.telegram.org/bots/api#editforumtopic */ async editForumTopic(options) { return await this.callApi('editForumTopic', options); } /** * ## closeForumTopic * Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for * this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. * Returns True on success. * @see https://core.telegram.org/bots/api#closeforumtopic */ async closeForumTopic(options) { return await this.callApi('closeForumTopic', options); } /** * ## reopenForumTopic * Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. * Returns True on success. * @see https://core.telegram.org/bots/api#reopenforumtopic */ async reopenForumTopic(options) { return await this.callApi('reopenForumTopic', options); } /** * ## deleteForumTopic * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an * administrator in the chat for this to work and must have the can_delete_messages administrator rights. Returns True * on success. * @see https://core.telegram.org/bots/api#deleteforumtopic */ async deleteForumTopic(options) { return await this.callApi('deleteForumTopic', options); } /** * ## unpinAllForumTopicMessages * Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat * for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success. * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages */ async unpinAllForumTopicMessages(options) { return await this.callApi('unpinAllForumTopicMessages', options); } /** * ## editGeneralForumTopic * Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an * administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on * success. * @see https://core.telegram.org/bots/api#editgeneralforumtopic */ async editGeneralForumTopic(options) { return await this.callApi('editGeneralForumTopic', options); } /** * ## closeGeneralForumTopic * Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in * the chat for this to work and must have the ```can_manage_topics``` administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#closegeneralforumtopic */ async closeGeneralForumTopic(options) { return await this.callApi('closeGeneralForumTopic', options); } /** * ## reopenGeneralForumTopic * Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in * the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically * unhidden if it was hidden. Returns True on success. * @see https://core.telegram.org/bots/api#reopengeneralforumtopic */ async reopenGeneralForumTopic(options) { return await this.callApi('reopenGeneralForumTopic', options); } /** * ## hideGeneralForumTopic * Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the * chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically * closed if it was open. Returns True on success. * @see https://core.telegram.org/bots/api#hidegeneralforumtopic */ async hideGeneralForumTopic(options) { return await this.callApi('hideGeneralForumTopic', options); } /** * ## unhideGeneralForumTopic * Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success. * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic */ async unhideGeneralForumTopic(options) { return await this.callApi('unhideGeneralForumTopic', options); } /** * ## unpinAllGeneralForumTopicMessages * se this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in * the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on * success. * @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages */ async unpinAllGeneralForumTopicMessages(options) { return await this.callApi('unpinAllGeneralForumTopicMessages', options); } /** * ## answerCallbackQuery * Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the * user as a notification at the top of the chat screen or as an alert. On success, True is returned. * @see https://core.telegram.org/bots/api#answercallbackquery */ async answerCallbackQuery(options) { return await this.callApi('answerCallbackQuery', options); } /** * ## getUserChatBoosts * Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. * Returns a UserChatBoosts object. * @see https://core.telegram.org/bots/api#getuserchatboosts */ async getUserChatBoosts(options) { return await this.callApi('getUserChatBoosts', options); } /** * ## getBusinessConnection * Use this method to get information about the connection of the bot with a business account. Returns a * BusinessConnection object on success. * @see https://core.telegram.org/bots/api#getbusinessconnection */ async getBusinessConnection(options) { return await this.callApi('getBusinessConnection', options); } /** * ## setMyCommands * Use this method to change the list of the bot's commands. See this manual for more details about bot commands. * Returns True on success. * @see https://core.telegram.org/bots/api#setmycommands */ async setMyCommands(options) { return await this.callApi('setMyCommands', { ...options, commands: new JSONSerialized(options.commands), scope: new JSONSerialized(options.scope), }); } /** * ## deleteMyCommands * Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, * higher level commands will be shown to affected users. Returns True on success. * @see https://core.telegram.org/bots/api#deletemycommands */ async deleteMyCommands(options) { return await this.callApi('deleteMyCommands', { ...options, scope: new JSONSerialized(options?.scope), }); } /** * ## getMyCommands * Use this method to get the current list of the bot's commands for the given scope and user language. Returns an * Array of BotCommand objects. If commands aren't set, an empty list is returned. * @see https://core.telegram.org/bots/api#getmycommands */ async getMyCommands(options) { return await this.callApi('getMyCommands', { ...options, scope: new JSONSerialized(options?.scope), }); } /** * ## setMyName * Use this method to change the bot's name. Returns True on success. * @see https://core.telegram.org/bots/api#setmyname */ async setMyName(options) { return await this.callApi('setMyName', options); } /** * ## getMyName * Use this method to get the current bot name for the given user language. Returns BotName on success. * @see https://core.telegram.org/bots/api#getmyname */ async getMyName(options) { return await this.callApi('getMyName', options); } /** * ## setMyDescription * Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. * Returns True on success. * @see https://core.telegram.org/bots/api#setmydescription */ async setMyDescription(options) { return await this.callApi('setMyDescription', options); } /** * ## getMyDescription * Use this method to get the current bot description for the given user language. Returns BotDescription on success. * @see https://core.telegram.org/bots/api#getmydescription */ async getMyDescription(options) { return await this.callApi('getMyDescription', options); } /** * ## setMyShortDescription * 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. Returns True on success. * @see https://core.telegram.org/bots/api#setmyshortdescription */ async setMyShortDescription(options) { return await this.callApi('setMyShortDescription', options); } /** * ## getMyShortDescription * Use this method to get the current bot short description for the given user language. Returns BotShortDescription * on success. * @see https://core.telegram.org/bots/api#getmyshort