Node-telegram-bot-api: How to invoke the bot when mentioning it?

Created on 7 Mar 2017  路  2Comments  路  Source: yagop/node-telegram-bot-api

Hello guys! I have a doubt!
I would like to invoke the bot by mentioning it
Ex: @bot and it responds me with a default message

question

Most helpful comment

Thanks @GochoMugo but only works without individual chat with the bot, when the mentioned in group chat happens

All 2 comments

I have understood your use case as sth like this:

default-message

You would just have to look at the message's text. For example,

bot.on("message", function(message) {
    console.log(message.text); // => @botname
    // checking that the text only includes mention of the bot i.e. @botname
    // this can be improved of course to satisfy your use case! 
    const match = /^@\w+$/.exec(message.text.trim());
    if (match) {
        bot.sendMessage(message.chat.id, "default message");
    }
});

Thanks @GochoMugo but only works without individual chat with the bot, when the mentioned in group chat happens

Was this page helpful?
0 / 5 - 0 ratings