mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-26 03:44:58 +08:00
feat: add support for sending active messages in wecom
This commit is contained in:
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user