Built motion from commit (unavailable).|2.5.27
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 8c82cef..f2d06ae 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f66=['limit','offset','order','sort','pick','select','field','color','from','tools_tags','u.id','u.fullname','user_has_whatsapp_interactions','left_join','u.id\x20=\x20ui.UserId','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','unreadMessages','having','`\x20>\x200','Contact','operator','$substring','value','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','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','start','body','keys','some','isEmpty','WhatsappAccountId','where','concat','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','isArray','tag','filter','replace','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','group','i.id','QueryTypes','clone','contactName','t.id\x20IN\x20?','resolve','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','role','agent','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','toString','sequelize','keyBy','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','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.*','Contact.firstName','c.lastName','c.email','Contact.email','c.phone','Contact.phone','Contact.mobile','c.fax','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','WhatsappInteractionId','rows','show','includeAll','include','merge','options','create','params','describe','WhatsappMessage','addMessage','ids','getMessages','findOne','rawAttributes','format','findAll','addTags','setTags','omit','spread','emit','whatsappInteractionTags:save','removeTags','unix','join','root','server','files','tmp','transcript-%d-%s.zip','CmContact','firstName','lastName','attachments','Attachment','Messages','createdAt','secret','WhatsappAccount','Account','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','YYYY-MM-DD','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','basename','existsSync','createReadStream','pipe','createWriteStream','direction','out','System','renderFile','downloadInteraction.html','toFile','transcript-','.pdf','download','log','err','unlinkSync','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','end','status','json','count','set','apply','reject','update','then','destroy','error','stack','name','send','Users','map','fullname','TagIds','split','forEach','Tags','push','catch','index','WhatsappInteraction','fieldName','type','query','filters','model','intersection','fields','attributes','length','hasOwnProperty','nolimit'];(function(_0x3296c3,_0xc96c4a){var _0x1fb66a=function(_0xa92688){while(--_0xa92688){_0x3296c3['push'](_0x3296c3['shift']());}};_0x1fb66a(++_0xc96c4a);}(_0x5f66,0x1a0));var _0x65f6=function(_0x31e29a,_0x349c9b){_0x31e29a=_0x31e29a-0x0;var _0x32d892=_0x5f66[_0x31e29a];return _0x32d892;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x65f6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x65f6('0x1'));var jsonpatch=require(_0x65f6('0x2'));var rp=require(_0x65f6('0x3'));var moment=require(_0x65f6('0x4'));var BPromise=require(_0x65f6('0x5'));var Mustache=require('mustache');var util=require(_0x65f6('0x6'));var path=require('path');var sox=require(_0x65f6('0x7'));var csv=require(_0x65f6('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x65f6('0x9'));var crypto=require(_0x65f6('0xa'));var jsforce=require(_0x65f6('0xb'));var deskjs=require(_0x65f6('0xc'));var toCsv=require(_0x65f6('0x8'));var querystring=require(_0x65f6('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x65f6('0xe'));var qs=require(_0x65f6('0xf'));var as=require(_0x65f6('0x10'));var hardwareService=require(_0x65f6('0x11'));var logger=require('../../config/logger')(_0x65f6('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x65f6('0x13'));var db=require('../../mysqldb')['db'];config[_0x65f6('0x14')]=_['defaults'](config[_0x65f6('0x14')],{'host':_0x65f6('0x15'),'port':0x18eb});var socket=require(_0x65f6('0x16'))(new Redis(config[_0x65f6('0x14')]));require(_0x65f6('0x17'))[_0x65f6('0x18')](socket);function respondWithStatusCode(_0x44144b,_0xb1d40a){_0xb1d40a=_0xb1d40a||0xcc;return function(_0x46dbc6){if(_0x46dbc6){return _0x44144b[_0x65f6('0x19')](_0xb1d40a);}return _0x44144b['status'](_0xb1d40a)[_0x65f6('0x1a')]();};}function respondWithResult(_0x49a913,_0x5dd324){_0x5dd324=_0x5dd324||0xc8;return function(_0x1693e6){if(_0x1693e6){return _0x49a913[_0x65f6('0x1b')](_0x5dd324)[_0x65f6('0x1c')](_0x1693e6);}};}function respondWithFilteredResult(_0x1c955c,_0x1b1cbb){return function(_0x1f974c){if(_0x1f974c){var _0xc8660c=_0x1f974c[_0x65f6('0x1d')],_0x18380e=_0x1b1cbb['offset'],_0x495dd6=_0x1b1cbb['offset']+_0x1b1cbb['limit'],_0x4d79a1;if(_0x495dd6>=_0xc8660c){_0x495dd6=_0xc8660c;_0x4d79a1=0xc8;}else{_0x4d79a1=0xce;}_0x1c955c[_0x65f6('0x1b')](_0x4d79a1);return _0x1c955c[_0x65f6('0x1e')]('Content-Range',_0x18380e+'-'+_0x495dd6+'/'+_0xc8660c)[_0x65f6('0x1c')](_0x1f974c);}return null;};}function patchUpdates(_0x270893){return function(_0xbee6a4){try{jsonpatch[_0x65f6('0x1f')](_0xbee6a4,_0x270893,!![]);}catch(_0x219ab2){return BPromise[_0x65f6('0x20')](_0x219ab2);}return _0xbee6a4['save']();};}function saveUpdates(_0x197a49,_0x4bb39e){return function(_0x5b9e2a){if(_0x5b9e2a){return _0x5b9e2a[_0x65f6('0x21')](_0x197a49)[_0x65f6('0x22')](function(_0x524e42){return _0x524e42;});}return null;};}function removeEntity(_0x1eeaaa,_0x471a33){return function(_0x2317ce){if(_0x2317ce){return _0x2317ce[_0x65f6('0x23')]()['then'](function(){_0x1eeaaa[_0x65f6('0x1b')](0xcc)[_0x65f6('0x1a')]();});}};}function handleEntityNotFound(_0x20a161,_0x5963e0){return function(_0x5cb131){if(!_0x5cb131){_0x20a161['sendStatus'](0x194);}return _0x5cb131;};}function handleError(_0x29abdb,_0x16cde8){_0x16cde8=_0x16cde8||0x1f4;return function(_0x4b2292){logger[_0x65f6('0x24')](_0x4b2292[_0x65f6('0x25')]);if(_0x4b2292['name']){delete _0x4b2292[_0x65f6('0x26')];}_0x29abdb[_0x65f6('0x1b')](_0x16cde8)[_0x65f6('0x27')](_0x4b2292);};}function getInteractionUsers(_0x559330,_0x4ac04b){return new BPromise(function(_0x488d36,_0x266cfe){try{if(_0x4ac04b[_0x559330['id']]){_0x559330[_0x65f6('0x28')]=_[_0x65f6('0x29')](_0x4ac04b[_0x559330['id']],function(_0x408ccc){return{'id':_0x408ccc['id'],'fullname':_0x408ccc[_0x65f6('0x2a')]};});}}catch(_0x14a387){_0x266cfe(_0x14a387);}_0x488d36(_0x559330);});}function getInteractionTags(_0x144e55,_0x4ace4c){return new BPromise(function(_0x4ea23d,_0x154cbd){try{if(_0x144e55[_0x65f6('0x2b')]){_0x144e55['Tags']=[];_0x144e55['TagIds'][_0x65f6('0x2c')](',')[_0x65f6('0x2d')](function(_0x11fe3b){_0x144e55[_0x65f6('0x2e')][_0x65f6('0x2f')](_0x4ace4c[_0x11fe3b]);});}delete _0x144e55[_0x65f6('0x2b')];}catch(_0x5792a0){_0x154cbd(_0x5792a0);}_0x4ea23d(_0x144e55);});}function updateWhatsappInteraction(_0x103265,_0x38f3c6,_0x46f03c){return new BPromise(function(_0x4bc037,_0x217f35){return getInteractionUsers(_0x103265,_0x46f03c)[_0x65f6('0x22')](function(_0xbaed3c){return getInteractionTags(_0xbaed3c,_0x38f3c6);})[_0x65f6('0x22')](function(_0x37c086){_0x4bc037(_0x37c086);})[_0x65f6('0x30')](function(_0x4d4d84){_0x217f35(_0x4d4d84);});});}exports[_0x65f6('0x31')]=function(_0x1b24ea,_0x4f3e22){var _0x36dbf4={},_0x5a740a={},_0x2b403b={'count':0x0,'rows':[]};var _0x50494b=_[_0x65f6('0x29')](db[_0x65f6('0x32')]['rawAttributes'],function(_0x12dee6){return{'name':_0x12dee6[_0x65f6('0x33')],'type':_0x12dee6[_0x65f6('0x34')]['key']};});_0x5a740a['model']=_[_0x65f6('0x29')](_0x50494b,'name');_0x5a740a[_0x65f6('0x35')]=_['keys'](_0x1b24ea[_0x65f6('0x35')]);_0x5a740a[_0x65f6('0x36')]=_['intersection'](_0x5a740a[_0x65f6('0x37')],_0x5a740a['query']);_0x36dbf4['attributes']=_[_0x65f6('0x38')](_0x5a740a[_0x65f6('0x37')],qs[_0x65f6('0x39')](_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x39')]));_0x36dbf4[_0x65f6('0x3a')]=_0x36dbf4[_0x65f6('0x3a')][_0x65f6('0x3b')]?_0x36dbf4['attributes']:_0x5a740a[_0x65f6('0x37')];if(!_0x1b24ea['query'][_0x65f6('0x3c')](_0x65f6('0x3d'))){_0x36dbf4[_0x65f6('0x3e')]=qs[_0x65f6('0x3e')](_0x1b24ea['query'][_0x65f6('0x3e')]);_0x36dbf4[_0x65f6('0x3f')]=qs[_0x65f6('0x3f')](_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x3f')]);}_0x36dbf4[_0x65f6('0x40')]=qs[_0x65f6('0x41')](_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x41')]);_0x36dbf4['where']=qs[_0x65f6('0x36')](_[_0x65f6('0x42')](_0x1b24ea[_0x65f6('0x35')],_0x5a740a[_0x65f6('0x36')]),_0x50494b);var _0x83e2d9=[];var _0x1ac040=squel[_0x65f6('0x43')]()[_0x65f6('0x44')]('id')[_0x65f6('0x44')](_0x65f6('0x26'))[_0x65f6('0x44')](_0x65f6('0x45'))[_0x65f6('0x46')](_0x65f6('0x47'));var _0xb1a132=squel[_0x65f6('0x43')]()['field'](_0x65f6('0x48'))[_0x65f6('0x44')](_0x65f6('0x49'))[_0x65f6('0x44')]('ui.WhatsappInteractionId')[_0x65f6('0x46')](_0x65f6('0x4a'),'ui')[_0x65f6('0x4b')]('users','u',_0x65f6('0x4c'));var _0x3386a2=squel[_0x65f6('0x43')]()[_0x65f6('0x46')]('whatsapp_interactions','i')[_0x65f6('0x4b')]('cm_contacts','c',_0x65f6('0x4d'))[_0x65f6('0x4b')]('users','o',_0x65f6('0x4e'))['left_join'](_0x65f6('0x4f'),'a',_0x65f6('0x50'))[_0x65f6('0x4b')](_0x65f6('0x51'),'me',_0x65f6('0x52'))[_0x65f6('0x4b')]('whatsapp_interaction_has_tags','it','it.WhatsappInteractionId\x20=\x20i.id')[_0x65f6('0x4b')](_0x65f6('0x47'),'t',_0x65f6('0x53'));var _0x1e9e29=squel[_0x65f6('0x54')]();var _0x2d6ab9=[];var _0x149c28=squel[_0x65f6('0x54')]();var _0x414f49;if(_0x1b24ea['query'][_0x65f6('0x55')]){_0x414f49=as[_0x65f6('0x56')](_0x1b24ea[_0x65f6('0x35')]['search']);var _0x47e749=_0x414f49[_0x65f6('0x57')];for(var _0x49ba5a=0x0;_0x49ba5a<_0x414f49[_0x65f6('0x58')][_0x65f6('0x3b')];_0x49ba5a++){var _0x57eb04=_0x414f49[_0x65f6('0x58')][_0x49ba5a];var _0x4f96c4='i';var _0x247be3=_[_0x65f6('0x59')](_0x50494b,[_0x65f6('0x26'),_0x57eb04['field']]);if(!_0x247be3){switch(_0x57eb04[_0x65f6('0x44')]){case _0x65f6('0x5a'):if(_0x57eb04['value']==0x1){_0x3386a2[_0x65f6('0x5b')]('`'+_0x57eb04[_0x65f6('0x44')]+'`\x20=\x200');}else{_0x3386a2[_0x65f6('0x5b')]('`'+_0x57eb04[_0x65f6('0x44')]+_0x65f6('0x5c'));}break;case _0x65f6('0x5d'):if(_0x57eb04[_0x65f6('0x5e')]===_0x65f6('0x5f')){if(_0x57eb04[_0x65f6('0x60')][_0x65f6('0x2c')]('\x20')['length']>0x1){_0x1e9e29[_0x47e749]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x57eb04[_0x65f6('0x60')]),null);}else{var _0x2091f1='%'+_0x57eb04[_0x65f6('0x60')]+'%';_0x1e9e29[_0x47e749](_0x65f6('0x61'),_0x2091f1,_0x2091f1,_0x2091f1);}}else{_0x247be3=_['find'](_0x50494b,[_0x65f6('0x26'),_0x65f6('0x62')]);_0x57eb04[_0x65f6('0x44')]='ContactId';_0x4241db=as[_0x65f6('0x63')](_0x4f96c4,_0x247be3[_0x65f6('0x34')],_0x57eb04);_0x1e9e29[_0x47e749](_0x4241db[_0x65f6('0x64')],_0x4241db['value']['start'],_0x4241db[_0x65f6('0x60')][_0x65f6('0x1a')]);}break;case _0x65f6('0x65'):var _0x39364f=_0x57eb04[_0x65f6('0x60')][_0x65f6('0x2c')](',')[_0x65f6('0x29')](function(_0x138334){return Number(_0x138334);});_0x39364f[_0x65f6('0x2d')](function(_0xddbd90){_0x149c28['or'](_0x65f6('0x66'),'%,'+_0xddbd90+',%');});_0x2d6ab9=_[_0x65f6('0x67')](_0x2d6ab9,_0x39364f);break;case _0x65f6('0x68'):if(_0x57eb04[_0x65f6('0x5e')]==='$substring'){_0x1e9e29[_0x47e749](_0x65f6('0x69'),'%'+_0x57eb04[_0x65f6('0x60')]+'%',null);}else{_0x247be3=_[_0x65f6('0x59')](_0x50494b,['name',_0x65f6('0x6a')]);_0x57eb04[_0x65f6('0x44')]=_0x65f6('0x6a');_0x4241db=as[_0x65f6('0x63')](_0x4f96c4,_0x247be3['type'],_0x57eb04);_0x1e9e29[_0x47e749](_0x4241db[_0x65f6('0x64')],_0x4241db[_0x65f6('0x60')][_0x65f6('0x6b')],_0x4241db[_0x65f6('0x60')]['end']);}break;case _0x65f6('0x6c'):_0x4241db=as[_0x65f6('0x63')]('me',null,_0x57eb04);_0x1e9e29[_0x47e749](_0x4241db['text'],_0x4241db[_0x65f6('0x60')][_0x65f6('0x6b')],_0x4241db[_0x65f6('0x60')]['end']);break;}}else{var _0x4241db=as[_0x65f6('0x63')](_0x4f96c4,_0x247be3[_0x65f6('0x34')],_0x57eb04);_0x1e9e29[_0x47e749](_0x4241db[_0x65f6('0x64')],_0x4241db[_0x65f6('0x60')][_0x65f6('0x6b')],_0x4241db['value']['end']);}}}else{var _0x59cd44=_(_0x1b24ea[_0x65f6('0x35')])[_0x65f6('0x6d')]()[_0x65f6('0x29')](function(_0x471bec){return _[_0x65f6('0x6e')](_0x50494b,[_0x65f6('0x26'),_0x471bec])?_0x471bec:undefined;})['compact']()[_0x65f6('0x60')]();if(!_[_0x65f6('0x6f')](_0x59cd44)){_0x59cd44['forEach'](function(_0x225aeb){if(_0x225aeb===_0x65f6('0x70')){_0x3386a2[_0x65f6('0x71')]('i.WhatsappAccountId\x20IN\x20?',[][_0x65f6('0x72')](_0x1b24ea[_0x65f6('0x35')][_0x225aeb]));}else if(_0x225aeb==='createdAt'){var _0x271d76=JSON[_0x65f6('0x73')](_0x1b24ea[_0x65f6('0x35')][_0x225aeb])[_0x65f6('0x74')];var _0x3d55f7=JSON[_0x65f6('0x73')](_0x1b24ea[_0x65f6('0x35')][_0x225aeb])['$lte'];_0x3386a2['where'](_0x65f6('0x75'),_0x271d76,_0x3d55f7);}else{if(_0x1b24ea[_0x65f6('0x35')][_0x225aeb]==='null'){_0x3386a2[_0x65f6('0x71')]('i.'+_0x225aeb+'\x20IS\x20NULL');}else{_0x3386a2[_0x65f6('0x71')]('i.'+_0x225aeb+'\x20=\x20?',_0x1b24ea[_0x65f6('0x35')][_0x225aeb]);}}});}if(_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x76')]){if(_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x76')]==0x1){_0x3386a2[_0x65f6('0x5b')](_0x65f6('0x77'));}else{_0x3386a2[_0x65f6('0x5b')](_0x65f6('0x78'));}}if(_0x1b24ea['query']['tag']){_0x2d6ab9=_[_0x65f6('0x79')](_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x7a')])?_0x1b24ea['query']['tag']:new Array(_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x7a')]);_0x2d6ab9[_0x65f6('0x2d')](function(_0xc703f9){_0x149c28['or'](_0x65f6('0x66'),'%,'+_0xc703f9+',%');});}if(_0x1b24ea[_0x65f6('0x35')]['filter']){var _0x4f42ae=_0x1b24ea[_0x65f6('0x35')][_0x65f6('0x7b')]['replace']('\x5c','\x5c\x5c')[_0x65f6('0x7c')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x4f42ae)){_0x1e9e29['or'](_0x65f6('0x7d'),_0x4f42ae+'%')['or'](_0x65f6('0x7e'),_0x4f42ae+'%');}else{_0x1e9e29['or'](_0x65f6('0x7f'),qs[_0x65f6('0x80')](_0x4f42ae))['or']('CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?',_0x4f42ae+'%');}}}_0x3386a2[_0x65f6('0x71')](_0x1e9e29);_0x3386a2[_0x65f6('0x81')](_0x65f6('0x82'));var _0x59131c={'type':db['Sequelize'][_0x65f6('0x83')]['SELECT'],'raw':!![]};var _0x305967=_0x3386a2[_0x65f6('0x84')]();_0x305967[_0x65f6('0x44')](_0x65f6('0x82'));_0x305967['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');if(_0x36dbf4[_0x65f6('0x40')]){_0x36dbf4[_0x65f6('0x40')][_0x65f6('0x2d')](function(_0x57464e){var _0x46cbde=_0x57464e[0x0]===_0x65f6('0x85')?_0x57464e[0x0]:'i.'+_0x57464e[0x0];_0x3386a2[_0x65f6('0x40')](_0x46cbde,_0x57464e[0x1]==='DESC'?![]:!![]);});}if(!_[_0x65f6('0x6f')](_0x2d6ab9)){_0x3386a2[_0x65f6('0x5b')](_0x149c28);_0x305967['where'](_0x65f6('0x86'),_0x2d6ab9);}BPromise[_0x65f6('0x87')]()['then'](function(){if(!_0x414f49){if(_0x1b24ea[_0x65f6('0x35')]['WhatsappAccountId'])return;_0x305967[_0x65f6('0x71')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');_0x3386a2[_0x65f6('0x71')](_0x65f6('0x88'));return;}if(_0x1b24ea['user'][_0x65f6('0x89')]!==_0x65f6('0x8a'))return;return _0x1b24ea[_0x65f6('0x8b')][_0x65f6('0x8c')]({'attributes':['id'],'raw':!![]})[_0x65f6('0x22')](function(_0x31117f){if(_[_0x65f6('0x6f')](_0x31117f)){_0x305967[_0x65f6('0x71')](_0x65f6('0x8d'));_0x3386a2[_0x65f6('0x71')](_0x65f6('0x8d'));}else{_0x305967['where'](_0x65f6('0x8e'),_[_0x65f6('0x29')](_0x31117f,'id'));_0x3386a2[_0x65f6('0x71')](_0x65f6('0x8e'),_['map'](_0x31117f,'id'));}});})[_0x65f6('0x22')](function(){if(_0x1b24ea[_0x65f6('0x8b')]['role']===_0x65f6('0x8a')&&!_0x414f49&&!_0x1b24ea['query'][_0x65f6('0x70')])return[];return db['sequelize'][_0x65f6('0x35')](_0x305967[_0x65f6('0x8f')](),_0x59131c);})['then'](function(_0x4946c7){_0x2b403b[_0x65f6('0x1d')]=_0x4946c7[_0x65f6('0x3b')];if(_0x2b403b['count']===0x0)return[];return db[_0x65f6('0x90')][_0x65f6('0x35')](_0x1ac040[_0x65f6('0x8f')](),_0x59131c)['then'](function(_0x1348ec){_0x83e2d9=_[_0x65f6('0x91')](_0x1348ec,'id');_0x59131c=_['merge'](_0x59131c,{'model':db[_0x65f6('0x32')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1b24ea['query'][_0x65f6('0x39')]){_0x36dbf4['attributes']['forEach'](function(_0x20687f){_0x3386a2[_0x65f6('0x44')]('i.'+_0x20687f);});}else{_0x3386a2[_0x65f6('0x44')](_0x65f6('0x92'),_0x65f6('0x5a'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0x93'),_0x65f6('0x94'));_0x3386a2['field']('a.mandatoryDisposition',_0x65f6('0x95'));_0x3386a2['field'](_0x65f6('0x96'),_0x65f6('0x85'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0x97'));_0x3386a2[_0x65f6('0x44')]('c.firstName',_0x65f6('0x98'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0x99'),'Contact.lastName');_0x3386a2[_0x65f6('0x44')](_0x65f6('0x9a'),_0x65f6('0x9b'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0x9c'),_0x65f6('0x9d'));_0x3386a2['field']('c.mobile',_0x65f6('0x9e'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0x9f'),_0x65f6('0xa0'));_0x3386a2['field']('o.fullname',_0x65f6('0xa1'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0xa2'),_0x65f6('0xa3'));_0x3386a2[_0x65f6('0x44')](_0x65f6('0xa4'),'TagIds');}if(_0x36dbf4['limit'])_0x3386a2['limit'](_0x36dbf4[_0x65f6('0x3e')]);if(_0x36dbf4[_0x65f6('0x3f')])_0x3386a2[_0x65f6('0x3f')](_0x36dbf4[_0x65f6('0x3f')]);return db['sequelize']['query'](_0x3386a2[_0x65f6('0x8f')](),_0x59131c);})[_0x65f6('0x22')](function(_0x56077a){_0xb1a132[_0x65f6('0x71')]('ui.WhatsappInteractionId\x20IN\x20?',_[_0x65f6('0x29')](_0x56077a,'id'));return db['sequelize'][_0x65f6('0x35')](_0xb1a132[_0x65f6('0x8f')](),_0x59131c)['then'](function(_0x33f6cb){var _0x330e18=_[_0x65f6('0xa5')](_0x33f6cb,_0x65f6('0xa6'));var _0xec6a56=[];_0x56077a[_0x65f6('0x2d')](function(_0x584ea4){_0xec6a56[_0x65f6('0x2f')](updateWhatsappInteraction(_0x584ea4,_0x83e2d9,_0x330e18));});return BPromise['all'](_0xec6a56);});});})[_0x65f6('0x22')](function(_0x56336a){_0x2b403b[_0x65f6('0xa7')]=_0x56336a;return _0x2b403b;})[_0x65f6('0x22')](respondWithFilteredResult(_0x4f3e22,_0x36dbf4))[_0x65f6('0x30')](handleError(_0x4f3e22,null));};exports[_0x65f6('0xa8')]=function(_0x535558,_0x2b6f98){var _0x35885c={'raw':![],'where':{'id':_0x535558['params']['id']}},_0x376a23={};_0x376a23['model']=_[_0x65f6('0x6d')](db[_0x65f6('0x32')]['rawAttributes']);_0x376a23[_0x65f6('0x35')]=_[_0x65f6('0x6d')](_0x535558[_0x65f6('0x35')]);_0x376a23['filters']=_[_0x65f6('0x38')](_0x376a23[_0x65f6('0x37')],_0x376a23['query']);_0x35885c[_0x65f6('0x3a')]=_[_0x65f6('0x38')](_0x376a23[_0x65f6('0x37')],qs['fields'](_0x535558[_0x65f6('0x35')][_0x65f6('0x39')]));_0x35885c[_0x65f6('0x3a')]=_0x35885c['attributes'][_0x65f6('0x3b')]?_0x35885c['attributes']:_0x376a23[_0x65f6('0x37')];if(_0x535558[_0x65f6('0x35')][_0x65f6('0xa9')]){_0x35885c[_0x65f6('0xaa')]=[{'all':!![]}];}_0x35885c=_[_0x65f6('0xab')]({},_0x35885c,_0x535558[_0x65f6('0xac')]);return db['WhatsappInteraction'][_0x65f6('0x59')](_0x35885c)[_0x65f6('0x22')](handleEntityNotFound(_0x2b6f98,null))[_0x65f6('0x22')](respondWithResult(_0x2b6f98,null))[_0x65f6('0x30')](handleError(_0x2b6f98,null));};exports[_0x65f6('0xad')]=function(_0x59407d,_0x59f421){return db['WhatsappInteraction'][_0x65f6('0xad')](_0x59407d[_0x65f6('0x6c')],{})[_0x65f6('0x22')](respondWithResult(_0x59f421,0xc9))['catch'](handleError(_0x59f421,null));};exports[_0x65f6('0x21')]=function(_0x4de6fa,_0x4b2edb){if(_0x4de6fa[_0x65f6('0x6c')]['id']){delete _0x4de6fa[_0x65f6('0x6c')]['id'];}return db['WhatsappInteraction'][_0x65f6('0x59')]({'where':{'id':_0x4de6fa[_0x65f6('0xae')]['id']}})[_0x65f6('0x22')](handleEntityNotFound(_0x4b2edb,null))[_0x65f6('0x22')](saveUpdates(_0x4de6fa[_0x65f6('0x6c')],null))[_0x65f6('0x22')](respondWithResult(_0x4b2edb,null))[_0x65f6('0x30')](handleError(_0x4b2edb,null));};exports[_0x65f6('0x23')]=function(_0x477f29,_0x350641){return db[_0x65f6('0x32')][_0x65f6('0x59')]({'where':{'id':_0x477f29['params']['id']}})[_0x65f6('0x22')](handleEntityNotFound(_0x350641,null))['then'](removeEntity(_0x350641,null))['catch'](handleError(_0x350641,null));};exports[_0x65f6('0xaf')]=function(_0x10a877,_0xdcfe8){return db[_0x65f6('0x32')]['describe']()[_0x65f6('0x22')](respondWithResult(_0xdcfe8,null))['catch'](handleError(_0xdcfe8,null));};exports['addMessage']=function(_0x416ed4,_0x99fe6e,_0x1a7e52){return db[_0x65f6('0xb0')][_0x65f6('0x59')]({'where':{'id':_0x416ed4[_0x65f6('0xae')]['id']}})['then'](handleEntityNotFound(_0x99fe6e,null))[_0x65f6('0x22')](function(_0x56bf49){if(_0x56bf49){return _0x56bf49[_0x65f6('0xb1')](_0x416ed4[_0x65f6('0x6c')][_0x65f6('0xb2')],_['omit'](_0x416ed4[_0x65f6('0x6c')],['ids','id'])||{});}})['then'](respondWithResult(_0x99fe6e,null))[_0x65f6('0x30')](handleError(_0x99fe6e,null));};exports[_0x65f6('0xb3')]=function(_0x2dbed5,_0xf364a9,_0x3b8dd5){var _0x5adf21={'raw':![],'where':{}};var _0x439af3={};var _0x400633={'count':0x0,'rows':[]};return db[_0x65f6('0x32')][_0x65f6('0xb4')]({'where':{'id':_0x2dbed5['params']['id']}})[_0x65f6('0x22')](handleEntityNotFound(_0xf364a9,null))[_0x65f6('0x22')](function(_0x344163){if(_0x344163){_0x439af3[_0x65f6('0x37')]=_[_0x65f6('0x6d')](db[_0x65f6('0xb0')][_0x65f6('0xb5')]);_0x439af3[_0x65f6('0x35')]=_['keys'](_0x2dbed5[_0x65f6('0x35')]);_0x439af3[_0x65f6('0x36')]=_[_0x65f6('0x38')](_0x439af3[_0x65f6('0x37')],_0x439af3[_0x65f6('0x35')]);_0x5adf21[_0x65f6('0x3a')]=_['intersection'](_0x439af3[_0x65f6('0x37')],qs[_0x65f6('0x39')](_0x2dbed5['query'][_0x65f6('0x39')]));_0x5adf21['attributes']=_0x5adf21[_0x65f6('0x3a')][_0x65f6('0x3b')]?_0x5adf21[_0x65f6('0x3a')]:_0x439af3[_0x65f6('0x37')];if(!_0x2dbed5[_0x65f6('0x35')]['hasOwnProperty'](_0x65f6('0x3d'))){_0x5adf21[_0x65f6('0x3e')]=qs[_0x65f6('0x3e')](_0x2dbed5[_0x65f6('0x35')][_0x65f6('0x3e')]);_0x5adf21['offset']=qs['offset'](_0x2dbed5[_0x65f6('0x35')][_0x65f6('0x3f')]);}_0x5adf21[_0x65f6('0x40')]=qs[_0x65f6('0x41')](_0x2dbed5['query']['sort']);_0x5adf21['where']=qs[_0x65f6('0x36')](_[_0x65f6('0x42')](_0x2dbed5[_0x65f6('0x35')],_0x439af3['filters']));_0x5adf21[_0x65f6('0x71')][_0x65f6('0xa6')]=_0x344163['id'];if(_0x2dbed5[_0x65f6('0x35')][_0x65f6('0x7b')]){_0x5adf21[_0x65f6('0x71')]=_['merge'](_0x5adf21[_0x65f6('0x71')],{'$or':_[_0x65f6('0x29')](_0x5adf21['attributes'],function(_0x5aaa94){var _0x30b766={};_0x30b766[_0x5aaa94]={'$like':'%'+_0x2dbed5[_0x65f6('0x35')][_0x65f6('0x7b')]+'%'};return _0x30b766;})});}if(_0x2dbed5[_0x65f6('0x35')][_0x65f6('0x74')]){var _0x57dffb=_0x2dbed5[_0x65f6('0x35')]['$gte'][_0x65f6('0x2c')](',');var _0x5d181a={};_0x5d181a[_0x57dffb[0x0]]={'$gte':moment(_0x57dffb[0x1])[_0x65f6('0xb6')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5adf21[_0x65f6('0x71')]=_['merge'](_0x5adf21[_0x65f6('0x71')],_0x5d181a);}_0x5adf21=_[_0x65f6('0xab')]({},_0x5adf21,_0x2dbed5['options']);return db['WhatsappMessage'][_0x65f6('0x1d')]({'where':_0x5adf21[_0x65f6('0x71')]})[_0x65f6('0x22')](function(_0xcc2932){_0x400633[_0x65f6('0x1d')]=_0xcc2932;if(_0x2dbed5[_0x65f6('0x35')][_0x65f6('0xa9')]){_0x5adf21[_0x65f6('0xaa')]=[{'all':!![]}];}return db[_0x65f6('0xb0')][_0x65f6('0xb7')](_0x5adf21);})[_0x65f6('0x22')](function(_0x6babec){_0x400633[_0x65f6('0xa7')]=_0x6babec;return _0x400633;});}})[_0x65f6('0x22')](respondWithFilteredResult(_0xf364a9,_0x5adf21))[_0x65f6('0x30')](handleError(_0xf364a9,null));};exports[_0x65f6('0xb8')]=function(_0x1afc18,_0x5efe82,_0x557cbf){return db[_0x65f6('0x32')][_0x65f6('0x59')]({'where':{'id':_0x1afc18[_0x65f6('0xae')]['id']}})[_0x65f6('0x22')](handleEntityNotFound(_0x5efe82,null))[_0x65f6('0x22')](function(_0x849936){if(_0x849936){return _0x849936[_0x65f6('0xb9')](_0x1afc18[_0x65f6('0x6c')]['ids'],_[_0x65f6('0xba')](_0x1afc18[_0x65f6('0x6c')],[_0x65f6('0xb2'),'id'])||{})[_0x65f6('0xbb')](function(){return db['Tag'][_0x65f6('0xb7')]({'attributes':['id',_0x65f6('0x26'),'color'],'where':{'id':_0x1afc18[_0x65f6('0x6c')][_0x65f6('0xb2')]}});})[_0x65f6('0x22')](function(_0x207831){socket[_0x65f6('0xbc')](_0x65f6('0xbd'),{'id':Number(_0x1afc18['params']['id']),'tags':_0x207831||[]});return{'id':Number(_0x1afc18[_0x65f6('0xae')]['id']),'tags':_0x207831||[]};});}})[_0x65f6('0x22')](respondWithResult(_0x5efe82,null))[_0x65f6('0x30')](handleError(_0x5efe82,null));};exports[_0x65f6('0xbe')]=function(_0x5e77ba,_0x510277,_0x5d710b){return db[_0x65f6('0x32')][_0x65f6('0x59')]({'where':{'id':_0x5e77ba[_0x65f6('0xae')]['id']}})[_0x65f6('0x22')](handleEntityNotFound(_0x510277,null))[_0x65f6('0x22')](function(_0x5515a4){if(_0x5515a4){return _0x5515a4['removeTags'](_0x5e77ba[_0x65f6('0x35')][_0x65f6('0xb2')]);}})[_0x65f6('0x22')](respondWithStatusCode(_0x510277,null))['catch'](handleError(_0x510277,null));};exports['download']=function(_0x11f300,_0x4e819f){var _0x10a218=moment()[_0x65f6('0xbf')]()[_0x65f6('0x8f')]();var _0x17d9cc=path[_0x65f6('0xc0')](config[_0x65f6('0xc1')],_0x65f6('0xc2'),_0x65f6('0xc3'),_0x65f6('0xc4'));var _0x4cdc4c=path[_0x65f6('0xc0')](config[_0x65f6('0xc1')],'server',_0x65f6('0xc3'),'attachments');var _0x27afb5=path[_0x65f6('0xc0')](_0x17d9cc,_0x10a218);var _0x2149e1=util['format'](_0x65f6('0xc5'),_0x11f300['params']['id'],_0x10a218);var _0x568ca5=path[_0x65f6('0xc0')](_0x17d9cc,_0x2149e1);var _0x42dd14=[];_0x42dd14['push']({'model':db[_0x65f6('0x68')],'as':'User','attributes':['id',_0x65f6('0x2a')],'raw':!![]});_0x42dd14[_0x65f6('0x2f')]({'model':db[_0x65f6('0xc6')],'as':_0x65f6('0x5d'),'attributes':['id',_0x65f6('0xc7'),_0x65f6('0xc8')],'raw':!![]});if(_0x11f300[_0x65f6('0x35')][_0x65f6('0xc9')]){_0x42dd14['push']({'model':db[_0x65f6('0xca')],'as':_0x65f6('0xca'),'raw':!![]});}var _0x4723e9=[{'model':db[_0x65f6('0xb0')],'as':_0x65f6('0xcb'),'attributes':['id','body',_0x65f6('0xcc'),'direction',_0x65f6('0xcd'),'read'],'include':_0x42dd14}];_0x4723e9[_0x65f6('0x2f')]({'model':db[_0x65f6('0xce')],'as':_0x65f6('0xcf'),'attributes':['id',_0x65f6('0x26')]});_0x4723e9[_0x65f6('0x2f')]({'model':db[_0x65f6('0x68')],'as':_0x65f6('0xd0'),'attributes':['id',_0x65f6('0x2a')]});return db[_0x65f6('0x32')][_0x65f6('0x59')]({'where':{'id':_0x11f300[_0x65f6('0xae')]['id']},'include':_0x4723e9})[_0x65f6('0x22')](handleEntityNotFound(_0x4e819f,null))[_0x65f6('0x22')](function(_0x1c4172){if(_0x1c4172){var _0x37fa08=_0x1c4172[_0x65f6('0xd1')]({'plain':!![]});fs[_0x65f6('0xd2')](_0x27afb5);var _0x5da2f8={'format':'A4','border':_0x65f6('0xd3'),'header':{'height':'40px','contents':{'first':_0x65f6('0xd4')}},'footer':{'height':_0x65f6('0xd5'),'contents':{'default':util[_0x65f6('0xb6')](_0x65f6('0xd6'),util[_0x65f6('0xb6')](_0x65f6('0xd7'),'Whatsapp',_0x37fa08['id']),moment()[_0x65f6('0xb6')](_0x65f6('0xd8'))[_0x65f6('0x8f')]())}}};var _0x359734={'channel':_0x65f6('0xd9'),'account':_0x37fa08[_0x65f6('0xcf')][_0x65f6('0x26')],'agent':_0x37fa08[_0x65f6('0xd0')]?_0x37fa08[_0x65f6('0xd0')][_0x65f6('0x2a')]:_0x65f6('0xda'),'createdAt':moment(_0x37fa08['createdAt'])['format'](_0x65f6('0xdb'))[_0x65f6('0x8f')](),'closedAt':_0x37fa08[_0x65f6('0xdc')]?moment(_0x37fa08[_0x65f6('0xdd')])[_0x65f6('0xb6')](_0x65f6('0xdb'))[_0x65f6('0x8f')]():'','disposition':_0x37fa08['disposition'],'messages':_(_0x37fa08[_0x65f6('0xcb')])[_0x65f6('0x7b')]({'secret':![]})[_0x65f6('0x29')](function(_0xa68327){if(_0xa68327[_0x65f6('0xca')]){var _0x129f29=path[_0x65f6('0xc0')](_0x4cdc4c,_0xa68327[_0x65f6('0xca')][_0x65f6('0xde')]);if(fs[_0x65f6('0xdf')](_0x129f29)){fs[_0x65f6('0xe0')](_0x129f29)[_0x65f6('0xe1')](fs[_0x65f6('0xe2')](path['join'](_0x27afb5,_0xa68327['Attachment']['basename'])));}}return{'date':moment(_0xa68327[_0x65f6('0xcc')])[_0x65f6('0xb6')](_0x65f6('0xdb'))['toString'](),'sender':_0xa68327[_0x65f6('0xe3')]===_0x65f6('0xe4')?_0xa68327[_0x65f6('0x68')]?_0xa68327['User'][_0x65f6('0x2a')]:_0x65f6('0xe5'):_0xa68327['Contact'][_0x65f6('0xc7')]+(_0xa68327[_0x65f6('0x5d')][_0x65f6('0xc8')]?'\x20'+_0xa68327['Contact'][_0x65f6('0xc8')]:''),'body':_0xa68327[_0x65f6('0xca')]?_0xa68327[_0x65f6('0xca')][_0x65f6('0xde')]:_0xa68327[_0x65f6('0x6c')],'direction':_0xa68327[_0x65f6('0xe3')]===_0x65f6('0xe4')?'A':'C','secret':_0xa68327[_0x65f6('0xcd')],'read':_0xa68327[_0x65f6('0x76')],'attachment':_0xa68327[_0x65f6('0xca')]};})['value']()};return ejs[_0x65f6('0xe6')](path[_0x65f6('0xc0')](config[_0x65f6('0xc1')],'server','views',_0x65f6('0xe7')),{'interaction':_0x359734})['then'](function(_0x3f5cf8){return new BPromise(function(_0x3e8f5f,_0x272652){pdf[_0x65f6('0xad')](_0x3f5cf8,_0x5da2f8)[_0x65f6('0xe8')](path['join'](_0x27afb5,_0x65f6('0xe9')+_0x37fa08['id']+'-'+_0x10a218+_0x65f6('0xea')),function(_0x207187,_0x118502){if(_0x207187)return _0x272652(_0x207187);_0x3e8f5f(_0x118502);});});})['then'](function(){return new BPromise(function(_0x375351,_0x45709b){zipdir(_0x27afb5,{'saveTo':_0x568ca5},function(_0x11d3fb,_0x19232e){if(_0x11d3fb)return _0x45709b(_0x11d3fb);return _0x375351(_0x19232e);});})[_0x65f6('0x22')](function(){return new BPromise(function(_0x25e34a,_0xcef4ba){rimraf(_0x27afb5,function(_0x2d9adc){if(_0x2d9adc)_0xcef4ba(_0x2d9adc);return _0x25e34a();});});})[_0x65f6('0x22')](function(){return _0x4e819f[_0x65f6('0xeb')](_0x568ca5,_0x2149e1,function(_0x418778){if(_0x418778){console[_0x65f6('0xec')](_0x65f6('0xed'),_0x418778);}else{fs[_0x65f6('0xee')](_0x568ca5);}});});});}else{return _0x4e819f[_0x65f6('0x19')](0xc8);}})['catch'](handleError(_0x4e819f,null));};
\ No newline at end of file
+var _0x6cc9=['Tags','push','catch','index','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','sort','pick','select','field','color','from','u.id','u.fullname','ui.WhatsappInteractionId','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','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','conditions','length','find','unreadMessages','value','having','`\x20>\x200','Contact','$substring','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','start','Tag','User','operator','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','text','end','body','isEmpty','where','concat','createdAt','$gte','parse','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','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?','i.id','QueryTypes','SELECT','clone','order','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','role','sequelize','toString','keyBy','merge','WhatsappInteraction','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','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.*','Contact.firstName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.fax','o.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','rows','params','includeAll','include','create','describe','addMessage','ids','omit','getMessages','findOne','WhatsappMessage','hasOwnProperty','filter','format','options','findAll','addTags','setTags','emit','whatsappInteractionTags:save','removeTags','unix','join','root','server','attachments','transcript-%d-%s.zip','CmContact','firstName','lastName','Attachment','Messages','direction','secret','WhatsappAccount','Account','get','mkdirSync','Whatsapp','Owner','N.A.','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','basename','createReadStream','pipe','createWriteStream','out','renderFile','views','transcript-','.pdf','createPdfFromHTML','download','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','socket.io-emitter','register','sendStatus','status','json','count','offset','set','Content-Range','reject','save','update','then','destroy','error','stack','name','send','Users','map','fullname','TagIds','split','forEach'];(function(_0x1e51fe,_0x1543e4){var _0x9b8c5f=function(_0x341add){while(--_0x341add){_0x1e51fe['push'](_0x1e51fe['shift']());}};_0x9b8c5f(++_0x1543e4);}(_0x6cc9,0xb9));var _0x96cc=function(_0x5cd463,_0x1f6022){_0x5cd463=_0x5cd463-0x0;var _0x1c1a64=_0x6cc9[_0x5cd463];return _0x1c1a64;};'use strict';var emlformat=require(_0x96cc('0x0'));var rimraf=require(_0x96cc('0x1'));var zipdir=require(_0x96cc('0x2'));var jsonpatch=require(_0x96cc('0x3'));var rp=require('request-promise');var moment=require(_0x96cc('0x4'));var BPromise=require(_0x96cc('0x5'));var Mustache=require('mustache');var util=require(_0x96cc('0x6'));var path=require(_0x96cc('0x7'));var sox=require(_0x96cc('0x8'));var csv=require(_0x96cc('0x9'));var ejs=require(_0x96cc('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x96cc('0xb'));var crypto=require('crypto');var jsforce=require(_0x96cc('0xc'));var deskjs=require(_0x96cc('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x96cc('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x96cc('0xf'));var as=require(_0x96cc('0x10'));var pdf=require('../../components/export/pdf');var hardwareService=require('../../config/license/hardware');var logger=require(_0x96cc('0x11'))(_0x96cc('0x12'));var utils=require(_0x96cc('0x13'));var config=require(_0x96cc('0x14'));var licenseUtil=require(_0x96cc('0x15'));var db=require('../../mysqldb')['db'];config[_0x96cc('0x16')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x96cc('0x17'))(new Redis(config[_0x96cc('0x16')]));require('./whatsappInteraction.socket')[_0x96cc('0x18')](socket);function respondWithStatusCode(_0x2f2ad0,_0x25e949){_0x25e949=_0x25e949||0xcc;return function(_0x138348){if(_0x138348){return _0x2f2ad0[_0x96cc('0x19')](_0x25e949);}return _0x2f2ad0[_0x96cc('0x1a')](_0x25e949)['end']();};}function respondWithResult(_0x1e7ba8,_0x1904e0){_0x1904e0=_0x1904e0||0xc8;return function(_0x4b1a36){if(_0x4b1a36){return _0x1e7ba8[_0x96cc('0x1a')](_0x1904e0)[_0x96cc('0x1b')](_0x4b1a36);}};}function respondWithFilteredResult(_0x59b68f,_0x377fa9){return function(_0x1f9107){if(_0x1f9107){var _0x42c3e3=_0x1f9107[_0x96cc('0x1c')],_0x118b9b=_0x377fa9[_0x96cc('0x1d')],_0x4611ba=_0x377fa9[_0x96cc('0x1d')]+_0x377fa9['limit'],_0xb48084;if(_0x4611ba>=_0x42c3e3){_0x4611ba=_0x42c3e3;_0xb48084=0xc8;}else{_0xb48084=0xce;}_0x59b68f[_0x96cc('0x1a')](_0xb48084);return _0x59b68f[_0x96cc('0x1e')](_0x96cc('0x1f'),_0x118b9b+'-'+_0x4611ba+'/'+_0x42c3e3)[_0x96cc('0x1b')](_0x1f9107);}return null;};}function patchUpdates(_0x409e75){return function(_0x57f9e8){try{jsonpatch['apply'](_0x57f9e8,_0x409e75,!![]);}catch(_0x379bbb){return BPromise[_0x96cc('0x20')](_0x379bbb);}return _0x57f9e8[_0x96cc('0x21')]();};}function saveUpdates(_0x531e46,_0x36162b){return function(_0x3f15d7){if(_0x3f15d7){return _0x3f15d7[_0x96cc('0x22')](_0x531e46)[_0x96cc('0x23')](function(_0x331aa6){return _0x331aa6;});}return null;};}function removeEntity(_0x166eff,_0xcb396d){return function(_0x17afb1){if(_0x17afb1){return _0x17afb1[_0x96cc('0x24')]()[_0x96cc('0x23')](function(){_0x166eff[_0x96cc('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x48dbab,_0x24638a){return function(_0x1e3dd1){if(!_0x1e3dd1){_0x48dbab[_0x96cc('0x19')](0x194);}return _0x1e3dd1;};}function handleError(_0x99ce9f,_0x24e585){_0x24e585=_0x24e585||0x1f4;return function(_0x440953){logger[_0x96cc('0x25')](_0x440953[_0x96cc('0x26')]);if(_0x440953['name']){delete _0x440953[_0x96cc('0x27')];}_0x99ce9f[_0x96cc('0x1a')](_0x24e585)[_0x96cc('0x28')](_0x440953);};}function getInteractionUsers(_0x5c016a,_0x47e072){return new BPromise(function(_0x1377a0,_0x2544a1){try{if(_0x47e072[_0x5c016a['id']]){_0x5c016a[_0x96cc('0x29')]=_[_0x96cc('0x2a')](_0x47e072[_0x5c016a['id']],function(_0xbd2185){return{'id':_0xbd2185['id'],'fullname':_0xbd2185[_0x96cc('0x2b')]};});}}catch(_0x2ef38d){_0x2544a1(_0x2ef38d);}_0x1377a0(_0x5c016a);});}function getInteractionTags(_0x120587,_0x36862a){return new BPromise(function(_0x25bad1,_0x1c9f93){try{if(_0x120587[_0x96cc('0x2c')]){_0x120587['Tags']=[];_0x120587[_0x96cc('0x2c')][_0x96cc('0x2d')](',')[_0x96cc('0x2e')](function(_0x565a5a){_0x120587[_0x96cc('0x2f')][_0x96cc('0x30')](_0x36862a[_0x565a5a]);});}delete _0x120587[_0x96cc('0x2c')];}catch(_0x2de907){_0x1c9f93(_0x2de907);}_0x25bad1(_0x120587);});}function updateWhatsappInteraction(_0x2aec1a,_0x29cfee,_0x2f074e){return new BPromise(function(_0x10fa7e,_0xdff78d){return getInteractionUsers(_0x2aec1a,_0x2f074e)[_0x96cc('0x23')](function(_0x3c4f2f){return getInteractionTags(_0x3c4f2f,_0x29cfee);})[_0x96cc('0x23')](function(_0x44f876){_0x10fa7e(_0x44f876);})[_0x96cc('0x31')](function(_0x362f50){_0xdff78d(_0x362f50);});});}exports[_0x96cc('0x32')]=function(_0x36e7db,_0x36c04e){var _0x22538c={},_0x50f9fa={},_0x30e93f={'count':0x0,'rows':[]};var _0x4e351a=_[_0x96cc('0x2a')](db['WhatsappInteraction'][_0x96cc('0x33')],function(_0x2858e7){return{'name':_0x2858e7[_0x96cc('0x34')],'type':_0x2858e7[_0x96cc('0x35')]['key']};});_0x50f9fa[_0x96cc('0x36')]=_[_0x96cc('0x2a')](_0x4e351a,_0x96cc('0x27'));_0x50f9fa[_0x96cc('0x37')]=_[_0x96cc('0x38')](_0x36e7db[_0x96cc('0x37')]);_0x50f9fa[_0x96cc('0x39')]=_[_0x96cc('0x3a')](_0x50f9fa[_0x96cc('0x36')],_0x50f9fa[_0x96cc('0x37')]);_0x22538c[_0x96cc('0x3b')]=_[_0x96cc('0x3a')](_0x50f9fa['model'],qs[_0x96cc('0x3c')](_0x36e7db[_0x96cc('0x37')][_0x96cc('0x3c')]));_0x22538c[_0x96cc('0x3b')]=_0x22538c['attributes']['length']?_0x22538c[_0x96cc('0x3b')]:_0x50f9fa['model'];if(!_0x36e7db[_0x96cc('0x37')]['hasOwnProperty'](_0x96cc('0x3d'))){_0x22538c['limit']=qs[_0x96cc('0x3e')](_0x36e7db['query']['limit']);_0x22538c[_0x96cc('0x1d')]=qs[_0x96cc('0x1d')](_0x36e7db[_0x96cc('0x37')][_0x96cc('0x1d')]);}_0x22538c['order']=qs['sort'](_0x36e7db[_0x96cc('0x37')][_0x96cc('0x3f')]);_0x22538c['where']=qs[_0x96cc('0x39')](_[_0x96cc('0x40')](_0x36e7db['query'],_0x50f9fa[_0x96cc('0x39')]),_0x4e351a);var _0x4b5ffb=[];var _0x223f7f=squel[_0x96cc('0x41')]()['field']('id')[_0x96cc('0x42')](_0x96cc('0x27'))['field'](_0x96cc('0x43'))[_0x96cc('0x44')]('tools_tags');var _0x49297a=squel[_0x96cc('0x41')]()[_0x96cc('0x42')](_0x96cc('0x45'))[_0x96cc('0x42')](_0x96cc('0x46'))[_0x96cc('0x42')](_0x96cc('0x47'))[_0x96cc('0x44')]('user_has_whatsapp_interactions','ui')[_0x96cc('0x48')](_0x96cc('0x49'),'u',_0x96cc('0x4a'));var _0x148456=squel[_0x96cc('0x41')]()[_0x96cc('0x44')]('whatsapp_interactions','i')[_0x96cc('0x48')](_0x96cc('0x4b'),'c',_0x96cc('0x4c'))[_0x96cc('0x48')](_0x96cc('0x49'),'o',_0x96cc('0x4d'))[_0x96cc('0x48')](_0x96cc('0x4e'),'a',_0x96cc('0x4f'))[_0x96cc('0x48')](_0x96cc('0x50'),'me',_0x96cc('0x51'))[_0x96cc('0x48')](_0x96cc('0x52'),'it',_0x96cc('0x53'))[_0x96cc('0x48')](_0x96cc('0x54'),'t',_0x96cc('0x55'));var _0xf222ba=squel[_0x96cc('0x56')]();var _0x4d6ed1=[];var _0x4614a5=squel[_0x96cc('0x56')]();var _0x3d5055;if(_0x36e7db[_0x96cc('0x37')][_0x96cc('0x57')]){_0x3d5055=as[_0x96cc('0x58')](_0x36e7db[_0x96cc('0x37')][_0x96cc('0x57')]);var _0x21323b=_0x3d5055[_0x96cc('0x59')];for(var _0x5c0227=0x0;_0x5c0227<_0x3d5055[_0x96cc('0x5a')][_0x96cc('0x5b')];_0x5c0227++){var _0x5a2d82=_0x3d5055['conditions'][_0x5c0227];var _0x11788d='i';var _0x27df02=_[_0x96cc('0x5c')](_0x4e351a,[_0x96cc('0x27'),_0x5a2d82['field']]);if(!_0x27df02){switch(_0x5a2d82[_0x96cc('0x42')]){case _0x96cc('0x5d'):if(_0x5a2d82[_0x96cc('0x5e')]==0x1){_0x148456[_0x96cc('0x5f')]('`'+_0x5a2d82[_0x96cc('0x42')]+'`\x20=\x200');}else{_0x148456[_0x96cc('0x5f')]('`'+_0x5a2d82[_0x96cc('0x42')]+_0x96cc('0x60'));}break;case _0x96cc('0x61'):if(_0x5a2d82['operator']===_0x96cc('0x62')){if(_0x5a2d82['value'][_0x96cc('0x2d')]('\x20')[_0x96cc('0x5b')]>0x1){_0xf222ba[_0x21323b]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x96cc('0x63')](_0x5a2d82['value']),null);}else{var _0x3b2a45='%'+_0x5a2d82[_0x96cc('0x5e')]+'%';_0xf222ba[_0x21323b](_0x96cc('0x64'),_0x3b2a45,_0x3b2a45,_0x3b2a45);}}else{_0x27df02=_[_0x96cc('0x5c')](_0x4e351a,[_0x96cc('0x27'),_0x96cc('0x65')]);_0x5a2d82[_0x96cc('0x42')]='ContactId';_0x555bc0=as['buildExpression'](_0x11788d,_0x27df02[_0x96cc('0x35')],_0x5a2d82);_0xf222ba[_0x21323b](_0x555bc0['text'],_0x555bc0['value'][_0x96cc('0x66')],_0x555bc0[_0x96cc('0x5e')]['end']);}break;case _0x96cc('0x67'):var _0x28dd5b=_0x5a2d82[_0x96cc('0x5e')][_0x96cc('0x2d')](',')['map'](function(_0x3a5901){return Number(_0x3a5901);});_0x28dd5b['forEach'](function(_0x22bc46){_0x4614a5['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x22bc46+',%');});_0x4d6ed1=_['union'](_0x4d6ed1,_0x28dd5b);break;case _0x96cc('0x68'):if(_0x5a2d82[_0x96cc('0x69')]===_0x96cc('0x62')){_0xf222ba[_0x21323b](_0x96cc('0x6a'),'%'+_0x5a2d82['value']+'%',null);}else{_0x27df02=_[_0x96cc('0x5c')](_0x4e351a,[_0x96cc('0x27'),_0x96cc('0x6b')]);_0x5a2d82[_0x96cc('0x42')]='UserId';_0x555bc0=as[_0x96cc('0x6c')](_0x11788d,_0x27df02['type'],_0x5a2d82);_0xf222ba[_0x21323b](_0x555bc0[_0x96cc('0x6d')],_0x555bc0['value'][_0x96cc('0x66')],_0x555bc0['value'][_0x96cc('0x6e')]);}break;case _0x96cc('0x6f'):_0x555bc0=as[_0x96cc('0x6c')]('me',null,_0x5a2d82);_0xf222ba[_0x21323b](_0x555bc0[_0x96cc('0x6d')],_0x555bc0['value'][_0x96cc('0x66')],_0x555bc0[_0x96cc('0x5e')][_0x96cc('0x6e')]);break;}}else{var _0x555bc0=as['buildExpression'](_0x11788d,_0x27df02[_0x96cc('0x35')],_0x5a2d82);_0xf222ba[_0x21323b](_0x555bc0['text'],_0x555bc0[_0x96cc('0x5e')][_0x96cc('0x66')],_0x555bc0['value'][_0x96cc('0x6e')]);}}}else{var _0xd7c17c=_(_0x36e7db['query'])[_0x96cc('0x38')]()[_0x96cc('0x2a')](function(_0x45fde7){return _['some'](_0x4e351a,[_0x96cc('0x27'),_0x45fde7])?_0x45fde7:undefined;})['compact']()['value']();if(!_[_0x96cc('0x70')](_0xd7c17c)){_0xd7c17c['forEach'](function(_0x13287d){if(_0x13287d==='WhatsappAccountId'){_0x148456[_0x96cc('0x71')]('i.WhatsappAccountId\x20IN\x20?',[][_0x96cc('0x72')](_0x36e7db[_0x96cc('0x37')][_0x13287d]));}else if(_0x13287d===_0x96cc('0x73')){var _0x318c2b=JSON['parse'](_0x36e7db[_0x96cc('0x37')][_0x13287d])[_0x96cc('0x74')];var _0x3527bf=JSON[_0x96cc('0x75')](_0x36e7db['query'][_0x13287d])['$lte'];_0x148456[_0x96cc('0x71')](_0x96cc('0x76'),_0x318c2b,_0x3527bf);}else{if(_0x36e7db[_0x96cc('0x37')][_0x13287d]===_0x96cc('0x77')){_0x148456[_0x96cc('0x71')]('i.'+_0x13287d+_0x96cc('0x78'));}else{_0x148456[_0x96cc('0x71')]('i.'+_0x13287d+'\x20=\x20?',_0x36e7db['query'][_0x13287d]);}}});}if(_0x36e7db[_0x96cc('0x37')][_0x96cc('0x79')]){if(_0x36e7db['query'][_0x96cc('0x79')]==0x1){_0x148456[_0x96cc('0x5f')](_0x96cc('0x7a'));}else{_0x148456['having'](_0x96cc('0x7b'));}}if(_0x36e7db[_0x96cc('0x37')][_0x96cc('0x7c')]){_0x4d6ed1=_[_0x96cc('0x7d')](_0x36e7db[_0x96cc('0x37')][_0x96cc('0x7c')])?_0x36e7db[_0x96cc('0x37')][_0x96cc('0x7c')]:new Array(_0x36e7db[_0x96cc('0x37')]['tag']);_0x4d6ed1[_0x96cc('0x2e')](function(_0x5b32ab){_0x4614a5['or'](_0x96cc('0x7e'),'%,'+_0x5b32ab+',%');});}if(_0x36e7db[_0x96cc('0x37')]['filter']){var _0x1f7e32=_0x36e7db['query']['filter'][_0x96cc('0x7f')]('\x5c','\x5c\x5c')[_0x96cc('0x7f')](/'/g,'\x27\x27');if(qs[_0x96cc('0x80')](_0x1f7e32)){_0xf222ba['or'](_0x96cc('0x81'),_0x1f7e32+'%')['or'](_0x96cc('0x82'),_0x1f7e32+'%');}else{_0xf222ba['or'](_0x96cc('0x83'),qs[_0x96cc('0x63')](_0x1f7e32))['or'](_0x96cc('0x84'),_0x1f7e32+'%');}}}_0x148456[_0x96cc('0x71')](_0xf222ba);_0x148456['group'](_0x96cc('0x85'));var _0x48aeea={'type':db['Sequelize'][_0x96cc('0x86')][_0x96cc('0x87')],'raw':!![]};var _0x34f4ef=_0x148456[_0x96cc('0x88')]();_0x34f4ef[_0x96cc('0x42')](_0x96cc('0x85'));_0x34f4ef['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');if(_0x22538c[_0x96cc('0x89')]){_0x22538c[_0x96cc('0x89')]['forEach'](function(_0x52033b){var _0x11c465=_0x52033b[0x0]===_0x96cc('0x8a')?_0x52033b[0x0]:'i.'+_0x52033b[0x0];_0x148456[_0x96cc('0x89')](_0x11c465,_0x52033b[0x1]===_0x96cc('0x8b')?![]:!![]);});}if(!_[_0x96cc('0x70')](_0x4d6ed1)){_0x148456['having'](_0x4614a5);_0x34f4ef[_0x96cc('0x71')](_0x96cc('0x8c'),_0x4d6ed1);}BPromise[_0x96cc('0x8d')]()[_0x96cc('0x23')](function(){if(!_0x3d5055){if(_0x36e7db[_0x96cc('0x37')][_0x96cc('0x8e')])return;_0x34f4ef[_0x96cc('0x71')](_0x96cc('0x8f'));_0x148456[_0x96cc('0x71')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x36e7db[_0x96cc('0x90')]['role']!==_0x96cc('0x91'))return;return _0x36e7db[_0x96cc('0x90')][_0x96cc('0x92')]({'attributes':['id'],'raw':!![]})[_0x96cc('0x23')](function(_0x28256b){if(_[_0x96cc('0x70')](_0x28256b)){_0x34f4ef[_0x96cc('0x71')](_0x96cc('0x93'));_0x148456[_0x96cc('0x71')](_0x96cc('0x93'));}else{_0x34f4ef[_0x96cc('0x71')](_0x96cc('0x94'),_[_0x96cc('0x2a')](_0x28256b,'id'));_0x148456[_0x96cc('0x71')](_0x96cc('0x94'),_[_0x96cc('0x2a')](_0x28256b,'id'));}});})[_0x96cc('0x23')](function(){if(_0x36e7db[_0x96cc('0x90')][_0x96cc('0x95')]===_0x96cc('0x91')&&!_0x3d5055&&!_0x36e7db[_0x96cc('0x37')][_0x96cc('0x8e')])return[];return db[_0x96cc('0x96')][_0x96cc('0x37')](_0x34f4ef[_0x96cc('0x97')](),_0x48aeea);})['then'](function(_0x3c5be1){_0x30e93f[_0x96cc('0x1c')]=_0x3c5be1[_0x96cc('0x5b')];if(_0x30e93f['count']===0x0)return[];return db['sequelize']['query'](_0x223f7f[_0x96cc('0x97')](),_0x48aeea)[_0x96cc('0x23')](function(_0x6f39ec){_0x4b5ffb=_[_0x96cc('0x98')](_0x6f39ec,'id');_0x48aeea=_[_0x96cc('0x99')](_0x48aeea,{'model':db[_0x96cc('0x9a')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x36e7db['query'][_0x96cc('0x3c')]){_0x22538c[_0x96cc('0x3b')]['forEach'](function(_0x3034c1){_0x148456['field']('i.'+_0x3034c1);});}else{_0x148456[_0x96cc('0x42')](_0x96cc('0x9b'),_0x96cc('0x5d'));_0x148456[_0x96cc('0x42')](_0x96cc('0x9c'),'Account.key');_0x148456[_0x96cc('0x42')]('a.mandatoryDisposition','Account.mandatoryDisposition');_0x148456[_0x96cc('0x42')](_0x96cc('0x9d'),_0x96cc('0x8a'));_0x148456[_0x96cc('0x42')](_0x96cc('0x9e'));_0x148456[_0x96cc('0x42')]('c.firstName',_0x96cc('0x9f'));_0x148456['field']('c.lastName',_0x96cc('0xa0'));_0x148456[_0x96cc('0x42')](_0x96cc('0xa1'),_0x96cc('0xa2'));_0x148456[_0x96cc('0x42')](_0x96cc('0xa3'),_0x96cc('0xa4'));_0x148456[_0x96cc('0x42')]('c.mobile','Contact.mobile');_0x148456[_0x96cc('0x42')](_0x96cc('0xa5'),'Contact.fax');_0x148456[_0x96cc('0x42')](_0x96cc('0xa6'),'Owner.fullname');_0x148456['field'](_0x96cc('0xa7'),_0x96cc('0xa8'));_0x148456[_0x96cc('0x42')](_0x96cc('0xa9'),'TagIds');}if(_0x22538c[_0x96cc('0x3e')])_0x148456[_0x96cc('0x3e')](_0x22538c[_0x96cc('0x3e')]);if(_0x22538c['offset'])_0x148456[_0x96cc('0x1d')](_0x22538c[_0x96cc('0x1d')]);return db['sequelize'][_0x96cc('0x37')](_0x148456['toString'](),_0x48aeea);})[_0x96cc('0x23')](function(_0x9f656b){_0x49297a[_0x96cc('0x71')](_0x96cc('0xaa'),_['map'](_0x9f656b,'id'));return db[_0x96cc('0x96')]['query'](_0x49297a[_0x96cc('0x97')](),_0x48aeea)[_0x96cc('0x23')](function(_0x8aa1fc){var _0x32072a=_[_0x96cc('0xab')](_0x8aa1fc,_0x96cc('0xac'));var _0x2023aa=[];_0x9f656b[_0x96cc('0x2e')](function(_0x10ef85){_0x2023aa[_0x96cc('0x30')](updateWhatsappInteraction(_0x10ef85,_0x4b5ffb,_0x32072a));});return BPromise[_0x96cc('0xad')](_0x2023aa);});});})[_0x96cc('0x23')](function(_0x4c9fd7){_0x30e93f[_0x96cc('0xae')]=_0x4c9fd7;return _0x30e93f;})['then'](respondWithFilteredResult(_0x36c04e,_0x22538c))[_0x96cc('0x31')](handleError(_0x36c04e,null));};exports['show']=function(_0x35e95d,_0xd392ea){var _0xe64902={'raw':![],'where':{'id':_0x35e95d[_0x96cc('0xaf')]['id']}},_0x467975={};_0x467975['model']=_[_0x96cc('0x38')](db[_0x96cc('0x9a')][_0x96cc('0x33')]);_0x467975[_0x96cc('0x37')]=_[_0x96cc('0x38')](_0x35e95d['query']);_0x467975[_0x96cc('0x39')]=_[_0x96cc('0x3a')](_0x467975[_0x96cc('0x36')],_0x467975[_0x96cc('0x37')]);_0xe64902[_0x96cc('0x3b')]=_['intersection'](_0x467975[_0x96cc('0x36')],qs[_0x96cc('0x3c')](_0x35e95d[_0x96cc('0x37')][_0x96cc('0x3c')]));_0xe64902[_0x96cc('0x3b')]=_0xe64902['attributes'][_0x96cc('0x5b')]?_0xe64902['attributes']:_0x467975['model'];if(_0x35e95d[_0x96cc('0x37')][_0x96cc('0xb0')]){_0xe64902[_0x96cc('0xb1')]=[{'all':!![]}];}_0xe64902=_[_0x96cc('0x99')]({},_0xe64902,_0x35e95d['options']);return db[_0x96cc('0x9a')][_0x96cc('0x5c')](_0xe64902)['then'](handleEntityNotFound(_0xd392ea,null))['then'](respondWithResult(_0xd392ea,null))[_0x96cc('0x31')](handleError(_0xd392ea,null));};exports[_0x96cc('0xb2')]=function(_0x513ff5,_0x1d945d){return db[_0x96cc('0x9a')]['create'](_0x513ff5['body'],{})[_0x96cc('0x23')](respondWithResult(_0x1d945d,0xc9))['catch'](handleError(_0x1d945d,null));};exports[_0x96cc('0x22')]=function(_0x183db1,_0x38a989){if(_0x183db1[_0x96cc('0x6f')]['id']){delete _0x183db1[_0x96cc('0x6f')]['id'];}return db[_0x96cc('0x9a')][_0x96cc('0x5c')]({'where':{'id':_0x183db1[_0x96cc('0xaf')]['id']}})['then'](handleEntityNotFound(_0x38a989,null))[_0x96cc('0x23')](saveUpdates(_0x183db1[_0x96cc('0x6f')],null))[_0x96cc('0x23')](respondWithResult(_0x38a989,null))[_0x96cc('0x31')](handleError(_0x38a989,null));};exports[_0x96cc('0x24')]=function(_0x291cde,_0xb8cd9){return db[_0x96cc('0x9a')][_0x96cc('0x5c')]({'where':{'id':_0x291cde[_0x96cc('0xaf')]['id']}})['then'](handleEntityNotFound(_0xb8cd9,null))[_0x96cc('0x23')](removeEntity(_0xb8cd9,null))['catch'](handleError(_0xb8cd9,null));};exports['describe']=function(_0x3948cb,_0x2efe09){return db[_0x96cc('0x9a')][_0x96cc('0xb3')]()[_0x96cc('0x23')](respondWithResult(_0x2efe09,null))[_0x96cc('0x31')](handleError(_0x2efe09,null));};exports[_0x96cc('0xb4')]=function(_0x301377,_0x22f176,_0x13588a){return db['WhatsappMessage'][_0x96cc('0x5c')]({'where':{'id':_0x301377['params']['id']}})[_0x96cc('0x23')](handleEntityNotFound(_0x22f176,null))['then'](function(_0xc5266b){if(_0xc5266b){return _0xc5266b[_0x96cc('0xb4')](_0x301377['body'][_0x96cc('0xb5')],_[_0x96cc('0xb6')](_0x301377[_0x96cc('0x6f')],['ids','id'])||{});}})['then'](respondWithResult(_0x22f176,null))[_0x96cc('0x31')](handleError(_0x22f176,null));};exports[_0x96cc('0xb7')]=function(_0x20e487,_0xd1ddd0,_0x136f42){var _0x4af670={'raw':![],'where':{}};var _0x1ceb85={};var _0x1b0a94={'count':0x0,'rows':[]};return db[_0x96cc('0x9a')][_0x96cc('0xb8')]({'where':{'id':_0x20e487['params']['id']}})['then'](handleEntityNotFound(_0xd1ddd0,null))[_0x96cc('0x23')](function(_0x173acb){if(_0x173acb){_0x1ceb85['model']=_['keys'](db[_0x96cc('0xb9')][_0x96cc('0x33')]);_0x1ceb85[_0x96cc('0x37')]=_[_0x96cc('0x38')](_0x20e487[_0x96cc('0x37')]);_0x1ceb85['filters']=_[_0x96cc('0x3a')](_0x1ceb85[_0x96cc('0x36')],_0x1ceb85[_0x96cc('0x37')]);_0x4af670[_0x96cc('0x3b')]=_[_0x96cc('0x3a')](_0x1ceb85['model'],qs[_0x96cc('0x3c')](_0x20e487[_0x96cc('0x37')][_0x96cc('0x3c')]));_0x4af670[_0x96cc('0x3b')]=_0x4af670[_0x96cc('0x3b')][_0x96cc('0x5b')]?_0x4af670[_0x96cc('0x3b')]:_0x1ceb85['model'];if(!_0x20e487[_0x96cc('0x37')][_0x96cc('0xba')](_0x96cc('0x3d'))){_0x4af670[_0x96cc('0x3e')]=qs[_0x96cc('0x3e')](_0x20e487['query']['limit']);_0x4af670[_0x96cc('0x1d')]=qs['offset'](_0x20e487[_0x96cc('0x37')][_0x96cc('0x1d')]);}_0x4af670[_0x96cc('0x89')]=qs[_0x96cc('0x3f')](_0x20e487['query']['sort']);_0x4af670['where']=qs[_0x96cc('0x39')](_[_0x96cc('0x40')](_0x20e487[_0x96cc('0x37')],_0x1ceb85[_0x96cc('0x39')]));_0x4af670[_0x96cc('0x71')][_0x96cc('0xac')]=_0x173acb['id'];if(_0x20e487[_0x96cc('0x37')][_0x96cc('0xbb')]){_0x4af670[_0x96cc('0x71')]=_[_0x96cc('0x99')](_0x4af670[_0x96cc('0x71')],{'$or':_['map'](_0x4af670[_0x96cc('0x3b')],function(_0x471397){var _0x1d42a4={};_0x1d42a4[_0x471397]={'$like':'%'+_0x20e487[_0x96cc('0x37')][_0x96cc('0xbb')]+'%'};return _0x1d42a4;})});}if(_0x20e487[_0x96cc('0x37')]['$gte']){var _0x2d6a69=_0x20e487['query']['$gte'][_0x96cc('0x2d')](',');var _0x1e4dce={};_0x1e4dce[_0x2d6a69[0x0]]={'$gte':moment(_0x2d6a69[0x1])[_0x96cc('0xbc')]('YYYY-MM-DD\x20HH:mm:ss')};_0x4af670[_0x96cc('0x71')]=_[_0x96cc('0x99')](_0x4af670[_0x96cc('0x71')],_0x1e4dce);}_0x4af670=_['merge']({},_0x4af670,_0x20e487[_0x96cc('0xbd')]);return db[_0x96cc('0xb9')]['count']({'where':_0x4af670['where']})[_0x96cc('0x23')](function(_0x301d12){_0x1b0a94[_0x96cc('0x1c')]=_0x301d12;if(_0x20e487[_0x96cc('0x37')][_0x96cc('0xb0')]){_0x4af670[_0x96cc('0xb1')]=[{'all':!![]}];}return db[_0x96cc('0xb9')][_0x96cc('0xbe')](_0x4af670);})[_0x96cc('0x23')](function(_0x5f74d5){_0x1b0a94[_0x96cc('0xae')]=_0x5f74d5;return _0x1b0a94;});}})[_0x96cc('0x23')](respondWithFilteredResult(_0xd1ddd0,_0x4af670))[_0x96cc('0x31')](handleError(_0xd1ddd0,null));};exports[_0x96cc('0xbf')]=function(_0x4b2060,_0x4bae9e,_0x515e95){return db[_0x96cc('0x9a')][_0x96cc('0x5c')]({'where':{'id':_0x4b2060['params']['id']}})[_0x96cc('0x23')](handleEntityNotFound(_0x4bae9e,null))[_0x96cc('0x23')](function(_0x498786){if(_0x498786){return _0x498786[_0x96cc('0xc0')](_0x4b2060[_0x96cc('0x6f')][_0x96cc('0xb5')],_[_0x96cc('0xb6')](_0x4b2060[_0x96cc('0x6f')],[_0x96cc('0xb5'),'id'])||{})['spread'](function(){return db[_0x96cc('0x67')][_0x96cc('0xbe')]({'attributes':['id',_0x96cc('0x27'),_0x96cc('0x43')],'where':{'id':_0x4b2060[_0x96cc('0x6f')][_0x96cc('0xb5')]}});})[_0x96cc('0x23')](function(_0x21caa8){socket[_0x96cc('0xc1')](_0x96cc('0xc2'),{'id':Number(_0x4b2060[_0x96cc('0xaf')]['id']),'tags':_0x21caa8||[]});return{'id':Number(_0x4b2060[_0x96cc('0xaf')]['id']),'tags':_0x21caa8||[]};});}})[_0x96cc('0x23')](respondWithResult(_0x4bae9e,null))[_0x96cc('0x31')](handleError(_0x4bae9e,null));};exports[_0x96cc('0xc3')]=function(_0x41c3a4,_0x21c4f9,_0x5f38e9){return db[_0x96cc('0x9a')][_0x96cc('0x5c')]({'where':{'id':_0x41c3a4[_0x96cc('0xaf')]['id']}})[_0x96cc('0x23')](handleEntityNotFound(_0x21c4f9,null))[_0x96cc('0x23')](function(_0xaf9fec){if(_0xaf9fec){return _0xaf9fec[_0x96cc('0xc3')](_0x41c3a4['query'][_0x96cc('0xb5')]);}})[_0x96cc('0x23')](respondWithStatusCode(_0x21c4f9,null))[_0x96cc('0x31')](handleError(_0x21c4f9,null));};exports['download']=function(_0x415f19,_0xa95721){var _0x238e47=moment()[_0x96cc('0xc4')]()[_0x96cc('0x97')]();var _0x52c4a4=path['join'](config['root'],'server','files','tmp');var _0x2d057f=path[_0x96cc('0xc5')](config[_0x96cc('0xc6')],_0x96cc('0xc7'),'files',_0x96cc('0xc8'));var _0x139539=path[_0x96cc('0xc5')](_0x52c4a4,_0x238e47);var _0x3872d0=util['format'](_0x96cc('0xc9'),_0x415f19['params']['id'],_0x238e47);var _0x41f5ae=path[_0x96cc('0xc5')](_0x52c4a4,_0x3872d0);var _0xd4993b=[];_0xd4993b['push']({'model':db[_0x96cc('0x68')],'as':_0x96cc('0x68'),'attributes':['id',_0x96cc('0x2b')],'raw':!![]});_0xd4993b[_0x96cc('0x30')]({'model':db[_0x96cc('0xca')],'as':'Contact','attributes':['id',_0x96cc('0xcb'),_0x96cc('0xcc')],'raw':!![]});if(_0x415f19['query']['attachments']){_0xd4993b[_0x96cc('0x30')]({'model':db['Attachment'],'as':_0x96cc('0xcd'),'raw':!![]});}var _0x545681=[{'model':db[_0x96cc('0xb9')],'as':_0x96cc('0xce'),'attributes':['id','body',_0x96cc('0x73'),_0x96cc('0xcf'),_0x96cc('0xd0'),_0x96cc('0x79')],'include':_0xd4993b}];_0x545681['push']({'model':db[_0x96cc('0xd1')],'as':_0x96cc('0xd2'),'attributes':['id','name']});_0x545681[_0x96cc('0x30')]({'model':db[_0x96cc('0x68')],'as':'Owner','attributes':['id',_0x96cc('0x2b')]});return db[_0x96cc('0x9a')][_0x96cc('0x5c')]({'where':{'id':_0x415f19[_0x96cc('0xaf')]['id']},'include':_0x545681})[_0x96cc('0x23')](handleEntityNotFound(_0xa95721,null))[_0x96cc('0x23')](function(_0x2c363b){if(_0x2c363b){var _0x52406c=_0x2c363b[_0x96cc('0xd3')]({'plain':!![]});fs[_0x96cc('0xd4')](_0x139539);var _0x53c37d={'channel':_0x96cc('0xd5'),'account':_0x52406c[_0x96cc('0xd2')][_0x96cc('0x27')],'agent':_0x52406c[_0x96cc('0xd6')]?_0x52406c[_0x96cc('0xd6')]['fullname']:_0x96cc('0xd7'),'createdAt':moment(_0x52406c[_0x96cc('0x73')])['format'](_0x96cc('0xd8'))['toString'](),'closedAt':_0x52406c[_0x96cc('0xd9')]?moment(_0x52406c[_0x96cc('0xda')])['format'](_0x96cc('0xd8'))[_0x96cc('0x97')]():'','disposition':_0x52406c['disposition'],'messages':_(_0x52406c[_0x96cc('0xce')])['filter']({'secret':![]})[_0x96cc('0x2a')](function(_0x1d3d55){if(_0x1d3d55[_0x96cc('0xcd')]){var _0x144c8f=path['join'](_0x2d057f,_0x1d3d55[_0x96cc('0xcd')][_0x96cc('0xdb')]);if(fs['existsSync'](_0x144c8f)){fs[_0x96cc('0xdc')](_0x144c8f)[_0x96cc('0xdd')](fs[_0x96cc('0xde')](path['join'](_0x139539,_0x1d3d55['Attachment'][_0x96cc('0xdb')])));}}return{'date':moment(_0x1d3d55[_0x96cc('0x73')])[_0x96cc('0xbc')](_0x96cc('0xd8'))[_0x96cc('0x97')](),'sender':_0x1d3d55[_0x96cc('0xcf')]==='out'?_0x1d3d55[_0x96cc('0x68')]?_0x1d3d55[_0x96cc('0x68')][_0x96cc('0x2b')]:'System':_0x1d3d55[_0x96cc('0x61')]['firstName']+(_0x1d3d55['Contact']['lastName']?'\x20'+_0x1d3d55[_0x96cc('0x61')]['lastName']:''),'body':_0x1d3d55[_0x96cc('0xcd')]?_0x1d3d55[_0x96cc('0xcd')][_0x96cc('0xdb')]:_0x1d3d55[_0x96cc('0x6f')],'direction':_0x1d3d55[_0x96cc('0xcf')]===_0x96cc('0xdf')?'A':'C','secret':_0x1d3d55[_0x96cc('0xd0')],'read':_0x1d3d55[_0x96cc('0x79')],'attachment':_0x1d3d55[_0x96cc('0xcd')]};})[_0x96cc('0x5e')]()};return ejs[_0x96cc('0xe0')](path['join'](config['root'],_0x96cc('0xc7'),_0x96cc('0xe1'),'downloadInteraction.html'),{'interaction':_0x53c37d})[_0x96cc('0x23')](function(_0xf1e379){var _0x457459=path[_0x96cc('0xc5')](_0x139539,_0x96cc('0xe2')+_0x52406c['id']+'-'+_0x238e47+_0x96cc('0xe3'));var _0x47482f={'path':_0x457459,'channel':_0x96cc('0xd5'),'interactionId':_0x52406c['id']};return pdf[_0x96cc('0xe4')](_0xf1e379,_0x47482f);})[_0x96cc('0x23')](function(){return new BPromise(function(_0x1e9238,_0x1075b2){zipdir(_0x139539,{'saveTo':_0x41f5ae},function(_0x39fe2b,_0xa565){if(_0x39fe2b)return _0x1075b2(_0x39fe2b);return _0x1e9238(_0xa565);});})['then'](function(){return new BPromise(function(_0xfe86d8,_0x1da4a8){rimraf(_0x139539,function(_0x423b7e){if(_0x423b7e)_0x1da4a8(_0x423b7e);return _0xfe86d8();});});})[_0x96cc('0x23')](function(){return _0xa95721[_0x96cc('0xe5')](_0x41f5ae,_0x3872d0,function(_0x14fd34){if(_0x14fd34){console['log'](_0x96cc('0xe6'),_0x14fd34);}else{fs[_0x96cc('0xe7')](_0x41f5ae);}});});});}else{return _0xa95721[_0x96cc('0x19')](0xc8);}})[_0x96cc('0x31')](handleError(_0xa95721,null));};
\ No newline at end of file