连接中...
企微
飞书
微信

消息处理

全部
转快递
转人工
Bot

输入消息开始处理

系统自动识别运单号、路由到对应群

运单查询
活跃会话
统计
// 会话管理 function loadSessions() { fetch('/api/sessions') .then(r => r.json()) .then(data => { sessions = data.sessions || []; renderSessionList(); }); } function renderSessionList() { const list = document.getElementById('session-list'); const filter = document.querySelector('.filter-btn.active').dataset.filter; const filtered = filter === 'all' ? sessions : sessions.filter(s => s.status === filter); list.innerHTML = filtered.map(s => `
${s.title}
${s.platform} ${s.time} ${getStatusText(s.status)}
`).join(''); } function getStatusText(status) { const map = { bot: '🤖 Bot处理', courier: '📦 转快递', manual: '👤 转人工' }; return map[status] || status; } function selectSession(id) { currentSession = sessions.find(s => s.id === id); renderSessionList(); renderChat(); loadWaybillInfo(); } // 聊天渲染 function renderChat() { const container = document.getElementById('chat-messages'); if (!currentSession) { container.innerHTML = '
请选择会话
'; return; } container.innerHTML = currentSession.messages.map(m => `
${m.content}
${m.time}
`).join(''); container.scrollTop = container.scrollHeight; } // 运单查询 function loadWaybillInfo() { if (!currentSession?.waybill) return; document.getElementById('waybill-info').innerHTML = `
运单号${currentSession.waybill}
快递公司${currentSession.courier}
状态运输中
`; } function queryWMS() { if (!currentSession?.waybill) return; fetch(`/api/waybill/${currentSession.waybill}`) .then(r => r.json()) .then(data => { document.getElementById('waybill-info').innerHTML += `
WMS信息
货主: ${data.consignerName || '-'}
仓库: ${data.warehouseName || '-'}
订单: ${data.saleOrderCode || '-'}
`; }); } // 发送消息 function sendMessage() { const input = document.getElementById('msg-input'); const content = input.value.trim(); if (!content || !currentSession) return; fetch('/api/message', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({sessionId: currentSession.id, content}) }).then(() => { input.value = ''; loadSessions(); }); } function handleKey(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); } } // 快捷回复 function quickReply(type) { const replies = { query: '已为您查询运单,最新物流信息:', urge: '已催促快递公司优先处理,请耐心等待', register: '已登记发网WMS系统,处理中', contact: '快递小哥电话:' }; document.getElementById('msg-input').value = replies[type] || ''; } // 方向切换 function switchDirection(dir) { document.querySelectorAll('.dir-btn').forEach(b => b.classList.remove('active')); document.querySelector(`[onclick="switchDirection('${dir}')"]`).classList.add('active'); messageDirection = dir; } // 页面切换 function showPage(page) { document.querySelectorAll('.page').forEach(p => p.classList.remove('active')); document.getElementById(`page-${page}`).classList.add('active'); document.querySelectorAll('.sib-item').forEach(i => i.classList.remove('active')); document.querySelector(`.sib-item[onclick="showPage('${page}')"]`).classList.add('active'); if (page === 'dashboard') loadDashboard(); if (page === 'groups') loadGroups(); if (page === 'rules') loadRules(); } // 仪表盘 function loadDashboard() { fetch('/api/stats') .then(r => r.json()) .then(data => { document.getElementById('dashboard-content').innerHTML = `
${data.today}
今日会话
${data.pending}
待处理
${data.courier}
转快递
${data.manual}
转人工
`; }); } // 群组管理 function loadGroups() { const list = document.getElementById('group-list'); list.innerHTML = groups.map(g => `
${g.name}
${g.direction} · ${g.platform}
`).join(''); } function testWebhook(groupId) { fetch(`/api/webhook/test/${groupId}`, {method: 'POST'}) .then(() => showToast('测试消息已发送')); } // 规则配置 function loadRules() { fetch('/api/config') .then(r => r.json()) .then(cfg => { document.getElementById('rules-content').innerHTML = `

异常分类路由

${Object.entries(cfg.exception_rules || {}).map(([k,v]) => `
${k} → ${v.target}
`).join('')}
`; }); } // Toast提示 function showToast(msg) { const t = document.getElementById('toast'); t.textContent = msg; t.style.opacity = '1'; setTimeout(() => t.style.opacity = '0', 2000); } // WebSocket连接 function connectWebSocket() { const ws = new WebSocket(`ws://${location.host}/ws`); ws.onmessage = (e) => { const data = JSON.parse(e.data); if (data.type === 'new_message') { showToast('新消息: ' + data.preview); loadSessions(); } }; ws.onclose = () => setTimeout(connectWebSocket, 3000); } // 初始化 loadSessions(); loadGroups(); connectWebSocket();