Search code examples
botframeworkbot-framework-composerslack-block-kit

BotFramework Composer and Slack Block Kit


How can I send a BlockKit attachment from a Bot Framework Composer Bot using the C# slack-adapter?

I'm trying to use this in the .lg but the only message that gets to the slack client is: Value cannot be null. (Parameter '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:*"
            }
        }
    ]
}
```

Solution

  • The problem was that the first type property had to be "Attachment". Otherwise the dialog manager would create an Activity containing only a property type and a property content into which it would add my json: https://github.com/microsoft/botbuilder-dotnet/blob/c98feb7c58a5564cd8d31bedf050819af70058a3/libraries/Microsoft.Bot.Builder/ActivityFactory.cs#L210

    Then the name property wasn't under att.name but under att.content.name, that made the slack adapter go under a diferent path when converting the activity to a slack message, which expected a Uri to be passed, thus the error: https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Adapters/Microsoft.Bot.Builder.Adapters.Slack/SlackHelper.cs#L56

    The json that works (only modification needed was in the type property at the root):

    {
        "type": "Attachment",
        "name": "blocks",
        "content": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "${answer}"
                }
            },
            {
                "type": "divider"
            },
            ...MORE JSON HERE....
        ]
    }