首页 > 解决方案 > 如何使用 C# 在客户端获取建议的卡片操作内容

问题描述

我正在使用 Microsoft BotFramework,当机器人返回建议的 CardAction 时,内容未显示在客户端中。

机器人代码

private static async Task SendSuggestionOptionAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
    var reply = turnContext.Activity.CreateReply("Please choose anyone of this!");
    reply.Type = ActivityTypes.Message;
    reply.TextFormat = TextFormatTypes.Plain;
    reply.SuggestedActions = new SuggestedActions()
    {
        Actions = new List<CardAction>()
        {
            new CardAction() { Title = "Fourm", Type = ActionTypes.ImBack, Value = "Fourm" },
            new CardAction() { Title = "KB", Type = ActionTypes.ImBack, Value = "KB" },
        },
    };
    await turnContext.SendActivityAsync(reply, cancellationToken);
}

客户代码

var messagesReceived = await _httpClient.GetAsync(conversationUrl);
var messagesReceivedData = await messagesReceived.Content.ReadAsStringAsync();
var messagesRoot = JsonConvert.DeserializeObject<BotMessageRoot>(messagesReceivedData);

它只显示“请选择其中的任何一个!” 在 messgesReceivedData 上,但不显示建议的 CardAction 内容。有人可以帮助确定我在哪里犯了错误吗?我想将建议的 CardAction 内容绑定到我的客户。

机器人输出

{
   "id": "QYhDOe6oulCoU55XIoXc5|0000003",
   "conversationId": "QYhDOe6oulCoU55XIoXc5",
   "created": "2019-01-28T04:56:37.1646158Z",
   "from": "sync-test-bot",
   "text": "Please choose anyone of this!",
   "images": [],
   "attachments": []
}

没有论坛,这里显示 KB。

标签: c#xamarin.formsbotframework

解决方案


不确定答案,但您检查了响应标头吗?在 Outlook 可操作邮件中,卡片内容作为 JavaScript 对象位于 http 标头中。


推荐阅读