0

如何使用 C# slack-adapter 从 Bot Framework Composer Bot 发送 BlockKit 附件?

我正在尝试在 .lg 中使用它,但到达 slack 客户端的唯一消息是:值不能为空。(参数'uriString')

# SendSlackResponse()
[Activity
  Attachments = ${json(SlackMessage())}
]

# SlackMessage()
- ```
{
    "type": "application/json",
    "name": "blocks",
    "content": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where yo``u'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
            }
        }
    ]
}
```
4

1 回答 1

1

问题是第一个类型属性必须是“附件”。否则,对话框管理器将创建一个仅包含属性类型和属性内容的 Activity,它将向其中添加我的 json:https ://github.com/microsoft/botbuilder-dotnet/blob/c98feb7c58a5564cd8d31bedf050819af70058a3/libraries/Microsoft.Bot.Builder /ActivityFactory.cs#L210

然后 name 属性不在 att.name 下,而是在 att.content.name 下,这使得 slack 适配器在将活动转换为松弛消息时进入了不同的路径,该消息期望传递一个 Uri,因此出现错误: https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Slack/SlackHelper.cs#L56

有效的 json(只需要修改根的 type 属性):

{
    "type": "Attachment",
    "name": "blocks",
    "content": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "${answer}"
            }
        },
        {
            "type": "divider"
        },
        ...MORE JSON HERE....
    ]
}
于 2021-03-11T17:26:34.757 回答