Skip to content

API Reference Version 1.1.0

Philipp Naderer-Puiu edited this page Aug 4, 2017 · 1 revision

Classes

MultipartStream
TelegramBot

MultipartStream

Kind: global class

new MultipartStream(name, source)

Object to wrap file uploads to Telegram via multipart/form-data. The input can be a Stream for binary reading or a Path to the file.

Param Type Description
name string the name of the file
source io.Stream | fs.Path input binary stream or a path to the file

TelegramBot

Kind: global class

new TelegramBot(token)

A Telegram Bot API client. It manages the HTTPS-based communication with the API endpoint.

Param Type Description
token string the bot's unique authentication token

telegramBot.setWebhook(url, cert)

Registers a webhook for the bot. The provided URL must be using HTTPS for secure communication.

Kind: instance method of TelegramBot
See: Telegram Bot API - setWebhook

Param Type Description
url string the bot's HTTPS callback URL. An empty string removes the webhook.
cert MultipartStream optional self-signed public key certificate

telegramBot.getUpdates(options)

Retrieves updates using long polling requests.

Kind: instance method of TelegramBot
See: Telegram Bot API - getUpdates

Param Type Description
options Object optional parameters

telegramBot.getMe()

Test method to verify the auth token is working. Returns basic information about the bot.

Kind: instance method of TelegramBot
See: Telegram Bot API - getMe

telegramBot.sendMessage(chatId, text, options)

Sends a text message. On success, the sent message is returned.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendMessage

Param Type Description
chatId number | string identifier for the target chat
text string message text
options Object optional parameters

telegramBot.answerInlineQuery(inlineQueryId, results, options)

Answers inline queries for inline-enabled bots. No more than 50 results per query are allowed.

Kind: instance method of TelegramBot
See: Telegram Bot API - answerInlineQuery

Param Type Description
inlineQueryId numer | string the query id
results Array array of InlineQueryResult objects
options Object optional parameters

Example

updates.forEach(function(update) {
  if (utils.isInlineQuery(update)) {
    let query = utils.getInlineQuery(update);

    let searchResults = [
      {
        "type": "article",
        "id": "http://orf.at/stories/2353452/2353453/",
        "url": "http://orf.at/stories/2353452/2353453/",
        "title": "Noch mehr grünes Wasser",
        "description": "Jetzt sind beide Becken grün.",
        "thumb_url": "http://orf.at/static/4705004.jpg",
        "thumb_width": 640,
        "thumb_height": 360,
        "input_message_content": {
          "message_text": "Oje, noch mehr grünes Wasser!"
        }
      }
    ];

    bot.answerInlineQuery(query.id, searchResults, {
      cache_time: 5
    });
  }
});

telegramBot.forwardMessage(chatId, fromChatId, messageId, options)

Forwards messages of any kind to another chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - forwardMessage

Param Type Description
chatId number | string target chat id
fromChatId number | string source chat id
messageId number | string message id from the source chat
options Object optional parameters

telegramBot.sendPhoto(chatId, photo, options)

Sends a photo to a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendPhoto

Param Type Description
chatId number | string target chat id
photo MultipartStream multipart photo object
options Object optional parameters

telegramBot.sendAudio(chatId, audio, options)

Sends an audio message to a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendAudio

Param Type Description
chatId number | string target chat id
audio MultipartStream multipart audio object
options Object optional parameters

telegramBot.sendDocument(chatId, document, options)

Sends a document to a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendDocument

Param Type Description
chatId number | string target chat id
document MultipartStream multipart document object
options Object optional parameters

telegramBot.sendSticker(chatId, sticker, options)

Sends a .webp sticker to a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendSticker

Param Type Description
chatId number | string target chat id
sticker MultipartStream multipart sticker object
options Object optional parameters

telegramBot.sendVideo(chatId, video, options)

Sends a mp4 video to the chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendVideo

Param Type Description
chatId number | string target chat id
video MultipartStream multipart video object
options Object optional parameters

telegramBot.sendVideoNote(chatId, videoNote, options)

Sends a mp4 video note of up to 1 minute long to the chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendVideoNote

Param Type Description
chatId number | string target chat id
videoNote MultipartStream multipart video object
options Object optional parameters

telegramBot.sendVoice(chatId, voice, options)

Sends a voice message encoded with ogg and the low-latency Opus lossy audio coding format.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendVoice

