mullwar / telebot

The easy way to write Telegram bots in Node.js
https://www.npmjs.com/package/telebot
MIT License
1.48k stars 270 forks source link

namedButtons don't work for multiple users #238

Closed xyhtac closed 1 year ago

xyhtac commented 1 year ago

Can't make namedButtons keyboard work for all users.

Reproduce:

Step 1. Attach some bot.keyboard markup using namedButtons plugin to the reply message for /start command listener:

const BUTTONS = {
    left: {
        label: "Left Button",
        command: '/leftbutton'
    },
    right: {
        label: "Right Button",
        command: '/rightbutton'
    }
};
bot.on('/start', msg => {
    let replyMarkup = bot.keyboard([
        [ BUTTONS.left.label, BUTTONS.right.label  ]
    ], {resize: true});         
    return bot.sendMessage( msg.from.id, "Keyboard loaded", {replyMarkup} );
});

Step 2. Send /start from TG user 1. Buttons are loaded and working fine for user 1. Step 3. Send /start from TG user 2. Buttons are loaded and working fine for user 2 and not working for user 1 anymore.

Is it a bug or did i miss something? Regards.

xyhtac commented 1 year ago

Not a bug, just a lack of documentation.

If you are planning to change buttons dynamically, you need to define all possible commands in BUTTONS object and pass it to the module configuration. Then you will be able to redefine keyboard for any arbitrary user leaving other previously defined keyboards operational - as long as these buttons actually present in the configured BUTTONS object.

Hope this helps.