TelegramContext
Send API - Official Docs
sendMessage(text [, options])
- Official Docs
Sends text messages.
Param | Type | Description |
---|---|---|
text | String | Text of the message to be sent. |
options | Object | Other optional parameters. |
Exmaple:
context.sendMessage('hi', {
disableWebPagePreview: true,
disableNotification: true,
});
sendPhoto(photo [, options])
- Official Docs
Sends photos.
Param | Type | Description |
---|---|---|
photo | String | Pass a file id (recommended) or HTTP URL to send photo. |
options | Object | Other optional parameters. |
Example:
context.sendPhoto('https://example.com/image.png', {
caption: 'gooooooodPhoto',
disableNotification: true,
});
sendAudio(audio [, options])
- Official Docs
Sends audio files.
Param | Type | Description |
---|---|---|
audio | String | Pass a file id (recommended) or HTTP URL to send audio. |
options | Object | Other optional parameters. |
Example:
context.sendAudio('https://example.com/audio.mp3', {
caption: 'gooooooodAudio',
disableNotification: true,
});
sendDocument(document [, options])
- Official Docs
Sends general files.
Param | Type | Description |
---|---|---|
document | String | Pass a file id (recommended) or HTTP URL to send document. |
options | Object | Other optional parameters. |
Example:
context.sendDocument('https://example.com/doc.gif', {
caption: 'gooooooodDocument',
disableNotification: true,
});
sendSticker(sticker [, options])
- Official Docs
Sends .webp
stickers.
Param | Type | Description |
---|---|---|
sticker | String | Pass a file id (recommended) or HTTP URL to send sticker. |
options | Object | Other 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).
Param | Type | Description |
---|---|---|
video | String | Pass a file id (recommended) or HTTP URL to send video. |
options | Object | Other optional parameters. |
Example:
context.sendVideo('https://example.com/video.mp4', {
caption: 'gooooooodVideo',
disableNotification: true,
});
sendVoice(voice [, options])
- Official Docs
Sends audio files.
Param | Type | Description |
---|---|---|
voice | String | Pass a file id (recommended) or HTTP URL to send voice. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
videoNote | String | Pass a file id (recommended) or HTTP URL to send video note. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
media | InputMedia[] | A JSON-serialized array describing photos and videos to be sent, must include 2–10 items |
options | Object | Other optional parameters. |
Example:
context.sendMediaGroup([
{ type: 'photo', media: 'BQADBAADApYAAgcZZAfj2-xeidueWwI' },
]);
sendLocation(location [, options])
- Official Docs
Sends point on the map.
Param | Type | Description |
---|---|---|
location | Object | Object contains latitude and longitude. |
location.latitude | Number | Latitude of the location. |
location.longitude | Number | Longitude of the location. |
options | Object | Other optional parameters. |
Example:
context.sendLocation(
{
latitude: 30,
longitude: 45,
},
{
disableNotification: true,
}
);
sendVenue(venue [, options])
- Official Docs
Sends information about a venue.
Param | Type | Description |
---|---|---|
venue | Object | Object contains information of the venue. |
venue.latitude | Number | Latitude of the venue. |
venue.longitude | Number | Longitude of the venue. |
venue.title | String | Name of the venue. |
venue.address | String | Address of the venue. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
contact | Object | Object contains information of the contact. |
contact.phoneNumber | String | Phone number of the contact. |
contact.firstName | String | First name of the contact. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
action | String | Type of action to broadcast. |
Example:
context.sendChatAction('typing');
Get API
getUserProfilePhotos(options)
- Official Docs
Gets a list of profile pictures for a user.
Param | Type | Description |
---|---|---|
options | Object | Other 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.
Param | Type | Description |
---|---|---|
userId | Number | Unique 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).
Param | Type | Description |
---|---|---|
text | String | New text of the message. |
options | Object | Other 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).
Param | Type | Description |
---|---|---|
caption | String | New caption of the message. |
options | Object | Other 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).
Param | Type | Description |
---|---|---|
replyMarkup | Object | New replyMarkup of the message. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
messageId | Number | Identifier 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).
Param | Type | Description |
---|---|---|
location | Object | Object contains new latitude and longitude. |
location.latitude | Number | Latitude of new location. |
location.longitude | Number | Longitude of new location. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
options | Object | Other optional parameters. |
Example:
context.stopMessageLiveLocation();
Group API
kickChatMember(userId [, options])
- Official Docs
Kicks a user from the group, the supergroup or the channel.
Param | Type | Description |
---|---|---|
userId | Number | Unique identifier of the target user. |
options | Object | Other optional parameters. |
Example:
context.kickChatMember(USER_ID, { untilDate: UNIX_TIME });
unbanChatMember(userId)
- Official Docs
Unbans a previously kicked user in the supergroup or channel.
Param | Type | Description |
---|---|---|
userId | Number | Unique identifier of the target user. |
Example:
context.unbanChatMember(USER_ID);
restrictChatMember(userId [, options])
- Official Docs
Restricts a user in the supergroup
Param | Type | Description |
---|---|---|
userId | Number | Unique identifier of the target user. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
userId | Number | Unique identifier of the target user. |
options | Object | Other optional parameters. |
Example:
context.promoteChatMember(USER_ID, {
canChangeInfo: true,
canInviteUsers: true,
});
exportChatInviteLink()
- Official Docs
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.
Param | Type | Description |
---|---|---|
photo | String | Pass 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.
Param | Type | Description |
---|---|---|
title | String | New chat title, 1-255 characters. |
Example:
context.setChatTitle('New Title');
setChatDescription(description)
- Official Docs
Changes the description of the supergroup or the channel.
Param | Type | Description |
---|---|---|
description | String | New chat description, 0-255 characters. |
Example:
context.setChatDescription('New Description');
setChatStickerSet(stickerSetName)
- Official Docs
Set a new group sticker set for the supergroup.
Param | Type | Description |
---|---|---|
stickerSetName | String | Name 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.
Param | Type | Description |
---|---|---|
messageId | Number | Identifier of a message to pin. |
options | Object | Other 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.
Param | Type | Description |
---|---|---|
product | Object | Object of the product. |
product.title | String | Product name. |
product.description | String | Product description. |
product.payload | String | Bot defined invoice payload. |
product.providerToken | String | Payments provider token. |
product.startParameter | String | Deep-linking parameter. |
product.currency | String | Three-letter ISO 4217 currency code. |
product.prices | Object[] | Breakdown of prices. |
options | Object | Additional 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.
Param | Type | Description |
---|---|---|
ok | Boolean | Specify if delivery of the product is possible. |
options | Object | Additional Telegram query options. |
Example:
context.answerShippingQuery(true);
answerPreCheckoutQuery(ok [, options])
- Official Docs
Respond to the pre-checkout query.
Param | Type | Description |
---|---|---|
ok | Boolean | Specify if delivery of the product is possible. |
options | Object | Additional Telegram query options. |
Example:
context.answerPreCheckoutQuery(true);
Inline mode API
answerInlineQuery(results [, options])
- Official Docs
Send answers to the inline query.
Param | Type | Description |
---|---|---|
results | InlineQueryResult[] | Array of object represents one result of an inline query. |
options | Object | Additional 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.
Param | Type | Description |
---|---|---|
gameShortName | String | Short name of the game. |
options | Object | Additional 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.
Param | Type | Description |
---|---|---|
score | Number | New score, must be non-negative. |
options | Object | Additional Telegram query options. |
Example:
context.setGameScore(999);
getGameHighScores()
- Official Docs
Gets data for high score tables.
Param | Type | Description |
---|---|---|
options | Object | Additional Telegram query options. |
Example:
context.getGameHighScores();
Others
forwardMessageFrom(fromChatId, messageId [, options])
- Official Docs
Forwards messages of any kind.
Param | Type | Description |
---|---|---|
fromChatId | Number | String | Unique identifier for the chat where the original message was sent. |
messageId | Number | Message identifier in the chat specified in fromChatId. |
options | Object | Other optional parameters. |
Example:
context.forwardMessageFrom(CHAT_ID, MESSAGE_ID, {
disableNotification: true,
});
forwardMessageTo(toChatId, messageId [, options])
- Official Docs
Forwards messages of any kind.
Param | Type | Description |
---|---|---|
toChatId | Number | String | Unique identifier for the target chat or username of the target channel. |
messageId | Number | Message identifier in the chat specified in fromChatId. |
options | Object | Other optional parameters. |
Example:
context.forwardMessageTo(CHAT_ID, MESSAGE_ID, {
disableNotification: true,
});