Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from flask import Flask, request #import main Flask class and request object
- from flask import json
- app = 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
- response = {
- "text": "Hi there"
- }
- ## convert response message into JSON and send back to Slack
- return json.jsonify(response)
- if __name__ == '__main__':
- app.run(debug=True, port=8000) #run app in debug mode on port 8000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement