feat(slack): fetch thread context via conversations.replies#6008
Closed
tonywcs wants to merge 1 commit into
Closed
feat(slack): fetch thread context via conversations.replies#6008tonywcs wants to merge 1 commit into
tonywcs wants to merge 1 commit into
Conversation
When a user messages in a Slack thread, the agent now fetches prior thread messages via the Slack API (conversations.replies) and injects them as context. This gives the agent visibility into the full thread conversation, even on first interaction or after a gateway restart. Changes: - Add _fetch_thread_context() method that calls conversations.replies to retrieve up to 20 prior messages in a thread - Inject thread context into the message text before processing - Track fetched threads to avoid redundant API calls - Only triggers for thread replies (thread_ts != ts), not channel msgs Also includes the existing active thread tracking so the bot responds to follow-up messages in threads it has already participated in, without requiring a new @mention each time.
Contributor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When a user messages in a Slack thread, the agent currently has no visibility into prior thread messages — each thread reply starts with zero context. This PR fixes that by fetching thread history from the Slack API.
Changes
_fetch_thread_context()— new method that callsconversations.repliesto retrieve up to 20 prior messages in a thread, formatted as[sender]: messagelinesthread_ts != ts), prior messages are fetched and prepended to the user's message as context_thread_history_fetchedset prevents redundant API calls for the same thread@mentioneach timeHow it works
thread_ts != ts(this is a thread reply)conversations.repliesto get prior messagesWhat's NOT affected
Testing
All 64 existing Slack tests pass. Tested manually in production Slack workspace.