1

I am wanting to create a slack app that listens for a message to be posted by a user and then responds with an ephemeral message for that user in the channel with some suggestions and buttons. I have a lambda subscribed to the Events API and it is receiving each message that is posted. I have another lambda set up to post the ephemeral message and when I call it from postman (through API Gateway) it does so successfully but when I try to press the buttons I get the error: this app responded with a 400 status code

I have specified the Request URL in the interactivity section of my slack app with the same URL that is used to invoke the Lambda that sends the message in the first place. When I check the logs, I get the first hit from postman, but after a button press I don't get any more pings.

I'm largely at a loss and not sure where to go from here, I read and re-read the slack docs and checked many stack overflow posts but none have helped me find an answer. Any help would be greatly appreciated.

Lambda that sends message:

const axios = require('axios')

exports.handler = async (event) => {
    // TODO implement
    console.log("Request: ", event)
    const response = {
        
        statusCode: 200,
    };
    

    let params = {
        "channel": "hardcoded_channelID",
        "user": "hardcoded_userID",
        "text": "Hello World",
        "blocks": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "Hello"
                }
            },
            {
                "type": "divider"
            },
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "Suggestion 1"
                }
            },
            {
                "type": "actions",
                "elements": [
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Helpful"
                        },
                        "value": "helpful",
                        "action_id": "1_helpful"
                    },
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Not Helpful"
                        },
                        "value": "notHelpful",
                        "action_id": "1_nothelpful"
                    },
                    {
                        "type": "button",
                        "style": "danger",
                        "text": {
                            "type": "plain_text",
                            "text": "Dismiss"
                        },
                        "value": "dismiss",
                        "action_id": "1_dismiss"
                    }
                ]
            },
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "Suggestion 2"
                }
            },
            {
                "type": "actions",
                "elements": [
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Helpful"
                        },
                        "value": "helpful",
                        "action_id": "2_heplful"
                    },
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Not Helpful"
                        },
                        "value": "notHelpful",
                        "action_id": "2_nothelpful"
                    },
                    {
                        "type": "button",
                        "style": "danger",
                        "text": {
                            "type": "plain_text",
                            "text": "Dismiss"
                        },
                        "value": "dismiss",
                        "action_id": "2_dismiss"
                    }
                ]
            },
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "Suggestion 3"
                }
            },
            {
                "type": "actions",
                "elements": [
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Helpful"
                        },
                        "value": "helpful",
                        "action_id": "3_helpful"
                    },
                    {
                        "type": "button",
                        "text": {
                            "type": "plain_text",
                            "text": "Not Helpful"
                        },
                        "value": "notHelpful",
                        "action_id": "3_nothelpful"
                    },
                    {
                        "type": "button",
                        "style": "danger",
                        "text": {
                            "type": "plain_text",
                            "text": "Dismiss"
                        },
                        "value": "dismiss",
                        "action_id": "3_dismiss"
                    }
                ]
            }
        ]
}
    let config = {
    method: 'post',
    url: 'https://slack.com/api/chat.postEphemeral',
    headers: {
        'Authorization': 'Bearer xoxb-token',
        'Content-Type': 'application/json'
    },
    data: params
};
    const res = await axios(config);
    console.log(res);
    return response;
};

Result of sent message in Slack: enter image description here

Error Code: enter image description here

Thomas S.
  • 85
  • 10
  • 1
    Issue might be with the use of interactivity within an ephemeral message. If you want the response to the message event to be private would sending a DM to the user make difference? – sandra Nov 22 '21 at 15:47
  • @sandra Good thought, I did try it as a normal message and the same thing is happening – Thomas S. Nov 23 '21 at 16:05
  • 2
    Interesting, it must not have anything to do with the type of message then. Based on the error your seeing it might be worth verifying that your server is acknowledging or understands the request.One thing to double check, is that it can accept URL encoded payloads. Interaction payloads are sent as application/x-www-form-urlencoded rather than application/json. – sandra Nov 24 '21 at 15:59
  • @sandra That is worth a try, would you know how to change that for an APIGateway Endpoint? – Thomas S. Nov 25 '21 at 17:58
  • @sandra Ok I figure it out with your help. So my Lambda function wasn't able to accept url encoded payloads and to fix it I had to check the "Use Lambda Proxy integration" box under the Integration Request for the POST method. Thank you for your help, Been stuck on this for a while now! – Thomas S. Nov 25 '21 at 18:17
  • 1
    Awesome! Happy to hear you were able to resolve this! – sandra Nov 26 '21 at 15:12

0 Answers0