Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index f006e9c..9ae52b4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x96e1=['register','sendStatus','end','json','offset','undefined','limit','count','status','Content-Range','apply','reject','save','update','then','error','stack','name','send','Users','TagIds','Tags','split','forEach','push','index','map','WhatsappInteraction','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','select','field','u.id','ui.WhatsappInteractionId','user_has_whatsapp_interactions','users','u.id\x20=\x20ui.UserId','from','whatsapp_interactions','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','tools_tags','expr','search','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','body','some','compact','isEmpty','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','group','i.id','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','getWhatsappAccounts','agent','sequelize','toString','keyBy','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','Contact.lastName','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','catch','show','params','includeAll','merge','options','create','destroy','describe','addMessage','WhatsappMessage','ids','omit','getMessages','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','rows','addTags','spread','color','emit','whatsappInteractionTags:save','removeTags','download','join','server','files','tmp','root','attachments','fullname','CmContact','Contact','firstName','lastName','Attachment','Messages','direction','secret','Account','Owner','get','mkdirSync','Whatsapp','N.A.','closed','closedAt','disposition','basename','existsSync','createWriteStream','System','downloadInteraction.html','transcript-','.pdf','log','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','ejs','lodash','squel','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket'];(function(_0xefd519,_0xc62635){var _0x4bb882=function(_0x37e0a1){while(--_0x37e0a1){_0xefd519['push'](_0xefd519['shift']());}};_0x4bb882(++_0xc62635);}(_0x96e1,0xd5));var _0x196e=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x96e1[_0x4a9fb1];return _0x348672;};'use strict';var emlformat=require(_0x196e('0x0'));var rimraf=require(_0x196e('0x1'));var zipdir=require(_0x196e('0x2'));var jsonpatch=require(_0x196e('0x3'));var rp=require('request-promise');var moment=require(_0x196e('0x4'));var BPromise=require(_0x196e('0x5'));var Mustache=require(_0x196e('0x6'));var util=require(_0x196e('0x7'));var path=require('path');var sox=require(_0x196e('0x8'));var csv=require('to-csv');var ejs=require(_0x196e('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x196e('0xa'));var squel=require(_0x196e('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x196e('0xc'));var toCsv=require('to-csv');var querystring=require(_0x196e('0xd'));var Papa=require('papaparse');var Redis=require(_0x196e('0xe'));var authService=require(_0x196e('0xf'));var qs=require(_0x196e('0x10'));var as=require(_0x196e('0x11'));var pdf=require(_0x196e('0x12'));var hardwareService=require(_0x196e('0x13'));var logger=require(_0x196e('0x14'))(_0x196e('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x196e('0x16'));var db=require(_0x196e('0x17'))['db'];config[_0x196e('0x18')]=_['defaults'](config[_0x196e('0x18')],{'host':_0x196e('0x19'),'port':0x18eb});var socket=require(_0x196e('0x1a'))(new Redis(config[_0x196e('0x18')]));require(_0x196e('0x1b'))[_0x196e('0x1c')](socket);function respondWithStatusCode(_0x788a15,_0x5a0a9a){_0x5a0a9a=_0x5a0a9a||0xcc;return function(_0x521171){if(_0x521171){return _0x788a15[_0x196e('0x1d')](_0x5a0a9a);}return _0x788a15['status'](_0x5a0a9a)[_0x196e('0x1e')]();};}function respondWithResult(_0x372944,_0x440875){_0x440875=_0x440875||0xc8;return function(_0x2cec6c){if(_0x2cec6c){return _0x372944['status'](_0x440875)[_0x196e('0x1f')](_0x2cec6c);}};}function respondWithFilteredResult(_0x355421,_0x339347){return function(_0xe61fa3){if(_0xe61fa3){var _0x398c3f=typeof _0x339347[_0x196e('0x20')]===_0x196e('0x21')&&typeof _0x339347[_0x196e('0x22')]===_0x196e('0x21');var _0x5de930=_0xe61fa3[_0x196e('0x23')];var _0x50735b=_0x398c3f?0x0:_0x339347[_0x196e('0x20')];var _0x1a55dc=_0x398c3f?_0xe61fa3[_0x196e('0x23')]:_0x339347[_0x196e('0x20')]+_0x339347[_0x196e('0x22')];var _0x2408d9;if(_0x1a55dc>=_0x5de930){_0x1a55dc=_0x5de930;_0x2408d9=0xc8;}else{_0x2408d9=0xce;}_0x355421[_0x196e('0x24')](_0x2408d9);return _0x355421['set'](_0x196e('0x25'),_0x50735b+'-'+_0x1a55dc+'/'+_0x5de930)[_0x196e('0x1f')](_0xe61fa3);}return null;};}function patchUpdates(_0x4b69bd){return function(_0x6a1225){try{jsonpatch[_0x196e('0x26')](_0x6a1225,_0x4b69bd,!![]);}catch(_0x3569e0){return BPromise[_0x196e('0x27')](_0x3569e0);}return _0x6a1225[_0x196e('0x28')]();};}function saveUpdates(_0x4e81f4,_0x1845c3){return function(_0x39126d){if(_0x39126d){return _0x39126d[_0x196e('0x29')](_0x4e81f4)[_0x196e('0x2a')](function(_0x366ffb){return _0x366ffb;});}return null;};}function removeEntity(_0x187142,_0xc3240f){return function(_0x12614a){if(_0x12614a){return _0x12614a['destroy']()['then'](function(){_0x187142[_0x196e('0x24')](0xcc)[_0x196e('0x1e')]();});}};}function handleEntityNotFound(_0x508e21,_0x4be2db){return function(_0x49523d){if(!_0x49523d){_0x508e21[_0x196e('0x1d')](0x194);}return _0x49523d;};}function handleError(_0x21af44,_0x3cb1d4){_0x3cb1d4=_0x3cb1d4||0x1f4;return function(_0x11d5a4){logger[_0x196e('0x2b')](_0x11d5a4[_0x196e('0x2c')]);if(_0x11d5a4[_0x196e('0x2d')]){delete _0x11d5a4[_0x196e('0x2d')];}_0x21af44['status'](_0x3cb1d4)[_0x196e('0x2e')](_0x11d5a4);};}function getInteractionUsers(_0xffd731,_0x5e7216){return new BPromise(function(_0x841b4,_0x18e1ee){try{if(_0x5e7216[_0xffd731['id']]){_0xffd731[_0x196e('0x2f')]=_['map'](_0x5e7216[_0xffd731['id']],function(_0x58c52f){return{'id':_0x58c52f['id'],'fullname':_0x58c52f['fullname']};});}}catch(_0x881ef){_0x18e1ee(_0x881ef);}_0x841b4(_0xffd731);});}function getInteractionTags(_0x57b088,_0xf1c029){return new BPromise(function(_0x123f93,_0xb7b6e1){try{if(_0x57b088[_0x196e('0x30')]){_0x57b088[_0x196e('0x31')]=[];_0x57b088[_0x196e('0x30')][_0x196e('0x32')](',')[_0x196e('0x33')](function(_0x27539d){_0x57b088['Tags'][_0x196e('0x34')](_0xf1c029[_0x27539d]);});}delete _0x57b088[_0x196e('0x30')];}catch(_0x122eca){_0xb7b6e1(_0x122eca);}_0x123f93(_0x57b088);});}function updateWhatsappInteraction(_0x3d467b,_0x27e878,_0x5f377f){return new BPromise(function(_0x40724,_0x160c71){return getInteractionUsers(_0x3d467b,_0x5f377f)[_0x196e('0x2a')](function(_0x4688e4){return getInteractionTags(_0x4688e4,_0x27e878);})[_0x196e('0x2a')](function(_0x49fe77){_0x40724(_0x49fe77);})['catch'](function(_0x2e992a){_0x160c71(_0x2e992a);});});}exports[_0x196e('0x35')]=function(_0x58f366,_0x21ddee){var _0x26d5c0={},_0x51528f={},_0x39ba97={'count':0x0,'rows':[]};var _0x3ed34e=_[_0x196e('0x36')](db[_0x196e('0x37')][_0x196e('0x38')],function(_0xb69892){return{'name':_0xb69892[_0x196e('0x39')],'type':_0xb69892[_0x196e('0x3a')][_0x196e('0x3b')]};});_0x51528f[_0x196e('0x3c')]=_['map'](_0x3ed34e,_0x196e('0x2d'));_0x51528f['query']=_[_0x196e('0x3d')](_0x58f366[_0x196e('0x3e')]);_0x51528f[_0x196e('0x3f')]=_[_0x196e('0x40')](_0x51528f['model'],_0x51528f[_0x196e('0x3e')]);_0x26d5c0[_0x196e('0x41')]=_['intersection'](_0x51528f[_0x196e('0x3c')],qs[_0x196e('0x42')](_0x58f366['query'][_0x196e('0x42')]));_0x26d5c0[_0x196e('0x41')]=_0x26d5c0['attributes'][_0x196e('0x43')]?_0x26d5c0[_0x196e('0x41')]:_0x51528f[_0x196e('0x3c')];if(!_0x58f366['query']['hasOwnProperty'](_0x196e('0x44'))){_0x26d5c0[_0x196e('0x22')]=qs[_0x196e('0x22')](_0x58f366['query'][_0x196e('0x22')]);_0x26d5c0[_0x196e('0x20')]=qs[_0x196e('0x20')](_0x58f366[_0x196e('0x3e')][_0x196e('0x20')]);}_0x26d5c0[_0x196e('0x45')]=qs['sort'](_0x58f366[_0x196e('0x3e')][_0x196e('0x46')]);_0x26d5c0[_0x196e('0x47')]=qs[_0x196e('0x3f')](_[_0x196e('0x48')](_0x58f366[_0x196e('0x3e')],_0x51528f[_0x196e('0x3f')]),_0x3ed34e);var _0x43ab76=[];var _0xb8ae07=squel[_0x196e('0x49')]()[_0x196e('0x4a')]('id')[_0x196e('0x4a')](_0x196e('0x2d'))['field']('color')['from']('tools_tags');var _0x47601b=squel['select']()[_0x196e('0x4a')](_0x196e('0x4b'))[_0x196e('0x4a')]('u.fullname')[_0x196e('0x4a')](_0x196e('0x4c'))['from'](_0x196e('0x4d'),'ui')['left_join'](_0x196e('0x4e'),'u',_0x196e('0x4f'));var _0x1874c1=squel[_0x196e('0x49')]()[_0x196e('0x50')](_0x196e('0x51'),'i')[_0x196e('0x52')](_0x196e('0x53'),'c',_0x196e('0x54'))[_0x196e('0x52')]('users','o',_0x196e('0x55'))['left_join'](_0x196e('0x56'),'a',_0x196e('0x57'))[_0x196e('0x52')](_0x196e('0x58'),'me',_0x196e('0x59'))['left_join'](_0x196e('0x5a'),'it',_0x196e('0x5b'))['left_join'](_0x196e('0x5c'),'t','t.id\x20=\x20it.TagId');var _0x518e0c=squel['expr']();var _0x3cc93c=[];var _0x339fab=squel[_0x196e('0x5d')]();var _0x8c9497;if(_0x58f366[_0x196e('0x3e')][_0x196e('0x5e')]){_0x8c9497=as['parseSearch'](_0x58f366['query'][_0x196e('0x5e')]);var _0x4ab9bb=_0x8c9497[_0x196e('0x5f')];for(var _0x2b83d4=0x0;_0x2b83d4<_0x8c9497[_0x196e('0x60')][_0x196e('0x43')];_0x2b83d4++){var _0x2aaf8f=_0x8c9497[_0x196e('0x60')][_0x2b83d4];var _0x2dc7ae='i';var _0x2f96d2=_[_0x196e('0x61')](_0x3ed34e,[_0x196e('0x2d'),_0x2aaf8f[_0x196e('0x4a')]]);if(!_0x2f96d2){switch(_0x2aaf8f['field']){case _0x196e('0x62'):if(_0x2aaf8f[_0x196e('0x63')]==0x1){_0x1874c1[_0x196e('0x64')]('`'+_0x2aaf8f[_0x196e('0x4a')]+_0x196e('0x65'));}else{_0x1874c1[_0x196e('0x64')]('`'+_0x2aaf8f[_0x196e('0x4a')]+'`\x20>\x200');}break;case'Contact':if(_0x2aaf8f[_0x196e('0x66')]===_0x196e('0x67')){if(_0x2aaf8f[_0x196e('0x63')]['split']('\x20')[_0x196e('0x43')]>0x1){_0x518e0c[_0x4ab9bb](_0x196e('0x68'),qs['getFullTextValue'](_0x2aaf8f[_0x196e('0x63')]),null);}else{var _0x3073c7='%'+_0x2aaf8f[_0x196e('0x63')]+'%';_0x518e0c[_0x4ab9bb](_0x196e('0x69'),_0x3073c7,_0x3073c7,_0x3073c7);}}else{_0x2f96d2=_[_0x196e('0x61')](_0x3ed34e,[_0x196e('0x2d'),_0x196e('0x6a')]);_0x2aaf8f[_0x196e('0x4a')]=_0x196e('0x6a');_0x262f0e=as[_0x196e('0x6b')](_0x2dc7ae,_0x2f96d2['type'],_0x2aaf8f);_0x518e0c[_0x4ab9bb](_0x262f0e[_0x196e('0x6c')],_0x262f0e['value'][_0x196e('0x6d')],_0x262f0e[_0x196e('0x63')]['end']);}break;case _0x196e('0x6e'):var _0x259cbf=_0x2aaf8f[_0x196e('0x63')]['split'](',')[_0x196e('0x36')](function(_0x126780){return Number(_0x126780);});_0x259cbf[_0x196e('0x33')](function(_0x44ab05){_0x339fab['or'](_0x196e('0x6f'),'%,'+_0x44ab05+',%');});_0x3cc93c=_[_0x196e('0x70')](_0x3cc93c,_0x259cbf);break;case _0x196e('0x71'):if(_0x2aaf8f[_0x196e('0x66')]===_0x196e('0x67')){_0x518e0c[_0x4ab9bb](_0x196e('0x72'),'%'+_0x2aaf8f[_0x196e('0x63')]+'%',null);}else{_0x2f96d2=_[_0x196e('0x61')](_0x3ed34e,['name','UserId']);_0x2aaf8f['field']=_0x196e('0x73');_0x262f0e=as['buildExpression'](_0x2dc7ae,_0x2f96d2[_0x196e('0x3a')],_0x2aaf8f);_0x518e0c[_0x4ab9bb](_0x262f0e['text'],_0x262f0e[_0x196e('0x63')][_0x196e('0x6d')],_0x262f0e['value'][_0x196e('0x1e')]);}break;case _0x196e('0x74'):_0x262f0e=as[_0x196e('0x6b')]('me',null,_0x2aaf8f);_0x518e0c[_0x4ab9bb](_0x262f0e[_0x196e('0x6c')],_0x262f0e[_0x196e('0x63')]['start'],_0x262f0e[_0x196e('0x63')][_0x196e('0x1e')]);break;}}else{var _0x262f0e=as['buildExpression'](_0x2dc7ae,_0x2f96d2[_0x196e('0x3a')],_0x2aaf8f);_0x518e0c[_0x4ab9bb](_0x262f0e[_0x196e('0x6c')],_0x262f0e['value']['start'],_0x262f0e[_0x196e('0x63')]['end']);}}}else{var _0x430f54=_(_0x58f366[_0x196e('0x3e')])[_0x196e('0x3d')]()[_0x196e('0x36')](function(_0x4726db){return _[_0x196e('0x75')](_0x3ed34e,[_0x196e('0x2d'),_0x4726db])?_0x4726db:undefined;})[_0x196e('0x76')]()[_0x196e('0x63')]();if(!_[_0x196e('0x77')](_0x430f54)){_0x430f54['forEach'](function(_0x2be24e){if(_0x2be24e==='WhatsappAccountId'){_0x1874c1[_0x196e('0x47')](_0x196e('0x78'),[][_0x196e('0x79')](_0x58f366['query'][_0x2be24e]));}else if(_0x2be24e===_0x196e('0x7a')){var _0x4e6c3e=JSON[_0x196e('0x7b')](_0x58f366[_0x196e('0x3e')][_0x2be24e])[_0x196e('0x7c')];var _0x8a1692=JSON['parse'](_0x58f366[_0x196e('0x3e')][_0x2be24e])[_0x196e('0x7d')];_0x1874c1['where'](_0x196e('0x7e'),_0x4e6c3e,_0x8a1692);}else{if(_0x58f366['query'][_0x2be24e]===_0x196e('0x7f')){_0x1874c1[_0x196e('0x47')]('i.'+_0x2be24e+_0x196e('0x80'));}else{_0x1874c1[_0x196e('0x47')]('i.'+_0x2be24e+_0x196e('0x81'),_0x58f366[_0x196e('0x3e')][_0x2be24e]);}}});}if(_0x58f366[_0x196e('0x3e')][_0x196e('0x82')]){if(_0x58f366[_0x196e('0x3e')]['read']==0x1){_0x1874c1[_0x196e('0x64')](_0x196e('0x83'));}else{_0x1874c1[_0x196e('0x64')](_0x196e('0x84'));}}if(_0x58f366[_0x196e('0x3e')]['tag']){_0x3cc93c=_[_0x196e('0x85')](_0x58f366[_0x196e('0x3e')]['tag'])?_0x58f366['query']['tag']:new Array(_0x58f366[_0x196e('0x3e')][_0x196e('0x86')]);_0x3cc93c[_0x196e('0x33')](function(_0x37c0f9){_0x339fab['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x37c0f9+',%');});}if(_0x58f366[_0x196e('0x3e')][_0x196e('0x87')]){var _0x566292=_0x58f366[_0x196e('0x3e')][_0x196e('0x87')][_0x196e('0x88')]('\x5c','\x5c\x5c')[_0x196e('0x88')](/'/g,'\x27\x27');if(qs[_0x196e('0x89')](_0x566292)){_0x518e0c['or'](_0x196e('0x8a'),_0x566292+'%')['or'](_0x196e('0x8b'),_0x566292+'%');}else{_0x518e0c['or'](_0x196e('0x8c'),qs['getFullTextValue'](_0x566292))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x566292+'%');}}}_0x1874c1[_0x196e('0x47')](_0x518e0c);_0x1874c1[_0x196e('0x8d')](_0x196e('0x8e'));var _0x5f32d7={'type':db['Sequelize'][_0x196e('0x8f')][_0x196e('0x90')],'raw':!![]};var _0x346bae=_0x1874c1[_0x196e('0x91')]();_0x346bae[_0x196e('0x4a')](_0x196e('0x8e'));_0x346bae['field'](_0x196e('0x92'),_0x196e('0x62'));if(_0x26d5c0[_0x196e('0x45')]){_0x26d5c0[_0x196e('0x45')]['forEach'](function(_0x41506c){var _0x3e8f05=_0x41506c[0x0]===_0x196e('0x93')?_0x41506c[0x0]:'i.'+_0x41506c[0x0];_0x1874c1['order'](_0x3e8f05,_0x41506c[0x1]===_0x196e('0x94')?![]:!![]);});}if(!_[_0x196e('0x77')](_0x3cc93c)){_0x1874c1[_0x196e('0x64')](_0x339fab);_0x346bae['where'](_0x196e('0x95'),_0x3cc93c);}BPromise[_0x196e('0x96')]()['then'](function(){if(!_0x8c9497){if(_0x58f366['query'][_0x196e('0x97')])return;_0x346bae[_0x196e('0x47')](_0x196e('0x98'));_0x1874c1[_0x196e('0x47')](_0x196e('0x98'));return;}if(_0x58f366[_0x196e('0x99')][_0x196e('0x9a')]!=='agent')return;return _0x58f366[_0x196e('0x99')][_0x196e('0x9b')]({'attributes':['id'],'raw':!![]})['then'](function(_0x41e3f2){if(_[_0x196e('0x77')](_0x41e3f2)){_0x346bae[_0x196e('0x47')]('i.WhatsappAccountId\x20IS\x20NULL');_0x1874c1[_0x196e('0x47')]('i.WhatsappAccountId\x20IS\x20NULL');}else{_0x346bae[_0x196e('0x47')](_0x196e('0x78'),_[_0x196e('0x36')](_0x41e3f2,'id'));_0x1874c1[_0x196e('0x47')](_0x196e('0x78'),_[_0x196e('0x36')](_0x41e3f2,'id'));}});})[_0x196e('0x2a')](function(){if(_0x58f366[_0x196e('0x99')][_0x196e('0x9a')]===_0x196e('0x9c')&&!_0x8c9497&&!_0x58f366[_0x196e('0x3e')][_0x196e('0x97')])return[];return db[_0x196e('0x9d')][_0x196e('0x3e')](_0x346bae[_0x196e('0x9e')](),_0x5f32d7);})[_0x196e('0x2a')](function(_0x4a0a1f){_0x39ba97[_0x196e('0x23')]=_0x4a0a1f[_0x196e('0x43')];if(_0x39ba97[_0x196e('0x23')]===0x0)return[];return db['sequelize']['query'](_0xb8ae07[_0x196e('0x9e')](),_0x5f32d7)[_0x196e('0x2a')](function(_0x51bc1a){_0x43ab76=_[_0x196e('0x9f')](_0x51bc1a,'id');_0x5f32d7=_['merge'](_0x5f32d7,{'model':db[_0x196e('0x37')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x58f366[_0x196e('0x3e')]['fields']){_0x26d5c0[_0x196e('0x41')][_0x196e('0x33')](function(_0x4611a0){_0x1874c1[_0x196e('0x4a')]('i.'+_0x4611a0);});}else{_0x1874c1['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x196e('0x62'));_0x1874c1[_0x196e('0x4a')](_0x196e('0xa0'),'Account.key');_0x1874c1[_0x196e('0x4a')](_0x196e('0xa1'),_0x196e('0xa2'));_0x1874c1['field'](_0x196e('0xa3'),_0x196e('0x93'));_0x1874c1[_0x196e('0x4a')](_0x196e('0xa4'));_0x1874c1['field'](_0x196e('0xa5'),_0x196e('0xa6'));_0x1874c1[_0x196e('0x4a')](_0x196e('0xa7'),_0x196e('0xa8'));_0x1874c1[_0x196e('0x4a')]('c.email','Contact.email');_0x1874c1[_0x196e('0x4a')](_0x196e('0xa9'),'Contact.phone');_0x1874c1['field'](_0x196e('0xaa'),_0x196e('0xab'));_0x1874c1[_0x196e('0x4a')](_0x196e('0xac'),_0x196e('0xad'));_0x1874c1['field'](_0x196e('0xae'),_0x196e('0xaf'));_0x1874c1[_0x196e('0x4a')](_0x196e('0xb0'),'Owner.internal');_0x1874c1['field'](_0x196e('0xb1'),'TagIds');}if(_0x26d5c0[_0x196e('0x22')])_0x1874c1[_0x196e('0x22')](_0x26d5c0[_0x196e('0x22')]);if(_0x26d5c0[_0x196e('0x20')])_0x1874c1[_0x196e('0x20')](_0x26d5c0[_0x196e('0x20')]);return db['sequelize']['query'](_0x1874c1[_0x196e('0x9e')](),_0x5f32d7);})[_0x196e('0x2a')](function(_0x2e7535){if(_0x2e7535[_0x196e('0x43')]>0x0)_0x47601b[_0x196e('0x47')](_0x196e('0xb2'),_[_0x196e('0x36')](_0x2e7535,'id'));return db['sequelize']['query'](_0x47601b[_0x196e('0x9e')](),_0x5f32d7)['then'](function(_0x34905b){var _0x2d4540=_[_0x196e('0xb3')](_0x34905b,_0x196e('0xb4'));var _0x1a4a4e=[];_0x2e7535[_0x196e('0x33')](function(_0x3edb0f){_0x1a4a4e[_0x196e('0x34')](updateWhatsappInteraction(_0x3edb0f,_0x43ab76,_0x2d4540));});return BPromise[_0x196e('0xb5')](_0x1a4a4e);});});})[_0x196e('0x2a')](function(_0x3736c2){_0x39ba97['rows']=_0x3736c2;return _0x39ba97;})[_0x196e('0x2a')](respondWithFilteredResult(_0x21ddee,_0x26d5c0))[_0x196e('0xb6')](handleError(_0x21ddee,null));};exports[_0x196e('0xb7')]=function(_0x194d2e,_0x5422f9){var _0x2ad46f={'raw':![],'where':{'id':_0x194d2e[_0x196e('0xb8')]['id']}},_0x32c93a={};_0x32c93a[_0x196e('0x3c')]=_[_0x196e('0x3d')](db[_0x196e('0x37')][_0x196e('0x38')]);_0x32c93a[_0x196e('0x3e')]=_['keys'](_0x194d2e[_0x196e('0x3e')]);_0x32c93a['filters']=_[_0x196e('0x40')](_0x32c93a[_0x196e('0x3c')],_0x32c93a['query']);_0x2ad46f[_0x196e('0x41')]=_[_0x196e('0x40')](_0x32c93a['model'],qs['fields'](_0x194d2e[_0x196e('0x3e')]['fields']));_0x2ad46f[_0x196e('0x41')]=_0x2ad46f['attributes']['length']?_0x2ad46f[_0x196e('0x41')]:_0x32c93a['model'];if(_0x194d2e[_0x196e('0x3e')][_0x196e('0xb9')]){_0x2ad46f['include']=[{'all':!![]}];}_0x2ad46f=_[_0x196e('0xba')]({},_0x2ad46f,_0x194d2e[_0x196e('0xbb')]);return db[_0x196e('0x37')][_0x196e('0x61')](_0x2ad46f)[_0x196e('0x2a')](handleEntityNotFound(_0x5422f9,null))[_0x196e('0x2a')](respondWithResult(_0x5422f9,null))[_0x196e('0xb6')](handleError(_0x5422f9,null));};exports['create']=function(_0x11937f,_0x33f636){return db['WhatsappInteraction'][_0x196e('0xbc')](_0x11937f[_0x196e('0x74')],{})['then'](respondWithResult(_0x33f636,0xc9))[_0x196e('0xb6')](handleError(_0x33f636,null));};exports[_0x196e('0x29')]=function(_0x4d11ee,_0x38c4d0){if(_0x4d11ee[_0x196e('0x74')]['id']){delete _0x4d11ee[_0x196e('0x74')]['id'];}return db[_0x196e('0x37')][_0x196e('0x61')]({'where':{'id':_0x4d11ee['params']['id']}})[_0x196e('0x2a')](handleEntityNotFound(_0x38c4d0,null))[_0x196e('0x2a')](saveUpdates(_0x4d11ee[_0x196e('0x74')],null))[_0x196e('0x2a')](respondWithResult(_0x38c4d0,null))[_0x196e('0xb6')](handleError(_0x38c4d0,null));};exports[_0x196e('0xbd')]=function(_0x3c9b90,_0x416a8c){return db[_0x196e('0x37')][_0x196e('0x61')]({'where':{'id':_0x3c9b90[_0x196e('0xb8')]['id']}})['then'](handleEntityNotFound(_0x416a8c,null))[_0x196e('0x2a')](removeEntity(_0x416a8c,null))[_0x196e('0xb6')](handleError(_0x416a8c,null));};exports['describe']=function(_0x4107b5,_0x2e634c){return db[_0x196e('0x37')][_0x196e('0xbe')]()['then'](respondWithResult(_0x2e634c,null))[_0x196e('0xb6')](handleError(_0x2e634c,null));};exports[_0x196e('0xbf')]=function(_0x3139c4,_0x1839df,_0x421129){return db[_0x196e('0xc0')]['find']({'where':{'id':_0x3139c4[_0x196e('0xb8')]['id']}})['then'](handleEntityNotFound(_0x1839df,null))[_0x196e('0x2a')](function(_0x746889){if(_0x746889){return _0x746889[_0x196e('0xbf')](_0x3139c4['body'][_0x196e('0xc1')],_[_0x196e('0xc2')](_0x3139c4[_0x196e('0x74')],['ids','id'])||{});}})[_0x196e('0x2a')](respondWithResult(_0x1839df,null))[_0x196e('0xb6')](handleError(_0x1839df,null));};exports[_0x196e('0xc3')]=function(_0x13612a,_0xeb492b,_0x565e24){var _0x500fd4={'raw':![],'where':{}};var _0x3514ee={};var _0x7b238e={'count':0x0,'rows':[]};return db['WhatsappInteraction']['findOne']({'where':{'id':_0x13612a[_0x196e('0xb8')]['id']}})[_0x196e('0x2a')](handleEntityNotFound(_0xeb492b,null))[_0x196e('0x2a')](function(_0x3965a0){if(_0x3965a0){_0x3514ee['model']=_[_0x196e('0x3d')](db[_0x196e('0xc0')]['rawAttributes']);_0x3514ee[_0x196e('0x3e')]=_[_0x196e('0x3d')](_0x13612a[_0x196e('0x3e')]);_0x3514ee[_0x196e('0x3f')]=_['intersection'](_0x3514ee[_0x196e('0x3c')],_0x3514ee[_0x196e('0x3e')]);_0x500fd4[_0x196e('0x41')]=_['intersection'](_0x3514ee[_0x196e('0x3c')],qs['fields'](_0x13612a['query']['fields']));_0x500fd4[_0x196e('0x41')]=_0x500fd4[_0x196e('0x41')][_0x196e('0x43')]?_0x500fd4[_0x196e('0x41')]:_0x3514ee[_0x196e('0x3c')];if(!_0x13612a[_0x196e('0x3e')]['hasOwnProperty'](_0x196e('0x44'))){_0x500fd4[_0x196e('0x22')]=qs[_0x196e('0x22')](_0x13612a[_0x196e('0x3e')][_0x196e('0x22')]);_0x500fd4[_0x196e('0x20')]=qs[_0x196e('0x20')](_0x13612a[_0x196e('0x3e')][_0x196e('0x20')]);}_0x500fd4[_0x196e('0x45')]=qs[_0x196e('0x46')](_0x13612a[_0x196e('0x3e')][_0x196e('0x46')]);_0x500fd4[_0x196e('0x47')]=qs['filters'](_[_0x196e('0x48')](_0x13612a[_0x196e('0x3e')],_0x3514ee['filters']));_0x500fd4['where'][_0x196e('0xb4')]=_0x3965a0['id'];if(_0x13612a[_0x196e('0x3e')][_0x196e('0x87')]){_0x500fd4[_0x196e('0x47')]=_[_0x196e('0xba')](_0x500fd4['where'],{'$or':_['map'](_0x500fd4[_0x196e('0x41')],function(_0x400d6c){var _0x1fa757={};_0x1fa757[_0x400d6c]={'$like':'%'+_0x13612a[_0x196e('0x3e')][_0x196e('0x87')]+'%'};return _0x1fa757;})});}if(_0x13612a['query'][_0x196e('0x7c')]){var _0x558fe2=_0x13612a['query'][_0x196e('0x7c')]['split'](',');var _0x3c5f01={};_0x3c5f01[_0x558fe2[0x0]]={'$gte':moment(_0x558fe2[0x1])[_0x196e('0xc4')](_0x196e('0xc5'))};_0x500fd4['where']=_['merge'](_0x500fd4['where'],_0x3c5f01);}_0x500fd4=_[_0x196e('0xba')]({},_0x500fd4,_0x13612a[_0x196e('0xbb')]);return db[_0x196e('0xc0')][_0x196e('0x23')]({'where':_0x500fd4['where']})[_0x196e('0x2a')](function(_0x23c4b0){_0x7b238e[_0x196e('0x23')]=_0x23c4b0;if(_0x13612a[_0x196e('0x3e')][_0x196e('0xb9')]){_0x500fd4[_0x196e('0xc6')]=[{'all':!![]}];}return db[_0x196e('0xc0')][_0x196e('0xc7')](_0x500fd4);})[_0x196e('0x2a')](function(_0x5ebdc3){_0x7b238e[_0x196e('0xc8')]=_0x5ebdc3;return _0x7b238e;});}})[_0x196e('0x2a')](respondWithFilteredResult(_0xeb492b,_0x500fd4))[_0x196e('0xb6')](handleError(_0xeb492b,null));};exports[_0x196e('0xc9')]=function(_0x3cd48c,_0x4f6174,_0x23b68b){return db[_0x196e('0x37')][_0x196e('0x61')]({'where':{'id':_0x3cd48c[_0x196e('0xb8')]['id']}})[_0x196e('0x2a')](handleEntityNotFound(_0x4f6174,null))[_0x196e('0x2a')](function(_0x1f18c4){if(_0x1f18c4){return _0x1f18c4['setTags'](_0x3cd48c[_0x196e('0x74')]['ids'],_[_0x196e('0xc2')](_0x3cd48c['body'],[_0x196e('0xc1'),'id'])||{})[_0x196e('0xca')](function(){return db['Tag'][_0x196e('0xc7')]({'attributes':['id','name',_0x196e('0xcb')],'where':{'id':_0x3cd48c[_0x196e('0x74')][_0x196e('0xc1')]}});})[_0x196e('0x2a')](function(_0x4b5e5c){socket[_0x196e('0xcc')](_0x196e('0xcd'),{'id':Number(_0x3cd48c['params']['id']),'tags':_0x4b5e5c||[]});return{'id':Number(_0x3cd48c[_0x196e('0xb8')]['id']),'tags':_0x4b5e5c||[]};});}})[_0x196e('0x2a')](respondWithResult(_0x4f6174,null))[_0x196e('0xb6')](handleError(_0x4f6174,null));};exports[_0x196e('0xce')]=function(_0x2d9d00,_0x26690b,_0x2ed308){return db[_0x196e('0x37')][_0x196e('0x61')]({'where':{'id':_0x2d9d00[_0x196e('0xb8')]['id']}})['then'](handleEntityNotFound(_0x26690b,null))[_0x196e('0x2a')](function(_0xe03e6b){if(_0xe03e6b){return _0xe03e6b[_0x196e('0xce')](_0x2d9d00[_0x196e('0x3e')][_0x196e('0xc1')]);}})['then'](respondWithStatusCode(_0x26690b,null))[_0x196e('0xb6')](handleError(_0x26690b,null));};exports[_0x196e('0xcf')]=function(_0x33c556,_0x6af859){var _0x136927=moment()['unix']()['toString']();var _0x4ea487=path[_0x196e('0xd0')](config['root'],_0x196e('0xd1'),_0x196e('0xd2'),_0x196e('0xd3'));var _0x584752=path[_0x196e('0xd0')](config[_0x196e('0xd4')],_0x196e('0xd1'),'files',_0x196e('0xd5'));var _0x51e0fa=path['join'](_0x4ea487,_0x136927);var _0x6857ff=util[_0x196e('0xc4')]('transcript-%d-%s.zip',_0x33c556[_0x196e('0xb8')]['id'],_0x136927);var _0x494550=path[_0x196e('0xd0')](_0x4ea487,_0x6857ff);var _0x5112fe=[];_0x5112fe[_0x196e('0x34')]({'model':db[_0x196e('0x71')],'as':'User','attributes':['id',_0x196e('0xd6')],'raw':!![]});_0x5112fe[_0x196e('0x34')]({'model':db[_0x196e('0xd7')],'as':_0x196e('0xd8'),'attributes':['id',_0x196e('0xd9'),_0x196e('0xda')],'raw':!![]});if(_0x33c556[_0x196e('0x3e')][_0x196e('0xd5')]){_0x5112fe[_0x196e('0x34')]({'model':db[_0x196e('0xdb')],'as':_0x196e('0xdb'),'raw':!![]});}var _0x358973=[{'model':db[_0x196e('0xc0')],'as':_0x196e('0xdc'),'attributes':['id','body',_0x196e('0x7a'),_0x196e('0xdd'),_0x196e('0xde'),_0x196e('0x82')],'include':_0x5112fe}];_0x358973[_0x196e('0x34')]({'model':db['WhatsappAccount'],'as':_0x196e('0xdf'),'attributes':['id',_0x196e('0x2d')]});_0x358973[_0x196e('0x34')]({'model':db[_0x196e('0x71')],'as':_0x196e('0xe0'),'attributes':['id',_0x196e('0xd6')]});return db[_0x196e('0x37')][_0x196e('0x61')]({'where':{'id':_0x33c556['params']['id']},'include':_0x358973})[_0x196e('0x2a')](handleEntityNotFound(_0x6af859,null))['then'](function(_0x30a52e){if(_0x30a52e){var _0x5898b3=_0x30a52e[_0x196e('0xe1')]({'plain':!![]});fs[_0x196e('0xe2')](_0x51e0fa);var _0x578049={'channel':_0x196e('0xe3'),'account':_0x5898b3['Account'][_0x196e('0x2d')],'agent':_0x5898b3[_0x196e('0xe0')]?_0x5898b3[_0x196e('0xe0')][_0x196e('0xd6')]:_0x196e('0xe4'),'createdAt':moment(_0x5898b3[_0x196e('0x7a')])[_0x196e('0xc4')](_0x196e('0xc5'))[_0x196e('0x9e')](),'closedAt':_0x5898b3[_0x196e('0xe5')]?moment(_0x5898b3[_0x196e('0xe6')])[_0x196e('0xc4')](_0x196e('0xc5'))['toString']():'','disposition':_0x5898b3[_0x196e('0xe7')],'messages':_(_0x5898b3[_0x196e('0xdc')])[_0x196e('0x87')]({'secret':![]})[_0x196e('0x36')](function(_0xee57e6){if(_0xee57e6[_0x196e('0xdb')]){var _0x50cd98=path['join'](_0x584752,_0xee57e6[_0x196e('0xdb')][_0x196e('0xe8')]);if(fs[_0x196e('0xe9')](_0x50cd98)){fs['createReadStream'](_0x50cd98)['pipe'](fs[_0x196e('0xea')](path[_0x196e('0xd0')](_0x51e0fa,_0xee57e6[_0x196e('0xdb')][_0x196e('0xe8')])));}}return{'date':moment(_0xee57e6[_0x196e('0x7a')])[_0x196e('0xc4')]('YYYY-MM-DD\x20HH:mm:ss')[_0x196e('0x9e')](),'sender':_0xee57e6['direction']==='out'?_0xee57e6[_0x196e('0x71')]?_0xee57e6[_0x196e('0x71')][_0x196e('0xd6')]:_0x196e('0xeb'):_0xee57e6[_0x196e('0xd8')]['firstName']+(_0xee57e6[_0x196e('0xd8')]['lastName']?'\x20'+_0xee57e6[_0x196e('0xd8')]['lastName']:''),'body':_0xee57e6[_0x196e('0xdb')]?_0xee57e6[_0x196e('0xdb')][_0x196e('0xe8')]:_0xee57e6['body'],'direction':_0xee57e6[_0x196e('0xdd')]==='out'?'A':'C','secret':_0xee57e6[_0x196e('0xde')],'read':_0xee57e6['read'],'attachment':_0xee57e6[_0x196e('0xdb')]};})['value']()};return ejs['renderFile'](path['join'](config[_0x196e('0xd4')],_0x196e('0xd1'),'views',_0x196e('0xec')),{'interaction':_0x578049})[_0x196e('0x2a')](function(_0x3ac726){var _0x4e9521=path[_0x196e('0xd0')](_0x51e0fa,_0x196e('0xed')+_0x5898b3['id']+'-'+_0x136927+_0x196e('0xee'));var _0x49961d={'path':_0x4e9521,'channel':_0x196e('0xe3'),'interactionId':_0x5898b3['id']};return pdf['createPdfFromHTML'](_0x3ac726,_0x49961d);})[_0x196e('0x2a')](function(){return new BPromise(function(_0x1290d2,_0x2c9465){zipdir(_0x51e0fa,{'saveTo':_0x494550},function(_0x2dc607,_0x473963){if(_0x2dc607)return _0x2c9465(_0x2dc607);return _0x1290d2(_0x473963);});})[_0x196e('0x2a')](function(){return new BPromise(function(_0x43a1fd,_0x53272c){rimraf(_0x51e0fa,function(_0x25483f){if(_0x25483f)_0x53272c(_0x25483f);return _0x43a1fd();});});})[_0x196e('0x2a')](function(){return _0x6af859[_0x196e('0xcf')](_0x494550,_0x6857ff,function(_0x4994ad){if(_0x4994ad){console[_0x196e('0xef')]('err',_0x4994ad);}else{fs[_0x196e('0xf0')](_0x494550);}});});});}else{return _0x6af859['sendStatus'](0xc8);}})['catch'](handleError(_0x6af859,null));};
\ No newline at end of file
+var _0x182f=['lodash','squel','crypto','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./whatsappInteraction.socket','sendStatus','status','end','undefined','limit','count','offset','Content-Range','apply','update','then','destroy','stack','name','send','map','fullname','TagIds','split','catch','index','WhatsappInteraction','type','model','query','keys','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','filters','select','field','color','from','tools_tags','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','left_join','cm_contacts','o.id\x20=\x20i.UserId','whatsapp_accounts','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','sqlOperator','conditions','length','find','value','having','`\x20>\x200','operator','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','start','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','text','body','some','isEmpty','where','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','i.id','Sequelize','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','t.id\x20IN\x20?','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','sequelize','toString','merge','Account.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','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','WhatsappInteractionId','push','all','rows','show','params','intersection','includeAll','include','create','describe','addMessage','WhatsappMessage','ids','getMessages','findOne','rawAttributes','format','YYYY-MM-DD\x20HH:mm:ss','options','findAll','addTags','spread','Tag','emit','whatsappInteractionTags:save','removeTags','unix','join','root','files','tmp','attachments','transcript-%d-%s.zip','User','Contact','Attachment','Messages','Account','Owner','get','mkdirSync','Whatsapp','N.A.','closed','closedAt','disposition','basename','existsSync','createReadStream','pipe','createWriteStream','direction','System','lastName','views','transcript-','.pdf','createPdfFromHTML','download','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','sox','ejs','fs-extra'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x182f,0xd9));var _0xf182=function(_0xc1cbcb,_0x442d98){_0xc1cbcb=_0xc1cbcb-0x0;var _0x47db48=_0x182f[_0xc1cbcb];return _0x47db48;};'use strict';var emlformat=require(_0xf182('0x0'));var rimraf=require(_0xf182('0x1'));var zipdir=require(_0xf182('0x2'));var jsonpatch=require(_0xf182('0x3'));var rp=require(_0xf182('0x4'));var moment=require(_0xf182('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xf182('0x6'));var csv=require('to-csv');var ejs=require(_0xf182('0x7'));var fs=require('fs');var fs_extra=require(_0xf182('0x8'));var _=require(_0xf182('0x9'));var squel=require(_0xf182('0xa'));var crypto=require(_0xf182('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf182('0xc'));var toCsv=require(_0xf182('0xd'));var querystring=require(_0xf182('0xe'));var Papa=require('papaparse');var Redis=require(_0xf182('0xf'));var authService=require(_0xf182('0x10'));var qs=require(_0xf182('0x11'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xf182('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf182('0x13'))(_0xf182('0x14'));var utils=require('../../config/utils');var config=require(_0xf182('0x15'));var licenseUtil=require(_0xf182('0x16'));var db=require(_0xf182('0x17'))['db'];config[_0xf182('0x18')]=_[_0xf182('0x19')](config[_0xf182('0x18')],{'host':_0xf182('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf182('0x18')]));require(_0xf182('0x1b'))['register'](socket);function respondWithStatusCode(_0x2a651d,_0x29be09){_0x29be09=_0x29be09||0xcc;return function(_0x549fa){if(_0x549fa){return _0x2a651d[_0xf182('0x1c')](_0x29be09);}return _0x2a651d[_0xf182('0x1d')](_0x29be09)[_0xf182('0x1e')]();};}function respondWithResult(_0x594eb6,_0x7a6241){_0x7a6241=_0x7a6241||0xc8;return function(_0x24390f){if(_0x24390f){return _0x594eb6[_0xf182('0x1d')](_0x7a6241)['json'](_0x24390f);}};}function respondWithFilteredResult(_0x4528ec,_0x46242e){return function(_0x3dc607){if(_0x3dc607){var _0x1bd66c=typeof _0x46242e['offset']===_0xf182('0x1f')&&typeof _0x46242e[_0xf182('0x20')]==='undefined';var _0x225938=_0x3dc607[_0xf182('0x21')];var _0x3eb980=_0x1bd66c?0x0:_0x46242e[_0xf182('0x22')];var _0x438572=_0x1bd66c?_0x3dc607[_0xf182('0x21')]:_0x46242e[_0xf182('0x22')]+_0x46242e['limit'];var _0x51d76a;if(_0x438572>=_0x225938){_0x438572=_0x225938;_0x51d76a=0xc8;}else{_0x51d76a=0xce;}_0x4528ec[_0xf182('0x1d')](_0x51d76a);return _0x4528ec['set'](_0xf182('0x23'),_0x3eb980+'-'+_0x438572+'/'+_0x225938)['json'](_0x3dc607);}return null;};}function patchUpdates(_0x559851){return function(_0x14c449){try{jsonpatch[_0xf182('0x24')](_0x14c449,_0x559851,!![]);}catch(_0x526c01){return BPromise['reject'](_0x526c01);}return _0x14c449['save']();};}function saveUpdates(_0x18dffb,_0xe2390){return function(_0x1c1757){if(_0x1c1757){return _0x1c1757[_0xf182('0x25')](_0x18dffb)[_0xf182('0x26')](function(_0x30bd27){return _0x30bd27;});}return null;};}function removeEntity(_0x220a7d,_0x109d43){return function(_0x4c5561){if(_0x4c5561){return _0x4c5561[_0xf182('0x27')]()[_0xf182('0x26')](function(){_0x220a7d[_0xf182('0x1d')](0xcc)[_0xf182('0x1e')]();});}};}function handleEntityNotFound(_0x55c10b,_0x2fb519){return function(_0x5f6e40){if(!_0x5f6e40){_0x55c10b[_0xf182('0x1c')](0x194);}return _0x5f6e40;};}function handleError(_0x588834,_0x186b0d){_0x186b0d=_0x186b0d||0x1f4;return function(_0x3a35bd){logger['error'](_0x3a35bd[_0xf182('0x28')]);if(_0x3a35bd['name']){delete _0x3a35bd[_0xf182('0x29')];}_0x588834[_0xf182('0x1d')](_0x186b0d)[_0xf182('0x2a')](_0x3a35bd);};}function getInteractionUsers(_0x441d24,_0x3959a3){return new BPromise(function(_0x3c7a22,_0x9eaf75){try{if(_0x3959a3[_0x441d24['id']]){_0x441d24['Users']=_[_0xf182('0x2b')](_0x3959a3[_0x441d24['id']],function(_0x406163){return{'id':_0x406163['id'],'fullname':_0x406163[_0xf182('0x2c')]};});}}catch(_0x2c7479){_0x9eaf75(_0x2c7479);}_0x3c7a22(_0x441d24);});}function getInteractionTags(_0x5e05f9,_0x580c1b){return new BPromise(function(_0x1300f8,_0x7149c0){try{if(_0x5e05f9[_0xf182('0x2d')]){_0x5e05f9['Tags']=[];_0x5e05f9[_0xf182('0x2d')][_0xf182('0x2e')](',')['forEach'](function(_0x3d7d63){_0x5e05f9['Tags']['push'](_0x580c1b[_0x3d7d63]);});}delete _0x5e05f9['TagIds'];}catch(_0x44f4dd){_0x7149c0(_0x44f4dd);}_0x1300f8(_0x5e05f9);});}function updateWhatsappInteraction(_0xdc1454,_0x3bd8ec,_0x463c22){return new BPromise(function(_0x752a31,_0x513c2e){return getInteractionUsers(_0xdc1454,_0x463c22)[_0xf182('0x26')](function(_0x540f24){return getInteractionTags(_0x540f24,_0x3bd8ec);})['then'](function(_0xb57d23){_0x752a31(_0xb57d23);})[_0xf182('0x2f')](function(_0x484746){_0x513c2e(_0x484746);});});}exports[_0xf182('0x30')]=function(_0x1b3a1b,_0x14b5e4){var _0x1a31a8={},_0x254ea9={},_0x34599f={'count':0x0,'rows':[]};var _0x11f6e0=_[_0xf182('0x2b')](db[_0xf182('0x31')]['rawAttributes'],function(_0x1080d2){return{'name':_0x1080d2['fieldName'],'type':_0x1080d2[_0xf182('0x32')]['key']};});_0x254ea9[_0xf182('0x33')]=_[_0xf182('0x2b')](_0x11f6e0,'name');_0x254ea9[_0xf182('0x34')]=_[_0xf182('0x35')](_0x1b3a1b[_0xf182('0x34')]);_0x254ea9['filters']=_['intersection'](_0x254ea9['model'],_0x254ea9[_0xf182('0x34')]);_0x1a31a8[_0xf182('0x36')]=_['intersection'](_0x254ea9[_0xf182('0x33')],qs['fields'](_0x1b3a1b[_0xf182('0x34')][_0xf182('0x37')]));_0x1a31a8[_0xf182('0x36')]=_0x1a31a8[_0xf182('0x36')]['length']?_0x1a31a8[_0xf182('0x36')]:_0x254ea9[_0xf182('0x33')];if(!_0x1b3a1b[_0xf182('0x34')][_0xf182('0x38')](_0xf182('0x39'))){_0x1a31a8['limit']=qs['limit'](_0x1b3a1b[_0xf182('0x34')]['limit']);_0x1a31a8[_0xf182('0x22')]=qs[_0xf182('0x22')](_0x1b3a1b['query'][_0xf182('0x22')]);}_0x1a31a8[_0xf182('0x3a')]=qs[_0xf182('0x3b')](_0x1b3a1b['query']['sort']);_0x1a31a8['where']=qs['filters'](_[_0xf182('0x3c')](_0x1b3a1b[_0xf182('0x34')],_0x254ea9[_0xf182('0x3d')]),_0x11f6e0);var _0x3cbd96=[];var _0xe1b6ba=squel[_0xf182('0x3e')]()[_0xf182('0x3f')]('id')['field'](_0xf182('0x29'))['field'](_0xf182('0x40'))[_0xf182('0x41')](_0xf182('0x42'));var _0x431ad7=squel['select']()[_0xf182('0x3f')]('u.id')[_0xf182('0x3f')](_0xf182('0x43'))[_0xf182('0x3f')](_0xf182('0x44'))[_0xf182('0x41')](_0xf182('0x45'),'ui')['left_join'](_0xf182('0x46'),'u',_0xf182('0x47'));var _0x39c7f5=squel[_0xf182('0x3e')]()[_0xf182('0x41')](_0xf182('0x48'),'i')[_0xf182('0x49')](_0xf182('0x4a'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xf182('0x49')](_0xf182('0x46'),'o',_0xf182('0x4b'))['left_join'](_0xf182('0x4c'),'a','a.id\x20=\x20i.WhatsappAccountId')[_0xf182('0x49')](_0xf182('0x4d'),'me',_0xf182('0x4e'))['left_join']('whatsapp_interaction_has_tags','it',_0xf182('0x4f'))['left_join'](_0xf182('0x42'),'t',_0xf182('0x50'));var _0x28a76e=squel[_0xf182('0x51')]();var _0x111a54=[];var _0x1f965a=squel[_0xf182('0x51')]();var _0x33769a;if(_0x1b3a1b[_0xf182('0x34')]['search']){_0x33769a=as['parseSearch'](_0x1b3a1b[_0xf182('0x34')][_0xf182('0x52')]);var _0x3ae793=_0x33769a[_0xf182('0x53')];for(var _0x490ad4=0x0;_0x490ad4<_0x33769a[_0xf182('0x54')][_0xf182('0x55')];_0x490ad4++){var _0x1a8707=_0x33769a[_0xf182('0x54')][_0x490ad4];var _0x33a7d6='i';var _0x3f1a3e=_[_0xf182('0x56')](_0x11f6e0,[_0xf182('0x29'),_0x1a8707['field']]);if(!_0x3f1a3e){switch(_0x1a8707[_0xf182('0x3f')]){case'unreadMessages':if(_0x1a8707[_0xf182('0x57')]==0x1){_0x39c7f5[_0xf182('0x58')]('`'+_0x1a8707['field']+'`\x20=\x200');}else{_0x39c7f5[_0xf182('0x58')]('`'+_0x1a8707[_0xf182('0x3f')]+_0xf182('0x59'));}break;case'Contact':if(_0x1a8707[_0xf182('0x5a')]==='$substring'){if(_0x1a8707[_0xf182('0x57')][_0xf182('0x2e')]('\x20')[_0xf182('0x55')]>0x1){_0x28a76e[_0x3ae793](_0xf182('0x5b'),qs[_0xf182('0x5c')](_0x1a8707[_0xf182('0x57')]),null);}else{var _0x2d109c='%'+_0x1a8707[_0xf182('0x57')]+'%';_0x28a76e[_0x3ae793](_0xf182('0x5d'),_0x2d109c,_0x2d109c,_0x2d109c);}}else{_0x3f1a3e=_[_0xf182('0x56')](_0x11f6e0,[_0xf182('0x29'),'ContactId']);_0x1a8707[_0xf182('0x3f')]=_0xf182('0x5e');_0x2dfe87=as[_0xf182('0x5f')](_0x33a7d6,_0x3f1a3e['type'],_0x1a8707);_0x28a76e[_0x3ae793](_0x2dfe87['text'],_0x2dfe87[_0xf182('0x57')][_0xf182('0x60')],_0x2dfe87[_0xf182('0x57')][_0xf182('0x1e')]);}break;case'Tag':var _0x3c70a2=_0x1a8707[_0xf182('0x57')][_0xf182('0x2e')](',')[_0xf182('0x2b')](function(_0x3e7d3e){return Number(_0x3e7d3e);});_0x3c70a2[_0xf182('0x61')](function(_0x4bf01f){_0x1f965a['or'](_0xf182('0x62'),'%,'+_0x4bf01f+',%');});_0x111a54=_['union'](_0x111a54,_0x3c70a2);break;case'User':if(_0x1a8707[_0xf182('0x5a')]===_0xf182('0x63')){_0x28a76e[_0x3ae793](_0xf182('0x64'),'%'+_0x1a8707[_0xf182('0x57')]+'%',null);}else{_0x3f1a3e=_['find'](_0x11f6e0,[_0xf182('0x29'),_0xf182('0x65')]);_0x1a8707[_0xf182('0x3f')]='UserId';_0x2dfe87=as['buildExpression'](_0x33a7d6,_0x3f1a3e[_0xf182('0x32')],_0x1a8707);_0x28a76e[_0x3ae793](_0x2dfe87[_0xf182('0x66')],_0x2dfe87[_0xf182('0x57')][_0xf182('0x60')],_0x2dfe87[_0xf182('0x57')]['end']);}break;case _0xf182('0x67'):_0x2dfe87=as['buildExpression']('me',null,_0x1a8707);_0x28a76e[_0x3ae793](_0x2dfe87[_0xf182('0x66')],_0x2dfe87[_0xf182('0x57')]['start'],_0x2dfe87[_0xf182('0x57')][_0xf182('0x1e')]);break;}}else{var _0x2dfe87=as[_0xf182('0x5f')](_0x33a7d6,_0x3f1a3e[_0xf182('0x32')],_0x1a8707);_0x28a76e[_0x3ae793](_0x2dfe87[_0xf182('0x66')],_0x2dfe87[_0xf182('0x57')]['start'],_0x2dfe87['value']['end']);}}}else{var _0xde79cb=_(_0x1b3a1b[_0xf182('0x34')])['keys']()['map'](function(_0x4eb2d3){return _[_0xf182('0x68')](_0x11f6e0,['name',_0x4eb2d3])?_0x4eb2d3:undefined;})['compact']()['value']();if(!_[_0xf182('0x69')](_0xde79cb)){_0xde79cb[_0xf182('0x61')](function(_0x4a04bd){if(_0x4a04bd==='WhatsappAccountId'){_0x39c7f5[_0xf182('0x6a')](_0xf182('0x6b'),[][_0xf182('0x6c')](_0x1b3a1b[_0xf182('0x34')][_0x4a04bd]));}else if(_0x4a04bd===_0xf182('0x6d')){var _0x51c946=JSON[_0xf182('0x6e')](_0x1b3a1b[_0xf182('0x34')][_0x4a04bd])[_0xf182('0x6f')];var _0x166b91=JSON[_0xf182('0x6e')](_0x1b3a1b[_0xf182('0x34')][_0x4a04bd])['$lte'];_0x39c7f5[_0xf182('0x6a')](_0xf182('0x70'),_0x51c946,_0x166b91);}else{if(_0x1b3a1b[_0xf182('0x34')][_0x4a04bd]===_0xf182('0x71')){_0x39c7f5[_0xf182('0x6a')]('i.'+_0x4a04bd+_0xf182('0x72'));}else{_0x39c7f5[_0xf182('0x6a')]('i.'+_0x4a04bd+_0xf182('0x73'),_0x1b3a1b['query'][_0x4a04bd]);}}});}if(_0x1b3a1b['query'][_0xf182('0x74')]){if(_0x1b3a1b[_0xf182('0x34')]['read']==0x1){_0x39c7f5['having'](_0xf182('0x75'));}else{_0x39c7f5[_0xf182('0x58')]('`unreadMessages`\x20>\x200');}}if(_0x1b3a1b[_0xf182('0x34')][_0xf182('0x76')]){_0x111a54=_[_0xf182('0x77')](_0x1b3a1b[_0xf182('0x34')]['tag'])?_0x1b3a1b[_0xf182('0x34')]['tag']:new Array(_0x1b3a1b[_0xf182('0x34')][_0xf182('0x76')]);_0x111a54[_0xf182('0x61')](function(_0x4858c9){_0x1f965a['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4858c9+',%');});}if(_0x1b3a1b['query'][_0xf182('0x78')]){var _0x362dc5=_0x1b3a1b[_0xf182('0x34')][_0xf182('0x78')][_0xf182('0x79')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xf182('0x7a')](_0x362dc5)){_0x28a76e['or'](_0xf182('0x7b'),_0x362dc5+'%')['or'](_0xf182('0x7c'),_0x362dc5+'%');}else{_0x28a76e['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xf182('0x5c')](_0x362dc5))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x362dc5+'%');}}}_0x39c7f5['where'](_0x28a76e);_0x39c7f5['group'](_0xf182('0x7d'));var _0x4d915b={'type':db[_0xf182('0x7e')]['QueryTypes'][_0xf182('0x7f')],'raw':!![]};var _0x37a411=_0x39c7f5[_0xf182('0x80')]();_0x37a411['field'](_0xf182('0x7d'));_0x37a411[_0xf182('0x3f')](_0xf182('0x81'),_0xf182('0x82'));if(_0x1a31a8[_0xf182('0x3a')]){_0x1a31a8[_0xf182('0x3a')]['forEach'](function(_0x734300){var _0x241ef4=_0x734300[0x0]===_0xf182('0x83')?_0x734300[0x0]:'i.'+_0x734300[0x0];_0x39c7f5[_0xf182('0x3a')](_0x241ef4,_0x734300[0x1]==='DESC'?![]:!![]);});}if(!_[_0xf182('0x69')](_0x111a54)){_0x39c7f5[_0xf182('0x58')](_0x1f965a);_0x37a411[_0xf182('0x6a')](_0xf182('0x84'),_0x111a54);}BPromise['resolve']()['then'](function(){if(!_0x33769a){if(_0x1b3a1b[_0xf182('0x34')][_0xf182('0x85')])return;_0x37a411[_0xf182('0x6a')](_0xf182('0x86'));_0x39c7f5[_0xf182('0x6a')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x1b3a1b[_0xf182('0x87')][_0xf182('0x88')]!==_0xf182('0x89'))return;return _0x1b3a1b['user'][_0xf182('0x8a')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2161b1){if(_['isEmpty'](_0x2161b1)){_0x37a411[_0xf182('0x6a')](_0xf182('0x8b'));_0x39c7f5[_0xf182('0x6a')](_0xf182('0x8b'));}else{_0x37a411['where']('i.WhatsappAccountId\x20IN\x20?',_[_0xf182('0x2b')](_0x2161b1,'id'));_0x39c7f5[_0xf182('0x6a')](_0xf182('0x6b'),_['map'](_0x2161b1,'id'));}});})[_0xf182('0x26')](function(){if(_0x1b3a1b[_0xf182('0x87')][_0xf182('0x88')]===_0xf182('0x89')&&!_0x33769a&&!_0x1b3a1b[_0xf182('0x34')][_0xf182('0x85')])return[];return db[_0xf182('0x8c')]['query'](_0x37a411[_0xf182('0x8d')](),_0x4d915b);})[_0xf182('0x26')](function(_0x181d11){_0x34599f['count']=_0x181d11[_0xf182('0x55')];if(_0x34599f[_0xf182('0x21')]===0x0)return[];return db[_0xf182('0x8c')][_0xf182('0x34')](_0xe1b6ba[_0xf182('0x8d')](),_0x4d915b)[_0xf182('0x26')](function(_0x34a11a){_0x3cbd96=_['keyBy'](_0x34a11a,'id');_0x4d915b=_[_0xf182('0x8e')](_0x4d915b,{'model':db[_0xf182('0x31')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1b3a1b['query']['fields']){_0x1a31a8[_0xf182('0x36')][_0xf182('0x61')](function(_0x1e4897){_0x39c7f5[_0xf182('0x3f')]('i.'+_0x1e4897);});}else{_0x39c7f5[_0xf182('0x3f')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xf182('0x82'));_0x39c7f5[_0xf182('0x3f')]('a.key',_0xf182('0x8f'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x90'),_0xf182('0x91'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x92'),'contactName');_0x39c7f5[_0xf182('0x3f')](_0xf182('0x93'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x94'),_0xf182('0x95'));_0x39c7f5[_0xf182('0x3f')]('c.lastName',_0xf182('0x96'));_0x39c7f5['field'](_0xf182('0x97'),_0xf182('0x98'));_0x39c7f5['field'](_0xf182('0x99'),_0xf182('0x9a'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x9b'),_0xf182('0x9c'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x9d'),_0xf182('0x9e'));_0x39c7f5[_0xf182('0x3f')](_0xf182('0x9f'),'Owner.fullname');_0x39c7f5[_0xf182('0x3f')](_0xf182('0xa0'),'Owner.internal');_0x39c7f5['field'](_0xf182('0xa1'),_0xf182('0x2d'));}if(_0x1a31a8[_0xf182('0x20')])_0x39c7f5['limit'](_0x1a31a8[_0xf182('0x20')]);if(_0x1a31a8[_0xf182('0x22')])_0x39c7f5[_0xf182('0x22')](_0x1a31a8[_0xf182('0x22')]);return db[_0xf182('0x8c')]['query'](_0x39c7f5['toString'](),_0x4d915b);})[_0xf182('0x26')](function(_0xf60eab){if(_0xf60eab[_0xf182('0x55')]>0x0)_0x431ad7[_0xf182('0x6a')]('ui.WhatsappInteractionId\x20IN\x20?',_[_0xf182('0x2b')](_0xf60eab,'id'));return db['sequelize'][_0xf182('0x34')](_0x431ad7[_0xf182('0x8d')](),_0x4d915b)[_0xf182('0x26')](function(_0x4ab736){var _0x1737d9=_[_0xf182('0xa2')](_0x4ab736,_0xf182('0xa3'));var _0x24e535=[];_0xf60eab[_0xf182('0x61')](function(_0x3092ec){_0x24e535[_0xf182('0xa4')](updateWhatsappInteraction(_0x3092ec,_0x3cbd96,_0x1737d9));});return BPromise[_0xf182('0xa5')](_0x24e535);});});})['then'](function(_0x224f99){_0x34599f[_0xf182('0xa6')]=_0x224f99;return _0x34599f;})['then'](respondWithFilteredResult(_0x14b5e4,_0x1a31a8))['catch'](handleError(_0x14b5e4,null));};exports[_0xf182('0xa7')]=function(_0x5816b5,_0x30ea3c){var _0x59d6f3={'raw':![],'where':{'id':_0x5816b5[_0xf182('0xa8')]['id']}},_0x514a81={};_0x514a81['model']=_[_0xf182('0x35')](db[_0xf182('0x31')]['rawAttributes']);_0x514a81['query']=_['keys'](_0x5816b5['query']);_0x514a81[_0xf182('0x3d')]=_[_0xf182('0xa9')](_0x514a81[_0xf182('0x33')],_0x514a81['query']);_0x59d6f3[_0xf182('0x36')]=_[_0xf182('0xa9')](_0x514a81['model'],qs[_0xf182('0x37')](_0x5816b5[_0xf182('0x34')][_0xf182('0x37')]));_0x59d6f3[_0xf182('0x36')]=_0x59d6f3[_0xf182('0x36')]['length']?_0x59d6f3['attributes']:_0x514a81['model'];if(_0x5816b5[_0xf182('0x34')][_0xf182('0xaa')]){_0x59d6f3[_0xf182('0xab')]=[{'all':!![]}];}_0x59d6f3=_[_0xf182('0x8e')]({},_0x59d6f3,_0x5816b5['options']);return db[_0xf182('0x31')][_0xf182('0x56')](_0x59d6f3)[_0xf182('0x26')](handleEntityNotFound(_0x30ea3c,null))[_0xf182('0x26')](respondWithResult(_0x30ea3c,null))[_0xf182('0x2f')](handleError(_0x30ea3c,null));};exports[_0xf182('0xac')]=function(_0x528cf5,_0x5bfd86){return db['WhatsappInteraction']['create'](_0x528cf5[_0xf182('0x67')],{})['then'](respondWithResult(_0x5bfd86,0xc9))[_0xf182('0x2f')](handleError(_0x5bfd86,null));};exports[_0xf182('0x25')]=function(_0x5b2f68,_0x19c376){if(_0x5b2f68['body']['id']){delete _0x5b2f68['body']['id'];}return db[_0xf182('0x31')][_0xf182('0x56')]({'where':{'id':_0x5b2f68[_0xf182('0xa8')]['id']}})[_0xf182('0x26')](handleEntityNotFound(_0x19c376,null))[_0xf182('0x26')](saveUpdates(_0x5b2f68['body'],null))['then'](respondWithResult(_0x19c376,null))['catch'](handleError(_0x19c376,null));};exports[_0xf182('0x27')]=function(_0x4d8383,_0x4fb12b){return db[_0xf182('0x31')][_0xf182('0x56')]({'where':{'id':_0x4d8383[_0xf182('0xa8')]['id']}})[_0xf182('0x26')](handleEntityNotFound(_0x4fb12b,null))['then'](removeEntity(_0x4fb12b,null))['catch'](handleError(_0x4fb12b,null));};exports[_0xf182('0xad')]=function(_0xe3a642,_0x2d8f0f){return db[_0xf182('0x31')][_0xf182('0xad')]()[_0xf182('0x26')](respondWithResult(_0x2d8f0f,null))[_0xf182('0x2f')](handleError(_0x2d8f0f,null));};exports[_0xf182('0xae')]=function(_0x5e1c65,_0x225c4f,_0x1448b5){return db[_0xf182('0xaf')][_0xf182('0x56')]({'where':{'id':_0x5e1c65['params']['id']}})[_0xf182('0x26')](handleEntityNotFound(_0x225c4f,null))[_0xf182('0x26')](function(_0x110fa0){if(_0x110fa0){return _0x110fa0[_0xf182('0xae')](_0x5e1c65[_0xf182('0x67')][_0xf182('0xb0')],_['omit'](_0x5e1c65[_0xf182('0x67')],['ids','id'])||{});}})[_0xf182('0x26')](respondWithResult(_0x225c4f,null))[_0xf182('0x2f')](handleError(_0x225c4f,null));};exports[_0xf182('0xb1')]=function(_0x473e13,_0x4fcd25,_0x483809){var _0x4fcd42={'raw':![],'where':{}};var _0x219c75={};var _0x5ad806={'count':0x0,'rows':[]};return db[_0xf182('0x31')][_0xf182('0xb2')]({'where':{'id':_0x473e13['params']['id']}})[_0xf182('0x26')](handleEntityNotFound(_0x4fcd25,null))[_0xf182('0x26')](function(_0x1bba23){if(_0x1bba23){_0x219c75[_0xf182('0x33')]=_['keys'](db[_0xf182('0xaf')][_0xf182('0xb3')]);_0x219c75['query']=_['keys'](_0x473e13['query']);_0x219c75[_0xf182('0x3d')]=_['intersection'](_0x219c75[_0xf182('0x33')],_0x219c75[_0xf182('0x34')]);_0x4fcd42['attributes']=_[_0xf182('0xa9')](_0x219c75[_0xf182('0x33')],qs['fields'](_0x473e13[_0xf182('0x34')]['fields']));_0x4fcd42[_0xf182('0x36')]=_0x4fcd42[_0xf182('0x36')][_0xf182('0x55')]?_0x4fcd42[_0xf182('0x36')]:_0x219c75[_0xf182('0x33')];if(!_0x473e13[_0xf182('0x34')][_0xf182('0x38')](_0xf182('0x39'))){_0x4fcd42['limit']=qs[_0xf182('0x20')](_0x473e13[_0xf182('0x34')][_0xf182('0x20')]);_0x4fcd42[_0xf182('0x22')]=qs[_0xf182('0x22')](_0x473e13[_0xf182('0x34')][_0xf182('0x22')]);}_0x4fcd42[_0xf182('0x3a')]=qs[_0xf182('0x3b')](_0x473e13['query']['sort']);_0x4fcd42[_0xf182('0x6a')]=qs[_0xf182('0x3d')](_[_0xf182('0x3c')](_0x473e13['query'],_0x219c75[_0xf182('0x3d')]));_0x4fcd42['where'][_0xf182('0xa3')]=_0x1bba23['id'];if(_0x473e13[_0xf182('0x34')][_0xf182('0x78')]){_0x4fcd42['where']=_[_0xf182('0x8e')](_0x4fcd42[_0xf182('0x6a')],{'$or':_['map'](_0x4fcd42[_0xf182('0x36')],function(_0x5688a4){var _0x92204={};_0x92204[_0x5688a4]={'$like':'%'+_0x473e13[_0xf182('0x34')][_0xf182('0x78')]+'%'};return _0x92204;})});}if(_0x473e13[_0xf182('0x34')][_0xf182('0x6f')]){var _0x2ec391=_0x473e13[_0xf182('0x34')]['$gte'][_0xf182('0x2e')](',');var _0x159e38={};_0x159e38[_0x2ec391[0x0]]={'$gte':moment(_0x2ec391[0x1])[_0xf182('0xb4')](_0xf182('0xb5'))};_0x4fcd42[_0xf182('0x6a')]=_[_0xf182('0x8e')](_0x4fcd42['where'],_0x159e38);}_0x4fcd42=_['merge']({},_0x4fcd42,_0x473e13[_0xf182('0xb6')]);return db['WhatsappMessage'][_0xf182('0x21')]({'where':_0x4fcd42[_0xf182('0x6a')]})['then'](function(_0xe18320){_0x5ad806[_0xf182('0x21')]=_0xe18320;if(_0x473e13[_0xf182('0x34')][_0xf182('0xaa')]){_0x4fcd42[_0xf182('0xab')]=[{'all':!![]}];}return db[_0xf182('0xaf')][_0xf182('0xb7')](_0x4fcd42);})['then'](function(_0x74e79f){_0x5ad806[_0xf182('0xa6')]=_0x74e79f;return _0x5ad806;});}})[_0xf182('0x26')](respondWithFilteredResult(_0x4fcd25,_0x4fcd42))['catch'](handleError(_0x4fcd25,null));};exports[_0xf182('0xb8')]=function(_0x4a244f,_0x2ca54d,_0x4669d8){return db[_0xf182('0x31')][_0xf182('0x56')]({'where':{'id':_0x4a244f['params']['id']}})['then'](handleEntityNotFound(_0x2ca54d,null))[_0xf182('0x26')](function(_0x366056){if(_0x366056){return _0x366056['setTags'](_0x4a244f[_0xf182('0x67')][_0xf182('0xb0')],_['omit'](_0x4a244f[_0xf182('0x67')],[_0xf182('0xb0'),'id'])||{})[_0xf182('0xb9')](function(){return db[_0xf182('0xba')][_0xf182('0xb7')]({'attributes':['id',_0xf182('0x29'),'color'],'where':{'id':_0x4a244f[_0xf182('0x67')][_0xf182('0xb0')]}});})[_0xf182('0x26')](function(_0x5e93ba){socket[_0xf182('0xbb')](_0xf182('0xbc'),{'id':Number(_0x4a244f[_0xf182('0xa8')]['id']),'tags':_0x5e93ba||[]});return{'id':Number(_0x4a244f[_0xf182('0xa8')]['id']),'tags':_0x5e93ba||[]};});}})['then'](respondWithResult(_0x2ca54d,null))[_0xf182('0x2f')](handleError(_0x2ca54d,null));};exports[_0xf182('0xbd')]=function(_0x594643,_0x2cbd60,_0x5805cb){return db[_0xf182('0x31')][_0xf182('0x56')]({'where':{'id':_0x594643[_0xf182('0xa8')]['id']}})['then'](handleEntityNotFound(_0x2cbd60,null))[_0xf182('0x26')](function(_0x2f9fa7){if(_0x2f9fa7){return _0x2f9fa7['removeTags'](_0x594643['query']['ids']);}})['then'](respondWithStatusCode(_0x2cbd60,null))[_0xf182('0x2f')](handleError(_0x2cbd60,null));};exports['download']=function(_0x5593ae,_0x2928b1){var _0x21537d=moment()[_0xf182('0xbe')]()[_0xf182('0x8d')]();var _0x68755b=path[_0xf182('0xbf')](config[_0xf182('0xc0')],'server',_0xf182('0xc1'),_0xf182('0xc2'));var _0x406a10=path[_0xf182('0xbf')](config[_0xf182('0xc0')],'server',_0xf182('0xc1'),_0xf182('0xc3'));var _0x235449=path[_0xf182('0xbf')](_0x68755b,_0x21537d);var _0x3d808e=util[_0xf182('0xb4')](_0xf182('0xc4'),_0x5593ae[_0xf182('0xa8')]['id'],_0x21537d);var _0x13a2b4=path[_0xf182('0xbf')](_0x68755b,_0x3d808e);var _0x7fb7c7=[];_0x7fb7c7[_0xf182('0xa4')]({'model':db[_0xf182('0xc5')],'as':_0xf182('0xc5'),'attributes':['id',_0xf182('0x2c')],'raw':!![]});_0x7fb7c7[_0xf182('0xa4')]({'model':db['CmContact'],'as':_0xf182('0xc6'),'attributes':['id','firstName','lastName'],'raw':!![]});if(_0x5593ae['query'][_0xf182('0xc3')]){_0x7fb7c7[_0xf182('0xa4')]({'model':db[_0xf182('0xc7')],'as':_0xf182('0xc7'),'raw':!![]});}var _0x25b572=[{'model':db[_0xf182('0xaf')],'as':_0xf182('0xc8'),'attributes':['id','body',_0xf182('0x6d'),'direction','secret',_0xf182('0x74')],'include':_0x7fb7c7}];_0x25b572[_0xf182('0xa4')]({'model':db['WhatsappAccount'],'as':_0xf182('0xc9'),'attributes':['id',_0xf182('0x29')]});_0x25b572[_0xf182('0xa4')]({'model':db[_0xf182('0xc5')],'as':_0xf182('0xca'),'attributes':['id',_0xf182('0x2c')]});return db[_0xf182('0x31')]['find']({'where':{'id':_0x5593ae[_0xf182('0xa8')]['id']},'include':_0x25b572})['then'](handleEntityNotFound(_0x2928b1,null))[_0xf182('0x26')](function(_0xfe56e3){if(_0xfe56e3){var _0x5a8c03=_0xfe56e3[_0xf182('0xcb')]({'plain':!![]});fs[_0xf182('0xcc')](_0x235449);var _0x5f1487={'channel':_0xf182('0xcd'),'account':_0x5a8c03[_0xf182('0xc9')][_0xf182('0x29')],'agent':_0x5a8c03['Owner']?_0x5a8c03[_0xf182('0xca')][_0xf182('0x2c')]:_0xf182('0xce'),'createdAt':moment(_0x5a8c03[_0xf182('0x6d')])[_0xf182('0xb4')](_0xf182('0xb5'))[_0xf182('0x8d')](),'closedAt':_0x5a8c03[_0xf182('0xcf')]?moment(_0x5a8c03[_0xf182('0xd0')])[_0xf182('0xb4')](_0xf182('0xb5'))[_0xf182('0x8d')]():'','disposition':_0x5a8c03[_0xf182('0xd1')],'messages':_(_0x5a8c03[_0xf182('0xc8')])[_0xf182('0x78')]({'secret':![]})[_0xf182('0x2b')](function(_0x5e5ab3){if(_0x5e5ab3['Attachment']){var _0x9bd2cd=path[_0xf182('0xbf')](_0x406a10,_0x5e5ab3[_0xf182('0xc7')][_0xf182('0xd2')]);if(fs[_0xf182('0xd3')](_0x9bd2cd)){fs[_0xf182('0xd4')](_0x9bd2cd)[_0xf182('0xd5')](fs[_0xf182('0xd6')](path[_0xf182('0xbf')](_0x235449,_0x5e5ab3[_0xf182('0xc7')][_0xf182('0xd2')])));}}return{'date':moment(_0x5e5ab3[_0xf182('0x6d')])[_0xf182('0xb4')](_0xf182('0xb5'))['toString'](),'sender':_0x5e5ab3[_0xf182('0xd7')]==='out'?_0x5e5ab3[_0xf182('0xc5')]?_0x5e5ab3[_0xf182('0xc5')][_0xf182('0x2c')]:_0xf182('0xd8'):_0x5e5ab3['Contact']['firstName']+(_0x5e5ab3[_0xf182('0xc6')][_0xf182('0xd9')]?'\x20'+_0x5e5ab3[_0xf182('0xc6')][_0xf182('0xd9')]:''),'body':_0x5e5ab3[_0xf182('0xc7')]?_0x5e5ab3[_0xf182('0xc7')][_0xf182('0xd2')]:_0x5e5ab3[_0xf182('0x67')],'direction':_0x5e5ab3['direction']==='out'?'A':'C','secret':_0x5e5ab3['secret'],'read':_0x5e5ab3[_0xf182('0x74')],'attachment':_0x5e5ab3[_0xf182('0xc7')]};})[_0xf182('0x57')]()};return ejs['renderFile'](path[_0xf182('0xbf')](config[_0xf182('0xc0')],'server',_0xf182('0xda'),'downloadInteraction.html'),{'interaction':_0x5f1487})[_0xf182('0x26')](function(_0x177c9e){var _0x3f8d2d=path[_0xf182('0xbf')](_0x235449,_0xf182('0xdb')+_0x5a8c03['id']+'-'+_0x21537d+_0xf182('0xdc'));var _0x4b00ab={'path':_0x3f8d2d,'channel':_0xf182('0xcd'),'interactionId':_0x5a8c03['id']};return pdf[_0xf182('0xdd')](_0x177c9e,_0x4b00ab);})['then'](function(){return new BPromise(function(_0x5a8509,_0x10977b){zipdir(_0x235449,{'saveTo':_0x13a2b4},function(_0x3a20b0,_0x498d2e){if(_0x3a20b0)return _0x10977b(_0x3a20b0);return _0x5a8509(_0x498d2e);});})['then'](function(){return new BPromise(function(_0x140237,_0x2d3dcc){rimraf(_0x235449,function(_0x3a7898){if(_0x3a7898)_0x2d3dcc(_0x3a7898);return _0x140237();});});})['then'](function(){return _0x2928b1[_0xf182('0xde')](_0x13a2b4,_0x3d808e,function(_0xeeae41){if(_0xeeae41){console[_0xf182('0xdf')](_0xf182('0xe0'),_0xeeae41);}else{fs[_0xf182('0xe1')](_0x13a2b4);}});});});}else{return _0x2928b1['sendStatus'](0xc8);}})['catch'](handleError(_0x2928b1,null));};
\ No newline at end of file