客服推送处理+后台操作
This commit is contained in:
1 parent
b652132957
commit
a81c637a98
11 files changed
+302
-54
No files matched your search
@@ -60,6 +60,34 @@ export function fieldOf(body: string, field: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** 客服消息的 MsgType 中文名,只用于日志展示。 */
|
||||
const CUSTOMER_SERVICE_MSG_TYPES: Record<string, string> = {
|
||||
text: '文字',
|
||||
image: '图片',
|
||||
miniprogrampage: '小程序卡片',
|
||||
link: '链接',
|
||||
};
|
||||
|
||||
export function customerServiceMsgTypeLabel(msgType: string): string {
|
||||
if (!msgType) return '未知类型';
|
||||
return CUSTOMER_SERVICE_MSG_TYPES[msgType] ?? msgType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是客服消息推送。
|
||||
*
|
||||
* 小程序后台只有一个「消息推送 URL」,所以用户点客服按钮
|
||||
* (Event = user_enter_tempsession)和用户给客服发消息(MsgType = text / image …)
|
||||
* 都会推到同一个地址,和支付推送混在一起,必须分开认。
|
||||
*
|
||||
* 支付推送没有 MsgType 字段;有 MsgType 且不是 event 的,就是用户发来的消息。
|
||||
*/
|
||||
export function isCustomerServicePush(body: string): boolean {
|
||||
if (eventOf(body) === 'user_enter_tempsession') return true;
|
||||
const msgType = fieldOf(body, 'MsgType');
|
||||
return msgType !== '' && msgType !== 'event';
|
||||
}
|
||||
|
||||
/** 把值塞进 CDATA 安全地用于回包。 */
|
||||
export function cdata(value: string): string {
|
||||
return `<![CDATA[${value.replace(/]]>/g, ']] >')}]]>`;
|
||||
|
||||
Reference in new issue
Block a user