()
| 32 | |
| 33 | @app.route("/slack/events", methods=["POST"]) |
| 34 | def slack_app(): |
| 35 | if not signature_verifier.is_valid_request(request.get_data(), request.headers): |
| 36 | return make_response("invalid request", 403) |
| 37 | |
| 38 | if "payload" in request.form: |
| 39 | payload = json.loads(request.form["payload"]) |
| 40 | if payload["type"] == "shortcut" and payload["callback_id"] == "test-shortcut": |
| 41 | # Open a new modal by a global shortcut |
| 42 | try: |
| 43 | view = View( |
| 44 | type="modal", |
| 45 | callback_id="modal-id", |
| 46 | title=PlainTextObject(text="Awesome Modal"), |
| 47 | submit=PlainTextObject(text="Submit"), |
| 48 | close=PlainTextObject(text="Cancel"), |
| 49 | blocks=[ |
| 50 | InputBlock( |
| 51 | block_id="b-id", |
| 52 | label=PlainTextObject(text="Input label"), |
| 53 | element=PlainTextInputElement(action_id="a-id"), |
| 54 | ) |
| 55 | ], |
| 56 | ) |
| 57 | api_response = client.views_open( |
| 58 | trigger_id=payload["trigger_id"], |
| 59 | view=view, |
| 60 | ) |
| 61 | return make_response("", 200) |
| 62 | except SlackApiError as e: |
| 63 | code = e.response["error"] |
| 64 | return make_response(f"Failed to open a modal due to {code}", 200) |
| 65 | |
| 66 | if payload["type"] == "view_submission" and payload["view"]["callback_id"] == "modal-id": |
| 67 | # Handle a data submission request from the modal |
| 68 | submitted_data = payload["view"]["state"]["values"] |
| 69 | print(submitted_data) # {'b-id': {'a-id': {'type': 'plain_text_input', 'value': 'your input'}}} |
| 70 | return make_response( |
| 71 | jsonify( |
| 72 | { |
| 73 | "response_action": "update", |
| 74 | "view": View( |
| 75 | type="modal", |
| 76 | callback_id="modal-id", |
| 77 | title=PlainTextObject(text="Accepted"), |
| 78 | close=PlainTextObject(text="Close"), |
| 79 | blocks=[ |
| 80 | SectionBlock( |
| 81 | block_id="b-id", |
| 82 | text=PlainTextObject(text="Thanks for submitting the data!"), |
| 83 | ) |
| 84 | ], |
| 85 | ).to_dict(), |
| 86 | } |
| 87 | ), |
| 88 | 200, |
| 89 | ) |
| 90 | |
| 91 | return make_response("", 404) |
nothing calls this directly
no test coverage detected