Hi there, it's a really awesome bot you make :)
I can't seem to find a way to override bot.on('text') event with a specific text.
Something like bot.on(/hello/i) still gives me response from bot.on(text).
That would be bot.onText() not bot.on()!
so this is my code
bot.on('text', function (msg) {
var chatId = msg.chat.id;
bot.sendMessage(chatId, 'hello text text');
});
bot.onText(/\/ping/i, function(msg){
let chatId = msg.chat.id;
bot.sendMessage(chatId,"pong");
})
when i use /ping command on telegram, it also sends hello text text
which one should be onText and which one should be on?
The two methods are not exclusive. If the bot receives a text message, it always fires the text event (see src/telegram.js#L95). It then fires the corresponding callbacks for all matching regexps (see src/telegram.js#L106).
Closing with an accepted answer.
If the answer does not satisfy you, please reopen with more elaborate details and follow-up questions.
Most helpful comment
The two methods are not exclusive. If the bot receives a text message, it always fires the
textevent (see src/telegram.js#L95). It then fires the corresponding callbacks for all matching regexps (see src/telegram.js#L106).