feat: 飞书消息记录完善 记录发送者ID、姓名、群信息

- FeishuService 新增 get_user_info() 根据 user_id 获取飞书用户姓名
- feishu_bot.py 处理消息时获取发送者姓名,日志格式改为:发送者=姓名(ID), 群=chat_id, 类型=群聊/私聊, 租户=xxx
- feishu_longconn_service.py 同样获取发送者姓名并记录
- Conversation.ip_address 存储 feishu:user_id:sender_name(扩大字段到200字符)
- Conversation.invocation_method 存储 feishu_bot(group) / feishu_longconn(p2p) 等详细来源
- ChatSession.source 同步记录详细来源信息
This commit is contained in:
2026-04-02 15:40:26 +08:00
parent 88a79d1936
commit c07cbf47c8
5 changed files with 71 additions and 23 deletions

View File

@@ -73,19 +73,25 @@ class FeishuLongConnService:
# 获取发送者ID和群信息
sender_id = sender.sender_id.user_id
sender_open_id = getattr(sender.sender_id, 'open_id', '')
try:
tenant_key = sender.sender_id.tenant_key
except:
tenant_key = "unknown"
# 获取发送者姓名
sender_name = sender_id
try:
from src.integrations.feishu_service import FeishuService
fs = FeishuService()
user_info = fs.get_user_info(sender_id)
sender_name = user_info.get('name') or user_info.get('en_name') or sender_id
except Exception as e:
logger.warning(f"获取发送者信息失败: {e}")
# 详细日志记录
logger.info(f"📋 消息详情 [长连接]:")
logger.info(f" - 消息ID: {message_id}")
logger.info(f" - 会话类型: {'群聊(group)' if chat_type == 'group' else '私聊(p2p)' if chat_type == 'p2p' else chat_type}")
logger.info(f" - 会话ID: {chat_id}")
logger.info(f" - 发送者ID: {sender_id}")
logger.info(f" - 租户Key: {tenant_key}")
logger.info(f" - 消息类型: {message_type}")
chat_type_desc = '群聊(group)' if chat_type == 'group' else '私聊(p2p)' if chat_type == 'p2p' else chat_type
logger.info(f"📨 [长连接] 发送者={sender_name}({sender_id}), 群={chat_id}, 类型={chat_type_desc}, 消息ID={message_id}")
# 消息去重检查
if cache_manager.check_and_set_message_processed(message_id):
@@ -163,15 +169,14 @@ class FeishuLongConnService:
work_order_id=None,
tenant_id=tenant_id
)
logger.info(f"🆕 创建新会话: {session_id} (租户: {tenant_id})")
logger.info(f"🆕 创建新会话: {session_id}, 用户={sender_name}({sender_id}), 租户={tenant_id}")
# 调用实时对话接口处理消息
logger.info(f"🤖 调用 TSP Assistant 处理消息...")
response_data = chat_manager.process_message(
session_id=session_id,
user_message=text_content,
ip_address=f"Feishu:{sender_id}",
invocation_method=f"Feishu({chat_type})"
ip_address=f"feishu:{sender_id}:{sender_name}",
invocation_method=f"feishu_longconn({chat_type})"
)
logger.info(f"📊 处理结果: {response_data.get('success')}")