J-Rios / TLG_JoinCaptchaBot

Telegram Bot to verify if users joining a group are human. The Bot sends an image captcha for each new user and kicks any of them who can't solve the captcha in a specified time.
GNU General Public License v3.0
515 stars 217 forks source link

[Bug] Bot not sending silent messages #118

Closed J-Rios closed 2 years ago

J-Rios commented 2 years ago

Bot not sending silent messages

Description

Bot should be sending the messages in silent mode (it was done as feature some time ago), but it seems it is not happening.

Context

The Bot is initialized with disable_notification option set to true, and that should makes all send messages to be silent.

We need to check all documentation regarding Bot API and python-telegram-bot framework (also check for issues there), and check if it occurs in all devices (desktop, Android, IOS, etc.) or it is just happening depending the Telegram client that the users uses.

J-Rios commented 2 years ago

Related

https://github.com/J-Rios/TLG_JoinCaptchaBot/pull/35 https://github.com/J-Rios/TLG_JoinCaptchaBot/issues/33 https://github.com/J-Rios/TLG_JoinCaptchaBot/issues/71

J-Rios commented 2 years ago

From Telegram Bot API

There is the disable_notification parameter that can be use in any of the send message/photo/video/audio/etc. requests:

disable_notification (Boolean, Optional) Sends the message silently. Users will receive a notification with no sound.

So, when disable_notifications is set to true, the notification is shown, but no sound will fire.

From python-telegram-bot Framework

They include this parameter to all of send requests functions. Also, they add a defaults parameter in Updater element to setup the defaults parameters values that must be used when it is not explicitly set in the send function call:

defaults (telegram.ext.Defaults, optional) – An object containing default values to be used if not set explicitly in the bot methods.

This last thing is what we have used, and maybe the assumption of using that defaults to setup the disable_notification for all the messages are not working properly?

Marzal commented 2 years ago

Tested in Android Telegram Direct 7.9.3 and Telegram Desktop 2.9.4 beta (Linux), both have sound.

J-Rios commented 2 years ago

Found the issue. After I made some refactoring some time ago to isolate telegram request functions in another file (tlgbotutils.py), I was explicitly setting the disable_notification to False instead True...

Should be fixed with this change: https://github.com/J-Rios/TLG_JoinCaptchaBot/commit/893cd684df282a99ec8d0daab1f39eb85fffd050

I check/test the changes, but please, can you check it again too (using @join_captcha_bot)?

P.D. Note that groups with too less users will show the "User joined the group" and "TheJoinCaptchaBot removed User" messages, which are Telegram client specific (them are not send by the Bot, it comes from the user) and those are not silent, so that could make a confusion.

Marzal commented 2 years ago

Fixed.

Yesterday I tried too look at the code around https://github.com/J-Rios/TLG_JoinCaptchaBot/blob/eda77cc83cb189c06bddff6cf37acffd0028aeea/sources/join_captcha_bot.py#L2553, but I couldn't find any problem.

Thanks for the quick fix.

J-Rios commented 2 years ago

Nice ;)