mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 05:17:41 +00:00
Updated Readme
This commit is contained in:
parent
cfd32f47bf
commit
430adbba7f
10
README.hbs
10
README.hbs
@ -12,7 +12,15 @@ var TelegramBot = require('node-telegram-bot-api');
|
|||||||
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||||
// Setup polling way
|
// Setup polling way
|
||||||
var bot = new TelegramBot(token, {polling: true});
|
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;
|
var chatId = msg.chat.id;
|
||||||
// photo can be: a file path, a stream or a Telegram file_id
|
// photo can be: a file path, a stream or a Telegram file_id
|
||||||
var photo = 'cats.png';
|
var photo = 'cats.png';
|
||||||
|
22
README.md
22
README.md
@ -12,7 +12,15 @@ var TelegramBot = require('node-telegram-bot-api');
|
|||||||
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||||
// Setup polling way
|
// Setup polling way
|
||||||
var bot = new TelegramBot(token, {polling: true});
|
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;
|
var chatId = msg.chat.id;
|
||||||
// photo can be: a file path, a stream or a Telegram file_id
|
// photo can be: a file path, a stream or a Telegram file_id
|
||||||
var photo = 'cats.png';
|
var photo = 'cats.png';
|
||||||
@ -64,6 +72,7 @@ TelegramBot
|
|||||||
* [.getFile(fileId)](#TelegramBot+getFile) ⇒ <code>Promise</code>
|
* [.getFile(fileId)](#TelegramBot+getFile) ⇒ <code>Promise</code>
|
||||||
* [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ <code>Promise</code>
|
* [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ <code>Promise</code>
|
||||||
* [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ <code>Promise</code>
|
* [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ <code>Promise</code>
|
||||||
|
* [.onText(regexp, callback)](#TelegramBot+onText)
|
||||||
|
|
||||||
<a name="new_TelegramBot_new"></a>
|
<a name="new_TelegramBot_new"></a>
|
||||||
### new TelegramBot(token, [options])
|
### 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 |
|
| 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 |
|
| 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. |
|
||||||
|
|
||||||
* * *
|
* * *
|
||||||
|
@ -489,13 +489,13 @@ TelegramBot.prototype.downloadFile = function(fileId, downloadDir) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a RegExp to test against an incomming text message
|
* Register a RegExp to test against an incomming text message.
|
||||||
* @param {RegExp} regexp [RegExp to be executed with `exec`]
|
* @param {RegExp} regexp RegExp to be executed with `exec`.
|
||||||
* @param {Function} fn [Callback receives 2 parameters, the msg and the
|
* @param {Function} callback Callback will be called with 2 parameters,
|
||||||
* result of executing `regexp.exec` on message text]
|
* the `msg` and the result of executing `regexp.exec` on message text.
|
||||||
*/
|
*/
|
||||||
TelegramBot.prototype.onText = function (regexp, fn) {
|
TelegramBot.prototype.onText = function (regexp, callback) {
|
||||||
this.textRegexpCallbacks.push({regexp: regexp, callback: fn});
|
this.textRegexpCallbacks.push({regexp: regexp, callback: callback});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = TelegramBot;
|
module.exports = TelegramBot;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user