"use strict";(self["webpackChunkautoshopee_kit"]=self["webpackChunkautoshopee_kit"]||[]).push([[1163],{71163:function(t,e,n){n.r(e),n.d(e,{default:function(){return m}});var r=function(){var t=this,e=t._self._c;return e("layout-single",{attrs:{"require-authed":"","require-paid":""}},[e("template",{slot:"header"},[e("h1",{staticClass:"text-warning"},[e("i",{staticClass:"fa fa-location-arrow",attrs:{"aria-hidden":"true"}}),e("span",{staticClass:"ml-5"},[t._v(t._s(t.$t("SHOPEE_AUTO_SEND_MESSAGE")))])])]),e("div",[e("div",[e("Row",[e("Col",{attrs:{span:16,offset:4}},[e("div",[t._v(" "+t._s(t.socketChat)+" ")]),e("div",{staticClass:"mt-10"},[t._v(" "+t._s(t.logChat)+" ")])])],1)],1)])],2)},s=[],a=(n(94826),n(16439));const o="wss://seller-push-ws.shopee.vn/socket.io/?region=vn&EIO=3&transport=websocket",i=t=>{try{const e=JSON.parse(t.replace(/^(\d*?)\[/,"["));return{event:e[0]||"",data:e[1]||{}}}catch(e){return{event:"",data:{}}}},c=async()=>{const{userId:t,token:e}=await(0,a.T)();return["420",JSON.stringify(["login",{token:e,account_id:`0-${t}`,app_id:"pmminichat"}])].join("")},u={intervalPing:5e3,sendLogin:2e3},d=async(t,e,n)=>{let r=null;const s=new WebSocket(o),a=()=>{s.send("2"),s.send(`42${JSON.stringify(["heartbeat","heart beat"])}`),s.send(`42${JSON.stringify(["heartbeat","pmminichat|0|0"])}`)},d=async()=>{const t=await c();return s.send(t)},l=e=>{let n=e.data;if(!n)return!1;if(n=n.trim(),!n||["3","2"].includes(n))return!1;if("40"===n)return setTimeout(d,u.sendLogin);const{event:r,data:s}=i(n);if(r&&"message"===r&&s.message_content){const e=JSON.parse(s.message_content);if(!e||!e.request_id)return!1;t&&t(e)}};return s.onopen=()=>{e&&e(s),r=setInterval(a,u.intervalPing)},s.onclose=()=>{n&&n("closed"),clearInterval(r)},s.onerror=t=>{n&&n(t),clearInterval(r)},s.onmessage=l,s};var l={name:"ShopeeAutoReplyReview",metaInfo(){return{title:this.$t("SHOPEE_AUTO_SEND_MESSAGE")}},data(){const t=[];return{socketChat:{timeConnected:null,timeDisConnected:null,connected:!1,disconnected:!1,error:null},logChat:t}},methods:{onNewMessage(t){console.error({chatData:t}),this.logChat.push(t)},startListenSocket(){d(this.onNewMessage,(()=>{this.socketChat.connected=!0,this.socketChat.timeConnected=new Date}),(t=>{this.socketChat.disconnected=!0,this.socketChat.timeDisConnected=new Date,this.socketChat.error=t}))}},created(){this.startListenSocket()}},h=l,p=n(1001),_=(0,p.Z)(h,r,s,!1,null,null,null),m=_.exports},94826:function(t,e,n){n.d(e,{b:function(){return c}});var r=n(28828),s=n(16158),a=n(55962);const o=a.Z.object({toUserId:a.Z.number().integer().required(),toShopId:a.Z.number().integer().required(),text:a.Z.string().required()});var i=n(16439);const c=async(t,e,n,a="")=>{await o.validateAsync({toUserId:t,toShopId:e,text:n});const c="/webchat/api/v1.2/mini/messages",u={to_id:t,shop_id:e,type:"text",content:{text:n,uid:(0,r.v4)()},request_id:(0,r.v4)(),chat_send_option:{force_send_cancel_order_warning:!1,comply_cancel_order_warning:!1},entry_point:"direct_chat_entry_point",choice_info:{real_shop_id:null},biz_id:0,source:"minichat"};a&&(u.conversation_id=a);const d=Date.now(),{userId:l,ctoken:h,authorization:p}=await(0,i.T)();if(!(l&&h&&p))throw"WEBCHAT_AUTH_ERROR";const{query:_,headers:m}=(0,i.$)({userId:l,ctoken:h,body:u,timestamp:d,authorization:p}),f={headers:m,params:_},v=await s.Uo.post(c,u,f);return v}},16439:function(t,e,n){n.d(e,{$:function(){return u},T:function(){return d}});var r=n(99552),s=n(53306),a=n.n(s),o=n(16158),i=n(50282);const c={userId:0,ctoken:"",authorization:"",token:""},u=({userId:t,ctoken:e,body:n,timestamp:s,authorization:o})=>{const i=1,c="396c15ad-6d3e-4018-98be-cef58cb45cd0",u="7.3.4",d="v1.2",l="sc",h={_uid:`0-${t}`,_v:u},p={fromID:t,plat:u,ver:d,reqID:n.request_id,toID:n.to_id,timestamp:s,type:n.type,strinput:"text"===n.type?n.content.text:""},_=r.Z.stringify({key:c,plat:p.plat,ver:p.ver,fromID:p.fromID,reqID:p.reqID,toID:p.toID,timestamp:p.timestamp,type:p.type,strinput:p.strinput},{sort:!1,encode:!1}),m={...h,_api_source:l,csrf_token:e},f={"x-v":i,"x-s":a().SHA256(_).toString(),ts:s,Authorization:`Bearer ${o}`};return{query:m,headers:f}},d=async()=>{if(!c.authorization){const t=await(0,i.jq)();c.authorization=t.token,c.token=t.p_token;const e=await(0,i.V_)();c.userId=e.id;const n=await(0,o.GX)();c.ctoken=n.find((t=>"CTOKEN"===t.name)).value}return c}}}]);
//# sourceMappingURL=1163.5d651ea0.js.map