更新时间:2023-08-28 GMT+08:00
代码使用示例-用户转人工
参考Demo举例:
上述两种召唤人工的方式均可实现,采用相同的调用方式,可以参考MainContent.vue的transform方法。
//召唤人工 transform() { let transformData = { channel: 'WEB', controlType: "TRANS2AGENT", mediaType: "TEXT", content: 'hello', sourceType: "CUSTOMER", to: this.$Chat.getChannelId(), "from": this.$Chat.userId, senderNickname: this.$Chat.userName }; let that = this; let transSuccess = function (data) { if (data['resultCode'] === '0') { that.sendUserInfo(); } else { EventBus.$emit("toAgentFailed"); } } this.$Chat.send(transformData, transSuccess); },
Demo当前在send方法调用失败时,会发送toAgentFailed事件,该事件会触发用户留言的方法。成功时,会向客服座席发送用户在接入时填写的用户信息,可以参考用户接入中的信息;具体方法如下:
//向座席发送用户信息 sendUserInfo() { let storage = window.localStorage; let userInfo = storage.getItem("sc_chat_user"); if (userInfo) { let data = JSON.parse(userInfo); let message = ''; if (data.userPhone) { message += ('用户电话:' + data.userPhone + ","); } if (data.userEmail) { message += ('用户邮箱:' + data.userEmail); } if (message !== '') { let connectMessage = { channel: 'WEB', controlType: "CHAT", mediaType: "TEXT", content: message, sourceType: "CUSTOMER", to: this.$Chat.getChannelId(), "from": this.$Chat.userId, senderNickname: this.$Chat.userName }; this.$Chat.send(connectMessage); } } }