UNPKG

@tencentcloud/ai-desk-customer-wechat

Version:

AI Desk customer UIKit for wechat mini program

3 lines (2 loc) 14 kB
"use strict";const s=require("../../../../common/vendor.js"),Ge=require("../../../adapter-vue.js"),i=require("../../../@aidesk/uikit-engine/index.js"),w=require("./message-elements/message-desk/index.js"),xe=require("../../common/Toast/index-uniapp.js"),l=require("../../../utils/utils.js"),P=require("../../../utils/env.js"),B=require("../../../utils/chatStorage.js"),C=require("../../../utils/index.js"),Pe=require("../../../index.js"),f=require("../../../constant.js"),ge=require("../../../utils/logger.js"),pe=require("../../../utils/state.js"),Be=require("../../common/Toast/type.js");Math||(Xe+ts+Ne+Qe+rs+ze+qe+$e+He+Ve+We+Ye+Je+ss+es+Ze+ns+os+Ke+as+us)();const Ke=()=>"./message-elements/simple-message-list/index.js",Ne=()=>"./message-elements/message-text.js",Qe=()=>"./message-elements/message-image-uniapp.js",qe=()=>"./message-elements/message-audio-uniapp.js",$e=()=>"./message-elements/message-record/index.js",He=()=>"./message-elements/message-file.js",Ve=()=>"./message-elements/message-face.js",Ye=()=>"./message-elements/message-custom.js",Je=()=>"./message-elements/message-bubble-uniapp.js",We=()=>"./message-elements/message-location.js",Xe=()=>"./message-elements/message-timestamp.js",ze=()=>"./message-elements/message-video-uniapp.js",Ze=()=>"./message-tool/index-uniapp.js",es=()=>"./message-tool/message-revoked.js",ss=()=>"./message-elements/message-desk/message-plugin-uniapp.js",ts=()=>"./message-elements/message-thinking.js",ns=()=>"./scroll-button/index.js",os=()=>"../../common/Dialog/index.js",as=()=>"../../common/Drawer/index.js",rs=()=>"../../common/ProgressMessage/index.js",us=()=>"./bottom-quick-order/index.js",cs=s.defineComponent({__name:"index-uniapp",props:{bottomQuickOrder:{},showBottomQuickOrder:{type:Boolean,default:!1},toolbarButtonList:{default:()=>[]},enableFeedback:{default:0},enableAINote:{default:1}},emits:["closeInputToolBar","handleEditor","closeBottomQuickOrder","like","dislike"],setup(fe,{expose:ve,emit:Me}){var de;const{ref:u,nextTick:k,onMounted:me,onUnmounted:Se,getCurrentInstance:K,computed:N}=Ge.vue,g=fe,T=Me;let Ce=0,p=null;const Q=new Set,q=((de=K())==null?void 0:de.proxy)||K(),d=u([]),A=u(!1),b=u(""),D=u(""),v=u(5e3),c=u(i.Vt.TYPES),R=u(!1),$=u(!1),h=u([]),y=u(),E=u(),O=u(""),j=u(!1),H=u(),M=u({}),m=u("none"),he=N(()=>{const t=["tui-chat"];return P.isUniFrameWork&&t.push("tui-chat-h5"),P.isTikTok&&(Array.isArray(g.toolbarButtonList)&&g.toolbarButtonList.length>0?m.value==="none"?t.push("adjust-height-in-tt"):m.value==="emojiPicker"?t.push("adjust-height-emoji-in-tt"):m.value==="tools"&&t.push("adjust-height-tools-in-tt"):m.value==="none"?t.push("adjust-height-no-toolbar-button-in-tt"):m.value==="emojiPicker"?t.push("adjust-height-no-toolbar-button-emoji-in-tt"):m.value==="tools"&&t.push("adjust-height-no-toolbar-button-tools-in-tt")),t}),V=u(""),S=u(!1),Y=u(),_=()=>{v.value+=300;const t=setTimeout(()=>{v.value+=1,clearTimeout(t)},300)},J=t=>{b.value=t,Object.keys(M.value).length>0&&B.chatStorage.setChatStorage("audioPlayedMapping",M.value),Le()},W=u(!1),X=N(()=>!W.value&&l.isNonEmptyObject(g.bottomQuickOrder)&&g.showBottomQuickOrder);me(()=>{M.value=B.chatStorage.getChatStorage("audioPlayedMapping")||{},i.Kt.watch(i.a.CONV,{currentConversationID:J}),i.Kt.watch(i.a.CHAT,{messageList:ee,messageSource:se,isCompleted:ne,newMessageList:Z}),i.Kt.watch(i.a.CUSTOM,{formPopup:le}),s.v("messageList",q),s.index.$on("scroll-to-bottom",U)}),Se(()=>{i.Kt.unwatch(i.a.CHAT,{messageList:ee,messageSource:se,isCompleted:ne,newMessageList:Z}),i.Kt.unwatch(i.a.CONV,{currentConversationID:J}),i.Kt.unwatch(i.a.CUSTOM,{formPopup:le}),p==null||p.disconnect(),p=null,s.index.$off("scroll-to-bottom"),Object.keys(M.value).length>0&&B.chatStorage.setChatStorage("audioPlayedMapping",M.value)});const z=l.throttle(function(t){var n;(n=E.value)==null||n.judgeScrollOverOneScreen(t)},500);function Te(t,n){n!=null&&n.newAudioSrc&&(V.value=n.newAudioSrc)}function Z(t){t.forEach(n=>{if(n.type===i.Vt.TYPES.MSG_CUSTOM){const e=C.JSONToObject(n.payload.data),a=n.conversationID;e&&(e.src===f.CUSTOM_MESSAGE_SRC.BOT_STATUS?(l.updateCustomStore("canEndConversation",{conversationID:a,value:!0}),e.content.content==="inBot"&&l.updateCustomStore("isInHumanService",{conversationID:a,value:!1})):e.src===f.CUSTOM_MESSAGE_SRC.SEAT_STATUS?e.content.command==="updateSeatStatus"&&(l.updateCustomStore("canEndConversation",{conversationID:a,value:!0}),e.content.content==="queuing"?l.updateCustomStore("isQueuing",{conversationID:a,value:e.content.waitingQueueLength}):e.content.content==="inSeat"?(l.updateCustomStore("isInHumanService",{conversationID:a,value:!0}),l.updateCustomStore("isQueuing",{conversationID:a,value:-1})):e.content.content==="outSeat"&&(l.updateCustomStore("isInHumanService",{conversationID:a,value:!1}),l.updateCustomStore("isQueuing",{conversationID:a,value:-1}))):e.src===f.CUSTOM_MESSAGE_SRC.TYPING_STATE||(e.src===f.CUSTOM_MESSAGE_SRC.NO_SEAT_ONLINE||e.src===f.CUSTOM_MESSAGE_SRC.TIMEOUT||e.src===f.CUSTOM_MESSAGE_SRC.END?(l.updateCustomStore("canEndConversation",{conversationID:a,value:!1}),l.updateCustomStore("isQueuing",{conversationID:a,value:-1})):e.src===f.CUSTOM_MESSAGE_SRC.GET_FEEDBACK_MENU&&l.updateCustomStore("feedbackTags",e.content.menu)))}})}async function ee(t){var e,a,o;if(!Pe.isCustomerConversation(b.value)){ge.Log.w(`Messages filtered as they are not customer service messages. currentConversationID: ${b.value}`);return}p==null||p.disconnect(),d.value=t.filter(r=>C.isThinkingMessage(r)?C.isThinkingMessageOverTime(r):C.isTransferMessageWithoutDesc(r)?!1:!r.isDeleted&&!C.isMessageInvisible(r)).map(r=>(r.vueForRenderKey=`${r.ID}`,r));const n=(a=d.value)==null?void 0:a[((e=d.value)==null?void 0:e.length)-1];y.value?te(y.value):!R.value&&!((o=E.value)!=null&&o.isScrollButtonVisible&&(n==null?void 0:n.flow)==="in")&&k(()=>{_()}),k(()=>x())}async function U(){var t;try{const{scrollHeight:n}=await s.P("#messageScrollList","messageList");n?v.value===n?v.value=n+1:v.value=n:_()}catch{_()}(t=E.value)==null||t.hideScrollButton(),x()}function ye(){x()}async function se(t){y.value=t,te(y.value)}function te(t){var n;(n=d.value)!=null&&n.some(e=>(e==null?void 0:e.ID)===(t==null?void 0:t.ID))&&k(async()=>{await De(t),await ae(t==null?void 0:t.ID),y.value=void 0})}function ne(t){A.value=t}const _e=()=>{var n,e;R.value=!0;const t=((e=(n=d.value)==null?void 0:n[0])==null?void 0:e.ID)||"";i.Yt.getMessageList().then(()=>{k(()=>{O.value=t;const a=setTimeout(()=>{O.value="",R.value=!1,clearTimeout(a)},500)})})},L=(t,n,e,a=!1)=>{a&&($.value=!0),D.value=n.ID};let F;const G=(t,n,e,a)=>{if(!P.isH5)return;function o(){clearTimeout(F),L(t,n,e,!0)}function r(){F=setTimeout(o,500)}function I(){clearTimeout(F)}switch(a){case"touchstart":r();break;case"touchend":I(),setTimeout(()=>{$.value=!1},50);break}},Ie=t=>{T("handleEditor",t,"reedit")},oe=t=>{S.value=!0,Y.value=t},ke=t=>{if(!d.value)return;const n=[],e=d.value.filter((a,o)=>!a.isRevoked&&!a.hasRiskContent&&a.type===c.value.MSG_IMAGE?(n.push(o),!0):!1);s.index.previewImage({current:n.indexOf(t),urls:e.map(a=>{var o;return(o=a.payload.imageInfoArray)==null?void 0:o[2].url})})},be=()=>{S.value=!S.value,Y.value.resendMessage()};function ae(t){return new Promise(n=>{if(h.value.indexOf(t)<0){h.value.push(t);const a=setTimeout(()=>{h.value.splice(h.value.indexOf(t),1),clearTimeout(a),n()},3e3)}})}function re(t){v.value=t}async function x(){!d.value||d.value.length===0||l.isEnabledMessageReadReceiptGlobal()&&(p&&p.disconnect(),p=s.index.createIntersectionObserver(q,{threshold:[.3],observeAll:!0}).relativeTo("#messageScrollList",{top:-70}),p&&p.observe(".message-li.in .message-bubble-container",t=>{if(Q.has(t.id)||t.intersectionRatio===0)return;const n=d.value.find(e=>t.id.indexOf(e.ID)>-1);if(n){const{needReadReceipt:e,readReceiptInfo:a,flow:o,ID:r,payload:I}=n;e&&o==="in"&&!a.isPeerRead&&(i.Yt.sendMessageReadReceipt([n]),Q.add(t.id),ge.Log.l(`Receipt sent. ID:${r} payload:${JSON.stringify(I)}`))}}))}async function De(t){const n=t.ID,e=d.value&&d.value.some(a=>a.ID===n);if(n&&e){const a=setTimeout(async()=>{try{const o=await s.T("#messageScrollList","messageList"),r=await s.T("#tui-"+n,"messageList"),{scrollTop:I}=await s.P("#messageScrollList","messageList"),Fe=r.top+I-o.top-Ce++%2;re(Fe),clearTimeout(a)}catch{}},500)}else xe.Toast({message:i.jt.t("TUIChat.无法定位到原消息"),type:Be.TOAST_TYPE.WARNING})}function Re(){D.value="",T("closeInputToolBar")}function Ee(t){H.value=t,j.value=!0}function Oe(t){M.value[t]=!0}function je(){O.value||R.value||_()}function we(){_()}function ue(){T("closeBottomQuickOrder")}function Ae(){if(!g.bottomQuickOrder)return;const t={...g.bottomQuickOrder,customField:(g.bottomQuickOrder.customField||[]).map(n=>({name:n.name?String(n.name):"",value:n.value?String(n.value):""}))};i.Yt.sendCustomMessage({to:b.value.replace("C2C",""),conversationType:"C2C",payload:{data:JSON.stringify({src:f.CUSTOM_MESSAGE_SRC.PRODUCT_CARD,content:t,customerServicePlugin:0})},needReadReceipt:l.isEnabledMessageReadReceiptGlobal()}),ue()}function Ue(t){m.value=t}function ce(t){T("like",t)}function ie(t){T("dislike",t)}function le(t){W.value=t}async function Le(){let e=pe.state.get("preloadedEmojiMap");e||(e=new Map,pe.state.set("preloadedEmojiMap",e));let a="";for(let o=0;o<=61;o++)if(a=`https://web.sdk.qcloud.com/im/assets/emoji-plugin/emoji_${o}@2x.png`,!e.has(o))try{const r=await s.index.request({url:a,responseType:"arraybuffer",timeout:1e4});r.statusCode===200&&e.set(o,"data:image/png;base64,"+s.index.arrayBufferToBase64(r.data))}catch{e.delete(o)}}return ve({scrollToLatestMessage:U,adjustHeightInTikTok:Ue}),(t,n)=>s.e$1({a:s.unref(d).length&&!s.unref(A)},s.unref(d).length&&!s.unref(A)?{b:s.t(s.unref(i.jt).t("TUIChat.查看更多")),c:s.o(_e)}:{},{d:s.f(s.unref(d),(e,a,o)=>s.e$1({a:"34c53318-0-"+o,b:s.p({currTime:e.time,prevTime:a>0?s.unref(d)[a-1].time:0}),c:!e.isRevoked&&!s.unref(w.isPluginMessage)(e)},!e.isRevoked&&!s.unref(w.isPluginMessage)(e)?s.e$1({d:s.unref(C.isThinkingMessage)(e)},s.unref(C.isThinkingMessage)(e)?{e:"34c53318-2-"+o+","+("34c53318-1-"+o)}:e.type===s.unref(c).MSG_TEXT?{g:"34c53318-3-"+o+","+("34c53318-1-"+o),h:s.p({content:e.getMessageContent(),flow:e.flow})}:e.type===s.unref(c).MSG_IMAGE?{j:s.o(r=>ke(a),e.vueForRenderKey),k:"34c53318-5-"+o+","+("34c53318-4-"+o),l:s.p({content:e.getMessageContent(),messageItem:e}),m:"34c53318-4-"+o+","+("34c53318-1-"+o),n:s.p({content:e.getMessageContent(),messageItem:s.unref(l.deepCopy)(e)})}:e.type===s.unref(c).MSG_VIDEO?{p:"34c53318-7-"+o+","+("34c53318-6-"+o),q:s.p({content:e.getMessageContent(),messageItem:e}),r:"34c53318-6-"+o+","+("34c53318-1-"+o),s:s.p({content:e.getMessageContent(),messageItem:s.unref(l.deepCopy)(e)})}:e.type===s.unref(c).MSG_AUDIO?{v:s.o(Oe,e.vueForRenderKey),w:s.o(Te,e.vueForRenderKey),x:"34c53318-8-"+o+","+("34c53318-1-"+o),y:s.p({content:e.getMessageContent(),messageItem:e,broadcastNewAudioSrc:s.unref(V)})}:e.type===s.unref(c).MSG_MERGER?{A:s.o(Ee,e.vueForRenderKey),B:"34c53318-9-"+o+","+("34c53318-1-"+o),C:s.p({renderData:e.payload,messageItem:e})}:e.type===s.unref(c).MSG_FILE?{E:"34c53318-10-"+o+","+("34c53318-1-"+o),F:s.p({content:e.getMessageContent()})}:e.type===s.unref(c).MSG_FACE?{H:"34c53318-11-"+o+","+("34c53318-1-"+o),I:s.p({content:e.getMessageContent()})}:e.type===s.unref(c).MSG_LOCATION?{K:"34c53318-12-"+o+","+("34c53318-1-"+o),L:s.p({content:e.getMessageContent()})}:e.type===s.unref(c).MSG_CUSTOM?{N:"34c53318-13-"+o+","+("34c53318-1-"+o),O:s.p({content:e.getMessageContent(),messageItem:e})}:{},{f:e.type===s.unref(c).MSG_TEXT,i:e.type===s.unref(c).MSG_IMAGE,o:e.type===s.unref(c).MSG_VIDEO,t:e.type===s.unref(c).MSG_AUDIO,z:e.type===s.unref(c).MSG_MERGER,D:e.type===s.unref(c).MSG_FILE,G:e.type===s.unref(c).MSG_FACE,J:e.type===s.unref(c).MSG_LOCATION,M:e.type===s.unref(c).MSG_CUSTOM,P:s.o(r=>oe(e),e.vueForRenderKey),Q:s.o(ae,e.vueForRenderKey),R:s.o(re,e.vueForRenderKey),S:s.o(r=>L(r,e,a,!0),e.vueForRenderKey),T:s.o(r=>G(r,e,a,"touchstart"),e.vueForRenderKey),U:s.o(r=>G(r,e,a,"touchend"),e.vueForRenderKey),V:s.o(ce,e.vueForRenderKey),W:s.o(ie,e.vueForRenderKey),X:"34c53318-1-"+o,Y:s.p({messageItem:s.unref(l.deepCopy)(e),content:e.getMessageContent(),isAudioPlayed:s.unref(M)[e.ID],blinkMessageIDList:s.unref(h),enableFeedback:g.enableFeedback,enableAINote:g.enableAINote}),Z:`msg-bubble-${e.ID}`}):!e.isRevoked&&s.unref(w.isPluginMessage)(e)?{ab:s.o(oe,e.vueForRenderKey),ac:s.o(L,e.vueForRenderKey),ad:s.o(G,e.vueForRenderKey),ae:s.o(je,e.vueForRenderKey),af:s.o(we,e.vueForRenderKey),ag:s.o(ce,e.vueForRenderKey),ah:s.o(ie,e.vueForRenderKey),ai:"34c53318-14-"+o,aj:s.p({message:s.unref(l.deepCopy)(e),blinkMessageIDList:s.unref(h),enableFeedback:g.enableFeedback,enableAINote:g.enableAINote})}:{ak:s.o(r=>Ie(e),e.vueForRenderKey),al:"34c53318-15-"+o,am:s.p({isEdit:e.type===s.unref(c).MSG_TEXT,messageItem:e})},{aa:!e.isRevoked&&s.unref(w.isPluginMessage)(e),an:e.ID===s.unref(D)},e.ID===s.unref(D)?{ao:e.flow==="out"?1:"",ap:e.flow==="in"?1:"",aq:"34c53318-16-"+o,ar:s.p({messageItem:e})}:{},{as:`tui-${e.ID}`,at:e.vueForRenderKey,av:s.n("message-li "+e.flow)})),e:s.unref(v),f:`tui-${s.unref(O)}`,g:s.o((...e)=>s.unref(z)&&s.unref(z)(...e)),h:s.sr(E,"34c53318-17",{k:"scrollButtonInstanceRef"}),i:s.o(U),j:s.o(ye),k:s.unref(S)},s.unref(S)?{l:s.t(s.unref(i.jt).t("TUIChat.确认重发该消息?")),m:s.o(e=>be()),n:s.o(e=>S.value=e),o:s.p({show:s.unref(S),isH5:!0,center:!0,isHeaderShow:!1})}:{},{p:s.o(e=>j.value=!1),q:s.p({isMounted:s.unref(j),messageID:s.unref(H)}),r:s.p({visible:s.unref(j),overlayColor:"transparent",popDirection:"right"}),s:s.unref(X)},s.unref(X)?{t:s.o(ue),v:s.o(Ae),w:s.p({bottomQuickOrder:g.bottomQuickOrder})}:{},{x:s.n(s.unref(he)),y:s.o(Re)})}}),is=s._export_sfc(cs,[["__scopeId","data-v-34c53318"]]);wx.createComponent(is); //# sourceMappingURL=../../../../../.sourcemap/mp-weixin/ai-desk-customer-uniapp/components/CustomerServiceChat/message-list/index-uniapp.js.map