mirror of
https://gitee.com/270580156/weiyu.git
synced 2026-05-16 04:07:51 +00:00
1 line
39 KiB
JavaScript
1 line
39 KiB
JavaScript
"use strict"; var bd_kfe_httpapi = { requestUsername: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/visitor/api/username", contentType: "application/json; charset=utf-8", type: "get", data: { subDomain: bd_kfe_data.subDomain, client: bd_kfe_data.client }, success: function (e) { bd_kfe_data.uid = e.data.uid, bd_kfe_data.username = e.data.username, bd_kfe_data.password = e.data.username, bd_kfe_data.nickname = e.data.nickname, localStorage.bd_kfe_uid = bd_kfe_data.uid, localStorage.bd_kfe_username = bd_kfe_data.username, localStorage.bd_kfe_nickname = bd_kfe_data.nickname, bd_kfe_httpapi.login() }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, registerUser: function () { var e = bd_kfe_utils.getUrlParam("username"), t = null == bd_kfe_utils.getUrlParam("nickname") ? e : bd_kfe_utils.getUrlParam("nickname"), a = null === bd_kfe_utils.getUrlParam("avatar") ? "" : bd_kfe_utils.getUrlParam("avatar"), d = e; $.ajax({ url: bd_kfe_data.HTTP_HOST + "/visitor/api/register/user", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ username: e, nickname: t, password: d, avatar: a, subDomain: bd_kfe_data.subDomain, client: bd_kfe_data.client }), success: function (n) { bd_kfe_utils.printLog("registerUser success: " + JSON.stringify(n)), 200 === n.status_code ? (bd_kfe_data.uid = n.data.uid, bd_kfe_data.username = n.data.username, bd_kfe_data.password = d, bd_kfe_data.nickname = n.data.nickname, bd_kfe_data.avatar = n.data.avatar, localStorage.bd_kfe_uid = bd_kfe_data.uid, localStorage.bd_kfe_username = bd_kfe_data.username, localStorage.bd_kfe_nickname = bd_kfe_data.nickname) : (bd_kfe_data.uid = n.data, bd_kfe_data.username = e + "@" + bd_kfe_data.subDomain, bd_kfe_data.password = d, bd_kfe_data.nickname = t, bd_kfe_data.avatar = a, localStorage.bd_kfe_uid = bd_kfe_data.uid, localStorage.bd_kfe_username = bd_kfe_data.username, localStorage.bd_kfe_nickname = bd_kfe_data.nickname), bd_kfe_httpapi.login() }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, login: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/visitor/token", type: "post", data: { username: bd_kfe_data.username, password: bd_kfe_data.password, grant_type: "password", scope: "all" }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Basic Y2xpZW50OnNlY3JldA==") }, success: function (e) { bd_kfe_utils.printLog("login success: " + JSON.stringify(e)), bd_kfe_data.passport.token = e, localStorage.bd_kfe_access_token = e.access_token, 0 === bd_kfe_data.thread.id && bd_kfe_httpapi.requestThread() }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, isTokenValid: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/user/token/valide", contentType: "application/json; charset=utf-8", type: "get", data: { client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + localStorage.bd_kfe_access_token) }, success: function (e) { console.log("isTokenValid success:", e) }, error: function (e) { console.log("isTokenValid error:", e), app.login() } }) }, fingerPrint2: function () { var e = DeviceInfo.getDeviceInfo({ domain: "" }); $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/fingerprint2/browser", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ browserInfo: encodeURI(e.browserInfo), deviceType: encodeURI(e.deviceType), fingerprint: encodeURI(e.fingerprint), language: encodeURI(e.language), os: encodeURI(e.os), osVersion: encodeURI(e.osVersion), referrer: encodeURI(bd_kfe_data.refererUrl), url: encodeURI(bd_kfe_data.websiteUrl), client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, browse: function () { if (!bd_kfe_data.thread.tid || 0 == bd_kfe_data.thread.tid.trim().length) return void bd_kfe_utils.printLog("thread tid is null"); var e = bd_kfe_data.websiteUrl; e = e.endsWith("#") ? e.substring(0, e.length - 1) : e, bd_kfe_data.websiteTitle && bd_kfe_data.websiteTitle.length > 6 && (bd_kfe_data.websiteTitle = bd_kfe_data.websiteTitle.substring(0, 6)), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/thread/set/url", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ tid: bd_kfe_data.thread.tid, preUrl: encodeURI(bd_kfe_data.refererUrl), url: encodeURI(e), title: encodeURI(bd_kfe_data.websiteTitle) }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("browse:" + JSON.stringify(e.data)) }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, acceptInviteBrowse: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/browse/invite/accept", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ biid: bd_kfe_data.browseInviteBIid, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("browse invite accept:" + e.data) }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, rejectInviteBrowse: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/browse/invite/reject", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ biid: bd_kfe_data.browseInviteBIid, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("browse invite reject:" + e.data) }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, requestThread: function () { var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0]; return "1" === bd_kfe_data.preload ? ("workGroup" === bd_kfe_data.type ? (bd_kfe_httpapi.getWorkGroupStatus(bd_kfe_data.workGroupWid), bd_kfe_httpapi.getPrechatSettings()) : bd_kfe_httpapi.getUserStatus(bd_kfe_data.agentUid), void bd_kfe_stompapi.byteDeskConnect()) : (e && $("#bytedesk_loading").show(), "1" === bd_kfe_data.v2robot ? void bd_kfe_httpapi.requestWorkGroupThreadV2() : void $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/thread/request", contentType: "application/json; charset=utf-8", type: "get", data: { wId: bd_kfe_data.workGroupWid, type: bd_kfe_data.type, aId: bd_kfe_data.agentUid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (t) { bd_kfe_httpapi.dealWithThread(t, e) }, error: function (e) { bd_kfe_utils.printLog(e), bd_kfe_httpapi.login() } })) }, requestWorkGroupThreadV2: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/v2/thread/workGroup", contentType: "application/json; charset=utf-8", type: "get", data: { wId: bd_kfe_data.workGroupWid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + localStorage.bd_kfe_access_token) }, success: function (e) { bd_kfe_httpapi.dealWithThread(e, !1) }, error: function (e) { bd_kfe_utils.printLog(e), bd_kfe_httpapi.login() } }) }, requestAgent: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/thread/request/agent", contentType: "application/json; charset=utf-8", type: "get", data: { wId: bd_kfe_data.workGroupWid, type: bd_kfe_data.type, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("message:" + JSON.stringify(e)), $("#bytedesk_loading").hide(); var t = e.data; 200 === e.status_code ? (bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread, bd_kfe_httpapi.showLoadHistoryMessage(), bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = t.user.avatar, bd_kfe_data.agentNickname = t.user.nickname, bd_kfe_data.agentDescription = t.user.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_data.isRobot = !1, bd_kfe_data.isThreadClosed = !1, bd_kfe_utils.toggleRequestAgentTip(!1)) : 201 === e.status_code ? (bd_kfe_data.thread = t.thread, bd_kfe_httpapi.showLoadHistoryMessage(), bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = t.user.avatar, bd_kfe_data.agentNickname = t.user.nickname, bd_kfe_data.agentDescription = t.user.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_data.isRobot = !1, bd_kfe_data.isThreadClosed = !1, bd_kfe_utils.toggleRequestAgentTip(!1)) : 202 === e.status_code ? (bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread, bd_kfe_data.isThreadClosed = !1) : 203 === e.status_code ? (bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread, bd_kfe_data.thread.appointed ? bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname : bd_kfe_data.agentNickname = bd_kfe_data.thread.workGroup.nickname, $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), bd_kfe_data.isRobot = !1, "form" === t.sessionType ? bd_kfe_utils.switchLeaveMessage() : console.log("聊天页面留言"), bd_kfe_utils.toggleRequestAgentTip(!1)) : 204 === e.status_code ? (bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread, bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = bd_kfe_data.thread.workGroup.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.workGroup.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.workGroup.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), "form" === t.sessionType ? bd_kfe_utils.switchLeaveMessage() : console.log("聊天页面留言")) : 205 === e.status_code ? (bd_kfe_data.questionnaireItemItems = t.questionnaire.questionnaireItems[0].questionnaireItemItems, bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread) : 206 === e.status_code ? (bd_kfe_utils.pushToMessageArray(t), bd_kfe_data.thread = t.thread, bd_kfe_data.isRobot = !0, bd_kfe_data.agentAvatar = t.user.avatar, bd_kfe_data.agentNickname = t.user.nickname, bd_kfe_data.agentDescription = t.user.description, $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription)) : -1 === e.status_code ? bd_kfe_httpapi.login() : -2 === e.status_code || e.status_code, bd_kfe_utils.scrollToBottom(), bd_kfe_stompapi.byteDeskConnect() }, error: function (e) { bd_kfe_utils.printLog(e), bd_kfe_httpapi.login() } }) }, dealWithThread: function (e) { var t = arguments.length > 1 && void 0 !== arguments[1] && arguments[1]; $("#bytedesk_loading").hide(); var a = e.data; 200 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_httpapi.showLoadHistoryMessage(), bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = a.user.avatar, bd_kfe_data.agentNickname = a.user.nickname, bd_kfe_data.agentDescription = a.user.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_data.isRobot = !1, bd_kfe_data.isThreadClosed = !1, bd_kfe_stompapi.appendCommodityInfo()) : 201 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_httpapi.showLoadHistoryMessage(), bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = a.user.avatar, bd_kfe_data.agentNickname = a.user.nickname, bd_kfe_data.agentDescription = a.user.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_data.isRobot = !1, bd_kfe_data.isThreadClosed = !1, bd_kfe_stompapi.appendCommodityInfo()) : 202 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_data.isThreadClosed = !1) : 203 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = bd_kfe_data.thread.workGroup.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.workGroup.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.workGroup.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_data.isRobot = !1, "form" === a.sessionType ? bd_kfe_utils.switchLeaveMessage() : console.log("聊天页面留言")) : 204 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_data.thread.appointed ? (bd_kfe_data.agentAvatar = bd_kfe_data.thread.agent.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.agent.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.agent.description) : (bd_kfe_data.agentAvatar = bd_kfe_data.thread.workGroup.avatar, bd_kfe_data.agentNickname = bd_kfe_data.thread.workGroup.nickname, bd_kfe_data.agentDescription = bd_kfe_data.thread.workGroup.description), $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), "form" === a.sessionType ? bd_kfe_utils.switchLeaveMessage() : console.log("聊天页面留言"), $("#bytedesk-leavemsg-tip").text(a.content)) : 205 === e.status_code ? (bd_kfe_data.questionnaireItemItems = a.questionnaire.questionnaireItems[0].questionnaireItemItems, bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread) : 206 === e.status_code ? (bd_kfe_utils.pushToMessageArray(a), bd_kfe_data.thread = a.thread, bd_kfe_data.isRobot = !0, bd_kfe_data.agentAvatar = a.user.avatar, bd_kfe_data.agentNickname = a.user.nickname, bd_kfe_data.agentDescription = a.user.description, $("#bytedesk_agent_avatar").attr("src", bd_kfe_data.agentAvatar), $("#bytedesk_agent_nickname").text(bd_kfe_data.agentNickname), $("#bytedesk_agent_description").text(bd_kfe_data.agentDescription), bd_kfe_utils.toggleRequestAgentTip(!0), bd_kfe_httpapi.getTransferWords()) : -1 === e.status_code ? bd_kfe_httpapi.login() : -2 === e.status_code || e.status_code, bd_kfe_utils.scrollToBottom(), t || (null != a.thread && void 0 != a.thread && bd_kfe_httpapi.dealWithWorkGroup(a.thread.workGroup), bd_kfe_httpapi.getQuickButtons(), setInterval(function () { bd_kfe_httpapi.loadMessagesUnread() }, 5e3), bd_kfe_httpapi.getMessagesUnread(), bd_kfe_stompapi.byteDeskConnect()), bd_kfe_httpapi.browse() }, rate: function () { bd_kfe_data.rateContent = $("#suggestcontent").val(), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/rate/do", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ tid: bd_kfe_data.thread.tid, score: bd_kfe_data.rateScore, note: bd_kfe_data.rateContent, invite: bd_kfe_data.isInviteRate, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("rate: " + e.data), bd_kfe_data.isRated = !0, 200 === e.status_code ? ($("#bytedesk_main").show(), $("#bytedesk_rate").hide()) : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog(e), alert(e) } }) }, closeWebPage: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/thread/visitor/close", type: "post", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify({ tid: bd_kfe_data.thread.tid, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("close thread: " + e.data), navigator.userAgent.indexOf("MSIE") > 0 ? navigator.userAgent.indexOf("MSIE 6.0") > 0 ? (window.opener = null, window.close()) : (window.open("", "_top"), window.top.close()) : navigator.userAgent.indexOf("Firefox") > 0 ? (window.location.href = "about:blank ", window.opener = null, window.open("", "_self", ""), window.close()) : (window.opener = null, window.open("", "_self", ""), window.close()) }, error: function (e) { bd_kfe_utils.printLog(e), alert(e) } }) }, showLoadHistoryMessage: function () { "1" === bd_kfe_data.history && $("#bytedesk_more").show() }, loadHistoryMessages: function () { arguments.length > 0 && void 0 !== arguments[0] && arguments[0]; if ("1" === bd_kfe_data.history) { var e = "加载中..."; "en" === bd_kfe_data.lang && (e = "Loading..."), $("#bytedesk_more").text(e); var t = "appointed" === bd_kfe_data.type ? bd_kfe_data.agentUid : bd_kfe_data.workGroupWid; $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/user/wid", type: "get", data: { wid: t, page: bd_kfe_data.page, size: 20, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("loadHistoryMessages: " + JSON.stringify(e.data)); var t = "加载更多消息"; if ("en" === bd_kfe_data.lang && (t = "Loading More"), $("#bytedesk_more").text(t), 200 === e.status_code) { bd_kfe_data.page += 1, bd_kfe_data.hasMoreHistoryMessage = !e.data.last, bd_kfe_data.hasMoreHistoryMessage ? $("#bytedesk_more").show() : $("#bytedesk_more").hide(); for (var a = e.data.content.length, d = 0; d < a; d++) { var n = e.data.content[d]; if ("notification_thread_reentry" === n.type) { if (d + 1 < a) { var s = e.data.content[d + 1]; if ("notification_thread_reentry" === s.type) continue; bd_kfe_utils.pushToMessageArray(n, !0) } } else bd_kfe_utils.pushToMessageArray(n, !0) } } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog(e), $("#bytedesk_more").hide() } }) } }, getTopAnswers: function () { if ("1" !== bd_kfe_data.preload && "2" === bd_kfe_data.column) return "workGroup" === bd_kfe_data.type ? void bd_kfe_httpapi.getTopAnswersWorkGroup() : void $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/answer/top", contentType: "application/json; charset=utf-8", type: "get", data: { uid: bd_kfe_data.adminUid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("fetch answers success:" + JSON.stringify(e.data)), 200 === e.status_code ? (bd_kfe_data.answers = e.data, bd_kfe_utils.pushAnswers(bd_kfe_data.answers.content)) : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("fetch answers error:" + e) } }) }, getTopAnswersWorkGroup: function () { "1" !== bd_kfe_data.preload && "2" === bd_kfe_data.column && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/answer/top/workgroup", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("getTopAnswersWorkGroup success:" + JSON.stringify(e.data)), 200 === e.status_code ? (bd_kfe_data.answers = e.data, bd_kfe_utils.pushAnswers(bd_kfe_data.answers.content)) : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("getTopAnswersWorkGroup error:" + e) } }) }, appendQueryMessage: function (e) { var t = bd_kfe_utils.guid(), a = { mid: t, type: bd_kfe_data.MESSAGE_TYPE_ROBOT, content: e, imageUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: t, status: bd_kfe_data.MESSAGE_STATUS_STORED, user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(a) }, appendReplyMessage: function (e, t) { var a = bd_kfe_utils.guid(), d = { mid: a, type: bd_kfe_data.MESSAGE_TYPE_ROBOT, content: t, imageUrl: t, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: bd_kfe_data.MESSAGE_STATUS_STORED, answer: { aid: e }, answers: [], user: { uid: bd_kfe_data.thread.agent.uid, username: bd_kfe_data.thread.agent.username, nickname: bd_kfe_data.thread.agent.nickname, avatar: bd_kfe_data.thread.agent.avatar } }; return bd_kfe_utils.pushRightAnswerToMessageArray(d), d.mid }, queryAnswer: function (e, t, a) { bd_kfe_httpapi.appendQueryMessage(decodeURIComponent(t)); var d = bd_kfe_httpapi.appendReplyMessage(e, decodeURIComponent(a)); $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/v2/answer/query", contentType: "application/json; charset=utf-8", type: "get", data: { tid: bd_kfe_data.thread.tid, aid: e, mid: d, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("query answer success:" + JSON.stringify(e.data)), 200 === e.status_code ? bd_kfe_utils.scrollToBottom() : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } }) }, queryCategory: function (e, t) { bd_kfe_httpapi.appendQueryMessage(t), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/v2/answer/category", contentType: "application/json; charset=utf-8", type: "get", data: { tid: bd_kfe_data.thread.tid, cid: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("queryCategory success:" + JSON.stringify(e)), 200 === e.status_code) { var t = e.data.reply; bd_kfe_utils.pushToMessageArray(t), bd_kfe_utils.scrollToBottom() } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query categories error:" + e) } }) }, messageAnswer: function (e) { if (bd_kfe_httpapi.appendQueryMessage(e), -1 !== e.indexOf("人工")) return void bd_kfe_httpapi.requestAgent(); for (var t = 0; t < bd_kfe_data.transferWords.length; t++) { var a = bd_kfe_data.transferWords[t]; if ("contains" === a.type) { if (-1 !== e.indexOf(a.content)) return void bd_kfe_httpapi.requestAgent() } else if ("match" === a.type && e === a.content) return void bd_kfe_httpapi.requestAgent() } $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/elastic/robot/message", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, content: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("message answer success:" + JSON.stringify(e)), 200 === e.status_code) { var t = e.data.reply; bd_kfe_utils.pushRightAnswerToMessageArray(t), bd_kfe_utils.scrollToBottom() } else if (201 === e.status_code) { var t = e.data.reply; bd_kfe_utils.pushNoAnswerToMessageArray(t), bd_kfe_utils.scrollToBottom() } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } }) }, previewAnswer: function (e) { bd_kfe_data.IS_PRODUCTION || ($("#bytedesk_faq_preview").html(""), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/elastic/robot/preview", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, content: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if ($("#bytedesk_faq_preview").html(""), e.data.totalHits > 0) { $("#bytedesk_faq_preview").show(); for (var t = 0; t < e.data.searchHits.length && t < 4; t++) { var a = e.data.searchHits[t], d = a.content.question, n = a.content.answer, s = '<span class="bytedesk_faq_preview-item" onclick="bd_kfe_utils.handleFaqPreviewItemClicked(\'' + encodeURIComponent(d) + "','" + encodeURIComponent(n) + "')\" >" + d + "</span>"; $("#bytedesk_faq_preview").append(s) } } }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } })) }, robotQueryAnswer: function (e, t) { var a = bd_kfe_utils.guid(), d = { mid: a, type: bd_kfe_data.MESSAGE_TYPE_TEXT, content: t, imageUrl: t, createdAt: bd_kfe_utils.currentTimestamp(), localId: a, status: bd_kfe_data.MESSAGE_STATUS_STORED, user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(d), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/robot/query", contentType: "application/json; charset=utf-8", type: "get", data: { type: "aid", mid: a, tid: bd_kfe_data.thread.tid, aid: e, question: t, uid: bd_kfe_data.adminUid, keyword: "", client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("robot query answer success:" + JSON.stringify(e.data)), 200 === e.status_code ? bd_kfe_utils.scrollToBottom() : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } }) }, robotMessageAnswer: function (e) { var t = bd_kfe_utils.guid(), a = { mid: t, type: bd_kfe_data.MESSAGE_TYPE_TEXT, content: e, imageUrl: e, createdAt: bd_kfe_utils.currentTimestamp(), localId: t, status: bd_kfe_data.MESSAGE_STATUS_STORED, user: { uid: bd_kfe_data.my_uid(), username: bd_kfe_data.my_username(), nickname: bd_kfe_data.my_nickname(), avatar: bd_kfe_data.my_avatar() } }; bd_kfe_utils.pushToMessageArray(a), $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/robot/query", contentType: "application/json; charset=utf-8", type: "get", data: { type: "keyword", mid: t, tid: bd_kfe_data.thread.tid, aid: "", question: "", uid: bd_kfe_data.adminUid, keyword: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("robot msg answer success:" + JSON.stringify(e.data)), 200 === e.status_code ? bd_kfe_utils.scrollToBottom() : alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } }) }, rateAnswer: function (e, t, a) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/answer/rate", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ aid: e + "", mid: t + "", rate: a, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("success:" + JSON.stringify(e.data)), 200 === e.status_code) { var t = e.data; bd_kfe_utils.pushToMessageArray(t) } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + JSON.stringify(e)) } }) }, sendMobile: function () { var e = $.trim($("#bytedesk_input-mobile").val()); if (11 !== e.length) return void alert("请正确天下手机号"); $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/crm/collect", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ adminUid: bd_kfe_data.adminUid, visitorUid: bd_kfe_data.uid, threadTid: bd_kfe_data.thread.tid, name: bd_kfe_data.nickname, mobile: e, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("success:" + e.data), 200 === e.status_code) { var t = bd_kfe_utils.guid(), a = { mid: t, type: "notification", content: "呼叫成功,我们会尽快联系您", createdAt: bd_kfe_utils.currentTimestamp(), localId: t, status: "stored", user: { uid: "", username: bd_kfe_data.username, nickname: bd_kfe_data.nickname, avatar: bd_kfe_data.avatar } }; bd_kfe_utils.pushToMessageArray(a) } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog("query answers error:" + e) } }) }, leaveMessage: function () { var e = $("#bytedesk_leavemsg_mobile").val(), t = $("#bytedesk_leavemsg_content").val(); $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/leavemsg/save", contentType: "application/json; charset=utf-8", dataType: "json", type: "post", data: JSON.stringify({ wid: bd_kfe_data.workGroupWid, aid: bd_kfe_data.agentUid, type: bd_kfe_data.type, mobile: e, email: "", content: t, client: bd_kfe_data.client }), beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("leave message: " + e.data), 200 === e.status_code) { var t = "留言成功"; "en" === bd_kfe_data.lang && (t = "leaveMessage success"), alert(t) } else alert(e.message) }, error: function (e) { bd_kfe_utils.printLog(e); var t = "留言失败"; "en" === bd_kfe_data.lang && (t = "leaveMessage failed"), alert(t) } }) }, getWorkGroupStatus: function (e) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/status/workGroup", contentType: "application/json; charset=utf-8", type: "get", data: { wid: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (t) { if (200 === t.status_code) { var a = t.data.status; window.parent.postMessage({ msg: "bytedesk-status", type: "workGroup", uuid: e, status: a }, "*"), bd_kfe_utils.printLog("status:" + a) } else alert(t.message) }, error: function (e) { bd_kfe_utils.printLog("get workGroup status error:" + e) } }) }, getUserStatus: function (e) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/status/agent", contentType: "application/json; charset=utf-8", type: "get", data: { uid: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (t) { if (200 === t.status_code) { var a = t.data.status; window.parent.postMessage({ msg: "bytedesk-status", type: "agent", uuid: e, status: a }, "*"), bd_kfe_utils.printLog("status:" + a) } else alert(t.message) }, error: function (e) { bd_kfe_utils.printLog("get user status error:" + e) } }) }, getUnreadCount: function (e) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/unreadCount", contentType: "application/json; charset=utf-8", type: "get", data: { wid: e, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("get unread count success:" + e.data) }, error: function (e) { bd_kfe_utils.printLog("get unreadCount error:" + e) } }) }, getUnreadCountVisitor: function () { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/unreadCount/visitor", contentType: "application/json; charset=utf-8", type: "get", data: { client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { bd_kfe_utils.printLog("get unread count visitor success:", e.data) }, error: function (e) { bd_kfe_utils.printLog("get unreadCount visitor error:", e) } }) }, getPrechatSettings: function () { "workGroup" === bd_kfe_data.type && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/visitor/api/prechat/settings", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, client: bd_kfe_data.client }, success: function (e) { if (console.log("fetch pre setting success:", e.data), 200 === e.status_code) { var t = e.data; bd_kfe_httpapi.dealWithWorkGroup(t) } }, error: function (e) { bd_kfe_utils.printLog("fetch pre setting error:", e) } }) }, dealWithWorkGroup: function (e) { if (console.log("dealWithWorkGroup:", e), null !== e.wid) { if ("1" === bd_kfe_data.preload) return void (e.autoPop && window.parent.postMessage("bytedesk-popup", "*")); bd_kfe_data.workGroupNickname = e.nickname, bd_kfe_data.workGroupAvatar = e.avatar, bd_kfe_data.workGroupDescription = e.description, e.autoPop && window.parent.postMessage("bytedesk-popup", "*"), e.showTopTip && $("#bytedesk_toptip").html(e.topTip), e.showCollectMobile && $("#bytedesk_message-input").show(), e.showForm && ($("#bytedesk_form-name-div").show(), $("#bytedesk_form-mobile-div").show(), bd_kfe_utils.switchForm()), e.hideLogo && $("#bytedesk_logo").hide(), e.showRightColumn && "2" === bd_kfe_data.column ? bd_kfe_utils.showRightColumn(e.workTabs) : "2" === bd_kfe_data.column && (console.log("默认显示faq-2"), $("#bytedesk_right").show(), $("#bytedesk_right_tab").append("<button class='bytedesk_right_tablinks'>常见问题</button>"), $("#bytedesk_right_tabcontent").append("<div id='faq' class='bytedesk_right_tabcontent'><div id=\"bytedesk_question\"></div></div >"), bd_kfe_httpapi.getTopAnswers(), bd_kfe_utils.rightTabInit()) } }, getQuickButtons: function () { "1" !== bd_kfe_data.preload && "workGroup" === bd_kfe_data.type && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/quickbutton/query/workGroup", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { e.data.length > 0 && ($("#bytedesk_quick_question").show(), $(".footer").css("height", "135px")); for (var t = 0; t < e.data.length && t < 4; t++) { var a = e.data[t], d = '<span class="bytedesk_quick_question-item" onclick="bd_kfe_utils.handleQuickbuttonClick(\'' + a.type + "','" + a.title + "','" + a.content + "')\" >" + a.title + "</span>"; $("#bytedesk_quick_question").append(d) } }, error: function (e) { bd_kfe_utils.printLog("getQuickButtons error:", e) } }) }, getTransferWords: function () { "1" !== bd_kfe_data.preload && "workGroup" === bd_kfe_data.type && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/transferword/query/workGroup", contentType: "application/json; charset=utf-8", type: "get", data: { wid: bd_kfe_data.workGroupWid, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { console.log("getTransferWords:", e), bd_kfe_data.transferWords = e.data }, error: function (e) { bd_kfe_utils.printLog("getQuickButtons error:", e) } }) }, loadHistoryMessagesByTopic: function (e) { "1" !== bd_kfe_data.preload && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/topic", type: "get", data: { topic: e, page: bd_kfe_data.page, size: 10, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("loadHistoryMessagesByTopic: " + JSON.stringify(e)), 200 === e.status_code) for (var t = 0; t < e.data.content.length; t++) { var a = e.data.content[t]; if ("notification_form_request" === a.type || a.type, "notification_thread_reentry" === a.type) { if (t + 1 < length) { var d = e.data.content[t + 1]; if ("notification_thread_reentry" === d.type) continue; bd_kfe_utils.pushToMessageArray(a, !0) } } else bd_kfe_utils.pushToMessageArray(a, !0) } bd_kfe_utils.scrollToBottom() }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, loadLatestMessage: function () { "1" !== bd_kfe_data.preload && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/topic", type: "get", data: { topic: bd_kfe_data.thread.topic, page: 0, size: 10, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("loadLatestMessage: " + JSON.stringify(e)), 200 === e.status_code) for (var t = 0; t < e.data.content.length; t++) { var a = e.data.content[t]; if ("notification_form_request" === a.type || a.type, "notification_thread_reentry" === a.type) { if (t + 1 < length) { var d = e.data.content[t + 1]; if ("notification_thread_reentry" === d.type) continue; bd_kfe_utils.pushToMessageArray(a, !0) } } else bd_kfe_utils.pushToMessageArray(a, !0) } bd_kfe_utils.scrollToBottom() }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, loadMessagesUnread: function () { bd_kfe_data.isConnected || bd_kfe_data.isRobot || bd_kfe_httpapi.getMessagesUnread() }, getMessagesUnread: function () { "1" !== bd_kfe_data.preload && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/api/messages/unread/message/visitor/schedule", type: "get", data: { page: 0, size: 10, client: bd_kfe_data.client }, beforeSend: function (e) { e.setRequestHeader("Authorization", "Bearer " + bd_kfe_data.passport.token.access_token) }, success: function (e) { if (bd_kfe_utils.printLog("loadMessagesUnread: " + JSON.stringify(e)), 200 === e.status_code) for (var t = 0; t < e.data.content.length; t++) { var a = e.data.content[t]; if ("notification_form_request" === a.type || a.type, "notification_thread_reentry" === a.type) { if (t + 1 < length) { var d = e.data.content[t + 1]; if ("notification_thread_reentry" === d.type) continue; bd_kfe_utils.pushToMessageArray(a, !0) } } else bd_kfe_utils.pushToMessageArray(a, !0) } }, error: function (e) { bd_kfe_utils.printLog(e) } }) }, getBaseUrl: function () { bd_kfe_data.IS_PRODUCTION && $.ajax({ url: bd_kfe_data.HTTP_HOST + "/visitor/api/wechatUrl", contentType: "application/json; charset=utf-8", type: "get", data: { client: "web" }, success: function (e) { console.log("get base url:", e), bd_kfe_data.CHAT_URL = "https://" + e.data.url }, error: function (e) { console.log("get base url error:", e) } }) }, getShortUrl: function (e, t, a) { $.ajax({ url: bd_kfe_data.HTTP_HOST + "/url/to/short", contentType: "application/json; charset=utf-8", type: "get", data: { url: e, uid: bd_kfe_data.adminUid, client: "web" }, success: function (e) { console.log("get short url success:", e.data), bd_kfe_data.IS_PRODUCTION ? bd_kfe_data.shortCode = "http://url.chainsnow.com/chat/" + e.data : bd_kfe_data.shortCode = bd_kfe_data.HTTP_HOST + "/chat/" + e.data, t(bd_kfe_data.shortCode) }, error: function (e) { console.log("get short url error:", e), a(e) } }) } }; |