Node-telegram-bot-api: Override text event with specific text

Created on 27 Aug 2016  路  4Comments  路  Source: yagop/node-telegram-bot-api

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).

Most helpful comment

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).

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saeedhei picture saeedhei  路  4Comments

FerX picture FerX  路  4Comments

dimawebmaker picture dimawebmaker  路  3Comments

qunatumwhiskey picture qunatumwhiskey  路  4Comments

lenny76 picture lenny76  路  3Comments