I am creating a slack bot, which has a slash command that processes some data. The slash command responds with a confirmation block. The slash command handling works as expected, I am receiving the users' data and I can respond to it, but when I click on the yes/no buttons I get "This App responded with status Code 404".

from flask import Flask, Response, jsonify
from flask import request
from slackeventsapi import SlackEventAdapter
import os
from threading import Thread
from slack import WebClient
import json



# This `app` represents your existing Flask app
app = Flask(__name__)

SLACK_SIGNING_SECRET = os.environ['SLACK_SIGNING_SECRET']
slack_token = os.environ['SLACK_BOT_TOKEN']
VERIFICATION_TOKEN = os.environ['VERIFICATION_TOKEN']

# instantiating slack client
slack_client = WebClient(slack_token)


@app.route("/")
def event_hook(request):
    json_dict = json.loads(request.body.decode("utf-8"))
    print(f"event hook: json_dict {json_dict}")
    if json_dict["token"] != VERIFICATION_TOKEN:
        return {"status": 403}

    if "type" in json_dict:
        if json_dict["type"] == "url_verification":
            response_dict = {"challenge": json_dict["challenge"]}
            return response_dict
    return {"status": 500}


slack_events_adapter = SlackEventAdapter(
    SLACK_SIGNING_SECRET, "/slack/events", app
)




def get_confirmation_block(confirmation_text: str, command_id: str):
    return [
        {
            "type": "header",
                    "text": {
                        "type": "plain_text",
                        "text": "New request",
                                "emoji": True
                    }
        },
        {
            "type": "section",
                    "fields": [
                        {
                            "type": "mrkdwn",
                            "text": "*Type:*\nPaid Time Off"
                        },
                        {
                            "type": "mrkdwn",
                            "text": "*Created by:*\n<example.com|Fred Enriquez>"
                        }
                    ]
        },
        {
            "type": "section",
                    "fields": [
                        {
                            "type": "mrkdwn",
                            "text": "*When:*\nAug 10 - Aug 13"
                        }
                    ]
        },
        {
            "type": "actions",
                    "elements": [
                        {
                            "type": "button",
                            "text": {
                                    "type": "plain_text",
                                "emoji": True,
                                "text": "Approve"
                            },
                            "style": "primary",
                            "value": "click_me_123"
                        },
                        {
                            "type": "button",
                            "text": {
                                    "type": "plain_text",
                                "emoji": True,
                                "text": "Reject"
                            },
                            "style": "danger",
                            "value": "click_me_123"
                        }
                    ]
        }
    ]




@app.route("/slack/events", methods=["POST"])
def message_actions():
    # Parse the request payload
    message_action = json.loads(request.form["payload"])
    user_id = message_action["user"]["id"]
    print(message_action)
    print("HERE") # I don't receive this
    return {"", 200}


@app.route("/slack/add_data", methods=["POST"])
def handle_slash_command():
    data = request.form
    print(data)
    channel_id = data["channel_id"]
    text = data['text'].strip()

    # Interactive message with confirmation buttons
    confirmation_text = f'Received: {text}\nDo you want to add this?'
    confirmation_block = get_confirmation_block(confirmation_text,
                                                "add_smth_confirmation")

    slack_client.chat_postMessage(channel=channel_id,
                                  blocks=confirmation_block,
                                  )

    return Response(status=200)


# Start the server on port 3000
if __name__ == "__main__":
    app.run(port=3000)

This is what I see in the channel - the 404 error

I can't find a similar error and I read the slack-api docs. And /slack/events is setup as the Request URL in Interactivity settings.

0

There are 0 answers