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(telegram): align resume and cwd command flows

cyh6b07f0343ac7
diff --git a/core/handlers/session_handler.py b/core/handlers/session_handler.py
index 69b1d5901..52961710a 100644
--- a/core/handlers/session_handler.py
+++ b/core/handlers/session_handler.py
@@ -249,7 +249,13 @@ class SessionHandler(BaseHandler):
im_client = self._get_im_client(context)
if is_dm:
return bool(getattr(im_client, "should_use_thread_for_dm_session", lambda: False)())
- return bool(getattr(im_client, "should_use_thread_for_reply", lambda: False)())
+ uses_thread_replies = bool(getattr(im_client, "should_use_thread_for_reply", lambda: False)())
+ if not uses_thread_replies:
+ return False
+ uses_message_anchor = bool(
+ getattr(im_client, "should_use_message_id_for_channel_session", lambda _context=None: True)(context)
+ )
+ return uses_message_anchor
def _build_resume_confirmation(
self,
@@ -630,11 +636,12 @@ class SessionHandler(BaseHandler):
)
mapped_thread = followup_context.thread_id or confirmation_ts
+ mapping_thread_id = mapped_thread if thread_capable else None
mapping_context = MessageContext(
user_id=user_id,
channel_id=followup_context.channel_id,
platform=followup_context.platform,
- thread_id=mapped_thread,
+ thread_id=mapping_thread_id,
message_id=confirmation_ts,
platform_specific={"is_dm": is_dm},
)
diff --git a/modules/im/telegram.py b/modules/im/telegram.py
index b27c455b4..b9f7c03b8 100644
--- a/modules/im/telegram.py
+++ b/modules/im/telegram.py
@@ -521,18 +521,20 @@ class TelegramBot(BaseIMClient):
await self.send_message(context, self._t("telegram.cwdPromptCanceled"))
return True
known_commands = {
- "/start",
- "/new",
- "/clear",
- "/resume",
- "/settings",
- "/routing",
- "/cwd",
- "/setcwd",
- "/bind",
- "/stop",
+ "start",
+ "new",
+ "clear",
+ "resume",
+ "settings",
+ "routing",
+ "cwd",
+ "setcwd",
+ "set_cwd",
+ "bind",
+ "stop",
}
- if stripped in known_commands:
+ parsed_command = self.parse_text_command(stripped, allow_plain_bind=True)
+ if parsed_command and parsed_command[0] in known_commands:
return False
self._cwd_prompts.pop(self._interaction_scope_key(context), None)
if self._controller is None or not hasattr(self._controller, "command_handler"):
diff --git a/tests/test_resume_session.py b/tests/test_resume_session.py
index a93387ffe..5d3e02371 100644
--- a/tests/test_resume_session.py
+++ b/tests/test_resume_session.py
@@ -244,6 +244,35 @@ class ResumeSessionTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(im_client.messages[1][1], "SUB123")
self.assertIn("Reply in the subchannel", im_client.messages[1][2])
+ async def test_handle_resume_session_submission_telegram_group_keeps_channel_mapping(self):
+ settings = _StubSettingsManager()
+ im_client = _StubIMClient()
+ ctrl = _StubController()
+ ctrl.init_minimal(im_client, settings, _StubConfig(platform="telegram"))
+ ctrl.im_client.should_use_thread_for_reply = lambda: True
+ ctrl.im_client.should_use_message_id_for_channel_session = lambda context=None: False
+
+ await ctrl.session_handler.handle_resume_session_submission(
+ user_id="U777",
+ channel_id="-100123",
+ thread_id=None,
+ agent="codex",
+ session_id="sess_telegram_group",
+ host_message_ts="HOST1",
+ is_dm=False,
+ platform="telegram",
+ )
+
+ self.assertEqual(
+ settings.set_calls,
+ [("telegram::-100123", "codex", "telegram_-100123", "sess_telegram_group")],
+ )
+ self.assertEqual(settings.mark_calls, [("U777", "-100123", "T1")])
+ self.assertEqual(len(im_client.messages), 2)
+ self.assertEqual(im_client.messages[0][1], None)
+ self.assertEqual(im_client.messages[1][1], None)
+ self.assertIn("Send your next message directly", im_client.messages[1][2])
+
async def test_command_handlers_handle_resume_opens_modal(self):
settings = _StubSettingsManager()
im_client = _StubIMClient()
diff --git a/tests/test_telegram_bot.py b/tests/test_telegram_bot.py
index 6eb00fbcc..4be05cabb 100644
--- a/tests/test_telegram_bot.py
+++ b/tests/test_telegram_bot.py
@@ -137,6 +137,23 @@ def test_pending_cwd_prompt_consumes_next_plain_message() -> None:
assert bot._interaction_scope_key(context) not in bot._cwd_prompts
+def test_pending_cwd_prompt_bypasses_slash_command_with_args() -> None:
+ bot = TelegramBot(TelegramConfig(bot_token="123456:test-token"))
+ context = MessageContext(
+ user_id="42",
+ channel_id="-100123",
+ thread_id="1",
+ platform="telegram",
+ platform_specific={"is_dm": False},
+ )
+ bot._cwd_prompts[bot._interaction_scope_key(context)] = SimpleNamespace(message_id="10", current_cwd="/tmp")
+
+ handled = asyncio.run(bot._consume_cwd_prompt(context, "/resume codex:abc"))
+
+ assert handled is False
+ assert bot._interaction_scope_key(context) in bot._cwd_prompts
+
+
def test_resume_menu_uses_short_callback_ids() -> None:
bot = TelegramBot(TelegramConfig(bot_token="123456:test-token"))
context = MessageContext(