Search code examples
pythontelegramtelethon

How to send a silent broadcast / message (without generating a notification) in my channel using Telethon?


I'm using Telethon library, and so far I find it awesome :) Many thanks to @Lonami for maintaining! It works perfectly for all my needs so far.

One thing I would like to know is how can I either convert a created channel to a silent one (so it will not be sending any notification to the users), or at least send a particular message without sending the notification.

I create my channel and then upload a photo using a bot account like that:

newChannel = clientCreator(CreateChannelRequest(title=my_title, about=my_description, broadcast=True))
<...>
channel = clientBot.get_entity(InputPeerChannel(channel_ID, channel_hash))
clientBot.send_file(channel.id, image_file, silent=True)

However, despite I specify silent=True parameter while sending, the image sent by bot is still triggering a notification for the user that has joined the channel. Am I doing something wrong, or that's some Telegram API bug/limitation?

P.S. Even when I specify "Silent broadcast" in official client, it still generates a notification while posting (unless the user disables it manually for the channel of course). So I guess that's likely a bug - or some misunderstanding of the concept from my side.


Solution

  • There were similar issue in telethon bugtracker: https://github.com/python-telegram-bot/python-telegram-bot/issues/1729

    The reply was:

    @borissimkin The keyword argument you are looking for is disable_notification. Please have a look at your documentation ;)

    UPD: there are the silent=True argument to the send_message only: https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.messages.MessageMethods.send_message

    I tested it, it works now: badge counter grows, and there were no sound played. The bug is fixed.