如何更新已经从BOT发送给用户的自适应卡? [英] How to update an adaptive card which is already sent to user from BOT?

查看:187
本文介绍了如何更新已经从BOT发送给用户的自适应卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发送了带有捕获详细信息和按钮的卡片.单击任务模块中的提交后,该模块将通过http API保存详细信息,此处的活动类型为Invoke. 现在,我必须更新现有的自适应卡.

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 type is Invoke. Now i have to update the existing adaptive Card.

我有更新消息的代码,但是如何更新卡或重新发送卡.

I have the code to update the message, but how to update the card or resend the card again.

                connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                reply = activity.CreateReply($"You sent {activity.Text} which was {activity.Text.Length} characters");
                var msgToUpdate = await connector.Conversations.ReplyToActivityAsync(reply);
                Activity updatedReply = activity.CreateReply($"This is an updated message");
                await connector.Conversations.UpdateActivityAsync(reply.Conversation.Id, msgToUpdate.Id, updatedReply);

推荐答案

这涉及几个步骤.

  1. 创建自适应卡并在自适应卡操作中添加唯一ID(GUID).

  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'}"
    }
}
};

  • 发送消息后,请保持自适应卡uniqueId和消息ID的映射.

  • 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
    

  • 当用户单击UpdateMe操作按钮时,检查uniqueId的映射(这将在activity.Value中).

  • When user clicks on UpdateMe action button, check the mapping for uniqueId (This will be in activity.Value).

    如果您需要更多详细信息,请告诉我们.

    Let us knwo if you need more details.

    这篇关于如何更新已经从BOT发送给用户的自适应卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