实现抖音转接客服

This commit is contained in:
jjz
2025-09-15 14:16:14 +08:00
parent bc632fff18
commit 8851643d80
3 changed files with 190 additions and 22 deletions

View File

@@ -117,23 +117,33 @@ class DouYinBackendService:
or self.current_store_id
or '')
msg_type = platform_message.get('msg_type', 'text')
content_for_backend = platform_message.get('content', '')
pin_image = platform_message.get('pin_image')
if not pin_image:
pin_image = ""
# 检查消息类型如果是特殊类型如staff_list保持原格式
message_type = platform_message.get('type', 'message')
if message_type == 'staff_list':
# 对于客服列表消息,直接转发原始格式
msg = platform_message.copy()
# 确保store_id正确
msg['store_id'] = store_id
else:
pass
# 构造标准消息格式
msg = {
'type': 'message',
'content': content_for_backend,
'pin_image': pin_image,
'msg_type': msg_type,
'sender': {'id': sender_id},
'store_id': store_id
}
# 对于普通消息,使用原有的格式转换逻辑
msg_type = platform_message.get('msg_type', 'text')
content_for_backend = platform_message.get('content', '')
pin_image = platform_message.get('pin_image')
if not pin_image:
pin_image = ""
else:
pass
# 构造标准消息格式
msg = {
'type': 'message',
'content': content_for_backend,
'pin_image': pin_image,
'msg_type': msg_type,
'sender': {'id': sender_id},
'store_id': store_id
}
backend.send_message(msg)
return None
@@ -302,7 +312,9 @@ class DouYinMessageHandler:
# 发送到后端
await self.ai_service.send_message_to_backend(message_template.to_dict())
self._log(f"发送客服列表消息的结构体为: {message_template.to_json()}")
self._log(f"✅ 成功发送客服列表到后端,共 {len(staff_infos)} 个客服", "SUCCESS")
self._log(f" [DY] 成功发送客服列表到后端,共 {len(staff_infos)} 个客服", "SUCCESS")
print(f"🔥 [DY] 客服列表已上传到后端: {len(staff_infos)} 个客服")
print(f"[DY] 客服详情: {[{'id': s['staff_id'], 'name': s['name']} for s in staff_infos]}")
return True
except Exception as e:
@@ -1823,6 +1835,17 @@ class DouYinListenerForGUI:
if not message_handler_success:
self._log("❌ 消息处理器启动失败", "ERROR")
return False
# 发送客服列表到后端
try:
staff_list_success = await self.douyin_bot.message_handler.send_staff_list_to_backend()
if staff_list_success:
print(f"🔥 [DY] 客服列表已上传到后端")
else:
print(f"⚠️ [DY] 客服列表上传失败")
except Exception as e:
print(f"❌ [DY] 客服列表上传异常: {e}")
self._log(f"❌ 抖音客服列表上传异常: {e}", "ERROR")
# 注册到全局管理器
dy_manager = DouYinWebsocketManager()

View File

@@ -574,7 +574,8 @@ class ChatPdd:
# 通过后端服务发送
await self.backend_service.send_message_to_backend(message_template.to_dict())
self._log(f"发送客服列表消息的结构体为: {message_template.to_json()}")
self._log(f"✅ 成功发送客服列表到后端,共 {len(self.customer_list)} 个客服", "SUCCESS")
self._log(f" [PDD] 成功发送客服列表到后端,共 {len(self.customer_list)} 个客服", "SUCCESS")
print(f"🔥 [PDD] 客服列表已上传到后端: {len(self.customer_list)} 个客服")
return True
except Exception as e: