Built motion from commit 932cf0d0.|2.5.42
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 5ccc53d..8ff893a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3fce=['describe','addMessage','ids','getMessages','findOne','WhatsappMessage','YYYY-MM-DD\x20HH:mm:ss','options','includeAll','findAll','addTags','setTags','spread','emit','whatsappInteractionTags:save','removeTags','download','unix','root','server','files','join','transcript-%d-%s.zip','CmContact','firstName','lastName','attachments','Attachment','Messages','WhatsappAccount','Account','Owner','get','Whatsapp','N.A.','format','basename','existsSync','createReadStream','pipe','createWriteStream','out','User','direction','secret','renderFile','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','log','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','ejs','fs-extra','squel','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/export/pdf','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','register','sendStatus','status','offset','undefined','count','limit','set','Content-Range','json','apply','save','then','error','stack','name','send','Users','map','fullname','TagIds','split','forEach','Tags','push','catch','waiting','talking','answered','unmanaged','total','closed','UserId','index','WhatsappInteraction','rawAttributes','fieldName','key','model','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','tools_tags','u.fullname','from','left_join','users','u.id\x20=\x20ui.UserId','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','whatsapp_accounts','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','conditions','length','find','value','`\x20=\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','type','text','start','end','Tag','union','body','keys','compact','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','$gte','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','having','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','unreadMessages','contactName','DESC','t.id\x20IN\x20?','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','role','agent','sequelize','toString','keyBy','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','Contact.mobile','Contact.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','all','rows','show','include','create','update','destroy','params'];(function(_0x13bf5b,_0x57dde4){var _0x9956ff=function(_0x39ccbe){while(--_0x39ccbe){_0x13bf5b['push'](_0x13bf5b['shift']());}};_0x9956ff(++_0x57dde4);}(_0x3fce,0x121));var _0xe3fc=function(_0x21353c,_0x2ea587){_0x21353c=_0x21353c-0x0;var _0xa99120=_0x3fce[_0x21353c];return _0xa99120;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xe3fc('0x0'));var zipdir=require(_0xe3fc('0x1'));var jsonpatch=require(_0xe3fc('0x2'));var rp=require(_0xe3fc('0x3'));var moment=require(_0xe3fc('0x4'));var BPromise=require(_0xe3fc('0x5'));var Mustache=require(_0xe3fc('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xe3fc('0x7'));var fs=require('fs');var fs_extra=require(_0xe3fc('0x8'));var _=require('lodash');var squel=require(_0xe3fc('0x9'));var crypto=require('crypto');var jsforce=require(_0xe3fc('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xe3fc('0xb'));var querystring=require(_0xe3fc('0xc'));var Papa=require(_0xe3fc('0xd'));var Redis=require(_0xe3fc('0xe'));var authService=require(_0xe3fc('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xe3fc('0x10'));var hardwareService=require(_0xe3fc('0x11'));var logger=require(_0xe3fc('0x12'))('api');var utils=require(_0xe3fc('0x13'));var config=require(_0xe3fc('0x14'));var licenseUtil=require(_0xe3fc('0x15'));var db=require(_0xe3fc('0x16'))['db'];config[_0xe3fc('0x17')]=_[_0xe3fc('0x18')](config[_0xe3fc('0x17')],{'host':'localhost','port':0x18eb});var socket=require(_0xe3fc('0x19'))(new Redis(config[_0xe3fc('0x17')]));require('./whatsappInteraction.socket')[_0xe3fc('0x1a')](socket);function respondWithStatusCode(_0x3d437f,_0x5edfdf){_0x5edfdf=_0x5edfdf||0xcc;return function(_0x28403f){if(_0x28403f){return _0x3d437f[_0xe3fc('0x1b')](_0x5edfdf);}return _0x3d437f['status'](_0x5edfdf)['end']();};}function respondWithResult(_0x5953ac,_0x27b618){_0x27b618=_0x27b618||0xc8;return function(_0x4283be){if(_0x4283be){return _0x5953ac[_0xe3fc('0x1c')](_0x27b618)['json'](_0x4283be);}};}function respondWithFilteredResult(_0x58a4b8,_0x354695){return function(_0x5a4d98){if(_0x5a4d98){var _0x404e04=typeof _0x354695[_0xe3fc('0x1d')]===_0xe3fc('0x1e')&&typeof _0x354695['limit']==='undefined';var _0x42140f=_0x5a4d98[_0xe3fc('0x1f')];var _0x16b914=_0x404e04?0x0:_0x354695['offset'];var _0x4472f7=_0x404e04?_0x5a4d98[_0xe3fc('0x1f')]:_0x354695['offset']+_0x354695[_0xe3fc('0x20')];var _0x82da29;if(_0x4472f7>=_0x42140f){_0x4472f7=_0x42140f;_0x82da29=0xc8;}else{_0x82da29=0xce;}_0x58a4b8['status'](_0x82da29);return _0x58a4b8[_0xe3fc('0x21')](_0xe3fc('0x22'),_0x16b914+'-'+_0x4472f7+'/'+_0x42140f)[_0xe3fc('0x23')](_0x5a4d98);}return null;};}function patchUpdates(_0x5b53a7){return function(_0x4ac172){try{jsonpatch[_0xe3fc('0x24')](_0x4ac172,_0x5b53a7,!![]);}catch(_0x4f4134){return BPromise['reject'](_0x4f4134);}return _0x4ac172[_0xe3fc('0x25')]();};}function saveUpdates(_0x2e9322,_0x3a8071){return function(_0x177a14){if(_0x177a14){return _0x177a14['update'](_0x2e9322)[_0xe3fc('0x26')](function(_0x54e294){return _0x54e294;});}return null;};}function removeEntity(_0x507656,_0x5abdb3){return function(_0x58adb8){if(_0x58adb8){return _0x58adb8['destroy']()[_0xe3fc('0x26')](function(){_0x507656[_0xe3fc('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x60e9b8,_0x188ca2){return function(_0x5be1d6){if(!_0x5be1d6){_0x60e9b8[_0xe3fc('0x1b')](0x194);}return _0x5be1d6;};}function handleError(_0xc40376,_0x1ecb86){_0x1ecb86=_0x1ecb86||0x1f4;return function(_0x3bc101){logger[_0xe3fc('0x27')](_0x3bc101[_0xe3fc('0x28')]);if(_0x3bc101[_0xe3fc('0x29')]){delete _0x3bc101[_0xe3fc('0x29')];}_0xc40376[_0xe3fc('0x1c')](_0x1ecb86)[_0xe3fc('0x2a')](_0x3bc101);};}function getInteractionUsers(_0x30a897,_0x39f375){return new BPromise(function(_0x25a0af,_0x43714d){try{if(_0x39f375[_0x30a897['id']]){_0x30a897[_0xe3fc('0x2b')]=_[_0xe3fc('0x2c')](_0x39f375[_0x30a897['id']],function(_0x59cc02){return{'id':_0x59cc02['id'],'fullname':_0x59cc02[_0xe3fc('0x2d')]};});}}catch(_0x2f910e){_0x43714d(_0x2f910e);}_0x25a0af(_0x30a897);});}function getInteractionTags(_0x1ce4af,_0x4ae4e4){return new BPromise(function(_0x3e1158,_0x15c46f){try{if(_0x1ce4af[_0xe3fc('0x2e')]){_0x1ce4af['Tags']=[];_0x1ce4af[_0xe3fc('0x2e')][_0xe3fc('0x2f')](',')[_0xe3fc('0x30')](function(_0x20ac90){_0x1ce4af[_0xe3fc('0x31')][_0xe3fc('0x32')](_0x4ae4e4[_0x20ac90]);});}delete _0x1ce4af['TagIds'];}catch(_0x3b0820){_0x15c46f(_0x3b0820);}_0x3e1158(_0x1ce4af);});}function updateWhatsappInteraction(_0x3bb70d,_0x9baaec,_0x36701e){return new BPromise(function(_0x1f441d,_0x437e4e){return getInteractionUsers(_0x3bb70d,_0x36701e)[_0xe3fc('0x26')](function(_0x888634){return getInteractionTags(_0x888634,_0x9baaec);})[_0xe3fc('0x26')](function(_0x11c271){return getStateInteraction(_0x11c271);})[_0xe3fc('0x26')](function(_0x25edfd){_0x1f441d(_0x25edfd);})[_0xe3fc('0x33')](function(_0x4bba26){_0x437e4e(_0x4bba26);});});}function getStateInteraction(_0x580cba){return new BPromise(function(_0x4ced3a){_0x580cba[_0xe3fc('0x34')]=0x0;_0x580cba[_0xe3fc('0x35')]=0x0;_0x580cba[_0xe3fc('0x36')]=0x0;_0x580cba[_0xe3fc('0x37')]=0x0;_0x580cba[_0xe3fc('0x38')]=0x0;if(!_0x580cba[_0xe3fc('0x39')]&&!_0x580cba[_0xe3fc('0x3a')]){_0x580cba[_0xe3fc('0x34')]+=0x1;}if(!_0x580cba['closed']&&_0x580cba[_0xe3fc('0x3a')]){_0x580cba[_0xe3fc('0x35')]+=0x1;if(_0x580cba['waiting']){_0x580cba[_0xe3fc('0x34')]-=0x1;}}if(_0x580cba[_0xe3fc('0x39')]&&_0x580cba[_0xe3fc('0x3a')]){_0x580cba[_0xe3fc('0x36')]+=0x1;if(_0x580cba[_0xe3fc('0x35')]){_0x580cba['talking']-=0x1;}}if(_0x580cba[_0xe3fc('0x39')]&&!_0x580cba['UserId']){_0x580cba['unmanaged']+=0x1;if(_0x580cba[_0xe3fc('0x34')]){_0x580cba[_0xe3fc('0x34')]-=0x1;}}_0x580cba['total']+=0x1;_0x4ced3a(_0x580cba);});}exports[_0xe3fc('0x3b')]=function(_0x575910,_0x24600b){var _0x40804e={},_0x1b2fa2={},_0x157bcc={'count':0x0,'rows':[]};var _0x54d491=_[_0xe3fc('0x2c')](db[_0xe3fc('0x3c')][_0xe3fc('0x3d')],function(_0x1ebd60){return{'name':_0x1ebd60[_0xe3fc('0x3e')],'type':_0x1ebd60['type'][_0xe3fc('0x3f')]};});_0x1b2fa2[_0xe3fc('0x40')]=_[_0xe3fc('0x2c')](_0x54d491,'name');_0x1b2fa2[_0xe3fc('0x41')]=_['keys'](_0x575910[_0xe3fc('0x41')]);_0x1b2fa2[_0xe3fc('0x42')]=_[_0xe3fc('0x43')](_0x1b2fa2[_0xe3fc('0x40')],_0x1b2fa2[_0xe3fc('0x41')]);_0x40804e['attributes']=_[_0xe3fc('0x43')](_0x1b2fa2[_0xe3fc('0x40')],qs[_0xe3fc('0x44')](_0x575910[_0xe3fc('0x41')][_0xe3fc('0x44')]));_0x40804e['attributes']=_0x40804e[_0xe3fc('0x45')]['length']?_0x40804e['attributes']:_0x1b2fa2['model'];if(!_0x575910[_0xe3fc('0x41')][_0xe3fc('0x46')](_0xe3fc('0x47'))){_0x40804e[_0xe3fc('0x20')]=qs[_0xe3fc('0x20')](_0x575910[_0xe3fc('0x41')]['limit']);_0x40804e[_0xe3fc('0x1d')]=qs['offset'](_0x575910[_0xe3fc('0x41')][_0xe3fc('0x1d')]);}_0x40804e[_0xe3fc('0x48')]=qs[_0xe3fc('0x49')](_0x575910['query'][_0xe3fc('0x49')]);_0x40804e[_0xe3fc('0x4a')]=qs[_0xe3fc('0x42')](_[_0xe3fc('0x4b')](_0x575910[_0xe3fc('0x41')],_0x1b2fa2[_0xe3fc('0x42')]),_0x54d491);var _0x57506f=[];var _0x484726=squel[_0xe3fc('0x4c')]()[_0xe3fc('0x4d')]('id')[_0xe3fc('0x4d')](_0xe3fc('0x29'))[_0xe3fc('0x4d')](_0xe3fc('0x4e'))['from'](_0xe3fc('0x4f'));var _0x47c77a=squel[_0xe3fc('0x4c')]()['field']('u.id')['field'](_0xe3fc('0x50'))[_0xe3fc('0x4d')]('ui.WhatsappInteractionId')[_0xe3fc('0x51')]('user_has_whatsapp_interactions','ui')[_0xe3fc('0x52')](_0xe3fc('0x53'),'u',_0xe3fc('0x54'));var _0x23f9b7=squel[_0xe3fc('0x4c')]()[_0xe3fc('0x51')]('whatsapp_interactions','i')['left_join'](_0xe3fc('0x55'),'c',_0xe3fc('0x56'))[_0xe3fc('0x52')](_0xe3fc('0x53'),'o',_0xe3fc('0x57'))[_0xe3fc('0x52')](_0xe3fc('0x58'),'a','a.id\x20=\x20i.WhatsappAccountId')[_0xe3fc('0x52')](_0xe3fc('0x59'),'me',_0xe3fc('0x5a'))[_0xe3fc('0x52')]('whatsapp_interaction_has_tags','it','it.WhatsappInteractionId\x20=\x20i.id')['left_join'](_0xe3fc('0x4f'),'t',_0xe3fc('0x5b'));var _0x2321fd=squel[_0xe3fc('0x5c')]();var _0x34d7ff=[];var _0x26e479=squel[_0xe3fc('0x5c')]();var _0x27d0bf;if(_0x575910[_0xe3fc('0x41')][_0xe3fc('0x5d')]){_0x27d0bf=as[_0xe3fc('0x5e')](_0x575910[_0xe3fc('0x41')][_0xe3fc('0x5d')]);var _0x5c7d4a=_0x27d0bf['sqlOperator'];for(var _0x4fe840=0x0;_0x4fe840<_0x27d0bf[_0xe3fc('0x5f')][_0xe3fc('0x60')];_0x4fe840++){var _0x33eb2b=_0x27d0bf['conditions'][_0x4fe840];var _0x4b06cf='i';var _0x832a89=_[_0xe3fc('0x61')](_0x54d491,[_0xe3fc('0x29'),_0x33eb2b['field']]);if(!_0x832a89){switch(_0x33eb2b['field']){case'unreadMessages':if(_0x33eb2b[_0xe3fc('0x62')]==0x1){_0x23f9b7['having']('`'+_0x33eb2b['field']+_0xe3fc('0x63'));}else{_0x23f9b7['having']('`'+_0x33eb2b['field']+'`\x20>\x200');}break;case _0xe3fc('0x64'):if(_0x33eb2b[_0xe3fc('0x65')]===_0xe3fc('0x66')){if(_0x33eb2b[_0xe3fc('0x62')][_0xe3fc('0x2f')]('\x20')['length']>0x1){_0x2321fd[_0x5c7d4a](_0xe3fc('0x67'),qs[_0xe3fc('0x68')](_0x33eb2b['value']),null);}else{var _0x2a95e1='%'+_0x33eb2b[_0xe3fc('0x62')]+'%';_0x2321fd[_0x5c7d4a](_0xe3fc('0x69'),_0x2a95e1,_0x2a95e1,_0x2a95e1);}}else{_0x832a89=_[_0xe3fc('0x61')](_0x54d491,[_0xe3fc('0x29'),_0xe3fc('0x6a')]);_0x33eb2b[_0xe3fc('0x4d')]=_0xe3fc('0x6a');_0x4d6ee2=as[_0xe3fc('0x6b')](_0x4b06cf,_0x832a89[_0xe3fc('0x6c')],_0x33eb2b);_0x2321fd[_0x5c7d4a](_0x4d6ee2[_0xe3fc('0x6d')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6e')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6f')]);}break;case _0xe3fc('0x70'):var _0x460c7b=_0x33eb2b[_0xe3fc('0x62')][_0xe3fc('0x2f')](',')['map'](function(_0x2541a1){return Number(_0x2541a1);});_0x460c7b[_0xe3fc('0x30')](function(_0x3ae3bd){_0x26e479['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x3ae3bd+',%');});_0x34d7ff=_[_0xe3fc('0x71')](_0x34d7ff,_0x460c7b);break;case'User':if(_0x33eb2b[_0xe3fc('0x65')]==='$substring'){_0x2321fd[_0x5c7d4a]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x33eb2b[_0xe3fc('0x62')]+'%',null);}else{_0x832a89=_[_0xe3fc('0x61')](_0x54d491,[_0xe3fc('0x29'),_0xe3fc('0x3a')]);_0x33eb2b['field']=_0xe3fc('0x3a');_0x4d6ee2=as[_0xe3fc('0x6b')](_0x4b06cf,_0x832a89[_0xe3fc('0x6c')],_0x33eb2b);_0x2321fd[_0x5c7d4a](_0x4d6ee2[_0xe3fc('0x6d')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6e')],_0x4d6ee2[_0xe3fc('0x62')]['end']);}break;case _0xe3fc('0x72'):_0x4d6ee2=as['buildExpression']('me',null,_0x33eb2b);_0x2321fd[_0x5c7d4a](_0x4d6ee2[_0xe3fc('0x6d')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6e')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6f')]);break;}}else{var _0x4d6ee2=as[_0xe3fc('0x6b')](_0x4b06cf,_0x832a89[_0xe3fc('0x6c')],_0x33eb2b);_0x2321fd[_0x5c7d4a](_0x4d6ee2[_0xe3fc('0x6d')],_0x4d6ee2[_0xe3fc('0x62')][_0xe3fc('0x6e')],_0x4d6ee2[_0xe3fc('0x62')]['end']);}}}else{var _0x3c33de=_(_0x575910[_0xe3fc('0x41')])[_0xe3fc('0x73')]()[_0xe3fc('0x2c')](function(_0x290bde){return _['some'](_0x54d491,[_0xe3fc('0x29'),_0x290bde])?_0x290bde:undefined;})[_0xe3fc('0x74')]()[_0xe3fc('0x62')]();if(!_['isEmpty'](_0x3c33de)){_0x3c33de[_0xe3fc('0x30')](function(_0x84dcd0){if(_0x84dcd0==='WhatsappAccountId'){_0x23f9b7[_0xe3fc('0x4a')](_0xe3fc('0x75'),[][_0xe3fc('0x76')](_0x575910['query'][_0x84dcd0]));}else if(_0x84dcd0===_0xe3fc('0x77')){var _0x452ad7=JSON['parse'](_0x575910[_0xe3fc('0x41')][_0x84dcd0])[_0xe3fc('0x78')];var _0x3b9077=JSON[_0xe3fc('0x79')](_0x575910[_0xe3fc('0x41')][_0x84dcd0])['$lte'];_0x23f9b7['where'](_0xe3fc('0x7a'),_0x452ad7,_0x3b9077);}else{if(_0x575910[_0xe3fc('0x41')][_0x84dcd0]===_0xe3fc('0x7b')){_0x23f9b7['where']('i.'+_0x84dcd0+'\x20IS\x20NULL');}else{_0x23f9b7[_0xe3fc('0x4a')]('i.'+_0x84dcd0+_0xe3fc('0x7c'),_0x575910[_0xe3fc('0x41')][_0x84dcd0]);}}});}if(_0x575910[_0xe3fc('0x41')][_0xe3fc('0x7d')]){if(_0x575910[_0xe3fc('0x41')][_0xe3fc('0x7d')]==0x1){_0x23f9b7[_0xe3fc('0x7e')](_0xe3fc('0x7f'));}else{_0x23f9b7[_0xe3fc('0x7e')](_0xe3fc('0x80'));}}if(_0x575910['query'][_0xe3fc('0x81')]){_0x34d7ff=_[_0xe3fc('0x82')](_0x575910[_0xe3fc('0x41')][_0xe3fc('0x81')])?_0x575910[_0xe3fc('0x41')][_0xe3fc('0x81')]:new Array(_0x575910[_0xe3fc('0x41')]['tag']);_0x34d7ff['forEach'](function(_0x1d41d1){_0x26e479['or'](_0xe3fc('0x83'),'%,'+_0x1d41d1+',%');});}if(_0x575910[_0xe3fc('0x41')]['filter']){var _0x286fc5=_0x575910[_0xe3fc('0x41')][_0xe3fc('0x84')][_0xe3fc('0x85')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs['isNumeric'](_0x286fc5)){_0x2321fd['or'](_0xe3fc('0x86'),_0x286fc5+'%')['or'](_0xe3fc('0x87'),_0x286fc5+'%');}else{_0x2321fd['or'](_0xe3fc('0x88'),qs[_0xe3fc('0x68')](_0x286fc5))['or'](_0xe3fc('0x89'),_0x286fc5+'%');}}}_0x23f9b7['where'](_0x2321fd);_0x23f9b7[_0xe3fc('0x8a')](_0xe3fc('0x8b'));var _0x58675e={'type':db[_0xe3fc('0x8c')][_0xe3fc('0x8d')][_0xe3fc('0x8e')],'raw':!![]};var _0x1c3c7c=_0x23f9b7[_0xe3fc('0x8f')]();_0x1c3c7c[_0xe3fc('0x4d')](_0xe3fc('0x8b'));_0x1c3c7c[_0xe3fc('0x4d')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xe3fc('0x90'));if(_0x40804e[_0xe3fc('0x48')]){_0x40804e[_0xe3fc('0x48')][_0xe3fc('0x30')](function(_0x40b353){var _0x392d40=_0x40b353[0x0]===_0xe3fc('0x91')?_0x40b353[0x0]:'i.'+_0x40b353[0x0];_0x23f9b7['order'](_0x392d40,_0x40b353[0x1]===_0xe3fc('0x92')?![]:!![]);});}if(!_['isEmpty'](_0x34d7ff)){_0x23f9b7['having'](_0x26e479);_0x1c3c7c[_0xe3fc('0x4a')](_0xe3fc('0x93'),_0x34d7ff);}BPromise['resolve']()[_0xe3fc('0x26')](function(){if(!_0x27d0bf){if(_0x575910['query'][_0xe3fc('0x94')])return;_0x1c3c7c[_0xe3fc('0x4a')](_0xe3fc('0x95'));_0x23f9b7[_0xe3fc('0x4a')](_0xe3fc('0x95'));return;}if(_0x575910[_0xe3fc('0x96')]['role']!=='agent')return;return _0x575910['user'][_0xe3fc('0x97')]({'attributes':['id'],'raw':!![]})['then'](function(_0x347e2f){if(_['isEmpty'](_0x347e2f)){_0x1c3c7c[_0xe3fc('0x4a')](_0xe3fc('0x98'));_0x23f9b7[_0xe3fc('0x4a')](_0xe3fc('0x98'));}else{_0x1c3c7c['where']('i.WhatsappAccountId\x20IN\x20?',_['map'](_0x347e2f,'id'));_0x23f9b7[_0xe3fc('0x4a')](_0xe3fc('0x75'),_[_0xe3fc('0x2c')](_0x347e2f,'id'));}});})[_0xe3fc('0x26')](function(){if(_0x575910[_0xe3fc('0x96')][_0xe3fc('0x99')]===_0xe3fc('0x9a')&&!_0x27d0bf&&!_0x575910['query'][_0xe3fc('0x94')])return[];return db[_0xe3fc('0x9b')][_0xe3fc('0x41')](_0x1c3c7c[_0xe3fc('0x9c')](),_0x58675e);})[_0xe3fc('0x26')](function(_0x114185){_0x157bcc['count']=_0x114185[_0xe3fc('0x60')];if(_0x157bcc['count']===0x0)return[];return db['sequelize'][_0xe3fc('0x41')](_0x484726[_0xe3fc('0x9c')](),_0x58675e)[_0xe3fc('0x26')](function(_0x350f93){_0x57506f=_[_0xe3fc('0x9d')](_0x350f93,'id');_0x58675e=_[_0xe3fc('0x9e')](_0x58675e,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x575910[_0xe3fc('0x41')][_0xe3fc('0x44')]){_0x40804e[_0xe3fc('0x45')][_0xe3fc('0x30')](function(_0x2cb0d1){_0x23f9b7[_0xe3fc('0x4d')]('i.'+_0x2cb0d1);});}else{_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0x9f'),_0xe3fc('0x90'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa0'),_0xe3fc('0xa1'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa2'),_0xe3fc('0xa3'));_0x23f9b7[_0xe3fc('0x4d')]('CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END',_0xe3fc('0x91'));_0x23f9b7[_0xe3fc('0x4d')]('i.*');_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa4'),'Contact.firstName');_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa5'),_0xe3fc('0xa6'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa7'),_0xe3fc('0xa8'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xa9'),_0xe3fc('0xaa'));_0x23f9b7[_0xe3fc('0x4d')]('c.mobile',_0xe3fc('0xab'));_0x23f9b7[_0xe3fc('0x4d')]('c.fax',_0xe3fc('0xac'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xad'),'Owner.fullname');_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xae'),_0xe3fc('0xaf'));_0x23f9b7[_0xe3fc('0x4d')](_0xe3fc('0xb0'),_0xe3fc('0x2e'));}if(_0x40804e[_0xe3fc('0x20')])_0x23f9b7[_0xe3fc('0x20')](_0x40804e['limit']);if(_0x40804e[_0xe3fc('0x1d')])_0x23f9b7[_0xe3fc('0x1d')](_0x40804e[_0xe3fc('0x1d')]);return db[_0xe3fc('0x9b')][_0xe3fc('0x41')](_0x23f9b7[_0xe3fc('0x9c')](),_0x58675e);})[_0xe3fc('0x26')](function(_0x479b52){if(_0x479b52['length']>0x0)_0x47c77a[_0xe3fc('0x4a')](_0xe3fc('0xb1'),_[_0xe3fc('0x2c')](_0x479b52,'id'));return db['sequelize']['query'](_0x47c77a[_0xe3fc('0x9c')](),_0x58675e)[_0xe3fc('0x26')](function(_0x4d8e58){var _0x476f23=_[_0xe3fc('0xb2')](_0x4d8e58,'WhatsappInteractionId');var _0x20cd96=[];_0x479b52[_0xe3fc('0x30')](function(_0x20f2c2){_0x20cd96[_0xe3fc('0x32')](updateWhatsappInteraction(_0x20f2c2,_0x57506f,_0x476f23));});return BPromise[_0xe3fc('0xb3')](_0x20cd96);});});})[_0xe3fc('0x26')](function(_0xcde302){_0x157bcc[_0xe3fc('0xb4')]=_0xcde302;return _0x157bcc;})['then'](respondWithFilteredResult(_0x24600b,_0x40804e))['catch'](handleError(_0x24600b,null));};exports[_0xe3fc('0xb5')]=function(_0x198d6e,_0x16884f){var _0x307060={'raw':![],'where':{'id':_0x198d6e['params']['id']}},_0x20cf62={};_0x20cf62[_0xe3fc('0x40')]=_[_0xe3fc('0x73')](db[_0xe3fc('0x3c')][_0xe3fc('0x3d')]);_0x20cf62[_0xe3fc('0x41')]=_[_0xe3fc('0x73')](_0x198d6e[_0xe3fc('0x41')]);_0x20cf62[_0xe3fc('0x42')]=_[_0xe3fc('0x43')](_0x20cf62[_0xe3fc('0x40')],_0x20cf62[_0xe3fc('0x41')]);_0x307060['attributes']=_[_0xe3fc('0x43')](_0x20cf62[_0xe3fc('0x40')],qs[_0xe3fc('0x44')](_0x198d6e[_0xe3fc('0x41')][_0xe3fc('0x44')]));_0x307060['attributes']=_0x307060[_0xe3fc('0x45')][_0xe3fc('0x60')]?_0x307060[_0xe3fc('0x45')]:_0x20cf62[_0xe3fc('0x40')];if(_0x198d6e[_0xe3fc('0x41')]['includeAll']){_0x307060[_0xe3fc('0xb6')]=[{'all':!![]}];}_0x307060=_[_0xe3fc('0x9e')]({},_0x307060,_0x198d6e['options']);return db[_0xe3fc('0x3c')]['find'](_0x307060)[_0xe3fc('0x26')](handleEntityNotFound(_0x16884f,null))[_0xe3fc('0x26')](respondWithResult(_0x16884f,null))[_0xe3fc('0x33')](handleError(_0x16884f,null));};exports[_0xe3fc('0xb7')]=function(_0x1241cd,_0x478f7d){return db[_0xe3fc('0x3c')][_0xe3fc('0xb7')](_0x1241cd['body'],{})[_0xe3fc('0x26')](respondWithResult(_0x478f7d,0xc9))['catch'](handleError(_0x478f7d,null));};exports[_0xe3fc('0xb8')]=function(_0x499dd1,_0x45eec5){if(_0x499dd1[_0xe3fc('0x72')]['id']){delete _0x499dd1[_0xe3fc('0x72')]['id'];}return db[_0xe3fc('0x3c')]['find']({'where':{'id':_0x499dd1['params']['id']}})[_0xe3fc('0x26')](handleEntityNotFound(_0x45eec5,null))[_0xe3fc('0x26')](saveUpdates(_0x499dd1[_0xe3fc('0x72')],null))[_0xe3fc('0x26')](respondWithResult(_0x45eec5,null))[_0xe3fc('0x33')](handleError(_0x45eec5,null));};exports[_0xe3fc('0xb9')]=function(_0x5517bb,_0x4ad5db){return db[_0xe3fc('0x3c')][_0xe3fc('0x61')]({'where':{'id':_0x5517bb[_0xe3fc('0xba')]['id']}})[_0xe3fc('0x26')](handleEntityNotFound(_0x4ad5db,null))[_0xe3fc('0x26')](removeEntity(_0x4ad5db,null))[_0xe3fc('0x33')](handleError(_0x4ad5db,null));};exports['describe']=function(_0x15d549,_0x578e48){return db[_0xe3fc('0x3c')][_0xe3fc('0xbb')]()[_0xe3fc('0x26')](respondWithResult(_0x578e48,null))[_0xe3fc('0x33')](handleError(_0x578e48,null));};exports[_0xe3fc('0xbc')]=function(_0x3e5daf,_0x1f121c,_0x389d15){return db['WhatsappMessage'][_0xe3fc('0x61')]({'where':{'id':_0x3e5daf[_0xe3fc('0xba')]['id']}})['then'](handleEntityNotFound(_0x1f121c,null))[_0xe3fc('0x26')](function(_0x55bc0b){if(_0x55bc0b){return _0x55bc0b['addMessage'](_0x3e5daf[_0xe3fc('0x72')][_0xe3fc('0xbd')],_['omit'](_0x3e5daf[_0xe3fc('0x72')],['ids','id'])||{});}})[_0xe3fc('0x26')](respondWithResult(_0x1f121c,null))[_0xe3fc('0x33')](handleError(_0x1f121c,null));};exports[_0xe3fc('0xbe')]=function(_0x505146,_0xb05498,_0x2f50dd){var _0x16b35d={'raw':![],'where':{}};var _0xf01caf={};var _0x5e6af2={'count':0x0,'rows':[]};return db['WhatsappInteraction'][_0xe3fc('0xbf')]({'where':{'id':_0x505146[_0xe3fc('0xba')]['id']}})[_0xe3fc('0x26')](handleEntityNotFound(_0xb05498,null))[_0xe3fc('0x26')](function(_0x1af88d){if(_0x1af88d){_0xf01caf[_0xe3fc('0x40')]=_[_0xe3fc('0x73')](db[_0xe3fc('0xc0')][_0xe3fc('0x3d')]);_0xf01caf['query']=_[_0xe3fc('0x73')](_0x505146[_0xe3fc('0x41')]);_0xf01caf[_0xe3fc('0x42')]=_['intersection'](_0xf01caf[_0xe3fc('0x40')],_0xf01caf[_0xe3fc('0x41')]);_0x16b35d['attributes']=_[_0xe3fc('0x43')](_0xf01caf[_0xe3fc('0x40')],qs[_0xe3fc('0x44')](_0x505146[_0xe3fc('0x41')][_0xe3fc('0x44')]));_0x16b35d['attributes']=_0x16b35d[_0xe3fc('0x45')][_0xe3fc('0x60')]?_0x16b35d[_0xe3fc('0x45')]:_0xf01caf[_0xe3fc('0x40')];if(!_0x505146[_0xe3fc('0x41')][_0xe3fc('0x46')](_0xe3fc('0x47'))){_0x16b35d['limit']=qs[_0xe3fc('0x20')](_0x505146[_0xe3fc('0x41')][_0xe3fc('0x20')]);_0x16b35d[_0xe3fc('0x1d')]=qs[_0xe3fc('0x1d')](_0x505146['query']['offset']);}_0x16b35d['order']=qs[_0xe3fc('0x49')](_0x505146[_0xe3fc('0x41')][_0xe3fc('0x49')]);_0x16b35d[_0xe3fc('0x4a')]=qs[_0xe3fc('0x42')](_[_0xe3fc('0x4b')](_0x505146[_0xe3fc('0x41')],_0xf01caf[_0xe3fc('0x42')]));_0x16b35d['where']['WhatsappInteractionId']=_0x1af88d['id'];if(_0x505146[_0xe3fc('0x41')]['filter']){_0x16b35d[_0xe3fc('0x4a')]=_[_0xe3fc('0x9e')](_0x16b35d[_0xe3fc('0x4a')],{'$or':_[_0xe3fc('0x2c')](_0x16b35d[_0xe3fc('0x45')],function(_0x37ebe2){var _0x2b12ff={};_0x2b12ff[_0x37ebe2]={'$like':'%'+_0x505146[_0xe3fc('0x41')][_0xe3fc('0x84')]+'%'};return _0x2b12ff;})});}if(_0x505146[_0xe3fc('0x41')][_0xe3fc('0x78')]){var _0x32066b=_0x505146[_0xe3fc('0x41')][_0xe3fc('0x78')]['split'](',');var _0xce6dcb={};_0xce6dcb[_0x32066b[0x0]]={'$gte':moment(_0x32066b[0x1])['format'](_0xe3fc('0xc1'))};_0x16b35d['where']=_['merge'](_0x16b35d['where'],_0xce6dcb);}_0x16b35d=_[_0xe3fc('0x9e')]({},_0x16b35d,_0x505146[_0xe3fc('0xc2')]);return db[_0xe3fc('0xc0')]['count']({'where':_0x16b35d[_0xe3fc('0x4a')]})[_0xe3fc('0x26')](function(_0x31ab1d){_0x5e6af2[_0xe3fc('0x1f')]=_0x31ab1d;if(_0x505146[_0xe3fc('0x41')][_0xe3fc('0xc3')]){_0x16b35d[_0xe3fc('0xb6')]=[{'all':!![]}];}return db[_0xe3fc('0xc0')][_0xe3fc('0xc4')](_0x16b35d);})[_0xe3fc('0x26')](function(_0x3ded1e){_0x5e6af2[_0xe3fc('0xb4')]=_0x3ded1e;return _0x5e6af2;});}})['then'](respondWithFilteredResult(_0xb05498,_0x16b35d))[_0xe3fc('0x33')](handleError(_0xb05498,null));};exports[_0xe3fc('0xc5')]=function(_0x15c597,_0xad69a4,_0x353079){return db[_0xe3fc('0x3c')][_0xe3fc('0x61')]({'where':{'id':_0x15c597[_0xe3fc('0xba')]['id']}})[_0xe3fc('0x26')](handleEntityNotFound(_0xad69a4,null))['then'](function(_0x28b6f3){if(_0x28b6f3){return _0x28b6f3[_0xe3fc('0xc6')](_0x15c597[_0xe3fc('0x72')][_0xe3fc('0xbd')],_['omit'](_0x15c597[_0xe3fc('0x72')],[_0xe3fc('0xbd'),'id'])||{})[_0xe3fc('0xc7')](function(){return db[_0xe3fc('0x70')][_0xe3fc('0xc4')]({'attributes':['id',_0xe3fc('0x29'),_0xe3fc('0x4e')],'where':{'id':_0x15c597[_0xe3fc('0x72')][_0xe3fc('0xbd')]}});})[_0xe3fc('0x26')](function(_0x2ca11c){socket[_0xe3fc('0xc8')](_0xe3fc('0xc9'),{'id':Number(_0x15c597[_0xe3fc('0xba')]['id']),'tags':_0x2ca11c||[]});return{'id':Number(_0x15c597[_0xe3fc('0xba')]['id']),'tags':_0x2ca11c||[]};});}})['then'](respondWithResult(_0xad69a4,null))[_0xe3fc('0x33')](handleError(_0xad69a4,null));};exports[_0xe3fc('0xca')]=function(_0x2c640e,_0x55abbc,_0x2dd21d){return db[_0xe3fc('0x3c')][_0xe3fc('0x61')]({'where':{'id':_0x2c640e['params']['id']}})['then'](handleEntityNotFound(_0x55abbc,null))['then'](function(_0x249791){if(_0x249791){return _0x249791[_0xe3fc('0xca')](_0x2c640e[_0xe3fc('0x41')]['ids']);}})[_0xe3fc('0x26')](respondWithStatusCode(_0x55abbc,null))[_0xe3fc('0x33')](handleError(_0x55abbc,null));};exports[_0xe3fc('0xcb')]=function(_0x3ad74d,_0x23e903){var _0x70f5bc=moment()[_0xe3fc('0xcc')]()[_0xe3fc('0x9c')]();var _0x1fae1e=path['join'](config[_0xe3fc('0xcd')],_0xe3fc('0xce'),_0xe3fc('0xcf'),'tmp');var _0x3469b0=path['join'](config[_0xe3fc('0xcd')],_0xe3fc('0xce'),_0xe3fc('0xcf'),'attachments');var _0x4f8a93=path[_0xe3fc('0xd0')](_0x1fae1e,_0x70f5bc);var _0x1d7d5e=util['format'](_0xe3fc('0xd1'),_0x3ad74d[_0xe3fc('0xba')]['id'],_0x70f5bc);var _0x49b737=path[_0xe3fc('0xd0')](_0x1fae1e,_0x1d7d5e);var _0x4b9129=[];_0x4b9129[_0xe3fc('0x32')]({'model':db['User'],'as':'User','attributes':['id',_0xe3fc('0x2d')],'raw':!![]});_0x4b9129['push']({'model':db[_0xe3fc('0xd2')],'as':_0xe3fc('0x64'),'attributes':['id',_0xe3fc('0xd3'),_0xe3fc('0xd4')],'raw':!![]});if(_0x3ad74d[_0xe3fc('0x41')][_0xe3fc('0xd5')]){_0x4b9129['push']({'model':db[_0xe3fc('0xd6')],'as':_0xe3fc('0xd6'),'raw':!![]});}var _0x24dbb0=[{'model':db['WhatsappMessage'],'as':_0xe3fc('0xd7'),'attributes':['id',_0xe3fc('0x72'),_0xe3fc('0x77'),'direction','secret',_0xe3fc('0x7d')],'include':_0x4b9129}];_0x24dbb0[_0xe3fc('0x32')]({'model':db[_0xe3fc('0xd8')],'as':_0xe3fc('0xd9'),'attributes':['id',_0xe3fc('0x29')]});_0x24dbb0[_0xe3fc('0x32')]({'model':db['User'],'as':_0xe3fc('0xda'),'attributes':['id',_0xe3fc('0x2d')]});return db['WhatsappInteraction'][_0xe3fc('0x61')]({'where':{'id':_0x3ad74d['params']['id']},'include':_0x24dbb0})['then'](handleEntityNotFound(_0x23e903,null))[_0xe3fc('0x26')](function(_0x16e173){if(_0x16e173){var _0x23752b=_0x16e173[_0xe3fc('0xdb')]({'plain':!![]});fs['mkdirSync'](_0x4f8a93);var _0x3a4c4b={'channel':_0xe3fc('0xdc'),'account':_0x23752b[_0xe3fc('0xd9')][_0xe3fc('0x29')],'agent':_0x23752b[_0xe3fc('0xda')]?_0x23752b[_0xe3fc('0xda')][_0xe3fc('0x2d')]:_0xe3fc('0xdd'),'createdAt':moment(_0x23752b[_0xe3fc('0x77')])[_0xe3fc('0xde')]('YYYY-MM-DD\x20HH:mm:ss')[_0xe3fc('0x9c')](),'closedAt':_0x23752b[_0xe3fc('0x39')]?moment(_0x23752b['closedAt'])[_0xe3fc('0xde')](_0xe3fc('0xc1'))['toString']():'','disposition':_0x23752b['disposition'],'messages':_(_0x23752b[_0xe3fc('0xd7')])[_0xe3fc('0x84')]({'secret':![]})[_0xe3fc('0x2c')](function(_0x447c7b){if(_0x447c7b[_0xe3fc('0xd6')]){var _0x211124=path[_0xe3fc('0xd0')](_0x3469b0,_0x447c7b[_0xe3fc('0xd6')][_0xe3fc('0xdf')]);if(fs[_0xe3fc('0xe0')](_0x211124)){fs[_0xe3fc('0xe1')](_0x211124)[_0xe3fc('0xe2')](fs[_0xe3fc('0xe3')](path[_0xe3fc('0xd0')](_0x4f8a93,_0x447c7b[_0xe3fc('0xd6')][_0xe3fc('0xdf')])));}}return{'date':moment(_0x447c7b[_0xe3fc('0x77')])[_0xe3fc('0xde')]('YYYY-MM-DD\x20HH:mm:ss')[_0xe3fc('0x9c')](),'sender':_0x447c7b['direction']===_0xe3fc('0xe4')?_0x447c7b[_0xe3fc('0xe5')]?_0x447c7b['User'][_0xe3fc('0x2d')]:'System':_0x447c7b['Contact'][_0xe3fc('0xd3')]+(_0x447c7b[_0xe3fc('0x64')][_0xe3fc('0xd4')]?'\x20'+_0x447c7b[_0xe3fc('0x64')]['lastName']:''),'body':_0x447c7b[_0xe3fc('0xd6')]?_0x447c7b['Attachment'][_0xe3fc('0xdf')]:_0x447c7b['body'],'direction':_0x447c7b[_0xe3fc('0xe6')]===_0xe3fc('0xe4')?'A':'C','secret':_0x447c7b[_0xe3fc('0xe7')],'read':_0x447c7b[_0xe3fc('0x7d')],'attachment':_0x447c7b[_0xe3fc('0xd6')]};})[_0xe3fc('0x62')]()};return ejs[_0xe3fc('0xe8')](path[_0xe3fc('0xd0')](config['root'],_0xe3fc('0xce'),_0xe3fc('0xe9'),_0xe3fc('0xea')),{'interaction':_0x3a4c4b})['then'](function(_0x3bac08){var _0x24c91c=path['join'](_0x4f8a93,'transcript-'+_0x23752b['id']+'-'+_0x70f5bc+_0xe3fc('0xeb'));var _0x1df0c3={'path':_0x24c91c,'channel':_0xe3fc('0xdc'),'interactionId':_0x23752b['id']};return pdf[_0xe3fc('0xec')](_0x3bac08,_0x1df0c3);})[_0xe3fc('0x26')](function(){return new BPromise(function(_0x177d7d,_0xa0ad35){zipdir(_0x4f8a93,{'saveTo':_0x49b737},function(_0x524e03,_0x22d3fc){if(_0x524e03)return _0xa0ad35(_0x524e03);return _0x177d7d(_0x22d3fc);});})[_0xe3fc('0x26')](function(){return new BPromise(function(_0x5f344e,_0x1ddcfe){rimraf(_0x4f8a93,function(_0x31428a){if(_0x31428a)_0x1ddcfe(_0x31428a);return _0x5f344e();});});})[_0xe3fc('0x26')](function(){return _0x23e903[_0xe3fc('0xcb')](_0x49b737,_0x1d7d5e,function(_0x160d76){if(_0x160d76){console[_0xe3fc('0xed')]('err',_0x160d76);}else{fs['unlinkSync'](_0x49b737);}});});});}else{return _0x23e903[_0xe3fc('0x1b')](0xc8);}})[_0xe3fc('0x33')](handleError(_0x23e903,null));};
\ No newline at end of file
+var _0xd5c8=['i.createdAt\x20BETWEEN\x20?\x20AND\x20?','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','filter','replace','isNumeric','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','i.id','Sequelize','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','getWhatsappAccounts','sequelize','toString','keyBy','merge','a.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','Contact.firstName','c.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','WhatsappInteractionId','push','all','rows','show','params','filters','includeAll','include','options','WhatsappInteraction','destroy','describe','addMessage','ids','WhatsappMessage','hasOwnProperty','findAll','addTags','setTags','omit','spread','emit','whatsappInteractionTags:save','removeTags','download','unix','join','server','files','tmp','root','format','transcript-%d-%s.zip','CmContact','firstName','lastName','attachments','Attachment','Messages','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','disposition','basename','existsSync','createReadStream','createWriteStream','out','System','views','downloadInteraction.ejs','createPdfFromHTML','log','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','offset','undefined','count','limit','set','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','catch','waiting','talking','answered','unmanaged','total','closed','UserId','index','rawAttributes','fieldName','model','query','attributes','intersection','fields','length','nolimit','order','sort','pick','select','field','color','from','tools_tags','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','left_join','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','end','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','text','body','type','keys','some','compact','isEmpty','WhatsappAccountId','where','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte'];(function(_0x29712d,_0xb0fcad){var _0x2ee031=function(_0x53d196){while(--_0x53d196){_0x29712d['push'](_0x29712d['shift']());}};_0x2ee031(++_0xb0fcad);}(_0xd5c8,0x166));var _0x8d5c=function(_0x471448,_0x1c0e9e){_0x471448=_0x471448-0x0;var _0x38190b=_0xd5c8[_0x471448];return _0x38190b;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x8d5c('0x0'));var jsonpatch=require(_0x8d5c('0x1'));var rp=require(_0x8d5c('0x2'));var moment=require(_0x8d5c('0x3'));var BPromise=require(_0x8d5c('0x4'));var Mustache=require(_0x8d5c('0x5'));var util=require(_0x8d5c('0x6'));var path=require(_0x8d5c('0x7'));var sox=require(_0x8d5c('0x8'));var csv=require('to-csv');var ejs=require(_0x8d5c('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x8d5c('0xa'));var crypto=require(_0x8d5c('0xb'));var jsforce=require(_0x8d5c('0xc'));var deskjs=require(_0x8d5c('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8d5c('0xe'));var Redis=require('ioredis');var authService=require(_0x8d5c('0xf'));var qs=require(_0x8d5c('0x10'));var as=require(_0x8d5c('0x11'));var pdf=require(_0x8d5c('0x12'));var hardwareService=require(_0x8d5c('0x13'));var logger=require(_0x8d5c('0x14'))(_0x8d5c('0x15'));var utils=require(_0x8d5c('0x16'));var config=require(_0x8d5c('0x17'));var licenseUtil=require(_0x8d5c('0x18'));var db=require(_0x8d5c('0x19'))['db'];config[_0x8d5c('0x1a')]=_['defaults'](config[_0x8d5c('0x1a')],{'host':_0x8d5c('0x1b'),'port':0x18eb});var socket=require(_0x8d5c('0x1c'))(new Redis(config[_0x8d5c('0x1a')]));require(_0x8d5c('0x1d'))[_0x8d5c('0x1e')](socket);function respondWithStatusCode(_0x3c26e3,_0x330a94){_0x330a94=_0x330a94||0xcc;return function(_0x516388){if(_0x516388){return _0x3c26e3[_0x8d5c('0x1f')](_0x330a94);}return _0x3c26e3[_0x8d5c('0x20')](_0x330a94)['end']();};}function respondWithResult(_0x56878f,_0x645f26){_0x645f26=_0x645f26||0xc8;return function(_0x4a1dab){if(_0x4a1dab){return _0x56878f['status'](_0x645f26)['json'](_0x4a1dab);}};}function respondWithFilteredResult(_0xa5fbe5,_0x43f233){return function(_0x200846){if(_0x200846){var _0x189005=typeof _0x43f233[_0x8d5c('0x21')]===_0x8d5c('0x22')&&typeof _0x43f233['limit']==='undefined';var _0x51d5da=_0x200846['count'];var _0x379bfb=_0x189005?0x0:_0x43f233[_0x8d5c('0x21')];var _0x31cd31=_0x189005?_0x200846[_0x8d5c('0x23')]:_0x43f233[_0x8d5c('0x21')]+_0x43f233[_0x8d5c('0x24')];var _0x167c74;if(_0x31cd31>=_0x51d5da){_0x31cd31=_0x51d5da;_0x167c74=0xc8;}else{_0x167c74=0xce;}_0xa5fbe5[_0x8d5c('0x20')](_0x167c74);return _0xa5fbe5[_0x8d5c('0x25')](_0x8d5c('0x26'),_0x379bfb+'-'+_0x31cd31+'/'+_0x51d5da)[_0x8d5c('0x27')](_0x200846);}return null;};}function patchUpdates(_0x4e87dd){return function(_0x2f067f){try{jsonpatch[_0x8d5c('0x28')](_0x2f067f,_0x4e87dd,!![]);}catch(_0x4c0cdf){return BPromise[_0x8d5c('0x29')](_0x4c0cdf);}return _0x2f067f[_0x8d5c('0x2a')]();};}function saveUpdates(_0x11b4f8,_0x47519d){return function(_0x568bcf){if(_0x568bcf){return _0x568bcf[_0x8d5c('0x2b')](_0x11b4f8)[_0x8d5c('0x2c')](function(_0x506828){return _0x506828;});}return null;};}function removeEntity(_0x5e0daa,_0x1e36d8){return function(_0xa8aeac){if(_0xa8aeac){return _0xa8aeac['destroy']()['then'](function(){_0x5e0daa[_0x8d5c('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5d40ba,_0x20c2f3){return function(_0x2be887){if(!_0x2be887){_0x5d40ba[_0x8d5c('0x1f')](0x194);}return _0x2be887;};}function handleError(_0x130af7,_0xd060b1){_0xd060b1=_0xd060b1||0x1f4;return function(_0x2302a8){logger[_0x8d5c('0x2d')](_0x2302a8[_0x8d5c('0x2e')]);if(_0x2302a8['name']){delete _0x2302a8[_0x8d5c('0x2f')];}_0x130af7[_0x8d5c('0x20')](_0xd060b1)[_0x8d5c('0x30')](_0x2302a8);};}function getInteractionUsers(_0x58feb4,_0xe7290){return new BPromise(function(_0x3116c5,_0x3f9d1a){try{if(_0xe7290[_0x58feb4['id']]){_0x58feb4[_0x8d5c('0x31')]=_[_0x8d5c('0x32')](_0xe7290[_0x58feb4['id']],function(_0x152517){return{'id':_0x152517['id'],'fullname':_0x152517[_0x8d5c('0x33')]};});}}catch(_0x3519da){_0x3f9d1a(_0x3519da);}_0x3116c5(_0x58feb4);});}function getInteractionTags(_0x37b9d0,_0x417d87){return new BPromise(function(_0x2c1464,_0x3036a9){try{if(_0x37b9d0[_0x8d5c('0x34')]){_0x37b9d0[_0x8d5c('0x35')]=[];_0x37b9d0[_0x8d5c('0x34')][_0x8d5c('0x36')](',')[_0x8d5c('0x37')](function(_0x427311){_0x37b9d0['Tags']['push'](_0x417d87[_0x427311]);});}delete _0x37b9d0['TagIds'];}catch(_0x5b64c6){_0x3036a9(_0x5b64c6);}_0x2c1464(_0x37b9d0);});}function updateWhatsappInteraction(_0x661bec,_0x216900,_0x348a43){return new BPromise(function(_0x4bb598,_0x2248dd){return getInteractionUsers(_0x661bec,_0x348a43)[_0x8d5c('0x2c')](function(_0x1339a9){return getInteractionTags(_0x1339a9,_0x216900);})[_0x8d5c('0x2c')](function(_0x57d2e1){return getStateInteraction(_0x57d2e1);})[_0x8d5c('0x2c')](function(_0x54a5d6){_0x4bb598(_0x54a5d6);})[_0x8d5c('0x38')](function(_0x52b656){_0x2248dd(_0x52b656);});});}function getStateInteraction(_0x51f6bc){return new BPromise(function(_0x21e114){_0x51f6bc[_0x8d5c('0x39')]=0x0;_0x51f6bc[_0x8d5c('0x3a')]=0x0;_0x51f6bc[_0x8d5c('0x3b')]=0x0;_0x51f6bc[_0x8d5c('0x3c')]=0x0;_0x51f6bc[_0x8d5c('0x3d')]=0x0;if(!_0x51f6bc[_0x8d5c('0x3e')]&&!_0x51f6bc[_0x8d5c('0x3f')]){_0x51f6bc[_0x8d5c('0x39')]+=0x1;}if(!_0x51f6bc[_0x8d5c('0x3e')]&&_0x51f6bc[_0x8d5c('0x3f')]){_0x51f6bc[_0x8d5c('0x3a')]+=0x1;if(_0x51f6bc['waiting']){_0x51f6bc['waiting']-=0x1;}}if(_0x51f6bc['closed']&&_0x51f6bc['UserId']){_0x51f6bc['answered']+=0x1;if(_0x51f6bc[_0x8d5c('0x3a')]){_0x51f6bc[_0x8d5c('0x3a')]-=0x1;}}if(_0x51f6bc['closed']&&!_0x51f6bc[_0x8d5c('0x3f')]){_0x51f6bc[_0x8d5c('0x3c')]+=0x1;if(_0x51f6bc[_0x8d5c('0x39')]){_0x51f6bc[_0x8d5c('0x39')]-=0x1;}}_0x51f6bc[_0x8d5c('0x3d')]+=0x1;_0x21e114(_0x51f6bc);});}exports[_0x8d5c('0x40')]=function(_0x4ca52d,_0x56f15b){var _0x210134={},_0x10eeef={},_0x5fd4f2={'count':0x0,'rows':[]};var _0xdad44b=_[_0x8d5c('0x32')](db['WhatsappInteraction'][_0x8d5c('0x41')],function(_0x3d01b1){return{'name':_0x3d01b1[_0x8d5c('0x42')],'type':_0x3d01b1['type']['key']};});_0x10eeef[_0x8d5c('0x43')]=_[_0x8d5c('0x32')](_0xdad44b,_0x8d5c('0x2f'));_0x10eeef[_0x8d5c('0x44')]=_['keys'](_0x4ca52d['query']);_0x10eeef['filters']=_['intersection'](_0x10eeef[_0x8d5c('0x43')],_0x10eeef[_0x8d5c('0x44')]);_0x210134[_0x8d5c('0x45')]=_[_0x8d5c('0x46')](_0x10eeef[_0x8d5c('0x43')],qs[_0x8d5c('0x47')](_0x4ca52d['query'][_0x8d5c('0x47')]));_0x210134[_0x8d5c('0x45')]=_0x210134[_0x8d5c('0x45')][_0x8d5c('0x48')]?_0x210134[_0x8d5c('0x45')]:_0x10eeef[_0x8d5c('0x43')];if(!_0x4ca52d[_0x8d5c('0x44')]['hasOwnProperty'](_0x8d5c('0x49'))){_0x210134[_0x8d5c('0x24')]=qs['limit'](_0x4ca52d[_0x8d5c('0x44')]['limit']);_0x210134[_0x8d5c('0x21')]=qs[_0x8d5c('0x21')](_0x4ca52d[_0x8d5c('0x44')]['offset']);}_0x210134[_0x8d5c('0x4a')]=qs[_0x8d5c('0x4b')](_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x4b')]);_0x210134['where']=qs['filters'](_[_0x8d5c('0x4c')](_0x4ca52d[_0x8d5c('0x44')],_0x10eeef['filters']),_0xdad44b);var _0x32a2c0=[];var _0x118ef7=squel[_0x8d5c('0x4d')]()[_0x8d5c('0x4e')]('id')[_0x8d5c('0x4e')]('name')[_0x8d5c('0x4e')](_0x8d5c('0x4f'))[_0x8d5c('0x50')](_0x8d5c('0x51'));var _0x326a1c=squel[_0x8d5c('0x4d')]()[_0x8d5c('0x4e')]('u.id')[_0x8d5c('0x4e')](_0x8d5c('0x52'))[_0x8d5c('0x4e')](_0x8d5c('0x53'))[_0x8d5c('0x50')](_0x8d5c('0x54'),'ui')[_0x8d5c('0x55')](_0x8d5c('0x56'),'u',_0x8d5c('0x57'));var _0xf39d50=squel[_0x8d5c('0x4d')]()[_0x8d5c('0x50')](_0x8d5c('0x58'),'i')['left_join'](_0x8d5c('0x59'),'c',_0x8d5c('0x5a'))[_0x8d5c('0x55')](_0x8d5c('0x56'),'o','o.id\x20=\x20i.UserId')['left_join'](_0x8d5c('0x5b'),'a',_0x8d5c('0x5c'))[_0x8d5c('0x55')](_0x8d5c('0x5d'),'me','me.WhatsappInteractionId\x20=\x20i.id')[_0x8d5c('0x55')](_0x8d5c('0x5e'),'it',_0x8d5c('0x5f'))[_0x8d5c('0x55')](_0x8d5c('0x51'),'t',_0x8d5c('0x60'));var _0x3d3b20=squel[_0x8d5c('0x61')]();var _0x2e2523=[];var _0x201b12=squel[_0x8d5c('0x61')]();var _0x2b3092;if(_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x62')]){_0x2b3092=as[_0x8d5c('0x63')](_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x62')]);var _0x430d74=_0x2b3092[_0x8d5c('0x64')];for(var _0x499cfb=0x0;_0x499cfb<_0x2b3092['conditions'][_0x8d5c('0x48')];_0x499cfb++){var _0x11c864=_0x2b3092[_0x8d5c('0x65')][_0x499cfb];var _0xea4028='i';var _0x1e3470=_[_0x8d5c('0x66')](_0xdad44b,[_0x8d5c('0x2f'),_0x11c864[_0x8d5c('0x4e')]]);if(!_0x1e3470){switch(_0x11c864[_0x8d5c('0x4e')]){case _0x8d5c('0x67'):if(_0x11c864[_0x8d5c('0x68')]==0x1){_0xf39d50[_0x8d5c('0x69')]('`'+_0x11c864[_0x8d5c('0x4e')]+_0x8d5c('0x6a'));}else{_0xf39d50[_0x8d5c('0x69')]('`'+_0x11c864[_0x8d5c('0x4e')]+_0x8d5c('0x6b'));}break;case _0x8d5c('0x6c'):if(_0x11c864[_0x8d5c('0x6d')]===_0x8d5c('0x6e')){if(_0x11c864[_0x8d5c('0x68')]['split']('\x20')[_0x8d5c('0x48')]>0x1){_0x3d3b20[_0x430d74]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x8d5c('0x6f')](_0x11c864[_0x8d5c('0x68')]),null);}else{var _0x3cc4e6='%'+_0x11c864[_0x8d5c('0x68')]+'%';_0x3d3b20[_0x430d74](_0x8d5c('0x70'),_0x3cc4e6,_0x3cc4e6,_0x3cc4e6);}}else{_0x1e3470=_['find'](_0xdad44b,['name',_0x8d5c('0x71')]);_0x11c864[_0x8d5c('0x4e')]=_0x8d5c('0x71');_0x9b5d3d=as[_0x8d5c('0x72')](_0xea4028,_0x1e3470['type'],_0x11c864);_0x3d3b20[_0x430d74](_0x9b5d3d['text'],_0x9b5d3d[_0x8d5c('0x68')][_0x8d5c('0x73')],_0x9b5d3d[_0x8d5c('0x68')][_0x8d5c('0x74')]);}break;case _0x8d5c('0x75'):var _0x1e5207=_0x11c864['value'][_0x8d5c('0x36')](',')[_0x8d5c('0x32')](function(_0x527930){return Number(_0x527930);});_0x1e5207[_0x8d5c('0x37')](function(_0x4cc59b){_0x201b12['or'](_0x8d5c('0x76'),'%,'+_0x4cc59b+',%');});_0x2e2523=_[_0x8d5c('0x77')](_0x2e2523,_0x1e5207);break;case _0x8d5c('0x78'):if(_0x11c864['operator']==='$substring'){_0x3d3b20[_0x430d74]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x11c864['value']+'%',null);}else{_0x1e3470=_[_0x8d5c('0x66')](_0xdad44b,[_0x8d5c('0x2f'),_0x8d5c('0x3f')]);_0x11c864[_0x8d5c('0x4e')]=_0x8d5c('0x3f');_0x9b5d3d=as[_0x8d5c('0x72')](_0xea4028,_0x1e3470['type'],_0x11c864);_0x3d3b20[_0x430d74](_0x9b5d3d[_0x8d5c('0x79')],_0x9b5d3d['value'][_0x8d5c('0x73')],_0x9b5d3d[_0x8d5c('0x68')][_0x8d5c('0x74')]);}break;case _0x8d5c('0x7a'):_0x9b5d3d=as[_0x8d5c('0x72')]('me',null,_0x11c864);_0x3d3b20[_0x430d74](_0x9b5d3d[_0x8d5c('0x79')],_0x9b5d3d[_0x8d5c('0x68')]['start'],_0x9b5d3d['value'][_0x8d5c('0x74')]);break;}}else{var _0x9b5d3d=as[_0x8d5c('0x72')](_0xea4028,_0x1e3470[_0x8d5c('0x7b')],_0x11c864);_0x3d3b20[_0x430d74](_0x9b5d3d[_0x8d5c('0x79')],_0x9b5d3d[_0x8d5c('0x68')][_0x8d5c('0x73')],_0x9b5d3d['value'][_0x8d5c('0x74')]);}}}else{var _0x46eb29=_(_0x4ca52d[_0x8d5c('0x44')])[_0x8d5c('0x7c')]()[_0x8d5c('0x32')](function(_0x4e2ed7){return _[_0x8d5c('0x7d')](_0xdad44b,['name',_0x4e2ed7])?_0x4e2ed7:undefined;})[_0x8d5c('0x7e')]()[_0x8d5c('0x68')]();if(!_[_0x8d5c('0x7f')](_0x46eb29)){_0x46eb29[_0x8d5c('0x37')](function(_0x2e816e){if(_0x2e816e===_0x8d5c('0x80')){_0xf39d50[_0x8d5c('0x81')](_0x8d5c('0x82'),[][_0x8d5c('0x83')](_0x4ca52d[_0x8d5c('0x44')][_0x2e816e]));}else if(_0x2e816e===_0x8d5c('0x84')){var _0x367fe5=JSON[_0x8d5c('0x85')](_0x4ca52d[_0x8d5c('0x44')][_0x2e816e])[_0x8d5c('0x86')];var _0x42e541=JSON['parse'](_0x4ca52d[_0x8d5c('0x44')][_0x2e816e])[_0x8d5c('0x87')];_0xf39d50['where'](_0x8d5c('0x88'),_0x367fe5,_0x42e541);}else{if(_0x4ca52d['query'][_0x2e816e]==='null'){_0xf39d50[_0x8d5c('0x81')]('i.'+_0x2e816e+_0x8d5c('0x89'));}else{_0xf39d50[_0x8d5c('0x81')]('i.'+_0x2e816e+_0x8d5c('0x8a'),_0x4ca52d[_0x8d5c('0x44')][_0x2e816e]);}}});}if(_0x4ca52d['query'][_0x8d5c('0x8b')]){if(_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x8b')]==0x1){_0xf39d50['having'](_0x8d5c('0x8c'));}else{_0xf39d50[_0x8d5c('0x69')](_0x8d5c('0x8d'));}}if(_0x4ca52d[_0x8d5c('0x44')]['tag']){_0x2e2523=_[_0x8d5c('0x8e')](_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x8f')])?_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x8f')]:new Array(_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x8f')]);_0x2e2523['forEach'](function(_0x7c9019){_0x201b12['or'](_0x8d5c('0x76'),'%,'+_0x7c9019+',%');});}if(_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x90')]){var _0x90061d=_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x90')][_0x8d5c('0x91')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0x8d5c('0x92')](_0x90061d)){_0x3d3b20['or']('i.id\x20LIKE\x20?',_0x90061d+'%')['or']('i.phone\x20LIKE\x20?',_0x90061d+'%');}else{_0x3d3b20['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x8d5c('0x6f')](_0x90061d))['or'](_0x8d5c('0x93'),_0x90061d+'%');}}}_0xf39d50[_0x8d5c('0x81')](_0x3d3b20);_0xf39d50['group'](_0x8d5c('0x94'));var _0x5e86f5={'type':db[_0x8d5c('0x95')]['QueryTypes'][_0x8d5c('0x96')],'raw':!![]};var _0x42cc7a=_0xf39d50['clone']();_0x42cc7a[_0x8d5c('0x4e')](_0x8d5c('0x94'));_0x42cc7a[_0x8d5c('0x4e')](_0x8d5c('0x97'),_0x8d5c('0x67'));if(_0x210134['order']){_0x210134[_0x8d5c('0x4a')][_0x8d5c('0x37')](function(_0xfc4a61){var _0x317239=_0xfc4a61[0x0]===_0x8d5c('0x98')?_0xfc4a61[0x0]:'i.'+_0xfc4a61[0x0];_0xf39d50[_0x8d5c('0x4a')](_0x317239,_0xfc4a61[0x1]===_0x8d5c('0x99')?![]:!![]);});}if(!_[_0x8d5c('0x7f')](_0x2e2523)){_0xf39d50[_0x8d5c('0x69')](_0x201b12);_0x42cc7a[_0x8d5c('0x81')](_0x8d5c('0x9a'),_0x2e2523);}BPromise[_0x8d5c('0x9b')]()[_0x8d5c('0x2c')](function(){if(!_0x2b3092){if(_0x4ca52d['query'][_0x8d5c('0x80')])return;_0x42cc7a['where'](_0x8d5c('0x9c'));_0xf39d50[_0x8d5c('0x81')](_0x8d5c('0x9c'));return;}if(_0x4ca52d[_0x8d5c('0x9d')][_0x8d5c('0x9e')]!=='agent')return;return _0x4ca52d[_0x8d5c('0x9d')][_0x8d5c('0x9f')]({'attributes':['id'],'raw':!![]})[_0x8d5c('0x2c')](function(_0x4b49b9){if(_[_0x8d5c('0x7f')](_0x4b49b9)){_0x42cc7a['where']('i.WhatsappAccountId\x20IS\x20NULL');_0xf39d50[_0x8d5c('0x81')]('i.WhatsappAccountId\x20IS\x20NULL');}else{_0x42cc7a[_0x8d5c('0x81')]('i.WhatsappAccountId\x20IN\x20?',_['map'](_0x4b49b9,'id'));_0xf39d50['where'](_0x8d5c('0x82'),_[_0x8d5c('0x32')](_0x4b49b9,'id'));}});})[_0x8d5c('0x2c')](function(){if(_0x4ca52d[_0x8d5c('0x9d')][_0x8d5c('0x9e')]==='agent'&&!_0x2b3092&&!_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x80')])return[];return db[_0x8d5c('0xa0')][_0x8d5c('0x44')](_0x42cc7a[_0x8d5c('0xa1')](),_0x5e86f5);})[_0x8d5c('0x2c')](function(_0x4228d5){_0x5fd4f2[_0x8d5c('0x23')]=_0x4228d5[_0x8d5c('0x48')];if(_0x5fd4f2['count']===0x0)return[];return db['sequelize']['query'](_0x118ef7[_0x8d5c('0xa1')](),_0x5e86f5)['then'](function(_0x54ca67){_0x32a2c0=_[_0x8d5c('0xa2')](_0x54ca67,'id');_0x5e86f5=_[_0x8d5c('0xa3')](_0x5e86f5,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x4ca52d[_0x8d5c('0x44')][_0x8d5c('0x47')]){_0x210134[_0x8d5c('0x45')][_0x8d5c('0x37')](function(_0x51e1ba){_0xf39d50[_0x8d5c('0x4e')]('i.'+_0x51e1ba);});}else{_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0x97'),_0x8d5c('0x67'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xa4'),'Account.key');_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xa5'),_0x8d5c('0xa6'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xa7'),_0x8d5c('0x98'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xa8'));_0xf39d50['field'](_0x8d5c('0xa9'),_0x8d5c('0xaa'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xab'),'Contact.lastName');_0xf39d50['field'](_0x8d5c('0xac'),_0x8d5c('0xad'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xae'),_0x8d5c('0xaf'));_0xf39d50['field'](_0x8d5c('0xb0'),_0x8d5c('0xb1'));_0xf39d50['field'](_0x8d5c('0xb2'),'Contact.fax');_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xb3'),_0x8d5c('0xb4'));_0xf39d50[_0x8d5c('0x4e')](_0x8d5c('0xb5'),_0x8d5c('0xb6'));_0xf39d50['field'](_0x8d5c('0xb7'),_0x8d5c('0x34'));}if(_0x210134[_0x8d5c('0x24')])_0xf39d50[_0x8d5c('0x24')](_0x210134[_0x8d5c('0x24')]);if(_0x210134['offset'])_0xf39d50[_0x8d5c('0x21')](_0x210134[_0x8d5c('0x21')]);return db[_0x8d5c('0xa0')][_0x8d5c('0x44')](_0xf39d50[_0x8d5c('0xa1')](),_0x5e86f5);})[_0x8d5c('0x2c')](function(_0x5e6cc0){if(_0x5e6cc0[_0x8d5c('0x48')]>0x0)_0x326a1c['where']('ui.WhatsappInteractionId\x20IN\x20?',_[_0x8d5c('0x32')](_0x5e6cc0,'id'));return db[_0x8d5c('0xa0')][_0x8d5c('0x44')](_0x326a1c[_0x8d5c('0xa1')](),_0x5e86f5)[_0x8d5c('0x2c')](function(_0x4d37c7){var _0x2f9135=_[_0x8d5c('0xb8')](_0x4d37c7,_0x8d5c('0xb9'));var _0x484f23=[];_0x5e6cc0[_0x8d5c('0x37')](function(_0x2a05b7){_0x484f23[_0x8d5c('0xba')](updateWhatsappInteraction(_0x2a05b7,_0x32a2c0,_0x2f9135));});return BPromise[_0x8d5c('0xbb')](_0x484f23);});});})[_0x8d5c('0x2c')](function(_0x255081){_0x5fd4f2[_0x8d5c('0xbc')]=_0x255081;return _0x5fd4f2;})[_0x8d5c('0x2c')](respondWithFilteredResult(_0x56f15b,_0x210134))[_0x8d5c('0x38')](handleError(_0x56f15b,null));};exports[_0x8d5c('0xbd')]=function(_0x1644b6,_0x39a225){var _0xffae91={'raw':![],'where':{'id':_0x1644b6[_0x8d5c('0xbe')]['id']}},_0x329ba5={};_0x329ba5[_0x8d5c('0x43')]=_[_0x8d5c('0x7c')](db['WhatsappInteraction'][_0x8d5c('0x41')]);_0x329ba5[_0x8d5c('0x44')]=_['keys'](_0x1644b6['query']);_0x329ba5[_0x8d5c('0xbf')]=_[_0x8d5c('0x46')](_0x329ba5['model'],_0x329ba5[_0x8d5c('0x44')]);_0xffae91[_0x8d5c('0x45')]=_[_0x8d5c('0x46')](_0x329ba5['model'],qs[_0x8d5c('0x47')](_0x1644b6[_0x8d5c('0x44')]['fields']));_0xffae91['attributes']=_0xffae91[_0x8d5c('0x45')]['length']?_0xffae91['attributes']:_0x329ba5[_0x8d5c('0x43')];if(_0x1644b6['query'][_0x8d5c('0xc0')]){_0xffae91[_0x8d5c('0xc1')]=[{'all':!![]}];}_0xffae91=_[_0x8d5c('0xa3')]({},_0xffae91,_0x1644b6[_0x8d5c('0xc2')]);return db[_0x8d5c('0xc3')]['find'](_0xffae91)['then'](handleEntityNotFound(_0x39a225,null))[_0x8d5c('0x2c')](respondWithResult(_0x39a225,null))[_0x8d5c('0x38')](handleError(_0x39a225,null));};exports['create']=function(_0x5e0b0d,_0x50b820){return db[_0x8d5c('0xc3')]['create'](_0x5e0b0d[_0x8d5c('0x7a')],{})[_0x8d5c('0x2c')](respondWithResult(_0x50b820,0xc9))['catch'](handleError(_0x50b820,null));};exports[_0x8d5c('0x2b')]=function(_0x3914a7,_0x1bba3c){if(_0x3914a7['body']['id']){delete _0x3914a7[_0x8d5c('0x7a')]['id'];}return db['WhatsappInteraction'][_0x8d5c('0x66')]({'where':{'id':_0x3914a7[_0x8d5c('0xbe')]['id']}})[_0x8d5c('0x2c')](handleEntityNotFound(_0x1bba3c,null))['then'](saveUpdates(_0x3914a7[_0x8d5c('0x7a')],null))['then'](respondWithResult(_0x1bba3c,null))[_0x8d5c('0x38')](handleError(_0x1bba3c,null));};exports[_0x8d5c('0xc4')]=function(_0x4f409f,_0x2e0970){return db[_0x8d5c('0xc3')][_0x8d5c('0x66')]({'where':{'id':_0x4f409f[_0x8d5c('0xbe')]['id']}})['then'](handleEntityNotFound(_0x2e0970,null))['then'](removeEntity(_0x2e0970,null))[_0x8d5c('0x38')](handleError(_0x2e0970,null));};exports[_0x8d5c('0xc5')]=function(_0x29d07e,_0x525e9e){return db['WhatsappInteraction'][_0x8d5c('0xc5')]()[_0x8d5c('0x2c')](respondWithResult(_0x525e9e,null))[_0x8d5c('0x38')](handleError(_0x525e9e,null));};exports['addMessage']=function(_0x3f0f2a,_0x4127ec,_0x2bb8c9){return db['WhatsappMessage'][_0x8d5c('0x66')]({'where':{'id':_0x3f0f2a[_0x8d5c('0xbe')]['id']}})[_0x8d5c('0x2c')](handleEntityNotFound(_0x4127ec,null))['then'](function(_0x4f83f1){if(_0x4f83f1){return _0x4f83f1[_0x8d5c('0xc6')](_0x3f0f2a[_0x8d5c('0x7a')][_0x8d5c('0xc7')],_['omit'](_0x3f0f2a[_0x8d5c('0x7a')],[_0x8d5c('0xc7'),'id'])||{});}})[_0x8d5c('0x2c')](respondWithResult(_0x4127ec,null))[_0x8d5c('0x38')](handleError(_0x4127ec,null));};exports['getMessages']=function(_0x3b7ef9,_0x4fa35b,_0x1b077d){var _0x222e93={'raw':![],'where':{}};var _0x1105a1={};var _0x5579c1={'count':0x0,'rows':[]};return db[_0x8d5c('0xc3')]['findOne']({'where':{'id':_0x3b7ef9[_0x8d5c('0xbe')]['id']}})[_0x8d5c('0x2c')](handleEntityNotFound(_0x4fa35b,null))['then'](function(_0x647ffa){if(_0x647ffa){_0x1105a1[_0x8d5c('0x43')]=_[_0x8d5c('0x7c')](db[_0x8d5c('0xc8')][_0x8d5c('0x41')]);_0x1105a1['query']=_[_0x8d5c('0x7c')](_0x3b7ef9[_0x8d5c('0x44')]);_0x1105a1[_0x8d5c('0xbf')]=_[_0x8d5c('0x46')](_0x1105a1['model'],_0x1105a1['query']);_0x222e93[_0x8d5c('0x45')]=_[_0x8d5c('0x46')](_0x1105a1[_0x8d5c('0x43')],qs[_0x8d5c('0x47')](_0x3b7ef9['query'][_0x8d5c('0x47')]));_0x222e93[_0x8d5c('0x45')]=_0x222e93['attributes'][_0x8d5c('0x48')]?_0x222e93[_0x8d5c('0x45')]:_0x1105a1[_0x8d5c('0x43')];if(!_0x3b7ef9[_0x8d5c('0x44')][_0x8d5c('0xc9')]('nolimit')){_0x222e93[_0x8d5c('0x24')]=qs[_0x8d5c('0x24')](_0x3b7ef9[_0x8d5c('0x44')][_0x8d5c('0x24')]);_0x222e93['offset']=qs['offset'](_0x3b7ef9[_0x8d5c('0x44')]['offset']);}_0x222e93[_0x8d5c('0x4a')]=qs[_0x8d5c('0x4b')](_0x3b7ef9['query'][_0x8d5c('0x4b')]);_0x222e93[_0x8d5c('0x81')]=qs[_0x8d5c('0xbf')](_[_0x8d5c('0x4c')](_0x3b7ef9[_0x8d5c('0x44')],_0x1105a1[_0x8d5c('0xbf')]));_0x222e93[_0x8d5c('0x81')][_0x8d5c('0xb9')]=_0x647ffa['id'];if(_0x3b7ef9['query'][_0x8d5c('0x90')]){_0x222e93[_0x8d5c('0x81')]=_[_0x8d5c('0xa3')](_0x222e93[_0x8d5c('0x81')],{'$or':_[_0x8d5c('0x32')](_0x222e93[_0x8d5c('0x45')],function(_0x1253b5){var _0x90e08e={};_0x90e08e[_0x1253b5]={'$like':'%'+_0x3b7ef9['query']['filter']+'%'};return _0x90e08e;})});}if(_0x3b7ef9[_0x8d5c('0x44')]['$gte']){var _0x36137a=_0x3b7ef9[_0x8d5c('0x44')]['$gte'][_0x8d5c('0x36')](',');var _0x54eb50={};_0x54eb50[_0x36137a[0x0]]={'$gte':moment(_0x36137a[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x222e93[_0x8d5c('0x81')]=_[_0x8d5c('0xa3')](_0x222e93[_0x8d5c('0x81')],_0x54eb50);}_0x222e93=_['merge']({},_0x222e93,_0x3b7ef9[_0x8d5c('0xc2')]);return db[_0x8d5c('0xc8')][_0x8d5c('0x23')]({'where':_0x222e93[_0x8d5c('0x81')]})[_0x8d5c('0x2c')](function(_0x52bad3){_0x5579c1['count']=_0x52bad3;if(_0x3b7ef9[_0x8d5c('0x44')][_0x8d5c('0xc0')]){_0x222e93[_0x8d5c('0xc1')]=[{'all':!![]}];}return db[_0x8d5c('0xc8')][_0x8d5c('0xca')](_0x222e93);})[_0x8d5c('0x2c')](function(_0x5cfefc){_0x5579c1[_0x8d5c('0xbc')]=_0x5cfefc;return _0x5579c1;});}})[_0x8d5c('0x2c')](respondWithFilteredResult(_0x4fa35b,_0x222e93))[_0x8d5c('0x38')](handleError(_0x4fa35b,null));};exports[_0x8d5c('0xcb')]=function(_0x3b0ea5,_0x1f5518,_0x1e29a5){return db[_0x8d5c('0xc3')]['find']({'where':{'id':_0x3b0ea5[_0x8d5c('0xbe')]['id']}})[_0x8d5c('0x2c')](handleEntityNotFound(_0x1f5518,null))[_0x8d5c('0x2c')](function(_0x4f6642){if(_0x4f6642){return _0x4f6642[_0x8d5c('0xcc')](_0x3b0ea5['body'][_0x8d5c('0xc7')],_[_0x8d5c('0xcd')](_0x3b0ea5[_0x8d5c('0x7a')],[_0x8d5c('0xc7'),'id'])||{})[_0x8d5c('0xce')](function(){return db[_0x8d5c('0x75')][_0x8d5c('0xca')]({'attributes':['id','name',_0x8d5c('0x4f')],'where':{'id':_0x3b0ea5['body']['ids']}});})[_0x8d5c('0x2c')](function(_0x42a30a){socket[_0x8d5c('0xcf')](_0x8d5c('0xd0'),{'id':Number(_0x3b0ea5[_0x8d5c('0xbe')]['id']),'tags':_0x42a30a||[]});return{'id':Number(_0x3b0ea5[_0x8d5c('0xbe')]['id']),'tags':_0x42a30a||[]};});}})[_0x8d5c('0x2c')](respondWithResult(_0x1f5518,null))['catch'](handleError(_0x1f5518,null));};exports[_0x8d5c('0xd1')]=function(_0x752831,_0x25ed01,_0x4475cb){return db[_0x8d5c('0xc3')][_0x8d5c('0x66')]({'where':{'id':_0x752831['params']['id']}})['then'](handleEntityNotFound(_0x25ed01,null))[_0x8d5c('0x2c')](function(_0xf8d319){if(_0xf8d319){return _0xf8d319[_0x8d5c('0xd1')](_0x752831[_0x8d5c('0x44')]['ids']);}})[_0x8d5c('0x2c')](respondWithStatusCode(_0x25ed01,null))[_0x8d5c('0x38')](handleError(_0x25ed01,null));};exports[_0x8d5c('0xd2')]=function(_0x5d661a,_0x3d2da8){var _0x259c8a=moment()[_0x8d5c('0xd3')]()[_0x8d5c('0xa1')]();var _0x36f6be=path[_0x8d5c('0xd4')](config['root'],_0x8d5c('0xd5'),_0x8d5c('0xd6'),_0x8d5c('0xd7'));var _0x18d691=path[_0x8d5c('0xd4')](config[_0x8d5c('0xd8')],'server',_0x8d5c('0xd6'),'attachments');var _0x508578=path[_0x8d5c('0xd4')](_0x36f6be,_0x259c8a);var _0x3072ca=util[_0x8d5c('0xd9')](_0x8d5c('0xda'),_0x5d661a[_0x8d5c('0xbe')]['id'],_0x259c8a);var _0x2c7609=path[_0x8d5c('0xd4')](_0x36f6be,_0x3072ca);var _0x1705ae=[];_0x1705ae['push']({'model':db[_0x8d5c('0x78')],'as':_0x8d5c('0x78'),'attributes':['id','fullname'],'raw':!![]});_0x1705ae['push']({'model':db[_0x8d5c('0xdb')],'as':_0x8d5c('0x6c'),'attributes':['id',_0x8d5c('0xdc'),_0x8d5c('0xdd')],'raw':!![]});if(_0x5d661a[_0x8d5c('0x44')][_0x8d5c('0xde')]){_0x1705ae[_0x8d5c('0xba')]({'model':db[_0x8d5c('0xdf')],'as':_0x8d5c('0xdf'),'raw':!![]});}var _0x3beac0=[{'model':db[_0x8d5c('0xc8')],'as':_0x8d5c('0xe0'),'attributes':['id',_0x8d5c('0x7a'),'createdAt',_0x8d5c('0xe1'),_0x8d5c('0xe2'),'read'],'include':_0x1705ae}];_0x3beac0[_0x8d5c('0xba')]({'model':db[_0x8d5c('0xe3')],'as':_0x8d5c('0xe4'),'attributes':['id',_0x8d5c('0x2f')]});_0x3beac0[_0x8d5c('0xba')]({'model':db['User'],'as':_0x8d5c('0xe5'),'attributes':['id',_0x8d5c('0x33')]});return db[_0x8d5c('0xc3')]['find']({'where':{'id':_0x5d661a[_0x8d5c('0xbe')]['id']},'include':_0x3beac0})[_0x8d5c('0x2c')](handleEntityNotFound(_0x3d2da8,null))[_0x8d5c('0x2c')](function(_0x35a71d){if(_0x35a71d){var _0x13b8e3=_0x35a71d[_0x8d5c('0xe6')]({'plain':!![]});fs[_0x8d5c('0xe7')](_0x508578);var _0x3e7b2f={'channel':_0x8d5c('0xe8'),'account':_0x13b8e3['Account'][_0x8d5c('0x2f')],'agent':_0x13b8e3[_0x8d5c('0xe5')]?_0x13b8e3[_0x8d5c('0xe5')][_0x8d5c('0x33')]:_0x8d5c('0xe9'),'createdAt':moment(_0x13b8e3[_0x8d5c('0x84')])[_0x8d5c('0xd9')](_0x8d5c('0xea'))[_0x8d5c('0xa1')](),'closedAt':_0x13b8e3[_0x8d5c('0x3e')]?moment(_0x13b8e3[_0x8d5c('0xeb')])[_0x8d5c('0xd9')](_0x8d5c('0xea'))[_0x8d5c('0xa1')]():'','disposition':_0x13b8e3[_0x8d5c('0xec')],'messages':_(_0x13b8e3['Messages'])[_0x8d5c('0x90')]({'secret':![]})[_0x8d5c('0x32')](function(_0x3ff50d){if(_0x3ff50d['Attachment']){var _0x404970=path['join'](_0x18d691,_0x3ff50d['Attachment'][_0x8d5c('0xed')]);if(fs[_0x8d5c('0xee')](_0x404970)){fs[_0x8d5c('0xef')](_0x404970)['pipe'](fs[_0x8d5c('0xf0')](path[_0x8d5c('0xd4')](_0x508578,_0x3ff50d[_0x8d5c('0xdf')]['basename'])));}}return{'date':moment(_0x3ff50d[_0x8d5c('0x84')])[_0x8d5c('0xd9')](_0x8d5c('0xea'))[_0x8d5c('0xa1')](),'sender':_0x3ff50d[_0x8d5c('0xe1')]===_0x8d5c('0xf1')?_0x3ff50d[_0x8d5c('0x78')]?_0x3ff50d[_0x8d5c('0x78')][_0x8d5c('0x33')]:_0x8d5c('0xf2'):_0x3ff50d['Contact'][_0x8d5c('0xdc')]+(_0x3ff50d['Contact']['lastName']?'\x20'+_0x3ff50d[_0x8d5c('0x6c')][_0x8d5c('0xdd')]:''),'body':_0x3ff50d[_0x8d5c('0xdf')]?_0x3ff50d['Attachment']['basename']:_0x3ff50d[_0x8d5c('0x7a')],'direction':_0x3ff50d[_0x8d5c('0xe1')]===_0x8d5c('0xf1')?'A':'C','secret':_0x3ff50d[_0x8d5c('0xe2')],'read':_0x3ff50d[_0x8d5c('0x8b')],'attachment':_0x3ff50d[_0x8d5c('0xdf')]};})[_0x8d5c('0x68')]()};return ejs['renderFile'](path[_0x8d5c('0xd4')](config['root'],'server',_0x8d5c('0xf3'),_0x8d5c('0xf4')),{'interaction':_0x3e7b2f})[_0x8d5c('0x2c')](function(_0x30035b){var _0x20269e=path[_0x8d5c('0xd4')](_0x508578,'transcript-'+_0x13b8e3['id']+'-'+_0x259c8a+'.pdf');var _0x42a3bb={'path':_0x20269e,'channel':_0x8d5c('0xe8'),'interactionId':_0x13b8e3['id']};return pdf[_0x8d5c('0xf5')](_0x30035b,_0x42a3bb);})[_0x8d5c('0x2c')](function(){return new BPromise(function(_0x5ca639,_0x262f5b){zipdir(_0x508578,{'saveTo':_0x2c7609},function(_0x179891,_0x541300){if(_0x179891)return _0x262f5b(_0x179891);return _0x5ca639(_0x541300);});})[_0x8d5c('0x2c')](function(){return new BPromise(function(_0x3ea136,_0x57145c){rimraf(_0x508578,function(_0x41438b){if(_0x41438b)_0x57145c(_0x41438b);return _0x3ea136();});});})[_0x8d5c('0x2c')](function(){return _0x3d2da8[_0x8d5c('0xd2')](_0x2c7609,_0x3072ca,function(_0x34e70e){if(_0x34e70e){console[_0x8d5c('0xf6')]('err',_0x34e70e);}else{fs['unlinkSync'](_0x2c7609);}});});});}else{return _0x3d2da8[_0x8d5c('0x1f')](0xc8);}})[_0x8d5c('0x38')](handleError(_0x3d2da8,null));};
\ No newline at end of file