Spaces:
Sleeping
Sleeping
Update router.py
Browse files
router.py
CHANGED
|
@@ -32,12 +32,25 @@ def _get_sender_role(user_id: str) -> str:
|
|
| 32 |
return "unknown"
|
| 33 |
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def route_event(event: dict) -> None:
|
| 36 |
"""
|
| 37 |
-
Entry point for every Slack message event
|
| 38 |
-
|
| 39 |
"""
|
| 40 |
user_id = event.get("user", "")
|
|
|
|
| 41 |
|
| 42 |
# Ignore bot messages (including our own)
|
| 43 |
if event.get("bot_id") or event.get("subtype") == "bot_message":
|
|
@@ -48,6 +61,10 @@ def route_event(event: dict) -> None:
|
|
| 48 |
if not text:
|
| 49 |
return
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
sender_role = _get_sender_role(user_id)
|
| 52 |
|
| 53 |
if sender_role == "unknown":
|
|
|
|
| 32 |
return "unknown"
|
| 33 |
|
| 34 |
|
| 35 |
+
def _is_managed_channel(channel_id: str) -> bool:
|
| 36 |
+
"""
|
| 37 |
+
Returns True if the message comes from a channel
|
| 38 |
+
that has at least one registered candidate.
|
| 39 |
+
"""
|
| 40 |
+
candidates = sheets.get_active_candidates()
|
| 41 |
+
managed = {c.get("channel_id", "") for c in candidates if c.get("channel_id")}
|
| 42 |
+
# Also allow the default env channel for backwards compatibility
|
| 43 |
+
managed.add(os.environ.get("SLACK_CHANNEL_ID", ""))
|
| 44 |
+
return channel_id in managed
|
| 45 |
+
|
| 46 |
+
|
| 47 |
def route_event(event: dict) -> None:
|
| 48 |
"""
|
| 49 |
+
Entry point for every Slack message event.
|
| 50 |
+
Handles messages from any registered department channel.
|
| 51 |
"""
|
| 52 |
user_id = event.get("user", "")
|
| 53 |
+
channel_id = event.get("channel", "")
|
| 54 |
|
| 55 |
# Ignore bot messages (including our own)
|
| 56 |
if event.get("bot_id") or event.get("subtype") == "bot_message":
|
|
|
|
| 61 |
if not text:
|
| 62 |
return
|
| 63 |
|
| 64 |
+
# Only process messages from managed department channels
|
| 65 |
+
if not _is_managed_channel(channel_id):
|
| 66 |
+
return
|
| 67 |
+
|
| 68 |
sender_role = _get_sender_role(user_id)
|
| 69 |
|
| 70 |
if sender_role == "unknown":
|