Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update_activity in messages #2101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NeeluGeorge
Copy link

@NeeluGeorge NeeluGeorge commented Apr 24, 2024

closes: OfficeDev/Microsoft-Teams-Samples#1226

Description

Python sdk documentation says to pass replyToId as updated_activity.id, but this was not getting passed to the reference created in update_activity

https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/update-and-delete-bot-messages?tabs=python#update-cards

Specific Changes

Added activity.id as the "activity_id" in reference

@NeeluGeorge NeeluGeorge requested a review from a team as a code owner April 24, 2024 15:06
@tracyboehrer
Copy link
Member

@NeeluGeorge What is the reason for this? What is it solving? 'apply_conversation_reference' does this, except conditionally.

@NeeluGeorge
Copy link
Author

@tracyboehrer 'apply_conversation_reference' is using reference.activity_id
But TurnContext.get_conversation_reference(self.activity) called before this will map reference.activity_id with the original activity's id field.
Here we are passing self.activity in TurnContext.get_conversation_reference(self.activity) , not the activity we pass as argument

So our updated activity.id is left unused.This throws invalid ID error

@tracyboehrer
Copy link
Member

@NeeluGeorge Thanks for that. I'll dig a little. I note that the Python get_conversation_reference is different from the DotNet and JS implementations.

@tracyboehrer
Copy link
Member

tracyboehrer commented May 9, 2024

@NeeluGeorge reference.activity_id should be TurnContext.activity.id. That happens in get_conversation_reference. But, Pythons get_conversation_reference is outdated, and that assignment should be conditional, which I will update. So doing this could potentially change that logic.

That doc states the Activity passed to update_activity should have its id set to the incoming activity.reply_to_id. Is there a value for that property?

@NeeluGeorge
Copy link
Author

NeeluGeorge commented May 29, 2024

@NeeluGeorge reference.activity_id should be TurnContext.activity.id. That happens in get_conversation_reference. But, Pythons get_conversation_reference is outdated, and that assignment should be conditional, which I will update. So doing this could potentially change that logic.

That doc states the Activity passed to update_activity should have its id set to the incoming activity.reply_to_id. Is there a value for that property?

Yes @tracyboehrer

Sample code for updation

` async def post_updated_message(self):

    adaptive_card_attachment = CardFactory.adaptive_card(self.message.messageBody)
    
    updated_activity = MessageFactory.attachment(adaptive_card_attachment)
    
    updated_activity.id = self.turn_context.activity.reply_to_id
    
    await self.turn_context.update_activity(updated_activity)

`

Error:

`
"Error occurred while reacting to message Error: (BadArgument) Invalid activity ID 1:1zUqrpY6kJ6PjcsmO2_1zjCfKsKLgLaF9vcA7h72Rd8QWCNetmMA6CVxiWCJdrz8m-8JkEngpiqrMSdN10rR6nA", "time": "2024-05-29T15:09:39.146814"}

`
Issue in update activity:

reference = TurnContext.get_conversation_reference(self.activity)

Here self.activity is having a different id.

Only our updated_activity has id= 'reply_to_id'

But this is left unused while creating reference

@NeeluGeorgeKB4
Copy link

@tracyboehrer
Has this been fixed in any of the recent releases?

@tracyboehrer
Copy link
Member

In 4.15.1 there was a fix in CloudAdapter related to the id passed to update_activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The update_activity python documentation contains errors and no samples for update_activity
3 participants