Skip to main content
Version: 1.4

TelegramContext

Send API - Official Docs

sendMessage(text [, options]) - Official Docs

Sends text messages.

ParamTypeDescription
textStringText of the message to be sent.
optionsObjectOther optional parameters.

Exmaple:

context.sendMessage('hi', {
disableWebPagePreview: true,
disableNotification: true,
});

sendPhoto(photo [, options]) - Official Docs

Sends photos.

ParamTypeDescription
photoStringPass a file id (recommended) or HTTP URL to send photo.
optionsObjectOther optional parameters.

Example:

context.sendPhoto('https://example.com/image.png', {
caption: 'gooooooodPhoto',
disableNotification: true,
});

sendAudio(audio [, options]) - Official Docs

Sends audio files.

ParamTypeDescription
audioStringPass a file id (recommended) or HTTP URL to send audio.
optionsObjectOther optional parameters.

Example:

context.sendAudio('https://example.com/audio.mp3', {
caption: 'gooooooodAudio',
disableNotification: true,
});

sendDocument(document [, options]) - Official Docs

Sends general files.

ParamTypeDescription
documentStringPass a file id (recommended) or HTTP URL to send document.
optionsObjectOther optional parameters.

Example:

context.sendDocument('https://example.com/doc.gif', {
caption: 'gooooooodDocument',
disableNotification: true,
});

sendSticker(sticker [, options]) - Official Docs

Sends .webp stickers.

ParamTypeDescription
stickerStringPass a file id (recommended) or HTTP URL to send sticker.
optionsObjectOther optional parameters.

Example:

context.sendSticker('CAADAgADQAADyIsGAAE7MpzFPFQX5QI', {
disableNotification: true,
});

sendVideo(video [, options]) - Official Docs

Sends video files, Telegram clients support mp4 videos (other formats may be sent as Document).

ParamTypeDescription
videoStringPass a file id (recommended) or HTTP URL to send video.
optionsObjectOther optional parameters.

Example:

context.sendVideo('https://example.com/video.mp4', {
caption: 'gooooooodVideo',
disableNotification: true,
});

sendVoice(voice [, options]) - Official Docs

Sends audio files.

ParamTypeDescription
voiceStringPass a file id (recommended) or HTTP URL to send voice.
optionsObjectOther optional parameters.

Example:

context.sendVoice('https://example.com/voice.ogg', {
caption: 'gooooooodVoice',
disableNotification: true,
});

sendVideoNote(videoNote [, options]) - Official Docs

Sends video messages. As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.

ParamTypeDescription
videoNoteStringPass a file id (recommended) or HTTP URL to send video note.
optionsObjectOther optional parameters.

Example:

context.sendVideoNote('https://example.com/video_note.mp4', {
duration: 40,
disableNotification: true,
});

sendMediaGroup(media [, options]) - Official Docs

send a group of photos or videos as an album.

ParamTypeDescription
mediaInputMedia[]A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
optionsObjectOther optional parameters.

Example:

context.sendMediaGroup([
{ type: 'photo', media: 'BQADBAADApYAAgcZZAfj2-xeidueWwI' },
]);

sendLocation(location [, options]) - Official Docs

Sends point on the map.

ParamTypeDescription
locationObjectObject contains latitude and longitude.
location.latitudeNumberLatitude of the location.
location.longitudeNumberLongitude of the location.
optionsObjectOther optional parameters.

Example:

context.sendLocation(
{
latitude: 30,
longitude: 45,
},
{
disableNotification: true,
}
);

sendVenue(venue [, options]) - Official Docs

Sends information about a venue.

ParamTypeDescription
venueObjectObject contains information of the venue.
venue.latitudeNumberLatitude of the venue.
venue.longitudeNumberLongitude of the venue.
venue.titleStringName of the venue.
venue.addressStringAddress of the venue.
optionsObjectOther optional parameters.

Example:

context.sendVenue(
{
latitude: 30,
longitude: 45,
title: 'a_title',
address: 'an_address',
},
{
disableNotification: true,
}
);

sendContact(contact [, options]) - Official Docs

Sends phone contacts.

ParamTypeDescription
contactObjectObject contains information of the contact.
contact.phoneNumberStringPhone number of the contact.
contact.firstNameStringFirst name of the contact.
optionsObjectOther optional parameters.

Example:

context.sendContact(
{
phoneNumber: '886123456789',
firstName: 'first',
},
{ lastName: 'last' }
);

sendChatAction(action) - Official Docs

Tells the user that something is happening on the bot's side.

ParamTypeDescription
actionStringType of action to broadcast.

Example:

context.sendChatAction('typing');

Get API

getUserProfilePhotos(options) - Official Docs

Gets a list of profile pictures for a user.

ParamTypeDescription
optionsObjectOther optional parameters

Example:

