diff --git a/astrbot/core/platform/sources/dingtalk/dingtalk_event.py b/astrbot/core/platform/sources/dingtalk/dingtalk_event.py index d520189d8..197701e0d 100644 --- a/astrbot/core/platform/sources/dingtalk/dingtalk_event.py +++ b/astrbot/core/platform/sources/dingtalk/dingtalk_event.py @@ -25,6 +25,20 @@ async def send_with_client( client: dingtalk_stream.ChatbotHandler, message: MessageChain, ): + icm = cast(dingtalk_stream.ChatbotMessage, self.message_obj.raw_message) + ats = [] + # fixes: #4218 + # 钉钉 at 机器人需要使用 sender_staff_id 而不是 sender_id + for i in message.chain: + if isinstance(i, Comp.At): + print(i.qq, icm.sender_id, icm.sender_staff_id) + if str(i.qq) in str(icm.sender_id or ""): + # 适配器会将开头的 $:LWCP_v1:$ 去掉,因此我们用 in 判断 + ats.append(f"@{icm.sender_staff_id}") + else: + ats.append(f"@{i.qq}") + at_str = " ".join(ats) + for segment in message.chain: if isinstance(segment, Comp.Plain): segment.text = segment.text.strip() @@ -32,7 +46,7 @@ async def send_with_client( None, client.reply_markdown, segment.text, - segment.text, + f"{at_str} {segment.text}".strip(), cast(dingtalk_stream.ChatbotMessage, self.message_obj.raw_message), ) elif isinstance(segment, Comp.Image):