Interactive response not shown on Slack
I found a section on the Slack API page that explains what's going on with your interactive component!
Everything I am about to go over is in the Responding to the interaction section of the official documentation.
There are two steps to responding to an interaction:
- Acknowledgment response - send an OK 200 back to slack within 3 seconds of receiving the request payload. The text you send with this response will not alter the contents of the current slack message.
- Composed response - send your updated message to slack using a POST request and the response_url they package in the request payload.
So the reason OP's code does not work is that Slack does no longer accept a full message as direct response to an interaction. Instead all response messages need to be send to the response_url
.
However, to enable backwards compatibility it is still possible to respond directly with message including attachments, but not with messages containing layout blocks.
Code
Here is the code I used to substitute the original button message with the text "Hi Erik!"
import requestsfrom flask import Flask, json, requestapp = Flask(__name__) #create the Flask app@app.route('/slash', methods=['POST'])def slash_response(): """ endpoint for receiving all slash command requests from Slack """ # blocks defintion from message builder # converting from JSON to array blocks = json.loads("""[ { "type": "section", "text": { "type": "plain_text", "text": "Please select an option:", "emoji": true } }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "Click me", "emoji": true }, "value": "button_1" } ] } ]""") # compose response message response = { "blocks": blocks } ## convert response message into JSON and send back to Slack return json.jsonify(response)@app.route('/interactive', methods=['POST'])def interactive_response(): """ endpoint for receiving all interactivity requests from Slack """ # compose response message data = json.loads(request.form["payload"]) response = { 'text': 'Hi Erik!', } requests.post(data['response_url'], json=response) return '' if __name__ == '__main__': app.run(debug=True, port=8000) #run app in debug mode on port 8000