Built motion from commit (unavailable).|2.5.18
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 9e4d05d..748e861 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa44f=['sqlOperator','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','length','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','UserId','body','some','compact','isEmpty','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','\x27\x27\x27\x27','isNumeric','i.id\x20LIKE\x20?','getFullTextValue','i.id','Sequelize','QueryTypes','SELECT','clone','t.id\x20IN\x20?','resolve','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','sequelize','count','toString','keyBy','merge','WhatsappInteraction','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','c.firstName','Contact.lastName','c.email','Contact.email','Contact.phone','c.mobile','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','all','catch','show','keys','rawAttributes','includeAll','include','options','create','params','describe','addMessage','ids','getMessages','WhatsappInteractionId','format','YYYY-MM-DD\x20HH:mm:ss','WhatsappMessage','rows','addTags','setTags','omit','spread','emit','whatsappInteractionTags:save','removeTags','unix','join','root','files','tmp','server','attachments','transcript-%d-%s.zip','CmContact','firstName','Attachment','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','10px','40px','<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.','closed','closedAt','disposition','Messages','basename','createReadStream','createWriteStream','out','System','lastName','renderFile','downloadInteraction.html','toFile','transcript-','.pdf','log','err','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','../../components/auth/service','../../config/license/hardware','api','../../config/environment','redis','defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','offset','limit','Content-Range','json','apply','reject','save','update','then','destroy','end','error','name','Users','map','fullname','TagIds','Tags','split','forEach','push','fieldName','type','key','query','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','left_join','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch'];(function(_0x57c856,_0x292d19){var _0x2fb9b3=function(_0x30bcc4){while(--_0x30bcc4){_0x57c856['push'](_0x57c856['shift']());}};_0x2fb9b3(++_0x292d19);}(_0xa44f,0x95));var _0xfa44=function(_0x52cc8e,_0x2df155){_0x52cc8e=_0x52cc8e-0x0;var _0x8efe16=_0xa44f[_0x52cc8e];return _0x8efe16;};'use strict';var pdf=require(_0xfa44('0x0'));var emlformat=require(_0xfa44('0x1'));var rimraf=require(_0xfa44('0x2'));var zipdir=require(_0xfa44('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xfa44('0x4'));var moment=require(_0xfa44('0x5'));var BPromise=require(_0xfa44('0x6'));var Mustache=require(_0xfa44('0x7'));var util=require('util');var path=require(_0xfa44('0x8'));var sox=require(_0xfa44('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xfa44('0xa'));var squel=require(_0xfa44('0xb'));var crypto=require(_0xfa44('0xc'));var jsforce=require(_0xfa44('0xd'));var deskjs=require(_0xfa44('0xe'));var toCsv=require(_0xfa44('0xf'));var querystring=require('querystring');var Papa=require(_0xfa44('0x10'));var Redis=require('ioredis');var authService=require(_0xfa44('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xfa44('0x12'));var logger=require('../../config/logger')(_0xfa44('0x13'));var utils=require('../../config/utils');var config=require(_0xfa44('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xfa44('0x15')]=_[_0xfa44('0x16')](config[_0xfa44('0x15')],{'host':_0xfa44('0x17'),'port':0x18eb});var socket=require(_0xfa44('0x18'))(new Redis(config[_0xfa44('0x15')]));require(_0xfa44('0x19'))[_0xfa44('0x1a')](socket);function respondWithStatusCode(_0x142290,_0x5eee59){_0x5eee59=_0x5eee59||0xcc;return function(_0x530c7){if(_0x530c7){return _0x142290[_0xfa44('0x1b')](_0x5eee59);}return _0x142290[_0xfa44('0x1c')](_0x5eee59)['end']();};}function respondWithResult(_0x45fc26,_0x213689){_0x213689=_0x213689||0xc8;return function(_0xce162e){if(_0xce162e){return _0x45fc26[_0xfa44('0x1c')](_0x213689)['json'](_0xce162e);}};}function respondWithFilteredResult(_0x34cea6,_0x2abb92){return function(_0x5546d0){if(_0x5546d0){var _0x43cee7=_0x5546d0['count'],_0x27a13a=_0x2abb92[_0xfa44('0x1d')],_0x45a0d6=_0x2abb92['offset']+_0x2abb92[_0xfa44('0x1e')],_0x31f30f;if(_0x45a0d6>=_0x43cee7){_0x45a0d6=_0x43cee7;_0x31f30f=0xc8;}else{_0x31f30f=0xce;}_0x34cea6['status'](_0x31f30f);return _0x34cea6['set'](_0xfa44('0x1f'),_0x27a13a+'-'+_0x45a0d6+'/'+_0x43cee7)[_0xfa44('0x20')](_0x5546d0);}return null;};}function patchUpdates(_0x2e0283){return function(_0x425300){try{jsonpatch[_0xfa44('0x21')](_0x425300,_0x2e0283,!![]);}catch(_0x171d3d){return BPromise[_0xfa44('0x22')](_0x171d3d);}return _0x425300[_0xfa44('0x23')]();};}function saveUpdates(_0x75d09c,_0x5af6b8){return function(_0x849de7){if(_0x849de7){return _0x849de7[_0xfa44('0x24')](_0x75d09c)[_0xfa44('0x25')](function(_0x37be6f){return _0x37be6f;});}return null;};}function removeEntity(_0x1ab6fe,_0x949d7e){return function(_0x401ca8){if(_0x401ca8){return _0x401ca8[_0xfa44('0x26')]()[_0xfa44('0x25')](function(){_0x1ab6fe['status'](0xcc)[_0xfa44('0x27')]();});}};}function handleEntityNotFound(_0x2e4e5b,_0x1589f2){return function(_0xc9a6ea){if(!_0xc9a6ea){_0x2e4e5b['sendStatus'](0x194);}return _0xc9a6ea;};}function handleError(_0x1eeaa4,_0x50ec78){_0x50ec78=_0x50ec78||0x1f4;return function(_0x4f4f17){logger[_0xfa44('0x28')](_0x4f4f17['stack']);if(_0x4f4f17[_0xfa44('0x29')]){delete _0x4f4f17[_0xfa44('0x29')];}_0x1eeaa4[_0xfa44('0x1c')](_0x50ec78)['send'](_0x4f4f17);};}function getInteractionUsers(_0x38f87b,_0xdce038){return new BPromise(function(_0x423985,_0xa18fdc){try{if(_0xdce038[_0x38f87b['id']]){_0x38f87b[_0xfa44('0x2a')]=_[_0xfa44('0x2b')](_0xdce038[_0x38f87b['id']],function(_0xa12998){return{'id':_0xa12998['id'],'fullname':_0xa12998[_0xfa44('0x2c')]};});}}catch(_0x1b17d1){_0xa18fdc(_0x1b17d1);}_0x423985(_0x38f87b);});}function getInteractionTags(_0x323cc0,_0x5ebbc6){return new BPromise(function(_0x3d81f8,_0x475db3){try{if(_0x323cc0[_0xfa44('0x2d')]){_0x323cc0[_0xfa44('0x2e')]=[];_0x323cc0[_0xfa44('0x2d')][_0xfa44('0x2f')](',')[_0xfa44('0x30')](function(_0xff3aef){_0x323cc0[_0xfa44('0x2e')][_0xfa44('0x31')](_0x5ebbc6[_0xff3aef]);});}delete _0x323cc0[_0xfa44('0x2d')];}catch(_0x268a01){_0x475db3(_0x268a01);}_0x3d81f8(_0x323cc0);});}function updateWhatsappInteraction(_0x39aad9,_0xa28325,_0x3095d0){return new BPromise(function(_0x4e700d,_0x37a203){return getInteractionUsers(_0x39aad9,_0x3095d0)[_0xfa44('0x25')](function(_0x1e9fc6){return getInteractionTags(_0x1e9fc6,_0xa28325);})[_0xfa44('0x25')](function(_0x5af9b4){_0x4e700d(_0x5af9b4);})['catch'](function(_0x31aa0e){_0x37a203(_0x31aa0e);});});}exports['index']=function(_0x1b9166,_0x318c3a){var _0x3dc157={},_0x4c1543={},_0x2e4dba={'count':0x0,'rows':[]};var _0x5de18f=_[_0xfa44('0x2b')](db['WhatsappInteraction']['rawAttributes'],function(_0x187139){return{'name':_0x187139[_0xfa44('0x32')],'type':_0x187139[_0xfa44('0x33')][_0xfa44('0x34')]};});_0x4c1543['model']=_[_0xfa44('0x2b')](_0x5de18f,'name');_0x4c1543[_0xfa44('0x35')]=_['keys'](_0x1b9166[_0xfa44('0x35')]);_0x4c1543[_0xfa44('0x36')]=_[_0xfa44('0x37')](_0x4c1543[_0xfa44('0x38')],_0x4c1543[_0xfa44('0x35')]);_0x3dc157[_0xfa44('0x39')]=_[_0xfa44('0x37')](_0x4c1543[_0xfa44('0x38')],qs[_0xfa44('0x3a')](_0x1b9166['query'][_0xfa44('0x3a')]));_0x3dc157['attributes']=_0x3dc157[_0xfa44('0x39')]['length']?_0x3dc157[_0xfa44('0x39')]:_0x4c1543[_0xfa44('0x38')];if(!_0x1b9166['query'][_0xfa44('0x3b')](_0xfa44('0x3c'))){_0x3dc157[_0xfa44('0x1e')]=qs[_0xfa44('0x1e')](_0x1b9166[_0xfa44('0x35')][_0xfa44('0x1e')]);_0x3dc157['offset']=qs[_0xfa44('0x1d')](_0x1b9166['query'][_0xfa44('0x1d')]);}_0x3dc157[_0xfa44('0x3d')]=qs['sort'](_0x1b9166[_0xfa44('0x35')][_0xfa44('0x3e')]);_0x3dc157[_0xfa44('0x3f')]=qs[_0xfa44('0x36')](_[_0xfa44('0x40')](_0x1b9166[_0xfa44('0x35')],_0x4c1543[_0xfa44('0x36')]),_0x5de18f);var _0x27fbfb=[];var _0x2366ce=squel[_0xfa44('0x41')]()[_0xfa44('0x42')]('id')[_0xfa44('0x42')](_0xfa44('0x29'))[_0xfa44('0x42')](_0xfa44('0x43'))[_0xfa44('0x44')](_0xfa44('0x45'));var _0x524a9c=squel[_0xfa44('0x41')]()[_0xfa44('0x42')](_0xfa44('0x46'))['field'](_0xfa44('0x47'))[_0xfa44('0x42')](_0xfa44('0x48'))[_0xfa44('0x44')](_0xfa44('0x49'),'ui')[_0xfa44('0x4a')](_0xfa44('0x4b'),'u',_0xfa44('0x4c'));var _0x549249=squel[_0xfa44('0x41')]()['from'](_0xfa44('0x4d'),'i')[_0xfa44('0x4a')](_0xfa44('0x4e'),'c',_0xfa44('0x4f'))['left_join'](_0xfa44('0x4b'),'o','o.id\x20=\x20i.UserId')[_0xfa44('0x4a')](_0xfa44('0x50'),'a',_0xfa44('0x51'))[_0xfa44('0x4a')](_0xfa44('0x52'),'me',_0xfa44('0x53'))['left_join']('whatsapp_interaction_has_tags','it',_0xfa44('0x54'))['left_join'](_0xfa44('0x45'),'t',_0xfa44('0x55'));var _0x4d18b9=squel['expr']();var _0x4c3fc7=[];var _0x2d10f0=squel[_0xfa44('0x56')]();var _0x10bddf;if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x57')]){_0x10bddf=as[_0xfa44('0x58')](_0x1b9166[_0xfa44('0x35')][_0xfa44('0x57')]);var _0x320342=_0x10bddf[_0xfa44('0x59')];for(var _0x13f690=0x0;_0x13f690<_0x10bddf['conditions']['length'];_0x13f690++){var _0x5d5599=_0x10bddf['conditions'][_0x13f690];var _0x259bb3='i';var _0x2f46f3=_[_0xfa44('0x5a')](_0x5de18f,['name',_0x5d5599[_0xfa44('0x42')]]);if(!_0x2f46f3){switch(_0x5d5599[_0xfa44('0x42')]){case _0xfa44('0x5b'):if(_0x5d5599[_0xfa44('0x5c')]==0x1){_0x549249[_0xfa44('0x5d')]('`'+_0x5d5599[_0xfa44('0x42')]+_0xfa44('0x5e'));}else{_0x549249[_0xfa44('0x5d')]('`'+_0x5d5599['field']+_0xfa44('0x5f'));}break;case _0xfa44('0x60'):if(_0x5d5599[_0xfa44('0x61')]===_0xfa44('0x62')){if(_0x5d5599[_0xfa44('0x5c')][_0xfa44('0x2f')]('\x20')[_0xfa44('0x63')]>0x1){_0x4d18b9[_0x320342](_0xfa44('0x64'),qs['getFullTextValue'](_0x5d5599[_0xfa44('0x5c')]),null);}else{var _0x13579d='%'+_0x5d5599['value']+'%';_0x4d18b9[_0x320342]('c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?',_0x13579d,_0x13579d,_0x13579d);}}else{_0x2f46f3=_[_0xfa44('0x5a')](_0x5de18f,[_0xfa44('0x29'),_0xfa44('0x65')]);_0x5d5599[_0xfa44('0x42')]=_0xfa44('0x65');_0x136afe=as[_0xfa44('0x66')](_0x259bb3,_0x2f46f3[_0xfa44('0x33')],_0x5d5599);_0x4d18b9[_0x320342](_0x136afe[_0xfa44('0x67')],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x68')],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x27')]);}break;case _0xfa44('0x69'):var _0x4872bc=_0x5d5599[_0xfa44('0x5c')][_0xfa44('0x2f')](',')['map'](function(_0x22c22c){return Number(_0x22c22c);});_0x4872bc[_0xfa44('0x30')](function(_0x49cb2e){_0x2d10f0['or'](_0xfa44('0x6a'),'%,'+_0x49cb2e+',%');});_0x4c3fc7=_[_0xfa44('0x6b')](_0x4c3fc7,_0x4872bc);break;case _0xfa44('0x6c'):if(_0x5d5599[_0xfa44('0x61')]===_0xfa44('0x62')){_0x4d18b9[_0x320342]('CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','%'+_0x5d5599['value']+'%',null);}else{_0x2f46f3=_[_0xfa44('0x5a')](_0x5de18f,[_0xfa44('0x29'),_0xfa44('0x6d')]);_0x5d5599[_0xfa44('0x42')]=_0xfa44('0x6d');_0x136afe=as[_0xfa44('0x66')](_0x259bb3,_0x2f46f3[_0xfa44('0x33')],_0x5d5599);_0x4d18b9[_0x320342](_0x136afe[_0xfa44('0x67')],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x68')],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x27')]);}break;case _0xfa44('0x6e'):_0x136afe=as[_0xfa44('0x66')]('me',null,_0x5d5599);_0x4d18b9[_0x320342](_0x136afe['text'],_0x136afe['value']['start'],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x27')]);break;}}else{var _0x136afe=as[_0xfa44('0x66')](_0x259bb3,_0x2f46f3[_0xfa44('0x33')],_0x5d5599);_0x4d18b9[_0x320342](_0x136afe[_0xfa44('0x67')],_0x136afe['value'][_0xfa44('0x68')],_0x136afe[_0xfa44('0x5c')][_0xfa44('0x27')]);}}}else{var _0x1da312=_(_0x1b9166['query'])['keys']()[_0xfa44('0x2b')](function(_0x3034e5){return _[_0xfa44('0x6f')](_0x5de18f,[_0xfa44('0x29'),_0x3034e5])?_0x3034e5:undefined;})[_0xfa44('0x70')]()['value']();if(!_[_0xfa44('0x71')](_0x1da312)){_0x1da312[_0xfa44('0x30')](function(_0x4ed86f){if(_0x4ed86f===_0xfa44('0x72')){_0x549249[_0xfa44('0x3f')](_0xfa44('0x73'),[]['concat'](_0x1b9166[_0xfa44('0x35')][_0x4ed86f]));}else if(_0x4ed86f===_0xfa44('0x74')){var _0x4db524=JSON[_0xfa44('0x75')](_0x1b9166['query'][_0x4ed86f])[_0xfa44('0x76')];var _0x5b1fbc=JSON['parse'](_0x1b9166[_0xfa44('0x35')][_0x4ed86f])[_0xfa44('0x77')];_0x549249['where'](_0xfa44('0x78'),_0x4db524,_0x5b1fbc);}else{if(_0x1b9166[_0xfa44('0x35')][_0x4ed86f]===_0xfa44('0x79')){_0x549249['where']('i.'+_0x4ed86f+'\x20IS\x20NULL');}else{_0x549249['where']('i.'+_0x4ed86f+'\x20=\x20?',_0x1b9166['query'][_0x4ed86f]);}}});}if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x7a')]){if(_0x1b9166['query']['read']==0x1){_0x549249[_0xfa44('0x5d')](_0xfa44('0x7b'));}else{_0x549249[_0xfa44('0x5d')](_0xfa44('0x7c'));}}if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x7d')]){_0x4c3fc7=_[_0xfa44('0x7e')](_0x1b9166[_0xfa44('0x35')][_0xfa44('0x7d')])?_0x1b9166[_0xfa44('0x35')][_0xfa44('0x7d')]:new Array(_0x1b9166['query']['tag']);_0x4c3fc7[_0xfa44('0x30')](function(_0x240402){_0x2d10f0['or'](_0xfa44('0x6a'),'%,'+_0x240402+',%');});}if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x7f')]){var _0x396f93=_0x1b9166[_0xfa44('0x35')]['filter'][_0xfa44('0x80')]('\x5c','\x5c\x5c')[_0xfa44('0x80')]('\x27\x27',_0xfa44('0x81'));if(qs[_0xfa44('0x82')](_0x396f93)){_0x4d18b9['or'](_0xfa44('0x83'),_0x396f93+'%')['or']('i.phone\x20LIKE\x20?',_0x396f93+'%');}else{_0x4d18b9['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xfa44('0x84')](_0x396f93))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x396f93+'%');}}}_0x549249[_0xfa44('0x3f')](_0x4d18b9);_0x549249['group'](_0xfa44('0x85'));var _0x2fa7b6={'type':db[_0xfa44('0x86')][_0xfa44('0x87')][_0xfa44('0x88')],'raw':!![]};var _0x29e67d=_0x549249[_0xfa44('0x89')]();_0x29e67d[_0xfa44('0x42')](_0xfa44('0x85'));_0x29e67d[_0xfa44('0x42')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xfa44('0x5b'));if(_0x3dc157['order']){_0x3dc157[_0xfa44('0x3d')][_0xfa44('0x30')](function(_0x12076a){_0x549249['order']('i.'+_0x12076a[0x0],_0x12076a[0x1]==='DESC'?![]:!![]);});}if(!_[_0xfa44('0x71')](_0x4c3fc7)){_0x549249[_0xfa44('0x5d')](_0x2d10f0);_0x29e67d[_0xfa44('0x3f')](_0xfa44('0x8a'),_0x4c3fc7);}BPromise[_0xfa44('0x8b')]()['then'](function(){if(!_0x10bddf){if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x72')]||_0x1b9166[_0xfa44('0x35')]['journey'])return;_0x29e67d[_0xfa44('0x3f')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');_0x549249['where'](_0xfa44('0x8c'));return;}return _0x1b9166[_0xfa44('0x8d')][_0xfa44('0x8e')]({'attributes':['id'],'raw':!![]})[_0xfa44('0x25')](function(_0xc785b5){if(_[_0xfa44('0x71')](_0xc785b5)){_0x29e67d[_0xfa44('0x3f')](_0xfa44('0x8f'));_0x549249['where'](_0xfa44('0x8f'));}else{_0x29e67d[_0xfa44('0x3f')](_0xfa44('0x73'),_[_0xfa44('0x2b')](_0xc785b5,'id'));_0x549249[_0xfa44('0x3f')](_0xfa44('0x73'),_[_0xfa44('0x2b')](_0xc785b5,'id'));}});})[_0xfa44('0x25')](function(){db[_0xfa44('0x90')][_0xfa44('0x35')](_0x29e67d['toString'](),_0x2fa7b6)[_0xfa44('0x25')](function(_0x545c56){_0x2e4dba['count']=_0x545c56[_0xfa44('0x63')];if(_0x2e4dba[_0xfa44('0x91')]===0x0)return[];return db[_0xfa44('0x90')]['query'](_0x2366ce[_0xfa44('0x92')](),_0x2fa7b6)[_0xfa44('0x25')](function(_0x42ebf5){_0x27fbfb=_[_0xfa44('0x93')](_0x42ebf5,'id');_0x2fa7b6=_[_0xfa44('0x94')](_0x2fa7b6,{'model':db[_0xfa44('0x95')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1b9166[_0xfa44('0x35')][_0xfa44('0x3a')]){_0x3dc157[_0xfa44('0x39')][_0xfa44('0x30')](function(_0x3095c3){_0x549249[_0xfa44('0x42')]('i.'+_0x3095c3);});}else{_0x549249[_0xfa44('0x42')](_0xfa44('0x96'),_0xfa44('0x5b'));_0x549249[_0xfa44('0x42')](_0xfa44('0x97'),_0xfa44('0x98'));_0x549249['field'](_0xfa44('0x99'),_0xfa44('0x9a'));_0x549249[_0xfa44('0x42')](_0xfa44('0x9b'));_0x549249[_0xfa44('0x42')](_0xfa44('0x9c'),'Contact.firstName');_0x549249[_0xfa44('0x42')]('c.lastName',_0xfa44('0x9d'));_0x549249[_0xfa44('0x42')](_0xfa44('0x9e'),_0xfa44('0x9f'));_0x549249[_0xfa44('0x42')]('c.phone',_0xfa44('0xa0'));_0x549249[_0xfa44('0x42')](_0xfa44('0xa1'),'Contact.mobile');_0x549249['field']('c.fax',_0xfa44('0xa2'));_0x549249['field']('o.fullname',_0xfa44('0xa3'));_0x549249[_0xfa44('0x42')](_0xfa44('0xa4'),_0xfa44('0xa5'));_0x549249[_0xfa44('0x42')](_0xfa44('0xa6'),_0xfa44('0x2d'));}if(_0x3dc157['limit'])_0x549249[_0xfa44('0x1e')](_0x3dc157[_0xfa44('0x1e')]);if(_0x3dc157[_0xfa44('0x1d')])_0x549249[_0xfa44('0x1d')](_0x3dc157['offset']);return db['sequelize'][_0xfa44('0x35')](_0x549249['toString'](),_0x2fa7b6);})[_0xfa44('0x25')](function(_0x22a1a9){_0x524a9c['where']('ui.WhatsappInteractionId\x20IN\x20?',_[_0xfa44('0x2b')](_0x22a1a9,'id'));return db[_0xfa44('0x90')][_0xfa44('0x35')](_0x524a9c[_0xfa44('0x92')](),_0x2fa7b6)['then'](function(_0x5c6221){var _0xf8195a=_[_0xfa44('0xa7')](_0x5c6221,'WhatsappInteractionId');var _0x3f3173=[];_0x22a1a9[_0xfa44('0x30')](function(_0x6e90ea){_0x3f3173[_0xfa44('0x31')](updateWhatsappInteraction(_0x6e90ea,_0x27fbfb,_0xf8195a));});return BPromise[_0xfa44('0xa8')](_0x3f3173);});});})[_0xfa44('0x25')](function(_0x14cf3e){_0x2e4dba['rows']=_0x14cf3e;return _0x2e4dba;})['then'](respondWithFilteredResult(_0x318c3a,_0x3dc157));})[_0xfa44('0xa9')](handleError(_0x318c3a,null));};exports[_0xfa44('0xaa')]=function(_0x15bfa3,_0x491bf8){var _0x581433={'raw':![],'where':{'id':_0x15bfa3['params']['id']}},_0x48d9e0={};_0x48d9e0[_0xfa44('0x38')]=_[_0xfa44('0xab')](db[_0xfa44('0x95')][_0xfa44('0xac')]);_0x48d9e0[_0xfa44('0x35')]=_[_0xfa44('0xab')](_0x15bfa3[_0xfa44('0x35')]);_0x48d9e0[_0xfa44('0x36')]=_[_0xfa44('0x37')](_0x48d9e0[_0xfa44('0x38')],_0x48d9e0[_0xfa44('0x35')]);_0x581433[_0xfa44('0x39')]=_[_0xfa44('0x37')](_0x48d9e0[_0xfa44('0x38')],qs[_0xfa44('0x3a')](_0x15bfa3[_0xfa44('0x35')][_0xfa44('0x3a')]));_0x581433[_0xfa44('0x39')]=_0x581433[_0xfa44('0x39')]['length']?_0x581433[_0xfa44('0x39')]:_0x48d9e0[_0xfa44('0x38')];if(_0x15bfa3[_0xfa44('0x35')][_0xfa44('0xad')]){_0x581433[_0xfa44('0xae')]=[{'all':!![]}];}_0x581433=_[_0xfa44('0x94')]({},_0x581433,_0x15bfa3[_0xfa44('0xaf')]);return db[_0xfa44('0x95')]['find'](_0x581433)[_0xfa44('0x25')](handleEntityNotFound(_0x491bf8,null))[_0xfa44('0x25')](respondWithResult(_0x491bf8,null))[_0xfa44('0xa9')](handleError(_0x491bf8,null));};exports[_0xfa44('0xb0')]=function(_0x13059c,_0xa24c7){return db[_0xfa44('0x95')][_0xfa44('0xb0')](_0x13059c[_0xfa44('0x6e')],{})[_0xfa44('0x25')](respondWithResult(_0xa24c7,0xc9))[_0xfa44('0xa9')](handleError(_0xa24c7,null));};exports[_0xfa44('0x24')]=function(_0x46544c,_0x385892){if(_0x46544c[_0xfa44('0x6e')]['id']){delete _0x46544c[_0xfa44('0x6e')]['id'];}return db[_0xfa44('0x95')][_0xfa44('0x5a')]({'where':{'id':_0x46544c[_0xfa44('0xb1')]['id']}})[_0xfa44('0x25')](handleEntityNotFound(_0x385892,null))[_0xfa44('0x25')](saveUpdates(_0x46544c[_0xfa44('0x6e')],null))['then'](respondWithResult(_0x385892,null))[_0xfa44('0xa9')](handleError(_0x385892,null));};exports['destroy']=function(_0x291d86,_0x4d1ce1){return db['WhatsappInteraction'][_0xfa44('0x5a')]({'where':{'id':_0x291d86[_0xfa44('0xb1')]['id']}})[_0xfa44('0x25')](handleEntityNotFound(_0x4d1ce1,null))[_0xfa44('0x25')](removeEntity(_0x4d1ce1,null))[_0xfa44('0xa9')](handleError(_0x4d1ce1,null));};exports['describe']=function(_0x34680c,_0x3c3381){return db[_0xfa44('0x95')][_0xfa44('0xb2')]()[_0xfa44('0x25')](respondWithResult(_0x3c3381,null))[_0xfa44('0xa9')](handleError(_0x3c3381,null));};exports[_0xfa44('0xb3')]=function(_0x16873d,_0x5ea1af,_0x10e25f){return db['WhatsappMessage'][_0xfa44('0x5a')]({'where':{'id':_0x16873d['params']['id']}})[_0xfa44('0x25')](handleEntityNotFound(_0x5ea1af,null))['then'](function(_0x2c403a){if(_0x2c403a){return _0x2c403a[_0xfa44('0xb3')](_0x16873d[_0xfa44('0x6e')][_0xfa44('0xb4')],_['omit'](_0x16873d[_0xfa44('0x6e')],['ids','id'])||{});}})[_0xfa44('0x25')](respondWithResult(_0x5ea1af,null))['catch'](handleError(_0x5ea1af,null));};exports[_0xfa44('0xb5')]=function(_0x462f88,_0x172f8f,_0x501af3){var _0x1038d2={'raw':![],'where':{}};var _0x1953e6={};var _0x54fdcf={'count':0x0,'rows':[]};return db[_0xfa44('0x95')]['findOne']({'where':{'id':_0x462f88['params']['id']}})['then'](handleEntityNotFound(_0x172f8f,null))[_0xfa44('0x25')](function(_0x448d87){if(_0x448d87){_0x1953e6[_0xfa44('0x38')]=_[_0xfa44('0xab')](db['WhatsappMessage'][_0xfa44('0xac')]);_0x1953e6['query']=_[_0xfa44('0xab')](_0x462f88['query']);_0x1953e6[_0xfa44('0x36')]=_['intersection'](_0x1953e6[_0xfa44('0x38')],_0x1953e6[_0xfa44('0x35')]);_0x1038d2[_0xfa44('0x39')]=_['intersection'](_0x1953e6[_0xfa44('0x38')],qs[_0xfa44('0x3a')](_0x462f88[_0xfa44('0x35')][_0xfa44('0x3a')]));_0x1038d2[_0xfa44('0x39')]=_0x1038d2[_0xfa44('0x39')][_0xfa44('0x63')]?_0x1038d2[_0xfa44('0x39')]:_0x1953e6[_0xfa44('0x38')];if(!_0x462f88[_0xfa44('0x35')][_0xfa44('0x3b')](_0xfa44('0x3c'))){_0x1038d2[_0xfa44('0x1e')]=qs[_0xfa44('0x1e')](_0x462f88[_0xfa44('0x35')][_0xfa44('0x1e')]);_0x1038d2[_0xfa44('0x1d')]=qs[_0xfa44('0x1d')](_0x462f88[_0xfa44('0x35')][_0xfa44('0x1d')]);}_0x1038d2[_0xfa44('0x3d')]=qs[_0xfa44('0x3e')](_0x462f88['query'][_0xfa44('0x3e')]);_0x1038d2[_0xfa44('0x3f')]=qs['filters'](_['pick'](_0x462f88['query'],_0x1953e6[_0xfa44('0x36')]));_0x1038d2[_0xfa44('0x3f')][_0xfa44('0xb6')]=_0x448d87['id'];if(_0x462f88[_0xfa44('0x35')][_0xfa44('0x7f')]){_0x1038d2[_0xfa44('0x3f')]=_['merge'](_0x1038d2[_0xfa44('0x3f')],{'$or':_[_0xfa44('0x2b')](_0x1038d2[_0xfa44('0x39')],function(_0x4fee83){var _0x5b19d8={};_0x5b19d8[_0x4fee83]={'$like':'%'+_0x462f88[_0xfa44('0x35')][_0xfa44('0x7f')]+'%'};return _0x5b19d8;})});}if(_0x462f88[_0xfa44('0x35')]['$gte']){var _0x2300e7=_0x462f88['query']['$gte'][_0xfa44('0x2f')](',');var _0x29291a={};_0x29291a[_0x2300e7[0x0]]={'$gte':moment(_0x2300e7[0x1])[_0xfa44('0xb7')](_0xfa44('0xb8'))};_0x1038d2['where']=_[_0xfa44('0x94')](_0x1038d2['where'],_0x29291a);}_0x1038d2=_[_0xfa44('0x94')]({},_0x1038d2,_0x462f88['options']);return db[_0xfa44('0xb9')][_0xfa44('0x91')]({'where':_0x1038d2[_0xfa44('0x3f')]})[_0xfa44('0x25')](function(_0x395c5a){_0x54fdcf[_0xfa44('0x91')]=_0x395c5a;if(_0x462f88[_0xfa44('0x35')][_0xfa44('0xad')]){_0x1038d2[_0xfa44('0xae')]=[{'all':!![]}];}return db[_0xfa44('0xb9')]['findAll'](_0x1038d2);})[_0xfa44('0x25')](function(_0x16ab0f){_0x54fdcf[_0xfa44('0xba')]=_0x16ab0f;return _0x54fdcf;});}})[_0xfa44('0x25')](respondWithFilteredResult(_0x172f8f,_0x1038d2))[_0xfa44('0xa9')](handleError(_0x172f8f,null));};exports[_0xfa44('0xbb')]=function(_0x1f174c,_0x256c75,_0x5499af){return db[_0xfa44('0x95')][_0xfa44('0x5a')]({'where':{'id':_0x1f174c['params']['id']}})[_0xfa44('0x25')](handleEntityNotFound(_0x256c75,null))[_0xfa44('0x25')](function(_0x1cc6fc){if(_0x1cc6fc){return _0x1cc6fc[_0xfa44('0xbc')](_0x1f174c['body'][_0xfa44('0xb4')],_[_0xfa44('0xbd')](_0x1f174c[_0xfa44('0x6e')],[_0xfa44('0xb4'),'id'])||{})[_0xfa44('0xbe')](function(){return db[_0xfa44('0x69')]['findAll']({'attributes':['id',_0xfa44('0x29'),_0xfa44('0x43')],'where':{'id':_0x1f174c['body'][_0xfa44('0xb4')]}});})[_0xfa44('0x25')](function(_0x4c2b1f){socket[_0xfa44('0xbf')](_0xfa44('0xc0'),{'id':Number(_0x1f174c['params']['id']),'tags':_0x4c2b1f||[]});return{'id':Number(_0x1f174c[_0xfa44('0xb1')]['id']),'tags':_0x4c2b1f||[]};});}})['then'](respondWithResult(_0x256c75,null))[_0xfa44('0xa9')](handleError(_0x256c75,null));};exports[_0xfa44('0xc1')]=function(_0x21845b,_0x5e9252,_0x79b76e){return db['WhatsappInteraction'][_0xfa44('0x5a')]({'where':{'id':_0x21845b['params']['id']}})['then'](handleEntityNotFound(_0x5e9252,null))[_0xfa44('0x25')](function(_0x2e1d67){if(_0x2e1d67){return _0x2e1d67[_0xfa44('0xc1')](_0x21845b[_0xfa44('0x35')][_0xfa44('0xb4')]);}})[_0xfa44('0x25')](respondWithStatusCode(_0x5e9252,null))[_0xfa44('0xa9')](handleError(_0x5e9252,null));};exports['download']=function(_0x8dc186,_0x3ea7de){var _0x21d4ed=moment()[_0xfa44('0xc2')]()[_0xfa44('0x92')]();var _0x1ede51=path[_0xfa44('0xc3')](config[_0xfa44('0xc4')],'server',_0xfa44('0xc5'),_0xfa44('0xc6'));var _0x26b828=path['join'](config[_0xfa44('0xc4')],_0xfa44('0xc7'),_0xfa44('0xc5'),_0xfa44('0xc8'));var _0xe29584=path[_0xfa44('0xc3')](_0x1ede51,_0x21d4ed);var _0x9d5973=util[_0xfa44('0xb7')](_0xfa44('0xc9'),_0x8dc186[_0xfa44('0xb1')]['id'],_0x21d4ed);var _0x555f7c=path[_0xfa44('0xc3')](_0x1ede51,_0x9d5973);var _0x27f885=[];_0x27f885[_0xfa44('0x31')]({'model':db[_0xfa44('0x6c')],'as':_0xfa44('0x6c'),'attributes':['id','fullname'],'raw':!![]});_0x27f885[_0xfa44('0x31')]({'model':db[_0xfa44('0xca')],'as':_0xfa44('0x60'),'attributes':['id',_0xfa44('0xcb'),'lastName'],'raw':!![]});if(_0x8dc186[_0xfa44('0x35')][_0xfa44('0xc8')]){_0x27f885[_0xfa44('0x31')]({'model':db[_0xfa44('0xcc')],'as':_0xfa44('0xcc'),'raw':!![]});}var _0x44f7b0=[{'model':db[_0xfa44('0xb9')],'as':'Messages','attributes':['id',_0xfa44('0x6e'),_0xfa44('0x74'),_0xfa44('0xcd'),_0xfa44('0xce'),_0xfa44('0x7a')],'include':_0x27f885}];_0x44f7b0[_0xfa44('0x31')]({'model':db[_0xfa44('0xcf')],'as':_0xfa44('0xd0'),'attributes':['id','name']});_0x44f7b0[_0xfa44('0x31')]({'model':db[_0xfa44('0x6c')],'as':_0xfa44('0xd1'),'attributes':['id','fullname']});return db[_0xfa44('0x95')][_0xfa44('0x5a')]({'where':{'id':_0x8dc186[_0xfa44('0xb1')]['id']},'include':_0x44f7b0})['then'](handleEntityNotFound(_0x3ea7de,null))[_0xfa44('0x25')](function(_0x3469a2){if(_0x3469a2){var _0x58600c=_0x3469a2[_0xfa44('0xd2')]({'plain':!![]});fs[_0xfa44('0xd3')](_0xe29584);var _0x4fca5e={'format':'A4','border':_0xfa44('0xd4'),'header':{'height':_0xfa44('0xd5'),'contents':{'first':_0xfa44('0xd6')}},'footer':{'height':_0xfa44('0xd7'),'contents':{'default':util[_0xfa44('0xb7')](_0xfa44('0xd8'),util[_0xfa44('0xb7')](_0xfa44('0xd9'),_0xfa44('0xda'),_0x58600c['id']),moment()['format'](_0xfa44('0xdb'))['toString']())}}};var _0x4b3377={'channel':'Whatsapp','account':_0x58600c[_0xfa44('0xd0')][_0xfa44('0x29')],'agent':_0x58600c[_0xfa44('0xd1')]?_0x58600c['Owner'][_0xfa44('0x2c')]:_0xfa44('0xdc'),'createdAt':moment(_0x58600c[_0xfa44('0x74')])[_0xfa44('0xb7')](_0xfa44('0xb8'))[_0xfa44('0x92')](),'closedAt':_0x58600c[_0xfa44('0xdd')]?moment(_0x58600c[_0xfa44('0xde')])[_0xfa44('0xb7')](_0xfa44('0xb8'))['toString']():'','disposition':_0x58600c[_0xfa44('0xdf')],'messages':_(_0x58600c[_0xfa44('0xe0')])[_0xfa44('0x7f')]({'secret':![]})['map'](function(_0x887b6b){if(_0x887b6b[_0xfa44('0xcc')]){var _0x133d89=path[_0xfa44('0xc3')](_0x26b828,_0x887b6b[_0xfa44('0xcc')][_0xfa44('0xe1')]);if(fs['existsSync'](_0x133d89)){fs[_0xfa44('0xe2')](_0x133d89)['pipe'](fs[_0xfa44('0xe3')](path[_0xfa44('0xc3')](_0xe29584,_0x887b6b['Attachment'][_0xfa44('0xe1')])));}}return{'date':moment(_0x887b6b[_0xfa44('0x74')])[_0xfa44('0xb7')](_0xfa44('0xb8'))[_0xfa44('0x92')](),'sender':_0x887b6b[_0xfa44('0xcd')]===_0xfa44('0xe4')?_0x887b6b['User']?_0x887b6b[_0xfa44('0x6c')][_0xfa44('0x2c')]:_0xfa44('0xe5'):_0x887b6b[_0xfa44('0x60')]['firstName']+(_0x887b6b[_0xfa44('0x60')][_0xfa44('0xe6')]?'\x20'+_0x887b6b[_0xfa44('0x60')][_0xfa44('0xe6')]:''),'body':_0x887b6b[_0xfa44('0xcc')]?_0x887b6b[_0xfa44('0xcc')][_0xfa44('0xe1')]:_0x887b6b[_0xfa44('0x6e')],'direction':_0x887b6b[_0xfa44('0xcd')]===_0xfa44('0xe4')?'A':'C','secret':_0x887b6b[_0xfa44('0xce')],'read':_0x887b6b['read'],'attachment':_0x887b6b[_0xfa44('0xcc')]};})['value']()};return ejs[_0xfa44('0xe7')](path[_0xfa44('0xc3')](config[_0xfa44('0xc4')],'server','views',_0xfa44('0xe8')),{'interaction':_0x4b3377})[_0xfa44('0x25')](function(_0x211d57){return new BPromise(function(_0x28e429,_0x4835da){pdf[_0xfa44('0xb0')](_0x211d57,_0x4fca5e)[_0xfa44('0xe9')](path['join'](_0xe29584,_0xfa44('0xea')+_0x58600c['id']+'-'+_0x21d4ed+_0xfa44('0xeb')),function(_0x2a0bcd,_0x158382){if(_0x2a0bcd)return _0x4835da(_0x2a0bcd);_0x28e429(_0x158382);});});})[_0xfa44('0x25')](function(){return new BPromise(function(_0x25caa0,_0x134d00){zipdir(_0xe29584,{'saveTo':_0x555f7c},function(_0x3b3232,_0x3ae938){if(_0x3b3232)return _0x134d00(_0x3b3232);return _0x25caa0(_0x3ae938);});})[_0xfa44('0x25')](function(){return new BPromise(function(_0x3ce0e0,_0x20ccf6){rimraf(_0xe29584,function(_0x3519c6){if(_0x3519c6)_0x20ccf6(_0x3519c6);return _0x3ce0e0();});});})[_0xfa44('0x25')](function(){return _0x3ea7de['download'](_0x555f7c,_0x9d5973,function(_0x216835){if(_0x216835){console[_0xfa44('0xec')](_0xfa44('0xed'),_0x216835);}else{fs['unlinkSync'](_0x555f7c);}});});});}else{return _0x3ea7de[_0xfa44('0x1b')](0xc8);}})[_0xfa44('0xa9')](handleError(_0x3ea7de,null));};
\ No newline at end of file
+var _0x955f=['pipe','createWriteStream','basename','out','System','secret','renderFile','views','downloadInteraction.html','transcript-','log','err','unlinkSync','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','util','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./whatsappInteraction.socket','register','sendStatus','status','json','count','offset','limit','Content-Range','apply','reject','save','then','destroy','end','error','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','push','index','WhatsappInteraction','rawAttributes','type','model','query','filters','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','select','field','from','u.id','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','u.id\x20=\x20ui.UserId','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','tools_tags','t.id\x20=\x20it.TagId','expr','search','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','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?','find','ContactId','buildExpression','start','Tag','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','text','body','keys','some','isEmpty','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','$lte','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','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?','group','i.id','Sequelize','QueryTypes','SELECT','clone','contactName','DESC','t.id\x20IN\x20?','resolve','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','role','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','agent','sequelize','toString','keyBy','a.key','Account.key','Account.mandatoryDisposition','c.firstName','Contact.firstName','c.email','Contact.email','c.mobile','c.fax','Contact.fax','o.fullname','o.internal','Owner.internal','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','catch','intersection','includeAll','include','merge','options','create','update','params','describe','addMessage','omit','ids','getMessages','findOne','WhatsappMessage','$gte','format','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','color','whatsappInteractionTags:save','removeTags','unix','join','root','server','tmp','files','transcript-%d-%s.zip','CmContact','firstName','Messages','direction','WhatsappAccount','Account','Owner','get','mkdirSync','40px','<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','YYYY-MM-DD','Whatsapp','closed','closedAt','disposition','Attachment','existsSync','createReadStream'];(function(_0x5ec1fc,_0x1d90e3){var _0x454c2c=function(_0x58e91b){while(--_0x58e91b){_0x5ec1fc['push'](_0x5ec1fc['shift']());}};_0x454c2c(++_0x1d90e3);}(_0x955f,0x1eb));var _0xf955=function(_0x52aa33,_0x43d674){_0x52aa33=_0x52aa33-0x0;var _0x2d78f7=_0x955f[_0x52aa33];return _0x2d78f7;};'use strict';var pdf=require(_0xf955('0x0'));var emlformat=require(_0xf955('0x1'));var rimraf=require(_0xf955('0x2'));var zipdir=require(_0xf955('0x3'));var jsonpatch=require(_0xf955('0x4'));var rp=require('request-promise');var moment=require(_0xf955('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf955('0x6'));var path=require('path');var sox=require(_0xf955('0x7'));var csv=require(_0xf955('0x8'));var ejs=require(_0xf955('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf955('0xa'));var crypto=require(_0xf955('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf955('0xc'));var toCsv=require(_0xf955('0x8'));var querystring=require(_0xf955('0xd'));var Papa=require(_0xf955('0xe'));var Redis=require(_0xf955('0xf'));var authService=require(_0xf955('0x10'));var qs=require(_0xf955('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf955('0x12'));var logger=require('../../config/logger')(_0xf955('0x13'));var utils=require(_0xf955('0x14'));var config=require(_0xf955('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xf955('0x16'))['db'];config['redis']=_[_0xf955('0x17')](config['redis'],{'host':_0xf955('0x18'),'port':0x18eb});var socket=require(_0xf955('0x19'))(new Redis(config[_0xf955('0x1a')]));require(_0xf955('0x1b'))[_0xf955('0x1c')](socket);function respondWithStatusCode(_0x341b8c,_0x1c3235){_0x1c3235=_0x1c3235||0xcc;return function(_0x2783f2){if(_0x2783f2){return _0x341b8c[_0xf955('0x1d')](_0x1c3235);}return _0x341b8c[_0xf955('0x1e')](_0x1c3235)['end']();};}function respondWithResult(_0xc29b35,_0x54e60b){_0x54e60b=_0x54e60b||0xc8;return function(_0x3139d5){if(_0x3139d5){return _0xc29b35[_0xf955('0x1e')](_0x54e60b)[_0xf955('0x1f')](_0x3139d5);}};}function respondWithFilteredResult(_0x15c07c,_0x50930d){return function(_0x5ac6cb){if(_0x5ac6cb){var _0x1e20d1=_0x5ac6cb[_0xf955('0x20')],_0xe6de5c=_0x50930d[_0xf955('0x21')],_0x3c49c0=_0x50930d[_0xf955('0x21')]+_0x50930d[_0xf955('0x22')],_0x4d7b5b;if(_0x3c49c0>=_0x1e20d1){_0x3c49c0=_0x1e20d1;_0x4d7b5b=0xc8;}else{_0x4d7b5b=0xce;}_0x15c07c[_0xf955('0x1e')](_0x4d7b5b);return _0x15c07c['set'](_0xf955('0x23'),_0xe6de5c+'-'+_0x3c49c0+'/'+_0x1e20d1)[_0xf955('0x1f')](_0x5ac6cb);}return null;};}function patchUpdates(_0xfb8102){return function(_0x488d04){try{jsonpatch[_0xf955('0x24')](_0x488d04,_0xfb8102,!![]);}catch(_0x5daa73){return BPromise[_0xf955('0x25')](_0x5daa73);}return _0x488d04[_0xf955('0x26')]();};}function saveUpdates(_0x37143d,_0xa4ebb4){return function(_0x160071){if(_0x160071){return _0x160071['update'](_0x37143d)[_0xf955('0x27')](function(_0x5fab1c){return _0x5fab1c;});}return null;};}function removeEntity(_0x3585c7,_0x13a1a7){return function(_0x17dec2){if(_0x17dec2){return _0x17dec2[_0xf955('0x28')]()[_0xf955('0x27')](function(){_0x3585c7['status'](0xcc)[_0xf955('0x29')]();});}};}function handleEntityNotFound(_0x1acf33,_0xba8a22){return function(_0x406632){if(!_0x406632){_0x1acf33[_0xf955('0x1d')](0x194);}return _0x406632;};}function handleError(_0x13a86d,_0x3796f7){_0x3796f7=_0x3796f7||0x1f4;return function(_0x51f3ab){logger[_0xf955('0x2a')](_0x51f3ab[_0xf955('0x2b')]);if(_0x51f3ab[_0xf955('0x2c')]){delete _0x51f3ab[_0xf955('0x2c')];}_0x13a86d[_0xf955('0x1e')](_0x3796f7)[_0xf955('0x2d')](_0x51f3ab);};}function getInteractionUsers(_0x4d4af0,_0x2232a7){return new BPromise(function(_0x1e5d37,_0x4ec3e8){try{if(_0x2232a7[_0x4d4af0['id']]){_0x4d4af0[_0xf955('0x2e')]=_[_0xf955('0x2f')](_0x2232a7[_0x4d4af0['id']],function(_0xf3c870){return{'id':_0xf3c870['id'],'fullname':_0xf3c870[_0xf955('0x30')]};});}}catch(_0x59bfb5){_0x4ec3e8(_0x59bfb5);}_0x1e5d37(_0x4d4af0);});}function getInteractionTags(_0x3a951c,_0x518fb3){return new BPromise(function(_0x227104,_0x2c222a){try{if(_0x3a951c[_0xf955('0x31')]){_0x3a951c[_0xf955('0x32')]=[];_0x3a951c[_0xf955('0x31')][_0xf955('0x33')](',')[_0xf955('0x34')](function(_0x366b6d){_0x3a951c['Tags'][_0xf955('0x35')](_0x518fb3[_0x366b6d]);});}delete _0x3a951c[_0xf955('0x31')];}catch(_0x3964d3){_0x2c222a(_0x3964d3);}_0x227104(_0x3a951c);});}function updateWhatsappInteraction(_0x2046c8,_0x4fea0c,_0x23c848){return new BPromise(function(_0x31dad5,_0x3c81bc){return getInteractionUsers(_0x2046c8,_0x23c848)[_0xf955('0x27')](function(_0xdbc53e){return getInteractionTags(_0xdbc53e,_0x4fea0c);})['then'](function(_0x4d7155){_0x31dad5(_0x4d7155);})['catch'](function(_0x2626cb){_0x3c81bc(_0x2626cb);});});}exports[_0xf955('0x36')]=function(_0x374e95,_0x6d564c){var _0x467447={},_0x39de9c={},_0x5acb00={'count':0x0,'rows':[]};var _0x3acc4b=_['map'](db[_0xf955('0x37')][_0xf955('0x38')],function(_0xe33ef2){return{'name':_0xe33ef2['fieldName'],'type':_0xe33ef2[_0xf955('0x39')]['key']};});_0x39de9c[_0xf955('0x3a')]=_[_0xf955('0x2f')](_0x3acc4b,_0xf955('0x2c'));_0x39de9c[_0xf955('0x3b')]=_['keys'](_0x374e95[_0xf955('0x3b')]);_0x39de9c[_0xf955('0x3c')]=_['intersection'](_0x39de9c[_0xf955('0x3a')],_0x39de9c[_0xf955('0x3b')]);_0x467447[_0xf955('0x3d')]=_['intersection'](_0x39de9c[_0xf955('0x3a')],qs[_0xf955('0x3e')](_0x374e95[_0xf955('0x3b')]['fields']));_0x467447[_0xf955('0x3d')]=_0x467447[_0xf955('0x3d')][_0xf955('0x3f')]?_0x467447[_0xf955('0x3d')]:_0x39de9c[_0xf955('0x3a')];if(!_0x374e95[_0xf955('0x3b')][_0xf955('0x40')](_0xf955('0x41'))){_0x467447['limit']=qs[_0xf955('0x22')](_0x374e95[_0xf955('0x3b')][_0xf955('0x22')]);_0x467447[_0xf955('0x21')]=qs[_0xf955('0x21')](_0x374e95[_0xf955('0x3b')][_0xf955('0x21')]);}_0x467447[_0xf955('0x42')]=qs[_0xf955('0x43')](_0x374e95[_0xf955('0x3b')][_0xf955('0x43')]);_0x467447[_0xf955('0x44')]=qs[_0xf955('0x3c')](_[_0xf955('0x45')](_0x374e95[_0xf955('0x3b')],_0x39de9c[_0xf955('0x3c')]),_0x3acc4b);var _0x356ec2=[];var _0x34f0f1=squel[_0xf955('0x46')]()['field']('id')[_0xf955('0x47')](_0xf955('0x2c'))[_0xf955('0x47')]('color')[_0xf955('0x48')]('tools_tags');var _0x398224=squel['select']()[_0xf955('0x47')](_0xf955('0x49'))[_0xf955('0x47')](_0xf955('0x4a'))['field'](_0xf955('0x4b'))[_0xf955('0x48')](_0xf955('0x4c'),'ui')['left_join']('users','u',_0xf955('0x4d'));var _0x314281=squel[_0xf955('0x46')]()[_0xf955('0x48')]('whatsapp_interactions','i')[_0xf955('0x4e')](_0xf955('0x4f'),'c',_0xf955('0x50'))['left_join'](_0xf955('0x51'),'o','o.id\x20=\x20i.UserId')[_0xf955('0x4e')](_0xf955('0x52'),'a',_0xf955('0x53'))['left_join'](_0xf955('0x54'),'me',_0xf955('0x55'))[_0xf955('0x4e')](_0xf955('0x56'),'it','it.WhatsappInteractionId\x20=\x20i.id')[_0xf955('0x4e')](_0xf955('0x57'),'t',_0xf955('0x58'));var _0x17e687=squel[_0xf955('0x59')]();var _0x4f5a95=[];var _0x29126c=squel['expr']();var _0x35c23c;if(_0x374e95['query'][_0xf955('0x5a')]){_0x35c23c=as['parseSearch'](_0x374e95['query'][_0xf955('0x5a')]);var _0x45c7fe=_0x35c23c['sqlOperator'];for(var _0x142e8f=0x0;_0x142e8f<_0x35c23c['conditions']['length'];_0x142e8f++){var _0x4c2977=_0x35c23c['conditions'][_0x142e8f];var _0x3c37e2='i';var _0x1abe1c=_['find'](_0x3acc4b,['name',_0x4c2977[_0xf955('0x47')]]);if(!_0x1abe1c){switch(_0x4c2977[_0xf955('0x47')]){case _0xf955('0x5b'):if(_0x4c2977[_0xf955('0x5c')]==0x1){_0x314281[_0xf955('0x5d')]('`'+_0x4c2977[_0xf955('0x47')]+_0xf955('0x5e'));}else{_0x314281[_0xf955('0x5d')]('`'+_0x4c2977[_0xf955('0x47')]+_0xf955('0x5f'));}break;case _0xf955('0x60'):if(_0x4c2977[_0xf955('0x61')]==='$substring'){if(_0x4c2977[_0xf955('0x5c')][_0xf955('0x33')]('\x20')[_0xf955('0x3f')]>0x1){_0x17e687[_0x45c7fe](_0xf955('0x62'),qs[_0xf955('0x63')](_0x4c2977['value']),null);}else{var _0xf5d575='%'+_0x4c2977[_0xf955('0x5c')]+'%';_0x17e687[_0x45c7fe](_0xf955('0x64'),_0xf5d575,_0xf5d575,_0xf5d575);}}else{_0x1abe1c=_[_0xf955('0x65')](_0x3acc4b,[_0xf955('0x2c'),_0xf955('0x66')]);_0x4c2977[_0xf955('0x47')]=_0xf955('0x66');_0x545c1f=as[_0xf955('0x67')](_0x3c37e2,_0x1abe1c[_0xf955('0x39')],_0x4c2977);_0x17e687[_0x45c7fe](_0x545c1f['text'],_0x545c1f[_0xf955('0x5c')][_0xf955('0x68')],_0x545c1f[_0xf955('0x5c')][_0xf955('0x29')]);}break;case _0xf955('0x69'):var _0x3b0e91=_0x4c2977[_0xf955('0x5c')][_0xf955('0x33')](',')[_0xf955('0x2f')](function(_0x26e837){return Number(_0x26e837);});_0x3b0e91[_0xf955('0x34')](function(_0x2b8173){_0x29126c['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x2b8173+',%');});_0x4f5a95=_[_0xf955('0x6a')](_0x4f5a95,_0x3b0e91);break;case _0xf955('0x6b'):if(_0x4c2977[_0xf955('0x61')]===_0xf955('0x6c')){_0x17e687[_0x45c7fe](_0xf955('0x6d'),'%'+_0x4c2977[_0xf955('0x5c')]+'%',null);}else{_0x1abe1c=_[_0xf955('0x65')](_0x3acc4b,['name','UserId']);_0x4c2977['field']=_0xf955('0x6e');_0x545c1f=as['buildExpression'](_0x3c37e2,_0x1abe1c['type'],_0x4c2977);_0x17e687[_0x45c7fe](_0x545c1f[_0xf955('0x6f')],_0x545c1f['value'][_0xf955('0x68')],_0x545c1f[_0xf955('0x5c')][_0xf955('0x29')]);}break;case _0xf955('0x70'):_0x545c1f=as['buildExpression']('me',null,_0x4c2977);_0x17e687[_0x45c7fe](_0x545c1f[_0xf955('0x6f')],_0x545c1f[_0xf955('0x5c')][_0xf955('0x68')],_0x545c1f[_0xf955('0x5c')][_0xf955('0x29')]);break;}}else{var _0x545c1f=as[_0xf955('0x67')](_0x3c37e2,_0x1abe1c['type'],_0x4c2977);_0x17e687[_0x45c7fe](_0x545c1f[_0xf955('0x6f')],_0x545c1f[_0xf955('0x5c')][_0xf955('0x68')],_0x545c1f['value'][_0xf955('0x29')]);}}}else{var _0x40ca54=_(_0x374e95[_0xf955('0x3b')])[_0xf955('0x71')]()[_0xf955('0x2f')](function(_0x339661){return _[_0xf955('0x72')](_0x3acc4b,['name',_0x339661])?_0x339661:undefined;})['compact']()[_0xf955('0x5c')]();if(!_[_0xf955('0x73')](_0x40ca54)){_0x40ca54[_0xf955('0x34')](function(_0x3f0873){if(_0x3f0873===_0xf955('0x74')){_0x314281[_0xf955('0x44')](_0xf955('0x75'),[][_0xf955('0x76')](_0x374e95[_0xf955('0x3b')][_0x3f0873]));}else if(_0x3f0873===_0xf955('0x77')){var _0x71ee3a=JSON['parse'](_0x374e95[_0xf955('0x3b')][_0x3f0873])['$gte'];var _0x431729=JSON['parse'](_0x374e95['query'][_0x3f0873])[_0xf955('0x78')];_0x314281[_0xf955('0x44')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x71ee3a,_0x431729);}else{if(_0x374e95[_0xf955('0x3b')][_0x3f0873]===_0xf955('0x79')){_0x314281['where']('i.'+_0x3f0873+'\x20IS\x20NULL');}else{_0x314281[_0xf955('0x44')]('i.'+_0x3f0873+_0xf955('0x7a'),_0x374e95[_0xf955('0x3b')][_0x3f0873]);}}});}if(_0x374e95['query'][_0xf955('0x7b')]){if(_0x374e95[_0xf955('0x3b')][_0xf955('0x7b')]==0x1){_0x314281[_0xf955('0x5d')](_0xf955('0x7c'));}else{_0x314281[_0xf955('0x5d')](_0xf955('0x7d'));}}if(_0x374e95[_0xf955('0x3b')]['tag']){_0x4f5a95=_[_0xf955('0x7e')](_0x374e95[_0xf955('0x3b')]['tag'])?_0x374e95[_0xf955('0x3b')][_0xf955('0x7f')]:new Array(_0x374e95[_0xf955('0x3b')][_0xf955('0x7f')]);_0x4f5a95['forEach'](function(_0x2e0d12){_0x29126c['or'](_0xf955('0x80'),'%,'+_0x2e0d12+',%');});}if(_0x374e95['query']['filter']){var _0x2fe31b=_0x374e95[_0xf955('0x3b')][_0xf955('0x81')][_0xf955('0x82')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xf955('0x83')](_0x2fe31b)){_0x17e687['or'](_0xf955('0x84'),_0x2fe31b+'%')['or'](_0xf955('0x85'),_0x2fe31b+'%');}else{_0x17e687['or'](_0xf955('0x86'),qs[_0xf955('0x63')](_0x2fe31b))['or'](_0xf955('0x87'),_0x2fe31b+'%');}}}_0x314281[_0xf955('0x44')](_0x17e687);_0x314281[_0xf955('0x88')](_0xf955('0x89'));var _0x12d8d1={'type':db[_0xf955('0x8a')][_0xf955('0x8b')][_0xf955('0x8c')],'raw':!![]};var _0x5c92ed=_0x314281[_0xf955('0x8d')]();_0x5c92ed[_0xf955('0x47')](_0xf955('0x89'));_0x5c92ed[_0xf955('0x47')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xf955('0x5b'));if(_0x467447[_0xf955('0x42')]){_0x467447[_0xf955('0x42')][_0xf955('0x34')](function(_0x2b266d){var _0x30df2a=_0x2b266d[0x0]===_0xf955('0x8e')?_0x2b266d[0x0]:'i.'+_0x2b266d[0x0];_0x314281[_0xf955('0x42')](_0x30df2a,_0x2b266d[0x1]===_0xf955('0x8f')?![]:!![]);});}if(!_[_0xf955('0x73')](_0x4f5a95)){_0x314281[_0xf955('0x5d')](_0x29126c);_0x5c92ed['where'](_0xf955('0x90'),_0x4f5a95);}BPromise[_0xf955('0x91')]()[_0xf955('0x27')](function(){if(!_0x35c23c){if(_0x374e95[_0xf955('0x3b')][_0xf955('0x74')])return;_0x5c92ed[_0xf955('0x44')](_0xf955('0x92'));_0x314281['where'](_0xf955('0x92'));return;}if(_0x374e95['user'][_0xf955('0x93')]!=='agent')return;return _0x374e95[_0xf955('0x94')][_0xf955('0x95')]({'attributes':['id'],'raw':!![]})[_0xf955('0x27')](function(_0x147b5c){if(_[_0xf955('0x73')](_0x147b5c)){_0x5c92ed[_0xf955('0x44')]('i.WhatsappAccountId\x20IS\x20NULL');_0x314281[_0xf955('0x44')](_0xf955('0x96'));}else{_0x5c92ed[_0xf955('0x44')]('i.WhatsappAccountId\x20IN\x20?',_['map'](_0x147b5c,'id'));_0x314281[_0xf955('0x44')](_0xf955('0x75'),_[_0xf955('0x2f')](_0x147b5c,'id'));}});})['then'](function(){if(_0x374e95[_0xf955('0x94')]['role']===_0xf955('0x97')&&!_0x35c23c&&!_0x374e95['query'][_0xf955('0x74')])return[];return db[_0xf955('0x98')][_0xf955('0x3b')](_0x5c92ed['toString'](),_0x12d8d1);})[_0xf955('0x27')](function(_0x397f7e){_0x5acb00[_0xf955('0x20')]=_0x397f7e['length'];if(_0x5acb00[_0xf955('0x20')]===0x0)return[];return db[_0xf955('0x98')][_0xf955('0x3b')](_0x34f0f1[_0xf955('0x99')](),_0x12d8d1)[_0xf955('0x27')](function(_0x130e1a){_0x356ec2=_[_0xf955('0x9a')](_0x130e1a,'id');_0x12d8d1=_['merge'](_0x12d8d1,{'model':db[_0xf955('0x37')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x374e95[_0xf955('0x3b')][_0xf955('0x3e')]){_0x467447[_0xf955('0x3d')][_0xf955('0x34')](function(_0x585a62){_0x314281[_0xf955('0x47')]('i.'+_0x585a62);});}else{_0x314281[_0xf955('0x47')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x314281[_0xf955('0x47')](_0xf955('0x9b'),_0xf955('0x9c'));_0x314281[_0xf955('0x47')]('a.mandatoryDisposition',_0xf955('0x9d'));_0x314281['field']('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',_0xf955('0x8e'));_0x314281[_0xf955('0x47')]('i.*');_0x314281['field'](_0xf955('0x9e'),_0xf955('0x9f'));_0x314281[_0xf955('0x47')]('c.lastName','Contact.lastName');_0x314281[_0xf955('0x47')](_0xf955('0xa0'),_0xf955('0xa1'));_0x314281['field']('c.phone','Contact.phone');_0x314281['field'](_0xf955('0xa2'),'Contact.mobile');_0x314281[_0xf955('0x47')](_0xf955('0xa3'),_0xf955('0xa4'));_0x314281[_0xf955('0x47')](_0xf955('0xa5'),'Owner.fullname');_0x314281[_0xf955('0x47')](_0xf955('0xa6'),_0xf955('0xa7'));_0x314281[_0xf955('0x47')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0xf955('0x31'));}if(_0x467447[_0xf955('0x22')])_0x314281['limit'](_0x467447[_0xf955('0x22')]);if(_0x467447[_0xf955('0x21')])_0x314281[_0xf955('0x21')](_0x467447[_0xf955('0x21')]);return db[_0xf955('0x98')][_0xf955('0x3b')](_0x314281['toString'](),_0x12d8d1);})['then'](function(_0x230e2e){_0x398224['where'](_0xf955('0xa8'),_[_0xf955('0x2f')](_0x230e2e,'id'));return db[_0xf955('0x98')][_0xf955('0x3b')](_0x398224['toString'](),_0x12d8d1)['then'](function(_0x7a6712){var _0x12b9f8=_[_0xf955('0xa9')](_0x7a6712,_0xf955('0xaa'));var _0xee52ad=[];_0x230e2e['forEach'](function(_0x21f45e){_0xee52ad[_0xf955('0x35')](updateWhatsappInteraction(_0x21f45e,_0x356ec2,_0x12b9f8));});return BPromise[_0xf955('0xab')](_0xee52ad);});});})[_0xf955('0x27')](function(_0x5ce8b7){_0x5acb00['rows']=_0x5ce8b7;return _0x5acb00;})[_0xf955('0x27')](respondWithFilteredResult(_0x6d564c,_0x467447))[_0xf955('0xac')](handleError(_0x6d564c,null));};exports['show']=function(_0x379f35,_0x41a96e){var _0x395e56={'raw':![],'where':{'id':_0x379f35['params']['id']}},_0x3d7a6={};_0x3d7a6[_0xf955('0x3a')]=_[_0xf955('0x71')](db[_0xf955('0x37')][_0xf955('0x38')]);_0x3d7a6[_0xf955('0x3b')]=_[_0xf955('0x71')](_0x379f35[_0xf955('0x3b')]);_0x3d7a6['filters']=_['intersection'](_0x3d7a6['model'],_0x3d7a6[_0xf955('0x3b')]);_0x395e56[_0xf955('0x3d')]=_[_0xf955('0xad')](_0x3d7a6[_0xf955('0x3a')],qs[_0xf955('0x3e')](_0x379f35[_0xf955('0x3b')][_0xf955('0x3e')]));_0x395e56['attributes']=_0x395e56[_0xf955('0x3d')][_0xf955('0x3f')]?_0x395e56['attributes']:_0x3d7a6[_0xf955('0x3a')];if(_0x379f35[_0xf955('0x3b')][_0xf955('0xae')]){_0x395e56[_0xf955('0xaf')]=[{'all':!![]}];}_0x395e56=_[_0xf955('0xb0')]({},_0x395e56,_0x379f35[_0xf955('0xb1')]);return db[_0xf955('0x37')][_0xf955('0x65')](_0x395e56)['then'](handleEntityNotFound(_0x41a96e,null))['then'](respondWithResult(_0x41a96e,null))['catch'](handleError(_0x41a96e,null));};exports[_0xf955('0xb2')]=function(_0x3945f5,_0x210666){return db[_0xf955('0x37')][_0xf955('0xb2')](_0x3945f5['body'],{})[_0xf955('0x27')](respondWithResult(_0x210666,0xc9))[_0xf955('0xac')](handleError(_0x210666,null));};exports[_0xf955('0xb3')]=function(_0x1e7024,_0x43e078){if(_0x1e7024[_0xf955('0x70')]['id']){delete _0x1e7024[_0xf955('0x70')]['id'];}return db[_0xf955('0x37')][_0xf955('0x65')]({'where':{'id':_0x1e7024['params']['id']}})[_0xf955('0x27')](handleEntityNotFound(_0x43e078,null))['then'](saveUpdates(_0x1e7024[_0xf955('0x70')],null))[_0xf955('0x27')](respondWithResult(_0x43e078,null))[_0xf955('0xac')](handleError(_0x43e078,null));};exports[_0xf955('0x28')]=function(_0x35968b,_0x187fb0){return db[_0xf955('0x37')]['find']({'where':{'id':_0x35968b[_0xf955('0xb4')]['id']}})['then'](handleEntityNotFound(_0x187fb0,null))[_0xf955('0x27')](removeEntity(_0x187fb0,null))[_0xf955('0xac')](handleError(_0x187fb0,null));};exports['describe']=function(_0x3503c6,_0x264576){return db[_0xf955('0x37')][_0xf955('0xb5')]()[_0xf955('0x27')](respondWithResult(_0x264576,null))[_0xf955('0xac')](handleError(_0x264576,null));};exports[_0xf955('0xb6')]=function(_0x5e3870,_0x11fd9e,_0x431c0c){return db['WhatsappMessage'][_0xf955('0x65')]({'where':{'id':_0x5e3870[_0xf955('0xb4')]['id']}})['then'](handleEntityNotFound(_0x11fd9e,null))['then'](function(_0x356eb0){if(_0x356eb0){return _0x356eb0[_0xf955('0xb6')](_0x5e3870[_0xf955('0x70')]['ids'],_[_0xf955('0xb7')](_0x5e3870[_0xf955('0x70')],[_0xf955('0xb8'),'id'])||{});}})[_0xf955('0x27')](respondWithResult(_0x11fd9e,null))[_0xf955('0xac')](handleError(_0x11fd9e,null));};exports[_0xf955('0xb9')]=function(_0x1a2ecc,_0x8d0c5b,_0x2ab571){var _0x210cfb={'raw':![],'where':{}};var _0x42939b={};var _0x41fde7={'count':0x0,'rows':[]};return db[_0xf955('0x37')][_0xf955('0xba')]({'where':{'id':_0x1a2ecc['params']['id']}})['then'](handleEntityNotFound(_0x8d0c5b,null))[_0xf955('0x27')](function(_0xc7cc7b){if(_0xc7cc7b){_0x42939b[_0xf955('0x3a')]=_[_0xf955('0x71')](db[_0xf955('0xbb')]['rawAttributes']);_0x42939b[_0xf955('0x3b')]=_[_0xf955('0x71')](_0x1a2ecc['query']);_0x42939b[_0xf955('0x3c')]=_[_0xf955('0xad')](_0x42939b[_0xf955('0x3a')],_0x42939b[_0xf955('0x3b')]);_0x210cfb['attributes']=_[_0xf955('0xad')](_0x42939b['model'],qs[_0xf955('0x3e')](_0x1a2ecc[_0xf955('0x3b')][_0xf955('0x3e')]));_0x210cfb[_0xf955('0x3d')]=_0x210cfb['attributes'][_0xf955('0x3f')]?_0x210cfb[_0xf955('0x3d')]:_0x42939b[_0xf955('0x3a')];if(!_0x1a2ecc[_0xf955('0x3b')][_0xf955('0x40')]('nolimit')){_0x210cfb[_0xf955('0x22')]=qs[_0xf955('0x22')](_0x1a2ecc[_0xf955('0x3b')]['limit']);_0x210cfb[_0xf955('0x21')]=qs[_0xf955('0x21')](_0x1a2ecc[_0xf955('0x3b')][_0xf955('0x21')]);}_0x210cfb[_0xf955('0x42')]=qs[_0xf955('0x43')](_0x1a2ecc[_0xf955('0x3b')]['sort']);_0x210cfb['where']=qs['filters'](_[_0xf955('0x45')](_0x1a2ecc[_0xf955('0x3b')],_0x42939b['filters']));_0x210cfb[_0xf955('0x44')][_0xf955('0xaa')]=_0xc7cc7b['id'];if(_0x1a2ecc[_0xf955('0x3b')]['filter']){_0x210cfb[_0xf955('0x44')]=_[_0xf955('0xb0')](_0x210cfb['where'],{'$or':_['map'](_0x210cfb[_0xf955('0x3d')],function(_0x8eae44){var _0x184581={};_0x184581[_0x8eae44]={'$like':'%'+_0x1a2ecc[_0xf955('0x3b')][_0xf955('0x81')]+'%'};return _0x184581;})});}if(_0x1a2ecc['query'][_0xf955('0xbc')]){var _0x250a78=_0x1a2ecc[_0xf955('0x3b')][_0xf955('0xbc')][_0xf955('0x33')](',');var _0x480d95={};_0x480d95[_0x250a78[0x0]]={'$gte':moment(_0x250a78[0x1])[_0xf955('0xbd')](_0xf955('0xbe'))};_0x210cfb[_0xf955('0x44')]=_[_0xf955('0xb0')](_0x210cfb['where'],_0x480d95);}_0x210cfb=_[_0xf955('0xb0')]({},_0x210cfb,_0x1a2ecc[_0xf955('0xb1')]);return db[_0xf955('0xbb')][_0xf955('0x20')]({'where':_0x210cfb[_0xf955('0x44')]})['then'](function(_0x702587){_0x41fde7[_0xf955('0x20')]=_0x702587;if(_0x1a2ecc['query'][_0xf955('0xae')]){_0x210cfb[_0xf955('0xaf')]=[{'all':!![]}];}return db[_0xf955('0xbb')][_0xf955('0xbf')](_0x210cfb);})[_0xf955('0x27')](function(_0x38e031){_0x41fde7[_0xf955('0xc0')]=_0x38e031;return _0x41fde7;});}})[_0xf955('0x27')](respondWithFilteredResult(_0x8d0c5b,_0x210cfb))[_0xf955('0xac')](handleError(_0x8d0c5b,null));};exports[_0xf955('0xc1')]=function(_0x478d05,_0x5395aa,_0x3bec17){return db[_0xf955('0x37')][_0xf955('0x65')]({'where':{'id':_0x478d05[_0xf955('0xb4')]['id']}})['then'](handleEntityNotFound(_0x5395aa,null))[_0xf955('0x27')](function(_0x1d4389){if(_0x1d4389){return _0x1d4389['setTags'](_0x478d05['body'][_0xf955('0xb8')],_[_0xf955('0xb7')](_0x478d05[_0xf955('0x70')],[_0xf955('0xb8'),'id'])||{})['spread'](function(){return db[_0xf955('0x69')][_0xf955('0xbf')]({'attributes':['id',_0xf955('0x2c'),_0xf955('0xc2')],'where':{'id':_0x478d05[_0xf955('0x70')][_0xf955('0xb8')]}});})[_0xf955('0x27')](function(_0x3602e8){socket['emit'](_0xf955('0xc3'),{'id':Number(_0x478d05[_0xf955('0xb4')]['id']),'tags':_0x3602e8||[]});return{'id':Number(_0x478d05[_0xf955('0xb4')]['id']),'tags':_0x3602e8||[]};});}})[_0xf955('0x27')](respondWithResult(_0x5395aa,null))[_0xf955('0xac')](handleError(_0x5395aa,null));};exports[_0xf955('0xc4')]=function(_0x2a3339,_0x313107,_0x1f17fb){return db[_0xf955('0x37')]['find']({'where':{'id':_0x2a3339[_0xf955('0xb4')]['id']}})[_0xf955('0x27')](handleEntityNotFound(_0x313107,null))[_0xf955('0x27')](function(_0x27391f){if(_0x27391f){return _0x27391f[_0xf955('0xc4')](_0x2a3339[_0xf955('0x3b')][_0xf955('0xb8')]);}})['then'](respondWithStatusCode(_0x313107,null))[_0xf955('0xac')](handleError(_0x313107,null));};exports['download']=function(_0x2d1e51,_0x2734bd){var _0x14cde9=moment()[_0xf955('0xc5')]()[_0xf955('0x99')]();var _0x621a28=path[_0xf955('0xc6')](config[_0xf955('0xc7')],_0xf955('0xc8'),'files',_0xf955('0xc9'));var _0x2d79a0=path[_0xf955('0xc6')](config[_0xf955('0xc7')],_0xf955('0xc8'),_0xf955('0xca'),'attachments');var _0x23aff1=path[_0xf955('0xc6')](_0x621a28,_0x14cde9);var _0x378c6e=util['format'](_0xf955('0xcb'),_0x2d1e51[_0xf955('0xb4')]['id'],_0x14cde9);var _0x2e5554=path[_0xf955('0xc6')](_0x621a28,_0x378c6e);var _0x3b3c0e=[];_0x3b3c0e[_0xf955('0x35')]({'model':db['User'],'as':_0xf955('0x6b'),'attributes':['id',_0xf955('0x30')],'raw':!![]});_0x3b3c0e[_0xf955('0x35')]({'model':db[_0xf955('0xcc')],'as':_0xf955('0x60'),'attributes':['id',_0xf955('0xcd'),'lastName'],'raw':!![]});if(_0x2d1e51[_0xf955('0x3b')]['attachments']){_0x3b3c0e['push']({'model':db['Attachment'],'as':'Attachment','raw':!![]});}var _0x45c516=[{'model':db['WhatsappMessage'],'as':_0xf955('0xce'),'attributes':['id',_0xf955('0x70'),'createdAt',_0xf955('0xcf'),'secret',_0xf955('0x7b')],'include':_0x3b3c0e}];_0x45c516['push']({'model':db[_0xf955('0xd0')],'as':_0xf955('0xd1'),'attributes':['id',_0xf955('0x2c')]});_0x45c516[_0xf955('0x35')]({'model':db['User'],'as':_0xf955('0xd2'),'attributes':['id','fullname']});return db[_0xf955('0x37')][_0xf955('0x65')]({'where':{'id':_0x2d1e51[_0xf955('0xb4')]['id']},'include':_0x45c516})[_0xf955('0x27')](handleEntityNotFound(_0x2734bd,null))[_0xf955('0x27')](function(_0x3b5869){if(_0x3b5869){var _0x1cc042=_0x3b5869[_0xf955('0xd3')]({'plain':!![]});fs[_0xf955('0xd4')](_0x23aff1);var _0x226161={'format':'A4','border':'10px','header':{'height':_0xf955('0xd5'),'contents':{'first':_0xf955('0xd6')}},'footer':{'height':_0xf955('0xd7'),'contents':{'default':util[_0xf955('0xbd')](_0xf955('0xd8'),util[_0xf955('0xbd')](_0xf955('0xd9'),'Whatsapp',_0x1cc042['id']),moment()[_0xf955('0xbd')](_0xf955('0xda'))[_0xf955('0x99')]())}}};var _0x1e35d7={'channel':_0xf955('0xdb'),'account':_0x1cc042[_0xf955('0xd1')][_0xf955('0x2c')],'agent':_0x1cc042[_0xf955('0xd2')]?_0x1cc042[_0xf955('0xd2')][_0xf955('0x30')]:'N.A.','createdAt':moment(_0x1cc042[_0xf955('0x77')])[_0xf955('0xbd')](_0xf955('0xbe'))[_0xf955('0x99')](),'closedAt':_0x1cc042[_0xf955('0xdc')]?moment(_0x1cc042[_0xf955('0xdd')])[_0xf955('0xbd')](_0xf955('0xbe'))['toString']():'','disposition':_0x1cc042[_0xf955('0xde')],'messages':_(_0x1cc042[_0xf955('0xce')])[_0xf955('0x81')]({'secret':![]})[_0xf955('0x2f')](function(_0x2148f0){if(_0x2148f0[_0xf955('0xdf')]){var _0x206b42=path[_0xf955('0xc6')](_0x2d79a0,_0x2148f0['Attachment']['basename']);if(fs[_0xf955('0xe0')](_0x206b42)){fs[_0xf955('0xe1')](_0x206b42)[_0xf955('0xe2')](fs[_0xf955('0xe3')](path['join'](_0x23aff1,_0x2148f0['Attachment'][_0xf955('0xe4')])));}}return{'date':moment(_0x2148f0[_0xf955('0x77')])['format'](_0xf955('0xbe'))[_0xf955('0x99')](),'sender':_0x2148f0[_0xf955('0xcf')]===_0xf955('0xe5')?_0x2148f0[_0xf955('0x6b')]?_0x2148f0['User'][_0xf955('0x30')]:_0xf955('0xe6'):_0x2148f0[_0xf955('0x60')][_0xf955('0xcd')]+(_0x2148f0[_0xf955('0x60')]['lastName']?'\x20'+_0x2148f0[_0xf955('0x60')]['lastName']:''),'body':_0x2148f0[_0xf955('0xdf')]?_0x2148f0['Attachment'][_0xf955('0xe4')]:_0x2148f0[_0xf955('0x70')],'direction':_0x2148f0[_0xf955('0xcf')]===_0xf955('0xe5')?'A':'C','secret':_0x2148f0[_0xf955('0xe7')],'read':_0x2148f0[_0xf955('0x7b')],'attachment':_0x2148f0[_0xf955('0xdf')]};})[_0xf955('0x5c')]()};return ejs[_0xf955('0xe8')](path[_0xf955('0xc6')](config['root'],'server',_0xf955('0xe9'),_0xf955('0xea')),{'interaction':_0x1e35d7})[_0xf955('0x27')](function(_0x522403){return new BPromise(function(_0x5e6e24,_0x494dda){pdf[_0xf955('0xb2')](_0x522403,_0x226161)['toFile'](path['join'](_0x23aff1,_0xf955('0xeb')+_0x1cc042['id']+'-'+_0x14cde9+'.pdf'),function(_0x2f8e43,_0x1ed1e1){if(_0x2f8e43)return _0x494dda(_0x2f8e43);_0x5e6e24(_0x1ed1e1);});});})['then'](function(){return new BPromise(function(_0x4f7329,_0x161004){zipdir(_0x23aff1,{'saveTo':_0x2e5554},function(_0x2a01fa,_0x1b4ace){if(_0x2a01fa)return _0x161004(_0x2a01fa);return _0x4f7329(_0x1b4ace);});})[_0xf955('0x27')](function(){return new BPromise(function(_0x30e0a1,_0x5cbf1e){rimraf(_0x23aff1,function(_0x143bfd){if(_0x143bfd)_0x5cbf1e(_0x143bfd);return _0x30e0a1();});});})['then'](function(){return _0x2734bd['download'](_0x2e5554,_0x378c6e,function(_0x591585){if(_0x591585){console[_0xf955('0xec')](_0xf955('0xed'),_0x591585);}else{fs[_0xf955('0xee')](_0x2e5554);}});});});}else{return _0x2734bd['sendStatus'](0xc8);}})['catch'](handleError(_0x2734bd,null));};
\ No newline at end of file