0

I'm starting to use the Slack API with Python.

So far I was able to connect it and send messages just fine.

I want to create a dialog option so users can input variables and I'm able to do it but when I try to submit the dialog, an error appears saying: We had some trouble connecting. Try again?

slack bot fail

Here's the code:

@app.route("/test", methods=["POST"])
def message_actions():
    data = request.form
    user_id = data.get('user_id')
    client.api_call(api_method="dialog.open",
                    json={"trigger_id": data.get("trigger_id"),
                          "dialog": {
                        "title": "Request a coffee",
                        "submit_label": "Submit",
                        "callback_id": user_id + "coffee_order_form",
                        "elements": [{
                            "label": "Coffee Type",
                            "type": "select",
                            "name": "meal_preferences",
                            "placeholder": "Select a drink",
                            "options": [
                                {
                                    "label": "Cappuccino",
                                    "value": "cappuccino"
                                },
                                {
                                    "label": "Latte",
                                    "value": "latte"
                                },
                                {
                                    "label": "Pour Over",
                                    "value": "pour_over"
                                },
                                {
                                    "label": "Cold Brew",
                                    "value": "cold_brew"
                                }
                            ]
                        }
                        ]
                    }}
                    )

    return make_response("", 200)

1 Answers1

0

You are not showing us any of the code that is supposed to handle the submission of the modal, only the code that creates it.

When the user submits the modal, your app will need to handle a view_submission event

I'm not sure if you are using bolt, but you can see an example of how view_submissions are handled with slack bolt here

You'll need to acknowledge the submission within 3 seconds. A simple 200 will do

m.oulmakki
  • 296
  • 1
  • 6