jiuyiUniapp/jiuyi2/unpackage/dist/dev/mp-weixin/TUIKit/tui-customer-service-plugin/server.js

87 lines
3.3 KiB
JavaScript

"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const common_vendor = require("../../common/vendor.js");
const TUIKit_tuiCustomerServicePlugin_utils_index = require("./utils/index.js");
const _TUICustomerServer = class _TUICustomerServer {
constructor() {
__publicField(this, "customerServiceAccounts");
console.log("TUICustomerServer.init ok");
common_vendor.R.registerService(common_vendor.E.TUICustomerServicePlugin.SERVICE.NAME, this);
common_vendor.R.registerExtension(common_vendor.E.TUIContact.EXTENSION.CONTACT_LIST.EXT_ID, this);
this.customerServiceAccounts = ["@customer_service_account"];
}
static getInstance() {
if (!_TUICustomerServer.instance) {
_TUICustomerServer.instance = new _TUICustomerServer();
}
return _TUICustomerServer.instance;
}
// Set customer service number
setCustomerServiceAccounts(accounts) {
this.customerServiceAccounts = accounts;
}
// Obtain customer service number
getCustomerServiceAccounts() {
return this.customerServiceAccounts;
}
// Determine if the current session is a customer service session
isCustomerConversation(conversationID) {
const userID = conversationID && conversationID.slice(3) || "";
return this.customerServiceAccounts.indexOf(userID) > -1;
}
// Determine if the current message is a customer service message
isCustomerServicePluginMessage(message) {
if (!message || !this.isCustomerConversation(message.conversationID)) {
return false;
}
return TUIKit_tuiCustomerServicePlugin_utils_index.isCustomerServiceMessage(message) || TUIKit_tuiCustomerServicePlugin_utils_index.isMessageInvisible(message);
}
onGetExtension(extensionID) {
if (extensionID === common_vendor.E.TUIContact.EXTENSION.CONTACT_LIST.EXT_ID) {
return [
{
weight: 0,
icon: "",
text: "客服号",
data: {
name: "customer",
accountList: this.customerServiceAccounts
}
}
];
}
}
onCall(method, params) {
switch (method) {
case common_vendor.E.TUICustomerServicePlugin.SERVICE.METHOD.ACTIVE_CONVERSATION:
if (this.isCustomerConversation(params.conversationID)) {
common_vendor.R.callService({
serviceName: common_vendor.E.TUIChat.SERVICE.NAME,
method: common_vendor.E.TUIChat.SERVICE.METHOD.SET_CHAT_TYPE,
params: { chatType: "customerService" }
});
common_vendor.R.callService({
serviceName: common_vendor.E.TUIChat.SERVICE.NAME,
method: common_vendor.E.TUIChat.SERVICE.METHOD.SEND_CUSTOM_MESSAGE,
params: {
to: params.conversationID.slice(3),
conversationType: "C2C",
payload: {
data: JSON.stringify({ src: "7", customerServicePlugin: 0 })
}
}
});
}
break;
}
}
};
__publicField(_TUICustomerServer, "instance");
let TUICustomerServer = _TUICustomerServer;
exports.TUICustomerServer = TUICustomerServer;