node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

My bot can't get 'new_chat_members' event - only working for bots created with botfather for testing, not real users

Open bluetyphoon77 opened this issue 1 year ago • 35 comments

Hi guyz, My bot can't get 'new_chat_members' event - only working with test-bots created on my account with botfather for testing, not with real users joining the group. Any idea why ???

I use the bot.on('new_chat_members', (msg) => { ...

Thanks in advance for your advices @VDS13 @Sidelux Could you help ? thanks in advance Y.

bluetyphoon77 avatar Jan 08 '24 21:01 bluetyphoon77

Hello. Are administrator rights granted to the bot?

VDS13 avatar Jan 09 '24 19:01 VDS13

Without administrator rights, it does not track this event.

VDS13 avatar Jan 09 '24 19:01 VDS13

Hi @VDS13 😊🙏 thanks for your answer. My bot is already Admin in the group where I added it. You mean I have to set something in botfather?

And do you know why it works perfectly for test bots created under my account and joining the group, but not with other users?

bluetyphoon77 avatar Jan 09 '24 20:01 bluetyphoon77

Hello. Are administrator rights granted to the bot?

Yes they already are

bluetyphoon77 avatar Jan 10 '24 01:01 bluetyphoon77

Is the group public or private?

VDS13 avatar Jan 10 '24 04:01 VDS13

@VDS13 Hey Dmitry, it is public

bluetyphoon77 avatar Jan 10 '24 10:01 bluetyphoon77

Strange. Let's summarize: a bot with administrator rights, a public group, not a supergroup, new_chat_members works on your bots, but not on users?

VDS13 avatar Jan 10 '24 11:01 VDS13

yes exactly ! i agree it is weird :) here is the group: https://t.me/Souffles_Magiques

bluetyphoon77 avatar Jan 10 '24 11:01 bluetyphoon77

Show a piece of code from the beginning to the new_chat_members event handler.

VDS13 avatar Jan 10 '24 11:01 VDS13

bot.on('new_chat_members', (msg) => { console.log(msg) } });

nothing is coming. I want channel id through my bot like https://t.me/username_to_id_bot bot is doing.

dev-anshu avatar Jan 11 '24 05:01 dev-anshu

There are no others in the code before this handler (let's say bot.on('message', ...))?

VDS13 avatar Jan 11 '24 05:01 VDS13

const TelegramBot = require('node-telegram-bot-api'); const token = '<bot_token>';

const bot = new TelegramBot(token, { polling: true }); bot.on('message', (msg) => { console.log(msg) } });

I am trying to get channel_id when my bot joins any channel. how can I do it? can you give me any solution

dev-anshu avatar Jan 11 '24 06:01 dev-anshu

If your message handler comes before new_chat_members, then try swapping them. That is:

const TelegramBot = require('node-telegram-bot-api');
const token = '<bot_token>';

const bot = new TelegramBot(token, { polling: true });
bot.on('new_chat_members', (msg) => {
     console.log(msg)
});
bot.on('message', (msg) => {
     console.log(msg)
});

VDS13 avatar Jan 11 '24 06:01 VDS13

Still not working, I am getting message when i send to bot, but while adding bot to any channel I am not getting any channel_id, new-chat_members not working. This is working for groups but not channels.

dev-anshu avatar Jan 11 '24 07:01 dev-anshu

Hi @VDS13 Here is a test code using what I use:

import TelegramBot from 'node-telegram-bot-api';

// Replace 'YOUR_BOT_TOKEN' with your actual bot token const bot = new TelegramBot('xxxxxxxxxxxxxxx', { polling: true });

// Event handler for new chat members bot.on('new_chat_members', (msg) => { console.log('New user event triggered'); console.log('New chat members:', msg.new_chat_members);

// Process new members processNewMembers(msg.new_chat_members); });

// Function to process new members const processNewMembers = (newMembers) => { newMembers.forEach((member) => { console.log('New member:', member); // Perform any additional processing here }); };

// Event handler for messages bot.on('message', (msg) => { console.log('Received message:', msg.text); });

// Start the bot console.log('Bot is running...');

bluetyphoon77 avatar Jan 11 '24 11:01 bluetyphoon77

Obviously I'm not the only one with this problem. Telegram maybe changed something and your event handler has to be updated ?

bluetyphoon77 avatar Jan 11 '24 11:01 bluetyphoon77

@dev-anshu for me adding a test bot created with botfather is working ! Event is triggerd. But any other bot or real user not.

bluetyphoon77 avatar Jan 11 '24 11:01 bluetyphoon77