context.getUserProfilePhotos().then((result) => {
console.log(result);
// {
// totalCount: 3,
// photos: [
// [
// {
// fileId: 'AgADBAADGTo4Gz8cZAeR-ouu4XBx78EeqRkABHahi76pN-aO0UoDA050',
// fileSize: 14650,
// width: 160,
// height: 160,
// },
// {
// fileId: 'AgADBAADGTo4Gz8cZAeR-ouu4XBx78EeqRkABKCfooqTgFUX0EoD5B1C',
// fileSize: 39019,
// width: 320,
// height: 320,
// },
// {
// fileId: 'AgADBAADGTo4Gz8cZAeR-ouu4XBx78EeqRkABPL_pC9K3UpI0koD1B1C',
// fileSize: 132470,
// width: 640,
// height: 640,
// },
// ],
// ],
// }
});

getChat() - Official Docs

Gets 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.)

Example:

context.getChat().then((result) => {
console.log(result);
// {
// id: 313534466,
// firstName: 'first',
// lastName: 'last',
// username: 'username',
// type: 'private',
// }
});

getChatAdministrators() - Official Docs

Gets a list of administrators in the chat.

Example:

context.getChatAdministrators().then((result) => {
console.log(result);
// [
// {
// user: {
// id: 313534466,
// firstName: 'first',
// lastName: 'last',
// username: 'username',
// languangeCode: 'zh-TW',
// },
// status: 'creator',
// },
// ]
});

getChatMembersCount() - Official Docs

Gets the number of members in the chat.

Example:

context.getChatMembersCount().then((result) => {
console.log(result);
// '6'
});

getChatMember(userId) - Official Docs

Gets information about a member of the chat.

ParamTypeDescription
userIdNumberUnique identifier of the target user.

Example:

context.getChatMember(USER_ID).then((result) => {
console.log(result);
// {
// user: {
// id: 313534466,
// firstName: 'first',
// lastName: 'last',
// username: 'username',
// languangeCode: 'zh-TW',
// },
// status: 'creator',
// }
});

Updating API

editMessageText(text [, options]) - Official Docs

Edits text and game messages sent by the bot or via the bot (for inline bots).

ParamTypeDescription
textStringNew text of the message.
optionsObjectOther optional parameters.

Example:

context.editMessageText('new_text');

editMessageCaption(caption [, options]) - Official Docs

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

ParamTypeDescription
captionStringNew caption of the message.
optionsObjectOther optional parameters.

Example:

context.editMessageCaption('new_caption');

editMessageReplyMarkup(replyMarkup [, options]) - Official Docs

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

ParamTypeDescription
replyMarkupObjectNew replyMarkup of the message.
optionsObjectOther optional parameters.

Example:

context.editMessageReplyMarkup({
keyboard: [[{ text: 'new_button_1' }, { text: 'new_button_2' }]],
resizeKeyboard: true,
oneTimeKeyboard: true,
});

deleteMessage(messageId) - Official Docs

Deletes a message, including service messages.

ParamTypeDescription
messageIdNumberIdentifier of the message to delete.

Example:

context.deleteMessage(MESSAGE_ID);

editMessageLiveLocation(location [, options]) - Official Docs

Edit live location messages sent by the bot or via the bot (for inline bots).

ParamTypeDescription
locationObjectObject contains new latitude and longitude.
location.latitudeNumberLatitude of new location.
location.longitudeNumberLongitude of new location.
optionsObjectOther optional parameters.

Example:

context.editMessageLiveLocation({
latitude: 30,
longitude: 45,
});

stopMessageLiveLocation(options) - Official Docs

Stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires.

ParamTypeDescription
optionsObjectOther optional parameters.

Example:

context.stopMessageLiveLocation();

Group API

kickChatMember(userId [, options]) - Official Docs

Kicks a user from the group, the supergroup or the channel.

ParamTypeDescription
userIdNumberUnique identifier of the target user.
optionsObjectOther optional parameters.

Example:

context.kickChatMember(USER_ID, { untilDate: UNIX_TIME });

unbanChatMember(userId) - Official Docs

Unbans a previously kicked user in the supergroup or channel.

ParamTypeDescription
userIdNumberUnique identifier of the target user.

Example:

context.unbanChatMember(USER_ID);

restrictChatMember(userId [, options]) - Official Docs

Restricts a user in the supergroup

ParamTypeDescription
userIdNumberUnique identifier of the target user.
optionsObjectOther optional parameters.

Example:

context.restrictChatMember(USER_ID, { canSendMessages: true });

promoteChatMember(userId [, options]) - Official Docs

Promotes or demotes a user in the supergroup or the channel.

ParamTypeDescription
userIdNumberUnique identifier of the target user.
optionsObjectOther optional parameters.

Example:

context.promoteChatMember(USER_ID, {
canChangeInfo: true,
canInviteUsers: true,
});

Exports an invite link to the supergroup or the channel.

Example:

context.exportChatInviteLink();

setChatPhoto(photo) - Official Docs

Sets a new profile photo for the chat.

ParamTypeDescription
photoStringPass a file id (recommended) or HTTP URL to send photo.

Example:

context.setChatPhoto('https://example.com/image.png');

