microsoft / BotFramework-Services

Microsoft Bot Framework Services
Creative Commons Attribution 4.0 International
38 stars 11 forks source link

Slack interactive messages not working with azure bot service connector #326

Closed bolleman closed 2 years ago

bolleman commented 2 years ago

I'm using the Slack channel in Azure Bot Service (for clarity, not the Slack adapter package). My bot is receiving bot events properly, but block kit button clicks (aka interactive messages) generate the following error. 400errorSlack The Slack channel shows as Healthy but nothing is being forwarded to my bot endpoint. The Slack app is configured with the request_url specified in the Azure Bot Service documentation for configuring a Slack channel as follows:

"interactivity": {
            "is_enabled": true,
            "request_url": "https://slack.botframework.com/api/Actions"
        },

It looks like this issue was raised back in Jun 2020 and then fixed in Jul 2020: https://github.com/microsoft/BotBuilder-Samples/issues/2553 https://github.com/microsoft/botbuilder-dotnet/issues/4246

However, it also appears that it is not working again for others as well: https://stackoverflow.com/questions/68215851/microsoft-bot-framework-respond-to-slack-block-kit-ui-action-buttons#new-answer

Just wondering if this is a new bug or am I missing something in the config. Thanks!

ssss141414 commented 2 years ago

Hi @Bolleman , We're trying repro it. Can you provide your code about constructing this Activity with buttons?

bolleman commented 2 years ago

I created a new Composer project with one dialog, as follows. The Slack bot channel registration contains the default scopes.

I haven't put in a trigger in this dialog to handle the event/activity from the Slack button click yet as I was waiting to see it come through on ngrok first so I know what it will look like. If you also happen to know what trigger I should use that would be awesome as I'm going to need to know that next. Thanks for your help!

{
  "$kind": "Microsoft.AdaptiveDialog",
  "$designer": {
    "name": "TestSlack",
    "description": "",
    "id": "A79tBe"
  },
  "autoEndDialog": true,
  "defaultResultProperty": "dialog.result",
  "triggers": [
    {
      "$kind": "Microsoft.OnUnknownIntent",
      "$designer": {
        "id": "mb2n1u",
        "comment": "This trigger fires when an incoming activity is not handled by any other trigger."
      },
      "actions": [
        {
          "$kind": "Microsoft.HttpRequest",
          "$designer": {
            "id": "fVgcUr",
            "name": "Start new thread"
          },
          "resultProperty": "dialog.sendResult",
          "method": "POST",
          "url": " https://slack.com/api/chat.postMessage",
          "headers": {
            "Authorization": "Bearer ${turn.activity.channelData.ApiToken}"
          },
          "contentType": "application/json",
          "responseType": "json",
          "body": {
            "channel": "${turn.activity.channelData.SlackMessage.event.channel}",
            "blocks": [
              {
                "type": "actions",
                "block_id": "actionblock789",
                "elements": [
                  {
                    "type": "button",
                    "text": {
                      "type": "plain_text",
                      "text": "Primary Button"
                    },
                    "style": "primary",
                    "value": "click_me_456"
                  },
                  {
                    "type": "button",
                    "text": {
                      "type": "plain_text",
                      "text": "Link Button"
                    },
                    "url": "https://api.slack.com/block-kit"
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  ],
  "generator": "TestSlack.lg",
  "id": "TestSlack",
  "recognizer": {
    "$kind": "Microsoft.RegexRecognizer",
    "intents": []
  }
}
bolleman commented 2 years ago

I did further searching and discovered there is a legacy Slack message button format using attachments in addition to the current Block Kit button elements that I used initially. I added the legacy approach to the previous dialog (see below) and it works. This provides a suitable workaround for my purposes so I am closing the issue. I've created an issue on MSDocs so others are aware.

Also, since I now see this comes through as a regular message activity, that answers the other question of how to trigger off it.

{
  "$kind": "Microsoft.AdaptiveDialog",
  "$designer": {
    "name": "TestSlack",
    "description": "",
    "id": "A79tBe"
  },
  "autoEndDialog": true,
  "defaultResultProperty": "dialog.result",
  "triggers": [
    {
      "$kind": "Microsoft.OnUnknownIntent",
      "$designer": {
        "id": "mb2n1u",
        "comment": "This trigger fires when an incoming activity is not handled by any other trigger."
      },
      "actions": [
        {
          "$kind": "Microsoft.HttpRequest",
          "$designer": {
            "id": "fVgcUr",
            "name": "Start new thread"
          },
          "resultProperty": "dialog.sendResult",
          "method": "POST",
          "url": " https://slack.com/api/chat.postMessage",
          "headers": {
            "Authorization": "Bearer ${turn.activity.channelData.ApiToken}"
          },
          "contentType": "application/json",
          "responseType": "json",
          "body": {
            "channel": "${turn.activity.channelData.SlackMessage.event.channel}",
            "blocks": [
              {
                "type": "actions",
                "block_id": "actionblock789",
                "elements": [
                  {
                    "type": "button",
                    "text": {
                      "type": "plain_text",
                      "text": "Primary Button"
                    },
                    "style": "primary",
                    "value": "click_me_456"
                  },
                  {
                    "type": "button",
                    "text": {
                      "type": "plain_text",
                      "text": "Link Button"
                    },
                    "url": "https://api.slack.com/block-kit"
                  }
                ]
              }
            ]
          }
        },
        {
          "$kind": "Microsoft.HttpRequest",
          "$designer": {
            "id": "YSkbjQ",
            "name": "Start new thread"
          },
          "resultProperty": "dialog.sendResult",
          "method": "POST",
          "url": " https://slack.com/api/chat.postMessage",
          "headers": {
            "Authorization": "Bearer ${turn.activity.channelData.ApiToken}"
          },
          "contentType": "application/json",
          "responseType": "json",
          "body": {
            "channel": "${turn.activity.channelData.SlackMessage.event.channel}",
            "text": "Would you like to play a game?",
            "attachments": [
              {
                "text": "Choose a game to play",
                "fallback": "You are unable to choose a game",
                "callback_id": "wopr_game",
                "color": "#3AA3E3",
                "attachment_type": "default",
                "actions": [
                  {
                    "name": "game",
                    "text": "Chess",
                    "type": "button",
                    "value": "chess"
                  },
                  {
                    "name": "game",
                    "text": "Falken's Maze",
                    "type": "button",
                    "value": "maze"
                  },
                  {
                    "name": "game",
                    "text": "Thermonuclear War",
                    "style": "danger",
                    "type": "button",
                    "value": "war",
                    "confirm": {
                      "title": "Are you sure?",
                      "text": "Wouldn't you prefer a good game of chess?",
                      "ok_text": "Yes",
                      "dismiss_text": "No"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  ],
  "generator": "TestSlack.lg",
  "id": "TestSlack",
  "recognizer": {
    "$kind": "Microsoft.RegexRecognizer",
    "intents": []
  }
}