Python Bot API: Set messages to read after some time - python

I have a bot which polls data regularly from some input and if a specific logic applies, sends a message to a telegram channel.
The messages are only relevant for readers if the reader in the channel more or less directly read the message, i.e. after let's say 30 min, the message is irrelevant. I do not want to delete the message for historic purposes, BUT I'd like to set it to read for everyone.
Is there a way to set the "read"-status for the receivers? Is it possible to do so, i.e. change, for already sent, i.e. previous messages?
To avoid having to keep track of sent messages with their timings, is it even possible to specify that directly when sending the message?

No, this is not possible. The read status can only be changed by the user itself. Anything not mentioned in the official API docs at https://core.telegram.org/bots/api can not be done with Telegram Bots.
As a side note: AFAIK the read status is not binary for each user. This can be observed by noting that viewing a channel message from different devices/clients with the same account will up the view count by more than 1.

Related

How to save the information in Telegram notification by python ? (possible?)

I want when someone sends a message in Telegram, the information of the message is stored in the telegram bot or something else without seeing the other party's message.
I assume you want to do what is known as "ghost mode" which means you read messages but they're not double-checked.
Before I answer your question, I should warn you that Telegram's founder is against such use (see https://twitter.com/durov/status/891227609706536960).
The fun fact is you don't have to do anything to avoid double-checking a message. In fact there is an extra step for that. Therefore, all you need to do is to read the message. You can do so in telethon as simple as this:
#app.on(events.NewMessage())
def read(event):
print(event.message.message)

Is it possible to use aiogram to send messages without handlers?

Recently I've been writing bot which parses site and sends message to users, whenever new information appears. Is it possible to make it on aiogram? Thank you for your answer in advance
Yes. it is.
But you have to store user_id of your users, then when "information appears" you take from your storage user_ids and send message to each user. Also it is unreal to send message for all users in one time due to telegram limits (see here).

Message a single user by user id

I am looking at this sample: https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/57.teams-conversation-bot/bots/teams_conversation_bot.py
_message_all_members iterates thorough a list of all members and sends each one a message.
I need a way to send one message to one user. I know their user id. Can you help me write a function that takes a text message and a user id and sends it. Whoever wrote that sample is a pervert, and I can't unwrap all the layers. tc1, tc2. wtf?
I think what you're looking for is "proactive notification", a method to send an activity to a user without the bot first receiving a message from them?
The thing that makes this awkward is that to use the SDK, you need to have a TurnContext that represents the conversation between the bot and the user... this is typically done using the adapter.continue_conversation method which requires you to pass the conversation reference. The conversation reference itself can either be cached from a previous bot message from that user or obtained by creating a new conversation with that user (this would be using the adapter.create_conversation method).
The tc1, tc2 stuff are essentially just references to turn contexts in nested callback methods as this is how create_conversation and continue_conversation work.
There is a specific proactive notification sample that might work better for you here: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/16.proactive-messages

View filtered real time updates of this channel using python

I am a part of a public telegram channel with too much noise and only some meaningful important updates. I want to filter out noise and need to view real time updates(new messages) with specific words in text body of message of this channel using python.
I followed the code from below post by Lonami to try and get messages and it works beautifully, but it brings in all the historical messages as well.
Telegram get chat messages /posts - python Telethon
Could someone guide me to get the new messages real time one by one as they are posted ?

Forward a message with multiple media files using bot Telegram API

I'm having a problem forwarding messages with multiple media files (in my particular case, photos).
I'm using forwardMessage method to forward the message that user sends to bot (which, in some cases, might contain more than one photo):
bot.forwardMessage(admin_id, from_chat_id, message_id)
But, the thing is, according to Telegram API v3.5, the message which contain media group breaks up into array of messages, and hence the bot breaks up the message from user into multiple messages. E.g. if user have sent a message with 3 photos, then the bot forwards 3 messages, each of which contains a photo.
What I want is to forward a message with multiple media files as it is, as one message, not as multiple messages.
I know that probably I can take each photo from each message that the bot receives, put them one-by-one into array, and then send it from the bot using sendMediaGroup method, but I'd like to know if I can get it working with forwardMessage method.
Thanks in advance.
You can't forward original content via forwardMessage, for instance, you can't forward with an inline keyboard.
I think this may be a mistake, you can suggest that to #BotSupport.
Telegram API had updated a method call sendMediaGroup for sending images as album.
https://core.telegram.org/bots/api#sendmediagroup
Have a look :)

Categories