Harkirat Saluja
Harkirat Saluja

Reputation: 8124

How to update adaptive card on task module on submit bot framework?

I have a requirement where I need to update as existing adaptive card on submitting a form from task module in Microsoft teams. I am able to achieve this by sending a new card but I need to achieve this by reusing the adaptive card which was sent as the main message.

The flow is as follows:-

  1. Adaptive card with an update button is sent using the bot framework.
  2. On pressing update, handleTeamsTaskModuleFetch is called inside my bot application. Here I make an api call to my backend to get the adaptive card for my modal. This is an input form.
  3. On submitting the form, handleTeamsTaskModuleSubmit is called inside my bot application. Here I make an api to my backend to save the information. Post this I need to update my original adaptive card message, by adding a success/failure text.

The issue which I am facing is that I need the information about the existing card which was originally sent and update that. The documentation has shown ways to update by sending entirely a new card. I cannot use that because my card is dynamic and cannot have a fixed structure.

So my question here is that is there any way in which I can get the adaptive card that is sent in my main message, inside my handleTeamsTaskModuleSubmit function so that I can edit that and use updateActivity with replyToId to update the original message.

Upvotes: 0

Views: 1973

Answers (1)

Sayali-MSFT
Sayali-MSFT

Reputation: 369

You can update the existing card using below code:

      var updateCardActivity = new Activity(ActivityTypes.Message)
                    {
                        Id = turnContext.Activity.ReplyToId,
                        Conversation = turnContext.Activity.Conversation,
                        Attachments = new List<Attachment> { Your Adaptive Card },
                    };
                    await turnContext.UpdateActivityAsync(updateCardActivity, cancellationToken);

Reference sample code link: https://github.com/OfficeDev/microsoft-teams-faqplusplus-app/blob/master/Source/Microsoft.Teams.Apps.FAQPlusPlus/Bots/FaqPlusPlusBot.cs

Upvotes: 1

Related Questions