MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / slack_app

Function slack_app

integration_tests/samples/basic_usage/views.py:30–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

is_valid_requestMethod · 0.45
views_openMethod · 0.45

Tested by

no test coverage detected