Does Bot Framework Support Slack BlockKit Actions for Interactivity?

Jose Antonio Gonzalez Rodriguez 0 Reputation points
2024-12-20T13:30:36.63+00:00

I currently have a Slack app with Interactivity enabled.

I have connected the Slack app with Azure Bot successfully.

I can send messages, and if a user reacts with an emoji, I can get that reaction on my backend.

Now I have added action buttons to my message. Slack renders it correctly, but when I click on any button, Slack returns a 400 error.

From what I can see, it is calling the Slack API blocks.actions, and part of the payload includes the button (action) that was clicked.

The error message I get is This app responded with Status Code 400, so I'm thinking it has to do with the bot not accepting the payload Slack sends.

The request URL for Interactivity that I'm using is https://slack.botframework.com/api/Actions.

Does the Bot Framework support Slack block actions, or is there an alternative to make it work?

Thank you, and happy holidays! :)

P.S. If someone replies I'm not gonna be checking this until next year :)

Payload

Screenshot 2024-12-20 at 13.21.29 copy

How it displays on Slack

Screenshot 2024-12-20 at 13.16.15

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
871 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 14,551 Reputation points
    2024-12-20T21:55:58.4733333+00:00

    Hello Jose Antonio Gonzalez Rodriguez,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having error message I get is This app responded with Status Code 400

    It is essential to verify that the URL https://slack.botframework.com/api/Actions is the correct endpoint for processing Slack block actions. The Bot Framework may require additional configuration or a custom integration layer to handle the payload effectively. If the default endpoint does not fully support block actions, consider building a middleware or custom endpoint that processes Slack's block action payloads and forwards them to the Bot Framework.

    Ensure that the payload sent by Slack complies with Slack's Block Kit Builder - https://app.slack.com/block-kit-builder/ standards. This tool is excellent for verifying the payload structure and ensuring all required fields are included. Specifically, the payload must contain fields like actions, callback_id, and trigger_id. Once validated, compare this payload against what the Bot Framework expects. Inconsistencies in payload structure may lead to errors, such as the reported 400 status code.

    In scenarios where the Bot Framework does not natively support block actions, implementing middleware can bridge the gap. Middleware intercepts and processes Slack's payloads, allowing you to extract button actions and execute specific logic. The middleware should also ensure an immediate response to Slack (e.g., a 200 OK status) within the required timeframe to avoid timeouts. This is an example middleware implementation using Node.js:

    const express = require('express');
    const bodyParser = require('body-parser');
    const app = express();
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());
    app.post('/api/slack/actions', (req, res) => {
        const payload = JSON.parse(req.body.payload);
        
        if (payload.type === 'block_actions') {
            const actionId = payload.actions[0].action_id;
            const userId = payload.user.id;
            console.log(`Action ${actionId} triggered by user ${userId}`);
            
            // Add logic to handle the specific action
            res.status(200).send('Action received!');
        } else {
            res.status(400).send('Unsupported action type.');
        }
    });
    app.listen(3000, () => console.log('Middleware listening on port 3000.'));
    

    Confirm that your Bot Framework is correctly set up to handle Slack-specific data. This involves ensuring that the channelData property in the activity payload is structured as per Slack’s requirements. Misalignment between the expected and actual payload structures can lead to errors when processing interactive messages.

    Finally, ensure your Slack app has all necessary permissions configured. Permissions such as commands, chat:write, and interactive_messages are required for handling block actions. You can verify and update these in the Slack admin console.

    You can review the links below:

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.