转人工服务,相关配置
1.展示人工-进入人工-退出人工
{
name: '展示人工服务',
type: 'cmd',
cmd: { code: 'agent_entrance_display' },
},
{
name: '直接进入人工服务',
type: 'cmd',
cmd: { code: 'agent_join' }
},
{
name: '退出人工服务',
type: 'cmd',
cmd: { code: 'agent_leave' },
},
官网给的例子字段错误,应该是cmd字段,不应该是comment字段
2.转人工后发送消息
makeSocket({ ctx }) { //连接人工客服
// 连接 ws
const ws = new WebSocket('ws://10.180.0.64:8000//ws');
ctx.appendMessage({
type: 'system',
content: {
text: '已进入人工客服',
},
});
// ws 的事件配置
ws.onmessage = (e) => {
// ctx.appendMessage({
// type: 'text',
// content: {
// text: '滑到底部',
// },
// });
setTimeout(() => { //滑到底部
ctx.ui.scrollToEnd()
}, 3000);
return;
};
ws.onmessage(); //这里假装执行
ws.onopen = (e) => {
};
ws.onclose = (e) => { //当退出时能够监听到
ctx.appendMessage({
type: 'system',
content: {
text: '人工客服已退出服务',
},
});
};
return {
// 发送接口,用户发送信息时触发
send(msg) {
// ws.send('发给后端的数据');
},
// 结束接口,退出服务时触发
close() {
ws.close();
},
};
}
这里使用了WebSocket,还没有连接后端尝试,官网有详细的案例