Skip to content

Commit 5211e7d

Browse files
committed
ref(slack): Fix thread_ts handling and add missing type annotations
Remove the ts fallback from SlackEventRequest.thread_ts so top-level messages correctly yield None instead of collapsing into the message ts. Add missing return type annotations to has_assistant_scope and is_assistant_thread_event. Move variable extraction before org resolution in _handle_seer_prompt for earlier lifecycle context.
1 parent b7049b3 commit 5211e7d

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/sentry/integrations/slack/requests/event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def user_id(self) -> str:
7575
def thread_ts(self) -> str:
7676
if self.is_assistant_thread_event:
7777
return self.dm_data.get("assistant_thread", {}).get("thread_ts", "")
78-
return self.dm_data.get("thread_ts") or self.dm_data.get("ts", "")
78+
return self.dm_data.get("thread_ts")
7979

8080
@property
81-
def has_assistant_scope(self):
81+
def has_assistant_scope(self) -> bool:
8282
return SlackScope.ASSISTANT_WRITE in self.integration.metadata.get("scopes", [])
8383

8484
@property
85-
def is_assistant_thread_event(self):
85+
def is_assistant_thread_event(self) -> bool:
8686
return self.dm_data.get("type") == "assistant_thread_started"
8787

8888
@property

src/sentry/integrations/slack/webhooks/event.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,17 @@ def _handle_seer_prompt(
447447
spec=SlackMessagingSpec(),
448448
).capture() as lifecycle:
449449
data = slack_request.data.get("event", {})
450+
channel_id = data.get("channel")
451+
text = data.get("text")
452+
ts = data.get("ts") or data.get("message_ts")
453+
thread_ts = slack_request.thread_ts
450454
lifecycle.add_extras(
451455
{
452456
"integration_id": slack_request.integration.id,
453-
"thread_ts": data.get("thread_ts"),
457+
"thread_ts": thread_ts,
458+
"channel_id": channel_id,
459+
"text": text,
460+
"ts": ts,
454461
}
455462
)
456463

@@ -465,21 +472,6 @@ def _handle_seer_prompt(
465472
organization_id = result["organization_id"]
466473
installation = result["installation"]
467474

468-
channel_id = data.get("channel")
469-
text = data.get("text")
470-
ts = data.get("ts") or data.get("message_ts")
471-
thread_ts = data.get("thread_ts")
472-
473-
lifecycle.add_extras(
474-
{
475-
"channel_id": channel_id,
476-
"text": text,
477-
"ts": ts,
478-
"thread_ts": thread_ts,
479-
"user_id": slack_request.user_id,
480-
}
481-
)
482-
483475
if not channel_id or not text or not ts or not slack_request.user_id:
484476
lifecycle.record_halt(SeerSlackHaltReason.MISSING_EVENT_DATA)
485477
return self.respond()
@@ -606,6 +598,7 @@ def post(self, request: Request) -> Response:
606598
command, _ = slack_request.get_command_and_args()
607599

608600
resp: Response | None
601+
# If we have the assistant scope, we don't want to fallback to commands anymore.
609602
if slack_request.has_assistant_scope:
610603
resp = self.on_direct_message(slack_request)
611604
elif command in COMMANDS:

0 commit comments

Comments
 (0)