mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 21:07:39 +00:00
Added onlyFirstMatch option
This commit is contained in:
parent
00d74d13c8
commit
0fb142f6ac
@ -114,6 +114,7 @@ Emits `message` when a message arrives.
|
|||||||
| [options.webHook] | <code>Boolean</code> | <code>Object</code> | <code>false</code> | Set true to enable WebHook or set options |
|
| [options.webHook] | <code>Boolean</code> | <code>Object</code> | <code>false</code> | Set true to enable WebHook or set options |
|
||||||
| [options.webHook.key] | <code>String</code> | | PEM private key to webHook server. |
|
| [options.webHook.key] | <code>String</code> | | PEM private key to webHook server. |
|
||||||
| [options.webHook.cert] | <code>String</code> | | PEM certificate (public) to webHook server. |
|
| [options.webHook.cert] | <code>String</code> | | PEM certificate (public) to webHook server. |
|
||||||
|
| [options.onlyFirstMatch] | <code>Boolean</code> | <code>false</code> | false: try matching all regexps; true: stop after first match |
|
||||||
|
|
||||||
<a name="TelegramBot+stopPolling"></a>
|
<a name="TelegramBot+stopPolling"></a>
|
||||||
|
|
||||||
@ -537,7 +538,7 @@ username of a user, group or channel, etc.).
|
|||||||
|
|
||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
|
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel |
|
||||||
|
|
||||||
<a name="TelegramBot+getChatAdministrators"></a>
|
<a name="TelegramBot+getChatAdministrators"></a>
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class TelegramBot extends EventEmitter {
|
|||||||
* @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options
|
* @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options
|
||||||
* @param {String} [options.webHook.key] PEM private key to webHook server.
|
* @param {String} [options.webHook.key] PEM private key to webHook server.
|
||||||
* @param {String} [options.webHook.cert] PEM certificate (public) to webHook server.
|
* @param {String} [options.webHook.cert] PEM certificate (public) to webHook server.
|
||||||
|
* @param {Boolean} [options.onlyFirstMatch=false] Set to true to stop after first match. Otherwise, all regexps are executed
|
||||||
* @see https://core.telegram.org/bots/api
|
* @see https://core.telegram.org/bots/api
|
||||||
*/
|
*/
|
||||||
constructor(token, options = {}) {
|
constructor(token, options = {}) {
|
||||||
@ -99,12 +100,14 @@ class TelegramBot extends EventEmitter {
|
|||||||
TelegramBot.messageTypes.forEach(processMessageType);
|
TelegramBot.messageTypes.forEach(processMessageType);
|
||||||
if (message.text) {
|
if (message.text) {
|
||||||
debug('Text message');
|
debug('Text message');
|
||||||
this.textRegexpCallbacks.forEach(reg => {
|
this.textRegexpCallbacks.some(reg => {
|
||||||
debug('Matching %s whith', message.text, reg.regexp);
|
debug('Matching %s whith', message.text, reg.regexp);
|
||||||
const result = reg.regexp.exec(message.text);
|
const result = reg.regexp.exec(message.text);
|
||||||
if (result) {
|
if (result) {
|
||||||
debug('Matches', reg.regexp);
|
debug('Matches', reg.regexp);
|
||||||
reg.callback(message, result);
|
reg.callback(message, result);
|
||||||
|
// returning truthy value exits .some
|
||||||
|
return this.options.onlyFirstMatch;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user