Telegram

Telegram wrapper API reference.

const { Telegram } = require('telegraf')

Constructor

Initialize new Telegraf app.

telegram.new Telegram(token, options)

Param Type Description
token string Bot Token
options object Telegram options

Telegram options:

{
  agent: null,        // https.Agent instance, allows custom proxy, certificate, keep alive, etc.
  webhookReply: true  // Reply via webhook
}

webhookReply

Use this property to control reply via webhook feature.

telegram.webhookReply = [bool]

answerCallbackQuery

Use this method to send answers to callback queries.

telegram.answerCallbackQuery(callbackQueryId, text, url, showAlert, cacheTime) => Promise

Param Type Description
callbackQueryId string Query id
[text] string Notification text
[url] string Game url
[showAlert] bool Show alert instead of notification
[cacheTime] number The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.

See Telegram api docs

answerGameQuery

Use this method to send answers to game query.

telegram.answerGameQuery(callbackQueryId, url) => Promise

Param Type Description
callbackQueryId string Query id
url string Notification text

answerShippingQuery

Use this method to send answers to shipping query.

telegram.answerShippingQuery(shippingQueryId, ok, shippingOptions, errorMessage) => Promise

Param Type Description
shippingQueryId string Shipping Query id
ok bool Specify True if delivery to the specified address is possible
shippingOptions bool Shipping Options
errorMessage bool Error message in human readable form

answerPreCheckoutQuery

Use this method to send answers to shipping query.

telegram.answerPreCheckoutQuery(preCheckoutQueryId, ok, errorMessage) => Promise

Param Type Description
preCheckoutQueryId string Shipping Query id
ok bool Specify True if everything is alright (goods are available, etc.)
errorMessage bool Error message in human readable form

answerInlineQuery

Use this method to send answers to an inline query.

telegram.answerInlineQuery(inlineQueryId, results, extra) => Promise

Param Type Description
inlineQueryId string Query id
results object[] Results
[extra] object Extra parameters

deleteMessage

Use this method to delete bot messages

telegram.deleteMessage(chatId, messageId) => Promise

Param Type Description
chatId number|string Chat id
messageId string Message id

editMessageCaption

Use this method to edit captions of messages sent by the bot or via the bot

telegram.editMessageCaption(chatId, messageId, inlineMessageId, caption, extra) => Promise

Param Type Description
chatId number|string Chat id
messageId string Message id
inlineMessageId string Inline message id
caption string Caption
[extra] object Extra parameters

editMessageReplyMarkup

Use this method to edit only the reply markup of messages sent by the bot or via the bot.

telegram.editMessageReplyMarkup(chatId, messageId, inlineMessageId, markup, extra) => Promise

Param Type Description
chatId number|string Chat id
messageId string Message id
inlineMessageId string Inline message id
markup object Keyboard markup
[extra] object Extra parameters

editMessageText

Use this method to edit text messages sent by the bot or via the bot.

telegram.editMessageText(chatId, messageId, inlineMessageId, text, extra) => Promise

Param Type Description
chatId number|string Chat id
messageId string Message id
inlineMessageId string Inline message id
text string Message
[extra] object Extra parameters

forwardMessage

Forwards message.

telegram.forwardMessage(chatId, fromChatId, messageId, extra) => Promise

Param Type Description
chatId number|string Target Chat id
fromChatId number|string Source Chat id
messageId number Message id
[extra] object Extra parameters

sendCopy

Sends message copy.

telegram.sendCopy(chatId, message, extra) => Promise

Param Type Description
chatId number|string Target Chat id
message object Message
[extra] object Extra parameters

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.

telegram.getWebhookInfo() => Promise

getChat

Use this method to get up to date information about the chat (current name of the user for one-on-one conversatio ns, current username of a user, group or channel, etc.).

telegram.getChat(chatId) => Promise

Param Type Description
chatId number|string Chat id

See Telegram api docs

getChatAdministrators

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.

telegram.getChatAdministrators(chatId) => Promise

Param Type Description
chatId number|string Chat id

See Telegram api docs

setGameScore

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.

telegram.setGameScore(userId, score, inlineMessageId, chatId, messageId, editMessage, force) => Promise

Param Type Description
userId number\ Target User id
score number\ Target User id
inlineMessageId string Inline message id(optional)
chatId number|string Target Chat id(optional)
messageId number|string Message id(optional)
editMessage boolean edit target message, default value is True
force boolean Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters(optional)

See Telegram api docs

getGameHighScores

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.

telegram.getGameHighScores(userId, inlineMessageId, chatId, messageId) => Promise

Param Type Description
userId number\ Target User id
inlineMessageId string Inline message id(optional)
chatId number|string Target Chat id(optional)
messageId number|string Message id(optional)

See Telegram api docs

getChatMember

