我在 slack-azure 集成方面遇到问题。我正在尝试使用斜杠命令构建一个机器人,该命令将请求发送到 azure 函数。函数执行后我想将结果返回给用户。我在函数末尾使用 JSON 和简单的 return 语句。
问题是 Slack 不会解释这个 json,而是将其视为普通字符串并打印原始 json。
我认为 json 写得正确,因为我在 Slack Block Kit Builder 中测试了它并将其发送到我的频道并且它显示正确。
这是来自 Block Kit Builder 的消息的样子(这就是它应该的样子):
机器人响应如下所示:
这是这个 json 字符串
[{"type":"section","text":{"type":"mrkdwn","text":"• https://www.nike.com/pl/t/jordan-why-not-buty-do-koszykowki-zer02-6P4dl5/AO6219-100?nst=0&cp=euns_kw_pla!pl!goo!cssgeneric!c!!!305375159198&ds_rl=1252249&gclid=Cj0KCQjwjrvpBRC0ARIsAFrFuV9pv41cqv0h8USkHXpK0yay6pqZGnAklqJukHC-JCi3EGHVQX3MELsaAmmUEALw_wcB&gclsrc=aw.ds\\n"}}]
这是我构建 json 有效负载的函数
public JArray FormatResponse(List<string> results)
{
var links = ExtractLinksFromResponse(results);
string textString = string.Empty;
foreach (var l in links)
{
textString += $@"• {l}\n";
}
dynamic response = new ExpandoObject();
response.type = "section";
dynamic text = new ExpandoObject();
text.type = "mrkdwn";
text.text = textString;
response.text = text;
string json = JsonConvert.SerializeObject(response);
json.Replace("&", "&");
json.Replace("<", "<");
json.Replace(">", ">");
var parsedJson = JObject.Parse(json);
var jsonArray = new JArray();
jsonArray.Add(parsedJson);
return jsonArray;
}
这是我的“主要”azure 函数的一部分,我在其中调用 FormatResponse 并将其返回到我的 Slack 机器人:
var responseContent = responseFormatter.FormatResponse(results);
var response = req.CreateResponse(HttpStatusCode.OK, responseContent, JsonMediaTypeFormatter.DefaultMediaType);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return response;
也许我的回复中缺少一些标头,或者我应该以其他方式发送它?
蛊毒传说
白板的微信
相关分类