Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import requests
  2. from flask import Flask, request #import main Flask class and request object
  3. from flask import json
  4.  
  5. app = Flask(__name__) #create the Flask app
  6.  
  7. @app.route('/slash', methods=['POST'])
  8. def slash_response():
  9. """ endpoint for receiving all slash command requests from Slack """
  10.  
  11. # blocks defintion from message builder
  12. # converting from JSON to array
  13. blocks = json.loads("""[
  14. {
  15. "type": "section",
  16. "text": {
  17. "type": "plain_text",
  18. "text": "Please select an option:",
  19. "emoji": true
  20. }
  21. },
  22. {
  23. "type": "actions",
  24. "elements": [
  25. {
  26. "type": "button",
  27. "text": {
  28. "type": "plain_text",
  29. "text": "Click me",
  30. "emoji": true
  31. },
  32. "value": "button_1"
  33. }
  34. ]
  35. }
  36. ]""")
  37.  
  38. # compose response message
  39. response = {
  40. "blocks": blocks
  41. }
  42.  
  43. ## convert response message into JSON and send back to Slack
  44. return json.jsonify(response)
  45.  
  46. @app.route('/interactive', methods=['POST'])
  47. def interactive_response():
  48. """ endpoint for receiving all interactivity requests from Slack """
  49.  
  50. # compose response message
  51. response = {
  52. "text": "Hi there"
  53. }
  54.  
  55. ## convert response message into JSON and send back to Slack
  56. return json.jsonify(response)
  57.  
  58. if __name__ == '__main__':
  59. app.run(debug=True, port=8000) #run app in debug mode on port 8000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement