diff --git a/app/agent/tools/base.py b/app/agent/tools/base.py index d9c80c84..44248539 100644 --- a/app/agent/tools/base.py +++ b/app/agent/tools/base.py @@ -68,5 +68,6 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta): username=self._username, title=title, text=message - ) + ), + escape_markdown=False ) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 58cbbdf6..2ee4f0e5 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -906,14 +906,14 @@ class ChainBase(metaclass=ABCMeta): # 按设定发送 self.eventmanager.send_event(etype=EventType.NoticeMessage, data={**send_message.model_dump(), "type": send_message.mtype}) - self.messagequeue.send_message("post_message", message=send_message) + self.messagequeue.send_message("post_message", message=send_message, **kwargs) if not send_orignal: return # 发送消息事件 self.eventmanager.send_event(etype=EventType.NoticeMessage, data={**message.model_dump(), "type": message.mtype}) # 按原消息发送 self.messagequeue.send_message("post_message", message=message, - immediately=True if message.userid else False) + immediately=True if message.userid else False, **kwargs) async def async_post_message(self, message: Optional[Notification] = None, @@ -989,7 +989,7 @@ class ChainBase(metaclass=ABCMeta): # 按设定发送 await self.eventmanager.async_send_event(etype=EventType.NoticeMessage, data={**send_message.model_dump(), "type": send_message.mtype}) - await self.messagequeue.async_send_message("post_message", message=send_message) + await self.messagequeue.async_send_message("post_message", message=send_message, **kwargs) if not send_orignal: return # 发送消息事件 @@ -997,7 +997,7 @@ class ChainBase(metaclass=ABCMeta): data={**message.model_dump(), "type": message.mtype}) # 按原消息发送 await self.messagequeue.async_send_message("post_message", message=message, - immediately=True if message.userid else False) + immediately=True if message.userid else False, **kwargs) def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> None: """ diff --git a/app/modules/slack/__init__.py b/app/modules/slack/__init__.py index 5517e66d..2dabfc8c 100644 --- a/app/modules/slack/__init__.py +++ b/app/modules/slack/__init__.py @@ -264,7 +264,7 @@ class SlackModule(_ModuleBase, _MessageBase[Slack]): userid=userid, username=username, text=text) return None - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息 diff --git a/app/modules/synologychat/__init__.py b/app/modules/synologychat/__init__.py index 47e138ee..104221eb 100644 --- a/app/modules/synologychat/__init__.py +++ b/app/modules/synologychat/__init__.py @@ -120,7 +120,7 @@ class SynologyChatModule(_ModuleBase, _MessageBase[SynologyChat]): logger.debug(f"解析SynologyChat消息失败:{str(err)}") return None - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息体 diff --git a/app/modules/telegram/__init__.py b/app/modules/telegram/__init__.py index ccef4668..11cde0cc 100644 --- a/app/modules/telegram/__init__.py +++ b/app/modules/telegram/__init__.py @@ -261,7 +261,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]): return cleaned - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息体 @@ -283,7 +283,8 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]): image=message.image, userid=userid, link=message.link, buttons=message.buttons, original_message_id=message.original_message_id, - original_chat_id=message.original_chat_id) + original_chat_id=message.original_chat_id, + escape_markdown=kwargs.get("escape_markdown")) def post_medias_message(self, message: Notification, medias: List[MediaInfo]) -> None: """ diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index d47c0290..fec0e9c7 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -32,7 +32,7 @@ class Telegram: _user_chat_mapping: Dict[str, str] = {} # userid -> chat_id mapping for reply targeting _bot_username: Optional[str] = None # Bot username for mention detection _escape_chars = r'_*[]()~`>#+-=|{}.!' # Telegram MarkdownV2 - _markdown_escape_pattern = re.compile(f'([{re.escape(_escape_chars)}])') #Telegram MarkdownV2 规则转义特殊字符正则pattern + _markdown_escape_pattern = re.compile(f'([{re.escape(_escape_chars)}])') # Telegram MarkdownV2 规则转义特殊字符正则pattern def __init__(self, TELEGRAM_TOKEN: Optional[str] = None, TELEGRAM_CHAT_ID: Optional[str] = None, **kwargs): """ 初始化参数 @@ -216,7 +216,8 @@ class Telegram: userid: Optional[str] = None, link: Optional[str] = None, buttons: Optional[List[List[dict]]] = None, original_message_id: Optional[int] = None, - original_chat_id: Optional[str] = None) -> Optional[bool]: + original_chat_id: Optional[str] = None, + escape_markdown: bool = True) -> Optional[bool]: """ 发送Telegram消息 :param title: 消息标题 @@ -227,7 +228,8 @@ class Telegram: :param buttons: 按钮列表,格式:[[{"text": "按钮文本", "callback_data": "回调数据"}]] :param original_message_id: 原消息ID,如果提供则编辑原消息 :param original_chat_id: 原消息的聊天ID,编辑消息时需要 - :userid: 发送消息的目标用户ID,为空则发给管理员 + :param escape_markdown: 是否对内容进行Markdown转义 + """ if not self._telegram_token or not self._telegram_chat_id: return None @@ -240,9 +242,12 @@ class Telegram: if title: title = self.escape_markdown(title) if text: - # 对text进行Markdown特殊字符转义 - text = self.escape_markdown(text) - caption = f"*{title}*\n{text}" + if escape_markdown: + text = self.escape_markdown(text) + if title: + caption = f"*{title}*\n{text}" + else: + caption = text else: caption = f"*{title}*" diff --git a/app/modules/vocechat/__init__.py b/app/modules/vocechat/__init__.py index c734b3c5..ff974515 100644 --- a/app/modules/vocechat/__init__.py +++ b/app/modules/vocechat/__init__.py @@ -139,7 +139,7 @@ class VoceChatModule(_ModuleBase, _MessageBase[VoceChat]): logger.error(f"VoceChat消息处理发生错误:{str(err)}") return None - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息内容 diff --git a/app/modules/webpush/__init__.py b/app/modules/webpush/__init__.py index 91965c8a..335a5506 100644 --- a/app/modules/webpush/__init__.py +++ b/app/modules/webpush/__init__.py @@ -71,7 +71,7 @@ class WebPushModule(_ModuleBase, _MessageBase): def init_setting(self) -> Tuple[str, Union[str, bool]]: pass - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息内容 diff --git a/app/modules/wechat/__init__.py b/app/modules/wechat/__init__.py index c4220e23..1d259353 100644 --- a/app/modules/wechat/__init__.py +++ b/app/modules/wechat/__init__.py @@ -184,7 +184,7 @@ class WechatModule(_ModuleBase, _MessageBase[WeChat]): logger.error(f"微信消息处理发生错误:{str(err)}") return None - def post_message(self, message: Notification) -> None: + def post_message(self, message: Notification, **kwargs) -> None: """ 发送消息 :param message: 消息内容