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.

feat: Remove platform-specific checks from controller

cyhhaoc47ff9338d24
diff --git a/core/controller.py b/core/controller.py
index b19733be1..303e6095b 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -135,12 +135,11 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
target_context = self._get_target_context(context)
# For Telegram, send with MarkdownV2 parse mode
# For Slack, use markdown
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
+ # parse_mode will be defaulted by IM client
await self.im_client.send_message_with_buttons(
target_context,
welcome_text,
- keyboard,
- parse_mode=parse_mode
+ keyboard
)
async def handle_user_message(self, context: MessageContext, message: str):
@@ -316,9 +315,11 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
# Format ready message using formatter
formatter = self.im_client.formatter
ready_msg = formatter.format_success("Ready for next message!")
+ # parse_mode will be defaulted by IM client
await self.im_client.send_message(
target_context,
ready_msg,
+ parse_mode=parse_mode,
reply_to=thread_id if self.config.platform == "slack" else None
)
@@ -515,8 +516,8 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
# Combine all parts
response_text = path_line + "\n" + "\n".join(status_lines)
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
- await self.im_client.send_message(context, response_text, parse_mode=parse_mode)
+ # parse_mode will be defaulted by IM client
+ await self.im_client.send_message(context, response_text)
except Exception as e:
logger.error(f"Error getting cwd: {e}")
await self.im_client.send_message(context, f"Error getting working directory: {str(e)}")
@@ -547,8 +548,8 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
if not os.path.isdir(absolute_path):
formatter = self.im_client.formatter
error_text = f"❌ Path exists but is not a directory: {formatter.format_code_inline(absolute_path)}"
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
- await self.im_client.send_message(context, error_text, parse_mode=parse_mode)
+ # parse_mode will be defaulted by IM client
+ await self.im_client.send_message(context, error_text)
return
# Save to user settings
@@ -563,8 +564,8 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
f"{formatter.format_code_inline(absolute_path)}\n\n"
f"This setting has been saved for your user."
)
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
- await self.im_client.send_message(context, response_text, parse_mode=parse_mode)
+ # parse_mode will be defaulted by IM client
+ await self.im_client.send_message(context, response_text)
except Exception as e:
logger.error(f"Error setting cwd: {e}")
@@ -784,8 +785,8 @@ Use the buttons below to manage your Claude Code sessions, or simply type any me
_Tip: All commands work in DMs, channels, and threads!_"""
# Send the info message for either info button
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
- await self.im_client.send_message(context, info_text, parse_mode=parse_mode)
+ # parse_mode will be defaulted by IM client
+ await self.im_client.send_message(context, info_text)
return
# Handle settings toggle buttons (existing functionality)
@@ -868,8 +869,8 @@ _Tip: All commands work in DMs, channels, and threads!_"""
)
# Send as new message
- parse_mode = 'MarkdownV2' if self.config.platform == "telegram" else 'markdown'
- await self.im_client.send_message(context, info_text, parse_mode=parse_mode)
+ # parse_mode will be defaulted by IM client
+ await self.im_client.send_message(context, info_text)
logger.info(f"Sent info_msg_types message to user {context.user_id}")
except Exception as e:
diff --git a/modules/im/base.py b/modules/im/base.py
index 3f2afda39..0f7fa64b4 100644
--- a/modules/im/base.py
+++ b/modules/im/base.py
@@ -102,6 +102,24 @@ class BaseIMClient(ABC):
self.on_callback_query_callback: Optional[Callable] = None
# Platform-specific formatter will be set by subclasses
self.formatter = None
+
+ def get_default_parse_mode(self) -> str:
+ """Get the default parse mode for this platform
+
+ Returns:
+ Default parse mode string for the platform
+ """
+ # Default implementation - subclasses should override
+ return None
+
+ def should_use_thread_for_reply(self) -> bool:
+ """Check if this platform uses threads for replies
+
+ Returns:
+ True if platform uses threads (like Slack), False otherwise
+ """
+ # Default implementation - subclasses should override
+ return False
@abstractmethod
async def send_message(self, context: MessageContext, text: str,
diff --git a/modules/im/slack.py b/modules/im/slack.py
index f258000c3..c30b95b97 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -35,6 +35,14 @@ class SlackBot(BaseIMClient):
# Store trigger IDs for modal interactions
self.trigger_ids: Dict[str, str] = {}
+ def get_default_parse_mode(self) -> str:
+ """Get the default parse mode for Slack"""
+ return "markdown"
+
+ def should_use_thread_for_reply(self) -> bool:
+ """Slack uses threads for replies"""
+ return True
+
def _ensure_clients(self):
"""Ensure web and socket clients are initialized"""
if self.web_client is None:
@@ -159,6 +167,10 @@ class SlackBot(BaseIMClient):
"""Send a message with interactive buttons"""
self._ensure_clients()
try:
+ # Default to markdown for Slack if not specified
+ if not parse_mode:
+ parse_mode = 'markdown'
+
# Convert markdown to Slack mrkdwn if needed
if parse_mode == 'markdown':
text = self._convert_markdown_to_slack_mrkdwn(text)
diff --git a/modules/im/telegram.py b/modules/im/telegram.py
index 0a4d91f63..d8036ac38 100644
--- a/modules/im/telegram.py
+++ b/modules/im/telegram.py
@@ -35,6 +35,14 @@ class TelegramBot(BaseIMClient):
# Store callback queries for answering
self._callback_queries: Dict[str, Any] = {}
+
+ def get_default_parse_mode(self) -> str:
+ """Get the default parse mode for Telegram"""
+ return "MarkdownV2"
+
+ def should_use_thread_for_reply(self) -> bool:
+ """Telegram doesn't use threads for replies"""
+ return False
async def handle_telegram_message(
self, update: Update, tg_context: ContextTypes.DEFAULT_TYPE
@@ -305,6 +313,7 @@ class TelegramBot(BaseIMClient):
# Handle thread_id as reply_to_message_id in Telegram
kwargs = {"chat_id": chat_id, "text": text}
+ # Default to MarkdownV2 for Telegram if not specified
if parse_mode:
# Handle different parse modes:
# 'markdown' (from Slack) -> 'Markdown' (Telegram v1)
@@ -314,6 +323,9 @@ class TelegramBot(BaseIMClient):
kwargs["parse_mode"] = "Markdown"
else:
kwargs["parse_mode"] = parse_mode
+ else:
+ # Default to MarkdownV2 for all messages
+ kwargs["parse_mode"] = "MarkdownV2"
if reply_to or context.thread_id:
kwargs["reply_to_message_id"] = int(reply_to or context.thread_id)
@@ -335,6 +347,12 @@ class TelegramBot(BaseIMClient):
"""Send a message with inline buttons - BaseIMClient implementation"""
bot = self.application.bot
+ # Default to MarkdownV2 if not specified
+ if not parse_mode:
+ parse_mode = "MarkdownV2"
+ elif parse_mode == "markdown":
+ parse_mode = "Markdown"
+
# Convert our generic keyboard to Telegram keyboard
tg_keyboard = []
for row in keyboard.buttons: