2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-22 18:07:16 +00:00

750 lines
37 KiB
Markdown
Raw Normal View History

2016-01-01 22:00:41 +01:00
[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) [![bitHound Score](https://www.bithound.io/github/yagop/node-telegram-bot-api/badges/score.svg)](https://www.bithound.io/github/yagop/node-telegram-bot-api) [![https://telegram.me/node_telegram_bot_api](https://img.shields.io/badge/💬 Telegram-node__telegram__bot__api-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬 Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez)
2015-10-10 18:28:21 +02:00
Node.js module to interact with official [Telegram Bot API](https://core.telegram.org/bots/api). A bot token is needed, to obtain one, talk to [@botfather](https://telegram.me/BotFather) and create a new bot.
2015-06-29 22:37:38 +02:00
2015-06-29 22:19:19 +02:00
```sh
npm install node-telegram-bot-api
```
```js
var TelegramBot = require('node-telegram-bot-api');
// replace the value below with the Telegram token you receive from @BotFather
2015-06-29 22:19:19 +02:00
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
2015-10-10 18:09:25 +02:00
// Create a bot that uses 'polling' to fetch new updates
var bot = new TelegramBot(token, { polling: true });
// Matches "/echo [whatever]"
2015-10-10 18:09:25 +02:00
bot.onText(/\/echo (.+)/, function (msg, match) {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message
var chatId = msg.chat.id;
var resp = match[1]; // the captured "whatever"
// send back the matched "whatever" to the chat
bot.sendMessage(chatId, resp);
2015-10-10 18:09:25 +02:00
});
// Listen for any kind of message. There are different kinds of
// messages.
2015-10-10 18:09:25 +02:00
bot.on('message', function (msg) {
2015-06-29 22:19:19 +02:00
var chatId = msg.chat.id;
// send a message to the chat acknowledging receipt of their message
bot.sendMessage(chatId, "Received your message");
2015-06-29 22:19:19 +02:00
});
```
2015-06-29 22:37:38 +02:00
There are some other examples on [examples](https://github.com/yagop/node-telegram-bot-api/tree/master/examples).
2015-08-08 12:59:16 +02:00
### Events
2016-01-04 23:34:27 +01:00
Every time TelegramBot receives a message, it emits a `message`. Depending on which [message](https://core.telegram.org/bots/api#message) was received, emits an event from this ones: `text`, `audio`, `document`, `photo`, `sticker`, `video`, `voice`, `contact`, `location`, `new_chat_participant`, `left_chat_participant`, `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`. Its much better to listen a specific event rather than a `message` in order to stay safe from the content.
TelegramBot emits `callback_query` when receives a [Callback Query](https://core.telegram.org/bots/api#callbackquery).
TelegramBot emits `inline_query` when receives an [Inline Query](https://core.telegram.org/bots/api#inlinequery) and `chosen_inline_result` when receives a [ChosenInlineResult](https://core.telegram.org/bots/api#choseninlineresult). Bot must be enabled on [inline mode](https://core.telegram.org/bots/api#inline-mode).
2016-12-17 02:19:00 +03:00
TelegramBot emits `channel_post` on a new incoming channel post of any kind.
TelegramBot emits `edited_message` when a message is edited, and also `edited_message_text` or `edited_message_caption` depending on which type of message was edited.
TelegramBot emits `edited_channel_post` when a channel post is edited, and also `edited_channel_post_text` or `edited_channel_post_caption` depending on which type of channel post was edited.
2015-06-29 00:51:10 +02:00
* * *
### WebHooks
Telegram only supports HTTPS connections to WebHooks, in order to set a WebHook a private key file and public certificate must be used. Since August 29, 2015 Telegram supports self signed ones, to generate them:
```bash
# Our private cert will be key.pem, keep in private this file.
openssl genrsa -out key.pem 2048
# Our public certificate will be crt.pem
openssl req -new -sha256 -key key.pem -out crt.pem
```
Once they are generated, the `crt.pem` can be provided to `telegramBot.setWebHook(url, crt)` as `crt`.
2015-07-08 22:04:55 +02:00
2015-09-26 22:52:14 +02:00
## API Reference
<a name="TelegramBot"></a>
2016-03-20 20:14:56 +01:00
2015-06-29 22:49:16 +02:00
## TelegramBot
2015-09-26 22:52:14 +02:00
TelegramBot
**Kind**: global class
**See**: https://core.telegram.org/bots/api
* [TelegramBot](#TelegramBot)
2016-01-04 23:43:31 +01:00
* [new TelegramBot(token, [options])](#new_TelegramBot_new)
* [.initPolling()](#TelegramBot+initPolling)
2016-07-07 23:51:13 +02:00
* [.stopPolling()](#TelegramBot+stopPolling) ⇒ <code>Promise</code>
* [.isPolling()](#TelegramBot+isPolling) ⇒ <code>Boolean</code>
* [.openWebHook()](#TelegramBot+openWebHook)
* [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ <code>Promise</code>
* [.hasOpenWebHook()](#TelegramBot+hasOpenWebHook) ⇒ <code>Boolean</code>
2016-01-04 23:43:31 +01:00
* [.getMe()](#TelegramBot+getMe) ⇒ <code>Promise</code>
* [.setWebHook(url, [options])](#TelegramBot+setWebHook)
* [.deleteWebHook()](#TelegramBot+deleteWebHook) ⇒ <code>Promise</code>
* [.getWebHookInfo()](#TelegramBot+getWebHookInfo) ⇒ <code>Promise</code>
* [.getUpdates([options])](#TelegramBot+getUpdates) ⇒ <code>Promise</code>
* [.processUpdate(update)](#TelegramBot+processUpdate)
2016-01-04 23:43:31 +01:00
* [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ <code>Promise</code>
* [.answerInlineQuery(inlineQueryId, results, [options])](#TelegramBot+answerInlineQuery) ⇒ <code>Promise</code>
* [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ <code>Promise</code>
2016-01-04 23:43:31 +01:00
* [.sendPhoto(chatId, photo, [options])](#TelegramBot+sendPhoto) ⇒ <code>Promise</code>
* [.sendAudio(chatId, audio, [options])](#TelegramBot+sendAudio) ⇒ <code>Promise</code>
2016-06-06 23:34:03 +02:00
* [.sendDocument(chatId, doc, [options], [fileOpts])](#TelegramBot+sendDocument) ⇒ <code>Promise</code>
2016-01-04 23:43:31 +01:00
* [.sendSticker(chatId, sticker, [options])](#TelegramBot+sendSticker) ⇒ <code>Promise</code>
* [.sendVideo(chatId, video, [options])](#TelegramBot+sendVideo) ⇒ <code>Promise</code>
* [.sendVoice(chatId, voice, [options])](#TelegramBot+sendVoice) ⇒ <code>Promise</code>
* [.sendChatAction(chatId, action)](#TelegramBot+sendChatAction) ⇒ <code>Promise</code>
2016-06-06 22:57:06 +02:00
* [.kickChatMember(chatId, userId)](#TelegramBot+kickChatMember) ⇒ <code>Promise</code>
* [.unbanChatMember(chatId, userId)](#TelegramBot+unbanChatMember) ⇒ <code>Promise</code>
* [.answerCallbackQuery(callbackQueryId, text, showAlert, [options])](#TelegramBot+answerCallbackQuery) ⇒ <code>Promise</code>
* [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ <code>Promise</code>
* [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ <code>Promise</code>
* [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ <code>Promise</code>
* [.getUserProfilePhotos(userId, [options])](#TelegramBot+getUserProfilePhotos) ⇒ <code>Promise</code>
2016-01-04 23:43:31 +01:00
* [.sendLocation(chatId, latitude, longitude, [options])](#TelegramBot+sendLocation) ⇒ <code>Promise</code>
* [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ <code>Promise</code>
* [.sendContact(chatId, phoneNumber, firstName, [options])](#TelegramBot+sendContact) ⇒ <code>Promise</code>
2016-01-04 23:43:31 +01:00
* [.getFile(fileId)](#TelegramBot+getFile) ⇒ <code>Promise</code>
* [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ <code>Promise</code>
* [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ <code>Promise</code>
* [.onText(regexp, callback)](#TelegramBot+onText)
2016-01-30 18:19:39 +01:00
* [.onReplyToMessage(chatId, messageId, callback)](#TelegramBot+onReplyToMessage)
* [.getChat(chatId)](#TelegramBot+getChat) ⇒ <code>Promise</code>
* [.getChatAdministrators(chatId)](#TelegramBot+getChatAdministrators) ⇒ <code>Promise</code>
* [.getChatMembersCount(chatId)](#TelegramBot+getChatMembersCount) ⇒ <code>Promise</code>
* [.getChatMember(chatId, userId)](#TelegramBot+getChatMember) ⇒ <code>Promise</code>
2016-10-10 14:47:52 +03:00
* [.leaveChat(chatId)](#TelegramBot+leaveChat) ⇒ <code>Promise</code>
2016-10-04 00:05:20 +05:30
* [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ <code>Promise</code>
* [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ <code>Promise</code>
2016-10-22 16:01:34 +05:30
* [.getGameHighScores(userId, [options])](#TelegramBot+getGameHighScores) ⇒ <code>Promise</code>
2015-09-26 22:52:14 +02:00
<a name="new_TelegramBot_new"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### new TelegramBot(token, [options])
2015-06-29 22:49:16 +02:00
Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a SSL certificate.
2015-08-08 12:59:16 +02:00
Emits `message` when a message arrives.
2015-06-29 22:49:16 +02:00
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| token | <code>String</code> | | Bot Token |
| [options] | <code>Object</code> | | |
| [options.polling] | <code>Boolean</code> &#124; <code>Object</code> | <code>false</code> | Set true to enable polling or set options |
| [options.polling.timeout] | <code>String</code> &#124; <code>Number</code> | <code>10</code> | Timeout in seconds for long polling |
| [options.polling.interval] | <code>String</code> &#124; <code>Number</code> | <code>300</code> | Interval between requests in miliseconds |
| [options.polling.autoStart] | <code>Boolean</code> | <code>true</code> | Start polling immediately |
2015-09-26 22:52:14 +02:00
| [options.webHook] | <code>Boolean</code> &#124; <code>Object</code> | <code>false</code> | Set true to enable WebHook or set options |
| [options.webHook.port] | <code>Number</code> | <code>8443</code> | Port to bind to |
| [options.webHook.key] | <code>String</code> | | Path to file with PEM private key for webHook server. The file is read **synchronously**! |
| [options.webHook.cert] | <code>String</code> | | Path to file with PEM certificate (public) for webHook server. The file is read **synchronously**! |
| [options.webHook.pfx] | <code>String</code> | | Path to file with PFX private key and certificate chain for webHook server. The file is read **synchronously**! |
| [options.webHook.autoOpen] | <code>Boolean</code> | <code>true</code> | Open webHook immediately |
| [options.webHook.https] | <code>Object</code> | | Options to be passed to `https.createServer()`. Note that `options.webHook.key`, `options.webHook.cert` and `options.webHook.pfx`, if provided, will be used to override `key`, `cert` and `pfx` in this object, respectively. See https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener for more information. |
| [options.onlyFirstMatch] | <code>Boolean</code> | <code>false</code> | Set to true to stop after first match. Otherwise, all regexps are executed |
2017-01-02 14:36:39 +03:00
| [options.request] | <code>Object</code> | | Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information. |
| [options.baseApiUrl] | <code>String</code> | <code>https://api.telegram.org</code> | API Base URl; useful for proxying and testing |
2015-06-29 00:51:10 +02:00
<a name="TelegramBot+initPolling"></a>
### telegramBot.initPolling()
Start polling
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
2016-07-07 23:51:13 +02:00
<a name="TelegramBot+stopPolling"></a>
### telegramBot.stopPolling() ⇒ <code>Promise</code>
Stops polling after the last polling request resolves
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>Promise</code> - promise Promise, of last polling request
<a name="TelegramBot+isPolling"></a>
### telegramBot.isPolling() ⇒ <code>Boolean</code>
Return true if polling. Otherwise, false.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
<a name="TelegramBot+openWebHook"></a>
### telegramBot.openWebHook()
Open webhook
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
<a name="TelegramBot+closeWebHook"></a>
### telegramBot.closeWebHook() ⇒ <code>Promise</code>
Close webhook after closing all current connections
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>Promise</code> - promise
<a name="TelegramBot+hasOpenWebHook"></a>
### telegramBot.hasOpenWebHook() ⇒ <code>Boolean</code>
Return true if using webhook and it is open i.e. accepts connections.
Otherwise, false.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+getMe"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.getMe() ⇒ <code>Promise</code>
2015-06-29 00:51:10 +02:00
Returns basic information about the bot in form of a `User` object.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getme
<a name="TelegramBot+setWebHook"></a>
2016-03-20 20:14:56 +01:00
### telegramBot.setWebHook(url, [options])
2015-07-07 22:11:54 +02:00
Specify an url to receive incoming updates via an outgoing webHook.
This method has an [older, compatible signature][setWebHook-v0.25.0]
that is being deprecated.
2015-07-07 22:11:54 +02:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#setwebhook
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | URL where Telegram will make HTTP Post. Leave empty to delete webHook. |
| [options] | <code>Object</code> | Additional Telegram query options |
| [options.certificate] | <code>String</code> &#124; <code>stream.Stream</code> | PEM certificate key (public). |
2015-06-29 00:51:10 +02:00
<a name="TelegramBot+deleteWebHook"></a>
### telegramBot.deleteWebHook() ⇒ <code>Promise</code>
Use this method to remove webhook integration if you decide to
switch back to getUpdates. Returns True on success.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#deletewebhook
<a name="TelegramBot+getWebHookInfo"></a>
### telegramBot.getWebHookInfo() ⇒ <code>Promise</code>
Use this method to get current webhook status.
On success, returns a [WebhookInfo](https://core.telegram.org/bots/api#webhookinfo) object.
If the bot is using getUpdates, will return an object with the
url field empty.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getwebhookinfo
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+getUpdates"></a>
2016-03-20 20:14:56 +01:00
### telegramBot.getUpdates([options]) ⇒ <code>Promise</code>
Use this method to receive incoming updates using long polling.
This method has an [older, compatible signature][getUpdates-v0.25.0]
that is being deprecated.
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getupdates
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-06-29 00:51:10 +02:00
<a name="TelegramBot+processUpdate"></a>
### telegramBot.processUpdate(update)
Process an update; emitting the proper events and executing regexp
callbacks. This method is useful should you be using a different
way to fetch updates, other than those provided by TelegramBot.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#update
| Param | Type |
| --- | --- |
| update | <code>Object</code> |
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendMessage"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendMessage(chatId, text, [options]) ⇒ <code>Promise</code>
2015-06-29 00:51:10 +02:00
Send text message.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendmessage
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| text | <code>String</code> | Text of the message to be sent |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-06-29 00:51:10 +02:00
2016-01-04 23:34:27 +01:00
<a name="TelegramBot+answerInlineQuery"></a>
2016-03-20 20:14:56 +01:00
2016-01-04 23:34:27 +01:00
### telegramBot.answerInlineQuery(inlineQueryId, results, [options]) ⇒ <code>Promise</code>
Send answers to an inline query.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#answerinlinequery
| Param | Type | Description |
| --- | --- | --- |
| inlineQueryId | <code>String</code> | Unique identifier of the query |
| results | <code>Array.&lt;InlineQueryResult&gt;</code> | An array of results for the inline query |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+forwardMessage"></a>
2016-03-20 20:14:56 +01:00
### telegramBot.forwardMessage(chatId, fromChatId, messageId, [options]) ⇒ <code>Promise</code>
2015-06-29 00:51:10 +02:00
Forward messages of any kind.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| fromChatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the chat where the original message was sent |
| messageId | <code>Number</code> &#124; <code>String</code> | Unique message identifier |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendPhoto"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendPhoto(chatId, photo, [options]) ⇒ <code>Promise</code>
2015-06-29 00:51:10 +02:00
Send photo
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendphoto
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-03 17:20:34 +01:00
| photo | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path or a Stream. Can also be a `file_id` previously uploaded |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendAudio"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendAudio(chatId, audio, [options]) ⇒ <code>Promise</code>
2015-06-29 00:51:10 +02:00
Send audio
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendaudio
2015-06-29 00:51:10 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-03 17:20:34 +01:00
| audio | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2015-07-07 22:11:54 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendDocument"></a>
2016-03-20 20:14:56 +01:00
2016-06-06 23:34:03 +02:00
### telegramBot.sendDocument(chatId, doc, [options], [fileOpts]) ⇒ <code>Promise</code>
2015-07-07 22:11:54 +02:00
Send Document
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendDocument
2015-07-06 01:40:54 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-03 17:20:34 +01:00
| doc | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2016-06-06 23:34:03 +02:00
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
2015-07-08 22:04:55 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendSticker"></a>
2016-03-20 20:14:56 +01:00
2016-01-03 17:20:34 +01:00
### telegramBot.sendSticker(chatId, sticker, [options]) ⇒ <code>Promise</code>
2015-07-08 22:04:55 +02:00
Send .webp stickers.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendsticker
2015-07-08 22:04:55 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-03 17:20:34 +01:00
| sticker | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. Stickers are WebP format files. |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2015-07-08 22:36:28 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendVideo"></a>
2016-03-20 20:14:56 +01:00
2016-01-03 17:20:34 +01:00
### telegramBot.sendVideo(chatId, video, [options]) ⇒ <code>Promise</code>
2015-08-08 12:59:16 +02:00
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
2015-07-08 22:36:28 +02:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendvideo
2015-07-08 22:36:28 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-04 23:34:27 +01:00
| video | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path or Stream. Can also be a `file_id` previously uploaded. |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2015-09-15 17:55:02 -03:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendVoice"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendVoice(chatId, voice, [options]) ⇒ <code>Promise</code>
Send voice
2015-09-15 17:55:02 -03:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendvoice
2015-09-15 17:55:02 -03:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
2016-01-03 17:20:34 +01:00
| voice | <code>String</code> &#124; <code>stream.Stream</code> &#124; <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
2015-09-26 22:52:14 +02:00
| [options] | <code>Object</code> | Additional Telegram query options |
2015-07-06 01:40:54 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendChatAction"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendChatAction(chatId, action) ⇒ <code>Promise</code>
2015-07-07 22:11:54 +02:00
Send chat action.
`typing` for text messages,
`upload_photo` for photos, `record_video` or `upload_video` for videos,
`record_audio` or `upload_audio` for audio files, `upload_document` for general files,
`find_location` for location data.
2015-07-06 01:40:54 +02:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendchataction
2015-07-08 22:04:55 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| action | <code>String</code> | Type of action to broadcast. |
2015-07-09 23:15:05 +02:00
2016-06-06 22:57:06 +02:00
<a name="TelegramBot+kickChatMember"></a>
### telegramBot.kickChatMember(chatId, userId) ⇒ <code>Promise</code>
Use this method to kick a user from a group or a supergroup.
In the case of supergroups, 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 group for this to work.
Returns True on success.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#kickchatmember
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
| userId | <code>String</code> | Unique identifier of the target user |
<a name="TelegramBot+unbanChatMember"></a>
### telegramBot.unbanChatMember(chatId, userId) ⇒ <code>Promise</code>
Use this method to unban a previously kicked user in a supergroup.
The user will not return to the group automatically, but will be
able to join via link, etc. The bot must be an administrator in
the group for this to work. Returns True on success.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#unbanchatmember
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
| userId | <code>String</code> | Unique identifier of the target user |
<a name="TelegramBot+answerCallbackQuery"></a>
### telegramBot.answerCallbackQuery(callbackQueryId, text, showAlert, [options]) ⇒ <code>Promise</code>
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.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#answercallbackquery
| Param | Type | Description |
| --- | --- | --- |
| callbackQueryId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the query to be answered |
| text | <code>String</code> | Text of the notification. If not specified, nothing will be shown to the user |
| showAlert | <code>Boolean</code> | Whether to show an alert or a notification at the top of the screen |
| [options] | <code>Object</code> | Additional Telegram query options |
<a name="TelegramBot+editMessageText"></a>
### telegramBot.editMessageText(text, [options]) ⇒ <code>Promise</code>
Use this method to edit text messages sent by the bot or via
the bot (for inline bots). On success, the edited Message is
returned.
Note that you must provide one of chat_id, message_id, or
inline_message_id in your request.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#editmessagetext
| Param | Type | Description |
| --- | --- | --- |
| text | <code>String</code> | New text of the message |
| [options] | <code>Object</code> | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
<a name="TelegramBot+editMessageCaption"></a>
### telegramBot.editMessageCaption(caption, [options]) ⇒ <code>Promise</code>
Use this method to edit captions of messages sent by the
bot or via the bot (for inline bots). On success, the
edited Message is returned.
Note that you must provide one of chat_id, message_id, or
inline_message_id in your request.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
2016-07-07 23:51:13 +02:00
**See**: https://core.telegram.org/bots/api#editmessagecaption
2016-06-06 22:57:06 +02:00
| Param | Type | Description |
| --- | --- | --- |
| caption | <code>String</code> | New caption of the message |
| [options] | <code>Object</code> | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
<a name="TelegramBot+editMessageReplyMarkup"></a>
### telegramBot.editMessageReplyMarkup(replyMarkup, [options]) ⇒ <code>Promise</code>
Use this method to edit only the reply markup of messages
sent by the bot or via the bot (for inline bots).
On success, the edited Message is returned.
Note that you must provide one of chat_id, message_id, or
inline_message_id in your request.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#editmessagetext
| Param | Type | Description |
| --- | --- | --- |
| replyMarkup | <code>Object</code> | A JSON-serialized object for an inline keyboard. |
| [options] | <code>Object</code> | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+getUserProfilePhotos"></a>
2016-03-20 20:14:56 +01:00
### telegramBot.getUserProfilePhotos(userId, [options]) ⇒ <code>Promise</code>
2015-07-09 23:15:05 +02:00
Use this method to get a list of profile pictures for a user.
Returns a [UserProfilePhotos](https://core.telegram.org/bots/api#userprofilephotos) object.
This method has an [older, compatible signature][getUserProfilePhotos-v0.25.0]
that is being deprecated.
2015-07-09 23:15:05 +02:00
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getuserprofilephotos
2015-07-09 23:15:05 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| userId | <code>Number</code> &#124; <code>String</code> | Unique identifier of the target user |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-07-09 13:40:11 +02:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+sendLocation"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.sendLocation(chatId, latitude, longitude, [options]) ⇒ <code>Promise</code>
2015-07-09 23:15:05 +02:00
Send location.
2015-07-09 13:40:11 +02:00
Use this method to send point on the map.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendlocation
2015-07-09 13:40:11 +02:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| latitude | <code>Float</code> | Latitude of location |
| longitude | <code>Float</code> | Longitude of location |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-09-26 17:46:06 +03:00
<a name="TelegramBot+sendVenue"></a>
### telegramBot.sendVenue(chatId, latitude, longitude, title, address, [options]) ⇒ <code>Promise</code>
Send venue.
Use this method to send information about a venue.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendvenue
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| latitude | <code>Float</code> | Latitude of location |
| longitude | <code>Float</code> | Longitude of location |
| title | <code>String</code> | Name of the venue |
| address | <code>String</code> | Address of the venue |
| [options] | <code>Object</code> | Additional Telegram query options |
2016-05-13 16:20:36 +02:00
<a name="TelegramBot+sendContact"></a>
### telegramBot.sendContact(chatId, phoneNumber, firstName, [options]) ⇒ <code>Promise</code>
Send contact.
Use this method to send phone contacts.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
2016-05-13 16:20:36 +02:00
**See**: https://core.telegram.org/bots/api#sendcontact
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| phoneNumber | <code>String</code> | Contact's phone number |
| firstName | <code>String</code> | Contact's first name |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+getFile"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.getFile(fileId) ⇒ <code>Promise</code>
2015-09-26 17:46:06 +03:00
Get file.
Use this method to get basic info about a file and prepare it for downloading.
Attention: link will be valid for 1 hour.
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getfile
2015-09-26 17:46:06 +03:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| fileId | <code>String</code> | File identifier to get info about |
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+getFileLink"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.getFileLink(fileId) ⇒ <code>Promise</code>
Get link for file.
Use this method to get link for file for subsequent use.
Attention: link will be valid for 1 hour.
2016-03-20 20:14:56 +01:00
This method is a sugar extension of the (getFile)[#getfilefileid] method,
which returns just path to file on remote server (you will have to manually build full uri after that).
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>Promise</code> - promise Promise which will have *fileURI* in resolve callback
**See**: https://core.telegram.org/bots/api#getfile
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| fileId | <code>String</code> | File identifier to get info about |
2015-09-26 19:52:17 +03:00
2015-09-26 22:52:14 +02:00
<a name="TelegramBot+downloadFile"></a>
2016-03-20 20:14:56 +01:00
2015-09-26 22:52:14 +02:00
### telegramBot.downloadFile(fileId, downloadDir) ⇒ <code>Promise</code>
2015-09-26 19:52:17 +03:00
Downloads file in the specified folder.
This is just a sugar for (getFile)[#getfilefiled] method
2015-09-26 22:52:14 +02:00
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>Promise</code> - promise Promise, which will have *filePath* of downloaded file in resolve callback
2015-09-26 19:52:17 +03:00
2015-09-26 22:52:14 +02:00
| Param | Type | Description |
| --- | --- | --- |
| fileId | <code>String</code> | File identifier to get info about |
| downloadDir | <code>String</code> | Absolute path to the folder in which file will be saved |
2015-09-26 19:52:17 +03:00
2015-10-10 18:09:25 +02:00
<a name="TelegramBot+onText"></a>
2016-03-20 20:14:56 +01:00
2015-10-10 18:09:25 +02:00
### telegramBot.onText(regexp, callback)
Register a RegExp to test against an incomming text message.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
| Param | Type | Description |
| --- | --- | --- |
| regexp | <code>RegExp</code> | RegExp to be executed with `exec`. |
| callback | <code>function</code> | Callback will be called with 2 parameters, the `msg` and the result of executing `regexp.exec` on message text. |
2016-01-30 18:06:04 +01:00
<a name="TelegramBot+onReplyToMessage"></a>
2016-03-20 20:14:56 +01:00
2016-01-30 18:19:39 +01:00
### telegramBot.onReplyToMessage(chatId, messageId, callback)
2016-01-30 18:06:04 +01:00
Register a reply to wait for a message response.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
| Param | Type | Description |
| --- | --- | --- |
2016-01-30 18:19:39 +01:00
| chatId | <code>Number</code> &#124; <code>String</code> | The chat id where the message cames from. |
| messageId | <code>Number</code> &#124; <code>String</code> | The message id to be replied. |
2016-03-20 20:14:56 +01:00
| callback | <code>function</code> | Callback will be called with the reply message. |
2016-01-30 18:06:04 +01:00
<a name="TelegramBot+getChat"></a>
### telegramBot.getChat(chatId) ⇒ <code>Promise</code>
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.).
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchat
| Param | Type | Description |
| --- | --- | --- |
2016-10-25 18:32:35 +02:00
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel |
<a name="TelegramBot+getChatAdministrators"></a>
### telegramBot.getChatAdministrators(chatId) ⇒ <code>Promise</code>
Returns the administrators in a chat in form of an Array of `ChatMember` objects.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatadministrators
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
<a name="TelegramBot+getChatMembersCount"></a>
### telegramBot.getChatMembersCount(chatId) ⇒ <code>Promise</code>
Use this method to get the number of members in a chat.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatmemberscount
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
<a name="TelegramBot+getChatMember"></a>
### telegramBot.getChatMember(chatId, userId) ⇒ <code>Promise</code>
Use this method to get information about a member of a chat.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatmember
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
| userId | <code>String</code> | Unique identifier of the target user |
2016-10-10 14:47:52 +03:00
<a name="TelegramBot+leaveChat"></a>
### telegramBot.leaveChat(chatId) ⇒ <code>Promise</code>
Leave a group, supergroup or channel.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#leavechat
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) |
2016-10-04 00:05:20 +05:30
<a name="TelegramBot+sendGame"></a>
### telegramBot.sendGame(chatId, gameShortName, [options]) ⇒ <code>Promise</code>
Use this method to send a game.
2016-10-04 00:05:20 +05:30
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendgame
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| gameShortName | <code>String</code> | name of the game to be sent. |
| [options] | <code>Object</code> | Additional Telegram query options |
<a name="TelegramBot+setGameScore"></a>
### telegramBot.setGameScore(userId, score, [options]) ⇒ <code>Promise</code>
Use this method to set the score of the specified user in a game.
2016-10-04 00:05:20 +05:30
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#setgamescore
2016-10-04 00:05:20 +05:30
| Param | Type | Description |
| --- | --- | --- |
| userId | <code>String</code> | Unique identifier of the target user |
| score | <code>Number</code> | New score value. |
| [options] | <code>Object</code> | Additional Telegram query options |
2016-10-22 16:01:34 +05:30
<a name="TelegramBot+getGameHighScores"></a>
### telegramBot.getGameHighScores(userId, [options]) ⇒ <code>Promise</code>
Use this method to get data for high score table.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getgamehighscores
| Param | Type | Description |
| --- | --- | --- |
| userId | <code>String</code> | Unique identifier of the target user |
| [options] | <code>Object</code> | Additional Telegram query options |
2015-09-26 22:52:14 +02:00
* * *
[setWebHook-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#telegrambotsetwebhookurl-cert
[getUpdates-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUpdates
[getUserProfilePhotos-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUserProfilePhotos