V
V
Vitaly the Wise2017-08-03 10:40:50
Node.js
Vitaly the Wise, 2017-08-03 10:40:50

How to write attachments message handler in telegram bot?

Hello. I am writing a simple telegram bot. There is a small problem. Here is the code:

bot.onText(/\/test/, function(msg) {
    const { from: { id } } = msg;
    const { text } = msg;
    const _bot = bot;

    _bot.sendMessage(id, text);
    _bot.onText(/(.+)/, function(msg) {
        console.log(msg);

        _bot.onText(/(.+)/, function() {});
    });
});

When I write /test, this code works and the bot answers me with the same message (that is, the bot asks me something). Then I answer and the message is displayed in the console. Ideally, it should exit this handler and simply shouldn't go there without the /test command. But if I write any message, it will print it to the console again. How can this be fixed? Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-08-03
@emp1re

if I understand you correctly

bot.onText((msg) => {
if (msg.text.toLowerCase().includes('/test')) {...}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question