我有一个问题工单应用程序,我想在创建新工单时在专用通道中发布消息。这个想法是要有一个基本的通知消息,例如“新票证”和一个指向票证网页的按钮。
但是我的松弛API有问题,我无法添加按钮(仅发布文本)。即使当我使用文档示例的json时,它也不起作用。
注意:我能够发布简单的消息,没问题。
试图适应消息,在按钮上输入网址代替值
JSON:
{
"channel": "XXXXXXXXXX",
"type": "section",
"text": {
"type": "mrkdwn",
"text": "You can add a button alongside text in your message."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Button",
"emoji": true
},
"value": "click_me_123"
}
}
结果: https://i.imgur.com/8CueU0y.png
即使文字处理不正确。
答案 0 :(得分:0)
您的JSON没有遵循正确的消息语法,因此Slack无法显示。
您需要在消息定义中的属性blocks
下将块的JSON包含在内-与channel
处于同一级别。您的块用JSON也需要是一个数组。
工作示例:
{
"channel": "XXXXXXXXXX",
"blocks":
[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"You can add a button alongside text in your message."
},
"accessory":{
"type":"button",
"text":{
"type":"plain_text",
"text":"Button",
"emoji":true
},
"value":"click_me_123"
}
}
]
}
有关“在消息中放入块”的参考文档,请参见this link