mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-26 15:34:26 +00:00
6e37aae636
* feat(wecom): add user feedback support for WeChat Work AI Bot This commit implements user feedback functionality (like/dislike) for WeChat Work AI Bot conversations, including: Backend changes: - Add feedback_id and stream_id fields to WecomBotEvent - Implement feedback event handling in WecomBotClient (api.py) - Add StreamSessionManager._feedback_index for feedback_id lookup - Add on_feedback decorator for custom feedback handlers - Create MonitoringFeedback entity for database persistence - Add dbm025 migration for monitoring_feedback table - Implement FeedbackMonitor helper class - Update all platform adapters with ap parameter support - Update botmgr to pass bot_info for monitoring context Frontend changes: - Add FeedbackCard and FeedbackList components - Add useFeedbackData hook for feedback data fetching - Add feedback tab to monitoring page - Add feedback types and interfaces - Add i18n translations (zh-Hans, en-US) Other changes: - Update Dockerfile with Chinese mirror for faster builds - Update docker-compose.yaml with network configuration - Update .gitignore for docker data and backup files Note: Known issues that need future improvement: - feedback_type=3 (cancel) is recorded but not properly handled - Duplicate feedback records are not deduplicated * chore: remove unnecessary migration for new table will be created automatically * chore: ruff format * chore: prettier * feat: add feedback handling support across multiple platform adapters * fix(web): remove unused imports and variables in monitoring module --------- Co-authored-by: 6mvp6 <13727783693@163.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
150 lines
2.9 KiB
Python
150 lines
2.9 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', '')
|
|
|
|
@property
|
|
def feedback_id(self) -> str:
|
|
"""
|
|
反馈 ID,用于关联用户点赞/点踩反馈
|
|
"""
|
|
return self.get('feedback_id', '')
|
|
|
|
@property
|
|
def stream_id(self) -> str:
|
|
"""
|
|
流式消息 ID
|
|
"""
|
|
return self.get('stream_id', '')
|