mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-26 03:44:58 +08:00
feat:add new messagetyps WeChatFile and add wechat file is accepted and transmitted in base64 format. (#1531)
This commit is contained in:
@@ -235,6 +235,7 @@ class WeChatPadMessageConverter(adapter.MessageConverter):
|
|||||||
'57': self._handler_compound_quote,
|
'57': self._handler_compound_quote,
|
||||||
'5': self._handler_compound_link,
|
'5': self._handler_compound_link,
|
||||||
'6': self._handler_compound_file,
|
'6': self._handler_compound_file,
|
||||||
|
'74': self._handler_compound_file,
|
||||||
'33': self._handler_compound_mini_program,
|
'33': self._handler_compound_mini_program,
|
||||||
'36': self._handler_compound_mini_program,
|
'36': self._handler_compound_mini_program,
|
||||||
'2000': partial(self._handler_compound_unsupported, text="[转账消息]"),
|
'2000': partial(self._handler_compound_unsupported, text="[转账消息]"),
|
||||||
@@ -320,10 +321,41 @@ class WeChatPadMessageConverter(adapter.MessageConverter):
|
|||||||
xml_data: ET.Element
|
xml_data: ET.Element
|
||||||
) -> platform_message.MessageChain:
|
) -> platform_message.MessageChain:
|
||||||
"""处理文件消息 (data_type=6)"""
|
"""处理文件消息 (data_type=6)"""
|
||||||
xml_data_str = ET.tostring(xml_data, encoding='unicode')
|
file_data = xml_data.find('.//appmsg')
|
||||||
return platform_message.MessageChain([
|
|
||||||
platform_message.WeChatForwardFile(xml_data=xml_data_str)
|
if file_data.findtext('.//type', "") == "74":
|
||||||
])
|
return None
|
||||||
|
|
||||||
|
else:
|
||||||
|
xml_data_str = ET.tostring(xml_data, encoding='unicode')
|
||||||
|
# print(xml_data_str)
|
||||||
|
|
||||||
|
# 提取img标签的属性
|
||||||
|
# print(xml_data)
|
||||||
|
file_name = file_data.find('title').text
|
||||||
|
file_id = file_data.find('md5').text
|
||||||
|
# file_szie = file_data.find('totallen')
|
||||||
|
|
||||||
|
# print(file_data)
|
||||||
|
if file_data is not None:
|
||||||
|
aeskey = xml_data.findtext('.//appattach/aeskey')
|
||||||
|
cdnthumburl = xml_data.findtext('.//appattach/cdnattachurl')
|
||||||
|
# cdnmidimgurl = img_tag.get('cdnmidimgurl')
|
||||||
|
|
||||||
|
# print(aeskey,cdnthumburl)
|
||||||
|
|
||||||
|
file_data = self.bot.cdn_download(aeskey=aeskey, file_type=5, file_url=cdnthumburl)
|
||||||
|
|
||||||
|
file_base64 = file_data["Data"]['FileData']
|
||||||
|
# print(file_data)
|
||||||
|
file_size = file_data["Data"]['TotalSize']
|
||||||
|
|
||||||
|
# print(file_base64)
|
||||||
|
return platform_message.MessageChain([
|
||||||
|
platform_message.WeChatFile(file_id=file_id, file_name=file_name, file_size=file_size,
|
||||||
|
file_base64=file_base64),
|
||||||
|
platform_message.WeChatForwardFile(xml_data=xml_data_str)
|
||||||
|
])
|
||||||
|
|
||||||
async def _handler_compound_link(
|
async def _handler_compound_link(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -922,3 +922,22 @@ class WeChatForwardQuote(MessageComponent):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.app_msg
|
return self.app_msg
|
||||||
|
|
||||||
|
|
||||||
|
class WeChatFile(MessageComponent):
|
||||||
|
"""文件。"""
|
||||||
|
|
||||||
|
type: str = 'File'
|
||||||
|
"""消息组件类型。"""
|
||||||
|
file_id: str = ''
|
||||||
|
"""文件识别 ID。"""
|
||||||
|
file_name: str = ''
|
||||||
|
"""文件名称。"""
|
||||||
|
file_size: int = ''
|
||||||
|
"""文件大小。"""
|
||||||
|
file_path: str = ''
|
||||||
|
"""文件地址"""
|
||||||
|
file_base64: str = ''
|
||||||
|
"""base64"""
|
||||||
|
def __str__(self):
|
||||||
|
return f'[文件]{self.file_name}'
|
||||||
Reference in New Issue
Block a user