消息
This commit is contained in:
15
TUIKit/tui-customer-service-plugin/utils/env.ts
Normal file
15
TUIKit/tui-customer-service-plugin/utils/env.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { getPlatform } from '@tencentcloud/universal-api';
|
||||
declare const uni: any;
|
||||
|
||||
export const isPC = getPlatform() === 'pc';
|
||||
|
||||
export const isH5 = getPlatform() === 'h5';
|
||||
|
||||
export const isWeChat = getPlatform() === 'wechat';
|
||||
|
||||
export const isApp = getPlatform() === 'app';
|
||||
|
||||
export const isUniFrameWork = typeof uni !== 'undefined';
|
||||
|
||||
// H5、小程序、app 均认为是手机端产品,如果需要统一手机端 UI 样式,可以直接用 isMobile 控制
|
||||
export const isMobile = isH5 || isWeChat || isApp;
|
||||
56
TUIKit/tui-customer-service-plugin/utils/index.ts
Normal file
56
TUIKit/tui-customer-service-plugin/utils/index.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { customerServicePayloadType, IMessageModel } from '../interface';
|
||||
import { CUSTOM_MESSAGE_SRC, TYPES } from '../constant';
|
||||
|
||||
// Determine if it is a JSON string
|
||||
export function isJSON(str: string): boolean {
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
if (typeof str === 'string') {
|
||||
try {
|
||||
const data = JSON.parse(str);
|
||||
if (data) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine if it is a JSON string
|
||||
export function JSONToObject(str: string) {
|
||||
if (!isJSON(str)) {
|
||||
return str;
|
||||
}
|
||||
return JSON.parse(str);
|
||||
}
|
||||
|
||||
export function isCustomerServiceMessage(message: IMessageModel): boolean {
|
||||
const customerServicePayload: customerServicePayloadType = JSONToObject(message?.payload?.data);
|
||||
return Number(customerServicePayload?.customerServicePlugin) === 0 || Number(customerServicePayload?.chatbotPlugin) === 1;
|
||||
}
|
||||
|
||||
export const isMessageRating = (message: IMessageModel): boolean => {
|
||||
const customerServicePayload: customerServicePayloadType = JSONToObject(message?.payload?.data);
|
||||
return isCustomerServiceMessage(message) && customerServicePayload.src === CUSTOM_MESSAGE_SRC.MENU;
|
||||
};
|
||||
|
||||
export const isMessageInvisible = (message: IMessageModel): boolean => {
|
||||
const customerServicePayload: customerServicePayloadType = JSONToObject(message?.payload?.data);
|
||||
const robotCommandArray = ['feedback', 'updateBotStatus'];
|
||||
const whiteList = [
|
||||
CUSTOM_MESSAGE_SRC.MENU,
|
||||
CUSTOM_MESSAGE_SRC.BRANCH,
|
||||
CUSTOM_MESSAGE_SRC.BRANCH_NUMBER,
|
||||
CUSTOM_MESSAGE_SRC.FROM_INPUT,
|
||||
CUSTOM_MESSAGE_SRC.PRODUCT_CARD,
|
||||
CUSTOM_MESSAGE_SRC.ROBOT_MSG,
|
||||
CUSTOM_MESSAGE_SRC.RICH_TEXT,
|
||||
CUSTOM_MESSAGE_SRC.STREAM_TEXT,
|
||||
];
|
||||
const isCustomerMessage = message?.type === TYPES.MSG_CUSTOM;
|
||||
const isCustomerInvisible = customerServicePayload?.src && !whiteList.includes(customerServicePayload?.src);
|
||||
const isRobot = customerServicePayload?.src === CUSTOM_MESSAGE_SRC.ROBOT && robotCommandArray.indexOf(customerServicePayload?.content?.command) !== -1;
|
||||
return isCustomerMessage && (isCustomerInvisible || isRobot);
|
||||
};
|
||||
Reference in New Issue
Block a user