2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 05:17:41 +00:00
This commit is contained in:
yago 2015-06-29 22:49:16 +02:00
parent f219f10c3c
commit bf141cec36
2 changed files with 66 additions and 53 deletions

112
README.md
View File

@ -2,9 +2,6 @@
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](telegram.me/BotFather) and create a new bot. 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](telegram.me/BotFather) and create a new bot.
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 valid (not self signed) SSL certificate.
```sh ```sh
npm install node-telegram-bot-api npm install node-telegram-bot-api
``` ```
@ -27,99 +24,114 @@ There are some other examples on [examples](https://github.com/yagop/node-telegr
* * * * * *
## Class: TelegramBot ## TelegramBot
NodeJS class for Telegram Bot API.
Support for WebHooks and long polling. Emits `message` when message arrives. 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 valid (not self signed) SSL certificate.
Emmits `message` when a message arrives.
### TelegramBot.getMe() See: https://core.telegram.org/bots/api
### Params:
* **String** *token* Bot Token
* **Object** *[options]*
* **Boolean|Object** *[options.polling=false]* Set true to enable polling
* **String|Number** *[options.polling.timeout=4]* Polling time
* **Boolean|Object** *[options.webHook=false]* Set true to enable WebHook
* **String** *[options.webHook.key]* PEM private key to webHook server
* **String** *[options.webHook.cert]* PEM certificate key to webHook server
## getMe()
Returns basic information about the bot in form of a `User` object. Returns basic information about the bot in form of a `User` object.
**Returns**: `Promise` ### Return:
### TelegramBot.setWebHook(url) * **Promise**
## setWebHook(url)
Specify a url to receive incoming updates via an outgoing webHook. Specify a url to receive incoming updates via an outgoing webHook.
**Parameters** ### Params:
**url**: `String`, URL * **String** *url* URL
## getUpdates([timeout], [limit], [offset])
### TelegramBot.getUpdates(timeout, limit, offset)
Use this method to receive incoming updates using long polling Use this method to receive incoming updates using long polling
**Parameters** See: https://core.telegram.org/bots/api#getupdates
**timeout**: `Number | String`, Timeout in seconds for long polling. ### Params:
**limit**: `Number | String`, Limits the number of updates to be retrieved. * **Number|String** *[timeout]* Timeout in seconds for long polling.
* **Number|String** *[limit]* Limits the number of updates to be retrieved.
* **Number|String** *[offset]* Identifier of the first update to be returned.
**offset**: `Number | String`, Identifier of the first update to be returned. ### Return:
**Returns**: `Promise`, Updates * **Promise** Updates
### TelegramBot.sendMessage(chatId, text, options) ## sendMessage(chatId, text, [options])
Send text message. Send text message.
**Parameters** See: https://core.telegram.org/bots/api#sendmessage
**chatId**: `Number | String`, Unique identifier for the message recipient ### Params:
**text**: `Sting`, Text of the message to be sent * **Number|String** *chatId* Unique identifier for the message recipient
* **Sting** *text* Text of the message to be sent
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options ### Return:
**Returns**: `Promise` * **Promise**
### TelegramBot.forwardMessage(chatId, fromChatId, messageId) ## forwardMessage(chatId, fromChatId, messageId)
Forward messages of any kind. Forward messages of any kind.
**Parameters** ### Params:
**chatId**: `Number | String`, Unique identifier for the message recipient * **Number|String** *chatId* Unique identifier for the message recipient
* **Number|String** *fromChatId* Unique identifier for the chat where the original message was sent
* **Number|String** *messageId* Unique message identifier
**fromChatId**: `Number | String`, Unique identifier for the chat where the ### Return:
original message was sent
**messageId**: `Number | String`, Unique message identifier * **Promise**
**Returns**: `Promise` ## sendPhoto(chatId, photo, [options])
### TelegramBot.sendPhoto(chatId, photo, options)
Send photo Send photo
**Parameters** See: https://core.telegram.org/bots/api#sendphoto
**chatId**: `Number | String`, Unique identifier for the message recipient ### Params:
**photo**: `String | stream.Stream`, A file path or a Stream. Can * **Number|String** *chatId* Unique identifier for the message recipient
also be a `file_id` previously uploaded * **String|stream.Stream** *photo* A file path or a Stream. Can also be a `file_id` previously uploaded
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options ### Return:
**Returns**: `Promise` * **Promise**
### TelegramBot.sendAudio(chatId, audio, options) ## sendAudio(chatId, audio, [options])
Send audio Send audio
**Parameters** See: https://core.telegram.org/bots/api#sendaudio
**chatId**: `Number | String`, Unique identifier for the message recipient ### Params:
**audio**: `String | stream.Stream`, A file path or a Stream. Can * **Number|String** *chatId* Unique identifier for the message recipient
also be a `file_id` previously uploaded. * **String|stream.Stream** *audio* A file path or a Stream. Can also be a `file_id` previously uploaded.
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options ### Return:
**Returns**: `Promise` * **Promise**
* * *

View File

@ -13,8 +13,9 @@ var fs = require('fs');
var requestPromise = Promise.promisify(request); var requestPromise = Promise.promisify(request);
/** /**
* NodeJS class for Telegram Bot API. Support for WebHooks and long polling. Emits `message` when * Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
* message arrives. * on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a valid (not self signed) SSL certificate.
* Emmits `message` when a message arrives.
* *
* @class TelegramBot * @class TelegramBot
* @constructor * @constructor