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

 ̄綄美尐妖づ 提交于 2019-12-02 05:26:26

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!