Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!