如何在Watson Assistant JSON响应中使用output.integrations.slack对接Slack
可行的解决方法如下:
- 修正字段命名与格式错误
你当前配置中使用的attachment是单数格式,不符合Slack及Watson Assistant的规则:Slack要求附件字段为复数attachments,且值必须为数组类型,你需要将现有attachment对象放入attachments数组中。 - 补充兜底文本避免空响应拦截
你当前generic配置下的values数组为空,部分版本的Watson Assistant会将空的通用响应判定为无效响应,直接拦截后续自定义集成的内容输出,你可以在values中添加一条纯文本兜底内容。 - 可选优化方案
如果你不需要使用附件的额外属性(如侧边颜色、前置文本等),可以直接将blocks字段放在slack对象下,无需嵌套在attachments中,兼容性更强。
修正后的配置示例(attachments版本)
{ "output": { "integrations": { "slack": { "attachments": [ { "blocks": [ { "text": { "text": "Pick a date for the deadline.", "type": "mrkdwn" }, "type": "section", "accessory": { "type": "datepicker", "action_id": "datepicker-action", "placeholder": { "text": "Select a date", "type": "plain_text", "emoji": true }, "initial_date": "1990-04-28" } } ] } ] } }, "generic": [ { "response_type": "text", "values": [ { "text": "请选择截止日期" } ], "selection_policy": "sequential" } ] } }
简化版本(直接使用blocks字段)
{ "output": { "integrations": { "slack": { "blocks": [ { "text": { "text": "Pick a date for the deadline.", "type": "mrkdwn" }, "type": "section", "accessory": { "type": "datepicker", "action_id": "datepicker-action", "placeholder": { "text": "Select a date", "type": "plain_text", "emoji": true }, "initial_date": "1990-04-28" } } ] } }, "generic": [ { "response_type": "text", "values": [ { "text": "请选择截止日期" } ], "selection_policy": "sequential" } ] } }
内容的提问来源于stack exchange,提问作者Rachel Dong
相关产品推荐
相关产品推荐

