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(slack): preserve reply target in markdown fallback

cyh29d777d37722
diff --git a/modules/im/slack.py b/modules/im/slack.py
index d1c2cab55..8c33b7f3b 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -740,7 +740,13 @@ class SlackBot(BaseIMClient):
if len(text) > _SLACK_MARKDOWN_TEXT_LIMIT:
if keyboard:
- return await self.send_message_with_buttons(context, text, keyboard, parse_mode="markdown")
+ return await self.send_message_with_buttons(
+ context,
+ text,
+ keyboard,
+ parse_mode="markdown",
+ reply_to=reply_to,
+ )
return await self.send_message(context, text, parse_mode="markdown", reply_to=reply_to)
blocks = [self._build_markdown_block(text)]
@@ -772,7 +778,13 @@ class SlackBot(BaseIMClient):
raise
logger.warning("Slack rejected native markdown block; falling back to legacy mrkdwn rendering")
if keyboard:
- return await self.send_message_with_buttons(context, text, keyboard, parse_mode="markdown")
+ return await self.send_message_with_buttons(
+ context,
+ text,
+ keyboard,
+ parse_mode="markdown",
+ reply_to=reply_to,
+ )
return await self.send_message(context, text, parse_mode="markdown", reply_to=reply_to)
if self.settings_manager and (context.thread_id or reply_to):
@@ -1375,6 +1387,7 @@ class SlackBot(BaseIMClient):
text: str,
keyboard: InlineKeyboard,
parse_mode: Optional[str] = None,
+ reply_to: Optional[str] = None,
) -> str:
"""Send a message with interactive buttons"""
self._ensure_clients()
@@ -1394,7 +1407,7 @@ class SlackBot(BaseIMClient):
else self._split_text(text, _SLACK_SECTION_TEXT_LIMIT)
)
for chunk in chunks[:-1]:
- await self._send_prepared_text_message(context, chunk, parse_mode=parse_mode)
+ await self._send_prepared_text_message(context, chunk, parse_mode=parse_mode, reply_to=reply_to)
text = chunks[-1]
visible_text = self._linkify_bare_urls_for_verbatim_mrkdwn(text) if linkify_verbatim_urls else text
@@ -1412,6 +1425,8 @@ class SlackBot(BaseIMClient):
# Handle thread replies
if context.thread_id:
kwargs["thread_ts"] = context.thread_id
+ elif reply_to:
+ kwargs["thread_ts"] = reply_to
response = await self._post_message_with_dm_recovery(
context,
@@ -1420,10 +1435,11 @@ class SlackBot(BaseIMClient):
)
# Mark thread as active if we sent a message to a thread
- if self.settings_manager and context.thread_id:
+ if self.settings_manager and (context.thread_id or reply_to):
+ thread_ts = context.thread_id or reply_to
if self.sessions:
- self.sessions.mark_thread_active(context.user_id, context.channel_id, context.thread_id)
- logger.debug(f"Marked thread {context.thread_id} as active after bot message with buttons")
+ self.sessions.mark_thread_active(context.user_id, context.channel_id, thread_ts)
+ logger.debug(f"Marked thread {thread_ts} as active after bot message with buttons")
return response["ts"]
diff --git a/tests/test_slack_dm_mentions.py b/tests/test_slack_dm_mentions.py
index 3154549d1..111532980 100644
--- a/tests/test_slack_dm_mentions.py
+++ b/tests/test_slack_dm_mentions.py
@@ -203,6 +203,59 @@ class SlackDmMentionTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(sent_payloads[1]["blocks"][0]["type"], "section")
self.assertEqual(sent_payloads[1]["blocks"][0]["text"]["type"], "mrkdwn")
+ async def test_send_markdown_message_long_button_fallback_preserves_reply_to(self):
+ slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
+ sent_payloads = []
+
+ class _WebClient:
+ async def chat_postMessage(self, **kwargs):
+ sent_payloads.append(kwargs)
+ return {"ts": "1710000000.000022"}
+
+ slack.web_client = _WebClient()
+ context = MessageContext(user_id="U123", channel_id="C123")
+ keyboard = InlineKeyboard(buttons=[[InlineButton(text="Continue", callback_data="quick_reply:Continue")]])
+ text = "x" * 12001
+
+ message_ts = await slack.send_markdown_message(
+ context,
+ text,
+ keyboard=keyboard,
+ reply_to="1710000000.000001",
+ )
+
+ self.assertEqual(message_ts, "1710000000.000022")
+ self.assertGreater(len(sent_payloads), 1)
+ self.assertTrue(all(payload["thread_ts"] == "1710000000.000001" for payload in sent_payloads))
+ self.assertEqual(sent_payloads[-1]["blocks"][-1]["type"], "actions")
+
+ async def test_send_markdown_message_button_rejection_fallback_preserves_reply_to(self):
+ slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
+ sent_payloads = []
+
+ class _WebClient:
+ async def chat_postMessage(self, **kwargs):
+ sent_payloads.append(kwargs)
+ if len(sent_payloads) == 1:
+ raise SlackApiError("invalid blocks", response=_ResponseLike({"error": "invalid_blocks"}))
+ return {"ts": "1710000000.000023"}
+
+ slack.web_client = _WebClient()
+ context = MessageContext(user_id="U123", channel_id="C123")
+ keyboard = InlineKeyboard(buttons=[[InlineButton(text="Continue", callback_data="quick_reply:Continue")]])
+
+ message_ts = await slack.send_markdown_message(
+ context,
+ "markdown table",
+ keyboard=keyboard,
+ reply_to="1710000000.000001",
+ )
+
+ self.assertEqual(message_ts, "1710000000.000023")
+ self.assertEqual(sent_payloads[0]["thread_ts"], "1710000000.000001")
+ self.assertEqual(sent_payloads[1]["thread_ts"], "1710000000.000001")
+ self.assertEqual(sent_payloads[1]["blocks"][-1]["type"], "actions")
+
async def test_send_message_disables_link_unfurl_when_configured(self):
slack = SlackBot(SlackConfig(bot_token="xoxb-test", disable_link_unfurl=True))
sent_payloads = []