Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index d40df85..c6e966d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4bf1=['../../config/logger','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','count','offset','limit','set','apply','save','update','then','destroy','error','stack','send','Users','map','TagIds','split','forEach','Tags','push','index','WhatsappInteraction','rawAttributes','type','key','model','name','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','select','from','field','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','left_join','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','users','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','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','find','unreadMessages','value','having','`\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','buildExpression','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','text','body','some','isEmpty','WhatsappAccountId','$gte','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','tag','isArray','filter','replace','\x27\x27\x27\x27','isNumeric','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?','Sequelize','clone','DESC','t.id\x20IN\x20?','resolve','journey','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','toString','sequelize','keyBy','merge','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','o.fullname','Owner.fullname','o.internal','WhatsappInteractionId','all','rows','catch','show','params','includeAll','options','create','describe','addMessage','omit','ids','findOne','WhatsappMessage','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','setTags','spread','color','emit','removeTags','download','unix','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','fullname','firstName','Attachment','Messages','createdAt','secret','Owner','get','mkdirSync','10px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','30px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','%s\x20#%d','Whatsapp','YYYY-MM-DD','N.A.','basename','existsSync','createReadStream','pipe','createWriteStream','direction','out','System','lastName','renderFile','views','downloadInteraction.html','toFile','transcript-','.pdf','log','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','ejs','lodash','squel','jsforce','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x327dc3,_0x3e78d2){var _0x599437=function(_0x1fbad5){while(--_0x1fbad5){_0x327dc3['push'](_0x327dc3['shift']());}};_0x599437(++_0x3e78d2);}(_0x4bf1,0xd6));var _0x14bf=function(_0x1337df,_0x58c59b){_0x1337df=_0x1337df-0x0;var _0x50641f=_0x4bf1[_0x1337df];return _0x50641f;};'use strict';var pdf=require(_0x14bf('0x0'));var emlformat=require(_0x14bf('0x1'));var rimraf=require(_0x14bf('0x2'));var zipdir=require(_0x14bf('0x3'));var jsonpatch=require(_0x14bf('0x4'));var rp=require('request-promise');var moment=require(_0x14bf('0x5'));var BPromise=require(_0x14bf('0x6'));var Mustache=require(_0x14bf('0x7'));var util=require('util');var path=require(_0x14bf('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x14bf('0x9'));var fs=require('fs');var _=require(_0x14bf('0xa'));var squel=require(_0x14bf('0xb'));var crypto=require('crypto');var jsforce=require(_0x14bf('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x14bf('0xd'));var querystring=require('querystring');var Papa=require(_0x14bf('0xe'));var Redis=require(_0x14bf('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x14bf('0x10'));var as=require(_0x14bf('0x11'));var hardwareService=require(_0x14bf('0x12'));var logger=require(_0x14bf('0x13'))('api');var utils=require(_0x14bf('0x14'));var config=require(_0x14bf('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x14bf('0x16')]=_[_0x14bf('0x17')](config['redis'],{'host':_0x14bf('0x18'),'port':0x18eb});var socket=require(_0x14bf('0x19'))(new Redis(config[_0x14bf('0x16')]));require(_0x14bf('0x1a'))[_0x14bf('0x1b')](socket);function respondWithStatusCode(_0x3fb2d6,_0x5f40f2){_0x5f40f2=_0x5f40f2||0xcc;return function(_0x58fb2c){if(_0x58fb2c){return _0x3fb2d6[_0x14bf('0x1c')](_0x5f40f2);}return _0x3fb2d6[_0x14bf('0x1d')](_0x5f40f2)[_0x14bf('0x1e')]();};}function respondWithResult(_0x29c76d,_0x8ee2dc){_0x8ee2dc=_0x8ee2dc||0xc8;return function(_0x2e2eff){if(_0x2e2eff){return _0x29c76d[_0x14bf('0x1d')](_0x8ee2dc)[_0x14bf('0x1f')](_0x2e2eff);}};}function respondWithFilteredResult(_0x21e3b7,_0x172e57){return function(_0x2df04d){if(_0x2df04d){var _0x484b73=_0x2df04d[_0x14bf('0x20')],_0x49985d=_0x172e57[_0x14bf('0x21')],_0x3ddf43=_0x172e57[_0x14bf('0x21')]+_0x172e57[_0x14bf('0x22')],_0x512d2c;if(_0x3ddf43>=_0x484b73){_0x3ddf43=_0x484b73;_0x512d2c=0xc8;}else{_0x512d2c=0xce;}_0x21e3b7['status'](_0x512d2c);return _0x21e3b7[_0x14bf('0x23')]('Content-Range',_0x49985d+'-'+_0x3ddf43+'/'+_0x484b73)[_0x14bf('0x1f')](_0x2df04d);}return null;};}function patchUpdates(_0x5b89db){return function(_0x6c38a5){try{jsonpatch[_0x14bf('0x24')](_0x6c38a5,_0x5b89db,!![]);}catch(_0x38f950){return BPromise['reject'](_0x38f950);}return _0x6c38a5[_0x14bf('0x25')]();};}function saveUpdates(_0x3778d2,_0x403aed){return function(_0x5c7555){if(_0x5c7555){return _0x5c7555[_0x14bf('0x26')](_0x3778d2)[_0x14bf('0x27')](function(_0x543ee1){return _0x543ee1;});}return null;};}function removeEntity(_0x239982,_0x52786e){return function(_0xd8835d){if(_0xd8835d){return _0xd8835d[_0x14bf('0x28')]()[_0x14bf('0x27')](function(){_0x239982[_0x14bf('0x1d')](0xcc)[_0x14bf('0x1e')]();});}};}function handleEntityNotFound(_0x49a8f1,_0x33c1d1){return function(_0x56fb0a){if(!_0x56fb0a){_0x49a8f1[_0x14bf('0x1c')](0x194);}return _0x56fb0a;};}function handleError(_0x15fc26,_0x36c6cb){_0x36c6cb=_0x36c6cb||0x1f4;return function(_0x530946){logger[_0x14bf('0x29')](_0x530946[_0x14bf('0x2a')]);if(_0x530946['name']){delete _0x530946['name'];}_0x15fc26[_0x14bf('0x1d')](_0x36c6cb)[_0x14bf('0x2b')](_0x530946);};}function getInteractionUsers(_0x55cedd,_0x6bbe21){return new BPromise(function(_0xd6739a,_0x47650a){try{if(_0x6bbe21[_0x55cedd['id']]){_0x55cedd[_0x14bf('0x2c')]=_[_0x14bf('0x2d')](_0x6bbe21[_0x55cedd['id']],function(_0x3e4ed0){return{'id':_0x3e4ed0['id'],'fullname':_0x3e4ed0['fullname']};});}}catch(_0x2e4a55){_0x47650a(_0x2e4a55);}_0xd6739a(_0x55cedd);});}function getInteractionTags(_0x4025b5,_0x24bc12){return new BPromise(function(_0x740735,_0xcd5be3){try{if(_0x4025b5[_0x14bf('0x2e')]){_0x4025b5['Tags']=[];_0x4025b5[_0x14bf('0x2e')][_0x14bf('0x2f')](',')[_0x14bf('0x30')](function(_0x4eee41){_0x4025b5[_0x14bf('0x31')][_0x14bf('0x32')](_0x24bc12[_0x4eee41]);});}delete _0x4025b5[_0x14bf('0x2e')];}catch(_0x1da7f6){_0xcd5be3(_0x1da7f6);}_0x740735(_0x4025b5);});}function updateWhatsappInteraction(_0x2fc21e,_0xa1b220,_0x508706){return new BPromise(function(_0x44a42a,_0x385cb5){return getInteractionUsers(_0x2fc21e,_0x508706)['then'](function(_0x28d799){return getInteractionTags(_0x28d799,_0xa1b220);})[_0x14bf('0x27')](function(_0x7f6dfb){_0x44a42a(_0x7f6dfb);})['catch'](function(_0x7ecc4c){_0x385cb5(_0x7ecc4c);});});}exports[_0x14bf('0x33')]=function(_0x2a9995,_0x315c09){var _0x55a2d0={},_0x535446={},_0x58e1cf={'count':0x0,'rows':[]};var _0x5eaad8=_[_0x14bf('0x2d')](db[_0x14bf('0x34')][_0x14bf('0x35')],function(_0x5497de){return{'name':_0x5497de['fieldName'],'type':_0x5497de[_0x14bf('0x36')][_0x14bf('0x37')]};});_0x535446[_0x14bf('0x38')]=_[_0x14bf('0x2d')](_0x5eaad8,_0x14bf('0x39'));_0x535446[_0x14bf('0x3a')]=_[_0x14bf('0x3b')](_0x2a9995[_0x14bf('0x3a')]);_0x535446['filters']=_['intersection'](_0x535446[_0x14bf('0x38')],_0x535446[_0x14bf('0x3a')]);_0x55a2d0[_0x14bf('0x3c')]=_[_0x14bf('0x3d')](_0x535446['model'],qs[_0x14bf('0x3e')](_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x3e')]));_0x55a2d0[_0x14bf('0x3c')]=_0x55a2d0[_0x14bf('0x3c')][_0x14bf('0x3f')]?_0x55a2d0['attributes']:_0x535446[_0x14bf('0x38')];if(!_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x40')](_0x14bf('0x41'))){_0x55a2d0['limit']=qs[_0x14bf('0x22')](_0x2a9995['query'][_0x14bf('0x22')]);_0x55a2d0[_0x14bf('0x21')]=qs[_0x14bf('0x21')](_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x21')]);}_0x55a2d0[_0x14bf('0x42')]=qs[_0x14bf('0x43')](_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x43')]);_0x55a2d0[_0x14bf('0x44')]=qs[_0x14bf('0x45')](_[_0x14bf('0x46')](_0x2a9995[_0x14bf('0x3a')],_0x535446['filters']),_0x5eaad8);var _0x22d5c6=[];var _0x5c35fc=squel[_0x14bf('0x47')]()['field']('id')['field']('name')['field']('color')[_0x14bf('0x48')]('tools_tags');var _0x397365=squel[_0x14bf('0x47')]()[_0x14bf('0x49')]('u.id')[_0x14bf('0x49')](_0x14bf('0x4a'))['field'](_0x14bf('0x4b'))[_0x14bf('0x48')](_0x14bf('0x4c'),'ui')[_0x14bf('0x4d')]('users','u',_0x14bf('0x4e'));var _0x1f7457=squel['select']()[_0x14bf('0x48')](_0x14bf('0x4f'),'i')[_0x14bf('0x4d')](_0x14bf('0x50'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0x14bf('0x4d')](_0x14bf('0x51'),'o','o.id\x20=\x20i.UserId')[_0x14bf('0x4d')](_0x14bf('0x52'),'a',_0x14bf('0x53'))['left_join'](_0x14bf('0x54'),'me',_0x14bf('0x55'))[_0x14bf('0x4d')](_0x14bf('0x56'),'it',_0x14bf('0x57'))[_0x14bf('0x4d')](_0x14bf('0x58'),'t',_0x14bf('0x59'));var _0x269f38=squel[_0x14bf('0x5a')]();var _0x1b08fa=[];var _0x566a29=squel[_0x14bf('0x5a')]();var _0x39eb4a;if(_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x5b')]){_0x39eb4a=as[_0x14bf('0x5c')](_0x2a9995[_0x14bf('0x3a')]['search']);var _0x551ffc=_0x39eb4a[_0x14bf('0x5d')];for(var _0x328df1=0x0;_0x328df1<_0x39eb4a['conditions'][_0x14bf('0x3f')];_0x328df1++){var _0x24a735=_0x39eb4a['conditions'][_0x328df1];var _0x1b6ff6='i';var _0x4cad59=_[_0x14bf('0x5e')](_0x5eaad8,[_0x14bf('0x39'),_0x24a735[_0x14bf('0x49')]]);if(!_0x4cad59){switch(_0x24a735['field']){case _0x14bf('0x5f'):if(_0x24a735[_0x14bf('0x60')]==0x1){_0x1f7457[_0x14bf('0x61')]('`'+_0x24a735[_0x14bf('0x49')]+'`\x20=\x200');}else{_0x1f7457['having']('`'+_0x24a735[_0x14bf('0x49')]+_0x14bf('0x62'));}break;case _0x14bf('0x63'):if(_0x24a735[_0x14bf('0x64')]===_0x14bf('0x65')){if(_0x24a735[_0x14bf('0x60')]['split']('\x20')[_0x14bf('0x3f')]>0x1){_0x269f38[_0x551ffc](_0x14bf('0x66'),qs[_0x14bf('0x67')](_0x24a735[_0x14bf('0x60')]),null);}else{var _0x58b618='%'+_0x24a735[_0x14bf('0x60')]+'%';_0x269f38[_0x551ffc]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x58b618,_0x58b618,_0x58b618);}}else{_0x4cad59=_['find'](_0x5eaad8,['name','ContactId']);_0x24a735[_0x14bf('0x49')]='ContactId';_0x26d772=as[_0x14bf('0x68')](_0x1b6ff6,_0x4cad59[_0x14bf('0x36')],_0x24a735);_0x269f38[_0x551ffc](_0x26d772['text'],_0x26d772[_0x14bf('0x60')][_0x14bf('0x69')],_0x26d772[_0x14bf('0x60')][_0x14bf('0x1e')]);}break;case _0x14bf('0x6a'):var _0x329bf0=_0x24a735[_0x14bf('0x60')][_0x14bf('0x2f')](',')['map'](function(_0x11ef14){return Number(_0x11ef14);});_0x329bf0[_0x14bf('0x30')](function(_0xff0147){_0x566a29['or'](_0x14bf('0x6b'),'%,'+_0xff0147+',%');});_0x1b08fa=_[_0x14bf('0x6c')](_0x1b08fa,_0x329bf0);break;case _0x14bf('0x6d'):if(_0x24a735[_0x14bf('0x64')]==='$substring'){_0x269f38[_0x551ffc](_0x14bf('0x6e'),'%'+_0x24a735['value']+'%',null);}else{_0x4cad59=_['find'](_0x5eaad8,['name',_0x14bf('0x6f')]);_0x24a735['field']=_0x14bf('0x6f');_0x26d772=as[_0x14bf('0x68')](_0x1b6ff6,_0x4cad59[_0x14bf('0x36')],_0x24a735);_0x269f38[_0x551ffc](_0x26d772[_0x14bf('0x70')],_0x26d772[_0x14bf('0x60')][_0x14bf('0x69')],_0x26d772[_0x14bf('0x60')][_0x14bf('0x1e')]);}break;case _0x14bf('0x71'):_0x26d772=as[_0x14bf('0x68')]('me',null,_0x24a735);_0x269f38[_0x551ffc](_0x26d772[_0x14bf('0x70')],_0x26d772[_0x14bf('0x60')][_0x14bf('0x69')],_0x26d772['value'][_0x14bf('0x1e')]);break;}}else{var _0x26d772=as[_0x14bf('0x68')](_0x1b6ff6,_0x4cad59['type'],_0x24a735);_0x269f38[_0x551ffc](_0x26d772[_0x14bf('0x70')],_0x26d772[_0x14bf('0x60')][_0x14bf('0x69')],_0x26d772['value']['end']);}}}else{var _0x8a521c=_(_0x2a9995[_0x14bf('0x3a')])[_0x14bf('0x3b')]()['map'](function(_0x2ba737){return _[_0x14bf('0x72')](_0x5eaad8,[_0x14bf('0x39'),_0x2ba737])?_0x2ba737:undefined;})['compact']()[_0x14bf('0x60')]();if(!_[_0x14bf('0x73')](_0x8a521c)){_0x8a521c[_0x14bf('0x30')](function(_0x3982f5){if(_0x3982f5===_0x14bf('0x74')){_0x1f7457[_0x14bf('0x44')]('i.WhatsappAccountId\x20IN\x20?',[]['concat'](_0x2a9995[_0x14bf('0x3a')][_0x3982f5]));}else if(_0x3982f5==='createdAt'){var _0x2473c1=JSON['parse'](_0x2a9995[_0x14bf('0x3a')][_0x3982f5])[_0x14bf('0x75')];var _0x2e5074=JSON[_0x14bf('0x76')](_0x2a9995['query'][_0x3982f5])[_0x14bf('0x77')];_0x1f7457[_0x14bf('0x44')](_0x14bf('0x78'),_0x2473c1,_0x2e5074);}else{if(_0x2a9995[_0x14bf('0x3a')][_0x3982f5]===_0x14bf('0x79')){_0x1f7457[_0x14bf('0x44')]('i.'+_0x3982f5+_0x14bf('0x7a'));}else{_0x1f7457['where']('i.'+_0x3982f5+'\x20=\x20?',_0x2a9995[_0x14bf('0x3a')][_0x3982f5]);}}});}if(_0x2a9995['query'][_0x14bf('0x7b')]){if(_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x7b')]==0x1){_0x1f7457['having']('`unreadMessages`\x20=\x200');}else{_0x1f7457[_0x14bf('0x61')]('`unreadMessages`\x20>\x200');}}if(_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x7c')]){_0x1b08fa=_[_0x14bf('0x7d')](_0x2a9995[_0x14bf('0x3a')]['tag'])?_0x2a9995[_0x14bf('0x3a')]['tag']:new Array(_0x2a9995['query'][_0x14bf('0x7c')]);_0x1b08fa['forEach'](function(_0x30027e){_0x566a29['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x30027e+',%');});}if(_0x2a9995['query']['filter']){var _0x4657e8=_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x7e')][_0x14bf('0x7f')]('\x5c','\x5c\x5c')[_0x14bf('0x7f')]('\x27\x27',_0x14bf('0x80'));if(qs[_0x14bf('0x81')](_0x4657e8)){_0x269f38['or'](_0x14bf('0x82'),_0x4657e8+'%')['or'](_0x14bf('0x83'),_0x4657e8+'%');}else{_0x269f38['or'](_0x14bf('0x84'),qs['getFullTextValue'](_0x4657e8))['or'](_0x14bf('0x85'),_0x4657e8+'%');}}}_0x1f7457[_0x14bf('0x44')](_0x269f38);_0x1f7457['group']('i.id');var _0x341901={'type':db[_0x14bf('0x86')]['QueryTypes']['SELECT'],'raw':!![]};var _0x29e5fe=_0x1f7457[_0x14bf('0x87')]();_0x29e5fe[_0x14bf('0x49')]('i.id');_0x29e5fe[_0x14bf('0x49')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x14bf('0x5f'));if(_0x55a2d0[_0x14bf('0x42')]){_0x55a2d0[_0x14bf('0x42')]['forEach'](function(_0x325e6d){_0x1f7457[_0x14bf('0x42')]('i.'+_0x325e6d[0x0],_0x325e6d[0x1]===_0x14bf('0x88')?![]:!![]);});}if(!_[_0x14bf('0x73')](_0x1b08fa)){_0x1f7457[_0x14bf('0x61')](_0x566a29);_0x29e5fe['where'](_0x14bf('0x89'),_0x1b08fa);}BPromise[_0x14bf('0x8a')]()[_0x14bf('0x27')](function(){if(!_0x39eb4a){if(_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x74')]||_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x8b')])return;_0x29e5fe[_0x14bf('0x44')](_0x14bf('0x8c'));_0x1f7457['where'](_0x14bf('0x8c'));return;}return _0x2a9995[_0x14bf('0x8d')][_0x14bf('0x8e')]({'attributes':['id'],'raw':!![]})[_0x14bf('0x27')](function(_0x461841){if(_[_0x14bf('0x73')](_0x461841)){_0x29e5fe[_0x14bf('0x44')](_0x14bf('0x8f'));_0x1f7457[_0x14bf('0x44')](_0x14bf('0x8f'));}else{_0x29e5fe['where']('i.WhatsappAccountId\x20IN\x20?',_[_0x14bf('0x2d')](_0x461841,'id'));_0x1f7457[_0x14bf('0x44')](_0x14bf('0x90'),_[_0x14bf('0x2d')](_0x461841,'id'));}});})['then'](function(){db['sequelize'][_0x14bf('0x3a')](_0x29e5fe[_0x14bf('0x91')](),_0x341901)['then'](function(_0x563ca7){_0x58e1cf[_0x14bf('0x20')]=_0x563ca7[_0x14bf('0x3f')];if(_0x58e1cf[_0x14bf('0x20')]===0x0)return[];return db[_0x14bf('0x92')][_0x14bf('0x3a')](_0x5c35fc[_0x14bf('0x91')](),_0x341901)[_0x14bf('0x27')](function(_0x1de558){_0x22d5c6=_[_0x14bf('0x93')](_0x1de558,'id');_0x341901=_[_0x14bf('0x94')](_0x341901,{'model':db[_0x14bf('0x34')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x2a9995[_0x14bf('0x3a')][_0x14bf('0x3e')]){_0x55a2d0[_0x14bf('0x3c')]['forEach'](function(_0x4a2bf4){_0x1f7457[_0x14bf('0x49')]('i.'+_0x4a2bf4);});}else{_0x1f7457[_0x14bf('0x49')](_0x14bf('0x95'),_0x14bf('0x5f'));_0x1f7457['field'](_0x14bf('0x96'),_0x14bf('0x97'));_0x1f7457[_0x14bf('0x49')](_0x14bf('0x98'),_0x14bf('0x99'));_0x1f7457[_0x14bf('0x49')](_0x14bf('0x9a'));_0x1f7457[_0x14bf('0x49')]('c.firstName','Contact.firstName');_0x1f7457[_0x14bf('0x49')](_0x14bf('0x9b'),_0x14bf('0x9c'));_0x1f7457[_0x14bf('0x49')](_0x14bf('0x9d'),_0x14bf('0x9e'));_0x1f7457[_0x14bf('0x49')](_0x14bf('0x9f'),_0x14bf('0xa0'));_0x1f7457['field']('c.mobile','Contact.mobile');_0x1f7457[_0x14bf('0x49')]('c.fax','Contact.fax');_0x1f7457[_0x14bf('0x49')](_0x14bf('0xa1'),_0x14bf('0xa2'));_0x1f7457[_0x14bf('0x49')](_0x14bf('0xa3'),'Owner.internal');_0x1f7457['field']('GROUP_CONCAT(DISTINCT\x20t.id)',_0x14bf('0x2e'));}if(_0x55a2d0[_0x14bf('0x22')])_0x1f7457[_0x14bf('0x22')](_0x55a2d0[_0x14bf('0x22')]);if(_0x55a2d0[_0x14bf('0x21')])_0x1f7457[_0x14bf('0x21')](_0x55a2d0[_0x14bf('0x21')]);return db[_0x14bf('0x92')]['query'](_0x1f7457[_0x14bf('0x91')](),_0x341901);})['then'](function(_0x54f92){_0x397365['where']('ui.WhatsappInteractionId\x20IN\x20?',_[_0x14bf('0x2d')](_0x54f92,'id'));return db[_0x14bf('0x92')][_0x14bf('0x3a')](_0x397365[_0x14bf('0x91')](),_0x341901)['then'](function(_0x71f21f){var _0x5afa63=_['groupBy'](_0x71f21f,_0x14bf('0xa4'));var _0x41d163=[];_0x54f92['forEach'](function(_0x4825ea){_0x41d163[_0x14bf('0x32')](updateWhatsappInteraction(_0x4825ea,_0x22d5c6,_0x5afa63));});return BPromise[_0x14bf('0xa5')](_0x41d163);});});})[_0x14bf('0x27')](function(_0x41e897){_0x58e1cf[_0x14bf('0xa6')]=_0x41e897;return _0x58e1cf;})[_0x14bf('0x27')](respondWithFilteredResult(_0x315c09,_0x55a2d0));})[_0x14bf('0xa7')](handleError(_0x315c09,null));};exports[_0x14bf('0xa8')]=function(_0x236218,_0x6002b8){var _0x1ee0f0={'raw':![],'where':{'id':_0x236218[_0x14bf('0xa9')]['id']}},_0x34c6a9={};_0x34c6a9[_0x14bf('0x38')]=_['keys'](db[_0x14bf('0x34')][_0x14bf('0x35')]);_0x34c6a9[_0x14bf('0x3a')]=_['keys'](_0x236218[_0x14bf('0x3a')]);_0x34c6a9[_0x14bf('0x45')]=_[_0x14bf('0x3d')](_0x34c6a9[_0x14bf('0x38')],_0x34c6a9[_0x14bf('0x3a')]);_0x1ee0f0[_0x14bf('0x3c')]=_[_0x14bf('0x3d')](_0x34c6a9[_0x14bf('0x38')],qs['fields'](_0x236218['query']['fields']));_0x1ee0f0[_0x14bf('0x3c')]=_0x1ee0f0[_0x14bf('0x3c')][_0x14bf('0x3f')]?_0x1ee0f0[_0x14bf('0x3c')]:_0x34c6a9[_0x14bf('0x38')];if(_0x236218[_0x14bf('0x3a')][_0x14bf('0xaa')]){_0x1ee0f0['include']=[{'all':!![]}];}_0x1ee0f0=_[_0x14bf('0x94')]({},_0x1ee0f0,_0x236218[_0x14bf('0xab')]);return db['WhatsappInteraction'][_0x14bf('0x5e')](_0x1ee0f0)[_0x14bf('0x27')](handleEntityNotFound(_0x6002b8,null))[_0x14bf('0x27')](respondWithResult(_0x6002b8,null))[_0x14bf('0xa7')](handleError(_0x6002b8,null));};exports[_0x14bf('0xac')]=function(_0x5b5500,_0x2baab6){return db[_0x14bf('0x34')][_0x14bf('0xac')](_0x5b5500[_0x14bf('0x71')],{})['then'](respondWithResult(_0x2baab6,0xc9))['catch'](handleError(_0x2baab6,null));};exports[_0x14bf('0x26')]=function(_0x4d71e9,_0x5bbf90){if(_0x4d71e9[_0x14bf('0x71')]['id']){delete _0x4d71e9[_0x14bf('0x71')]['id'];}return db[_0x14bf('0x34')]['find']({'where':{'id':_0x4d71e9['params']['id']}})['then'](handleEntityNotFound(_0x5bbf90,null))[_0x14bf('0x27')](saveUpdates(_0x4d71e9[_0x14bf('0x71')],null))['then'](respondWithResult(_0x5bbf90,null))[_0x14bf('0xa7')](handleError(_0x5bbf90,null));};exports[_0x14bf('0x28')]=function(_0x1a92c6,_0x3e051a){return db['WhatsappInteraction'][_0x14bf('0x5e')]({'where':{'id':_0x1a92c6[_0x14bf('0xa9')]['id']}})[_0x14bf('0x27')](handleEntityNotFound(_0x3e051a,null))[_0x14bf('0x27')](removeEntity(_0x3e051a,null))[_0x14bf('0xa7')](handleError(_0x3e051a,null));};exports['describe']=function(_0x4ad9e2,_0x1d6fc2){return db['WhatsappInteraction'][_0x14bf('0xad')]()['then'](respondWithResult(_0x1d6fc2,null))['catch'](handleError(_0x1d6fc2,null));};exports[_0x14bf('0xae')]=function(_0x3da540,_0x398a6b,_0x22cb25){return db['WhatsappMessage'][_0x14bf('0x5e')]({'where':{'id':_0x3da540['params']['id']}})[_0x14bf('0x27')](handleEntityNotFound(_0x398a6b,null))[_0x14bf('0x27')](function(_0x244ad7){if(_0x244ad7){return _0x244ad7[_0x14bf('0xae')](_0x3da540[_0x14bf('0x71')]['ids'],_[_0x14bf('0xaf')](_0x3da540[_0x14bf('0x71')],[_0x14bf('0xb0'),'id'])||{});}})['then'](respondWithResult(_0x398a6b,null))[_0x14bf('0xa7')](handleError(_0x398a6b,null));};exports['getMessages']=function(_0x4ed9b1,_0x2c0393,_0x4013bd){var _0x1b3dfb={'raw':![],'where':{}};var _0xb6f6a1={};var _0x4ccac2={'count':0x0,'rows':[]};return db[_0x14bf('0x34')][_0x14bf('0xb1')]({'where':{'id':_0x4ed9b1[_0x14bf('0xa9')]['id']}})[_0x14bf('0x27')](handleEntityNotFound(_0x2c0393,null))[_0x14bf('0x27')](function(_0x4811a3){if(_0x4811a3){_0xb6f6a1[_0x14bf('0x38')]=_[_0x14bf('0x3b')](db[_0x14bf('0xb2')]['rawAttributes']);_0xb6f6a1[_0x14bf('0x3a')]=_['keys'](_0x4ed9b1[_0x14bf('0x3a')]);_0xb6f6a1[_0x14bf('0x45')]=_[_0x14bf('0x3d')](_0xb6f6a1[_0x14bf('0x38')],_0xb6f6a1[_0x14bf('0x3a')]);_0x1b3dfb[_0x14bf('0x3c')]=_[_0x14bf('0x3d')](_0xb6f6a1['model'],qs[_0x14bf('0x3e')](_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x3e')]));_0x1b3dfb[_0x14bf('0x3c')]=_0x1b3dfb[_0x14bf('0x3c')][_0x14bf('0x3f')]?_0x1b3dfb['attributes']:_0xb6f6a1[_0x14bf('0x38')];if(!_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x40')](_0x14bf('0x41'))){_0x1b3dfb[_0x14bf('0x22')]=qs[_0x14bf('0x22')](_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x22')]);_0x1b3dfb[_0x14bf('0x21')]=qs[_0x14bf('0x21')](_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x21')]);}_0x1b3dfb[_0x14bf('0x42')]=qs['sort'](_0x4ed9b1[_0x14bf('0x3a')]['sort']);_0x1b3dfb[_0x14bf('0x44')]=qs[_0x14bf('0x45')](_[_0x14bf('0x46')](_0x4ed9b1[_0x14bf('0x3a')],_0xb6f6a1[_0x14bf('0x45')]));_0x1b3dfb[_0x14bf('0x44')][_0x14bf('0xa4')]=_0x4811a3['id'];if(_0x4ed9b1['query']['filter']){_0x1b3dfb[_0x14bf('0x44')]=_['merge'](_0x1b3dfb['where'],{'$or':_[_0x14bf('0x2d')](_0x1b3dfb[_0x14bf('0x3c')],function(_0x176c2e){var _0x5bc52b={};_0x5bc52b[_0x176c2e]={'$like':'%'+_0x4ed9b1['query']['filter']+'%'};return _0x5bc52b;})});}if(_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x75')]){var _0x2eb790=_0x4ed9b1[_0x14bf('0x3a')][_0x14bf('0x75')][_0x14bf('0x2f')](',');var _0x5198f5={};_0x5198f5[_0x2eb790[0x0]]={'$gte':moment(_0x2eb790[0x1])[_0x14bf('0xb3')](_0x14bf('0xb4'))};_0x1b3dfb['where']=_[_0x14bf('0x94')](_0x1b3dfb[_0x14bf('0x44')],_0x5198f5);}_0x1b3dfb=_[_0x14bf('0x94')]({},_0x1b3dfb,_0x4ed9b1[_0x14bf('0xab')]);return db[_0x14bf('0xb2')][_0x14bf('0x20')]({'where':_0x1b3dfb[_0x14bf('0x44')]})['then'](function(_0x24bc4d){_0x4ccac2['count']=_0x24bc4d;if(_0x4ed9b1[_0x14bf('0x3a')]['includeAll']){_0x1b3dfb[_0x14bf('0xb5')]=[{'all':!![]}];}return db['WhatsappMessage'][_0x14bf('0xb6')](_0x1b3dfb);})[_0x14bf('0x27')](function(_0x5d7188){_0x4ccac2['rows']=_0x5d7188;return _0x4ccac2;});}})[_0x14bf('0x27')](respondWithFilteredResult(_0x2c0393,_0x1b3dfb))[_0x14bf('0xa7')](handleError(_0x2c0393,null));};exports[_0x14bf('0xb7')]=function(_0x303f74,_0x3619cc,_0xe1344c){return db['WhatsappInteraction'][_0x14bf('0x5e')]({'where':{'id':_0x303f74[_0x14bf('0xa9')]['id']}})[_0x14bf('0x27')](handleEntityNotFound(_0x3619cc,null))[_0x14bf('0x27')](function(_0x36c074){if(_0x36c074){return _0x36c074[_0x14bf('0xb8')](_0x303f74[_0x14bf('0x71')]['ids'],_['omit'](_0x303f74[_0x14bf('0x71')],['ids','id'])||{})[_0x14bf('0xb9')](function(){return db['Tag'][_0x14bf('0xb6')]({'attributes':['id',_0x14bf('0x39'),_0x14bf('0xba')],'where':{'id':_0x303f74[_0x14bf('0x71')]['ids']}});})[_0x14bf('0x27')](function(_0x190ce0){socket[_0x14bf('0xbb')]('whatsappInteractionTags:save',{'id':Number(_0x303f74['params']['id']),'tags':_0x190ce0||[]});return{'id':Number(_0x303f74[_0x14bf('0xa9')]['id']),'tags':_0x190ce0||[]};});}})['then'](respondWithResult(_0x3619cc,null))[_0x14bf('0xa7')](handleError(_0x3619cc,null));};exports[_0x14bf('0xbc')]=function(_0x16554c,_0xd55688,_0x55731d){return db[_0x14bf('0x34')]['find']({'where':{'id':_0x16554c[_0x14bf('0xa9')]['id']}})[_0x14bf('0x27')](handleEntityNotFound(_0xd55688,null))[_0x14bf('0x27')](function(_0x47cc6e){if(_0x47cc6e){return _0x47cc6e['removeTags'](_0x16554c[_0x14bf('0x3a')]['ids']);}})[_0x14bf('0x27')](respondWithStatusCode(_0xd55688,null))[_0x14bf('0xa7')](handleError(_0xd55688,null));};exports[_0x14bf('0xbd')]=function(_0xbbe477,_0x20b179){var _0x1d051e=moment()[_0x14bf('0xbe')]()[_0x14bf('0x91')]();var _0xaede1e=path[_0x14bf('0xbf')](config[_0x14bf('0xc0')],_0x14bf('0xc1'),_0x14bf('0xc2'),_0x14bf('0xc3'));var _0x41b451=path[_0x14bf('0xbf')](config[_0x14bf('0xc0')],'server',_0x14bf('0xc2'),_0x14bf('0xc4'));var _0x4a4c5c=path[_0x14bf('0xbf')](_0xaede1e,_0x1d051e);var _0x23d512=util['format'](_0x14bf('0xc5'),_0xbbe477[_0x14bf('0xa9')]['id'],_0x1d051e);var _0x5a0b52=path['join'](_0xaede1e,_0x23d512);var _0xf03be6=[];_0xf03be6[_0x14bf('0x32')]({'model':db['User'],'as':'User','attributes':['id',_0x14bf('0xc6')],'raw':!![]});_0xf03be6['push']({'model':db['CmContact'],'as':_0x14bf('0x63'),'attributes':['id',_0x14bf('0xc7'),'lastName'],'raw':!![]});if(_0xbbe477[_0x14bf('0x3a')]['attachments']){_0xf03be6['push']({'model':db[_0x14bf('0xc8')],'as':'Attachment','raw':!![]});}var _0x30cd7b=[{'model':db[_0x14bf('0xb2')],'as':_0x14bf('0xc9'),'attributes':['id',_0x14bf('0x71'),_0x14bf('0xca'),'direction',_0x14bf('0xcb'),_0x14bf('0x7b')],'include':_0xf03be6}];_0x30cd7b['push']({'model':db['WhatsappAccount'],'as':'Account','attributes':['id',_0x14bf('0x39')]});_0x30cd7b['push']({'model':db['User'],'as':_0x14bf('0xcc'),'attributes':['id',_0x14bf('0xc6')]});return db[_0x14bf('0x34')][_0x14bf('0x5e')]({'where':{'id':_0xbbe477['params']['id']},'include':_0x30cd7b})['then'](handleEntityNotFound(_0x20b179,null))[_0x14bf('0x27')](function(_0x23046f){if(_0x23046f){var _0x59f9c0=_0x23046f[_0x14bf('0xcd')]({'plain':!![]});fs[_0x14bf('0xce')](_0x4a4c5c);var _0x3e3ce8={'format':'A4','border':_0x14bf('0xcf'),'header':{'height':'40px','contents':{'first':_0x14bf('0xd0')}},'footer':{'height':_0x14bf('0xd1'),'contents':{'default':util[_0x14bf('0xb3')](_0x14bf('0xd2'),util[_0x14bf('0xb3')](_0x14bf('0xd3'),_0x14bf('0xd4'),_0x59f9c0['id']),moment()['format'](_0x14bf('0xd5'))[_0x14bf('0x91')]())}}};var _0x5eaeb0={'channel':'Whatsapp','account':_0x59f9c0['Account'][_0x14bf('0x39')],'agent':_0x59f9c0['Owner']?_0x59f9c0[_0x14bf('0xcc')][_0x14bf('0xc6')]:_0x14bf('0xd6'),'createdAt':moment(_0x59f9c0[_0x14bf('0xca')])[_0x14bf('0xb3')]('YYYY-MM-DD\x20HH:mm:ss')[_0x14bf('0x91')](),'closedAt':_0x59f9c0['closed']?moment(_0x59f9c0['closedAt'])['format'](_0x14bf('0xb4'))[_0x14bf('0x91')]():'','disposition':_0x59f9c0['disposition'],'messages':_(_0x59f9c0[_0x14bf('0xc9')])[_0x14bf('0x7e')]({'secret':![]})[_0x14bf('0x2d')](function(_0x395e50){if(_0x395e50[_0x14bf('0xc8')]){var _0x5c5772=path[_0x14bf('0xbf')](_0x41b451,_0x395e50[_0x14bf('0xc8')][_0x14bf('0xd7')]);if(fs[_0x14bf('0xd8')](_0x5c5772)){fs[_0x14bf('0xd9')](_0x5c5772)[_0x14bf('0xda')](fs[_0x14bf('0xdb')](path[_0x14bf('0xbf')](_0x4a4c5c,_0x395e50[_0x14bf('0xc8')][_0x14bf('0xd7')])));}}return{'date':moment(_0x395e50[_0x14bf('0xca')])['format'](_0x14bf('0xb4'))['toString'](),'sender':_0x395e50[_0x14bf('0xdc')]===_0x14bf('0xdd')?_0x395e50['User']?_0x395e50[_0x14bf('0x6d')][_0x14bf('0xc6')]:_0x14bf('0xde'):_0x395e50[_0x14bf('0x63')]['firstName']+(_0x395e50[_0x14bf('0x63')][_0x14bf('0xdf')]?'\x20'+_0x395e50['Contact'][_0x14bf('0xdf')]:''),'body':_0x395e50['Attachment']?_0x395e50[_0x14bf('0xc8')][_0x14bf('0xd7')]:_0x395e50['body'],'direction':_0x395e50['direction']===_0x14bf('0xdd')?'A':'C','secret':_0x395e50['secret'],'read':_0x395e50[_0x14bf('0x7b')],'attachment':_0x395e50['Attachment']};})['value']()};return ejs[_0x14bf('0xe0')](path['join'](config['root'],_0x14bf('0xc1'),_0x14bf('0xe1'),_0x14bf('0xe2')),{'interaction':_0x5eaeb0})[_0x14bf('0x27')](function(_0x5ca8e1){return new BPromise(function(_0x5ea512,_0x5e5e6a){pdf['create'](_0x5ca8e1,_0x3e3ce8)[_0x14bf('0xe3')](path[_0x14bf('0xbf')](_0x4a4c5c,_0x14bf('0xe4')+_0x59f9c0['id']+'-'+_0x1d051e+_0x14bf('0xe5')),function(_0x475061,_0x1dbfb7){if(_0x475061)return _0x5e5e6a(_0x475061);_0x5ea512(_0x1dbfb7);});});})[_0x14bf('0x27')](function(){return new BPromise(function(_0x41d177,_0x110b4b){zipdir(_0x4a4c5c,{'saveTo':_0x5a0b52},function(_0x578bea,_0x4a2a1c){if(_0x578bea)return _0x110b4b(_0x578bea);return _0x41d177(_0x4a2a1c);});})[_0x14bf('0x27')](function(){return new BPromise(function(_0xe7839,_0x58e8e3){rimraf(_0x4a4c5c,function(_0x5d8992){if(_0x5d8992)_0x58e8e3(_0x5d8992);return _0xe7839();});});})[_0x14bf('0x27')](function(){return _0x20b179[_0x14bf('0xbd')](_0x5a0b52,_0x23d512,function(_0x3a2528){if(_0x3a2528){console[_0x14bf('0xe6')](_0x14bf('0xe7'),_0x3a2528);}else{fs[_0x14bf('0xe8')](_0x5a0b52);}});});});}else{return _0x20b179[_0x14bf('0x1c')](0xc8);}})[_0x14bf('0xa7')](handleError(_0x20b179,null));};
\ No newline at end of file
+var _0xcc62=['download','unix','join','root','server','files','tmp','transcript-%d-%s.zip','fullname','CmContact','firstName','attachments','Attachment','Messages','direction','secret','WhatsappAccount','Account','Owner','mkdirSync','Whatsapp','basename','createReadStream','pipe','createWriteStream','out','System','renderFile','views','downloadInteraction.html','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','eml-format','zip-dir','request-promise','moment','mustache','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','Users','map','TagIds','Tags','split','push','catch','index','WhatsappInteraction','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','select','field','tools_tags','u.fullname','ui.WhatsappInteractionId','from','user_has_whatsapp_interactions','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','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','conditions','find','unreadMessages','value','having','Contact','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','ContactId','type','text','Tag','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','operator','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','start','body','keys','compact','isEmpty','concat','createdAt','$gte','$lte','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','agent','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','sequelize','toString','keyBy','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','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','all','rows','show','params','include','create','describe','addMessage','ids','getMessages','WhatsappMessage','nolimit','WhatsappInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','options','includeAll','addTags','setTags','omit','spread','color','emit','removeTags'];(function(_0x264daf,_0x3f3151){var _0xdb6c9=function(_0xda8af1){while(--_0xda8af1){_0x264daf['push'](_0x264daf['shift']());}};_0xdb6c9(++_0x3f3151);}(_0xcc62,0x10b));var _0x2cc6=function(_0x2f35f6,_0x3dfa73){_0x2f35f6=_0x2f35f6-0x0;var _0x2f1c63=_0xcc62[_0x2f35f6];return _0x2f1c63;};'use strict';var emlformat=require(_0x2cc6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x2cc6('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x2cc6('0x2'));var moment=require(_0x2cc6('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x2cc6('0x4'));var util=require('util');var path=require(_0x2cc6('0x5'));var sox=require('sox');var csv=require(_0x2cc6('0x6'));var ejs=require(_0x2cc6('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x2cc6('0x8'));var squel=require('squel');var crypto=require(_0x2cc6('0x9'));var jsforce=require(_0x2cc6('0xa'));var deskjs=require(_0x2cc6('0xb'));var toCsv=require('to-csv');var querystring=require(_0x2cc6('0xc'));var Papa=require('papaparse');var Redis=require(_0x2cc6('0xd'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x2cc6('0xe'));var pdf=require('../../components/export/pdf');var hardwareService=require('../../config/license/hardware');var logger=require(_0x2cc6('0xf'))(_0x2cc6('0x10'));var utils=require(_0x2cc6('0x11'));var config=require(_0x2cc6('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0x2cc6('0x13'))['db'];config[_0x2cc6('0x14')]=_['defaults'](config['redis'],{'host':_0x2cc6('0x15'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x2cc6('0x14')]));require(_0x2cc6('0x16'))[_0x2cc6('0x17')](socket);function respondWithStatusCode(_0x47a472,_0x33650d){_0x33650d=_0x33650d||0xcc;return function(_0x10285b){if(_0x10285b){return _0x47a472[_0x2cc6('0x18')](_0x33650d);}return _0x47a472[_0x2cc6('0x19')](_0x33650d)[_0x2cc6('0x1a')]();};}function respondWithResult(_0x4ce6d8,_0x1b9016){_0x1b9016=_0x1b9016||0xc8;return function(_0x35f134){if(_0x35f134){return _0x4ce6d8[_0x2cc6('0x19')](_0x1b9016)[_0x2cc6('0x1b')](_0x35f134);}};}function respondWithFilteredResult(_0x42fdc7,_0x2f7161){return function(_0x544681){if(_0x544681){var _0x121956=typeof _0x2f7161[_0x2cc6('0x1c')]===_0x2cc6('0x1d')&&typeof _0x2f7161['limit']===_0x2cc6('0x1d');var _0x909549=_0x544681[_0x2cc6('0x1e')];var _0x485008=_0x121956?0x0:_0x2f7161[_0x2cc6('0x1c')];var _0x34158e=_0x121956?_0x544681[_0x2cc6('0x1e')]:_0x2f7161['offset']+_0x2f7161[_0x2cc6('0x1f')];var _0x4f803a;if(_0x34158e>=_0x909549){_0x34158e=_0x909549;_0x4f803a=0xc8;}else{_0x4f803a=0xce;}_0x42fdc7['status'](_0x4f803a);return _0x42fdc7['set'](_0x2cc6('0x20'),_0x485008+'-'+_0x34158e+'/'+_0x909549)[_0x2cc6('0x1b')](_0x544681);}return null;};}function patchUpdates(_0x31eb00){return function(_0x316649){try{jsonpatch[_0x2cc6('0x21')](_0x316649,_0x31eb00,!![]);}catch(_0x424fb8){return BPromise[_0x2cc6('0x22')](_0x424fb8);}return _0x316649[_0x2cc6('0x23')]();};}function saveUpdates(_0x4f0b4b,_0x316228){return function(_0x3165e4){if(_0x3165e4){return _0x3165e4[_0x2cc6('0x24')](_0x4f0b4b)[_0x2cc6('0x25')](function(_0x460168){return _0x460168;});}return null;};}function removeEntity(_0x80b226,_0x4bebe5){return function(_0x55f01c){if(_0x55f01c){return _0x55f01c[_0x2cc6('0x26')]()[_0x2cc6('0x25')](function(){_0x80b226[_0x2cc6('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x428f37,_0x51c3c3){return function(_0x452b87){if(!_0x452b87){_0x428f37[_0x2cc6('0x18')](0x194);}return _0x452b87;};}function handleError(_0x2ef9ef,_0x4f8fe9){_0x4f8fe9=_0x4f8fe9||0x1f4;return function(_0x42961e){logger[_0x2cc6('0x27')](_0x42961e[_0x2cc6('0x28')]);if(_0x42961e[_0x2cc6('0x29')]){delete _0x42961e[_0x2cc6('0x29')];}_0x2ef9ef[_0x2cc6('0x19')](_0x4f8fe9)[_0x2cc6('0x2a')](_0x42961e);};}function getInteractionUsers(_0x10edd9,_0x127edc){return new BPromise(function(_0x342f0f,_0x35639e){try{if(_0x127edc[_0x10edd9['id']]){_0x10edd9[_0x2cc6('0x2b')]=_[_0x2cc6('0x2c')](_0x127edc[_0x10edd9['id']],function(_0x1c3525){return{'id':_0x1c3525['id'],'fullname':_0x1c3525['fullname']};});}}catch(_0x1edd8f){_0x35639e(_0x1edd8f);}_0x342f0f(_0x10edd9);});}function getInteractionTags(_0x5a4bf5,_0xb6884){return new BPromise(function(_0x20476c,_0x77a862){try{if(_0x5a4bf5[_0x2cc6('0x2d')]){_0x5a4bf5[_0x2cc6('0x2e')]=[];_0x5a4bf5[_0x2cc6('0x2d')][_0x2cc6('0x2f')](',')['forEach'](function(_0x5e086f){_0x5a4bf5['Tags'][_0x2cc6('0x30')](_0xb6884[_0x5e086f]);});}delete _0x5a4bf5[_0x2cc6('0x2d')];}catch(_0x55fc5a){_0x77a862(_0x55fc5a);}_0x20476c(_0x5a4bf5);});}function updateWhatsappInteraction(_0x3019d8,_0xe3321,_0x49c4b2){return new BPromise(function(_0x27d24d,_0x3165dd){return getInteractionUsers(_0x3019d8,_0x49c4b2)[_0x2cc6('0x25')](function(_0x1771e6){return getInteractionTags(_0x1771e6,_0xe3321);})[_0x2cc6('0x25')](function(_0x6b8392){_0x27d24d(_0x6b8392);})[_0x2cc6('0x31')](function(_0x5970aa){_0x3165dd(_0x5970aa);});});}exports[_0x2cc6('0x32')]=function(_0x1a2cca,_0x533dd2){var _0x1bada4={},_0x26d79e={},_0x45c5c7={'count':0x0,'rows':[]};var _0x400d6d=_[_0x2cc6('0x2c')](db[_0x2cc6('0x33')][_0x2cc6('0x34')],function(_0x1bc490){return{'name':_0x1bc490[_0x2cc6('0x35')],'type':_0x1bc490['type'][_0x2cc6('0x36')]};});_0x26d79e[_0x2cc6('0x37')]=_['map'](_0x400d6d,_0x2cc6('0x29'));_0x26d79e[_0x2cc6('0x38')]=_['keys'](_0x1a2cca[_0x2cc6('0x38')]);_0x26d79e[_0x2cc6('0x39')]=_[_0x2cc6('0x3a')](_0x26d79e['model'],_0x26d79e['query']);_0x1bada4[_0x2cc6('0x3b')]=_[_0x2cc6('0x3a')](_0x26d79e[_0x2cc6('0x37')],qs[_0x2cc6('0x3c')](_0x1a2cca[_0x2cc6('0x38')]['fields']));_0x1bada4[_0x2cc6('0x3b')]=_0x1bada4[_0x2cc6('0x3b')][_0x2cc6('0x3d')]?_0x1bada4[_0x2cc6('0x3b')]:_0x26d79e[_0x2cc6('0x37')];if(!_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x3e')]('nolimit')){_0x1bada4[_0x2cc6('0x1f')]=qs[_0x2cc6('0x1f')](_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x1f')]);_0x1bada4['offset']=qs['offset'](_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x1c')]);}_0x1bada4[_0x2cc6('0x3f')]=qs[_0x2cc6('0x40')](_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x40')]);_0x1bada4[_0x2cc6('0x41')]=qs[_0x2cc6('0x39')](_[_0x2cc6('0x42')](_0x1a2cca[_0x2cc6('0x38')],_0x26d79e[_0x2cc6('0x39')]),_0x400d6d);var _0x31a8a5=[];var _0x5e436f=squel[_0x2cc6('0x43')]()[_0x2cc6('0x44')]('id')[_0x2cc6('0x44')](_0x2cc6('0x29'))['field']('color')['from'](_0x2cc6('0x45'));var _0xe54e3e=squel[_0x2cc6('0x43')]()[_0x2cc6('0x44')]('u.id')[_0x2cc6('0x44')](_0x2cc6('0x46'))[_0x2cc6('0x44')](_0x2cc6('0x47'))[_0x2cc6('0x48')](_0x2cc6('0x49'),'ui')[_0x2cc6('0x4a')](_0x2cc6('0x4b'),'u',_0x2cc6('0x4c'));var _0x30553e=squel['select']()[_0x2cc6('0x48')]('whatsapp_interactions','i')[_0x2cc6('0x4a')](_0x2cc6('0x4d'),'c',_0x2cc6('0x4e'))[_0x2cc6('0x4a')](_0x2cc6('0x4b'),'o',_0x2cc6('0x4f'))['left_join'](_0x2cc6('0x50'),'a',_0x2cc6('0x51'))[_0x2cc6('0x4a')](_0x2cc6('0x52'),'me','me.WhatsappInteractionId\x20=\x20i.id')[_0x2cc6('0x4a')]('whatsapp_interaction_has_tags','it',_0x2cc6('0x53'))[_0x2cc6('0x4a')](_0x2cc6('0x45'),'t',_0x2cc6('0x54'));var _0x99b693=squel[_0x2cc6('0x55')]();var _0xafcf86=[];var _0x1b6f9d=squel[_0x2cc6('0x55')]();var _0x48468e;if(_0x1a2cca['query'][_0x2cc6('0x56')]){_0x48468e=as['parseSearch'](_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x56')]);var _0x173404=_0x48468e['sqlOperator'];for(var _0x5caf7a=0x0;_0x5caf7a<_0x48468e[_0x2cc6('0x57')][_0x2cc6('0x3d')];_0x5caf7a++){var _0x2c5390=_0x48468e[_0x2cc6('0x57')][_0x5caf7a];var _0x501953='i';var _0xf1b8db=_[_0x2cc6('0x58')](_0x400d6d,[_0x2cc6('0x29'),_0x2c5390['field']]);if(!_0xf1b8db){switch(_0x2c5390[_0x2cc6('0x44')]){case _0x2cc6('0x59'):if(_0x2c5390[_0x2cc6('0x5a')]==0x1){_0x30553e['having']('`'+_0x2c5390[_0x2cc6('0x44')]+'`\x20=\x200');}else{_0x30553e[_0x2cc6('0x5b')]('`'+_0x2c5390['field']+'`\x20>\x200');}break;case _0x2cc6('0x5c'):if(_0x2c5390['operator']==='$substring'){if(_0x2c5390[_0x2cc6('0x5a')]['split']('\x20')[_0x2cc6('0x3d')]>0x1){_0x99b693[_0x173404](_0x2cc6('0x5d'),qs['getFullTextValue'](_0x2c5390[_0x2cc6('0x5a')]),null);}else{var _0x5b58e9='%'+_0x2c5390['value']+'%';_0x99b693[_0x173404]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x5b58e9,_0x5b58e9,_0x5b58e9);}}else{_0xf1b8db=_['find'](_0x400d6d,['name',_0x2cc6('0x5e')]);_0x2c5390[_0x2cc6('0x44')]=_0x2cc6('0x5e');_0x164979=as['buildExpression'](_0x501953,_0xf1b8db[_0x2cc6('0x5f')],_0x2c5390);_0x99b693[_0x173404](_0x164979[_0x2cc6('0x60')],_0x164979[_0x2cc6('0x5a')]['start'],_0x164979[_0x2cc6('0x5a')][_0x2cc6('0x1a')]);}break;case _0x2cc6('0x61'):var _0x4360b4=_0x2c5390['value'][_0x2cc6('0x2f')](',')[_0x2cc6('0x2c')](function(_0x429ee7){return Number(_0x429ee7);});_0x4360b4[_0x2cc6('0x62')](function(_0x1e1be3){_0x1b6f9d['or'](_0x2cc6('0x63'),'%,'+_0x1e1be3+',%');});_0xafcf86=_[_0x2cc6('0x64')](_0xafcf86,_0x4360b4);break;case _0x2cc6('0x65'):if(_0x2c5390[_0x2cc6('0x66')]===_0x2cc6('0x67')){_0x99b693[_0x173404](_0x2cc6('0x68'),'%'+_0x2c5390['value']+'%',null);}else{_0xf1b8db=_[_0x2cc6('0x58')](_0x400d6d,[_0x2cc6('0x29'),_0x2cc6('0x69')]);_0x2c5390[_0x2cc6('0x44')]='UserId';_0x164979=as[_0x2cc6('0x6a')](_0x501953,_0xf1b8db['type'],_0x2c5390);_0x99b693[_0x173404](_0x164979[_0x2cc6('0x60')],_0x164979[_0x2cc6('0x5a')][_0x2cc6('0x6b')],_0x164979[_0x2cc6('0x5a')]['end']);}break;case _0x2cc6('0x6c'):_0x164979=as[_0x2cc6('0x6a')]('me',null,_0x2c5390);_0x99b693[_0x173404](_0x164979[_0x2cc6('0x60')],_0x164979['value'][_0x2cc6('0x6b')],_0x164979[_0x2cc6('0x5a')][_0x2cc6('0x1a')]);break;}}else{var _0x164979=as[_0x2cc6('0x6a')](_0x501953,_0xf1b8db[_0x2cc6('0x5f')],_0x2c5390);_0x99b693[_0x173404](_0x164979[_0x2cc6('0x60')],_0x164979[_0x2cc6('0x5a')][_0x2cc6('0x6b')],_0x164979[_0x2cc6('0x5a')][_0x2cc6('0x1a')]);}}}else{var _0x43ac27=_(_0x1a2cca[_0x2cc6('0x38')])[_0x2cc6('0x6d')]()[_0x2cc6('0x2c')](function(_0x146e0c){return _['some'](_0x400d6d,[_0x2cc6('0x29'),_0x146e0c])?_0x146e0c:undefined;})[_0x2cc6('0x6e')]()[_0x2cc6('0x5a')]();if(!_[_0x2cc6('0x6f')](_0x43ac27)){_0x43ac27['forEach'](function(_0x3270e7){if(_0x3270e7==='WhatsappAccountId'){_0x30553e[_0x2cc6('0x41')]('i.WhatsappAccountId\x20IN\x20?',[][_0x2cc6('0x70')](_0x1a2cca[_0x2cc6('0x38')][_0x3270e7]));}else if(_0x3270e7===_0x2cc6('0x71')){var _0x3a4c86=JSON['parse'](_0x1a2cca[_0x2cc6('0x38')][_0x3270e7])[_0x2cc6('0x72')];var _0xc87048=JSON['parse'](_0x1a2cca[_0x2cc6('0x38')][_0x3270e7])[_0x2cc6('0x73')];_0x30553e[_0x2cc6('0x41')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x3a4c86,_0xc87048);}else{if(_0x1a2cca[_0x2cc6('0x38')][_0x3270e7]===_0x2cc6('0x74')){_0x30553e[_0x2cc6('0x41')]('i.'+_0x3270e7+'\x20IS\x20NULL');}else{_0x30553e[_0x2cc6('0x41')]('i.'+_0x3270e7+_0x2cc6('0x75'),_0x1a2cca[_0x2cc6('0x38')][_0x3270e7]);}}});}if(_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x76')]){if(_0x1a2cca[_0x2cc6('0x38')]['read']==0x1){_0x30553e[_0x2cc6('0x5b')](_0x2cc6('0x77'));}else{_0x30553e['having'](_0x2cc6('0x78'));}}if(_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x79')]){_0xafcf86=_[_0x2cc6('0x7a')](_0x1a2cca['query'][_0x2cc6('0x79')])?_0x1a2cca['query'][_0x2cc6('0x79')]:new Array(_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x79')]);_0xafcf86[_0x2cc6('0x62')](function(_0x317bf8){_0x1b6f9d['or'](_0x2cc6('0x63'),'%,'+_0x317bf8+',%');});}if(_0x1a2cca[_0x2cc6('0x38')]['filter']){var _0x4bb677=_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x7b')][_0x2cc6('0x7c')]('\x5c','\x5c\x5c')[_0x2cc6('0x7c')](/'/g,'\x27\x27');if(qs[_0x2cc6('0x7d')](_0x4bb677)){_0x99b693['or'](_0x2cc6('0x7e'),_0x4bb677+'%')['or'](_0x2cc6('0x7f'),_0x4bb677+'%');}else{_0x99b693['or'](_0x2cc6('0x80'),qs[_0x2cc6('0x81')](_0x4bb677))['or'](_0x2cc6('0x82'),_0x4bb677+'%');}}}_0x30553e[_0x2cc6('0x41')](_0x99b693);_0x30553e[_0x2cc6('0x83')](_0x2cc6('0x84'));var _0x5a010b={'type':db[_0x2cc6('0x85')][_0x2cc6('0x86')][_0x2cc6('0x87')],'raw':!![]};var _0x51aaa7=_0x30553e['clone']();_0x51aaa7[_0x2cc6('0x44')](_0x2cc6('0x84'));_0x51aaa7[_0x2cc6('0x44')](_0x2cc6('0x88'),_0x2cc6('0x59'));if(_0x1bada4[_0x2cc6('0x3f')]){_0x1bada4['order']['forEach'](function(_0x29544b){var _0x228d7c=_0x29544b[0x0]===_0x2cc6('0x89')?_0x29544b[0x0]:'i.'+_0x29544b[0x0];_0x30553e[_0x2cc6('0x3f')](_0x228d7c,_0x29544b[0x1]===_0x2cc6('0x8a')?![]:!![]);});}if(!_[_0x2cc6('0x6f')](_0xafcf86)){_0x30553e[_0x2cc6('0x5b')](_0x1b6f9d);_0x51aaa7['where']('t.id\x20IN\x20?',_0xafcf86);}BPromise[_0x2cc6('0x8b')]()['then'](function(){if(!_0x48468e){if(_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x8c')])return;_0x51aaa7[_0x2cc6('0x41')](_0x2cc6('0x8d'));_0x30553e['where'](_0x2cc6('0x8d'));return;}if(_0x1a2cca[_0x2cc6('0x8e')][_0x2cc6('0x8f')]!==_0x2cc6('0x90'))return;return _0x1a2cca['user']['getWhatsappAccounts']({'attributes':['id'],'raw':!![]})[_0x2cc6('0x25')](function(_0x1ba265){if(_[_0x2cc6('0x6f')](_0x1ba265)){_0x51aaa7['where'](_0x2cc6('0x91'));_0x30553e[_0x2cc6('0x41')](_0x2cc6('0x91'));}else{_0x51aaa7[_0x2cc6('0x41')](_0x2cc6('0x92'),_['map'](_0x1ba265,'id'));_0x30553e[_0x2cc6('0x41')]('i.WhatsappAccountId\x20IN\x20?',_[_0x2cc6('0x2c')](_0x1ba265,'id'));}});})['then'](function(){if(_0x1a2cca['user'][_0x2cc6('0x8f')]===_0x2cc6('0x90')&&!_0x48468e&&!_0x1a2cca['query']['WhatsappAccountId'])return[];return db[_0x2cc6('0x93')][_0x2cc6('0x38')](_0x51aaa7[_0x2cc6('0x94')](),_0x5a010b);})[_0x2cc6('0x25')](function(_0x19895b){_0x45c5c7[_0x2cc6('0x1e')]=_0x19895b[_0x2cc6('0x3d')];if(_0x45c5c7[_0x2cc6('0x1e')]===0x0)return[];return db['sequelize'][_0x2cc6('0x38')](_0x5e436f[_0x2cc6('0x94')](),_0x5a010b)[_0x2cc6('0x25')](function(_0x1536fb){_0x31a8a5=_[_0x2cc6('0x95')](_0x1536fb,'id');_0x5a010b=_[_0x2cc6('0x96')](_0x5a010b,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1a2cca[_0x2cc6('0x38')][_0x2cc6('0x3c')]){_0x1bada4[_0x2cc6('0x3b')]['forEach'](function(_0x39547d){_0x30553e[_0x2cc6('0x44')]('i.'+_0x39547d);});}else{_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x88'),_0x2cc6('0x59'));_0x30553e[_0x2cc6('0x44')]('a.key',_0x2cc6('0x97'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x98'),_0x2cc6('0x99'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x9a'),_0x2cc6('0x89'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x9b'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x9c'),_0x2cc6('0x9d'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0x9e'),_0x2cc6('0x9f'));_0x30553e['field'](_0x2cc6('0xa0'),_0x2cc6('0xa1'));_0x30553e['field'](_0x2cc6('0xa2'),'Contact.phone');_0x30553e[_0x2cc6('0x44')](_0x2cc6('0xa3'),_0x2cc6('0xa4'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0xa5'),_0x2cc6('0xa6'));_0x30553e[_0x2cc6('0x44')](_0x2cc6('0xa7'),_0x2cc6('0xa8'));_0x30553e[_0x2cc6('0x44')]('o.internal','Owner.internal');_0x30553e[_0x2cc6('0x44')](_0x2cc6('0xa9'),_0x2cc6('0x2d'));}if(_0x1bada4[_0x2cc6('0x1f')])_0x30553e[_0x2cc6('0x1f')](_0x1bada4['limit']);if(_0x1bada4[_0x2cc6('0x1c')])_0x30553e['offset'](_0x1bada4[_0x2cc6('0x1c')]);return db['sequelize'][_0x2cc6('0x38')](_0x30553e[_0x2cc6('0x94')](),_0x5a010b);})[_0x2cc6('0x25')](function(_0x4724e2){if(_0x4724e2[_0x2cc6('0x3d')]>0x0)_0xe54e3e['where']('ui.WhatsappInteractionId\x20IN\x20?',_[_0x2cc6('0x2c')](_0x4724e2,'id'));return db[_0x2cc6('0x93')]['query'](_0xe54e3e[_0x2cc6('0x94')](),_0x5a010b)[_0x2cc6('0x25')](function(_0x3baa52){var _0x1027b5=_[_0x2cc6('0xaa')](_0x3baa52,'WhatsappInteractionId');var _0x3d4c60=[];_0x4724e2['forEach'](function(_0x170b45){_0x3d4c60[_0x2cc6('0x30')](updateWhatsappInteraction(_0x170b45,_0x31a8a5,_0x1027b5));});return BPromise[_0x2cc6('0xab')](_0x3d4c60);});});})[_0x2cc6('0x25')](function(_0x26dbe1){_0x45c5c7[_0x2cc6('0xac')]=_0x26dbe1;return _0x45c5c7;})[_0x2cc6('0x25')](respondWithFilteredResult(_0x533dd2,_0x1bada4))[_0x2cc6('0x31')](handleError(_0x533dd2,null));};exports[_0x2cc6('0xad')]=function(_0x1a6baa,_0x127180){var _0x1af57e={'raw':![],'where':{'id':_0x1a6baa[_0x2cc6('0xae')]['id']}},_0x3a2dd7={};_0x3a2dd7[_0x2cc6('0x37')]=_['keys'](db['WhatsappInteraction']['rawAttributes']);_0x3a2dd7[_0x2cc6('0x38')]=_[_0x2cc6('0x6d')](_0x1a6baa[_0x2cc6('0x38')]);_0x3a2dd7['filters']=_[_0x2cc6('0x3a')](_0x3a2dd7[_0x2cc6('0x37')],_0x3a2dd7['query']);_0x1af57e[_0x2cc6('0x3b')]=_[_0x2cc6('0x3a')](_0x3a2dd7[_0x2cc6('0x37')],qs[_0x2cc6('0x3c')](_0x1a6baa['query']['fields']));_0x1af57e[_0x2cc6('0x3b')]=_0x1af57e[_0x2cc6('0x3b')][_0x2cc6('0x3d')]?_0x1af57e['attributes']:_0x3a2dd7[_0x2cc6('0x37')];if(_0x1a6baa[_0x2cc6('0x38')]['includeAll']){_0x1af57e[_0x2cc6('0xaf')]=[{'all':!![]}];}_0x1af57e=_['merge']({},_0x1af57e,_0x1a6baa['options']);return db[_0x2cc6('0x33')][_0x2cc6('0x58')](_0x1af57e)[_0x2cc6('0x25')](handleEntityNotFound(_0x127180,null))['then'](respondWithResult(_0x127180,null))['catch'](handleError(_0x127180,null));};exports[_0x2cc6('0xb0')]=function(_0x2e0a9b,_0x574508){return db[_0x2cc6('0x33')]['create'](_0x2e0a9b[_0x2cc6('0x6c')],{})['then'](respondWithResult(_0x574508,0xc9))[_0x2cc6('0x31')](handleError(_0x574508,null));};exports[_0x2cc6('0x24')]=function(_0x3f4dc5,_0x499669){if(_0x3f4dc5[_0x2cc6('0x6c')]['id']){delete _0x3f4dc5['body']['id'];}return db['WhatsappInteraction'][_0x2cc6('0x58')]({'where':{'id':_0x3f4dc5[_0x2cc6('0xae')]['id']}})[_0x2cc6('0x25')](handleEntityNotFound(_0x499669,null))['then'](saveUpdates(_0x3f4dc5[_0x2cc6('0x6c')],null))['then'](respondWithResult(_0x499669,null))['catch'](handleError(_0x499669,null));};exports['destroy']=function(_0x3d03c7,_0xa4e630){return db[_0x2cc6('0x33')][_0x2cc6('0x58')]({'where':{'id':_0x3d03c7[_0x2cc6('0xae')]['id']}})[_0x2cc6('0x25')](handleEntityNotFound(_0xa4e630,null))['then'](removeEntity(_0xa4e630,null))['catch'](handleError(_0xa4e630,null));};exports[_0x2cc6('0xb1')]=function(_0xdf45a6,_0x5ef848){return db[_0x2cc6('0x33')][_0x2cc6('0xb1')]()[_0x2cc6('0x25')](respondWithResult(_0x5ef848,null))[_0x2cc6('0x31')](handleError(_0x5ef848,null));};exports[_0x2cc6('0xb2')]=function(_0x44cee1,_0x500aae,_0x3043a4){return db['WhatsappMessage'][_0x2cc6('0x58')]({'where':{'id':_0x44cee1[_0x2cc6('0xae')]['id']}})[_0x2cc6('0x25')](handleEntityNotFound(_0x500aae,null))[_0x2cc6('0x25')](function(_0x41964c){if(_0x41964c){return _0x41964c[_0x2cc6('0xb2')](_0x44cee1[_0x2cc6('0x6c')][_0x2cc6('0xb3')],_['omit'](_0x44cee1[_0x2cc6('0x6c')],[_0x2cc6('0xb3'),'id'])||{});}})[_0x2cc6('0x25')](respondWithResult(_0x500aae,null))[_0x2cc6('0x31')](handleError(_0x500aae,null));};exports[_0x2cc6('0xb4')]=function(_0x23d34f,_0x22dddb,_0x24ce91){var _0xc95255={'raw':![],'where':{}};var _0x22a2f7={};var _0x303646={'count':0x0,'rows':[]};return db['WhatsappInteraction']['findOne']({'where':{'id':_0x23d34f[_0x2cc6('0xae')]['id']}})[_0x2cc6('0x25')](handleEntityNotFound(_0x22dddb,null))['then'](function(_0x16aa1a){if(_0x16aa1a){_0x22a2f7[_0x2cc6('0x37')]=_[_0x2cc6('0x6d')](db[_0x2cc6('0xb5')][_0x2cc6('0x34')]);_0x22a2f7[_0x2cc6('0x38')]=_[_0x2cc6('0x6d')](_0x23d34f[_0x2cc6('0x38')]);_0x22a2f7['filters']=_[_0x2cc6('0x3a')](_0x22a2f7[_0x2cc6('0x37')],_0x22a2f7['query']);_0xc95255['attributes']=_['intersection'](_0x22a2f7['model'],qs[_0x2cc6('0x3c')](_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0x3c')]));_0xc95255[_0x2cc6('0x3b')]=_0xc95255[_0x2cc6('0x3b')][_0x2cc6('0x3d')]?_0xc95255[_0x2cc6('0x3b')]:_0x22a2f7[_0x2cc6('0x37')];if(!_0x23d34f['query'][_0x2cc6('0x3e')](_0x2cc6('0xb6'))){_0xc95255[_0x2cc6('0x1f')]=qs[_0x2cc6('0x1f')](_0x23d34f['query']['limit']);_0xc95255[_0x2cc6('0x1c')]=qs[_0x2cc6('0x1c')](_0x23d34f[_0x2cc6('0x38')]['offset']);}_0xc95255[_0x2cc6('0x3f')]=qs[_0x2cc6('0x40')](_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0x40')]);_0xc95255[_0x2cc6('0x41')]=qs['filters'](_[_0x2cc6('0x42')](_0x23d34f[_0x2cc6('0x38')],_0x22a2f7[_0x2cc6('0x39')]));_0xc95255[_0x2cc6('0x41')][_0x2cc6('0xb7')]=_0x16aa1a['id'];if(_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0x7b')]){_0xc95255['where']=_['merge'](_0xc95255[_0x2cc6('0x41')],{'$or':_[_0x2cc6('0x2c')](_0xc95255[_0x2cc6('0x3b')],function(_0x4ee1a8){var _0x3fadd2={};_0x3fadd2[_0x4ee1a8]={'$like':'%'+_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0x7b')]+'%'};return _0x3fadd2;})});}if(_0x23d34f['query'][_0x2cc6('0x72')]){var _0x3a8c0d=_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0x72')][_0x2cc6('0x2f')](',');var _0x20b71a={};_0x20b71a[_0x3a8c0d[0x0]]={'$gte':moment(_0x3a8c0d[0x1])[_0x2cc6('0xb8')](_0x2cc6('0xb9'))};_0xc95255['where']=_[_0x2cc6('0x96')](_0xc95255[_0x2cc6('0x41')],_0x20b71a);}_0xc95255=_['merge']({},_0xc95255,_0x23d34f[_0x2cc6('0xba')]);return db[_0x2cc6('0xb5')][_0x2cc6('0x1e')]({'where':_0xc95255[_0x2cc6('0x41')]})[_0x2cc6('0x25')](function(_0x3ba743){_0x303646[_0x2cc6('0x1e')]=_0x3ba743;if(_0x23d34f[_0x2cc6('0x38')][_0x2cc6('0xbb')]){_0xc95255[_0x2cc6('0xaf')]=[{'all':!![]}];}return db[_0x2cc6('0xb5')]['findAll'](_0xc95255);})[_0x2cc6('0x25')](function(_0x412b14){_0x303646[_0x2cc6('0xac')]=_0x412b14;return _0x303646;});}})[_0x2cc6('0x25')](respondWithFilteredResult(_0x22dddb,_0xc95255))[_0x2cc6('0x31')](handleError(_0x22dddb,null));};exports[_0x2cc6('0xbc')]=function(_0x194175,_0x2ad2ef,_0xfca2f5){return db[_0x2cc6('0x33')][_0x2cc6('0x58')]({'where':{'id':_0x194175[_0x2cc6('0xae')]['id']}})['then'](handleEntityNotFound(_0x2ad2ef,null))[_0x2cc6('0x25')](function(_0x109537){if(_0x109537){return _0x109537[_0x2cc6('0xbd')](_0x194175[_0x2cc6('0x6c')][_0x2cc6('0xb3')],_[_0x2cc6('0xbe')](_0x194175[_0x2cc6('0x6c')],[_0x2cc6('0xb3'),'id'])||{})[_0x2cc6('0xbf')](function(){return db[_0x2cc6('0x61')]['findAll']({'attributes':['id',_0x2cc6('0x29'),_0x2cc6('0xc0')],'where':{'id':_0x194175[_0x2cc6('0x6c')]['ids']}});})['then'](function(_0x2d0cd4){socket[_0x2cc6('0xc1')]('whatsappInteractionTags:save',{'id':Number(_0x194175['params']['id']),'tags':_0x2d0cd4||[]});return{'id':Number(_0x194175['params']['id']),'tags':_0x2d0cd4||[]};});}})[_0x2cc6('0x25')](respondWithResult(_0x2ad2ef,null))[_0x2cc6('0x31')](handleError(_0x2ad2ef,null));};exports[_0x2cc6('0xc2')]=function(_0x49a214,_0x2810b1,_0x258a05){return db[_0x2cc6('0x33')][_0x2cc6('0x58')]({'where':{'id':_0x49a214[_0x2cc6('0xae')]['id']}})[_0x2cc6('0x25')](handleEntityNotFound(_0x2810b1,null))[_0x2cc6('0x25')](function(_0x3a0bca){if(_0x3a0bca){return _0x3a0bca[_0x2cc6('0xc2')](_0x49a214[_0x2cc6('0x38')]['ids']);}})['then'](respondWithStatusCode(_0x2810b1,null))['catch'](handleError(_0x2810b1,null));};exports[_0x2cc6('0xc3')]=function(_0x298a9b,_0x145d54){var _0x23c0b0=moment()[_0x2cc6('0xc4')]()[_0x2cc6('0x94')]();var _0x504a1f=path[_0x2cc6('0xc5')](config[_0x2cc6('0xc6')],_0x2cc6('0xc7'),_0x2cc6('0xc8'),_0x2cc6('0xc9'));var _0x148fd5=path[_0x2cc6('0xc5')](config[_0x2cc6('0xc6')],_0x2cc6('0xc7'),_0x2cc6('0xc8'),'attachments');var _0x572aee=path['join'](_0x504a1f,_0x23c0b0);var _0x1a68cf=util[_0x2cc6('0xb8')](_0x2cc6('0xca'),_0x298a9b[_0x2cc6('0xae')]['id'],_0x23c0b0);var _0x7f4891=path[_0x2cc6('0xc5')](_0x504a1f,_0x1a68cf);var _0x4505f3=[];_0x4505f3[_0x2cc6('0x30')]({'model':db[_0x2cc6('0x65')],'as':'User','attributes':['id',_0x2cc6('0xcb')],'raw':!![]});_0x4505f3['push']({'model':db[_0x2cc6('0xcc')],'as':_0x2cc6('0x5c'),'attributes':['id',_0x2cc6('0xcd'),'lastName'],'raw':!![]});if(_0x298a9b[_0x2cc6('0x38')][_0x2cc6('0xce')]){_0x4505f3['push']({'model':db['Attachment'],'as':_0x2cc6('0xcf'),'raw':!![]});}var _0x194a48=[{'model':db['WhatsappMessage'],'as':_0x2cc6('0xd0'),'attributes':['id','body',_0x2cc6('0x71'),_0x2cc6('0xd1'),_0x2cc6('0xd2'),_0x2cc6('0x76')],'include':_0x4505f3}];_0x194a48['push']({'model':db[_0x2cc6('0xd3')],'as':_0x2cc6('0xd4'),'attributes':['id','name']});_0x194a48[_0x2cc6('0x30')]({'model':db['User'],'as':_0x2cc6('0xd5'),'attributes':['id',_0x2cc6('0xcb')]});return db['WhatsappInteraction'][_0x2cc6('0x58')]({'where':{'id':_0x298a9b[_0x2cc6('0xae')]['id']},'include':_0x194a48})['then'](handleEntityNotFound(_0x145d54,null))['then'](function(_0x413068){if(_0x413068){var _0x545d8b=_0x413068['get']({'plain':!![]});fs[_0x2cc6('0xd6')](_0x572aee);var _0x5608b4={'channel':_0x2cc6('0xd7'),'account':_0x545d8b[_0x2cc6('0xd4')][_0x2cc6('0x29')],'agent':_0x545d8b[_0x2cc6('0xd5')]?_0x545d8b[_0x2cc6('0xd5')]['fullname']:'N.A.','createdAt':moment(_0x545d8b[_0x2cc6('0x71')])[_0x2cc6('0xb8')](_0x2cc6('0xb9'))[_0x2cc6('0x94')](),'closedAt':_0x545d8b['closed']?moment(_0x545d8b['closedAt'])[_0x2cc6('0xb8')](_0x2cc6('0xb9'))[_0x2cc6('0x94')]():'','disposition':_0x545d8b['disposition'],'messages':_(_0x545d8b[_0x2cc6('0xd0')])['filter']({'secret':![]})['map'](function(_0x2041c7){if(_0x2041c7[_0x2cc6('0xcf')]){var _0x3a6051=path[_0x2cc6('0xc5')](_0x148fd5,_0x2041c7[_0x2cc6('0xcf')][_0x2cc6('0xd8')]);if(fs['existsSync'](_0x3a6051)){fs[_0x2cc6('0xd9')](_0x3a6051)[_0x2cc6('0xda')](fs[_0x2cc6('0xdb')](path['join'](_0x572aee,_0x2041c7[_0x2cc6('0xcf')][_0x2cc6('0xd8')])));}}return{'date':moment(_0x2041c7[_0x2cc6('0x71')])['format'](_0x2cc6('0xb9'))[_0x2cc6('0x94')](),'sender':_0x2041c7[_0x2cc6('0xd1')]===_0x2cc6('0xdc')?_0x2041c7[_0x2cc6('0x65')]?_0x2041c7[_0x2cc6('0x65')][_0x2cc6('0xcb')]:_0x2cc6('0xdd'):_0x2041c7[_0x2cc6('0x5c')][_0x2cc6('0xcd')]+(_0x2041c7[_0x2cc6('0x5c')]['lastName']?'\x20'+_0x2041c7[_0x2cc6('0x5c')]['lastName']:''),'body':_0x2041c7[_0x2cc6('0xcf')]?_0x2041c7[_0x2cc6('0xcf')]['basename']:_0x2041c7['body'],'direction':_0x2041c7[_0x2cc6('0xd1')]===_0x2cc6('0xdc')?'A':'C','secret':_0x2041c7[_0x2cc6('0xd2')],'read':_0x2041c7['read'],'attachment':_0x2041c7[_0x2cc6('0xcf')]};})[_0x2cc6('0x5a')]()};return ejs[_0x2cc6('0xde')](path[_0x2cc6('0xc5')](config[_0x2cc6('0xc6')],_0x2cc6('0xc7'),_0x2cc6('0xdf'),_0x2cc6('0xe0')),{'interaction':_0x5608b4})[_0x2cc6('0x25')](function(_0x5ac671){var _0x3aa63a=path['join'](_0x572aee,_0x2cc6('0xe1')+_0x545d8b['id']+'-'+_0x23c0b0+_0x2cc6('0xe2'));var _0xc3922e={'path':_0x3aa63a,'channel':_0x2cc6('0xd7'),'interactionId':_0x545d8b['id']};return pdf[_0x2cc6('0xe3')](_0x5ac671,_0xc3922e);})[_0x2cc6('0x25')](function(){return new BPromise(function(_0x522f7b,_0x23a85b){zipdir(_0x572aee,{'saveTo':_0x7f4891},function(_0x5760ba,_0x53d25b){if(_0x5760ba)return _0x23a85b(_0x5760ba);return _0x522f7b(_0x53d25b);});})['then'](function(){return new BPromise(function(_0x7f56f3,_0x5a0c4d){rimraf(_0x572aee,function(_0x207e9f){if(_0x207e9f)_0x5a0c4d(_0x207e9f);return _0x7f56f3();});});})[_0x2cc6('0x25')](function(){return _0x145d54[_0x2cc6('0xc3')](_0x7f4891,_0x1a68cf,function(_0x36eb03){if(_0x36eb03){console[_0x2cc6('0xe4')](_0x2cc6('0xe5'),_0x36eb03);}else{fs[_0x2cc6('0xe6')](_0x7f4891);}});});});}else{return _0x145d54['sendStatus'](0xc8);}})[_0x2cc6('0x31')](handleError(_0x145d54,null));};
\ No newline at end of file