mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-12 13:50:59 +00:00
feat(wechatpad): 添加对@所有人的支持并统一处理消息派发 (#1588)
在消息转换器中添加对AtAll组件的支持,将@所有人转换为特定格式。同时在消息派发时统一处理@所有人的情况,确保通知能正确发送。
This commit is contained in:
@@ -40,8 +40,10 @@ class WeChatPadMessageConverter(adapter.MessageConverter):
|
|||||||
content_list = []
|
content_list = []
|
||||||
|
|
||||||
for component in message_chain:
|
for component in message_chain:
|
||||||
if isinstance(component, platform_message.At):
|
if isinstance(component, platform_message.AtAll):
|
||||||
content_list.append({'type': 'at', 'target': component.target})
|
content_list.append({"type": "at", "target": "all"})
|
||||||
|
elif isinstance(component, platform_message.At):
|
||||||
|
content_list.append({"type": "at", "target": component.target})
|
||||||
elif isinstance(component, platform_message.Plain):
|
elif isinstance(component, platform_message.Plain):
|
||||||
content_list.append({'type': 'text', 'content': component.text})
|
content_list.append({'type': 'text', 'content': component.text})
|
||||||
elif isinstance(component, platform_message.Image):
|
elif isinstance(component, platform_message.Image):
|
||||||
@@ -577,19 +579,26 @@ class WeChatPadAdapter(adapter.MessagePlatformAdapter):
|
|||||||
for msg in content_list:
|
for msg in content_list:
|
||||||
# 文本消息处理@
|
# 文本消息处理@
|
||||||
if msg['type'] == 'text' and at_targets:
|
if msg['type'] == 'text' and at_targets:
|
||||||
at_nick_name_list = []
|
if "all" in at_targets:
|
||||||
for member in member_info:
|
msg['content'] = f'@所有人 {msg["content"]}'
|
||||||
if member['user_name'] in at_targets:
|
else:
|
||||||
at_nick_name_list.append(f'@{member["nick_name"]}')
|
at_nick_name_list = []
|
||||||
msg['content'] = f'{" ".join(at_nick_name_list)} {msg["content"]}'
|
for member in member_info:
|
||||||
|
if member["user_name"] in at_targets:
|
||||||
|
at_nick_name_list.append(f'@{member["nick_name"]}')
|
||||||
|
msg['content'] = f'{" ".join(at_nick_name_list)} {msg["content"]}'
|
||||||
|
|
||||||
# 统一消息派发
|
# 统一消息派发
|
||||||
handler_map = {
|
handler_map = {
|
||||||
'text': lambda msg: self.bot.send_text_message(
|
'text': lambda msg: self.bot.send_text_message(
|
||||||
to_wxid=target_id, message=msg['content'], ats=at_targets
|
to_wxid=target_id,
|
||||||
|
message=msg['content'],
|
||||||
|
ats= ["notify@all"] if "all" in at_targets else at_targets
|
||||||
),
|
),
|
||||||
'image': lambda msg: self.bot.send_image_message(
|
'image': lambda msg: self.bot.send_image_message(
|
||||||
to_wxid=target_id, img_url=msg['image'], ats=at_targets
|
to_wxid=target_id,
|
||||||
|
img_url=msg["image"],
|
||||||
|
ats = ["notify@all"] if "all" in at_targets else at_targets
|
||||||
),
|
),
|
||||||
'WeChatEmoji': lambda msg: self.bot.send_emoji_message(
|
'WeChatEmoji': lambda msg: self.bot.send_emoji_message(
|
||||||
to_wxid=target_id, emoji_md5=msg['emoji_md5'], emoji_size=msg['emoji_size']
|
to_wxid=target_id, emoji_md5=msg['emoji_md5'], emoji_size=msg['emoji_size']
|
||||||
|
|||||||
Reference in New Issue
Block a user