Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 33bacd0..1c3539c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb5fa=['lastName','renderFile','views','downloadInteraction.ejs','transcript-','createPdfFromHTML','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','update','then','error','stack','name','Users','TagIds','Tags','split','push','catch','waiting','talking','answered','unmanaged','total','UserId','closed','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','sort','pick','select','field','color','from','tools_tags','u.id','u.fullname','user_has_whatsapp_interactions','users','u.id\x20=\x20ui.UserId','left_join','cm_contacts','whatsapp_accounts','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','search','parseSearch','sqlOperator','conditions','length','find','unreadMessages','value','having','`\x20=\x200','`\x20>\x200','Contact','operator','$substring','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','buildExpression','body','some','compact','isEmpty','forEach','i.WhatsappAccountId\x20IN\x20?','createdAt','$gte','$lte','where','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','tag','isArray','filter','replace','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','role','user','i.WhatsappAccountId\x20IS\x20NULL','agent','sequelize','keyBy','merge','WhatsappInteraction','a.key','Account.key','Account.mandatoryDisposition','c.firstName','Contact.firstName','Contact.lastName','c.email','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','toString','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','rows','params','includeAll','options','create','describe','WhatsappMessage','addMessage','ids','omit','getMessages','nolimit','format','findAll','setTags','emit','whatsappInteractionTags:save','removeTags','download','root','server','files','tmp','join','attachments','transcript-%d-%s.zip','fullname','CmContact','firstName','Attachment','Messages','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','disposition','existsSync','createReadStream','pipe','createWriteStream','basename','out','System'];(function(_0x37c096,_0x3abf0f){var _0x29c4f3=function(_0x436e67){while(--_0x436e67){_0x37c096['push'](_0x37c096['shift']());}};_0x29c4f3(++_0x3abf0f);}(_0xb5fa,0xf8));var _0xab5f=function(_0x52326e,_0x18f7b5){_0x52326e=_0x52326e-0x0;var _0x39b11e=_0xb5fa[_0x52326e];return _0x39b11e;};'use strict';var emlformat=require(_0xab5f('0x0'));var rimraf=require(_0xab5f('0x1'));var zipdir=require(_0xab5f('0x2'));var jsonpatch=require(_0xab5f('0x3'));var rp=require(_0xab5f('0x4'));var moment=require(_0xab5f('0x5'));var BPromise=require(_0xab5f('0x6'));var Mustache=require(_0xab5f('0x7'));var util=require(_0xab5f('0x8'));var path=require(_0xab5f('0x9'));var sox=require(_0xab5f('0xa'));var csv=require(_0xab5f('0xb'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xab5f('0xc'));var crypto=require(_0xab5f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xab5f('0xe'));var toCsv=require(_0xab5f('0xb'));var querystring=require(_0xab5f('0xf'));var Papa=require(_0xab5f('0x10'));var Redis=require(_0xab5f('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xab5f('0x12'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xab5f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xab5f('0x14'))(_0xab5f('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xab5f('0x16'))['db'];config[_0xab5f('0x17')]=_['defaults'](config[_0xab5f('0x17')],{'host':_0xab5f('0x18'),'port':0x18eb});var socket=require(_0xab5f('0x19'))(new Redis(config[_0xab5f('0x17')]));require(_0xab5f('0x1a'))[_0xab5f('0x1b')](socket);function respondWithStatusCode(_0x4319c7,_0x425053){_0x425053=_0x425053||0xcc;return function(_0x32def2){if(_0x32def2){return _0x4319c7[_0xab5f('0x1c')](_0x425053);}return _0x4319c7[_0xab5f('0x1d')](_0x425053)[_0xab5f('0x1e')]();};}function respondWithResult(_0x177e6d,_0x22588b){_0x22588b=_0x22588b||0xc8;return function(_0x3d5485){if(_0x3d5485){return _0x177e6d[_0xab5f('0x1d')](_0x22588b)[_0xab5f('0x1f')](_0x3d5485);}};}function respondWithFilteredResult(_0x340190,_0x4aca7d){return function(_0x2caadb){if(_0x2caadb){var _0x4da25e=typeof _0x4aca7d[_0xab5f('0x20')]===_0xab5f('0x21')&&typeof _0x4aca7d[_0xab5f('0x22')]===_0xab5f('0x21');var _0x4c344f=_0x2caadb[_0xab5f('0x23')];var _0x413412=_0x4da25e?0x0:_0x4aca7d[_0xab5f('0x20')];var _0x1bc5ae=_0x4da25e?_0x2caadb[_0xab5f('0x23')]:_0x4aca7d[_0xab5f('0x20')]+_0x4aca7d['limit'];var _0x3fca4c;if(_0x1bc5ae>=_0x4c344f){_0x1bc5ae=_0x4c344f;_0x3fca4c=0xc8;}else{_0x3fca4c=0xce;}_0x340190[_0xab5f('0x1d')](_0x3fca4c);return _0x340190[_0xab5f('0x24')]('Content-Range',_0x413412+'-'+_0x1bc5ae+'/'+_0x4c344f)[_0xab5f('0x1f')](_0x2caadb);}return null;};}function patchUpdates(_0x134a23){return function(_0x811e76){try{jsonpatch[_0xab5f('0x25')](_0x811e76,_0x134a23,!![]);}catch(_0x297dff){return BPromise[_0xab5f('0x26')](_0x297dff);}return _0x811e76['save']();};}function saveUpdates(_0x55daaf,_0x3c5847){return function(_0x3f3bae){if(_0x3f3bae){return _0x3f3bae[_0xab5f('0x27')](_0x55daaf)[_0xab5f('0x28')](function(_0x3fb403){return _0x3fb403;});}return null;};}function removeEntity(_0x49972a,_0x3db1a6){return function(_0x38d793){if(_0x38d793){return _0x38d793['destroy']()[_0xab5f('0x28')](function(){_0x49972a[_0xab5f('0x1d')](0xcc)[_0xab5f('0x1e')]();});}};}function handleEntityNotFound(_0x391fec,_0x4fee82){return function(_0x144281){if(!_0x144281){_0x391fec[_0xab5f('0x1c')](0x194);}return _0x144281;};}function handleError(_0x1e1fa9,_0x239229){_0x239229=_0x239229||0x1f4;return function(_0x5e43a5){logger[_0xab5f('0x29')](_0x5e43a5[_0xab5f('0x2a')]);if(_0x5e43a5[_0xab5f('0x2b')]){delete _0x5e43a5[_0xab5f('0x2b')];}_0x1e1fa9[_0xab5f('0x1d')](_0x239229)['send'](_0x5e43a5);};}function getInteractionUsers(_0x5c6229,_0x7f5308){return new BPromise(function(_0x464287,_0x290df8){try{if(_0x7f5308[_0x5c6229['id']]){_0x5c6229[_0xab5f('0x2c')]=_['map'](_0x7f5308[_0x5c6229['id']],function(_0x56a8e9){return{'id':_0x56a8e9['id'],'fullname':_0x56a8e9['fullname']};});}}catch(_0x5f2c8e){_0x290df8(_0x5f2c8e);}_0x464287(_0x5c6229);});}function getInteractionTags(_0x494c4b,_0xcfaa90){return new BPromise(function(_0x312140,_0x18ca34){try{if(_0x494c4b[_0xab5f('0x2d')]){_0x494c4b[_0xab5f('0x2e')]=[];_0x494c4b[_0xab5f('0x2d')][_0xab5f('0x2f')](',')['forEach'](function(_0x2acdfc){_0x494c4b[_0xab5f('0x2e')][_0xab5f('0x30')](_0xcfaa90[_0x2acdfc]);});}delete _0x494c4b[_0xab5f('0x2d')];}catch(_0x2ba2e6){_0x18ca34(_0x2ba2e6);}_0x312140(_0x494c4b);});}function updateWhatsappInteraction(_0x42af45,_0x4e86d2,_0x39c74d){return new BPromise(function(_0x529c2d,_0x3e02f6){return getInteractionUsers(_0x42af45,_0x39c74d)['then'](function(_0x55c8ab){return getInteractionTags(_0x55c8ab,_0x4e86d2);})['then'](function(_0x4e7fc1){return getStateInteraction(_0x4e7fc1);})[_0xab5f('0x28')](function(_0x56e0f3){_0x529c2d(_0x56e0f3);})[_0xab5f('0x31')](function(_0x137502){_0x3e02f6(_0x137502);});});}function getStateInteraction(_0x41023a){return new BPromise(function(_0x6fb3fc){_0x41023a[_0xab5f('0x32')]=0x0;_0x41023a[_0xab5f('0x33')]=0x0;_0x41023a[_0xab5f('0x34')]=0x0;_0x41023a[_0xab5f('0x35')]=0x0;_0x41023a[_0xab5f('0x36')]=0x0;if(!_0x41023a['closed']&&!_0x41023a[_0xab5f('0x37')]){_0x41023a['waiting']+=0x1;}if(!_0x41023a[_0xab5f('0x38')]&&_0x41023a[_0xab5f('0x37')]){_0x41023a[_0xab5f('0x33')]+=0x1;if(_0x41023a['waiting']){_0x41023a[_0xab5f('0x32')]-=0x1;}}if(_0x41023a[_0xab5f('0x38')]&&_0x41023a[_0xab5f('0x37')]){_0x41023a[_0xab5f('0x34')]+=0x1;if(_0x41023a[_0xab5f('0x33')]){_0x41023a[_0xab5f('0x33')]-=0x1;}}if(_0x41023a[_0xab5f('0x38')]&&!_0x41023a['UserId']){_0x41023a[_0xab5f('0x35')]+=0x1;if(_0x41023a[_0xab5f('0x32')]){_0x41023a[_0xab5f('0x32')]-=0x1;}}_0x41023a[_0xab5f('0x36')]+=0x1;_0x6fb3fc(_0x41023a);});}exports[_0xab5f('0x39')]=function(_0x141a34,_0x41184c){var _0x1d1f7d={},_0x4aaaa3={},_0x484fde={'count':0x0,'rows':[]};var _0x24878b=_[_0xab5f('0x3a')](db['WhatsappInteraction'][_0xab5f('0x3b')],function(_0x579946){return{'name':_0x579946[_0xab5f('0x3c')],'type':_0x579946[_0xab5f('0x3d')]['key']};});_0x4aaaa3[_0xab5f('0x3e')]=_['map'](_0x24878b,_0xab5f('0x2b'));_0x4aaaa3[_0xab5f('0x3f')]=_[_0xab5f('0x40')](_0x141a34[_0xab5f('0x3f')]);_0x4aaaa3[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0x4aaaa3['model'],_0x4aaaa3[_0xab5f('0x3f')]);_0x1d1f7d[_0xab5f('0x43')]=_[_0xab5f('0x42')](_0x4aaaa3[_0xab5f('0x3e')],qs[_0xab5f('0x44')](_0x141a34[_0xab5f('0x3f')]['fields']));_0x1d1f7d[_0xab5f('0x43')]=_0x1d1f7d[_0xab5f('0x43')]['length']?_0x1d1f7d[_0xab5f('0x43')]:_0x4aaaa3['model'];if(!_0x141a34[_0xab5f('0x3f')][_0xab5f('0x45')]('nolimit')){_0x1d1f7d[_0xab5f('0x22')]=qs[_0xab5f('0x22')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x22')]);_0x1d1f7d[_0xab5f('0x20')]=qs[_0xab5f('0x20')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x20')]);}_0x1d1f7d['order']=qs[_0xab5f('0x46')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x46')]);_0x1d1f7d['where']=qs[_0xab5f('0x41')](_[_0xab5f('0x47')](_0x141a34[_0xab5f('0x3f')],_0x4aaaa3[_0xab5f('0x41')]),_0x24878b);var _0x3e699e=[];var _0x14e815=squel[_0xab5f('0x48')]()[_0xab5f('0x49')]('id')[_0xab5f('0x49')](_0xab5f('0x2b'))[_0xab5f('0x49')](_0xab5f('0x4a'))[_0xab5f('0x4b')](_0xab5f('0x4c'));var _0x5f1018=squel[_0xab5f('0x48')]()[_0xab5f('0x49')](_0xab5f('0x4d'))[_0xab5f('0x49')](_0xab5f('0x4e'))['field']('ui.WhatsappInteractionId')[_0xab5f('0x4b')](_0xab5f('0x4f'),'ui')['left_join'](_0xab5f('0x50'),'u',_0xab5f('0x51'));var _0x85fd96=squel[_0xab5f('0x48')]()['from']('whatsapp_interactions','i')[_0xab5f('0x52')](_0xab5f('0x53'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')[_0xab5f('0x52')](_0xab5f('0x50'),'o','o.id\x20=\x20i.UserId')['left_join'](_0xab5f('0x54'),'a','a.id\x20=\x20i.WhatsappAccountId')[_0xab5f('0x52')](_0xab5f('0x55'),'me',_0xab5f('0x56'))[_0xab5f('0x52')](_0xab5f('0x57'),'it',_0xab5f('0x58'))[_0xab5f('0x52')](_0xab5f('0x4c'),'t',_0xab5f('0x59'));var _0x454932=squel['expr']();var _0x36db0a=[];var _0x493235=squel['expr']();var _0x43a51b;if(_0x141a34['query'][_0xab5f('0x5a')]){_0x43a51b=as[_0xab5f('0x5b')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x5a')]);var _0x1b9cbd=_0x43a51b[_0xab5f('0x5c')];for(var _0x269eb8=0x0;_0x269eb8<_0x43a51b[_0xab5f('0x5d')][_0xab5f('0x5e')];_0x269eb8++){var _0x51b5d5=_0x43a51b[_0xab5f('0x5d')][_0x269eb8];var _0x201896='i';var _0x1d8952=_[_0xab5f('0x5f')](_0x24878b,['name',_0x51b5d5[_0xab5f('0x49')]]);if(!_0x1d8952){switch(_0x51b5d5[_0xab5f('0x49')]){case _0xab5f('0x60'):if(_0x51b5d5[_0xab5f('0x61')]==0x1){_0x85fd96[_0xab5f('0x62')]('`'+_0x51b5d5['field']+_0xab5f('0x63'));}else{_0x85fd96[_0xab5f('0x62')]('`'+_0x51b5d5['field']+_0xab5f('0x64'));}break;case _0xab5f('0x65'):if(_0x51b5d5[_0xab5f('0x66')]===_0xab5f('0x67')){if(_0x51b5d5[_0xab5f('0x61')][_0xab5f('0x2f')]('\x20')[_0xab5f('0x5e')]>0x1){_0x454932[_0x1b9cbd]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xab5f('0x68')](_0x51b5d5[_0xab5f('0x61')]),null);}else{var _0x2d10e6='%'+_0x51b5d5[_0xab5f('0x61')]+'%';_0x454932[_0x1b9cbd](_0xab5f('0x69'),_0x2d10e6,_0x2d10e6,_0x2d10e6);}}else{_0x1d8952=_[_0xab5f('0x5f')](_0x24878b,['name','ContactId']);_0x51b5d5[_0xab5f('0x49')]=_0xab5f('0x6a');_0x15b9b1=as['buildExpression'](_0x201896,_0x1d8952[_0xab5f('0x3d')],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1['value'][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x1e')]);}break;case _0xab5f('0x6d'):var _0x5dde1b=_0x51b5d5['value'][_0xab5f('0x2f')](',')[_0xab5f('0x3a')](function(_0x1e4cd6){return Number(_0x1e4cd6);});_0x5dde1b['forEach'](function(_0x41fab8){_0x493235['or'](_0xab5f('0x6e'),'%,'+_0x41fab8+',%');});_0x36db0a=_['union'](_0x36db0a,_0x5dde1b);break;case _0xab5f('0x6f'):if(_0x51b5d5[_0xab5f('0x66')]===_0xab5f('0x67')){_0x454932[_0x1b9cbd](_0xab5f('0x70'),'%'+_0x51b5d5[_0xab5f('0x61')]+'%',null);}else{_0x1d8952=_[_0xab5f('0x5f')](_0x24878b,[_0xab5f('0x2b'),_0xab5f('0x37')]);_0x51b5d5[_0xab5f('0x49')]=_0xab5f('0x37');_0x15b9b1=as[_0xab5f('0x71')](_0x201896,_0x1d8952['type'],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')]['end']);}break;case _0xab5f('0x72'):_0x15b9b1=as[_0xab5f('0x71')]('me',null,_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1['text'],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1['value']['end']);break;}}else{var _0x15b9b1=as[_0xab5f('0x71')](_0x201896,_0x1d8952[_0xab5f('0x3d')],_0x51b5d5);_0x454932[_0x1b9cbd](_0x15b9b1[_0xab5f('0x6b')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x6c')],_0x15b9b1[_0xab5f('0x61')][_0xab5f('0x1e')]);}}}else{var _0x58442f=_(_0x141a34[_0xab5f('0x3f')])[_0xab5f('0x40')]()[_0xab5f('0x3a')](function(_0x610c3e){return _[_0xab5f('0x73')](_0x24878b,[_0xab5f('0x2b'),_0x610c3e])?_0x610c3e:undefined;})[_0xab5f('0x74')]()[_0xab5f('0x61')]();if(!_[_0xab5f('0x75')](_0x58442f)){_0x58442f[_0xab5f('0x76')](function(_0x5ca3b1){if(_0x5ca3b1==='WhatsappAccountId'){_0x85fd96['where'](_0xab5f('0x77'),[]['concat'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1]));}else if(_0x5ca3b1===_0xab5f('0x78')){var _0x5ec60c=JSON['parse'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1])[_0xab5f('0x79')];var _0x14e83f=JSON['parse'](_0x141a34[_0xab5f('0x3f')][_0x5ca3b1])[_0xab5f('0x7a')];_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x7c'),_0x5ec60c,_0x14e83f);}else{if(_0x141a34[_0xab5f('0x3f')][_0x5ca3b1]===_0xab5f('0x7d')){_0x85fd96[_0xab5f('0x7b')]('i.'+_0x5ca3b1+_0xab5f('0x7e'));}else{_0x85fd96[_0xab5f('0x7b')]('i.'+_0x5ca3b1+_0xab5f('0x7f'),_0x141a34['query'][_0x5ca3b1]);}}});}if(_0x141a34['query'][_0xab5f('0x80')]){if(_0x141a34['query'][_0xab5f('0x80')]==0x1){_0x85fd96['having'](_0xab5f('0x81'));}else{_0x85fd96[_0xab5f('0x62')]('`unreadMessages`\x20>\x200');}}if(_0x141a34['query'][_0xab5f('0x82')]){_0x36db0a=_[_0xab5f('0x83')](_0x141a34[_0xab5f('0x3f')][_0xab5f('0x82')])?_0x141a34[_0xab5f('0x3f')][_0xab5f('0x82')]:new Array(_0x141a34[_0xab5f('0x3f')]['tag']);_0x36db0a['forEach'](function(_0x2c29e7){_0x493235['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x2c29e7+',%');});}if(_0x141a34[_0xab5f('0x3f')][_0xab5f('0x84')]){var _0x5d4ed8=_0x141a34[_0xab5f('0x3f')][_0xab5f('0x84')][_0xab5f('0x85')]('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs['isNumeric'](_0x5d4ed8)){_0x454932['or'](_0xab5f('0x86'),_0x5d4ed8+'%')['or'](_0xab5f('0x87'),_0x5d4ed8+'%');}else{_0x454932['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x5d4ed8))['or'](_0xab5f('0x88'),_0x5d4ed8+'%');}}}_0x85fd96[_0xab5f('0x7b')](_0x454932);_0x85fd96[_0xab5f('0x89')](_0xab5f('0x8a'));var _0x12430f={'type':db[_0xab5f('0x8b')][_0xab5f('0x8c')]['SELECT'],'raw':!![]};var _0x23acfb=_0x85fd96['clone']();_0x23acfb[_0xab5f('0x49')](_0xab5f('0x8a'));_0x23acfb[_0xab5f('0x49')](_0xab5f('0x8d'),_0xab5f('0x60'));if(_0x1d1f7d[_0xab5f('0x8e')]){_0x1d1f7d['order'][_0xab5f('0x76')](function(_0x12f94e){var _0x12756c=_0x12f94e[0x0]===_0xab5f('0x8f')?_0x12f94e[0x0]:'i.'+_0x12f94e[0x0];_0x85fd96[_0xab5f('0x8e')](_0x12756c,_0x12f94e[0x1]===_0xab5f('0x90')?![]:!![]);});}if(!_['isEmpty'](_0x36db0a)){_0x85fd96[_0xab5f('0x62')](_0x493235);_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x91'),_0x36db0a);}BPromise[_0xab5f('0x92')]()['then'](function(){if(!_0x43a51b){if(_0x141a34['query'][_0xab5f('0x93')])return;_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x94'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x94'));return;}if(_0x141a34['user'][_0xab5f('0x95')]!=='agent')return;return _0x141a34[_0xab5f('0x96')]['getWhatsappAccounts']({'attributes':['id'],'raw':!![]})[_0xab5f('0x28')](function(_0x502538){if(_[_0xab5f('0x75')](_0x502538)){_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x97'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x97'));}else{_0x23acfb[_0xab5f('0x7b')](_0xab5f('0x77'),_[_0xab5f('0x3a')](_0x502538,'id'));_0x85fd96[_0xab5f('0x7b')](_0xab5f('0x77'),_[_0xab5f('0x3a')](_0x502538,'id'));}});})[_0xab5f('0x28')](function(){if(_0x141a34[_0xab5f('0x96')][_0xab5f('0x95')]===_0xab5f('0x98')&&!_0x43a51b&&!_0x141a34['query'][_0xab5f('0x93')])return[];return db['sequelize'][_0xab5f('0x3f')](_0x23acfb['toString'](),_0x12430f);})[_0xab5f('0x28')](function(_0x81d183){_0x484fde[_0xab5f('0x23')]=_0x81d183[_0xab5f('0x5e')];if(_0x484fde['count']===0x0)return[];return db[_0xab5f('0x99')]['query'](_0x14e815['toString'](),_0x12430f)['then'](function(_0x5d349e){_0x3e699e=_[_0xab5f('0x9a')](_0x5d349e,'id');_0x12430f=_[_0xab5f('0x9b')](_0x12430f,{'model':db[_0xab5f('0x9c')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x141a34[_0xab5f('0x3f')][_0xab5f('0x44')]){_0x1d1f7d[_0xab5f('0x43')]['forEach'](function(_0x32c470){_0x85fd96[_0xab5f('0x49')]('i.'+_0x32c470);});}else{_0x85fd96[_0xab5f('0x49')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xab5f('0x60'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0x9d'),_0xab5f('0x9e'));_0x85fd96[_0xab5f('0x49')]('a.mandatoryDisposition',_0xab5f('0x9f'));_0x85fd96[_0xab5f('0x49')]('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',_0xab5f('0x8f'));_0x85fd96[_0xab5f('0x49')]('i.*');_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa0'),_0xab5f('0xa1'));_0x85fd96['field']('c.lastName',_0xab5f('0xa2'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa3'),_0xab5f('0xa4'));_0x85fd96['field'](_0xab5f('0xa5'),'Contact.phone');_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa6'),_0xab5f('0xa7'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xa8'),_0xab5f('0xa9'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xaa'),_0xab5f('0xab'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xac'),_0xab5f('0xad'));_0x85fd96[_0xab5f('0x49')](_0xab5f('0xae'),_0xab5f('0x2d'));}if(_0x1d1f7d[_0xab5f('0x22')])_0x85fd96[_0xab5f('0x22')](_0x1d1f7d['limit']);if(_0x1d1f7d[_0xab5f('0x20')])_0x85fd96['offset'](_0x1d1f7d[_0xab5f('0x20')]);return db[_0xab5f('0x99')]['query'](_0x85fd96[_0xab5f('0xaf')](),_0x12430f);})[_0xab5f('0x28')](function(_0x22b3d9){if(_0x22b3d9[_0xab5f('0x5e')]>0x0)_0x5f1018[_0xab5f('0x7b')](_0xab5f('0xb0'),_[_0xab5f('0x3a')](_0x22b3d9,'id'));return db[_0xab5f('0x99')][_0xab5f('0x3f')](_0x5f1018[_0xab5f('0xaf')](),_0x12430f)[_0xab5f('0x28')](function(_0x2fbc0f){var _0x323cd8=_[_0xab5f('0xb1')](_0x2fbc0f,_0xab5f('0xb2'));var _0x3f54f7=[];_0x22b3d9[_0xab5f('0x76')](function(_0x43e7f8){_0x3f54f7[_0xab5f('0x30')](updateWhatsappInteraction(_0x43e7f8,_0x3e699e,_0x323cd8));});return BPromise[_0xab5f('0xb3')](_0x3f54f7);});});})['then'](function(_0x5b2035){_0x484fde[_0xab5f('0xb4')]=_0x5b2035;return _0x484fde;})[_0xab5f('0x28')](respondWithFilteredResult(_0x41184c,_0x1d1f7d))[_0xab5f('0x31')](handleError(_0x41184c,null));};exports['show']=function(_0x24cd3c,_0x3dab9a){var _0xe05cfd={'raw':![],'where':{'id':_0x24cd3c[_0xab5f('0xb5')]['id']}},_0x12e073={};_0x12e073['model']=_['keys'](db[_0xab5f('0x9c')][_0xab5f('0x3b')]);_0x12e073['query']=_['keys'](_0x24cd3c[_0xab5f('0x3f')]);_0x12e073[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0x12e073[_0xab5f('0x3e')],_0x12e073['query']);_0xe05cfd[_0xab5f('0x43')]=_['intersection'](_0x12e073[_0xab5f('0x3e')],qs[_0xab5f('0x44')](_0x24cd3c[_0xab5f('0x3f')][_0xab5f('0x44')]));_0xe05cfd[_0xab5f('0x43')]=_0xe05cfd[_0xab5f('0x43')][_0xab5f('0x5e')]?_0xe05cfd['attributes']:_0x12e073[_0xab5f('0x3e')];if(_0x24cd3c[_0xab5f('0x3f')][_0xab5f('0xb6')]){_0xe05cfd['include']=[{'all':!![]}];}_0xe05cfd=_[_0xab5f('0x9b')]({},_0xe05cfd,_0x24cd3c[_0xab5f('0xb7')]);return db[_0xab5f('0x9c')][_0xab5f('0x5f')](_0xe05cfd)[_0xab5f('0x28')](handleEntityNotFound(_0x3dab9a,null))[_0xab5f('0x28')](respondWithResult(_0x3dab9a,null))[_0xab5f('0x31')](handleError(_0x3dab9a,null));};exports['create']=function(_0x3e57c6,_0x18ff4e){return db[_0xab5f('0x9c')][_0xab5f('0xb8')](_0x3e57c6[_0xab5f('0x72')],{})[_0xab5f('0x28')](respondWithResult(_0x18ff4e,0xc9))['catch'](handleError(_0x18ff4e,null));};exports['update']=function(_0x17fd76,_0x1b419c){if(_0x17fd76[_0xab5f('0x72')]['id']){delete _0x17fd76[_0xab5f('0x72')]['id'];}return db['WhatsappInteraction'][_0xab5f('0x5f')]({'where':{'id':_0x17fd76['params']['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x1b419c,null))[_0xab5f('0x28')](saveUpdates(_0x17fd76[_0xab5f('0x72')],null))[_0xab5f('0x28')](respondWithResult(_0x1b419c,null))[_0xab5f('0x31')](handleError(_0x1b419c,null));};exports['destroy']=function(_0x52a486,_0x595b26){return db['WhatsappInteraction'][_0xab5f('0x5f')]({'where':{'id':_0x52a486['params']['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x595b26,null))[_0xab5f('0x28')](removeEntity(_0x595b26,null))[_0xab5f('0x31')](handleError(_0x595b26,null));};exports[_0xab5f('0xb9')]=function(_0x217a50,_0xfa5759){return db['WhatsappInteraction']['describe']()[_0xab5f('0x28')](respondWithResult(_0xfa5759,null))[_0xab5f('0x31')](handleError(_0xfa5759,null));};exports['addMessage']=function(_0x303f60,_0x46e581,_0x176553){return db[_0xab5f('0xba')][_0xab5f('0x5f')]({'where':{'id':_0x303f60[_0xab5f('0xb5')]['id']}})[_0xab5f('0x28')](handleEntityNotFound(_0x46e581,null))[_0xab5f('0x28')](function(_0x1cce17){if(_0x1cce17){return _0x1cce17[_0xab5f('0xbb')](_0x303f60[_0xab5f('0x72')][_0xab5f('0xbc')],_[_0xab5f('0xbd')](_0x303f60[_0xab5f('0x72')],[_0xab5f('0xbc'),'id'])||{});}})[_0xab5f('0x28')](respondWithResult(_0x46e581,null))['catch'](handleError(_0x46e581,null));};exports[_0xab5f('0xbe')]=function(_0x1a5a12,_0x2a7196,_0x34d741){var _0x5ce2a2={'raw':![],'where':{}};var _0xe88324={};var _0x2d0cee={'count':0x0,'rows':[]};return db[_0xab5f('0x9c')]['findOne']({'where':{'id':_0x1a5a12[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x2a7196,null))[_0xab5f('0x28')](function(_0x23a906){if(_0x23a906){_0xe88324['model']=_[_0xab5f('0x40')](db['WhatsappMessage'][_0xab5f('0x3b')]);_0xe88324[_0xab5f('0x3f')]=_[_0xab5f('0x40')](_0x1a5a12[_0xab5f('0x3f')]);_0xe88324[_0xab5f('0x41')]=_[_0xab5f('0x42')](_0xe88324[_0xab5f('0x3e')],_0xe88324[_0xab5f('0x3f')]);_0x5ce2a2[_0xab5f('0x43')]=_[_0xab5f('0x42')](_0xe88324[_0xab5f('0x3e')],qs['fields'](_0x1a5a12['query'][_0xab5f('0x44')]));_0x5ce2a2['attributes']=_0x5ce2a2[_0xab5f('0x43')][_0xab5f('0x5e')]?_0x5ce2a2['attributes']:_0xe88324[_0xab5f('0x3e')];if(!_0x1a5a12[_0xab5f('0x3f')]['hasOwnProperty'](_0xab5f('0xbf'))){_0x5ce2a2['limit']=qs[_0xab5f('0x22')](_0x1a5a12[_0xab5f('0x3f')]['limit']);_0x5ce2a2[_0xab5f('0x20')]=qs[_0xab5f('0x20')](_0x1a5a12[_0xab5f('0x3f')]['offset']);}_0x5ce2a2[_0xab5f('0x8e')]=qs[_0xab5f('0x46')](_0x1a5a12['query'][_0xab5f('0x46')]);_0x5ce2a2[_0xab5f('0x7b')]=qs[_0xab5f('0x41')](_[_0xab5f('0x47')](_0x1a5a12[_0xab5f('0x3f')],_0xe88324[_0xab5f('0x41')]));_0x5ce2a2[_0xab5f('0x7b')][_0xab5f('0xb2')]=_0x23a906['id'];if(_0x1a5a12['query'][_0xab5f('0x84')]){_0x5ce2a2[_0xab5f('0x7b')]=_[_0xab5f('0x9b')](_0x5ce2a2[_0xab5f('0x7b')],{'$or':_[_0xab5f('0x3a')](_0x5ce2a2[_0xab5f('0x43')],function(_0xae2ddb){var _0x2924f9={};_0x2924f9[_0xae2ddb]={'$like':'%'+_0x1a5a12[_0xab5f('0x3f')]['filter']+'%'};return _0x2924f9;})});}if(_0x1a5a12['query']['$gte']){var _0x3efd43=_0x1a5a12['query'][_0xab5f('0x79')][_0xab5f('0x2f')](',');var _0x3ed2a8={};_0x3ed2a8[_0x3efd43[0x0]]={'$gte':moment(_0x3efd43[0x1])[_0xab5f('0xc0')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5ce2a2[_0xab5f('0x7b')]=_['merge'](_0x5ce2a2[_0xab5f('0x7b')],_0x3ed2a8);}_0x5ce2a2=_[_0xab5f('0x9b')]({},_0x5ce2a2,_0x1a5a12['options']);return db[_0xab5f('0xba')]['count']({'where':_0x5ce2a2[_0xab5f('0x7b')]})[_0xab5f('0x28')](function(_0x505047){_0x2d0cee[_0xab5f('0x23')]=_0x505047;if(_0x1a5a12['query']['includeAll']){_0x5ce2a2['include']=[{'all':!![]}];}return db[_0xab5f('0xba')][_0xab5f('0xc1')](_0x5ce2a2);})[_0xab5f('0x28')](function(_0x1f9abf){_0x2d0cee[_0xab5f('0xb4')]=_0x1f9abf;return _0x2d0cee;});}})[_0xab5f('0x28')](respondWithFilteredResult(_0x2a7196,_0x5ce2a2))[_0xab5f('0x31')](handleError(_0x2a7196,null));};exports['addTags']=function(_0x10c60d,_0x4be3c4,_0x4da443){return db[_0xab5f('0x9c')]['find']({'where':{'id':_0x10c60d[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x4be3c4,null))[_0xab5f('0x28')](function(_0x2eb968){if(_0x2eb968){return _0x2eb968[_0xab5f('0xc2')](_0x10c60d[_0xab5f('0x72')][_0xab5f('0xbc')],_[_0xab5f('0xbd')](_0x10c60d[_0xab5f('0x72')],[_0xab5f('0xbc'),'id'])||{})['spread'](function(){return db[_0xab5f('0x6d')][_0xab5f('0xc1')]({'attributes':['id','name','color'],'where':{'id':_0x10c60d[_0xab5f('0x72')][_0xab5f('0xbc')]}});})[_0xab5f('0x28')](function(_0x11ab73){socket[_0xab5f('0xc3')](_0xab5f('0xc4'),{'id':Number(_0x10c60d[_0xab5f('0xb5')]['id']),'tags':_0x11ab73||[]});return{'id':Number(_0x10c60d[_0xab5f('0xb5')]['id']),'tags':_0x11ab73||[]};});}})[_0xab5f('0x28')](respondWithResult(_0x4be3c4,null))[_0xab5f('0x31')](handleError(_0x4be3c4,null));};exports[_0xab5f('0xc5')]=function(_0x5dc376,_0x332556,_0x1f4e9b){return db[_0xab5f('0x9c')][_0xab5f('0x5f')]({'where':{'id':_0x5dc376[_0xab5f('0xb5')]['id']}})['then'](handleEntityNotFound(_0x332556,null))[_0xab5f('0x28')](function(_0x3b1a93){if(_0x3b1a93){return _0x3b1a93[_0xab5f('0xc5')](_0x5dc376[_0xab5f('0x3f')][_0xab5f('0xbc')]);}})[_0xab5f('0x28')](respondWithStatusCode(_0x332556,null))[_0xab5f('0x31')](handleError(_0x332556,null));};exports[_0xab5f('0xc6')]=function(_0x562b48,_0xb29308){var _0x544cfb=moment()['unix']()[_0xab5f('0xaf')]();var _0x46e175=path['join'](config[_0xab5f('0xc7')],_0xab5f('0xc8'),_0xab5f('0xc9'),_0xab5f('0xca'));var _0x1d1c17=path[_0xab5f('0xcb')](config[_0xab5f('0xc7')],'server',_0xab5f('0xc9'),_0xab5f('0xcc'));var _0x172b67=path[_0xab5f('0xcb')](_0x46e175,_0x544cfb);var _0x56ddfa=util[_0xab5f('0xc0')](_0xab5f('0xcd'),_0x562b48[_0xab5f('0xb5')]['id'],_0x544cfb);var _0x5898d0=path[_0xab5f('0xcb')](_0x46e175,_0x56ddfa);var _0x4a09b4=[];_0x4a09b4['push']({'model':db['User'],'as':_0xab5f('0x6f'),'attributes':['id',_0xab5f('0xce')],'raw':!![]});_0x4a09b4[_0xab5f('0x30')]({'model':db[_0xab5f('0xcf')],'as':'Contact','attributes':['id',_0xab5f('0xd0'),'lastName'],'raw':!![]});if(_0x562b48[_0xab5f('0x3f')][_0xab5f('0xcc')]){_0x4a09b4[_0xab5f('0x30')]({'model':db[_0xab5f('0xd1')],'as':_0xab5f('0xd1'),'raw':!![]});}var _0x20ffaa=[{'model':db[_0xab5f('0xba')],'as':_0xab5f('0xd2'),'attributes':['id',_0xab5f('0x72'),_0xab5f('0x78'),_0xab5f('0xd3'),_0xab5f('0xd4'),_0xab5f('0x80')],'include':_0x4a09b4}];_0x20ffaa[_0xab5f('0x30')]({'model':db[_0xab5f('0xd5')],'as':_0xab5f('0xd6'),'attributes':['id',_0xab5f('0x2b')]});_0x20ffaa[_0xab5f('0x30')]({'model':db[_0xab5f('0x6f')],'as':_0xab5f('0xd7'),'attributes':['id',_0xab5f('0xce')]});return db[_0xab5f('0x9c')]['find']({'where':{'id':_0x562b48[_0xab5f('0xb5')]['id']},'include':_0x20ffaa})[_0xab5f('0x28')](handleEntityNotFound(_0xb29308,null))['then'](function(_0x115ef9){if(_0x115ef9){var _0x8ff3ac=_0x115ef9[_0xab5f('0xd8')]({'plain':!![]});fs[_0xab5f('0xd9')](_0x172b67);var _0x490af7={'channel':_0xab5f('0xda'),'account':_0x8ff3ac[_0xab5f('0xd6')][_0xab5f('0x2b')],'agent':_0x8ff3ac['Owner']?_0x8ff3ac[_0xab5f('0xd7')][_0xab5f('0xce')]:_0xab5f('0xdb'),'createdAt':moment(_0x8ff3ac[_0xab5f('0x78')])[_0xab5f('0xc0')](_0xab5f('0xdc'))[_0xab5f('0xaf')](),'closedAt':_0x8ff3ac[_0xab5f('0x38')]?moment(_0x8ff3ac[_0xab5f('0xdd')])[_0xab5f('0xc0')]('YYYY-MM-DD\x20HH:mm:ss')[_0xab5f('0xaf')]():'','disposition':_0x8ff3ac[_0xab5f('0xde')],'messages':_(_0x8ff3ac[_0xab5f('0xd2')])[_0xab5f('0x84')]({'secret':![]})['map'](function(_0xa331c){if(_0xa331c[_0xab5f('0xd1')]){var _0x3fb6fd=path[_0xab5f('0xcb')](_0x1d1c17,_0xa331c['Attachment']['basename']);if(fs[_0xab5f('0xdf')](_0x3fb6fd)){fs[_0xab5f('0xe0')](_0x3fb6fd)[_0xab5f('0xe1')](fs[_0xab5f('0xe2')](path[_0xab5f('0xcb')](_0x172b67,_0xa331c['Attachment'][_0xab5f('0xe3')])));}}return{'date':moment(_0xa331c[_0xab5f('0x78')])[_0xab5f('0xc0')](_0xab5f('0xdc'))[_0xab5f('0xaf')](),'sender':_0xa331c[_0xab5f('0xd3')]===_0xab5f('0xe4')?_0xa331c[_0xab5f('0x6f')]?_0xa331c[_0xab5f('0x6f')]['fullname']:_0xab5f('0xe5'):_0xa331c[_0xab5f('0x65')]['firstName']+(_0xa331c[_0xab5f('0x65')][_0xab5f('0xe6')]?'\x20'+_0xa331c[_0xab5f('0x65')][_0xab5f('0xe6')]:''),'body':_0xa331c[_0xab5f('0xd1')]?_0xa331c['Attachment'][_0xab5f('0xe3')]:_0xa331c[_0xab5f('0x72')],'direction':_0xa331c['direction']===_0xab5f('0xe4')?'A':'C','secret':_0xa331c[_0xab5f('0xd4')],'read':_0xa331c['read'],'attachment':_0xa331c[_0xab5f('0xd1')]};})['value']()};return ejs[_0xab5f('0xe7')](path[_0xab5f('0xcb')](config[_0xab5f('0xc7')],_0xab5f('0xc8'),_0xab5f('0xe8'),_0xab5f('0xe9')),{'interaction':_0x490af7})[_0xab5f('0x28')](function(_0xe3a487){var _0x2f61d8=path[_0xab5f('0xcb')](_0x172b67,_0xab5f('0xea')+_0x8ff3ac['id']+'-'+_0x544cfb+'.pdf');var _0x408566={'path':_0x2f61d8,'channel':_0xab5f('0xda'),'interactionId':_0x8ff3ac['id']};return pdf[_0xab5f('0xeb')](_0xe3a487,_0x408566);})[_0xab5f('0x28')](function(){return new BPromise(function(_0x3eb0ae,_0x195bcf){zipdir(_0x172b67,{'saveTo':_0x5898d0},function(_0x186440,_0x55e0df){if(_0x186440)return _0x195bcf(_0x186440);return _0x3eb0ae(_0x55e0df);});})[_0xab5f('0x28')](function(){return new BPromise(function(_0x32058f,_0x3d1ef7){rimraf(_0x172b67,function(_0x257dcb){if(_0x257dcb)_0x3d1ef7(_0x257dcb);return _0x32058f();});});})[_0xab5f('0x28')](function(){return _0xb29308[_0xab5f('0xc6')](_0x5898d0,_0x56ddfa,function(_0x580990){if(_0x580990){console[_0xab5f('0xec')](_0xab5f('0xed'),_0x580990);}else{fs[_0xab5f('0xee')](_0x5898d0);}});});});}else{return _0xb29308[_0xab5f('0x1c')](0xc8);}})[_0xab5f('0x31')](handleError(_0xb29308,null));};
\ No newline at end of file
+var _0x65cb=['left_join','from','whatsapp_interactions','cm_contacts','users','o.id\x20=\x20i.UserId','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','expr','search','parseSearch','sqlOperator','find','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)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','Tag','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','start','body','some','compact','isEmpty','WhatsappAccountId','where','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','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','Sequelize','QueryTypes','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','contactName','DESC','t.id\x20IN\x20?','resolve','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','i.WhatsappAccountId\x20IN\x20?','agent','sequelize','toString','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','Contact.firstName','c.lastName','c.email','Contact.email','Contact.phone','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','push','all','rows','show','params','include','options','create','destroy','describe','addMessage','WhatsappMessage','ids','omit','getMessages','findOne','pick','WhatsappInteractionId','YYYY-MM-DD\x20HH:mm:ss','includeAll','findAll','setTags','spread','emit','whatsappInteractionTags:save','download','unix','join','root','files','tmp','server','format','CmContact','firstName','lastName','Attachment','Messages','direction','secret','Account','Owner','get','mkdirSync','Whatsapp','N.A.','closedAt','disposition','basename','existsSync','createReadStream','createWriteStream','out','System','renderFile','downloadInteraction.ejs','.pdf','log','err','unlinkSync','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','end','sendStatus','error','name','map','fullname','Tags','TagIds','split','catch','waiting','talking','unmanaged','total','closed','UserId','answered','index','WhatsappInteraction','rawAttributes','type','key','query','keys','filters','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','order','sort','field','color','select'];(function(_0x1b00e8,_0x37cce9){var _0x523a49=function(_0x328180){while(--_0x328180){_0x1b00e8['push'](_0x1b00e8['shift']());}};_0x523a49(++_0x37cce9);}(_0x65cb,0xa4));var _0xb65c=function(_0x517e3b,_0x17d945){_0x517e3b=_0x517e3b-0x0;var _0x1dedf9=_0x65cb[_0x517e3b];return _0x1dedf9;};'use strict';var emlformat=require(_0xb65c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xb65c('0x1'));var jsonpatch=require(_0xb65c('0x2'));var rp=require(_0xb65c('0x3'));var moment=require('moment');var BPromise=require(_0xb65c('0x4'));var Mustache=require(_0xb65c('0x5'));var util=require(_0xb65c('0x6'));var path=require(_0xb65c('0x7'));var sox=require(_0xb65c('0x8'));var csv=require('to-csv');var ejs=require(_0xb65c('0x9'));var fs=require('fs');var fs_extra=require(_0xb65c('0xa'));var _=require(_0xb65c('0xb'));var squel=require(_0xb65c('0xc'));var crypto=require(_0xb65c('0xd'));var jsforce=require(_0xb65c('0xe'));var deskjs=require(_0xb65c('0xf'));var toCsv=require(_0xb65c('0x10'));var querystring=require('querystring');var Papa=require(_0xb65c('0x11'));var Redis=require(_0xb65c('0x12'));var authService=require(_0xb65c('0x13'));var qs=require(_0xb65c('0x14'));var as=require('../../components/parsers/advancedSearch');var pdf=require(_0xb65c('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb65c('0x16'))(_0xb65c('0x17'));var utils=require(_0xb65c('0x18'));var config=require(_0xb65c('0x19'));var licenseUtil=require(_0xb65c('0x1a'));var db=require(_0xb65c('0x1b'))['db'];config['redis']=_[_0xb65c('0x1c')](config[_0xb65c('0x1d')],{'host':_0xb65c('0x1e'),'port':0x18eb});var socket=require(_0xb65c('0x1f'))(new Redis(config[_0xb65c('0x1d')]));require(_0xb65c('0x20'))[_0xb65c('0x21')](socket);function respondWithStatusCode(_0x48c337,_0x3bd91d){_0x3bd91d=_0x3bd91d||0xcc;return function(_0x22eb85){if(_0x22eb85){return _0x48c337['sendStatus'](_0x3bd91d);}return _0x48c337[_0xb65c('0x22')](_0x3bd91d)['end']();};}function respondWithResult(_0x32f4b5,_0x20b28e){_0x20b28e=_0x20b28e||0xc8;return function(_0x2666e4){if(_0x2666e4){return _0x32f4b5[_0xb65c('0x22')](_0x20b28e)[_0xb65c('0x23')](_0x2666e4);}};}function respondWithFilteredResult(_0x396eb2,_0x1bca9d){return function(_0x203c7b){if(_0x203c7b){var _0x199b13=typeof _0x1bca9d[_0xb65c('0x24')]===_0xb65c('0x25')&&typeof _0x1bca9d[_0xb65c('0x26')]===_0xb65c('0x25');var _0x2a7c3d=_0x203c7b[_0xb65c('0x27')];var _0x48aedb=_0x199b13?0x0:_0x1bca9d[_0xb65c('0x24')];var _0x2733c6=_0x199b13?_0x203c7b[_0xb65c('0x27')]:_0x1bca9d[_0xb65c('0x24')]+_0x1bca9d[_0xb65c('0x26')];var _0xad9da4;if(_0x2733c6>=_0x2a7c3d){_0x2733c6=_0x2a7c3d;_0xad9da4=0xc8;}else{_0xad9da4=0xce;}_0x396eb2[_0xb65c('0x22')](_0xad9da4);return _0x396eb2[_0xb65c('0x28')](_0xb65c('0x29'),_0x48aedb+'-'+_0x2733c6+'/'+_0x2a7c3d)[_0xb65c('0x23')](_0x203c7b);}return null;};}function patchUpdates(_0x1730ad){return function(_0x30d735){try{jsonpatch[_0xb65c('0x2a')](_0x30d735,_0x1730ad,!![]);}catch(_0x33961d){return BPromise[_0xb65c('0x2b')](_0x33961d);}return _0x30d735[_0xb65c('0x2c')]();};}function saveUpdates(_0x108eb9,_0x4ad9e4){return function(_0xe6e1b0){if(_0xe6e1b0){return _0xe6e1b0[_0xb65c('0x2d')](_0x108eb9)[_0xb65c('0x2e')](function(_0x585f93){return _0x585f93;});}return null;};}function removeEntity(_0x1b7e00,_0x4c5627){return function(_0x49035e){if(_0x49035e){return _0x49035e['destroy']()[_0xb65c('0x2e')](function(){_0x1b7e00[_0xb65c('0x22')](0xcc)[_0xb65c('0x2f')]();});}};}function handleEntityNotFound(_0xc65b5a,_0x4a9b0c){return function(_0x22bf5b){if(!_0x22bf5b){_0xc65b5a[_0xb65c('0x30')](0x194);}return _0x22bf5b;};}function handleError(_0x3e372d,_0x21cb9c){_0x21cb9c=_0x21cb9c||0x1f4;return function(_0x1ffc77){logger[_0xb65c('0x31')](_0x1ffc77['stack']);if(_0x1ffc77[_0xb65c('0x32')]){delete _0x1ffc77[_0xb65c('0x32')];}_0x3e372d[_0xb65c('0x22')](_0x21cb9c)['send'](_0x1ffc77);};}function getInteractionUsers(_0x44fe3b,_0x5f5ca7){return new BPromise(function(_0x393320,_0x1284cd){try{if(_0x5f5ca7[_0x44fe3b['id']]){_0x44fe3b['Users']=_[_0xb65c('0x33')](_0x5f5ca7[_0x44fe3b['id']],function(_0x472bb7){return{'id':_0x472bb7['id'],'fullname':_0x472bb7[_0xb65c('0x34')]};});}}catch(_0xa6b257){_0x1284cd(_0xa6b257);}_0x393320(_0x44fe3b);});}function getInteractionTags(_0x1b3240,_0x2f33bc){return new BPromise(function(_0x358d20,_0x2153c8){try{if(_0x1b3240['TagIds']){_0x1b3240[_0xb65c('0x35')]=[];_0x1b3240[_0xb65c('0x36')][_0xb65c('0x37')](',')['forEach'](function(_0x4d9959){_0x1b3240[_0xb65c('0x35')]['push'](_0x2f33bc[_0x4d9959]);});}delete _0x1b3240[_0xb65c('0x36')];}catch(_0x52fe04){_0x2153c8(_0x52fe04);}_0x358d20(_0x1b3240);});}function updateWhatsappInteraction(_0x34c7c1,_0x387a60,_0x22f1ae){return new BPromise(function(_0x13deeb,_0x5dff9c){return getInteractionUsers(_0x34c7c1,_0x22f1ae)[_0xb65c('0x2e')](function(_0x590520){return getInteractionTags(_0x590520,_0x387a60);})[_0xb65c('0x2e')](function(_0x560c3f){return getStateInteraction(_0x560c3f);})[_0xb65c('0x2e')](function(_0x4070ea){_0x13deeb(_0x4070ea);})[_0xb65c('0x38')](function(_0x2b9c85){_0x5dff9c(_0x2b9c85);});});}function getStateInteraction(_0x5e375b){return new BPromise(function(_0x2ec9f5){_0x5e375b[_0xb65c('0x39')]=0x0;_0x5e375b[_0xb65c('0x3a')]=0x0;_0x5e375b['answered']=0x0;_0x5e375b[_0xb65c('0x3b')]=0x0;_0x5e375b[_0xb65c('0x3c')]=0x0;if(!_0x5e375b['closed']&&!_0x5e375b['UserId']){_0x5e375b[_0xb65c('0x39')]+=0x1;}if(!_0x5e375b[_0xb65c('0x3d')]&&_0x5e375b[_0xb65c('0x3e')]){_0x5e375b[_0xb65c('0x3a')]+=0x1;if(_0x5e375b['waiting']){_0x5e375b[_0xb65c('0x39')]-=0x1;}}if(_0x5e375b[_0xb65c('0x3d')]&&_0x5e375b[_0xb65c('0x3e')]){_0x5e375b[_0xb65c('0x3f')]+=0x1;if(_0x5e375b['talking']){_0x5e375b[_0xb65c('0x3a')]-=0x1;}}if(_0x5e375b[_0xb65c('0x3d')]&&!_0x5e375b[_0xb65c('0x3e')]){_0x5e375b[_0xb65c('0x3b')]+=0x1;if(_0x5e375b[_0xb65c('0x39')]){_0x5e375b[_0xb65c('0x39')]-=0x1;}}_0x5e375b[_0xb65c('0x3c')]+=0x1;_0x2ec9f5(_0x5e375b);});}exports[_0xb65c('0x40')]=function(_0xc83cb3,_0x338e36){var _0x765981={},_0x16c859={},_0x244362={'count':0x0,'rows':[]};var _0x5b7d0f=_['map'](db[_0xb65c('0x41')][_0xb65c('0x42')],function(_0x298edd){return{'name':_0x298edd['fieldName'],'type':_0x298edd[_0xb65c('0x43')][_0xb65c('0x44')]};});_0x16c859['model']=_['map'](_0x5b7d0f,_0xb65c('0x32'));_0x16c859[_0xb65c('0x45')]=_[_0xb65c('0x46')](_0xc83cb3[_0xb65c('0x45')]);_0x16c859[_0xb65c('0x47')]=_[_0xb65c('0x48')](_0x16c859['model'],_0x16c859[_0xb65c('0x45')]);_0x765981[_0xb65c('0x49')]=_[_0xb65c('0x48')](_0x16c859[_0xb65c('0x4a')],qs[_0xb65c('0x4b')](_0xc83cb3[_0xb65c('0x45')]['fields']));_0x765981[_0xb65c('0x49')]=_0x765981[_0xb65c('0x49')][_0xb65c('0x4c')]?_0x765981[_0xb65c('0x49')]:_0x16c859[_0xb65c('0x4a')];if(!_0xc83cb3['query'][_0xb65c('0x4d')](_0xb65c('0x4e'))){_0x765981[_0xb65c('0x26')]=qs[_0xb65c('0x26')](_0xc83cb3[_0xb65c('0x45')]['limit']);_0x765981['offset']=qs[_0xb65c('0x24')](_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x24')]);}_0x765981[_0xb65c('0x4f')]=qs['sort'](_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x50')]);_0x765981['where']=qs[_0xb65c('0x47')](_['pick'](_0xc83cb3[_0xb65c('0x45')],_0x16c859[_0xb65c('0x47')]),_0x5b7d0f);var _0x2ad35c=[];var _0x1af087=squel['select']()[_0xb65c('0x51')]('id')[_0xb65c('0x51')](_0xb65c('0x32'))[_0xb65c('0x51')](_0xb65c('0x52'))['from']('tools_tags');var _0x1657b6=squel[_0xb65c('0x53')]()[_0xb65c('0x51')]('u.id')[_0xb65c('0x51')]('u.fullname')[_0xb65c('0x51')]('ui.WhatsappInteractionId')['from']('user_has_whatsapp_interactions','ui')[_0xb65c('0x54')]('users','u','u.id\x20=\x20ui.UserId');var _0x41664f=squel[_0xb65c('0x53')]()[_0xb65c('0x55')](_0xb65c('0x56'),'i')[_0xb65c('0x54')](_0xb65c('0x57'),'c','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL')['left_join'](_0xb65c('0x58'),'o',_0xb65c('0x59'))['left_join'](_0xb65c('0x5a'),'a',_0xb65c('0x5b'))[_0xb65c('0x54')]('whatsapp_messages','me',_0xb65c('0x5c'))['left_join'](_0xb65c('0x5d'),'it',_0xb65c('0x5e'))[_0xb65c('0x54')]('tools_tags','t','t.id\x20=\x20it.TagId');var _0x852886=squel[_0xb65c('0x5f')]();var _0x3e5972=[];var _0x5bca91=squel[_0xb65c('0x5f')]();var _0x42b32e;if(_0xc83cb3['query'][_0xb65c('0x60')]){_0x42b32e=as[_0xb65c('0x61')](_0xc83cb3['query'][_0xb65c('0x60')]);var _0x3e461d=_0x42b32e[_0xb65c('0x62')];for(var _0x74cebb=0x0;_0x74cebb<_0x42b32e['conditions'][_0xb65c('0x4c')];_0x74cebb++){var _0x56da01=_0x42b32e['conditions'][_0x74cebb];var _0x395a9c='i';var _0x129c81=_[_0xb65c('0x63')](_0x5b7d0f,[_0xb65c('0x32'),_0x56da01[_0xb65c('0x51')]]);if(!_0x129c81){switch(_0x56da01[_0xb65c('0x51')]){case _0xb65c('0x64'):if(_0x56da01[_0xb65c('0x65')]==0x1){_0x41664f[_0xb65c('0x66')]('`'+_0x56da01['field']+_0xb65c('0x67'));}else{_0x41664f['having']('`'+_0x56da01[_0xb65c('0x51')]+_0xb65c('0x68'));}break;case _0xb65c('0x69'):if(_0x56da01[_0xb65c('0x6a')]==='$substring'){if(_0x56da01['value']['split']('\x20')['length']>0x1){_0x852886[_0x3e461d](_0xb65c('0x6b'),qs['getFullTextValue'](_0x56da01['value']),null);}else{var _0x49fc78='%'+_0x56da01[_0xb65c('0x65')]+'%';_0x852886[_0x3e461d](_0xb65c('0x6c'),_0x49fc78,_0x49fc78,_0x49fc78);}}else{_0x129c81=_['find'](_0x5b7d0f,[_0xb65c('0x32'),_0xb65c('0x6d')]);_0x56da01['field']='ContactId';_0x3dcc4b=as[_0xb65c('0x6e')](_0x395a9c,_0x129c81[_0xb65c('0x43')],_0x56da01);_0x852886[_0x3e461d](_0x3dcc4b[_0xb65c('0x6f')],_0x3dcc4b[_0xb65c('0x65')]['start'],_0x3dcc4b[_0xb65c('0x65')]['end']);}break;case _0xb65c('0x70'):var _0x4f4822=_0x56da01[_0xb65c('0x65')]['split'](',')[_0xb65c('0x33')](function(_0xbb88c6){return Number(_0xbb88c6);});_0x4f4822[_0xb65c('0x71')](function(_0x465d03){_0x5bca91['or'](_0xb65c('0x72'),'%,'+_0x465d03+',%');});_0x3e5972=_[_0xb65c('0x73')](_0x3e5972,_0x4f4822);break;case _0xb65c('0x74'):if(_0x56da01['operator']==='$substring'){_0x852886[_0x3e461d](_0xb65c('0x75'),'%'+_0x56da01[_0xb65c('0x65')]+'%',null);}else{_0x129c81=_['find'](_0x5b7d0f,[_0xb65c('0x32'),_0xb65c('0x3e')]);_0x56da01[_0xb65c('0x51')]='UserId';_0x3dcc4b=as[_0xb65c('0x6e')](_0x395a9c,_0x129c81[_0xb65c('0x43')],_0x56da01);_0x852886[_0x3e461d](_0x3dcc4b[_0xb65c('0x6f')],_0x3dcc4b['value'][_0xb65c('0x76')],_0x3dcc4b[_0xb65c('0x65')][_0xb65c('0x2f')]);}break;case _0xb65c('0x77'):_0x3dcc4b=as['buildExpression']('me',null,_0x56da01);_0x852886[_0x3e461d](_0x3dcc4b['text'],_0x3dcc4b[_0xb65c('0x65')]['start'],_0x3dcc4b[_0xb65c('0x65')][_0xb65c('0x2f')]);break;}}else{var _0x3dcc4b=as[_0xb65c('0x6e')](_0x395a9c,_0x129c81[_0xb65c('0x43')],_0x56da01);_0x852886[_0x3e461d](_0x3dcc4b[_0xb65c('0x6f')],_0x3dcc4b[_0xb65c('0x65')][_0xb65c('0x76')],_0x3dcc4b['value'][_0xb65c('0x2f')]);}}}else{var _0x593af0=_(_0xc83cb3[_0xb65c('0x45')])[_0xb65c('0x46')]()[_0xb65c('0x33')](function(_0x4c9877){return _[_0xb65c('0x78')](_0x5b7d0f,[_0xb65c('0x32'),_0x4c9877])?_0x4c9877:undefined;})[_0xb65c('0x79')]()[_0xb65c('0x65')]();if(!_[_0xb65c('0x7a')](_0x593af0)){_0x593af0[_0xb65c('0x71')](function(_0xb949fd){if(_0xb949fd===_0xb65c('0x7b')){_0x41664f[_0xb65c('0x7c')]('i.WhatsappAccountId\x20IN\x20?',[][_0xb65c('0x7d')](_0xc83cb3[_0xb65c('0x45')][_0xb949fd]));}else if(_0xb949fd===_0xb65c('0x7e')){var _0x10eaff=JSON[_0xb65c('0x7f')](_0xc83cb3[_0xb65c('0x45')][_0xb949fd])[_0xb65c('0x80')];var _0x47962d=JSON['parse'](_0xc83cb3[_0xb65c('0x45')][_0xb949fd])[_0xb65c('0x81')];_0x41664f['where'](_0xb65c('0x82'),_0x10eaff,_0x47962d);}else{if(_0xc83cb3[_0xb65c('0x45')][_0xb949fd]===_0xb65c('0x83')){_0x41664f[_0xb65c('0x7c')]('i.'+_0xb949fd+_0xb65c('0x84'));}else{_0x41664f[_0xb65c('0x7c')]('i.'+_0xb949fd+_0xb65c('0x85'),_0xc83cb3[_0xb65c('0x45')][_0xb949fd]);}}});}if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x86')]){if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x86')]==0x1){_0x41664f[_0xb65c('0x66')](_0xb65c('0x87'));}else{_0x41664f[_0xb65c('0x66')](_0xb65c('0x88'));}}if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x89')]){_0x3e5972=_[_0xb65c('0x8a')](_0xc83cb3[_0xb65c('0x45')]['tag'])?_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x89')]:new Array(_0xc83cb3['query']['tag']);_0x3e5972[_0xb65c('0x71')](function(_0x292eec){_0x5bca91['or'](_0xb65c('0x72'),'%,'+_0x292eec+',%');});}if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x8b')]){var _0xfae7f1=_0xc83cb3[_0xb65c('0x45')]['filter'][_0xb65c('0x8c')]('\x5c','\x5c\x5c')[_0xb65c('0x8c')](/'/g,'\x27\x27');if(qs['isNumeric'](_0xfae7f1)){_0x852886['or'](_0xb65c('0x8d'),_0xfae7f1+'%')['or'](_0xb65c('0x8e'),_0xfae7f1+'%');}else{_0x852886['or'](_0xb65c('0x8f'),qs['getFullTextValue'](_0xfae7f1))['or'](_0xb65c('0x90'),_0xfae7f1+'%');}}}_0x41664f['where'](_0x852886);_0x41664f['group'](_0xb65c('0x91'));var _0x2a052e={'type':db[_0xb65c('0x92')][_0xb65c('0x93')][_0xb65c('0x94')],'raw':!![]};var _0x44cb52=_0x41664f[_0xb65c('0x95')]();_0x44cb52['field'](_0xb65c('0x91'));_0x44cb52['field'](_0xb65c('0x96'),_0xb65c('0x64'));if(_0x765981[_0xb65c('0x4f')]){_0x765981[_0xb65c('0x4f')]['forEach'](function(_0x59f5f6){var _0x5f4d98=_0x59f5f6[0x0]===_0xb65c('0x97')?_0x59f5f6[0x0]:'i.'+_0x59f5f6[0x0];_0x41664f['order'](_0x5f4d98,_0x59f5f6[0x1]===_0xb65c('0x98')?![]:!![]);});}if(!_[_0xb65c('0x7a')](_0x3e5972)){_0x41664f[_0xb65c('0x66')](_0x5bca91);_0x44cb52[_0xb65c('0x7c')](_0xb65c('0x99'),_0x3e5972);}BPromise[_0xb65c('0x9a')]()[_0xb65c('0x2e')](function(){if(!_0x42b32e){if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x7b')])return;_0x44cb52[_0xb65c('0x7c')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');_0x41664f[_0xb65c('0x7c')](_0xb65c('0x9b'));return;}if(_0xc83cb3[_0xb65c('0x9c')][_0xb65c('0x9d')]!=='agent')return;return _0xc83cb3[_0xb65c('0x9c')][_0xb65c('0x9e')]({'attributes':['id'],'raw':!![]})[_0xb65c('0x2e')](function(_0x318edf){if(_[_0xb65c('0x7a')](_0x318edf)){_0x44cb52[_0xb65c('0x7c')](_0xb65c('0x9f'));_0x41664f[_0xb65c('0x7c')](_0xb65c('0x9f'));}else{_0x44cb52[_0xb65c('0x7c')]('i.WhatsappAccountId\x20IN\x20?',_[_0xb65c('0x33')](_0x318edf,'id'));_0x41664f[_0xb65c('0x7c')](_0xb65c('0xa0'),_['map'](_0x318edf,'id'));}});})[_0xb65c('0x2e')](function(){if(_0xc83cb3[_0xb65c('0x9c')][_0xb65c('0x9d')]===_0xb65c('0xa1')&&!_0x42b32e&&!_0xc83cb3['query'][_0xb65c('0x7b')])return[];return db[_0xb65c('0xa2')][_0xb65c('0x45')](_0x44cb52[_0xb65c('0xa3')](),_0x2a052e);})[_0xb65c('0x2e')](function(_0x32f631){_0x244362[_0xb65c('0x27')]=_0x32f631[_0xb65c('0x4c')];if(_0x244362[_0xb65c('0x27')]===0x0)return[];return db['sequelize'][_0xb65c('0x45')](_0x1af087[_0xb65c('0xa3')](),_0x2a052e)[_0xb65c('0x2e')](function(_0x5d09d4){_0x2ad35c=_[_0xb65c('0xa4')](_0x5d09d4,'id');_0x2a052e=_[_0xb65c('0xa5')](_0x2a052e,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0xc83cb3[_0xb65c('0x45')][_0xb65c('0x4b')]){_0x765981[_0xb65c('0x49')]['forEach'](function(_0x172964){_0x41664f['field']('i.'+_0x172964);});}else{_0x41664f[_0xb65c('0x51')](_0xb65c('0x96'),_0xb65c('0x64'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xa6'),_0xb65c('0xa7'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xa8'),_0xb65c('0xa9'));_0x41664f['field'](_0xb65c('0xaa'),_0xb65c('0x97'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xab'));_0x41664f['field'](_0xb65c('0xac'),_0xb65c('0xad'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xae'),'Contact.lastName');_0x41664f[_0xb65c('0x51')](_0xb65c('0xaf'),_0xb65c('0xb0'));_0x41664f[_0xb65c('0x51')]('c.phone',_0xb65c('0xb1'));_0x41664f[_0xb65c('0x51')]('c.mobile',_0xb65c('0xb2'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xb3'),_0xb65c('0xb4'));_0x41664f['field'](_0xb65c('0xb5'),_0xb65c('0xb6'));_0x41664f[_0xb65c('0x51')](_0xb65c('0xb7'),_0xb65c('0xb8'));_0x41664f['field'](_0xb65c('0xb9'),_0xb65c('0x36'));}if(_0x765981[_0xb65c('0x26')])_0x41664f[_0xb65c('0x26')](_0x765981[_0xb65c('0x26')]);if(_0x765981['offset'])_0x41664f[_0xb65c('0x24')](_0x765981['offset']);return db[_0xb65c('0xa2')]['query'](_0x41664f[_0xb65c('0xa3')](),_0x2a052e);})['then'](function(_0x5d506f){if(_0x5d506f[_0xb65c('0x4c')]>0x0)_0x1657b6[_0xb65c('0x7c')](_0xb65c('0xba'),_[_0xb65c('0x33')](_0x5d506f,'id'));return db[_0xb65c('0xa2')][_0xb65c('0x45')](_0x1657b6[_0xb65c('0xa3')](),_0x2a052e)['then'](function(_0x498b0d){var _0x3c63de=_[_0xb65c('0xbb')](_0x498b0d,'WhatsappInteractionId');var _0x59204e=[];_0x5d506f['forEach'](function(_0x37dc65){_0x59204e[_0xb65c('0xbc')](updateWhatsappInteraction(_0x37dc65,_0x2ad35c,_0x3c63de));});return BPromise[_0xb65c('0xbd')](_0x59204e);});});})[_0xb65c('0x2e')](function(_0x4e7804){_0x244362[_0xb65c('0xbe')]=_0x4e7804;return _0x244362;})[_0xb65c('0x2e')](respondWithFilteredResult(_0x338e36,_0x765981))[_0xb65c('0x38')](handleError(_0x338e36,null));};exports[_0xb65c('0xbf')]=function(_0x8a1a1b,_0x223515){var _0x2ee077={'raw':![],'where':{'id':_0x8a1a1b[_0xb65c('0xc0')]['id']}},_0x475b50={};_0x475b50[_0xb65c('0x4a')]=_[_0xb65c('0x46')](db[_0xb65c('0x41')][_0xb65c('0x42')]);_0x475b50['query']=_[_0xb65c('0x46')](_0x8a1a1b[_0xb65c('0x45')]);_0x475b50[_0xb65c('0x47')]=_[_0xb65c('0x48')](_0x475b50[_0xb65c('0x4a')],_0x475b50['query']);_0x2ee077['attributes']=_[_0xb65c('0x48')](_0x475b50[_0xb65c('0x4a')],qs[_0xb65c('0x4b')](_0x8a1a1b[_0xb65c('0x45')]['fields']));_0x2ee077[_0xb65c('0x49')]=_0x2ee077['attributes'][_0xb65c('0x4c')]?_0x2ee077[_0xb65c('0x49')]:_0x475b50['model'];if(_0x8a1a1b[_0xb65c('0x45')]['includeAll']){_0x2ee077[_0xb65c('0xc1')]=[{'all':!![]}];}_0x2ee077=_['merge']({},_0x2ee077,_0x8a1a1b[_0xb65c('0xc2')]);return db['WhatsappInteraction'][_0xb65c('0x63')](_0x2ee077)['then'](handleEntityNotFound(_0x223515,null))[_0xb65c('0x2e')](respondWithResult(_0x223515,null))['catch'](handleError(_0x223515,null));};exports[_0xb65c('0xc3')]=function(_0x4dcc70,_0x141701){return db[_0xb65c('0x41')][_0xb65c('0xc3')](_0x4dcc70[_0xb65c('0x77')],{})[_0xb65c('0x2e')](respondWithResult(_0x141701,0xc9))[_0xb65c('0x38')](handleError(_0x141701,null));};exports[_0xb65c('0x2d')]=function(_0x4d4352,_0x25326f){if(_0x4d4352[_0xb65c('0x77')]['id']){delete _0x4d4352[_0xb65c('0x77')]['id'];}return db['WhatsappInteraction'][_0xb65c('0x63')]({'where':{'id':_0x4d4352[_0xb65c('0xc0')]['id']}})[_0xb65c('0x2e')](handleEntityNotFound(_0x25326f,null))['then'](saveUpdates(_0x4d4352['body'],null))[_0xb65c('0x2e')](respondWithResult(_0x25326f,null))[_0xb65c('0x38')](handleError(_0x25326f,null));};exports[_0xb65c('0xc4')]=function(_0x4d3cca,_0x1bfd59){return db['WhatsappInteraction']['find']({'where':{'id':_0x4d3cca[_0xb65c('0xc0')]['id']}})['then'](handleEntityNotFound(_0x1bfd59,null))[_0xb65c('0x2e')](removeEntity(_0x1bfd59,null))[_0xb65c('0x38')](handleError(_0x1bfd59,null));};exports[_0xb65c('0xc5')]=function(_0x16f45e,_0x488c03){return db[_0xb65c('0x41')][_0xb65c('0xc5')]()[_0xb65c('0x2e')](respondWithResult(_0x488c03,null))[_0xb65c('0x38')](handleError(_0x488c03,null));};exports[_0xb65c('0xc6')]=function(_0xa314d4,_0x53c9e6,_0x589058){return db[_0xb65c('0xc7')][_0xb65c('0x63')]({'where':{'id':_0xa314d4[_0xb65c('0xc0')]['id']}})['then'](handleEntityNotFound(_0x53c9e6,null))['then'](function(_0x5e5e32){if(_0x5e5e32){return _0x5e5e32['addMessage'](_0xa314d4[_0xb65c('0x77')][_0xb65c('0xc8')],_[_0xb65c('0xc9')](_0xa314d4[_0xb65c('0x77')],[_0xb65c('0xc8'),'id'])||{});}})[_0xb65c('0x2e')](respondWithResult(_0x53c9e6,null))[_0xb65c('0x38')](handleError(_0x53c9e6,null));};exports[_0xb65c('0xca')]=function(_0x2a054f,_0x5e552c,_0x4e1aec){var _0x95b7cf={'raw':![],'where':{}};var _0x2aea22={};var _0x59d31a={'count':0x0,'rows':[]};return db[_0xb65c('0x41')][_0xb65c('0xcb')]({'where':{'id':_0x2a054f[_0xb65c('0xc0')]['id']}})['then'](handleEntityNotFound(_0x5e552c,null))[_0xb65c('0x2e')](function(_0x2a5be3){if(_0x2a5be3){_0x2aea22[_0xb65c('0x4a')]=_[_0xb65c('0x46')](db['WhatsappMessage'][_0xb65c('0x42')]);_0x2aea22[_0xb65c('0x45')]=_['keys'](_0x2a054f[_0xb65c('0x45')]);_0x2aea22['filters']=_[_0xb65c('0x48')](_0x2aea22[_0xb65c('0x4a')],_0x2aea22[_0xb65c('0x45')]);_0x95b7cf[_0xb65c('0x49')]=_[_0xb65c('0x48')](_0x2aea22[_0xb65c('0x4a')],qs[_0xb65c('0x4b')](_0x2a054f[_0xb65c('0x45')]['fields']));_0x95b7cf[_0xb65c('0x49')]=_0x95b7cf[_0xb65c('0x49')][_0xb65c('0x4c')]?_0x95b7cf[_0xb65c('0x49')]:_0x2aea22[_0xb65c('0x4a')];if(!_0x2a054f[_0xb65c('0x45')][_0xb65c('0x4d')](_0xb65c('0x4e'))){_0x95b7cf[_0xb65c('0x26')]=qs[_0xb65c('0x26')](_0x2a054f[_0xb65c('0x45')][_0xb65c('0x26')]);_0x95b7cf[_0xb65c('0x24')]=qs['offset'](_0x2a054f['query'][_0xb65c('0x24')]);}_0x95b7cf[_0xb65c('0x4f')]=qs[_0xb65c('0x50')](_0x2a054f[_0xb65c('0x45')][_0xb65c('0x50')]);_0x95b7cf[_0xb65c('0x7c')]=qs['filters'](_[_0xb65c('0xcc')](_0x2a054f[_0xb65c('0x45')],_0x2aea22['filters']));_0x95b7cf['where'][_0xb65c('0xcd')]=_0x2a5be3['id'];if(_0x2a054f[_0xb65c('0x45')][_0xb65c('0x8b')]){_0x95b7cf['where']=_[_0xb65c('0xa5')](_0x95b7cf[_0xb65c('0x7c')],{'$or':_[_0xb65c('0x33')](_0x95b7cf['attributes'],function(_0x170db8){var _0xf4d98d={};_0xf4d98d[_0x170db8]={'$like':'%'+_0x2a054f['query'][_0xb65c('0x8b')]+'%'};return _0xf4d98d;})});}if(_0x2a054f[_0xb65c('0x45')][_0xb65c('0x80')]){var _0x8605ad=_0x2a054f['query'][_0xb65c('0x80')][_0xb65c('0x37')](',');var _0x4a97ae={};_0x4a97ae[_0x8605ad[0x0]]={'$gte':moment(_0x8605ad[0x1])['format'](_0xb65c('0xce'))};_0x95b7cf[_0xb65c('0x7c')]=_[_0xb65c('0xa5')](_0x95b7cf[_0xb65c('0x7c')],_0x4a97ae);}_0x95b7cf=_['merge']({},_0x95b7cf,_0x2a054f[_0xb65c('0xc2')]);return db['WhatsappMessage']['count']({'where':_0x95b7cf['where']})[_0xb65c('0x2e')](function(_0x75a2f4){_0x59d31a[_0xb65c('0x27')]=_0x75a2f4;if(_0x2a054f[_0xb65c('0x45')][_0xb65c('0xcf')]){_0x95b7cf[_0xb65c('0xc1')]=[{'all':!![]}];}return db['WhatsappMessage'][_0xb65c('0xd0')](_0x95b7cf);})[_0xb65c('0x2e')](function(_0x1cab7a){_0x59d31a[_0xb65c('0xbe')]=_0x1cab7a;return _0x59d31a;});}})['then'](respondWithFilteredResult(_0x5e552c,_0x95b7cf))[_0xb65c('0x38')](handleError(_0x5e552c,null));};exports['addTags']=function(_0x62703d,_0x19f6f7,_0x28fb03){return db[_0xb65c('0x41')][_0xb65c('0x63')]({'where':{'id':_0x62703d[_0xb65c('0xc0')]['id']}})['then'](handleEntityNotFound(_0x19f6f7,null))[_0xb65c('0x2e')](function(_0x184089){if(_0x184089){return _0x184089[_0xb65c('0xd1')](_0x62703d[_0xb65c('0x77')][_0xb65c('0xc8')],_[_0xb65c('0xc9')](_0x62703d[_0xb65c('0x77')],[_0xb65c('0xc8'),'id'])||{})[_0xb65c('0xd2')](function(){return db[_0xb65c('0x70')][_0xb65c('0xd0')]({'attributes':['id',_0xb65c('0x32'),'color'],'where':{'id':_0x62703d[_0xb65c('0x77')][_0xb65c('0xc8')]}});})[_0xb65c('0x2e')](function(_0x5cf5c7){socket[_0xb65c('0xd3')](_0xb65c('0xd4'),{'id':Number(_0x62703d['params']['id']),'tags':_0x5cf5c7||[]});return{'id':Number(_0x62703d[_0xb65c('0xc0')]['id']),'tags':_0x5cf5c7||[]};});}})[_0xb65c('0x2e')](respondWithResult(_0x19f6f7,null))[_0xb65c('0x38')](handleError(_0x19f6f7,null));};exports['removeTags']=function(_0x107f97,_0x3a9d8d,_0x6aa238){return db[_0xb65c('0x41')]['find']({'where':{'id':_0x107f97[_0xb65c('0xc0')]['id']}})[_0xb65c('0x2e')](handleEntityNotFound(_0x3a9d8d,null))[_0xb65c('0x2e')](function(_0x5a8b55){if(_0x5a8b55){return _0x5a8b55['removeTags'](_0x107f97[_0xb65c('0x45')]['ids']);}})[_0xb65c('0x2e')](respondWithStatusCode(_0x3a9d8d,null))[_0xb65c('0x38')](handleError(_0x3a9d8d,null));};exports[_0xb65c('0xd5')]=function(_0x59e65d,_0x3f3591){var _0x3ed6e9=moment()[_0xb65c('0xd6')]()[_0xb65c('0xa3')]();var _0x5d6160=path[_0xb65c('0xd7')](config[_0xb65c('0xd8')],'server',_0xb65c('0xd9'),_0xb65c('0xda'));var _0xae1440=path[_0xb65c('0xd7')](config['root'],_0xb65c('0xdb'),_0xb65c('0xd9'),'attachments');var _0x190299=path[_0xb65c('0xd7')](_0x5d6160,_0x3ed6e9);var _0x35402d=util[_0xb65c('0xdc')]('transcript-%d-%s.zip',_0x59e65d['params']['id'],_0x3ed6e9);var _0x3edc77=path[_0xb65c('0xd7')](_0x5d6160,_0x35402d);var _0x36b8e5=[];_0x36b8e5['push']({'model':db['User'],'as':'User','attributes':['id',_0xb65c('0x34')],'raw':!![]});_0x36b8e5[_0xb65c('0xbc')]({'model':db[_0xb65c('0xdd')],'as':_0xb65c('0x69'),'attributes':['id',_0xb65c('0xde'),_0xb65c('0xdf')],'raw':!![]});if(_0x59e65d[_0xb65c('0x45')]['attachments']){_0x36b8e5[_0xb65c('0xbc')]({'model':db['Attachment'],'as':_0xb65c('0xe0'),'raw':!![]});}var _0x2735db=[{'model':db['WhatsappMessage'],'as':_0xb65c('0xe1'),'attributes':['id',_0xb65c('0x77'),_0xb65c('0x7e'),_0xb65c('0xe2'),_0xb65c('0xe3'),_0xb65c('0x86')],'include':_0x36b8e5}];_0x2735db['push']({'model':db['WhatsappAccount'],'as':_0xb65c('0xe4'),'attributes':['id',_0xb65c('0x32')]});_0x2735db[_0xb65c('0xbc')]({'model':db[_0xb65c('0x74')],'as':_0xb65c('0xe5'),'attributes':['id',_0xb65c('0x34')]});return db[_0xb65c('0x41')]['find']({'where':{'id':_0x59e65d[_0xb65c('0xc0')]['id']},'include':_0x2735db})[_0xb65c('0x2e')](handleEntityNotFound(_0x3f3591,null))[_0xb65c('0x2e')](function(_0x268a6c){if(_0x268a6c){var _0x533bb9=_0x268a6c[_0xb65c('0xe6')]({'plain':!![]});fs[_0xb65c('0xe7')](_0x190299);var _0x19c8bc={'channel':_0xb65c('0xe8'),'account':_0x533bb9[_0xb65c('0xe4')][_0xb65c('0x32')],'agent':_0x533bb9[_0xb65c('0xe5')]?_0x533bb9[_0xb65c('0xe5')]['fullname']:_0xb65c('0xe9'),'createdAt':moment(_0x533bb9[_0xb65c('0x7e')])[_0xb65c('0xdc')](_0xb65c('0xce'))[_0xb65c('0xa3')](),'closedAt':_0x533bb9['closed']?moment(_0x533bb9[_0xb65c('0xea')])[_0xb65c('0xdc')](_0xb65c('0xce'))['toString']():'','disposition':_0x533bb9[_0xb65c('0xeb')],'messages':_(_0x533bb9[_0xb65c('0xe1')])[_0xb65c('0x8b')]({'secret':![]})['map'](function(_0x3b3be9){if(_0x3b3be9[_0xb65c('0xe0')]){var _0x17dd44=path[_0xb65c('0xd7')](_0xae1440,_0x3b3be9[_0xb65c('0xe0')][_0xb65c('0xec')]);if(fs[_0xb65c('0xed')](_0x17dd44)){fs[_0xb65c('0xee')](_0x17dd44)['pipe'](fs[_0xb65c('0xef')](path[_0xb65c('0xd7')](_0x190299,_0x3b3be9[_0xb65c('0xe0')][_0xb65c('0xec')])));}}return{'date':moment(_0x3b3be9[_0xb65c('0x7e')])['format'](_0xb65c('0xce'))['toString'](),'sender':_0x3b3be9[_0xb65c('0xe2')]===_0xb65c('0xf0')?_0x3b3be9['User']?_0x3b3be9[_0xb65c('0x74')]['fullname']:_0xb65c('0xf1'):_0x3b3be9[_0xb65c('0x69')][_0xb65c('0xde')]+(_0x3b3be9[_0xb65c('0x69')][_0xb65c('0xdf')]?'\x20'+_0x3b3be9[_0xb65c('0x69')]['lastName']:''),'body':_0x3b3be9['Attachment']?_0x3b3be9[_0xb65c('0xe0')][_0xb65c('0xec')]:_0x3b3be9['body'],'direction':_0x3b3be9['direction']===_0xb65c('0xf0')?'A':'C','secret':_0x3b3be9[_0xb65c('0xe3')],'read':_0x3b3be9[_0xb65c('0x86')],'attachment':_0x3b3be9[_0xb65c('0xe0')]};})[_0xb65c('0x65')]()};return ejs[_0xb65c('0xf2')](path[_0xb65c('0xd7')](config[_0xb65c('0xd8')],'server','views',_0xb65c('0xf3')),{'interaction':_0x19c8bc})['then'](function(_0x33bd44){var _0x2b426f=path['join'](_0x190299,'transcript-'+_0x533bb9['id']+'-'+_0x3ed6e9+_0xb65c('0xf4'));var _0x4c4407={'path':_0x2b426f,'channel':_0xb65c('0xe8'),'interactionId':_0x533bb9['id']};return pdf['createPdfFromHTML'](_0x33bd44,_0x4c4407);})['then'](function(){return new BPromise(function(_0x2a98be,_0xa08887){zipdir(_0x190299,{'saveTo':_0x3edc77},function(_0x515d57,_0x45ef22){if(_0x515d57)return _0xa08887(_0x515d57);return _0x2a98be(_0x45ef22);});})[_0xb65c('0x2e')](function(){return new BPromise(function(_0x47b1f7,_0x3f072c){rimraf(_0x190299,function(_0x415b51){if(_0x415b51)_0x3f072c(_0x415b51);return _0x47b1f7();});});})[_0xb65c('0x2e')](function(){return _0x3f3591['download'](_0x3edc77,_0x35402d,function(_0x87773d){if(_0x87773d){console[_0xb65c('0xf5')](_0xb65c('0xf6'),_0x87773d);}else{fs[_0xb65c('0xf7')](_0x3edc77);}});});});}else{return _0x3f3591[_0xb65c('0x30')](0xc8);}})['catch'](handleError(_0x3f3591,null));};
\ No newline at end of file