mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-10 15:56:03 +00:00
* Expanded WeCom message parsing to capture msgtype, inline voice/video/file/link data, bounded base64 downloads, and richer mixed-message attachments (src/langbot/libs/wecom_ai_bot_api/api.py); added event accessors for new fields (src/langbot/libs/wecom_ai_bot_api/wecombotevent.py). Converter now maps richer WeCom payloads (text, images, files, voice, video, links) into platform message chain with fallbacks when nothing parsable is present (src/langbot/pkg/platform/sources/wecombot.py). Preprocessor now turns voice inputs into file URLs for downstream runners (src/langbot/pkg/pipeline/preproc/preproc.py). Dify runner uploads all incoming files (images/audio/video/docs) after downloading or decoding data URLs, infers MIME types, and passes typed file descriptors into chat/workflow calls (src/langbot/pkg/provider/runners/difysvapi.py). * Update src/langbot/pkg/platform/sources/wecombot.py Fixed the issue of duplicate text in the comments. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/langbot/libs/wecom_ai_bot_api/api.py Modify the way you approach challenges. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/langbot/pkg/platform/sources/wecombot.py Changing the variable names makes more sense. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat: use from_base64 for the voice file converting --------- Co-authored-by: tabriswang <tabriswang@finecomn.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
131 lines
2.5 KiB
Python
131 lines
2.5 KiB
Python
from typing import Dict, Any, Optional
|
||
|
||
|
||
class WecomBotEvent(dict):
|
||
@staticmethod
|
||
def from_payload(payload: Dict[str, Any]) -> Optional['WecomBotEvent']:
|
||
try:
|
||
event = WecomBotEvent(payload)
|
||
return event
|
||
except KeyError:
|
||
return None
|
||
|
||
@property
|
||
def type(self) -> str:
|
||
"""
|
||
事件类型
|
||
"""
|
||
return self.get('type', '')
|
||
|
||
@property
|
||
def msgtype(self) -> str:
|
||
"""
|
||
消息 msgtype
|
||
"""
|
||
return self.get('msgtype', '')
|
||
|
||
@property
|
||
def userid(self) -> str:
|
||
"""
|
||
用户id
|
||
"""
|
||
return self.get('from', {}).get('userid', '') or self.get('userid', '')
|
||
|
||
@property
|
||
def username(self) -> str:
|
||
"""
|
||
用户名称
|
||
"""
|
||
return self.get('username', '') or self.get('from', {}).get('alias', '') or self.get('from', {}).get('name', '') or self.userid
|
||
|
||
@property
|
||
def chatname(self) -> str:
|
||
"""
|
||
群组名称
|
||
"""
|
||
return self.get('chatname', '') or str(self.chatid)
|
||
|
||
@property
|
||
def content(self) -> str:
|
||
"""
|
||
内容
|
||
"""
|
||
return self.get('content', '')
|
||
|
||
@property
|
||
def picurl(self) -> str:
|
||
"""
|
||
图片url
|
||
"""
|
||
return self.get('picurl', '')
|
||
|
||
@property
|
||
def images(self):
|
||
"""
|
||
图片列表(兼容 mixed)
|
||
"""
|
||
return self.get('images', [])
|
||
|
||
@property
|
||
def file(self):
|
||
"""
|
||
文件信息
|
||
"""
|
||
return self.get('file', {})
|
||
|
||
@property
|
||
def voice(self):
|
||
"""
|
||
语音信息
|
||
"""
|
||
return self.get('voice', {})
|
||
|
||
@property
|
||
def video(self):
|
||
"""
|
||
视频信息
|
||
"""
|
||
return self.get('video', {})
|
||
|
||
@property
|
||
def link(self):
|
||
"""
|
||
链接消息信息
|
||
"""
|
||
return self.get('link', {})
|
||
|
||
@property
|
||
def location(self):
|
||
"""
|
||
位置信息
|
||
"""
|
||
return self.get('location', {})
|
||
|
||
@property
|
||
def attachments(self):
|
||
"""
|
||
原始 mixed 中的附件项
|
||
"""
|
||
return self.get('attachments', [])
|
||
|
||
@property
|
||
def chatid(self) -> str:
|
||
"""
|
||
群组id
|
||
"""
|
||
return self.get('chatid', {})
|
||
|
||
@property
|
||
def message_id(self) -> str:
|
||
"""
|
||
消息id
|
||
"""
|
||
return self.get('msgid', '')
|
||
|
||
@property
|
||
def ai_bot_id(self) -> str:
|
||
"""
|
||
AI Bot ID
|
||
"""
|
||
return self.get('aibotid', '')
|