@Omar Abdelkader - To solve the flickering behavior when calling updateActivity
for an Adaptive Card in a Teams conversation, you can make use of the attachments
property of the activity object. Instead of updating the entire Adaptive Card, you can update only the specific part of the card that needs to be changed.
Here's an example code snippet that demonstrates how to update a specific part of an Adaptive Card:
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Newtonsoft.Json.Linq;
// Create an Adaptive Card instance
var adaptiveCard = new AdaptiveCard();
adaptiveCard.Body.Add(new AdaptiveTextBlock { Text = "Hello, World!" });
// Create an Attachment with the Adaptive Card
var attachment = new Attachment
{
ContentType = AdaptiveCard.ContentType,
Content = JObject.FromObject(adaptiveCard),
};
// Create a new Activity with the Attachment
var activity = new Activity
{
Type = ActivityTypes.Message,
Attachments = new List<Attachment> { attachment },
};
// Set the Activity ID to the ID of the original message
activity.Id = "<original message ID>";
// Set the Conversation ID and Channel ID
activity.Conversation = new ConversationAccount { Id = "<conversation ID>" };
activity.ChannelId = "<channel ID>";
// Update the specific part of the Adaptive Card
var updatedCard = new AdaptiveCard();
updatedCard.Body.Add(new AdaptiveTextBlock { Text = "Hello, Teams!" });
// Create an Attachment with the updated Adaptive Card
var updatedAttachment = new Attachment
{
ContentType = AdaptiveCard.ContentType,
Content = JObject.FromObject(updatedCard),
};
// Create a new Activity with the updated Attachment
var updatedActivity = new Activity
{
Type = ActivityTypes.MessageUpdate,
Id = activity.Id,
Attachments = new List<Attachment> { updatedAttachment },
};
// Send the updated Activity to the conversation
await turnContext.UpdateActivityAsync(updatedActivity);
Thanks,
Nivedipa
If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.