Built motion from commit (unavailable).|2.5.27
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 748e861..f2d06ae 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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
+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