mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-10 21:10:59 +00:00
fix: dingtalk & wecom problems (#1424)
This commit is contained in:
@@ -115,13 +115,20 @@ class DingTalkClient:
|
|||||||
if event:
|
if event:
|
||||||
await self._handle_message(event)
|
await self._handle_message(event)
|
||||||
|
|
||||||
async def send_message(self, content: str, incoming_message):
|
async def send_message(self, content: str, incoming_message,at:bool):
|
||||||
if self.markdown_card:
|
if self.markdown_card:
|
||||||
self.EchoTextHandler.reply_markdown(
|
if at:
|
||||||
title=self.robot_name + '的回答',
|
self.EchoTextHandler.reply_markdown(
|
||||||
text=content,
|
title='@'+incoming_message.sender_nick+' '+content,
|
||||||
incoming_message=incoming_message,
|
text='@'+incoming_message.sender_nick+' '+content,
|
||||||
)
|
incoming_message=incoming_message,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.EchoTextHandler.reply_markdown(
|
||||||
|
title=content,
|
||||||
|
text=content,
|
||||||
|
incoming_message=incoming_message,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.EchoTextHandler.reply_text(content, incoming_message)
|
self.EchoTextHandler.reply_text(content, incoming_message)
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class WecomClient:
|
|||||||
self.access_token = ''
|
self.access_token = ''
|
||||||
self.secret_for_contacts = contacts_secret
|
self.secret_for_contacts = contacts_secret
|
||||||
self.app = Quart(__name__)
|
self.app = Quart(__name__)
|
||||||
self.wxcpt = WXBizMsgCrypt(self.token, self.aes, self.corpid)
|
|
||||||
self.app.add_url_rule(
|
self.app.add_url_rule(
|
||||||
'/callback/command',
|
'/callback/command',
|
||||||
'handle_callback',
|
'handle_callback',
|
||||||
@@ -171,16 +170,17 @@ class WecomClient:
|
|||||||
timestamp = request.args.get('timestamp')
|
timestamp = request.args.get('timestamp')
|
||||||
nonce = request.args.get('nonce')
|
nonce = request.args.get('nonce')
|
||||||
|
|
||||||
|
wxcpt = WXBizMsgCrypt(self.token, self.aes, self.corpid)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
echostr = request.args.get('echostr')
|
echostr = request.args.get('echostr')
|
||||||
ret, reply_echo_str = self.wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
|
ret, reply_echo_str = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
raise Exception(f'验证失败,错误码: {ret}')
|
raise Exception(f'验证失败,错误码: {ret}')
|
||||||
return reply_echo_str
|
return reply_echo_str
|
||||||
|
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
encrypt_msg = await request.data
|
encrypt_msg = await request.data
|
||||||
ret, xml_msg = self.wxcpt.DecryptMsg(encrypt_msg, msg_signature, timestamp, nonce)
|
ret, xml_msg = wxcpt.DecryptMsg(encrypt_msg, msg_signature, timestamp, nonce)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
raise Exception(f'消息解密失败,错误码: {ret}')
|
raise Exception(f'消息解密失败,错误码: {ret}')
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,14 @@ import datetime
|
|||||||
class DingTalkMessageConverter(adapter.MessageConverter):
|
class DingTalkMessageConverter(adapter.MessageConverter):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def yiri2target(message_chain: platform_message.MessageChain):
|
async def yiri2target(message_chain: platform_message.MessageChain):
|
||||||
|
content = ''
|
||||||
|
at = False
|
||||||
for msg in message_chain:
|
for msg in message_chain:
|
||||||
|
if type(msg) is platform_message.At:
|
||||||
|
at = True
|
||||||
if type(msg) is platform_message.Plain:
|
if type(msg) is platform_message.Plain:
|
||||||
return msg.text
|
content += msg.text
|
||||||
|
return content,at
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def target2yiri(event: DingTalkEvent, bot_name: str):
|
async def target2yiri(event: DingTalkEvent, bot_name: str):
|
||||||
@@ -128,8 +133,8 @@ class DingTalkAdapter(adapter.MessagePlatformAdapter):
|
|||||||
)
|
)
|
||||||
incoming_message = event.incoming_message
|
incoming_message = event.incoming_message
|
||||||
|
|
||||||
content = await DingTalkMessageConverter.yiri2target(message)
|
content,at = await DingTalkMessageConverter.yiri2target(message)
|
||||||
await self.bot.send_message(content, incoming_message)
|
await self.bot.send_message(content, incoming_message,at)
|
||||||
|
|
||||||
async def send_message(self, target_type: str, target_id: str, message: platform_message.MessageChain):
|
async def send_message(self, target_type: str, target_id: str, message: platform_message.MessageChain):
|
||||||
content = await DingTalkMessageConverter.yiri2target(message)
|
content = await DingTalkMessageConverter.yiri2target(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user