deleteChatPhoto() - Official Docs

Deletes the chat photo.

Example:

context.deleteChatPhoto();

setChatTitle(title) - Official Docs

Changes the title of the chat.

ParamTypeDescription
titleStringNew chat title, 1-255 characters.

Example:

context.setChatTitle('New Title');

setChatDescription(description) - Official Docs

Changes the description of the supergroup or the channel.

ParamTypeDescription
descriptionStringNew chat description, 0-255 characters.

Example:

context.setChatDescription('New Description');

setChatStickerSet(stickerSetName) - Official Docs

Set a new group sticker set for the supergroup.

ParamTypeDescription
stickerSetNameStringName of the sticker set to be set as the group sticker set.

Example:

context.setChatStickerSet('Sticker Set Name');

deleteChatStickerSet() - Official Docs

Delete a group sticker set from the supergroup.

Example:

context.deleteChatStickerSet();

pinChatMessage(messageId [, options]) - Official Docs

Pins a message in the supergroup.

ParamTypeDescription
messageIdNumberIdentifier of a message to pin.
optionsObjectOther optional parameters.

Example:

context.pinChatMessage(MESSAGE_ID, { disableNotification: true });

unpinChatMessage() - Official Docs

Unpins a message in the supergroup chat.

Example:

context.unpinChatMessage();

leaveChat() - Official Docs

Leaves the group, supergroup or channel.

Example:

context.leaveChat();

Payments API

sendInvoice(product [, options]) - Official Docs

Sends invoice.

ParamTypeDescription
productObjectObject of the product.
product.titleStringProduct name.
product.descriptionStringProduct description.
product.payloadStringBot defined invoice payload.
product.providerTokenStringPayments provider token.
product.startParameterStringDeep-linking parameter.
product.currencyStringThree-letter ISO 4217 currency code.
product.pricesObject[]Breakdown of prices.
optionsObjectAdditional Telegram query options.

Example:

context.sendInvoice({
title: 'product name',
description: 'product description',
payload: 'bot-defined invoice payload',
providerToken: 'PROVIDER_TOKEN',
startParameter: 'pay',
currency: 'USD',
prices: [
{ label: 'product', amount: 11000 },
{ label: 'tax', amount: 11000 },
],
});

answerShippingQuery(ok [, options]) - Official Docs

Reply to the shipping query.

ParamTypeDescription
okBooleanSpecify if delivery of the product is possible.
optionsObjectAdditional Telegram query options.

Example:

context.answerShippingQuery(true);

answerPreCheckoutQuery(ok [, options]) - Official Docs

Respond to the pre-checkout query.

ParamTypeDescription
okBooleanSpecify if delivery of the product is possible.
optionsObjectAdditional Telegram query options.

Example:

context.answerPreCheckoutQuery(true);

Inline mode API

answerInlineQuery(results [, options]) - Official Docs

Send answers to the inline query.

ParamTypeDescription
resultsInlineQueryResult[]Array of object represents one result of an inline query.
optionsObjectAdditional Telegram query options.

Example:

context.answerInlineQuery(
[
{
type: 'photo',
id: 'UNIQUE_ID',
photoFileId: 'FILE_ID',
title: 'PHOTO_TITLE',
},
{
type: 'audio',
id: 'UNIQUE_ID',
audioFileId: 'FILE_ID',
caption: 'AUDIO_TITLE',
},
],
{
cacheTime: 1000,
}
);

Game API

sendGame(gameShortName [, options]) - Official Docs

Sends a game.

ParamTypeDescription
gameShortNameStringShort name of the game.
optionsObjectAdditional Telegram query options.

Example:

context.sendGame('Mario Bros.', {
disableNotification: true,
});

setGameScore(score [, options]) - Official Docs

Sets the score of the specified user in a game.

ParamTypeDescription
scoreNumberNew score, must be non-negative.
optionsObjectAdditional Telegram query options.

Example:

context.setGameScore(999);

getGameHighScores() - Official Docs

Gets data for high score tables.

ParamTypeDescription
optionsObjectAdditional Telegram query options.

Example:

context.getGameHighScores();

Others

forwardMessageFrom(fromChatId, messageId [, options]) - Official Docs

Forwards messages of any kind.

ParamTypeDescription
fromChatIdNumber | StringUnique identifier for the chat where the original message was sent.
messageIdNumberMessage identifier in the chat specified in fromChatId.
optionsObjectOther optional parameters.

Example:

context.forwardMessageFrom(CHAT_ID, MESSAGE_ID, {
disableNotification: true,
});

forwardMessageTo(toChatId, messageId [, options]) - Official Docs

Forwards messages of any kind.

ParamTypeDescription
toChatIdNumber | StringUnique identifier for the target chat or username of the target channel.
messageIdNumberMessage identifier in the chat specified in fromChatId.
optionsObjectOther optional parameters.

Example:

context.forwardMessageTo(CHAT_ID, MESSAGE_ID, {
disableNotification: true,
});