How to update an adaptive card which is already sent to user from BOT?

前端 未结 2 1419
感情败类
感情败类 2021-01-14 14:33

I have already sent the card with capturing the details and with buttons.After clicking on submit from task module which will save details through http API here the activity

相关标签:
2条回答
  • 2021-01-14 15:23

    You can update adaptive card in channel like MS Teams not in directline. For updating card you need Accessor to store ActivityId which is generated while sending current message.

    Here I have provided the way to update message

    Code snippet

    0 讨论(0)
  • 2021-01-14 15:34

    This involves few steps.

    1. Create an Adaptive card and add unique id (GUID) in adaptive card action.

      var Card = new AdaptiveCard()
      {
            Body = new List<AdaptiveElement>()
      {
          new AdaptiveTextBlock(){Text="This is a test adaptive card"}
      },
      Actions = new List<AdaptiveAction>()
      {
          new AdaptiveSubmitAction()
          {
              Title="UpdateMe",
              DataJson= @"{'id':'uniqueId'}"
          }
      }
      };
      
    2. After sending message keep mapping of adaptive card uniqueId and message id.

      connector = new ConnectorClient(new Uri(activity.ServiceUrl));
      reply = activity.CreateReply();
      reply.Attachments.Add(Card.ToAttachment());
      var msgToUpdate = await connector.Conversations.ReplyToActivityAsync(reply);
      // Keep mapping of uniqueId and messageToUpdate.Id
      // UniqueId1 => messageId1
      // UniqueId2 => messageId2
      
    3. When user clicks on UpdateMe action button, check the mapping for uniqueId (This will be in activity.Value).

    4. Create new card and call connector.Conversations.UpdateActivityAsync with updated code.

    Let us knwo if you need more details.

    0 讨论(0)
提交回复
热议问题