Param Type Description
chatId number | string target chat id
voice MultipartStream multipart voice recording object
options Object optional parameters

telegramBot.sendLocation(chatId, latitude, longitude, options)

Sends a point on a map.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendLocation

Param Type Description
chatId number | string target chat id
latitude number numeric latitude
longitude number numeric longitude
options Object optional parameters

telegramBot.sendVenue(chatId, latitude, longitude, title, address, options)

Sends detailed information about a venue.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendVenue

Param Type Description
chatId number | string target chat id
latitude number numeric latitude
longitude number numeric longitude
title string venue name or title
address string detailed address of the venue
options Object optional parameters

telegramBot.sendContact(chatId, phoneNumber, firstName, options)

Sends a contact. The optional last_name has to be sent in the additional parameters.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendContact

Param Type Description
chatId number | string target chat id
phoneNumber string phone number as string
firstName string contact's first name
options Object optional parameters

telegramBot.sendChatAction(chatId, action)

Sends a work in progress indicator to the user. This might be useful if the bot needs more time to answer a specific message by the user.

Kind: instance method of TelegramBot
See: Telegram Bot API - sendChatAction

Param Type Description
chatId number | string target chat id
action string type of action or response a user will see in the future

telegramBot.getUserProfilePhotos(userId, options)

Retrieves a list of profile pictures for a user.

Kind: instance method of TelegramBot
See: Telegram Bot API - getUserProfilePhotos

Param Type Description
userId number | string user identifier
options Object optional parameters

telegramBot.getFile(fileId)

Retrieves basic information about the requested file and prepares it for downloading.

Kind: instance method of TelegramBot
See: Telegram Bot API - getFile

Param Type
fileId string

telegramBot.kickChatMember(chatId, userId)

Kicks a user from a group or a supergroup.

Kind: instance method of TelegramBot
See: Telegram Bot API - kickChatMember

Param Type Description
chatId number | string target chat id
userId number | string user to kick

telegramBot.leaveChat(chatId)

Lets a bot leave a group, supergroup or channel. The method returns true on success.

Kind: instance method of TelegramBot
See: Telegram Bot API - leaveChat

Param Type Description
chatId number | string target chat id

telegramBot.unbanChatMember(chatId, userId)

Annuls a ban of a chat member for the given supergroup. The user must join again via a link or invite.

Kind: instance method of TelegramBot
See: Telegram Bot API - unbanChatMember

Param Type Description
chatId number | string the target chat id
userId number | string user to unban

telegramBot.getChat(chatId)

Retrieves detailed information about the given chat

Kind: instance method of TelegramBot
See: Telegram Bot API - getChat

Param Type Description
chatId number | string target chat or username of the target supergroup or channel (in the format @channelusername)

telegramBot.getChatAdministrators(chatId)

Retrieves an array with a list of administrators in a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - getChatAdministrators

Param Type Description
chatId number | string target chat id

telegramBot.getChatMembersCount(chatId)

Returns an integer number of members in a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - getChatMembersCount

Param Type Description
chatId number | string target chat id

telegramBot.getChatMember(chatId, userId)

Retrieves information about a member of a chat.

Kind: instance method of TelegramBot
See: Telegram Bot API - getChatMember

Param Type Description
chatId number | string target chat id
userId number | string user identifier

telegramBot.answerCallbackQuery(callbackQueryId, options)

Sends answers to callback queries sent from inline keyboards.

Kind: instance method of TelegramBot
See: Telegram Bot API - answerCallbackQuery

Param Type Description
callbackQueryId number | string unique callback query identifier to answer to
options Object optional parameters

telegramBot.editMessageText(text, options)

Edits text messages sent by the bot or via the bot in inline queries.

Kind: instance method of TelegramBot
See: Telegram Bot API - editMessageText

Param Type Description
text string the new text
options Object optional parameters depending on the type of message to update

telegramBot.editMessageCaption(options)

Edits captions of messages sent by the bot or via the bot for inline bots.

Kind: instance method of TelegramBot
See: Telegram Bot API - editMessageCaption

Param Type Description
options Object optional parameters depending on the type of message to update

telegramBot.editMessageReplyMarkup(options)

Edits only the reply markup of messages sent by the bot or via the bot for inline bots.

Kind: instance method of TelegramBot
See: Telegram Bot API - editMessageReplyMarkup

