UNPKG

@tencentcloud/ai-desk-customer-wechat

Version:

AI Desk customer UIKit for wechat mini program

3 lines (2 loc) 6.19 kB
"use strict";require("../../common/vendor.js");const s=require("../@aidesk/uikit-engine/index.js"),l=require("./env.js"),S=require("../adapter-vue-uniapp.js"),p=require("./index.js"),u=require("../constant.js"),g=require("./logger.js"),M=require("./lib-marked.js");function _(e,t=new WeakMap){if(typeof e!="object"||e===null||e===void 0)return e;if(t.has(e))return t.get(e);const n=Object.create(Object.getPrototypeOf(e));return Object.keys(e).forEach(o=>{const i=e[o];typeof i!="object"||i===null?n[o]=i:Array.isArray(i)?n[o]=[...i]:i instanceof Set?n[o]=new Set([...i]):i instanceof Map?n[o]=new Map([...i]):(t.set(e,e),n[o]=_(i,t))}),n}function R(){return s.Kt.getData(s.a.USER,"displayMessageReadReceipt")&&s.Kt.getData(s.a.APP,"enabledMessageReadReceipt")}function O(e){return Object.assign({},e)}function E(e){const t=new Date().setHours(0,0,0,0),n=new Date(new Date().getFullYear(),0,1,0,0,0,0).getTime(),r=new Date(e),o=24*60*60*1e3,i=7*o,f=t-r.getTime();function a(c){return c<10?"0"+c:c.toString()}if(f<=0)return`${a(r.getHours())}:${a(r.getMinutes())}`;if(f<=o)return`${s.jt.t("time.昨天")} ${a(r.getHours())}:${a(r.getMinutes())}`;if(f<=i-o){const d=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"][r.getDay()];return`${s.jt.t("time."+d)} ${a(r.getHours())}:${a(r.getMinutes())}`}else return r.getTime()>=n?`${r.getMonth()+1}/${r.getDate()} ${a(r.getHours())}:${a(r.getMinutes())}`:`${r.getFullYear()}/${r.getMonth()+1}/${r.getDate()} ${a(r.getHours())}:${a(r.getMinutes())}`}const k=l.isApp&&S.vueVersion===2,w=l.isApp&&S.vueVersion===3,U=l.isWeChat&&S.vueVersion===2,h=e=>!!(k&&p.JSONToObject(e).src===u.CUSTOM_MESSAGE_SRC.STREAM_TEXT);function A(e){try{const t=decodeURIComponent(e);if(typeof URL<"u"){const n=new URL(t);return["http:","https:"].includes(n.protocol)?(n.username="",n.password="",n.href):null}return t}catch{return null}}function b(e){const t=A(e);t?l.isApp||l.isH5&&window.open(t,"_blank","noopener,noreferrer"):g.Log.w(`Invalid URL provided:${e}`)}function D(e){e!==1?s.Bt.switchMessageReadStatus(!1):s.Bt.switchMessageReadStatus(!0)}function N(e,t,n){if(!t){g.Log.w("taskFlowID is required");return}s.Yt.sendCustomMessage({to:e,conversationType:s.Vt.TYPES.CONV_C2C,payload:{data:JSON.stringify({src:u.CUSTOM_MESSAGE_SRC.TRANSFER_TO_TASK_FLOW,customerServicePlugin:0,taskId:t,env:"production",description:n||""})}},{onlineUserOnly:!n})}function $(e,t,n,r){if(!t&&(!n||n.length===0)){g.Log.w("groupID or specificMemberList is required");return}s.Yt.sendCustomMessage({to:e,conversationType:s.Vt.TYPES.CONV_C2C,payload:{data:JSON.stringify({src:u.CUSTOM_MESSAGE_SRC.TRANSFER_TO_HUMAN,customerServicePlugin:0,groupId:t||0,specificMemberList:n||[],description:r||""})}},{onlineUserOnly:!r})}function j(e){s.Yt.sendCustomMessage({to:e,conversationType:s.Vt.TYPES.CONV_C2C,payload:{data:JSON.stringify({customerServicePlugin:0,src:u.CUSTOM_MESSAGE_SRC.USER_END_CONVERSATION})},needReadReceipt:R()},{onlineUserOnly:!0})}function F(e){var t,n;return((t=e==null?void 0:e.groupProfile)==null?void 0:t.groupID)||((n=e==null?void 0:e.userProfile)==null?void 0:n.userID)}function I(e){return!!(e&&Object.getPrototypeOf(e)===Object.prototype&&Object.keys(e).length>0)}function P(e){let t=s.jt.t("TUIChat.自定义");if(p.isCustomerServiceMessage(e)){const n=p.JSONToObject(e.payload.data),r=n.src;if(r===u.CUSTOM_MESSAGE_SRC.BRANCH||r===u.CUSTOM_MESSAGE_SRC.BRANCH_NUMBER)t=n.content.header;else if(r===u.CUSTOM_MESSAGE_SRC.RICH_TEXT)t=y(n.content);else if(r===u.CUSTOM_MESSAGE_SRC.STREAM_TEXT){const o=Array.isArray(n.chunks)?n.chunks.join(""):n.chunks;t=y(o)}else r===u.CUSTOM_MESSAGE_SRC.MULTI_BRANCH?t=n.content.header:r===u.CUSTOM_MESSAGE_SRC.MULTI_FORM?t=n.content.tip:r===u.CUSTOM_MESSAGE_SRC.ROBOT_MSG&&(t=n.content.title)}return t}const T=new M.marked.Renderer;T.image=(e,t,n)=>s.jt.t("TUIChat.图片");T.link=(e,t,n)=>e?s.jt.t("TUIChat.链接"):n;function y(e){return M.marked.parse(e,{renderer:T}).replace(/\n+/g," ").trim().replace(/\*\*|\*|_|`|#/g,"").replace(/<[^>]+>/g,"")}function V(e,t){let n=null,r=0;return function(...o){const i=Date.now();i-r>=t?(e.apply(this,o),r=i):(clearTimeout(n),n=setTimeout(()=>{e.apply(this,o),r=Date.now()},t-(i-r)))}}const x=["standardTaskFlowBranchOption","standardTaskFlowInformationCollection","standardTaskFlowReplyMessage","fallback","faq","clarify","chitchat","rag","aiTaskFlowInformationCollection","aiTaskFlowEndReply","aiReply"],H=["fallback","faq","aiReply"];function B(e){try{const t=p.JSONToObject(e);return x.includes(t.messageType)&&t.role==="robot"}catch{return!1}}function G(e){try{const t=p.JSONToObject(e);return H.includes(t.messageType)&&t.role==="robot"}catch{return!1}}function q(e){let t=0;return/^[\x20-\x7E]+$/.test(e)?e.toLowerCase().includes("administrator")?t=2:e.length>45&&(t=3):t=1,t}function C(e,t){s.Kt.update(s.a.CUSTOM,e,t)}function L(e){e&&(e.close(),C("formPopup",!1))}function Y(e){e&&(e.open("bottom"),C("formPopup",!0))}function J(e,t){let n;return function(...r){const o=this;n&&clearTimeout(n),n=setTimeout(()=>{e.apply(o,r)},t)}}function K(e,t,n,r){const o=e.replace(/[\n\t]/g,"").trim();return o.replace(/<[^>]+>/g,"").replace(/https?:\/\/[\w\-._~:/?#\[\]@!$&'()*+,;=%]+/g,a=>{if(/[\u4e00-\u9fff]/.test(a))return a;let d=!1;a!==o&&(d=!0);const m=encodeURI(a);return`<a target="_blank" rel="noreferrer noopener" class="${t}" style="color:${n};text-decoration:underline" href="${m}" title="${r||""}">${d?a:e}</a>`})}exports.calculateTimestamp=E;exports.canShowAINote=G;exports.canShowFeedbackButton=B;exports.closeBottomPopup=L;exports.debounce=J;exports.deepCopy=_;exports.endQueuing=j;exports.getQuoteContentForDesk=P;exports.getStyledATagFromText=K;exports.getTo=F;exports.isEnabledMessageReadReceiptGlobal=R;exports.isNonEmptyObject=I;exports.isVue2ToWechat=U;exports.isVue3App=w;exports.needHackForStreamText=h;exports.openSafeUrl=b;exports.shallowCopyMessage=O;exports.showBottomPopup=Y;exports.switchReadStatus=D;exports.throttle=V;exports.transferToHuman=$;exports.transferToTaskFlow=N;exports.updateCustomStore=C;exports.validateUserID=q; //# sourceMappingURL=../../../.sourcemap/mp-weixin/ai-desk-customer-uniapp/utils/utils.js.map