From c36054ca1b1dbb7bc3e68d0bd5ae1b7335872a4e Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 5 May 2025 11:53:50 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=BE=AE=E4=BF=A1=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E6=94=AF=E6=8C=81=E6=96=87=E6=9C=AC=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/platform/sources/wecom/wecom_adapter.py | 15 ++++++++------- .../core/platform/sources/wecom/wecom_event.py | 10 +++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/astrbot/core/platform/sources/wecom/wecom_adapter.py b/astrbot/core/platform/sources/wecom/wecom_adapter.py index 784658807..234ba4e87 100644 --- a/astrbot/core/platform/sources/wecom/wecom_adapter.py +++ b/astrbot/core/platform/sources/wecom/wecom_adapter.py @@ -136,16 +136,17 @@ class WecomPlatformAdapter(Platform): self.config["corpid"].strip(), self.config["secret"].strip(), ) - # inject - self.wechat_kf_api = WeChatKF(client=self.client) - self.wechat_kf_message_api = WeChatKFMessage(self.client) - self.client.kf = self.wechat_kf_api - self.client.kf_message = self.wechat_kf_message_api - - self.client.API_BASE_URL = self.api_base_url # 微信客服 self.kf_name = self.config.get("kf_name", None) + if self.kf_name: + # inject + self.wechat_kf_api = WeChatKF(client=self.client) + self.wechat_kf_message_api = WeChatKFMessage(self.client) + self.client.kf = self.wechat_kf_api + self.client.kf_message = self.wechat_kf_message_api + + self.client.API_BASE_URL = self.api_base_url async def callback(msg: BaseMessage): if msg.type == "unknown" and msg._data["Event"] == "kf_msg_or_event": diff --git a/astrbot/core/platform/sources/wecom/wecom_event.py b/astrbot/core/platform/sources/wecom/wecom_event.py index 791e4ff75..01cec4230 100644 --- a/astrbot/core/platform/sources/wecom/wecom_event.py +++ b/astrbot/core/platform/sources/wecom/wecom_event.py @@ -84,26 +84,26 @@ class WecomPlatformEvent(AstrMessageEvent): async def send(self, message: MessageChain): message_obj = self.message_obj - is_wechat_kf = hasattr(self.message_obj.raw_message, "_wechat_kf_flag") + is_wechat_kf = hasattr(self.client, "kf_message") if is_wechat_kf: + # 微信客服 kf_message_api = getattr(self.client, "kf_message", None) if not kf_message_api: logger.warning("未找到微信客服发送消息方法。") return assert isinstance(kf_message_api, WeChatKFMessage) + user_id = self.get_sender_id() for comp in message.chain: if isinstance(comp, Plain): # Split long text messages if needed plain_chunks = await self.split_plain(comp.text) for chunk in plain_chunks: - # self.client.message.send_text( - # message_obj.self_id, message_obj.session_id, chunk - # ) - # kf_message_api.send_text() + kf_message_api.send_text(user_id, self.get_self_id(), chunk) await asyncio.sleep(0.5) # Avoid sending too fast else: logger.warning("没有实现的回复消息类型。") else: + # 企业微信应用 for comp in message.chain: if isinstance(comp, Plain): # Split long text messages if needed