Forward a message with multiple media files using bot Telegram API - python

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 :)

Related

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).

How can i forward mediagroup in python telegram bot?

I want to create a telegram bot in which a user can send a media group along with text and another user will receive it as a media group. I know that it can be done with sendmediagroup, but how to do it so that the media does not need to be saved, but can be forwarded immediately, like copy_message or forward_message?
You can just use sendMediaGroup() to send media files instead of forwarding it. Forwarding media group files is not supported yet I think.

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

How to capture reaction of an emoji to a message in Microsoft Team

Is there a way to capture the reaction/emojies on messages in Microsoft Teams using Microsoft Teams webhook (I'm coding in python)? If not can I do this using other tools ( Microsoft Graph, Power Apps, Power Automate, etc.).
I am using Microsoft Team Webhook to post message into Teams Channel, now I am trying to capture user reactions to each message and saved them in a database. Is there a way to get access to reactions? It would be great if I can do it by using current Webhook that I have.
Here is the function I am using to post the message to Microsoft Teams.
def sendMessageToTeams(webHookUrl: str,msg: str):
try:
# escaping underscores to avoid alerts in italics.
msg = msg.replace('_', '\_')
teams_msg = pymsteams.connectorcard(webHookUrl)
teams_msg.text(f'{msg}')
teams_msg.send()
except Exception as e:
print(f'failed to send alert: {str(e)}')
You can send messages to Teams channel using webhook. You can post messages by setting up incoming webhook within channel. Please look at https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook .
But you should specify your requirement you can achieve this with the Bot. A bot is also helpful to have conversation within Teams channel. Bot supported [Personal, Team, GroupChat] scope. Please go through the Conversation basic https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-basics?tabs=dotnet#send-a-message for more information how bot works within different scopes.
Thanks Sayali.
My first answer got deleted because it only referred to the link. So I added the detailed steps from the link.
I didn't have issue to sent message, reactions to Team, my problem was on how to capture the reaction to previous messages.
I finally found the answer by following the instruction on the following link which is self explanatory.
https://powerusers.microsoft.com/t5/Building-Flows/Collecting-Reactions-from-Teams-Messages/td-p/822090
Here is the steps form the post, I thought its better to simply refer to link, however received some comment to put the main steps here. So here we go:
Explanation:
1.Get messages
2.Go into an apply each loop for each message.
3.The reactions array associated with each message is filtered to match every type of reaction.
4.A compose action outputs the message ID along with the length of each reaction array (the count of each reaction type).
5.The final array of results is produced outside of the apply-each loop.

Python Bot API: Set messages to read after some time

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.

Categories