that's weird, anyway you can try go to botFather, use /mybots -> select your bot -> Gruop Privacy -> Turn off

Sp3rick avatar Jan 13 '24 15:01 Sp3rick

Hi @Sp3rick Thanks for your help. I did it but it did not work.

@VDS13 Do you, or anyone reading this, succeed with the code i provided in a group of yours ?

Are you sure events from library are up to date?

bluetyphoon77 avatar Jan 13 '24 23:01 bluetyphoon77

Is there any dev knowing if the code is still working ? @yagop @GochoMugo @kamikazechaser @danielperez9430 ? Cheeers

bluetyphoon77 avatar Jan 17 '24 21:01 bluetyphoon77

image

Source: https://core.telegram.org/bots/api-changelog#april-26-2021

danielperez9430 avatar Jan 17 '24 22:01 danielperez9430

So now, use "chat_member" for know if user join or left.

This warning is from 3 years ago, so maybe now is deprecated for normal users.

danielperez9430 avatar Jan 17 '24 22:01 danielperez9430

So now, use "chat_member" for know if user join or left.

This warning is from 3 years ago, so maybe now is deprecated for normal users.

You can try the following, it works for me. It detects both input and output in groups.

let TelegramBot = require('node-telegram-bot-api');
let bot = new TelegramBot('YOUR_TOKEN', { "polling": true })

bot.on('chat_member', (memberStatus) => {
  console.log(memberStatus)
})

solution_event_new_members

This code would return something similar to the following image

output_similar_edit

IscoV avatar Jan 17 '24 22:01 IscoV

Thanks for your answers @danielperez9430 and @IscoV 😊👍 I just used your code @IscoV but bot does not see nor any user nor any bot now.

When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes? Cheers

Ps: node-telegram-bot version is 0.64.0

bluetyphoon77 avatar Jan 19 '24 00:01 bluetyphoon77

I used:

let TelegramBot = require ('node-telegram-bot-api');

// Replace 'YOUR_BOT_TOKEN' with your actual bot token let bot = new TelegramBot('XXXX', { polling: true });

// Event handler for new chat members bot.on('chat_member', (memberStatus) => { console.log('User event triggered'); //console.log(memberStatus); let {chat, from, date, old_chat_member, new_chat_member } = memberStatus; console.log("Chat: ", chat); console.log("From: ", from); console.log("Date: ", date); console.log("Old Member: ", old_chat_member); console.log("New Member: ", new_chat_member);

});

// Start the bot console.log('Bot is running...');

bluetyphoon77 avatar Jan 19 '24 00:01 bluetyphoon77

Thanks for your answers @danielperez9430 and @IscoV 😊👍 I just used your code @IscoV but bot does not see nor any user nor any bot now.

When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes? Cheers

Ps: node-telegram-bot version is 0.64.0

At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.

IscoV avatar Jan 19 '24 09:01 IscoV

Thanks for your answers @danielperez9430 and @IscoV 😊👍 I just used your code @IscoV but bot does not see nor any user nor any bot now. When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes? Cheers Ps: node-telegram-bot version is 0.64.0

At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.

@IscoV Yes yes, I'm talking about this. I added a bot and a user joined for testing. Nothing shows. Have you tested it now on your group ?

bluetyphoon77 avatar Jan 19 '24 22:01 bluetyphoon77

Thanks for your answers @danielperez9430 and @IscoV 😊👍 I just used your code @IscoV but bot does not see nor any user nor any bot now. When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes? Cheers Ps: node-telegram-bot version is 0.64.0

At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.

@IscoV Yes yes, I'm talking about this. I added a bit and a user joined for testing. Nothing shows. Have you tested it now on your group ?

I tested it before sending it. Else, try to enable the update manually.

Paste the following URL in your browser and replace the YOUR_BOT_TOKEN

https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates?allowed_updates=["update_id","message","edited_message","channel_post","edited_channel_post","inline_query","chosen_inline_result","callback_query","shipping_query","pre_checkout_query","poll","poll_answer","my_chat_member","chat_member"]

IscoV avatar Jan 20 '24 18:01 IscoV

'new_chat_members' event sometimes works, sometimes it doesn't

nguyennhukhanh avatar Jan 23 '24 06:01 nguyennhukhanh

'new_chat_members' event sometimes works, sometimes it doesn't

You too? Is there any dev who is planning to fix this? Do you know a library that works for this? Better not lose more time if it seems so complex to have a fix for node telegram bot .

bluetyphoon77 avatar Jan 29 '24 11:01 bluetyphoon77