无法刷新可操作消息

我的可操作留言卡没有引用。这是我已经检查过的

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json","version": "1.0","type": "AdaptiveCard","originator": "<guid>","body": [
        {
            "type": "TextBlock","text": "The action has been recorded."
        }
    ]
}

从 API(Azure 函数)返回的响应如下

string card = "<card-json>";
req.HttpContext.Response.Headers.Add("CARD-actION-STATUS","action accepted,thank you.");
req.HttpContext.Response.Headers.Add("CARD-UPDATE-IN-BODY","true");
return new OkObjectResult(card);

我也试过了,没有成功

string card = "<card-json>";
req.HttpContext.response.contenttype = "application/json; charset=utf-8";
req.HttpContext.Response.Headers.Add("CARD-actION-STATUS","true");
req.HttpContext.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(card));
return new OkResult();

提交初始卡片的 POST 操作时,请参阅显示显示 action accepted,thank you. 的横幅,但卡片本身并未刷新。

这是示例 API 响应数据

无法刷新可操作消息

你有没有发现任何明显的错误?研究此行为后,我发现最常见的错误是未提供相关标头,但我确定添加了它们。

非常感谢任何帮助!

qqcoboo 回答:无法刷新可操作消息

我自己刚刚解决了这个问题。我是数据序列化问题。

为了创建自适应卡json,我使用了这两个包

  <ItemGroup>
    <PackageReference Include="AdaptiveCards" Version="2.0.0" />
    <PackageReference Include="AdaptiveCards.Templating" Version="1.0.1" />
  </ItemGroup>

具体的代码是

string templateFilePath = Path.Combine(ctx.FunctionAppDirectory,"ActionableMessageCards",cardTemplateName);
string template = await File.ReadAllTextAsync(templateFilePath);
var card = new AdaptiveCardTemplate(template);
var context = new EvaluationContext() { Root = cardData };
return card.Expand(context);

card.Expand() 返回一个转义的 json 字符串,即像这样的东西

"{\"key\": \"value\"}"

显然 return new OkObjectResult(card) 在我上面的问题中尝试再次序列化该字符串,结果只是一个字符串。哪个不是 application/json

我的解决方法是将一个对象而不是字符串传递给 return new OkObjectResult() 方法(顾名思义:D)。但是,由于我没有使用任何卡片模板的类型,因此我无法使用 System.Text.Json 进行反序列化,因为匿名类型不支持此功能。因此我使用了 Newtonsoft.Json。以下内容按预期工作并更新可操作的消息。

req.HttpContext.Response.Headers.Add("Content-Type","application/json");
req.HttpContext.Response.Headers.Add("CARD-ACTION-STATUS","Action accepted,thank you.");
req.HttpContext.Response.Headers.Add("CARD-UPDATE-IN-BODY","true");
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(card);
return new OkObjectResult(obj);
本文链接:https://www.f2er.com/1039807.html

大家都在问