Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda