我正在通过一个网络钩子把信息发送到Slake.使用单个"text"JSON元素的消息通知使用OSX和iOS上的Slake应用程序生成正确的通知文本.消息文本在频道中也是正确的.但是,当使用新的"BLOCKS"方法时,通知文本变成"此内容无法显示".消息确实正确显示在通道中.只是通知不起作用.

According to https://api.slack.com/messaging/composing/layouts the text in the first block is used for the notification:

When you're using blocks in your message payload, the text field becomes a fallback message displayed in notifications.

如果不使用"块"样式,则可以执行以下操作:

curl -s -k -X POST https://hooks.slack.com/services/${webhook} -H 'Content-type: application/json' --data @- << EOF
{
  "text": "${message}"
}
EOF

如果您使用挡路生成器应用程序,通过清除任何现有代码,然后添加一个节挡路来生成一个简单的块样式类似功能,您将得到如下所示:

[
    {
        "type": "section",
        "text": {
            "type": "plain_text",
            "text": "This is a plain text section block.",
            "emoji": true
        }
    }
]

Now at the bottom of the page, enter your channel and click "Send to Slack". The result is that the text arrives in the channel correctly, however the notification that pops up contains the text "This content can't be displayed".

起初我认为我自己的挡路样式代码是不正确的,然而,这个由挡路工具包生成器应用程序生成的代码也不起作用,这让我相信SLACK本身存在问题/bug.

还是我忽略了什么?

谢谢

推荐答案

There are multiple "text"properties in the message structure. I believe the doc is referring to the top-level one outside all blocks definitions.

例子:

{
  "channel": "C1H9RESGL",
  "text": "Text here for notifications",
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Danny Torrence left the following review for your property:"
      }
    }
  ]
}

Json相关问答推荐

Jolt转换问题—使用键查找匹配对象

如何使用JQ有条件 Select 值

删除JSON文件的特定内容

从json数组中删除特定元素

使用更高级别架构中的字段值在$def内实现约束

创建Json嵌套文件 struct

PowerShell女士:如何处理json对象?

在 PowerShell 中通过 aws cli 创建 cloudwatch alert 时出现字符串解析错误

Vega-Lite规范:尽管在规范中提供了数据,但显示空图表

jq 中的整个单词匹配

如何在循环中传递列表(会话(字符串属性))以在 Gatling Scala 中创建批量 Json 请求

使用 System.Text.Json 序列化记录成员

ASP.NET MVC - 将 Json 结果与 ViewResult 结合起来

未捕获的类型错误:无法读取 null 的属性props

Java的JSON字符串整洁/格式化程序

ASP.NET MVC:使用 JsonResult 控制属性名称的序列化

如何将 LinkedTreeMap 转换为 gson JsonObject

是否可以将数据写入本地 json 文件,除了Angular 之外什么都没有?

如何将单引号转义成双引号转成单引号

如何对 Javascript 对象进行排序,或将其转换为数组?