Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
Telegraf: After restricting permissions, my bot won't grant posting abilities back

I'm struggling to understand where I've gone wrong here so I'm looking for some extra eyes. I'm using Telegraf to make a Telegram bot in NodeJS. When a new user logs in, it should restrict them from being able to post anything until they answer a simple Captcha-style question. Assuming they answer correctly, they should be granted to ability to post again. If they answer incorrectly, they are kicked from the group.

Everything seems to be coming together except the part where the user is given back the ability to post after answering correctly. My understanding is restrictChatMember can be passed "true" for permissions you want to allow, but it's not working. What else am I missing?

bot.on('new_chat_members', (ctx) => {
  newMember = ctx.message.new_chat_members[0].id;
  newMemberName = ctx.message.new_chat_members[0].first_name;
  bot.telegram.restrictChatMember(ctx.chat.id, newMember);
  const keyboard = Keyboard.make([
    Key.callback('Answer1', 'Fail'),
    Key.callback('Answer2', 'Fail'),
    Key.callback('Answer3', 'Pass'),
    Key.callback('Answer4', 'Fail'),
    Key.callback('Answer5', 'Fail'),
  ]).inline();
    bot.telegram.sendMessage(ctx.chat.id, `Hello, ${newMemberName}!\nYou can post once You select Answer3`, keyboard).then(
        ({ message_id }) => { spamBlocker = message_id; });
});

bot.on("callback_query", function(callbackQuery) {
  let chatID = callbackQuery.update.callback_query.message.chat.id;
  if (callbackQuery.update.callback_query.data == "Pass") {
    bot.telegram.deleteMessage(chatID, spamBlocker);
    bot.telegram.restrictChatMember(chatID, newMember, [true, true, true, true]);
    bot.telegram.sendMessage(chatID, `${newMemberName}, ${welcomeMessage}`)
  } else {
    bot.telegram.kickChatMember(chatID, newMember);
    bot.telegram.deleteMessage(chatID, spamBlocker);
  }
});

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Thanks to the help of a kind stranger on the CodingHelp Discord, I was able to arrive at the following solution. The issue is restrictChatMember takes a chat ID, a member ID, and an object. The object takes key pairs (obvious in hind sight), so you tell it "can_send_messages": true, for example, and keep going for each line.

In my case, change this line:

bot.telegram.restrictChatMember(chatID, newMember, [true, true, true, true]);

to this:

bot.telegram.restrictChatMember(chatID, newMember, {"can_send_messages": true, "can_send_media_messages": true, "can_send_other_messages": true, "can_add_web_page_previews": true});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda