-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(slack): preserve thread context and always send fallback text #6255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jacobinwwey
wants to merge
11
commits into
AstrBotDevs:master
Choose a base branch
from
Jacobinwwey:fix/slack-thread-context-and-text-fallback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6e4ee51
fix(slack): preserve thread context and always send fallback text
Jacobinwwey 2154dff
refactor(slack): centralize target resolution and harden session decode
Jacobinwwey 8c1a09c
refactor(slack): split target resolution and clarify thread unwrapping
Jacobinwwey 7af3441
feat(slack): make fallback text configurable via platform config
Jacobinwwey b9d8dcb
fix(slack): log fallback errors and unify target resolution
Jacobinwwey bb8f0f8
fix(slack): align session send fallback and typing
Jacobinwwey 21e6597
refactor(slack): centralize send fallback and simplify session decode
Jacobinwwey af0c02c
refactor(slack): thread pre-normalized fallbacks through send pipeline
Jacobinwwey 35c6a0c
fix(slack): preserve fallback text and guard empty send target
Jacobinwwey 08c71aa
refactor(slack): simplify target resolver and harden fallback retry text
Jacobinwwey d5e6391
style(slack): apply ruff formatting
Jacobinwwey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| THREAD_SESSION_MARKER = "__thread__" | ||
| LEGACY_GROUP_SESSION_PREFIX = "group_" | ||
| SLACK_SAFE_TEXT_FALLBACK = "message" | ||
|
|
||
|
|
||
| def encode_thread_session_id(channel_id: str, thread_ts: str) -> str: | ||
| if not channel_id or not thread_ts: | ||
| return channel_id | ||
| return f"{channel_id}{THREAD_SESSION_MARKER}{thread_ts}" | ||
|
|
||
|
|
||
| def decode_slack_session_id(session_id: str) -> tuple[str, str | None]: | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
| if not session_id: | ||
| return "", None | ||
|
|
||
| if THREAD_SESSION_MARKER in session_id: | ||
| channel_id, thread_ts = session_id.split(THREAD_SESSION_MARKER, 1) | ||
| # Do not fallback to legacy parsing once thread marker is detected. | ||
| # Keep decoded channel_id even if thread_ts is missing. | ||
| return channel_id, thread_ts or None | ||
|
|
||
| # Backward compatibility for historical IDs like "group_<channel_id>". | ||
| if session_id.startswith(LEGACY_GROUP_SESSION_PREFIX): | ||
| return session_id[len(LEGACY_GROUP_SESSION_PREFIX) :], None | ||
|
|
||
| return session_id, None | ||
|
|
||
|
|
||
| def resolve_slack_message_target( | ||
| session_id: str, | ||
| *, | ||
| raw_message: dict | None = None, | ||
| group_id: str = "", | ||
| sender_id: str = "", | ||
| ) -> tuple[str, str | None]: | ||
| parsed_channel_id, parsed_thread_ts = decode_slack_session_id(session_id) | ||
|
|
||
| raw_channel_id = "" | ||
| raw_thread_ts = None | ||
| if isinstance(raw_message, dict): | ||
| raw_channel = raw_message.get("channel") | ||
| if raw_channel is not None and raw_channel != "": | ||
| raw_channel_id = str(raw_channel) | ||
| raw_thread = raw_message.get("thread_ts") | ||
| if raw_thread is not None and raw_thread != "": | ||
| raw_thread_ts = str(raw_thread) | ||
|
|
||
| channel_id = group_id or raw_channel_id or parsed_channel_id or sender_id | ||
| return channel_id, raw_thread_ts or parsed_thread_ts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.