feat: add support for sending active messages in wecom

This commit is contained in:
wangcham
2025-03-12 04:03:02 -04:00
parent 3c961e4652
commit 6a866bf871
2 changed files with 15 additions and 3 deletions

View File

@@ -66,7 +66,7 @@ class WecomClient():
else:
raise Exception("未获取用户")
async def send_to_all(self,content:str):
async def send_to_all(self,content:str,agent_id:int):
if not self.check_access_token_for_contacts():
self.access_token_for_contacts = await self.get_access_token(self.secret_for_contacts)
@@ -77,7 +77,7 @@ class WecomClient():
params = {
"touser" : user_ids_string,
"msgtype" : "text",
"agentid" : 1000002,
"agentid" : agent_id,
"text" : {
"content" : content,
},

View File

@@ -197,7 +197,19 @@ class WecomAdapter(adapter.MessagePlatformAdapter):
async def send_message(
self, target_type: str, target_id: str, message: platform_message.MessageChain
):
pass
"""企业微信目前只有发送给个人的方法,
构造target_id的方式为前半部分为账户id后半部分为agent_id,中间使用“|”符号隔开。
"""
content_list = await WecomMessageConverter.yiri2target(message, self.bot)
parts = target_id.split("|")
user_id = parts[0]
agent_id = int(parts[1])
if target_type == 'person':
for content in content_list:
if content["type"] == "text":
await self.bot.send_private_msg(user_id,agent_id,content["content"])
if content["type"] == "image":
await self.bot.send_image(user_id,agent_id,content["media"])
def register_listener(
self,