Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix: Correct Slack thread reply behavior to use user message timestamp

cyhhao97a90294b2cb
diff --git a/core/controller.py b/core/controller.py
index 745327875..02540ea89 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -135,24 +135,22 @@ Choose a command below or type any message to add it to the processing queue."""
# Send confirmation reply immediately
target_context = self._get_target_context(context)
- # For Slack, establish thread with the confirmation message
+ # For Slack, use the user's message timestamp as thread
confirmation_msg = None
- if self.config.platform == "slack" and hasattr(self.im_client, 'get_or_create_thread'):
- # Create thread if needed
- thread_ts = await self.im_client.get_or_create_thread(
- target_context.channel_id,
- target_context.user_id
- )
- if thread_ts:
- target_context.thread_id = thread_ts
+ if self.config.platform == "slack":
+ # Use the user's message timestamp as the thread ID
+ user_message_ts = context.message_id # This is the timestamp of the user's message
+ if user_message_ts:
+ target_context.thread_id = user_message_ts
- # Send confirmation with thread context
+ # Send confirmation as reply in the thread
confirmation_text = f"📝 *Received:* {message}\n⏳ *Processing...*"
formatted_confirmation = self.im_client.format_markdown(confirmation_text)
confirmation_msg = await self.im_client.send_message(
target_context,
formatted_confirmation,
- parse_mode='markdown'
+ parse_mode='markdown',
+ reply_to=user_message_ts # Reply to the user's message
)
else:
# For non-Slack platforms, just send confirmation
@@ -164,15 +162,15 @@ Choose a command below or type any message to add it to the processing queue."""
parse_mode='markdown'
)
- # Store thread context with the message
- thread_id = getattr(target_context, 'thread_id', None)
+ # Store thread context with the message (use user's message timestamp for Slack)
+ thread_id = user_message_ts if self.config.platform == "slack" and user_message_ts else None
await self.session_manager.add_message_with_context(
context.user_id,
context.channel_id,
message,
thread_id=thread_id
)
- logger.info(f"User {context.user_id} added message to queue")
+ logger.info(f"User {context.user_id} added message to queue with thread_id: {thread_id}")
# Check if not already executing, then start processing
if not await self.session_manager.is_executing(context.user_id):
@@ -220,7 +218,12 @@ Choose a command below or type any message to add it to the processing queue."""
target_context.thread_id = thread_id
formatted_msg = self.im_client.format_markdown(claude_msg)
- await self.im_client.send_message(target_context, formatted_msg, parse_mode='markdown')
+ await self.im_client.send_message(
+ target_context,
+ formatted_msg,
+ parse_mode='markdown',
+ reply_to=thread_id if self.config.platform == "slack" else None
+ )
try:
await self.claude_client.stream_execute(message, on_claude_message, context.user_id)
@@ -234,12 +237,14 @@ Choose a command below or type any message to add it to the processing queue."""
if remaining:
await self.im_client.send_message(
target_context,
- "✅ Completed. Processing next message..."
+ "✅ Completed. Processing next message...",
+ reply_to=thread_id if self.config.platform == "slack" else None
)
else:
await self.im_client.send_message(
target_context,
- "✅ All messages processed!"
+ "✅ All messages processed!",
+ reply_to=thread_id if self.config.platform == "slack" else None
)
except Exception as e:
@@ -249,7 +254,8 @@ Choose a command below or type any message to add it to the processing queue."""
self.claude_client.options.cwd = original_cwd
await self.im_client.send_message(
target_context,
- f"❌ Error processing message: {str(e)}\nStopping queue processing."
+ f"❌ Error processing message: {str(e)}\nStopping queue processing.",
+ reply_to=thread_id if self.config.platform == "slack" else None
)
break
diff --git a/modules/im/slack.py b/modules/im/slack.py
index 56d4c894b..bde2ccc24 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -22,8 +22,7 @@ class SlackBot(BaseIMClient):
self.web_client = None
self.socket_client = None
- # Store thread timestamps for conversation continuity
- self.thread_timestamps: Dict[str, str] = {}
+ # Note: Thread handling now uses user's message timestamp directly
# Store callback handlers
self.command_handlers: Dict[str, Callable] = {}
@@ -61,6 +60,9 @@ class SlackBot(BaseIMClient):
# Optionally broadcast to channel
if context.platform_specific and context.platform_specific.get('reply_broadcast'):
kwargs['reply_broadcast'] = True
+ elif reply_to:
+ # If reply_to is specified, use it as thread timestamp
+ kwargs['thread_ts'] = reply_to
# Handle formatting
if parse_mode == 'markdown':
@@ -69,11 +71,6 @@ class SlackBot(BaseIMClient):
# Send message
response = await self.web_client.chat_postMessage(**kwargs)
- # Store thread timestamp for future replies
- if not context.thread_id and response['ts']:
- thread_key = f"{context.channel_id}:{context.user_id}"
- self.thread_timestamps[thread_key] = response['ts']
-
return response['ts']
except SlackApiError as e:
@@ -658,8 +655,8 @@ class SlackBot(BaseIMClient):
async def get_or_create_thread(self, channel_id: str, user_id: str) -> Optional[str]:
"""Get existing thread timestamp or return None for new thread"""
- thread_key = f"{channel_id}:{user_id}"
- return self.thread_timestamps.get(thread_key)
+ # Deprecated: Thread handling now uses user's message timestamp directly
+ return None
async def send_slash_response(self, response_url: str, text: str,
ephemeral: bool = True) -> bool: