umputun / tg-spam

Anti-Spam bot for Telegram and anti-spam library
https://tg-spam.umputun.dev
MIT License
221 stars 39 forks source link

Does not support admin users w/o assigned @username #136

Closed johnd0e closed 1 month ago

johnd0e commented 1 month ago

Also tried to forward spam message to admin group - also no reaction.

The same one more time after bot restart - no reaction.

I'm admin of the group, and my user id is also stated in bot's --admin option.

The relevant part of the log (alexxis1999 is the spammer):

2024/10/11 16:38:54.818 [INFO] user "alexxis1999" (6301007238) added to approved users 2024/10/11 17:13:58.122 [WARN] failed to send message as markdown, Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 35 2024/10/11 19:03:54.669 [WARN] interrupt signal 2024/10/11 19:03:54.669 [ERROR] telegram listener failed, context canceled 2024/10/11 19:03:54.669 [ERROR] telegram listener failed, context canceled

stack trace: main.main() /build/app/main.go:169 +0x5b8 tg-spam master-acabef3-20241008T21:32:41 2024/10/11 19:03:55.743 [WARN] dynamic files dir "/srv/data" is not mounted, changes will be lost on container restart 2024/10/11 19:03:58.444 [INFO] loaded samples - spam: 182, ham: 438, excluded tokens: 279, stop-words: 11 2024/10/11 19:03:58.446 [INFO] basic auth enabled for webapi server 2024/10/11 19:03:58.446 [INFO] start webapi server on :8080 2024/10/11 19:03:58.476 [INFO] logger enabled for /srv/logs/tg-spam.log, max size 5M 2024/10/11 19:03:58.476 [INFO] start telegram listener for "FarManager" 2024/10/11 19:03:58.611 [INFO] added admins, full list of supers: {897129600, Paul_E_Smith, tgspamfarmanagerbot} 2024/10/11 19:03:58.611 [INFO] admin chat ID: -4595886163

umputun commented 1 month ago

The log doesn't provide much useful info as WARN itself is not the issue. For some messages, tg-spam may fail to send as markdown and should switch to plain text as a fallback. You may want to run it with --dbg, and this will provide more info.

johnd0e commented 1 month ago
2024/10/14 11:04:30.375 [DEBUG] {events/listener.go:348 events.(*TelegramListener).isAdminChat} message in admin chat -4595886163, from
2024/10/14 11:04:30.375 [DEBUG] {events/listener.go:350 events.(*TelegramListener).isAdminChat} is not superuser in admin chat, ignored

For whatever reason it does not type the name of my user. And obviously I am the owner of the admin chat.

umputun commented 1 month ago

your user should be defined in the list of "super-users" in addition to TG related permissions

--super= super-users [$SUPER_USER]

johnd0e commented 1 month ago

@umputun

And my user is defined, by its numerical id (as it has no nick)

In either way this is not the reason that user's name/id in the log is empty.

P.S.

Also I see this statement:

super defines the list of privileged users, can be repeated multiple times or provide as a comma-separated list in the environment. Those users are immune to spam detection and can also unban other users. All the admins of the group are privileged by default.

https://github.com/umputun/tg-spam/blob/master/README.md#application-options-in-details

umputun commented 1 month ago

Unfortunately, the log lines you pasted seem to be truncated, so I can't see much information here. Regarding your correction - yes, you are correct; I completely forgot the part that adds all admins to supers automatically.

Without seeing more details from the logs, it is hard to say what's going on. I can speculate this is related to the privacy settings of TG, and you may need to disable privacy mode for the bot.

johnd0e commented 1 month ago

I can speculate this is related to the privacy settings of TG, and you may need to disable privacy mode for the bot.

I do not agree that this is the case here. The state of privacy mode does not matter when the bot has admin rights. Furthermore, it affects whether the bot receives messages or not. In this instance, it is clear that the bot is receiving messages, as evidenced by the reactions in the logs.

Nevertheless, I followed the suggestion, but unfortunately, it was unsuccessful.

Unfortunately, the log lines you pasted seem to be truncated.

I am fairly certain that they are not truncated. I consistently receive this type of message in this form. If there are any suggestions on how to obtain complete, untruncated logs, I would appreciate it.

I completely forgot the part that adds all admins to supers automatically.

How can I verify whether that part is functioning correctly? When I run the bot without the --admin option, I see the following log entry:

2024/10/15 14:47:56.477 [INFO]  {events/listener.go:435 events.(*TelegramListener).updateSupers} added admins, full list of supers: {tgspamfarmanagerbot}
johnd0e commented 1 month ago

It seems that I've found the culprit:

And my user is defined, by its numerical id (as it has no nick)

After I've take tg username the problem is gone:

2024/10/15 14:53:49.702 [INFO]  {events/listener.go:435 events.(*TelegramListener).updateSupers} added admins, full list of supers: {tgspamfarmanagerbot, real_johnd0e}
2024/10/15 14:54:38.450 [DEBUG] {events/admin.go:64 events.(*admin).MsgHandler} message from admin chat: msg id: 14, update id: 223500437, from: real_johnd0e, sender: ""
umputun commented 1 month ago

I don't think this is a bug; it is just what the system is designed to do. Maybe it's worth clarifying in the README, but I don't recall any place where it promised to support either name or ID.

I will move this to FAQ discussions, so if others run into the same issue, they will see the fix.