Node-telegram-bot-api: callback query repeated problem

Created on 22 Dec 2016  路  2Comments  路  Source: yagop/node-telegram-bot-api

I've this code

var TelegramBot = require('node-telegram-bot-api');
moment = require('moment');
_ = require("underscore");
var bot = new TelegramBot("xxxxxxxxxxxxxxx", { polling: true });

bot.onText(/\/assenti/, function (msg) {
    bot.sendMessage(msg.chat.id, "Scegli il giorno", {
        reply_markup: {
            inline_keyboard: [[{
                text: "Oggi",
                callback_data: "0",
            }, {
                    text: "Domani",
                    callback_data: "1",
                }]],
        },
    });
    bot.on("callback_query", function (callbackQuery) {
            // 'callbackQuery' is of type CallbackQuery
            console.log(callbackQuery);
              bot.editMessageText(t, { chat_id: callbackQuery.message.chat.id, message_id: callbackQuery.message.message_id });

        })
    });
});

the problem is that when I call the command /assenti the second ot third time etc... the reply occours 2, 3 ... times

can you help me?

thanks
lenny

All 2 comments

You are calling bot.on() everytime the regexp callback (the onText() callback) is invoked! This means that each and every single time, you are adding a new listener for "callback_query"! Your logic is flawed!

@GochoMugo so tell us a logic that is not flawed!!!
not only say that "it`s flawed",then if we knew that we never asked it!
thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rezania815 picture Rezania815  路  3Comments

kenanchristian picture kenanchristian  路  4Comments

hems picture hems  路  3Comments

alikhil picture alikhil  路  3Comments

abbddo picture abbddo  路  3Comments