UNPKG

@xalbex/telegram-bot

Version:
1,407 lines (1,215 loc) 191 kB
import * as Https from 'https'; /** * All official methods of the Telegram Bot API without abstraction. */ export class TelegramBotRaw { /** * Each bot is given a unique authentication token when it is created. * The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 */ private token: string; /** * To use this class a token is **required** and can be obtained * by talking to [@botfather](https://telegram.me/BotFather). */ constructor (token: string) { // Token for the authentication this.token = token; } /** * Make an HTTPS POST multipart/form-data request to the Telegram server */ public async request (method: string, params: { [s: string]: any }): Promise<any> { return new Promise ((resolve, reject) => { // The separator used in the multipart request let boundary = 'FkEDmYLIktZjh6eaHViDpH0bbx'; // Parts the compose the body of the request let parts: Array<Buffer> = [] for (let name in params) { // Print the headers of this parameter parts.push (Buffer.from ('--' + boundary + '\r\nContent-Disposition: form-data; name="' + name + '"')); // If this parameter is a buffer send it as binary data if (params[name].name && params[name].data) parts.push (Buffer.from('; filename="'+ params[name].name +'"\r\nContent-Type: application/octet-stream\r\n\r\n'), params[name].data); // Else it is converted into a string else parts.push (Buffer.from('\r\n\r\n' + params[name])); // Conclude the part for this parameter parts.push (Buffer.from('\r\n')); } if (parts.length) { // Add the final separator to conclude the request parts.push (Buffer.from ('--' + boundary + '--\r\n')); } // Create the body concatenating the parts let body: Buffer = Buffer.concat (parts); // Initialize the HTTP request using the built-in module let request = Https.request ( { // All methods can be made with POST requests method: 'POST', // The path contains the authentication token // and the method of the Telegram API path: '/bot' + this.token + '/' + method, // Hostname of Telegram's servers hostname: 'api.telegram.org', // Headers that specify the type and length of the body headers: { 'Content-Type': 'multipart/form-data; boundary=' + boundary, 'Content-Length': body.byteLength }, }, (response) => { // The chunks that compose the HTTP response body let chunks: Array<Buffer> = []; // Set the callbacks for error in the errors and chunks response.on ('error', (error: Error ) => reject (error)); response.on ('data', (chunk: Buffer) => chunks.push (chunk)); // Callback called when the response is completed. // Now the concatenation of chunks is the whole response body. response.on ('end', () => { try { // Produce a string from the chunks let json = Buffer.concat (chunks).toString('utf8'); // Parse the string as a JSON let parsed = JSON.parse (json); // The response contains a JSON object, which always has a Boolean field ‘ok’ // and may have an optional String field ‘description’ // with a human-readable description of the result. // If ‘ok’ equals true, the request was successful and the result of the query // can be found in the ‘result’ field. In case of an unsuccessful request, // ‘ok’ equals false and the error is explained in the ‘description’. parsed.ok ? resolve (parsed.result) : reject (new Error (parsed.description)); } catch (error) { // Catch errors in the parsing phase reject (error); } }); }); // Catch errors during the request to the server request.on ('error', error => reject (error)); // Write the body of the request and close the request. request.write (body); request.end (); }); } /** * Use this method to receive incoming updates using long polling (wiki). An Array * of Update objects is returned. */ public async getUpdates (params: GetUpdatesParams): Promise<Array<Update>> { return this.request ('getUpdates', params); } /** * 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 request * comes from Telegram, we recommend using a secret path in the URL, e.g. * https://www.example.com/<token>. Since nobody else knows your bot‘s token, you * can be pretty sure it’s us. */ public async setWebhook (params: SetWebhookParams): Promise<boolean> { return this.request ('setWebhook', params); } /** * Use this method to remove webhook integration if you decide to switch back to * getUpdates. Returns True on success. Requires no parameters. */ public async deleteWebhook (): Promise<boolean> { return this.request ('deleteWebhook', {}); } /** * 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. */ public async getWebhookInfo (): Promise<WebhookInfo> { return this.request ('getWebhookInfo', {}); } /** * A simple method for testing your bot's auth token. Requires no parameters. * Returns basic information about the bot in form of a User object. */ public async getMe (): Promise<User> { return this.request ('getMe', {}); } /** * Use this method to send text messages. On success, the sent Message is returned. */ public async sendMessage (params: SendMessageParams): Promise<Message> { return this.request ('sendMessage', params); } /** * Use this method to forward messages of any kind. On success, the sent Message is * returned. */ public async forwardMessage (params: ForwardMessageParams): Promise<Message> { return this.request ('forwardMessage', params); } /** * Use this method to send photos. On success, the sent Message is returned. */ public async sendPhoto (params: SendPhotoParams): Promise<Message> { return this.request ('sendPhoto', params); } /** * 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 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. */ public async sendAudio (params: SendAudioParams): Promise<Message> { return this.request ('sendAudio', params); } /** * 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. */ public async sendDocument (params: SendDocumentParams): Promise<Message> { return this.request ('sendDocument', params); } /** * Use this method to send video files, Telegram clients support mp4 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. */ public async sendVideo (params: SendVideoParams): Promise<Message> { return this.request ('sendVideo', params); } /** * 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. */ public async sendAnimation (params: SendAnimationParams): Promise<Message> { return this.request ('sendAnimation', params); } /** * 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 (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. */ public async sendVoice (params: SendVoiceParams): Promise<Message> { return this.request ('sendVoice', params); } /** * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 * minute long. Use this method to send video messages. On success, the sent * Message is returned. */ public async sendVideoNote (params: SendVideoNoteParams): Promise<Message> { return this.request ('sendVideoNote', params); } /** * Use this method to send a group of photos or videos as an album. On success, an * array of the sent Messages is returned. */ public async sendMediaGroup (params: SendMediaGroupParams): Promise<Array<Message>> { return this.request ('sendMediaGroup', params); } /** * Use this method to send point on the map. On success, the sent Message is * returned. */ public async sendLocation (params: SendLocationParams): Promise<Message> { return this.request ('sendLocation', params); } /** * Use this method to edit live location messages sent by the bot or via the bot * (for inline bots). A location can be edited until its live_period expires or * editing is explicitly disabled by a call to stopMessageLiveLocation. On success, * if the edited message was sent by the bot, the edited Message is returned, * otherwise True is returned. */ public async editMessageLiveLocation (params: EditMessageLiveLocationParams): Promise<Message | boolean> { return this.request ('editMessageLiveLocation', params); } /** * Use this method to stop updating a live location message sent by the bot or via * the bot (for inline bots) before live_period expires. On success, if the message * was sent by the bot, the sent Message is returned, otherwise True is returned. */ public async stopMessageLiveLocation (params: StopMessageLiveLocationParams): Promise<Message | boolean> { return this.request ('stopMessageLiveLocation', params); } /** * Use this method to send information about a venue. On success, the sent Message * is returned. */ public async sendVenue (params: SendVenueParams): Promise<Message> { return this.request ('sendVenue', params); } /** * Use this method to send phone contacts. On success, the sent Message is * returned. */ public async sendContact (params: SendContactParams): Promise<Message> { return this.request ('sendContact', params); } /** * 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.Example: The ImageBot needs some time to process a request and upload * the image. Instead of sending a text message along the lines of “Retrieving * image, please wait…”, the bot may use sendChatAction with action = upload_photo. * The user will see a “sending photo” status for the bot. We only recommend using * this method when a response from the bot will take a noticeable amount of time * to arrive. */ public async sendChatAction (params: SendChatActionParams): Promise<boolean> { return this.request ('sendChatAction', params); } /** * Use this method to get a list of profile pictures for a user. Returns a * UserProfilePhotos object. */ public async getUserProfilePhotos (params: GetUserProfilePhotosParams): Promise<UserProfilePhotos> { return this.request ('getUserProfilePhotos', params); } /** * Use this method to get basic info 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. */ public async getFile (params: GetFileParams): Promise<File> { return this.request ('getFile', params); } /** * Use this method to 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. Returns True on success.Note: In regular groups (non-supergroups), * this method will only work if the ‘All Members Are Admins’ setting is off in the * target group. Otherwise members may only be removed by the group's creator or by * the member that added them. */ public async kickChatMember (params: KickChatMemberParams): Promise<boolean> { return this.request ('kickChatMember', params); } /** * Use this method to unban a previously kicked 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. * Returns True on success. */ public async unbanChatMember (params: UnbanChatMemberParams): Promise<boolean> { return this.request ('unbanChatMember', params); } /** * 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 * admin rights. Pass True for all boolean parameters to lift restrictions from a * user. Returns True on success. */ public async restrictChatMember (params: RestrictChatMemberParams): Promise<boolean> { return this.request ('restrictChatMember', params); } /** * 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 admin rights. Pass False for all boolean parameters to demote a * user. Returns True on success. */ public async promoteChatMember (params: PromoteChatMemberParams): Promise<boolean> { return this.request ('promoteChatMember', params); } /** * Use this method to generate a new invite link for a chat; any previously * generated link is revoked. The bot must be an administrator in the chat for this * to work and must have the appropriate admin rights. Returns the new invite link * as String on success. */ public async exportChatInviteLink (params: ExportChatInviteLinkParams): Promise<string> { return this.request ('exportChatInviteLink', params); } /** * 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 admin rights. Returns True on success.Note: In * regular groups (non-supergroups), this method will only work if the ‘All Members * Are Admins’ setting is off in the target group. */ public async setChatPhoto (params: SetChatPhotoParams): Promise<boolean> { return this.request ('setChatPhoto', params); } /** * 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 admin rights. Returns True on success.Note: In regular * groups (non-supergroups), this method will only work if the ‘All Members Are * Admins’ setting is off in the target group. */ public async deleteChatPhoto (params: DeleteChatPhotoParams): Promise<boolean> { return this.request ('deleteChatPhoto', params); } /** * 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 admin rights. Returns True on success.Note: In regular * groups (non-supergroups), this method will only work if the ‘All Members Are * Admins’ setting is off in the target group. */ public async setChatTitle (params: SetChatTitleParams): Promise<boolean> { return this.request ('setChatTitle', params); } /** * Use this method to change the description of 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. Returns True on success. */ public async setChatDescription (params: SetChatDescriptionParams): Promise<boolean> { return this.request ('setChatDescription', params); } /** * Use this method to pin a message in 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. Returns True on success. */ public async pinChatMessage (params: PinChatMessageParams): Promise<boolean> { return this.request ('pinChatMessage', params); } /** * Use this method to unpin a message in 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. Returns True on success. */ public async unpinChatMessage (params: UnpinChatMessageParams): Promise<boolean> { return this.request ('unpinChatMessage', params); } /** * Use this method for your bot to leave a group, supergroup or channel. Returns * True on success. */ public async leaveChat (params: LeaveChatParams): Promise<boolean> { return this.request ('leaveChat', params); } /** * Use this method to 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.). Returns a Chat object on success. */ public async getChat (params: GetChatParams): Promise<Chat> { return this.request ('getChat', params); } /** * Use this method to get a list of administrators in a chat. On success, returns * an Array of ChatMember objects that contains information about all chat * administrators except other bots. If the chat is a group or a supergroup and no * administrators were appointed, only the creator will be returned. */ public async getChatAdministrators (params: GetChatAdministratorsParams): Promise<Array<ChatMember>> { return this.request ('getChatAdministrators', params); } /** * Use this method to get the number of members in a chat. Returns Int on success. */ public async getChatMembersCount (params: GetChatMembersCountParams): Promise<number> { return this.request ('getChatMembersCount', params); } /** * Use this method to get information about a member of a chat. Returns a * ChatMember object on success. */ public async getChatMember (params: GetChatMemberParams): Promise<ChatMember> { return this.request ('getChatMember', params); } /** * 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 * admin 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. */ public async setChatStickerSet (params: SetChatStickerSetParams): Promise<boolean> { return this.request ('setChatStickerSet', params); } /** * 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 * admin 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. */ public async deleteChatStickerSet (params: DeleteChatStickerSetParams): Promise<boolean> { return this.request ('deleteChatStickerSet', params); } /** * 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.Alternatively, the user * can be redirected to the specified Game URL. For this option to work, you must * first create a game for your bot via @Botfather and accept the terms. Otherwise, * you may use links like t.me/your_bot?start=XXXX that open your bot with a * parameter. */ public async answerCallbackQuery (params: AnswerCallbackQueryParams): Promise<boolean> { return this.request ('answerCallbackQuery', params); } /** * Use this method to edit text and game messages sent by the bot or via the bot * (for inline bots). On success, if edited message is sent by the bot, the edited * Message is returned, otherwise True is returned. */ public async editMessageText (params: EditMessageTextParams): Promise<Message | boolean> { return this.request ('editMessageText', params); } /** * Use this method to edit captions of messages sent by the bot or via the bot (for * inline bots). On success, if edited message is sent by the bot, the edited * Message is returned, otherwise True is returned. */ public async editMessageCaption (params: EditMessageCaptionParams): Promise<Message | boolean> { return this.request ('editMessageCaption', params); } /** * Use this method to edit audio, document, photo, or video messages. If a message * is a part of a message album, then it can be edited only to a photo or a video. * Otherwise, message type can be changed arbitrarily. When inline message is * edited, new file can't be uploaded. Use previously uploaded file via its file_id * or specify a URL. On success, if the edited message was sent by the bot, the * edited Message is returned, otherwise True is returned. */ public async editMessageMedia (params: EditMessageMediaParams): Promise<Message | boolean> { return this.request ('editMessageMedia', params); } /** * Use this method to edit only the reply markup of messages sent by the bot or via * the bot (for inline bots). On success, if edited message is sent by the bot, the * edited Message is returned, otherwise True is returned. */ public async editMessageReplyMarkup (params: EditMessageReplyMarkupParams): Promise<Message | boolean> { return this.request ('editMessageReplyMarkup', params); } /** * Use this method to delete a message, including service messages, with the * following limitations: - A message can only be deleted if it was sent less than * 48 hours ago. - Bots can delete outgoing messages in groups and supergroups. - * Bots granted can_post_messages permissions can delete outgoing messages in * channels. - If the bot is an administrator of a group, it can delete any message * there. - If the bot has can_delete_messages permission in a supergroup or a * channel, it can delete any message there. Returns True on success. */ public async deleteMessage (params: DeleteMessageParams): Promise<boolean> { return this.request ('deleteMessage', params); } /** * Use this method to send .webp stickers. On success, the sent Message is * returned. */ public async sendSticker (params: SendStickerParams): Promise<Message> { return this.request ('sendSticker', params); } /** * Use this method to get a sticker set. On success, a StickerSet object is * returned. */ public async getStickerSet (params: GetStickerSetParams): Promise<StickerSet> { return this.request ('getStickerSet', params); } /** * Use this method to upload a .png file with a sticker for later use in * createNewStickerSet and addStickerToSet methods (can be used multiple times). * Returns the uploaded File on success. */ public async uploadStickerFile (params: UploadStickerFileParams): Promise<File> { return this.request ('uploadStickerFile', params); } /** * Use this method to create new sticker set owned by a user. The bot will be able * to edit the created sticker set. Returns True on success. */ public async createNewStickerSet (params: CreateNewStickerSetParams): Promise<boolean> { return this.request ('createNewStickerSet', params); } /** * Use this method to add a new sticker to a set created by the bot. Returns True * on success. */ public async addStickerToSet (params: AddStickerToSetParams): Promise<boolean> { return this.request ('addStickerToSet', params); } /** * Use this method to move a sticker in a set created by the bot to a specific * position . Returns True on success. */ public async setStickerPositionInSet (params: SetStickerPositionInSetParams): Promise<boolean> { return this.request ('setStickerPositionInSet', params); } /** * Use this method to delete a sticker from a set created by the bot. Returns True * on success. */ public async deleteStickerFromSet (params: DeleteStickerFromSetParams): Promise<boolean> { return this.request ('deleteStickerFromSet', params); } /** * Use this method to send answers to an inline query. On success, True is * returned. No more than 50 results per query are allowed. */ public async answerInlineQuery (params: AnswerInlineQueryParams): Promise<boolean> { return this.request ('answerInlineQuery', params); } /** * Use this method to send invoices. On success, the sent Message is returned. */ public async sendInvoice (params: SendInvoiceParams): Promise<Message> { return this.request ('sendInvoice', params); } /** * If you sent an invoice requesting a shipping address and the parameter * is_flexible was specified, the Bot API will send an Update with a shipping_query * field to the bot. Use this method to reply to shipping queries. On success, True * is returned. */ public async answerShippingQuery (params: AnswerShippingQueryParams): Promise<boolean> { return this.request ('answerShippingQuery', params); } /** * 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. Use this method to respond to such pre-checkout queries. On * success, True is returned. Note: The Bot API must receive an answer within 10 * seconds after the pre-checkout query was sent. */ public async answerPreCheckoutQuery (params: AnswerPreCheckoutQueryParams): Promise<boolean> { return this.request ('answerPreCheckoutQuery', params); } /** * Informs a user that some of the Telegram Passport elements they provided * contains errors. The user will not be able to re-submit their Passport to you * until the errors are fixed (the contents of the field for which you returned the * error must change). Returns True on success.Use this if the data submitted by * the user doesn't satisfy the standards your service requires for any reason. For * example, if a birthday date seems invalid, a submitted document is blurry, a * scan shows evidence of tampering, etc. Supply some details in the error message * to make sure the user knows how to correct the issues. */ public async setPassportDataErrors (params: SetPassportDataErrorsParams): Promise<boolean> { return this.request ('setPassportDataErrors', params); } /** * Use this method to send a game. On success, the sent Message is returned. */ public async sendGame (params: SendGameParams): Promise<Message> { return this.request ('sendGame', params); } /** * Use this method to set the score of the specified user in a game. On success, if * the message was sent by the bot, returns the edited Message, otherwise returns * True. Returns an error, if the new score is not greater than the user's current * score in the chat and force is False. */ public async setGameScore (params: SetGameScoreParams): Promise<Message | boolean> { return this.request ('setGameScore', params); } /** * Use this method to get data for high score tables. Will return the score of the * specified user and several of his neighbors in a game. On success, returns an * Array of GameHighScore objects.This method will currently return scores for the * target user, plus two of his closest neighbors on each side. Will also return * the top three users if the user and his neighbors are not among them. Please * note that this behavior is subject to change. */ public async getGameHighScores (params: GetGameHighScoresParams): Promise<Array<GameHighScore>> { return this.request ('getGameHighScores', params); } } /** * This object represents an incoming update. At most one of the optional * parameters can be present in any given update. */ export interface Update { /** * The update‘s unique identifier. Update identifiers start from a certain positive * number and increase sequentially. This ID becomes especially handy if you’re * using Webhooks, since it allows you to ignore repeated updates or to restore the * correct update sequence, should they get out of order. If there are no new * updates for at least a week, then identifier of the next update will be chosen * randomly instead of sequentially. */ update_id: number, /** * Optional. New incoming message of any kind — text, photo, sticker, etc. */ message?: Message, /** * Optional. New version of a message that is known to the bot and was edited */ edited_message?: Message, /** * Optional. New incoming channel post of any kind — text, photo, sticker, etc. */ channel_post?: Message, /** * Optional. New version of a channel post that is known to the bot and was edited */ edited_channel_post?: Message, /** * Optional. New incoming inline query */ inline_query?: InlineQuery, /** * Optional. The result of an inline query that was chosen by a user and sent to * their chat partner. Please see our documentation on the feedback collecting for * details on how to enable these updates for your bot. */ chosen_inline_result?: ChosenInlineResult, /** * Optional. New incoming callback query */ callback_query?: CallbackQuery, /** * Optional. New incoming shipping query. Only for invoices with flexible price */ shipping_query?: ShippingQuery, /** * Optional. New incoming pre-checkout query. Contains full information about * checkout */ pre_checkout_query?: PreCheckoutQuery, } /** * Use this method to receive incoming updates using long polling (wiki). An Array * of Update objects is returned. */ export interface GetUpdatesParams { /** * Identifier of the first update to be returned. Must be greater by one than the * highest among the identifiers of previously received updates. By default, * updates starting with the earliest unconfirmed update are returned. An update is * considered confirmed as soon as getUpdates is called with an offset higher than * its update_id. The negative offset can be specified to retrieve updates starting * from -offset update from the end of the updates queue. All previous updates will * forgotten. */ offset?: number, /** * Limits the number of updates to be retrieved. Values between 1—100 are accepted. * Defaults to 100. */ limit?: number, /** * Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. * Should be positive, short polling should be used for testing purposes only. */ timeout?: number, /** * List the types of updates you want your bot to receive. For example, specify * [“message”, “edited_channel_post”, “callback_query”] to only receive updates of * these types. See Update for a complete list of available update types. Specify * an empty list to receive all updates regardless of type (default). If not * specified, the previous setting will be used. Please note that this parameter * doesn't affect updates created before the call to the getUpdates, so unwanted * updates may be received for a short period of time. */ allowed_updates?: Array<string>, } /** * 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 request * comes from Telegram, we recommend using a secret path in the URL, e.g. * https://www.example.com/<token>. Since nobody else knows your bot‘s token, you * can be pretty sure it’s us. */ export interface SetWebhookParams { /** * HTTPS url to send updates to. Use an empty string to remove webhook integration */ url: string, /** * Upload your public key certificate so that the root certificate in use can be * checked. See our self-signed guide for details. */ certificate?: { name: string, data: Buffer }, /** * Maximum allowed number of simultaneous HTTPS connections to the webhook for * update delivery, 1-100. Defaults to 40. Use lower values to limit the load on * your bot‘s server, and higher values to increase your bot’s throughput. */ max_connections?: number, /** * List the types of updates you want your bot to receive. For example, specify * [“message”, “edited_channel_post”, “callback_query”] to only receive updates of * these types. See Update for a complete list of available update types. Specify * an empty list to receive all updates regardless of type (default). If not * specified, the previous setting will be used. Please note that this parameter * doesn't affect updates created before the call to the setWebhook, so unwanted * updates may be received for a short period of time. */ allowed_updates?: Array<string>, } /** * Contains information about the current status of a webhook. */ export interface WebhookInfo { /** * Webhook URL, may be empty if webhook is not set up */ url: string, /** * True, if a custom certificate was provided for webhook certificate checks */ has_custom_certificate: boolean, /** * Number of updates awaiting delivery */ pending_update_count: number, /** * Optional. Unix time for the most recent error that happened when trying to * deliver an update via webhook */ last_error_date?: number, /** * Optional. Error message in human-readable format for the most recent error that * happened when trying to deliver an update via webhook */ last_error_message?: string, /** * Optional. Maximum allowed number of simultaneous HTTPS connections to the * webhook for update delivery */ max_connections?: number, /** * Optional. A list of update types the bot is subscribed to. Defaults to all * update types */ allowed_updates?: Array<string>, } /** * This object represents a Telegram user or bot. */ export interface User { /** * Unique identifier for this user or bot */ id: number, /** * True, if this user is a bot */ is_bot: boolean, /** * User‘s or bot’s first name */ first_name: string, /** * Optional. User‘s or bot’s last name */ last_name?: string, /** * Optional. User‘s or bot’s username */ username?: string, /** * Optional. IETF language tag of the user's language */ language_code?: string, } /** * This object represents a chat. */ export interface Chat { /** * Unique identifier for this chat. This number may be greater than 32 bits and * some programming languages may have difficulty/silent defects in interpreting * it. But it is smaller than 52 bits, so a signed 64 bit integer or * double-precision float type are safe for storing this identifier. */ id: number, /** * Type of chat, can be either “private”, “group”, “supergroup” or “channel” */ type: string, /** * Optional. Title, for supergroups, channels and group chats */ title?: string, /** * Optional. Username, for private chats, supergroups and channels if available */ username?: string, /** * Optional. First name of the other party in a private chat */ first_name?: string, /** * Optional. Last name of the other party in a private chat */ last_name?: string, /** * Optional. True if a group has ‘All Members Are Admins’ enabled. */ all_members_are_administrators?: boolean, /** * Optional. Chat photo. Returned only in getChat. */ photo?: ChatPhoto, /** * Optional. Description, for supergroups and channel chats. Returned only in * getChat. */ description?: string, /** * Optional. Chat invite link, for supergroups and channel chats. Returned only in * getChat. */ invite_link?: string, /** * Optional. Pinned message, for supergroups and channel chats. Returned only in * getChat. */ pinned_message?: Message, /** * Optional. For supergroups, name of group sticker set. Returned only in getChat. */ sticker_set_name?: string, /** * Optional. True, if the bot can change the group sticker set. Returned only in * getChat. */ can_set_sticker_set?: boolean, } /** * This object represents a message. */ export interface Message { /** * Unique message identifier inside this chat */ message_id: number, /** * Optional. Sender, empty for messages sent to channels */ from?: User, /** * Date the message was sent in Unix time */ date: number, /** * Conversation the message belongs to */ chat: Chat, /** * Optional. For forwarded messages, sender of the original message */ forward_from?: User, /** * Optional. For messages forwarded from channels, information about the original * channel */ forward_from_chat?: Chat, /** * Optional. For messages forwarded from channels, identifier of the original * message in the channel */ forward_from_message_id?: number, /** * Optional. For messages forwarded from channels, signature of the post author if * present */ forward_signature?: string, /** * Optional. For forwarded messages, date the original message was sent in Unix * time */ forward_date?: number, /** * Optional. For replies, the original message. Note that the Message object in * this field will not contain further reply_to_message fields even if it itself is * a reply. */ reply_to_message?: Message, /** * Optional. Date the message was last edited in Unix time */ edit_date?: number, /** * Optional. The unique identifier of a media message group this message belongs to */ media_group_id?: string, /** * Optional. Signature of the post author for messages in channels */ author_signature?: string, /** * Optional. For text messages, the actual UTF-8 text of the message, 0-4096 * characters. */ text?: string, /** * Optional. For text messages, special entities like usernames, URLs, bot * commands, etc. that appear in the text */ entities?: Array<MessageEntity>, /** * Optional. For messages with a caption, special entities like usernames, URLs, * bot commands, etc. that appear in the caption */ caption_entities?: Array<MessageEntity>, /** * Optional. Message is an audio file, information about the file */ audio?: Audio, /** * Optional. Message is a general file, information about the file */ document?: Document, /** * Optional. Message is an animation, information about the animation. For backward * compatibility, when this field is set, the document field will also be set */ animation?: Animation, /** * Optional. Message is a game, information about the game. More about games » */ game?: Game, /** * Optional. Message is a photo, available sizes of the photo */ photo?: Array<PhotoSize>, /** * Optional. Message is a sticker, information about the sticker */ sticker?: Sticker, /** * Optional. Message is a video, information about the video */ video?: Video, /** * Optional. Message is a voice message, information about the file */ voice?: Voice, /** * Optional. Message is a video note, information about the video message */ video_note?: VideoNote, /** * Optional. Caption for the audio, document, photo, video or voice, 0-200 * characters */ caption?: string, /** * Optional. Message is a shared contact, information about the contact */ contact?: Contact, /** * Optional. Message is a shared location, information about the location */ location?: Location, /** * Optional. Message is a venue, information about the venue */ venue?: Venue, /** * Optional. New members that were added to the group or supergroup and information * about them (the bot itself may be one of these members) */ new_chat_members?: Array<User>, /** * Optional. A member was removed from the group, information about them (this * member may be the bot itself) */ left_chat_member?: User, /** * Optional. A chat title was changed to this value */ new_chat_title?: string, /** * Optional. A chat photo was change to this value */ new_chat_photo?: Array<PhotoSize>, /** * Optional. Service message: the chat photo was deleted */ delete_chat_photo?: boolean, /** * Optional. Service message: the group has been created */ group_chat_created?: boolean, /** * Optional. Service message: the supergroup has been created. This field can‘t be * received in a message coming through updates, because bot can’t be a member of a * supergroup when it is created. It can only be found in reply_to_message if * someone replies to a very first message in a directly created supergroup. */ supergroup_chat_created?: boolean, /** * Optional. Service message: the channel has been created. This field can‘t be * received in a message coming through updates, because bot can’t be a member of a * channel when it is created. It can only be found in reply_to_message if someone * replies to a very first message in a channel. */ channel_chat_created?: boolean, /** * Optional. The group has been migrated to a supergroup with the specified * identifier. This number may be greater than 32 bits and some programming * languages may have difficulty/silent defects in interpreting it. But it is * smaller than 52 bits, so a signed 64 bit integer or double-precision float type * are safe for storing this identifier. */ migrate_to_chat_id?: number, /** * Optional. The supergroup has been migrated from a group with the specified * identifier. This number may be greater than 32 bits and some programming * languages may have difficulty/silent defects in interpreting it. But it is * smaller than 52 bits, so a signed 64 bit integer or double-precision float type * are safe for storing this identifier. */ migrate_from_chat_id?: number, /** * Optional. Specified message was pinned. Note that the Message object in this * field will not contain further reply_to_message fields even if it is itself a * reply. */ pinned_message?: Message, /** * Optional. Message is an invoice for a payment, information about the invoice. * More about payments » */ invoice?: Invoice, /** * Optional. Message is a service message about a successful payment, information * about the payment. More about payments » */ successful_payment?: SuccessfulPayment, /** * Optional. The domain name of the website on which the user has logged in. More * about Telegram Login » */ connected_website?: string, /** * Optional. Telegram Passport data */ passport_data?: PassportData, } /** * This object represents one special entity in a text message. For example, * hashtags, usernames, URLs, etc. */ export interface MessageEntity { /** * Type of the entity. Can be mention (@username), hashtag, cashtag, bot_command, * url, email, phone_number, bold (bold text), italic (italic text), code * (monowidth string), pre (monowidth block), text_link (for clickable text URLs), * text_mention (for users without usernames) */ type: string, /** * Offset in UTF-16 code units to the start of the entity */ offset: number, /** * Length of the entity in UTF-16 code units */ length: number, /** * Optional. For “text_link” only, url that will be opened after user taps on the * text */ url?: string, /** * Optional. For “text_mention” only, the mentioned user */ user?: User, } /** * This object represents one size of a photo or a file / sticker thumbnail. */ export interface PhotoSize {