Skip to content

Commit 8574e7d

Browse files
committed
fix(slack): resolve httpx protocol errors and unbound variables
- Removed markdown formatting from Slack API URLs to fix UnsupportedProtocol. - Added safety checks for response_url to prevent 500 errors in App Home interactions. - Initialized action_id and cast IDs to strings to satisfy Pylance strict mode.
1 parent 61ca84c commit 8574e7d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

backend/api/routes/feedback.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ async def slack_interactions(request: Request):
6767
headers = {"Authorization": f"Bearer {slack_token}"}
6868

6969
if interaction_type == "block_actions":
70-
response_url = str(payload.get("response_url", ""))
7170
trigger_id = str(payload.get("trigger_id", ""))
7271
action = payload.get("actions", [])[0]
7372
action_id = action.get("action_id")
73+
response_url = payload.get("response_url")
74+
75+
if not response_url or not isinstance(response_url, str):
76+
logger.warning("slack_interaction_no_response_url", action_id=action_id)
77+
return Response(status_code=200)
7478

7579
blocks = payload.get("message", {}).get("blocks", [])
7680
raw_draft = blocks[1]["text"]["text"] if len(blocks) > 1 else ""
@@ -83,7 +87,7 @@ async def slack_interactions(request: Request):
8387
modal_view = build_upload_modal()
8488
async with httpx.AsyncClient() as client:
8589
res = await client.post(
86-
"[https://slack.com/api/views.open](https://slack.com/api/views.open)",
90+
"https://slack.com/api/views.open",
8791
headers=headers,
8892
json={"trigger_id": trigger_id, "view": modal_view},
8993
)
@@ -140,7 +144,7 @@ async def slack_interactions(request: Request):
140144
)
141145
async with httpx.AsyncClient() as client:
142146
res = await client.post(
143-
"[https://slack.com/api/views.open](https://slack.com/api/views.open)",
147+
"https://slack.com/api/views.open",
144148
headers=headers,
145149
json={"trigger_id": trigger_id, "view": modal_view},
146150
)
@@ -176,7 +180,7 @@ async def slack_interactions(request: Request):
176180
modal_view = build_generation_modal(channel_id=user_id)
177181
async with httpx.AsyncClient() as client:
178182
res = await client.post(
179-
"[https://slack.com/api/views.open](https://slack.com/api/views.open)",
183+
"https://slack.com/api/views.open",
180184
headers=headers,
181185
json={"trigger_id": trigger_id, "view": modal_view},
182186
)

0 commit comments

Comments
 (0)