Use this method to get information about a member of a chat.

telegram.getChatMember(chatId) => Promise

Param Type Description
chatId number|string Chat id

See Telegram api docs

getChatMembersCount

Use this method to get the number of members in a chat.

telegram.getChatMembersCount(chatId) => Promise

Param Type Description
chatId number|string Chat id

See Telegram api docs

getFile

Returns basic info about a file and prepare it for downloading.

telegram.getFile(fileId) => Promise

Param Type Description
fileId string File id

See Telegram api docs

Returns link to file.

telegram.getFileLink(fileId) => Promise

Param Type Description
fileId string|object File id or file object

getMe

Returns basic information about the bot.

telegram.getMe() => Promise

See Telegram api docs

getUserProfilePhotos

Returns profiles photos for provided user.

telegram.getUserProfilePhotos(userId, offset, limit) => Promise

Param Type Description
userId number Chat id
offset number Offset
limit number Limit

See Telegram api docs

kickChatMember

Use this method to kick a user from a group or a supergroup.

telegram.kickChatMember(chatId, userId) => Promise

Param Type Description
chatId number|string Chat id
userId number User id

See Telegram api docs

leaveChat

Use this method for your bot to leave a group, supergroup or channel.

telegram.leaveChat(chatId) => Promise

Param Type Description
chatId number|string Chat id

See Telegram api docs

deleteWebhook

Removes webhook integration.

telegram.deleteWebhook() => Promise

See Telegram api docs

sendAudio

Sends audio.

telegram.sendAudio(chatId, audio, extra) => Promise

Param Type Description
chatId number|string Chat id
audio File Document
[extra] object Extra parameters

sendGame

Sends game.

telegram.sendGame(chatId, gameName, extra) => Promise

Param Type Description
chatId number|string Chat id
gameName String Game short name
[extra] object Extra parameters

sendChatAction

Sends chat action.

telegram.sendChatAction(chatId, action) => Promise

Param Type Description
chatId number|string Chat id
action string Chat action

sendContact

Sends document.

telegram.sendContact(chatId, phoneNumber, firstName, extra) => Promise

Param Type Description
chatId number|string Chat id
phoneNumber string Contact phone number
firstName string Contact first name
[extra] object Extra parameters

sendDocument

Sends document.

telegram.sendDocument(chatId, doc, extra) => Promise

Param Type Description
chatId number|string Chat id
doc File Document
[extra] object Extra parameters

sendLocation

Sends location.

telegram.sendLocation(chatId, latitude, longitude, extra) => Promise

Param Type Description
chatId number|string Chat id
latitude number Latitude
longitude number Longitude
[extra] object Extra parameters

sendMessage

Sends text message.

telegram.sendMessage(chatId, text, extra) => Promise

Param Type Description
chatId number|string Chat id
text string Message
[extra] object Extra parameters

sendPhoto

Sends photo.

telegram.sendPhoto(chatId, photo, extra) => Promise

Param Type Description
chatId number|string Chat id
photo File Photo
[extra] object Extra parameters

sendSticker

Sends sticker.

telegram.sendSticker(chatId, sticker, extra) => Promise

Param Type Description
chatId number|string Chat id
sticker File Document
[extra] object Extra parameters

sendVenue

Sends venue information.

telegram.sendVenue(chatId, latitude, longitude, title, address, extra) => Promise

Param Type Description
chatId number|string Chat id
latitude number Latitude
longitude number Longitude
title string Venue title
address string Venue address
[extra] object Extra parameters

sendInvoice

Sends invoice.

telegram.sendInvoice(chatId, invoice) => Promise

Param Type Description
chatId number|string Chat id
invoice File Invoice object

sendVideo

Sends video.

telegram.sendVideo(chatId, video, extra) => Promise

Param Type Description
chatId number|string Chat id
video File Document
[extra] object Extra parameters

sendVideoNote

Sends round video.

telegram.sendVideoNote(chatId, video, extra) => Promise

Param Type Description
chatId number|string Chat id
video File Video note file
[extra] object Extra parameters

sendVoice

Sends voice.

telegram.sendVoice(chatId, voice, extra) => Promise

Param Type Description
chatId number|string Chat id
voice File Document
[extra] object Extra parameters

setWebhook

Specifies an url to receive incoming updates via an outgoing webhook.

telegram.setWebhook(url, [cert], [maxConnections], [allowedUpdates]) => Promise

Param Type Description
url string Public url for webhook
[cert] File SSL public certificate
[maxConnections] number User id
[allowedUpdates] string[] List the types of updates you want your bot to receive

See Telegram api docs

unbanChatMember

Use this method to unban a previously kicked user in a supergroup.

telegram.unbanChatMember(chatId, userId) => Promise

Param Type Description
chatId number|string Chat id
userId number User id

See Telegram api docs