mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 07:54:19 +00:00
Merge pull request #1218 from fdc310/master
新增了微信发送小程序、转发小程序,发送emoji表情以及发送链接
This commit is contained in:
@@ -47,6 +47,17 @@ class GewechatMessageConverter(adapter.MessageConverter):
|
|||||||
if not component.url:
|
if not component.url:
|
||||||
pass
|
pass
|
||||||
content_list.append({"type": "image", "image": component.url})
|
content_list.append({"type": "image", "image": component.url})
|
||||||
|
elif isinstance(component, platform_message.WeChatMiniPrograms):
|
||||||
|
content_list.append({"type": 'WeChatMiniPrograms', 'mini_app_id': component.mini_app_id, 'display_name': component.display_name,
|
||||||
|
'page_path': component.page_path, 'cover_img_url': component.image_url, 'title': component.title,
|
||||||
|
'user_name': component.user_name})
|
||||||
|
elif isinstance(component, platform_message.WeChatForwardMiniPrograms):
|
||||||
|
content_list.append({"type": 'WeChatForwardMiniPrograms', 'xml_data': component.xml_data, 'image_url': component.image_url})
|
||||||
|
elif isinstance(component, platform_message.WeChatEmoji):
|
||||||
|
content_list.append({'type': 'WeChatEmoji', 'emoji_md5': component.emoji_md5, 'emoji_size': component.emoji_size})
|
||||||
|
elif isinstance(component, platform_message.WeChatLink):
|
||||||
|
content_list.append({'type': 'WeChatLink', 'link_title': component.link_title, 'link_desc': component.link_desc,
|
||||||
|
'link_thumb_url': component.link_thumb_url, 'link_url': component.link_url})
|
||||||
|
|
||||||
|
|
||||||
elif isinstance(component, platform_message.Voice):
|
elif isinstance(component, platform_message.Voice):
|
||||||
@@ -364,6 +375,19 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter):
|
|||||||
elif msg['type'] == 'image':
|
elif msg['type'] == 'image':
|
||||||
|
|
||||||
self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"])
|
self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"])
|
||||||
|
elif msg['type'] == 'WeChatMiniPrograms':
|
||||||
|
self.bot.post_mini_app(app_id=self.config['app_id'], to_wxid=target_id, mini_app_id=msg['mini_app_id']
|
||||||
|
, display_name=msg['display_name'], page_path=msg['page_path']
|
||||||
|
, cover_img_url=msg['cover_img_url'], title=msg['title'], user_name=msg['user_name'])
|
||||||
|
elif msg['type'] == 'WeChatForwardMiniPrograms':
|
||||||
|
self.bot.forward_mini_app(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data'], cover_img_url=msg['image_url'])
|
||||||
|
elif msg['type'] == 'WeChatEmoji':
|
||||||
|
self.bot.post_emoji(app_id=self.config['app_id'], to_wxid=target_id,
|
||||||
|
emoji_md5=msg['emoji_md5'], emoji_size=msg['emoji_size'])
|
||||||
|
elif msg['type'] == 'WeChatLink':
|
||||||
|
self.bot.post_link(app_id=self.config['app_id'], to_wxid=target_id
|
||||||
|
,title=msg['link_title'], desc=msg['link_desc']
|
||||||
|
, link_url=msg['link_url'], thumb_url=msg['link_thumb_url'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -376,6 +400,7 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter):
|
|||||||
content_list = await self.message_converter.yiri2target(message)
|
content_list = await self.message_converter.yiri2target(message)
|
||||||
|
|
||||||
ats = [item["target"] for item in content_list if item["type"] == "at"]
|
ats = [item["target"] for item in content_list if item["type"] == "at"]
|
||||||
|
target_id = message_source.source_platform_object["Data"]["FromUserName"]["string"]
|
||||||
|
|
||||||
for msg in content_list:
|
for msg in content_list:
|
||||||
if msg["type"] == "text":
|
if msg["type"] == "text":
|
||||||
@@ -396,6 +421,22 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter):
|
|||||||
content=msg["content"],
|
content=msg["content"],
|
||||||
ats=",".join(ats)
|
ats=",".join(ats)
|
||||||
)
|
)
|
||||||
|
elif msg['type'] == 'image':
|
||||||
|
|
||||||
|
self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"])
|
||||||
|
elif msg['type'] == 'WeChatMiniPrograms':
|
||||||
|
self.bot.post_mini_app(app_id=self.config['app_id'], to_wxid=target_id, mini_app_id=msg['mini_app_id']
|
||||||
|
, display_name=msg['display_name'], page_path=msg['page_path']
|
||||||
|
, cover_img_url=msg['cover_img_url'], title=msg['title'], user_name=msg['user_name'])
|
||||||
|
elif msg['type'] == 'WeChatForwardMiniPrograms':
|
||||||
|
self.bot.forward_mini_app(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data'], cover_img_url=msg['image_url'])
|
||||||
|
elif msg['type'] == 'WeChatEmoji':
|
||||||
|
self.bot.post_emoji(app_id=self.config['app_id'], to_wxid=target_id,
|
||||||
|
emoji_md5=msg['emoji_md5'], emoji_size=msg['emoji_size'])
|
||||||
|
elif msg['type'] == 'WeChatLink':
|
||||||
|
self.bot.post_link(app_id=self.config['app_id'], to_wxid=target_id
|
||||||
|
, title=msg['link_title'], desc=msg['link_desc']
|
||||||
|
, link_url=msg['link_url'], thumb_url=msg['link_thumb_url'])
|
||||||
|
|
||||||
async def is_muted(self, group_id: int) -> bool:
|
async def is_muted(self, group_id: int) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -807,6 +807,56 @@ class File(MessageComponent):
|
|||||||
"""文件名称。"""
|
"""文件名称。"""
|
||||||
size: int
|
size: int
|
||||||
"""文件大小。"""
|
"""文件大小。"""
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'[文件]{self.name}'
|
return f'[文件]{self.name}'
|
||||||
|
|
||||||
|
# ================ 个人微信专用组件 ================
|
||||||
|
|
||||||
|
class WeChatMiniPrograms(MessageComponent):
|
||||||
|
"""小程序。个人微信专用组件。"""
|
||||||
|
type: str = 'WeChatMiniPrograms'
|
||||||
|
"""小程序id"""
|
||||||
|
mini_app_id: str
|
||||||
|
"""小程序归属用户id"""
|
||||||
|
user_name: str
|
||||||
|
"""小程序名称"""
|
||||||
|
display_name: typing.Optional[str] = ''
|
||||||
|
"""打开地址"""
|
||||||
|
page_path: typing.Optional[str] = ''
|
||||||
|
"""小程序标题"""
|
||||||
|
title: typing.Optional[str] = ''
|
||||||
|
"""首页图片"""
|
||||||
|
image_url: typing.Optional[str] = ''
|
||||||
|
|
||||||
|
|
||||||
|
class WeChatForwardMiniPrograms(MessageComponent):
|
||||||
|
"""转发小程序。个人微信专用组件。"""
|
||||||
|
type: str = 'WeChatForwardMiniPrograms'
|
||||||
|
"""xml数据"""
|
||||||
|
xml_data: str
|
||||||
|
"""首页图片"""
|
||||||
|
image_url: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class WeChatEmoji(MessageComponent):
|
||||||
|
"""emoji表情。个人微信专用组件。"""
|
||||||
|
type: str = 'WeChatEmoji'
|
||||||
|
"""emojimd5"""
|
||||||
|
emoji_md5: str
|
||||||
|
"""emoji大小"""
|
||||||
|
emoji_size: int
|
||||||
|
|
||||||
|
|
||||||
|
class WeChatLink(MessageComponent):
|
||||||
|
"""发送链接。个人微信专用组件。"""
|
||||||
|
type: str = 'WeChatLink'
|
||||||
|
"""标题"""
|
||||||
|
link_title: str = ''
|
||||||
|
"""链接描述"""
|
||||||
|
link_desc: str = ''
|
||||||
|
"""链接地址"""
|
||||||
|
link_url: str = ''
|
||||||
|
"""链接略缩图"""
|
||||||
|
link_thumb_url: str = ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user