a513f0fde363da8a196e738cbd3d971f82e727f7
[motion-next.git] / server / api / chatInteraction / chatInteraction.controller.js
1 const a66_0x1caa=['o.internal','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','i.id','mailTranscript','\x22%s\x22\x20<%s>','views','info','Contact.phone','format','setTags','nolimit','client','Messages','lastName','tail','`unreadMessages`\x20=\x200','secret','getMessages','select','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','SELECT','Mail\x20Transcript','ChatInteraction,\x20%s,\x20%s','html-pdf','limit','ChatMessage','me.ChatInteractionId\x20=\x20i.id','describe','i.id\x20LIKE\x20?','jayson/promise','user','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','i.ChatWebsiteId\x20IS\x20NOT\x20NULL','ContactId','status','order','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','$substring','sequelize','get','intersection','Contact.fax','vidaooApiKey','destroy','getFullTextValue','resolve','customerPort','$gte','basename','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','findOne','../../components/parsers/advancedSearch','tools_tags','server','text','sendStatus','../../config/logger','`unreadMessages`\x20>\x200','entity\x20not\x20found','rimraf','stack','closed','field','rawAttributes','./chatInteraction.socket','Contact.email','request\x20sent','YYYY-MM-DD\x20HH:mm:ss','include','Contact.mobile','unreadMessages','users','close','createdAt','c.mobile','now','groupBy','ChatInteractionId','json','merge','Tag','c.lastName','i.ChatWebsiteId\x20IN\x20?','follow','length','vidaooEscalation','type','where','YYYY-MM-DD','User','register','Account.mandatoryDisposition','40px','customer','sqlOperator','rows','pass','catch','files','auth','N.A.','createReadStream','CmContact','message','concat','POST','attachmentDownload','../../components/parsers/qs','result','keyBy','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','body','send','AbandonInteraction','journey','read','DESC','undefined','keys','some','transcript-%d-%s.zip','downloadInteraction.html','includeAll','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','isArray','tag','%s%d','addMessage','browserName','key','sendMail','[%s]\x20%s:\x20%s\x0a','Account.key','Owner.fullname','i.ChatWebsiteId\x20IS\x20NULL','offset','root','isEmpty','download','Contact.lastName','emit','path','firstName','appendFileSync','disposition','Chat','http','forEach','clone','Owner','%s\x20#%d','UserId','Interaction\x20already\x20assigned','show','omit','`\x20=\x200','https://api-vidaoo.xcally.com/api/v1/sessions','ChatWebsiteId','operator','unix','unlinkSync','having','util','Unauthorized','existsSync','removeTags','from','moment','end','findAll','Visitor','a.id\x20=\x20i.ChatWebsiteId','squel','referer','gte','it.ChatInteractionId\x20=\x20i.id','SendMail','fields','mkdirSync','../../rediscache','pathTranscript','pipe','debug','agentIdentifier','log','start','chat_interaction_has_tags','c.phone','name','filter','file','attributes','like','Smtp','c.fax','abandonInteraction,\x20%s,\x20%s,\x20%s','Tags','split','c.firstName','value','Contact','join','a.key','agent_alias','includeAgent','alias','i.*','port','color','customerIp','zip-dir','sort','fieldName','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','model','stringify','ui.ChatInteractionId','10px','parse','chat_websites','MailAccount','find','out','count','filename','secure','\x27\x27\x27\x27','closedAt','set','map','ids','renderFile','then','error','chatInteractionTags:save','transcript-','Error\x20in\x20Vidaoo\x20configuration','query','replace','createWriteStream','union','user_has_chat_interactions','30px','service','$lte','params','`\x20>\x200','getMyMessages','abandon','../../mysqldb','MM/DD/YYYY\x20HH:mm:ss','api','buildExpression','create','pick','fullname','ChatInteraction','\x20=\x20?','ui.ChatInteractionId\x20IN\x20?','push','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','Attachment','search','filters','server/files/chat/upload/','o.fullname','expr','../../config/environment','toString','left_join','chat_messages','Account','ChatWebsite','conditions','addTags','join_url','direction','agentAlias','System','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','u.id\x20=\x20ui.UserId','code','update','ejs','options','TagIds','chat_interactions'];(function(_0x1fdd70,_0x1caa49){const _0x5cf542=function(_0x566f4b){while(--_0x566f4b){_0x1fdd70['push'](_0x1fdd70['shift']());}};_0x5cf542(++_0x1caa49);}(a66_0x1caa,0x12b));const a66_0x5cf5=function(_0x1fdd70,_0x1caa49){_0x1fdd70=_0x1fdd70-0x0;let _0x5cf542=a66_0x1caa[_0x1fdd70];return _0x5cf542;};const _0x248663=a66_0x5cf5;'use strict';const pdf=require(_0x248663('0xb')),rimraf=require(_0x248663('0x2f')),zipdir=require(_0x248663('0xc6')),rp=require('request-promise-native'),moment=require(_0x248663('0x9b')),util=require(_0x248663('0x96')),path=require(_0x248663('0x81')),ejs=require(_0x248663('0x10f')),fs=require('fs'),_=require('lodash'),squel=require(_0x248663('0xa0')),{getSocket}=require(_0x248663('0xa7')),qs=require(_0x248663('0x5f')),as=require(_0x248663('0x27')),logger=require(_0x248663('0x2c'))(_0x248663('0xef')),config=require(_0x248663('0xff')),db=require(_0x248663('0xed'))['db'],{Op,ValidationError,QueryTypes}=require('sequelize'),socket=getSocket();require(_0x248663('0x34'))[_0x248663('0x4e')](socket);const jayson=require(_0x248663('0x11')),client=jayson[_0x248663('0x11e')][_0x248663('0x86')]({'port':0x232b}),client9004=jayson[_0x248663('0x11e')][_0x248663('0x86')]({'port':0x232c});function respondWithRpcPromise(_0x566f4b,_0x2013af,_0x362e27,_0x48a344){return new Promise(function(_0x43c56d,_0x3f0f05){const _0x2b25d1=a66_0x5cf5,_0x55b529=_0x48a344||client;return _0x55b529['request'](_0x566f4b,_0x362e27)[_0x2b25d1('0xdc')](function(_0x57b2ae){const _0x5b1492=_0x2b25d1;logger[_0x5b1492('0x119')](_0x5b1492('0xa'),_0x2013af,_0x5b1492('0x36')),logger[_0x5b1492('0xaa')]('ChatInteraction,\x20%s,\x20%s,\x20%s',_0x2013af,_0x5b1492('0x36'),JSON[_0x5b1492('0xcb')](_0x57b2ae));if(_0x57b2ae['error']){if(_0x57b2ae[_0x5b1492('0xdd')][_0x5b1492('0x10d')]===0x1f4)return logger[_0x5b1492('0xdd')](_0x5b1492('0xa'),_0x2013af,_0x57b2ae['error']['message']),_0x3f0f05(_0x57b2ae[_0x5b1492('0xdd')]['message']);return logger[_0x5b1492('0xdd')](_0x5b1492('0xa'),_0x2013af,_0x57b2ae[_0x5b1492('0xdd')][_0x5b1492('0x5b')]),_0x43c56d(_0x57b2ae[_0x5b1492('0xdd')][_0x5b1492('0x5b')]);}else logger[_0x5b1492('0x119')](_0x5b1492('0xa'),_0x2013af,'request\x20sent'),_0x43c56d(_0x57b2ae[_0x5b1492('0x60')][_0x5b1492('0x5b')]);})[_0x2b25d1('0x55')](function(_0x9a08ff){const _0x47e84d=_0x2b25d1;logger[_0x47e84d('0xdd')](_0x47e84d('0xa'),_0x2013af,_0x9a08ff),_0x3f0f05(_0x9a08ff);});});}function respondWithStatusCode(_0x39bff1,_0x14998d){return _0x14998d=_0x14998d||0xcc,function(_0x420847){const _0x553a6d=a66_0x5cf5;if(_0x420847)return _0x39bff1[_0x553a6d('0x2b')](_0x14998d);return _0x39bff1[_0x553a6d('0x16')](_0x14998d)[_0x553a6d('0x9c')]();};}function respondWithResult(_0x3d08d8,_0x272280){return _0x272280=_0x272280||0xc8,function(_0x3263b7){const _0x3698ec=a66_0x5cf5;if(_0x3263b7)return _0x3d08d8[_0x3698ec('0x16')](_0x272280)[_0x3698ec('0x42')](_0x3263b7);};}function respondWithFilteredResult(_0x524a91,_0x322bce){return function(_0x5e64ab){const _0x563fb5=a66_0x5cf5;if(_0x5e64ab){const _0x4e7940=_0x5e64ab[_0x563fb5('0xd3')],_0xaa21ed=_0x322bce[_0x563fb5('0x7b')];let _0x4a1783=_0x322bce[_0x563fb5('0x7b')]+_0x322bce[_0x563fb5('0xc')],_0xa297f1;return _0x4a1783>=_0x4e7940?(_0x4a1783=_0x4e7940,_0xa297f1=0xc8):_0xa297f1=0xce,_0x524a91[_0x563fb5('0x16')](_0xa297f1),_0x524a91[_0x563fb5('0xd8')]('Content-Range',_0xaa21ed+'-'+_0x4a1783+'/'+_0x4e7940)[_0x563fb5('0x42')](_0x5e64ab);}return null;};}function saveUpdates(_0xe57c9e){return function(_0x5932fd){const _0x42ebb8=a66_0x5cf5;if(_0x5932fd)return _0x5932fd[_0x42ebb8('0x10e')](_0xe57c9e)[_0x42ebb8('0xdc')](function(_0x4b2f66){return _0x4b2f66;});return null;};}function removeEntity(_0xe3e643){return function(_0x3c3fbc){const _0x2d0761=a66_0x5cf5;if(_0x3c3fbc)return _0x3c3fbc[_0x2d0761('0x1f')]()[_0x2d0761('0xdc')](function(){const _0x3a5922=_0x2d0761;_0xe3e643[_0x3a5922('0x16')](0xcc)['end']();});};}function handleEntityNotFound(_0x513e6c){return function(_0x9062ea){const _0x50fb42=a66_0x5cf5;return!_0x9062ea&&_0x513e6c[_0x50fb42('0x2b')](0x194),_0x9062ea;};}function handleError(_0x5e70b6,_0x1206e2){return _0x1206e2=_0x1206e2||0x1f4,function(_0x46c270){const _0x50e567=a66_0x5cf5;logger[_0x50e567('0xdd')](_0x46c270[_0x50e567('0x30')]),_0x46c270['name']&&delete _0x46c270[_0x50e567('0xb0')],_0x5e70b6['status'](_0x1206e2)[_0x50e567('0x64')](_0x46c270);};}function getInteractionUsers(_0x1521e8,_0x164683){return new Promise(function(_0x144e87,_0x4d4b3c){const _0x3e8659=a66_0x5cf5;try{_0x164683[_0x1521e8['id']]&&(_0x1521e8['Users']=_[_0x3e8659('0xd9')](_0x164683[_0x1521e8['id']],function(_0xa0755d){const _0x33afb4=_0x3e8659;return{'id':_0xa0755d['id'],'fullname':_0xa0755d[_0x33afb4('0xf3')]};}));}catch(_0x112897){_0x4d4b3c(_0x112897);}_0x144e87(_0x1521e8);});}function getInteractionTags(_0x139aac,_0x54a7b1){return new Promise(function(_0x193136,_0x35cd38){const _0x3fda29=a66_0x5cf5;try{_0x139aac[_0x3fda29('0x111')]&&(_0x139aac[_0x3fda29('0xb8')]=[],_0x139aac[_0x3fda29('0x111')][_0x3fda29('0xb9')](',')['forEach'](function(_0x2cccc4){const _0x3e7891=_0x3fda29;_0x139aac['Tags'][_0x3e7891('0xf7')](_0x54a7b1[_0x2cccc4]);})),delete _0x139aac['TagIds'];}catch(_0x1184a9){_0x35cd38(_0x1184a9);}_0x193136(_0x139aac);});}function updateChatInteraction(_0x2ddf05,_0x9752a6,_0xccdd4e){return new Promise(function(_0x475f85,_0x15b48b){const _0x475995=a66_0x5cf5;return getInteractionUsers(_0x2ddf05,_0xccdd4e)[_0x475995('0xdc')](function(_0x26c47c){return getInteractionTags(_0x26c47c,_0x9752a6);})[_0x475995('0xdc')](function(_0x37ba3a){_0x475f85(_0x37ba3a);})[_0x475995('0x55')](function(_0xb6e5d1){_0x15b48b(_0xb6e5d1);});});}exports['index']=function(_0x48e275,_0x3aad82){const _0x16b974=_0x248663,_0x2ace98={},_0x149ed1={},_0x1eeff7={'count':0x0,'rows':[]},_0x2ac9f1=_['map'](db[_0x16b974('0xf4')][_0x16b974('0x33')],function(_0x3554ea){const _0x17ccde=_0x16b974;return{'name':_0x3554ea[_0x17ccde('0xc8')],'type':_0x3554ea['type'][_0x17ccde('0x75')]};});_0x149ed1[_0x16b974('0xca')]=_[_0x16b974('0xd9')](_0x2ac9f1,_0x16b974('0xb0')),_0x149ed1[_0x16b974('0xe1')]=_[_0x16b974('0x6a')](_0x48e275[_0x16b974('0xe1')]),_0x149ed1['filters']=_[_0x16b974('0x1c')](_0x149ed1['model'],_0x149ed1[_0x16b974('0xe1')]),_0x2ace98[_0x16b974('0xb3')]=_[_0x16b974('0x1c')](_0x149ed1['model'],qs[_0x16b974('0xa5')](_0x48e275[_0x16b974('0xe1')][_0x16b974('0xa5')])),_0x2ace98['attributes']=_0x2ace98[_0x16b974('0xb3')]['length']?_0x2ace98[_0x16b974('0xb3')]:_0x149ed1['model'];typeof _0x48e275[_0x16b974('0xe1')][_0x16b974('0x11d')]===_0x16b974('0x69')&&(_0x2ace98[_0x16b974('0xc')]=qs[_0x16b974('0xc')](_0x48e275[_0x16b974('0xe1')][_0x16b974('0xc')]),_0x2ace98[_0x16b974('0x7b')]=qs[_0x16b974('0x7b')](_0x48e275[_0x16b974('0xe1')]['offset']));_0x2ace98[_0x16b974('0x17')]=qs[_0x16b974('0xc7')](_0x48e275[_0x16b974('0xe1')][_0x16b974('0xc7')]),_0x2ace98[_0x16b974('0x4b')]=qs['filters'](_[_0x16b974('0xf2')](_0x48e275['query'],_0x149ed1[_0x16b974('0xfb')]),_0x2ac9f1);let _0xf88e5e=[];const _0x46199f=squel['select']()[_0x16b974('0x32')]('id')[_0x16b974('0x32')](_0x16b974('0xb0'))[_0x16b974('0x32')](_0x16b974('0xc4'))[_0x16b974('0x9a')](_0x16b974('0x28')),_0x29dce7=squel[_0x16b974('0x6')]()[_0x16b974('0x32')]('u.id')[_0x16b974('0x32')]('u.fullname')[_0x16b974('0x32')](_0x16b974('0xcc'))[_0x16b974('0x9a')](_0x16b974('0xe5'),'ui')[_0x16b974('0x101')](_0x16b974('0x3b'),'u',_0x16b974('0x10c')),_0x327e9c=squel[_0x16b974('0x6')]()['from'](_0x16b974('0x112'),'i')[_0x16b974('0x101')]('cm_contacts','c',_0x16b974('0x10b'))[_0x16b974('0x101')](_0x16b974('0x3b'),'o','o.id\x20=\x20i.UserId')[_0x16b974('0x101')](_0x16b974('0xcf'),'a',_0x16b974('0x9f'))[_0x16b974('0x101')](_0x16b974('0x102'),'me',_0x16b974('0xe'))[_0x16b974('0x101')](_0x16b974('0xae'),'it',_0x16b974('0xa3'))[_0x16b974('0x101')](_0x16b974('0x28'),'t','t.id\x20=\x20it.TagId'),_0x2d28e9=squel[_0x16b974('0xfe')]();let _0x368041=[];const _0x12cd68=squel[_0x16b974('0xfe')]();let _0x55542f;if(_0x48e275[_0x16b974('0xe1')][_0x16b974('0xfa')]){_0x55542f=as['parseSearch'](_0x48e275[_0x16b974('0xe1')][_0x16b974('0xfa')]);const _0x548f6a=_0x55542f[_0x16b974('0x52')];for(let _0x46daa0=0x0;_0x46daa0<_0x55542f[_0x16b974('0x105')][_0x16b974('0x48')];_0x46daa0++){const _0x826fc5=_0x55542f[_0x16b974('0x105')][_0x46daa0],_0x3b728d='i';let _0xc1b341,_0x2d5254=_[_0x16b974('0xd1')](_0x2ac9f1,[_0x16b974('0xb0'),_0x826fc5[_0x16b974('0x32')]]);if(!_0x2d5254)switch(_0x826fc5['field']){case _0x16b974('0x3a'):_0x826fc5[_0x16b974('0xbb')]==0x1?_0x327e9c[_0x16b974('0x95')]('`'+_0x826fc5[_0x16b974('0x32')]+_0x16b974('0x8f')):_0x327e9c[_0x16b974('0x95')]('`'+_0x826fc5[_0x16b974('0x32')]+_0x16b974('0xea'));break;case _0x16b974('0xbc'):if(_0x826fc5[_0x16b974('0x92')]===_0x16b974('0x19')){if(_0x826fc5['value'][_0x16b974('0xb9')]('\x20')['length']>0x1)_0x2d28e9[_0x548f6a](_0x16b974('0x62'),qs[_0x16b974('0x20')](_0x826fc5['value']),null);else{const _0x5d0f44='%'+_0x826fc5[_0x16b974('0xbb')]+'%';_0x2d28e9[_0x548f6a](_0x16b974('0x13'),_0x5d0f44,_0x5d0f44,_0x5d0f44);}}else _0x2d5254=_[_0x16b974('0xd1')](_0x2ac9f1,[_0x16b974('0xb0'),'ContactId']),_0x826fc5['field']=_0x16b974('0x15'),_0xc1b341=as[_0x16b974('0xf0')](_0x3b728d,_0x2d5254['type'],_0x826fc5),_0x2d28e9[_0x548f6a](_0xc1b341[_0x16b974('0x2a')],_0xc1b341[_0x16b974('0xbb')]['start'],_0xc1b341[_0x16b974('0xbb')]['end']);break;case'Tag':{const _0x393f41=_0x826fc5[_0x16b974('0xbb')][_0x16b974('0xb9')](',')[_0x16b974('0xd9')](function(_0x1087d3){return Number(_0x1087d3);});_0x393f41['forEach'](function(_0x238c26){_0x12cd68['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x238c26+',%');}),_0x368041=_[_0x16b974('0xe4')](_0x368041,_0x393f41);}break;case'User':_0x826fc5[_0x16b974('0x92')]===_0x16b974('0x19')?_0x2d28e9[_0x548f6a](_0x16b974('0x6f'),'%'+_0x826fc5['value']+'%',null):(_0x2d5254=_[_0x16b974('0xd1')](_0x2ac9f1,[_0x16b974('0xb0'),_0x16b974('0x8b')]),_0x826fc5['field']=_0x16b974('0x8b'),_0xc1b341=as[_0x16b974('0xf0')](_0x3b728d,_0x2d5254['type'],_0x826fc5),_0x2d28e9[_0x548f6a](_0xc1b341[_0x16b974('0x2a')],_0xc1b341['value'][_0x16b974('0xad')],_0xc1b341[_0x16b974('0xbb')][_0x16b974('0x9c')]));break;case _0x16b974('0x63'):_0xc1b341=as['buildExpression']('me',null,_0x826fc5),_0x2d28e9[_0x548f6a](_0xc1b341[_0x16b974('0x2a')],_0xc1b341[_0x16b974('0xbb')][_0x16b974('0xad')],_0xc1b341[_0x16b974('0xbb')][_0x16b974('0x9c')]);break;}else _0xc1b341=as[_0x16b974('0xf0')](_0x3b728d,_0x2d5254[_0x16b974('0x4a')],_0x826fc5),_0x2d28e9[_0x548f6a](_0xc1b341[_0x16b974('0x2a')],_0xc1b341[_0x16b974('0xbb')]['start'],_0xc1b341[_0x16b974('0xbb')][_0x16b974('0x9c')]);}}else{const _0x3ec41d=_(_0x48e275[_0x16b974('0xe1')])['keys']()[_0x16b974('0xd9')](function(_0x120713){const _0x5814f5=_0x16b974;return _[_0x5814f5('0x6b')](_0x2ac9f1,[_0x5814f5('0xb0'),_0x120713])?_0x120713:undefined;})['compact']()[_0x16b974('0xbb')]();!_[_0x16b974('0x7d')](_0x3ec41d)&&_0x3ec41d[_0x16b974('0x87')](function(_0x3579d9){const _0x4da81f=_0x16b974;if(_0x3579d9===_0x4da81f('0x91'))_0x327e9c[_0x4da81f('0x4b')](_0x4da81f('0x46'),[][_0x4da81f('0x5c')](_0x48e275['query'][_0x3579d9]));else{if(_0x3579d9===_0x4da81f('0x3d')){const _0x142e4c=JSON[_0x4da81f('0xce')](_0x48e275['query'][_0x3579d9])[_0x4da81f('0x23')],_0x25c798=JSON[_0x4da81f('0xce')](_0x48e275[_0x4da81f('0xe1')][_0x3579d9])[_0x4da81f('0xe8')];_0x327e9c[_0x4da81f('0x4b')](_0x4da81f('0x114'),_0x142e4c,_0x25c798);}else _0x48e275['query'][_0x3579d9]==='null'?_0x327e9c[_0x4da81f('0x4b')]('i.'+_0x3579d9+'\x20IS\x20NULL'):_0x327e9c[_0x4da81f('0x4b')]('i.'+_0x3579d9+_0x4da81f('0xf5'),_0x48e275[_0x4da81f('0xe1')][_0x3579d9]);}});_0x48e275[_0x16b974('0xe1')][_0x16b974('0x67')]&&(_0x48e275[_0x16b974('0xe1')][_0x16b974('0x67')]==0x1?_0x327e9c[_0x16b974('0x95')](_0x16b974('0x3')):_0x327e9c[_0x16b974('0x95')](_0x16b974('0x2d')));_0x48e275['query'][_0x16b974('0x71')]&&(_0x368041=_[_0x16b974('0x70')](_0x48e275['query'][_0x16b974('0x71')])?_0x48e275[_0x16b974('0xe1')][_0x16b974('0x71')]:new Array(_0x48e275['query'][_0x16b974('0x71')]),_0x368041[_0x16b974('0x87')](function(_0x1be791){const _0x4ea815=_0x16b974;_0x12cd68['or'](_0x4ea815('0x25'),'%,'+_0x1be791+',%');}));if(_0x48e275[_0x16b974('0xe1')][_0x16b974('0xb1')]){const _0x5f421c=_0x48e275['query'][_0x16b974('0xb1')]['replace']('\x5c','\x5c\x5c')[_0x16b974('0xe2')]('\x27\x27',_0x16b974('0xd6'));qs['isNumeric'](_0x5f421c)?_0x2d28e9['or'](_0x16b974('0x10'),_0x5f421c+'%'):_0x2d28e9['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x5f421c))['or'](_0x16b974('0xf8'),_0x5f421c+'%');}}_0x327e9c['where'](_0x2d28e9),_0x327e9c['group'](_0x16b974('0x115'));let _0x202020={'type':QueryTypes[_0x16b974('0x8')],'raw':!![]};const _0xe43d5c=_0x327e9c[_0x16b974('0x88')]();_0xe43d5c[_0x16b974('0x32')]('i.id'),_0xe43d5c[_0x16b974('0x32')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x16b974('0x3a')),_0x2ace98[_0x16b974('0x17')]&&_0x2ace98['order'][_0x16b974('0x87')](function(_0x3830b9){const _0x42ca6a=_0x16b974;_0x327e9c[_0x42ca6a('0x17')]('i.'+_0x3830b9[0x0],_0x3830b9[0x1]===_0x42ca6a('0x68')?![]:!![]);}),!_['isEmpty'](_0x368041)&&(_0x327e9c[_0x16b974('0x95')](_0x12cd68),_0xe43d5c[_0x16b974('0x4b')]('t.id\x20IN\x20?',_0x368041)),Promise[_0x16b974('0x21')]()['then'](function(){const _0x305236=_0x16b974;if(!_0x55542f){if(_0x48e275[_0x305236('0xe1')]['ChatWebsiteId']||_0x48e275['query'][_0x305236('0x66')])return;_0xe43d5c[_0x305236('0x4b')](_0x305236('0x14')),_0x327e9c[_0x305236('0x4b')](_0x305236('0x14'));return;}return _0x48e275[_0x305236('0x12')]['getChatWebsites']({'attributes':['id'],'raw':!![]})[_0x305236('0xdc')](function(_0x58343c){const _0x458e69=_0x305236;_[_0x458e69('0x7d')](_0x58343c)?(_0xe43d5c[_0x458e69('0x4b')](_0x458e69('0x7a')),_0x327e9c[_0x458e69('0x4b')](_0x458e69('0x7a'))):(_0xe43d5c['where'](_0x458e69('0x46'),_[_0x458e69('0xd9')](_0x58343c,'id')),_0x327e9c[_0x458e69('0x4b')]('i.ChatWebsiteId\x20IN\x20?',_[_0x458e69('0xd9')](_0x58343c,'id')));});})[_0x16b974('0xdc')](function(){const _0x131808=_0x16b974;db[_0x131808('0x1a')][_0x131808('0xe1')](_0xe43d5c[_0x131808('0x100')](),_0x202020)[_0x131808('0xdc')](function(_0x30204){const _0x3be32b=_0x131808;_0x1eeff7['count']=_0x30204['length'];if(_0x1eeff7['count']===0x0)return[];return db[_0x3be32b('0x1a')][_0x3be32b('0xe1')](_0x46199f[_0x3be32b('0x100')](),_0x202020)[_0x3be32b('0xdc')](function(_0x1010a8){const _0x5bc824=_0x3be32b;_0xf88e5e=_[_0x5bc824('0x61')](_0x1010a8,'id'),_0x202020=_[_0x5bc824('0x43')](_0x202020,{'model':db[_0x5bc824('0xf4')],'mapToModel':!![],'raw':!![],'nest':!![]});_0x48e275[_0x5bc824('0xe1')][_0x5bc824('0xa5')]?_0x2ace98[_0x5bc824('0xb3')][_0x5bc824('0x87')](function(_0x166d5e){const _0x2e8701=_0x5bc824;_0x327e9c[_0x2e8701('0x32')]('i.'+_0x166d5e);}):(_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0x18'),_0x5bc824('0x3a')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0xbe'),_0x5bc824('0x78')),_0x327e9c['field']('a.mandatoryDisposition',_0x5bc824('0x4f')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0xc2')),_0x327e9c['field'](_0x5bc824('0xba'),'Contact.firstName'),_0x327e9c['field'](_0x5bc824('0x45'),_0x5bc824('0x7f')),_0x327e9c[_0x5bc824('0x32')]('c.email',_0x5bc824('0x35')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0xaf'),_0x5bc824('0x11a')),_0x327e9c['field'](_0x5bc824('0x3e'),_0x5bc824('0x39')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0xb6'),_0x5bc824('0x1d')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0xfd'),_0x5bc824('0x79')),_0x327e9c[_0x5bc824('0x32')](_0x5bc824('0x113'),'Owner.internal'),_0x327e9c['field']('GROUP_CONCAT(DISTINCT\x20t.id)',_0x5bc824('0x111')));if(_0x2ace98['limit'])_0x327e9c[_0x5bc824('0xc')](_0x2ace98[_0x5bc824('0xc')]);if(_0x2ace98[_0x5bc824('0x7b')])_0x327e9c[_0x5bc824('0x7b')](_0x2ace98['offset']);return db[_0x5bc824('0x1a')][_0x5bc824('0xe1')](_0x327e9c[_0x5bc824('0x100')](),_0x202020);})[_0x3be32b('0xdc')](function(_0x2e3084){const _0x1b13c5=_0x3be32b;return _0x29dce7['where'](_0x1b13c5('0xf6'),_[_0x1b13c5('0xd9')](_0x2e3084,'id')),db[_0x1b13c5('0x1a')][_0x1b13c5('0xe1')](_0x29dce7[_0x1b13c5('0x100')](),_0x202020)[_0x1b13c5('0xdc')](function(_0x205f12){const _0x28352f=_0x1b13c5,_0x4ffc8e=_[_0x28352f('0x40')](_0x205f12,_0x28352f('0x41')),_0x4fc141=[];return _0x2e3084[_0x28352f('0x87')](function(_0x1c922e){_0x4fc141['push'](updateChatInteraction(_0x1c922e,_0xf88e5e,_0x4ffc8e));}),Promise['all'](_0x4fc141);});});})[_0x131808('0xdc')](function(_0x52711e){const _0x121df9=_0x131808;return _0x1eeff7[_0x121df9('0x53')]=_0x52711e,_0x1eeff7;})['then'](respondWithFilteredResult(_0x3aad82,_0x2ace98));})[_0x16b974('0x55')](handleError(_0x3aad82,null));},exports[_0x248663('0x8d')]=function(_0x1fc17d,_0x576d5d){const _0x240841=_0x248663;let _0x3ddda8={'raw':![],'where':{'id':_0x1fc17d[_0x240841('0xe9')]['id']}};const _0x35aa60={};return _0x35aa60[_0x240841('0xca')]=_[_0x240841('0x6a')](db[_0x240841('0xf4')][_0x240841('0x33')]),_0x35aa60[_0x240841('0xe1')]=_[_0x240841('0x6a')](_0x1fc17d[_0x240841('0xe1')]),_0x35aa60[_0x240841('0xfb')]=_[_0x240841('0x1c')](_0x35aa60[_0x240841('0xca')],_0x35aa60[_0x240841('0xe1')]),_0x3ddda8[_0x240841('0xb3')]=_[_0x240841('0x1c')](_0x35aa60[_0x240841('0xca')],qs[_0x240841('0xa5')](_0x1fc17d[_0x240841('0xe1')][_0x240841('0xa5')])),_0x3ddda8[_0x240841('0xb3')]=_0x3ddda8['attributes'][_0x240841('0x48')]?_0x3ddda8['attributes']:_0x35aa60['model'],_0x1fc17d[_0x240841('0xe1')][_0x240841('0x6e')]&&(_0x3ddda8[_0x240841('0x38')]=[{'all':!![]}]),_0x3ddda8=_[_0x240841('0x43')]({},_0x3ddda8,_0x1fc17d[_0x240841('0x110')]),db[_0x240841('0xf4')]['findOne'](_0x3ddda8)[_0x240841('0xdc')](handleEntityNotFound(_0x576d5d,null))['then'](respondWithResult(_0x576d5d,null))[_0x240841('0x55')](handleError(_0x576d5d,null));},exports[_0x248663('0xf1')]=function(_0x4ddb00,_0x429286){const _0x2d7228=_0x248663;return db[_0x2d7228('0xf4')][_0x2d7228('0xf1')](_0x4ddb00[_0x2d7228('0x63')],{})[_0x2d7228('0xdc')](respondWithResult(_0x429286,0xc9))[_0x2d7228('0x55')](handleError(_0x429286,null));},exports[_0x248663('0x10e')]=function(_0x5d5eed,_0x58c619){const _0xd527da=_0x248663;return _0x5d5eed[_0xd527da('0x63')]['id']&&delete _0x5d5eed['body']['id'],db[_0xd527da('0xf4')]['findOne']({'where':{'id':_0x5d5eed[_0xd527da('0xe9')]['id']}})['then'](handleEntityNotFound(_0x58c619,null))[_0xd527da('0xdc')](saveUpdates(_0x5d5eed['body'],null))[_0xd527da('0xdc')](respondWithResult(_0x58c619,null))[_0xd527da('0x55')](handleError(_0x58c619,null));},exports[_0x248663('0x1f')]=function(_0x36340b,_0x2038b5){const _0x506472=_0x248663;return db[_0x506472('0xf4')][_0x506472('0x26')]({'where':{'id':_0x36340b['params']['id']}})[_0x506472('0xdc')](handleEntityNotFound(_0x2038b5,null))[_0x506472('0xdc')](removeEntity(_0x2038b5,null))['catch'](handleError(_0x2038b5,null));},exports[_0x248663('0xf')]=function(_0x1128e1,_0x1784d3){const _0x547d41=_0x248663;return db[_0x547d41('0xf4')][_0x547d41('0xf')]()[_0x547d41('0xdc')](respondWithResult(_0x1784d3,null))[_0x547d41('0x55')](handleError(_0x1784d3,null));},exports['createVidaooSession']=function(_0x41898c,_0x4da823){const _0x700405=_0x248663,_0xec8899=_0x41898c[_0x700405('0xe9')]['id'];let _0x536f8b,_0x1a7368,_0x49d643;return db[_0x700405('0xf4')][_0x700405('0x26')]({'where':{'id':_0xec8899}})['then'](function(_0x2176b0){const _0x1a7108=_0x700405;return _0x536f8b=_0x2176b0,db[_0x1a7108('0x104')][_0x1a7108('0x26')]({'where':{'id':_0x2176b0['ChatWebsiteId']},'attributes':['id',_0x1a7108('0x1e'),'vidaooEscalation'],'raw':!![]});})['then'](function(_0x47b62d){const _0x449c98=_0x700405;if(_0x47b62d&&_0x47b62d[_0x449c98('0x1e')]&&_0x47b62d[_0x449c98('0x49')]){_0x1a7368=_0x47b62d;const _0x3ac907={'rejectUnauthorized':![],'method':_0x449c98('0x5d'),'uri':_0x449c98('0x90'),'headers':{'X-APIKEY':_0x47b62d[_0x449c98('0x1e')]},'body':{'name':'MotionCWB:'+_0xec8899},'redirect':_0x449c98('0x47'),'json':!![]};return rp(_0x3ac907);}else throw new ValidationError(_0x449c98('0xe0'));})[_0x700405('0xdc')](function(_0x4a7b9b){const _0x273ec8=_0x700405;_0x49d643=_0x4a7b9b;if(_0x49d643['id']){const _0x58c438={'body':_0x49d643[_0x273ec8('0x107')],'ChatWebsiteId':_0x1a7368['id'],'ChatInteractionId':_0x536f8b['id'],'direction':_0x273ec8('0xd2'),'UserId':_0x41898c[_0x273ec8('0x12')]['id']};return db[_0x273ec8('0xd')][_0x273ec8('0xf1')](_0x58c438,{});}else throw new ValidationError('Unable\x20to\x20create\x20Vidaoo\x20session');})[_0x700405('0xdc')](function(){const _0x4249be=_0x700405;return _0x536f8b[_0x4249be('0x10e')]({'vidaooSessionId':_0x49d643['id']});})[_0x700405('0xdc')](respondWithResult(_0x4da823,null))[_0x700405('0x55')](handleError(_0x4da823,null));},exports['customUpdate']=function(_0x2cc5e7,_0x2cb445){const _0xe8834a=_0x248663;return _0x2cc5e7[_0xe8834a('0x63')]['id']&&delete _0x2cc5e7[_0xe8834a('0x63')]['id'],db[_0xe8834a('0xf4')][_0xe8834a('0x26')]({'where':{'id':_0x2cc5e7[_0xe8834a('0xe9')]['id']}})[_0xe8834a('0xdc')](handleEntityNotFound(_0x2cb445,null))[_0xe8834a('0xdc')](saveUpdates(_0x2cc5e7[_0xe8834a('0x63')],null))[_0xe8834a('0xdc')](respondWithResult(_0x2cb445,null))[_0xe8834a('0x55')](handleError(_0x2cb445,null));},exports[_0x248663('0xec')]=function(_0x139291,_0x20e892){const _0x247f45=_0x248663;return _0x139291[_0x247f45('0x63')]['id']&&delete _0x139291['body']['id'],db[_0x247f45('0xf4')][_0x247f45('0x26')]({'where':{'id':_0x139291[_0x247f45('0xe9')]['id']}})[_0x247f45('0xdc')](function(_0x145a71){const _0xb99d64=_0x247f45;if(!_0x145a71)logger['error'](_0xb99d64('0xb7'),_0xb99d64('0xec'),0x194,_0xb99d64('0x2e')),_0x20e892['sendStatus'](0x194);else{if(_0x145a71['UserId'])throw new ValidationError(_0xb99d64('0x8c'));}return _0x145a71;})['then'](function(_0x368be4){const _0x215a8a=_0x247f45;if(_0x368be4)return _0x368be4[_0x215a8a('0x10e')]({'closed':_0x139291[_0x215a8a('0x63')][_0x215a8a('0x31')],'disposition':_0x139291['body'][_0x215a8a('0x84')]})[_0x215a8a('0xdc')](function(_0x54f878){return _0x54f878;});})[_0x247f45('0xdc')](function(){const _0x1ffc74=_0x247f45;return respondWithRpcPromise(_0x1ffc74('0x65'),_0x1ffc74('0xec'),_0x139291['body'],client9004);})[_0x247f45('0xdc')](respondWithResult(_0x20e892,null))[_0x247f45('0x55')](handleError(_0x20e892,null));},exports['attachmentUpload']=function(_0xbb2900,_0x36ff31){const _0x392062=_0x248663;return _0xbb2900[_0x392062('0x63')][_0x392062('0xb0')]=_0xbb2900[_0x392062('0xb2')]['originalname'],_0xbb2900['body'][_0x392062('0x24')]=_0xbb2900['file'][_0x392062('0xd4')],_0xbb2900[_0x392062('0x63')][_0x392062('0x4a')]=_0xbb2900[_0x392062('0xb2')]['mimetype'],db[_0x392062('0xf9')][_0x392062('0xf1')](_0xbb2900[_0x392062('0x63')])[_0x392062('0xdc')](respondWithResult(_0x36ff31,0xc9))[_0x392062('0x55')](handleError(_0x36ff31,null));},exports[_0x248663('0x5e')]=function(_0x4c7bec,_0x1a0cd9){const _0x1c96d2=_0x248663;return db[_0x1c96d2('0xf4')][_0x1c96d2('0x26')]({'where':{'id':_0x4c7bec['params']['id']},'raw':!![]})[_0x1c96d2('0xdc')](handleEntityNotFound(_0x1a0cd9,null))['then'](function(_0x71a19f){const _0x32ae7e=_0x1c96d2;if(_0x71a19f){if(_0x71a19f[_0x32ae7e('0x31')])return _0x1a0cd9[_0x32ae7e('0x16')](0x193)[_0x32ae7e('0x42')]({'status':0x193,'message':_0x32ae7e('0x97')});return db['Attachment'][_0x32ae7e('0x26')]({'where':{'id':_0x4c7bec[_0x32ae7e('0xe1')]['attachId']},'raw':!![]})['then'](handleEntityNotFound(_0x1a0cd9,null));}})[_0x1c96d2('0xdc')](function(_0x56e65d){const _0x2448fa=_0x1c96d2;if(_0x56e65d)return _0x1a0cd9[_0x2448fa('0x7e')](path[_0x2448fa('0xbd')](config[_0x2448fa('0x7c')],'files/attachments/',_0x56e65d[_0x2448fa('0x24')]));})[_0x1c96d2('0x55')](handleError(_0x1a0cd9,null));},exports[_0x248663('0x3c')]=function(_0x432f88,_0x54a92d){const _0x118098=_0x248663;let _0xbedce0=null,_0x24a1c0=null,_0x3c1424=null;return _0x432f88[_0x118098('0x63')]['id']&&delete _0x432f88['body']['id'],_0x432f88[_0x118098('0x63')][_0x118098('0x116')]&&(_0x3c1424=path[_0x118098('0xbd')](config[_0x118098('0x7c')],_0x118098('0xfc'),util[_0x118098('0x11b')]('transcript-%s.txt',Date[_0x118098('0x3f')]())),_0x432f88[_0x118098('0x63')][_0x118098('0xa8')]=_0x3c1424),db[_0x118098('0xf4')][_0x118098('0x26')]({'where':{'id':_0x432f88[_0x118098('0xe9')]['id']},'include':[{'model':db[_0x118098('0xd')],'as':_0x118098('0x0'),'include':[{'model':db[_0x118098('0x4d')],'as':_0x118098('0x4d')}]}]})[_0x118098('0xdc')](handleEntityNotFound(_0x54a92d,null))[_0x118098('0xdc')](saveUpdates(_0x432f88['body'],null))[_0x118098('0xdc')](function(_0x45347e){const _0x2efae1=_0x118098;if(_0x45347e)return _0xbedce0=_0x45347e,db[_0x2efae1('0x104')]['findOne']({'where':{'id':_0xbedce0[_0x2efae1('0x91')]}});})[_0x118098('0xdc')](function(_0x1419dd){const _0xe72f43=_0x118098;if(_0x1419dd)return _0x24a1c0=_0x1419dd,db[_0xe72f43('0x5a')]['findOne']({'where':{'id':_0xbedce0[_0xe72f43('0x15')]}});})[_0x118098('0xdc')](function(_0x489f40){const _0x427a81=_0x118098;if(_0x489f40){if(_0x3c1424){let _0x210e1a=null;for(let _0x5103c6=0x1;_0x5103c6<_0xbedce0[_0x427a81('0x0')]['length'];++_0x5103c6){_0x210e1a=_0xbedce0[_0x427a81('0x0')][_0x5103c6];let _0x5335e5=_0x210e1a[_0x427a81('0x8b')]?util[_0x427a81('0x11b')](_0x427a81('0x72'),_0x24a1c0[_0x427a81('0x109')],_0x210e1a['UserId']):_0x427a81('0x10a');const _0x537f6d=_0x432f88[_0x427a81('0x63')][_0x427a81('0x51')]||util[_0x427a81('0x11b')](_0x427a81('0x72'),_0x427a81('0x9e'),_0x210e1a[_0x427a81('0x15')]);switch(_0x24a1c0[_0x427a81('0xab')]){case'website_alias':_0x5335e5=_0x210e1a[_0x427a81('0x8b')]?util[_0x427a81('0x11b')](_0x427a81('0x72'),_0x24a1c0['agentAlias'],_0x210e1a['UserId']):_0x427a81('0x10a');break;case _0x427a81('0xbf'):_0x5335e5=_0x210e1a[_0x427a81('0x8b')]?_0x210e1a[_0x427a81('0x4d')][_0x427a81('0xc1')]||_0x210e1a[_0x427a81('0x4d')]['fullname']:_0x427a81('0x10a');break;case'agent_fullname':_0x5335e5=_0x210e1a[_0x427a81('0x8b')]?_0x210e1a[_0x427a81('0x4d')][_0x427a81('0xf3')]:_0x427a81('0x10a');break;default:_0x5335e5=_0x210e1a[_0x427a81('0x8b')]?util[_0x427a81('0x11b')]('%s%d',_0x24a1c0[_0x427a81('0x109')],_0x210e1a[_0x427a81('0x8b')]):_0x427a81('0x10a');}const _0x4700f3=util[_0x427a81('0x11b')](_0x427a81('0x77'),moment(_0x210e1a['createdAt'])[_0x427a81('0x11b')](_0x427a81('0xee')),_0x210e1a['direction']==='in'?_0x537f6d:_0x5335e5,_0x210e1a[_0x427a81('0x63')]);!_0x210e1a['secret']&&fs[_0x427a81('0x83')](_0x3c1424,_0x4700f3);}return db[_0x427a81('0xd0')][_0x427a81('0x26')]({'where':{'service':!![]},'include':[{'model':db['MailServerOut'],'as':'Smtp','raw':!![]}]});}}})[_0x118098('0xdc')](function(_0xd9c6ef){const _0x549417=_0x118098;if(_0xd9c6ef&&_0xd9c6ef[_0x549417('0xb5')]&&_0x432f88[_0x549417('0x63')]){const _0x509dda={'tls':{'rejectUnauthorized':![]}};return _0xd9c6ef[_0x549417('0xb5')]['service']?_0x509dda['service']=_0xd9c6ef['Smtp'][_0x549417('0xe7')]:(_0x509dda['host']=_0xd9c6ef[_0x549417('0xb5')]['host'],_0x509dda['port']=_0xd9c6ef[_0x549417('0xb5')][_0x549417('0xc3')],_0x509dda[_0x549417('0xd5')]=_0xd9c6ef[_0x549417('0xb5')]['secure']),_0xd9c6ef[_0x549417('0xb5')]['authentication']&&(_0x509dda[_0x549417('0x57')]={'user':_0xd9c6ef[_0x549417('0xb5')][_0x549417('0x12')],'pass':_0xd9c6ef[_0x549417('0xb5')][_0x549417('0x54')]}),respondWithRpcPromise(_0x549417('0xa4'),_0x549417('0x76'),{'account':_0x509dda,'message':{'from':util[_0x549417('0x11b')](_0x549417('0x117'),_0xd9c6ef[_0x549417('0xb0')],_0xd9c6ef['email']||_0xd9c6ef[_0x549417('0xb5')]['user']),'to':_0x432f88[_0x549417('0x63')][_0x549417('0x116')],'subject':_0x549417('0x9'),'text':util[_0x549417('0x11b')]('Hi\x20%s,\x20attached\x20you\x20can\x20find\x20your\x20transcript\x20file.\x20\x0a\x0aRegards.\x20\x0a\x0a',_0x432f88[_0x549417('0x63')][_0x549417('0x116')]),'attachments':[{'path':_0x3c1424}]}})['then'](function(){return _0xbedce0;})[_0x549417('0x55')](function(_0x4ccb71){const _0x17c890=_0x549417;console[_0x17c890('0xdd')](_0x4ccb71);});}else return _0xbedce0;})['then'](respondWithStatusCode(_0x54a92d,0xc8))[_0x118098('0x55')](handleError(_0x54a92d,null));},exports[_0x248663('0x73')]=function(_0x37bb90,_0x3e35b8){const _0x2e07a7=_0x248663;return db['ChatMessage'][_0x2e07a7('0x26')]({'where':{'id':_0x37bb90[_0x2e07a7('0xe9')]['id']}})['then'](function(_0x4f9079){const _0x3272dd=_0x2e07a7;if(_0x4f9079)return _0x4f9079[_0x3272dd('0x73')](_0x37bb90[_0x3272dd('0x63')][_0x3272dd('0xda')],{'through':_[_0x3272dd('0x8e')](_0x37bb90[_0x3272dd('0x63')],['ids','id'])});})[_0x2e07a7('0xdc')](respondWithResult(_0x3e35b8,null))[_0x2e07a7('0x55')](handleError(_0x3e35b8,null));},exports[_0x248663('0x5')]=function(_0x351405,_0x496d1b){const _0x32e7a4=_0x248663;let _0x4268d3={'raw':![],'where':{}};const _0x2ef069={},_0x4fc220={'count':0x0,'rows':[]};return db[_0x32e7a4('0xf4')][_0x32e7a4('0x26')]({'where':{'id':_0x351405[_0x32e7a4('0xe9')]['id']}})[_0x32e7a4('0xdc')](handleEntityNotFound(_0x496d1b,null))[_0x32e7a4('0xdc')](function(_0x4881be){const _0x4ed416=_0x32e7a4;if(_0x4881be){_0x2ef069['model']=_['keys'](db[_0x4ed416('0xd')][_0x4ed416('0x33')]),_0x2ef069[_0x4ed416('0xe1')]=_[_0x4ed416('0x6a')](_0x351405[_0x4ed416('0xe1')]),_0x2ef069[_0x4ed416('0xfb')]=_['intersection'](_0x2ef069[_0x4ed416('0xca')],_0x2ef069[_0x4ed416('0xe1')]),_0x4268d3[_0x4ed416('0xb3')]=_[_0x4ed416('0x1c')](_0x2ef069[_0x4ed416('0xca')],qs['fields'](_0x351405['query'][_0x4ed416('0xa5')])),_0x4268d3[_0x4ed416('0xb3')]=_0x4268d3[_0x4ed416('0xb3')]['length']?_0x4268d3[_0x4ed416('0xb3')]:_0x2ef069['model'];typeof _0x351405[_0x4ed416('0xe1')][_0x4ed416('0x11d')]===_0x4ed416('0x69')&&(_0x4268d3[_0x4ed416('0xc')]=qs[_0x4ed416('0xc')](_0x351405['query'][_0x4ed416('0xc')]),_0x4268d3[_0x4ed416('0x7b')]=qs[_0x4ed416('0x7b')](_0x351405[_0x4ed416('0xe1')]['offset']));_0x4268d3['order']=qs[_0x4ed416('0xc7')](_0x351405[_0x4ed416('0xe1')][_0x4ed416('0xc7')]),_0x4268d3[_0x4ed416('0x4b')]=qs[_0x4ed416('0xfb')](_[_0x4ed416('0xf2')](_0x351405[_0x4ed416('0xe1')],_0x2ef069['filters'])),_0x4268d3[_0x4ed416('0x4b')][_0x4ed416('0x41')]=_0x4881be['id'];_0x351405[_0x4ed416('0xe1')][_0x4ed416('0xb1')]&&(_0x4268d3[_0x4ed416('0x4b')]=_['merge'](_0x4268d3[_0x4ed416('0x4b')],{[Op['or']]:_[_0x4ed416('0xd9')](_0x4268d3['attributes'],function(_0x316a45){const _0xfc5358=_0x4ed416,_0xea11bc={};return _0xea11bc[_0x316a45]={[Op[_0xfc5358('0xb4')]]:'%'+_0x351405['query'][_0xfc5358('0xb1')]+'%'},_0xea11bc;})}));if(_0x351405[_0x4ed416('0xe1')][_0x4ed416('0x23')]){const _0x3fd60f=_0x351405[_0x4ed416('0xe1')]['$gte'][_0x4ed416('0xb9')](','),_0xbabca2={};_0xbabca2[_0x3fd60f[0x0]]={[Op[_0x4ed416('0xa2')]]:moment(_0x3fd60f[0x1])[_0x4ed416('0x11b')](_0x4ed416('0x37'))},_0x4268d3[_0x4ed416('0x4b')]=_['merge'](_0x4268d3[_0x4ed416('0x4b')],_0xbabca2);}return _0x4268d3=_[_0x4ed416('0x43')]({},_0x4268d3,_0x351405[_0x4ed416('0x110')]),db[_0x4ed416('0xd')][_0x4ed416('0xd3')]({'where':_0x4268d3[_0x4ed416('0x4b')]})[_0x4ed416('0xdc')](function(_0x3e8aff){const _0x2af7aa=_0x4ed416;return _0x4fc220['count']=_0x3e8aff,_0x351405['query'][_0x2af7aa('0x6e')]&&(_0x4268d3[_0x2af7aa('0x38')]=[{'all':!![]}]),db[_0x2af7aa('0xd')][_0x2af7aa('0x9d')](_0x4268d3);})[_0x4ed416('0xdc')](function(_0x55095a){const _0x295830=_0x4ed416;return _0x4fc220[_0x295830('0x53')]=_0x55095a,_0x4fc220;});}})['then'](respondWithFilteredResult(_0x496d1b,_0x4268d3))['catch'](handleError(_0x496d1b,null));},exports[_0x248663('0xeb')]=function(_0x2c802e,_0x4e1ca8){const _0xbb6c7d=_0x248663;let _0x2d28aa={'where':{}};const _0x1673e6={},_0x191958={'count':0x0,'rows':[]};return db['ChatInteraction'][_0xbb6c7d('0x26')]({'where':{'id':_0x2c802e[_0xbb6c7d('0xe9')]['id']}})[_0xbb6c7d('0xdc')](handleEntityNotFound(_0x4e1ca8,null))[_0xbb6c7d('0xdc')](function(_0x6030bd){const _0x2c533f=_0xbb6c7d;if(_0x6030bd)return _0x1673e6['model']=_[_0x2c533f('0x6a')](db[_0x2c533f('0xd')][_0x2c533f('0x33')]),_0x1673e6[_0x2c533f('0xe1')]=_[_0x2c533f('0x6a')](_0x2c802e['query']),_0x1673e6['filters']=_[_0x2c533f('0x1c')](_0x1673e6[_0x2c533f('0xca')],_0x1673e6[_0x2c533f('0xe1')]),_0x2d28aa[_0x2c533f('0xb3')]=_[_0x2c533f('0x1c')](_0x1673e6[_0x2c533f('0xca')],qs[_0x2c533f('0xa5')](_0x2c802e[_0x2c533f('0xe1')]['fields'])),_0x2d28aa[_0x2c533f('0xb3')]=_0x2d28aa[_0x2c533f('0xb3')][_0x2c533f('0x48')]?_0x2d28aa[_0x2c533f('0xb3')]:_0x1673e6[_0x2c533f('0xca')],typeof _0x2c802e[_0x2c533f('0xe1')][_0x2c533f('0x11d')]===_0x2c533f('0x69')&&(_0x2d28aa[_0x2c533f('0xc')]=qs[_0x2c533f('0xc')](_0x2c802e['query'][_0x2c533f('0xc')]),_0x2d28aa[_0x2c533f('0x7b')]=qs[_0x2c533f('0x7b')](_0x2c802e[_0x2c533f('0xe1')][_0x2c533f('0x7b')])),_0x2d28aa[_0x2c533f('0x17')]=qs[_0x2c533f('0xc7')](_0x2c802e[_0x2c533f('0xe1')]['sort']),_0x2d28aa[_0x2c533f('0x4b')]=qs[_0x2c533f('0xfb')](_[_0x2c533f('0xf2')](_0x2c802e[_0x2c533f('0xe1')],_0x1673e6[_0x2c533f('0xfb')])),_0x2d28aa[_0x2c533f('0x4b')][_0x2c533f('0x41')]=_0x6030bd['id'],_0x2c802e[_0x2c533f('0xe1')][_0x2c533f('0xb1')]&&(_0x2d28aa[_0x2c533f('0x4b')]=_[_0x2c533f('0x43')](_0x2d28aa['where'],{[Op['or']]:_[_0x2c533f('0xd9')](_0x2d28aa['attributes'],function(_0x33157a){const _0xcc6f83=_0x2c533f,_0x2e8297={};return _0x2e8297[_0x33157a]={[Op[_0xcc6f83('0xb4')]]:'%'+_0x2c802e[_0xcc6f83('0xe1')][_0xcc6f83('0xb1')]+'%'},_0x2e8297;})})),_0x2d28aa[_0x2c533f('0x4b')][_0x2c533f('0x4')]=![],_0x2c802e[_0x2c533f('0xe1')]['id']&&(_0x2d28aa[_0x2c533f('0x4b')]['id']={[Op['gt']]:_0x2c802e[_0x2c533f('0xe1')]['id']}),_0x2d28aa=_['merge']({},_0x2d28aa,_0x2c802e[_0x2c533f('0x110')]),db[_0x2c533f('0xd')]['count']({'where':_0x2d28aa['where']})[_0x2c533f('0xdc')](function(_0x3785ac){const _0x331f82=_0x2c533f;return _0x191958[_0x331f82('0xd3')]=_0x3785ac,_0x2d28aa[_0x331f82('0x38')]=[],_0x2c802e[_0x331f82('0xe1')][_0x331f82('0xc0')]&&_0x2d28aa[_0x331f82('0x38')][_0x331f82('0xf7')]({'model':db[_0x331f82('0x4d')],'as':'User','attributes':['id',_0x331f82('0xf3'),'alias']}),_0x2c802e[_0x331f82('0xe1')][_0x331f82('0x6e')]&&(_0x2d28aa['include']=[{'all':!![]}]),db['ChatMessage'][_0x331f82('0x9d')](_0x2d28aa);})[_0x2c533f('0xdc')](function(_0x9149fd){const _0x3005da=_0x2c533f;return _0x191958[_0x3005da('0x53')]=_0x9149fd,_0x191958;});})[_0xbb6c7d('0xdc')](respondWithFilteredResult(_0x4e1ca8,_0x2d28aa))[_0xbb6c7d('0x55')](handleError(_0x4e1ca8,null));},exports[_0x248663('0x106')]=function(_0x48774d,_0x476908){const _0xefc51=_0x248663;return db[_0xefc51('0xf4')]['findOne']({'where':{'id':_0x48774d[_0xefc51('0xe9')]['id']}})[_0xefc51('0xdc')](function(_0xe75272){const _0x3201e5=_0xefc51;if(_0xe75272)return _0xe75272[_0x3201e5('0x11c')](_0x48774d[_0x3201e5('0x63')][_0x3201e5('0xda')],{'through':_['omit'](_0x48774d['body'],['ids','id'])})[_0x3201e5('0xdc')](function(){const _0x25d05f=_0x3201e5;return db[_0x25d05f('0x44')][_0x25d05f('0x9d')]({'attributes':['id',_0x25d05f('0xb0'),_0x25d05f('0xc4')],'where':{'id':_0x48774d[_0x25d05f('0x63')][_0x25d05f('0xda')]}});})[_0x3201e5('0xdc')](function(_0xf169a4){const _0x52b68a=_0x3201e5;return socket[_0x52b68a('0x80')](_0x52b68a('0xde'),{'id':Number(_0x48774d[_0x52b68a('0xe9')]['id']),'tags':_0xf169a4||[]}),{'id':Number(_0x48774d[_0x52b68a('0xe9')]['id']),'tags':_0xf169a4||[]};});})[_0xefc51('0xdc')](respondWithResult(_0x476908,null))[_0xefc51('0x55')](handleError(_0x476908,null));},exports[_0x248663('0x99')]=function(_0x168365,_0x5cd7b9){const _0x1057cd=_0x248663;return db[_0x1057cd('0xf4')][_0x1057cd('0x26')]({'where':{'id':_0x168365[_0x1057cd('0xe9')]['id']}})[_0x1057cd('0xdc')](handleEntityNotFound(_0x5cd7b9,null))['then'](function(_0xc30aa9){const _0x3fdf44=_0x1057cd;if(_0xc30aa9)return _0xc30aa9['removeTags'](_0x168365[_0x3fdf44('0xe1')]['ids']);})[_0x1057cd('0xdc')](respondWithStatusCode(_0x5cd7b9,null))['catch'](handleError(_0x5cd7b9,null));},exports['download']=function(_0x18ab10,_0x59e487){const _0x4a3a04=_0x248663,_0x35a5cf=moment()[_0x4a3a04('0x93')]()[_0x4a3a04('0x100')](),_0x467a8c=path[_0x4a3a04('0xbd')](config['root'],_0x4a3a04('0x56'),'tmp'),_0x1f0f9f=path[_0x4a3a04('0xbd')](config[_0x4a3a04('0x7c')],_0x4a3a04('0x29'),_0x4a3a04('0x56'),'attachments'),_0x145b02=path[_0x4a3a04('0xbd')](_0x467a8c,_0x35a5cf),_0xf0fed6=util[_0x4a3a04('0x11b')](_0x4a3a04('0x6c'),_0x18ab10[_0x4a3a04('0xe9')]['id'],_0x35a5cf),_0x3329c8=path['join'](_0x467a8c,_0xf0fed6),_0x1eded0=[];_0x1eded0['push']({'model':db[_0x4a3a04('0x4d')],'as':_0x4a3a04('0x4d'),'attributes':['id','fullname'],'raw':!![]}),_0x1eded0[_0x4a3a04('0xf7')]({'model':db[_0x4a3a04('0x5a')],'as':_0x4a3a04('0xbc'),'attributes':['id','firstName',_0x4a3a04('0x1')],'raw':!![]});_0x18ab10[_0x4a3a04('0xe1')]['attachments']&&_0x1eded0[_0x4a3a04('0xf7')]({'model':db[_0x4a3a04('0xf9')],'as':_0x4a3a04('0xf9'),'raw':!![]});const _0xc2a607=[{'model':db['ChatMessage'],'as':_0x4a3a04('0x0'),'attributes':['id','body',_0x4a3a04('0x3d'),_0x4a3a04('0x108'),'secret',_0x4a3a04('0x67')],'include':_0x1eded0}];return _0xc2a607[_0x4a3a04('0xf7')]({'model':db[_0x4a3a04('0x104')],'as':_0x4a3a04('0x103'),'attributes':['id','name']}),_0xc2a607[_0x4a3a04('0xf7')]({'model':db['User'],'as':_0x4a3a04('0x89'),'attributes':['id',_0x4a3a04('0xf3')]}),db['ChatInteraction'][_0x4a3a04('0x26')]({'where':{'id':_0x18ab10[_0x4a3a04('0xe9')]['id']},'include':_0xc2a607})[_0x4a3a04('0xdc')](handleEntityNotFound(_0x59e487,null))['then'](function(_0x27fca4){const _0x5aad80=_0x4a3a04;if(_0x27fca4){const _0x3d0bf9=_0x27fca4[_0x5aad80('0x1b')]({'plain':!![]});fs[_0x5aad80('0xa6')](_0x145b02);const _0x5c6e4a={'format':'A4','border':_0x5aad80('0xcd'),'header':{'height':_0x5aad80('0x50'),'contents':{'first':_0x5aad80('0x7')}},'footer':{'height':_0x5aad80('0xe6'),'contents':{'default':util[_0x5aad80('0x11b')](_0x5aad80('0xc9'),util[_0x5aad80('0x11b')](_0x5aad80('0x8a'),_0x5aad80('0x85'),_0x3d0bf9['id']),moment()[_0x5aad80('0x11b')](_0x5aad80('0x4c'))['toString']())}}},_0x48cb83={'channel':_0x5aad80('0x85'),'account':_0x3d0bf9['Account']['name'],'agent':_0x3d0bf9[_0x5aad80('0x89')]?_0x3d0bf9[_0x5aad80('0x89')][_0x5aad80('0xf3')]:_0x5aad80('0x58'),'createdAt':moment(_0x3d0bf9['createdAt'])[_0x5aad80('0x11b')](_0x5aad80('0x37'))[_0x5aad80('0x100')](),'closedAt':_0x3d0bf9[_0x5aad80('0x31')]?moment(_0x3d0bf9[_0x5aad80('0xd7')])[_0x5aad80('0x11b')]('YYYY-MM-DD\x20HH:mm:ss')[_0x5aad80('0x100')]():'','disposition':_0x3d0bf9[_0x5aad80('0x84')],'chatInfo':{'browser':_0x3d0bf9[_0x5aad80('0x74')],'os':_0x3d0bf9['osName'],'referer':_0x3d0bf9[_0x5aad80('0xa1')],'customerIp':_0x3d0bf9[_0x5aad80('0xc5')],'customerPort':_0x3d0bf9[_0x5aad80('0x22')]?_0x3d0bf9['customerPort']:_0x5aad80('0x58')},'messages':_(_0x3d0bf9['Messages'])[_0x5aad80('0x2')]()[_0x5aad80('0xb1')]({'secret':![]})[_0x5aad80('0xd9')](function(_0x3ceb15){const _0x5b1b82=_0x5aad80;if(_0x3ceb15[_0x5b1b82('0xf9')]){const _0x4e56b2=path[_0x5b1b82('0xbd')](_0x1f0f9f,_0x3ceb15[_0x5b1b82('0xf9')][_0x5b1b82('0x24')]);fs[_0x5b1b82('0x98')](_0x4e56b2)&&fs[_0x5b1b82('0x59')](_0x4e56b2)[_0x5b1b82('0xa9')](fs[_0x5b1b82('0xe3')](path[_0x5b1b82('0xbd')](_0x145b02,_0x3ceb15[_0x5b1b82('0xf9')][_0x5b1b82('0x24')])));}return{'date':moment(_0x3ceb15[_0x5b1b82('0x3d')])[_0x5b1b82('0x11b')](_0x5b1b82('0x37'))[_0x5b1b82('0x100')](),'sender':_0x3ceb15[_0x5b1b82('0x108')]===_0x5b1b82('0xd2')?_0x3ceb15[_0x5b1b82('0x4d')]?_0x3ceb15[_0x5b1b82('0x4d')]['fullname']:_0x5b1b82('0x10a'):_0x3ceb15['Contact'][_0x5b1b82('0x82')]+(_0x3ceb15[_0x5b1b82('0xbc')][_0x5b1b82('0x1')]?'\x20'+_0x3ceb15[_0x5b1b82('0xbc')]['lastName']:''),'body':_0x3ceb15[_0x5b1b82('0xf9')]?_0x3ceb15[_0x5b1b82('0xf9')][_0x5b1b82('0x24')]:_0x3ceb15['body'],'direction':_0x3ceb15['direction']===_0x5b1b82('0xd2')?'A':'C','secret':_0x3ceb15[_0x5b1b82('0x4')],'read':_0x3ceb15[_0x5b1b82('0x67')],'attachment':_0x3ceb15[_0x5b1b82('0xf9')]};})['value']()};return ejs[_0x5aad80('0xdb')](path[_0x5aad80('0xbd')](config[_0x5aad80('0x7c')],_0x5aad80('0x29'),_0x5aad80('0x118'),_0x5aad80('0x6d')),{'interaction':_0x48cb83})[_0x5aad80('0xdc')](function(_0x104d8a){return new Promise(function(_0x15ec72,_0x4d6e5a){const _0x318976=a66_0x5cf5;pdf['create'](_0x104d8a,_0x5c6e4a)['toFile'](path[_0x318976('0xbd')](_0x145b02,_0x318976('0xdf')+_0x3d0bf9['id']+'-'+_0x35a5cf+'.pdf'),function(_0x323610,_0x35fcb9){if(_0x323610)return _0x4d6e5a(_0x323610);_0x15ec72(_0x35fcb9);});});})[_0x5aad80('0xdc')](function(){const _0x2ad5d6=_0x5aad80;return new Promise(function(_0x37fd84,_0x3ed923){zipdir(_0x145b02,{'saveTo':_0x3329c8},function(_0x168622,_0x42823f){if(_0x168622)return _0x3ed923(_0x168622);return _0x37fd84(_0x42823f);});})[_0x2ad5d6('0xdc')](function(){return new Promise(function(_0x3cf1b2,_0x25cc0d){rimraf(_0x145b02,function(_0x450a69){if(_0x450a69)_0x25cc0d(_0x450a69);return _0x3cf1b2();});});})[_0x2ad5d6('0xdc')](function(){return _0x59e487['download'](_0x3329c8,_0xf0fed6,function(_0x155523){const _0x204b12=a66_0x5cf5;_0x155523?console[_0x204b12('0xac')]('err',_0x155523):fs[_0x204b12('0x94')](_0x3329c8);});});});}else return _0x59e487[_0x5aad80('0x2b')](0xc8);})[_0x4a3a04('0x55')](handleError(_0x59e487,null));};