1

How to limit access so the inline buttons don't show up for all users in a group? If it's not possible, what's the best alternative to allow admins to click which sends a command in the chat as the admin himself replying or posting.

Either only the user currently pressing the buttons or all admins?

  • The bot will show the buttons to all users regardless of if they are admin or not
  • The non admin users can click the buttons and the reply is given in the chat but no bot action is taken, it's ignored
  • If the admin selects any buttons the non admins can see the button menu change in realtime too

How do I stop non admins from seeing the menu at all? or limiting it to the current user interacting with it only?

Here's my code:


const main = (ctx) => {
    if( ctx.from._is_in_admin_list ){
    return ctx.reply('Select your audio list', Keyboard.reply(['Controls'], { columns: 1 }))
}
else {
}
}

bot.use(function(ctx, next){
    if( ctx.chat.id > 0 ) return next();
        return bot.telegram.getChatAdministrators(ctx.chat.id)
        .then(function(data){
            if( !data || !data.length ) return;
            console.log('admin list:', data);
            ctx.chat._admins = data;
            ctx.from._is_in_admin_list = data.some( adm => adm.user.id === ctx.from.id );
        })
        .catch(console.log)
        .then(_ => next(ctx));
});

bot.start(main)
bot.hears('Back', main)
bot.hears('Controls', (ctx) => {
    if( ctx.from._is_in_admin_list ){
    const keyboard = Keyboard.make(["/stop","/pause","/resume","/skip"], { columns: 2 })
    return ctx.reply('Controls menu selected', Keyboard.combine(keyboard, backKeyboard).reply())
}
else {
//do nothing
}
})

bot.launch()

0 Answers0