Param Type Description
options Object optional parameters depending on the type of message to update

telegramBot.getWebhookInfo()

Returns information about the current webhook configuration.

Kind: instance method of TelegramBot
See: Telegram Bot API - getWebhookInfo

telegramBot.deleteMessage(chatId, messageId)

Deletes a message after being sent.

Kind: instance method of TelegramBot
See: Telegram Bot API - deleteMessage

Param Type Description
chatId number | string identifier for the target chat
messageId number | string identifier for the message to delete

telegramBot.restrictChatMember(chatId, userId, options)

Restricts a user in a supergroup. The bot must be an administrator in the supergroup for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - restrictChatMember

Param Type Description
chatId number | string target chat id
userId number identifier of the target user
options object optional parameters

telegramBot.promoteChatMember(chatId, userId, options)

Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - promoteChatMember

Param Type Description
chatId number | string target chat id
userId number identifier of the target user
options object optional parameters

telegramBot.exportChatInviteLink(chatId)

Exports an invite link to a supergroup or a channel. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - exportChatInviteLink

Param Type Description
chatId number | string target chat id

telegramBot.setChatPhoto(chatId, photo)

Sets the profile photo of a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - setChatPhoto

Param Type Description
chatId number | string target chat id
photo MultipartStream multipart photo object

telegramBot.deleteChatPhoto(chatId)

Deletes a profile photo in a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - deleteChatPhoto

Param Type Description
chatId number | string target chat id

telegramBot.setChatTitle(chatId, title)

Changes the title of a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - setChatTitle

Param Type Description
chatId number | string target chat id
title string the new title, between 1 and 255 characters

telegramBot.setChatDescription(chatId, description)

Changes the description of a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - setChatDescription

Param Type Description
chatId number | string target chat id
description string the new description, between 1 and 255 characters

telegramBot.pinChatMessage(chatId, messageId, options)

Pins the specified message in a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - pinChatMessage

Param Type Description
chatId number | string target chat id
messageId number the message to pin
options object optional parameters

telegramBot.unpinChatMessage(chatId)

Unpins the currently pinned message in a chat. The bot must be an administrator in the supergroup or channel for this to work.

Kind: instance method of TelegramBot
See: Telegram Bot API - unpinChatMessage

Param Type Description
chatId number | string target chat id

telegramBot.getStickerSet(name)

Gets the specified sticker set.

Kind: instance method of TelegramBot
See: Telegram Bot API - getStickerSet

Param Type Description
name string the name of the sticker set

telegramBot.uploadStickerFile(userId, pngSticker)

Uploads a .png file with a sticker for later use in createNewStickerSet and addStickerToSet.

Kind: instance method of TelegramBot
See: Telegram Bot API - uploadStickerFile

Param Type Description
userId number the owner
pngSticker MultipartStream multipart png sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

telegramBot.createNewStickerSet(userId, name, title, pngSticker, emojis, options)

Creates a new sticker set owned by a user.

Kind: instance method of TelegramBot
See: Telegram Bot API - createNewStickerSet

Param Type Description
userId number the owner
name string short name of whole sticker set, between 1 and 64 characters
title string title of the sticker, between 1 and 64 characters
pngSticker MultipartStream multipart png sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
emojis string one or more emoji corresponding to the sticker
options Object optional parameters

telegramBot.addStickerToSet(userId, name, title, pngSticker, emojis, options)

Adds a sticker to an existing set owned by a user.

Kind: instance method of TelegramBot
See: Telegram Bot API - addStickerToSet

Param Type Description
userId number the owner
name string short name of sticker set, between 1 and 64 characters
title string title of the sticker, between 1 and 64 characters
pngSticker MultipartStream multipart png sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
emojis string one or more emoji corresponding to the sticker
options Object optional parameters

telegramBot.setStickerPositionInSet(sticker, position)

Moves a sticker in a set created by the bot to a specific position.

Kind: instance method of TelegramBot
See: Telegram Bot API - setStickerPositionInSet

Param Type Description
sticker string file identifier of the sticker
position number zero-based position in the set

telegramBot.deleteStickerFromSet(sticker)

Deletes a sticker from a set.

Kind: instance method of TelegramBot
See: Telegram Bot API - deleteStickerFromSet

Param Type Description
sticker string file identifier of the sticker
Clone this wiki locally