2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-28 12:57:38 +00:00

Updated Readme

This commit is contained in:
Yago 2015-10-10 18:09:25 +02:00
parent cfd32f47bf
commit 430adbba7f
3 changed files with 36 additions and 8 deletions

View File

@ -12,7 +12,15 @@ var TelegramBot = require('node-telegram-bot-api');
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
// Setup polling way
var bot = new TelegramBot(token, {polling: true});
bot.on('text', function (msg) {
bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id;
var resp = match[1];
bot.sendMessage(fromId, resp);
});
// Any kind of message
bot.on('message', function (msg) {
var chatId = msg.chat.id;
// photo can be: a file path, a stream or a Telegram file_id
var photo = 'cats.png';

View File

@ -12,7 +12,15 @@ var TelegramBot = require('node-telegram-bot-api');
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
// Setup polling way
var bot = new TelegramBot(token, {polling: true});
bot.on('text', function (msg) {
bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id;
var resp = match[1];
bot.sendMessage(fromId, resp);
});
// Any kind of message
bot.on('message', function (msg) {
var chatId = msg.chat.id;
// photo can be: a file path, a stream or a Telegram file_id
var photo = 'cats.png';
@ -64,6 +72,7 @@ TelegramBot
* [.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)
<a name="new_TelegramBot_new"></a>
### new TelegramBot(token, [options])
@ -305,4 +314,15 @@ This is just a sugar for (getFile)[#getfilefiled] method
| 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 |
<a name="TelegramBot+onText"></a>
### 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. |
* * *

View File

@ -489,13 +489,13 @@ TelegramBot.prototype.downloadFile = function(fileId, downloadDir) {
};
/**
* Register a RegExp to test against an incomming text message
* @param {RegExp} regexp [RegExp to be executed with `exec`]
* @param {Function} fn [Callback receives 2 parameters, the msg and the
* result of executing `regexp.exec` on message text]
* Register a RegExp to test against an incomming text message.
* @param {RegExp} regexp RegExp to be executed with `exec`.
* @param {Function} callback Callback will be called with 2 parameters,
* the `msg` and the result of executing `regexp.exec` on message text.
*/
TelegramBot.prototype.onText = function (regexp, fn) {
this.textRegexpCallbacks.push({regexp: regexp, callback: fn});
TelegramBot.prototype.onText = function (regexp, callback) {
this.textRegexpCallbacks.push({regexp: regexp, callback: callback});
};
module.exports = TelegramBot;