Built motion from commit a61a4a20.|2.5.46
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 3db490f..bafc539 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc2c7=['a.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','c.lastName','Contact.lastName','Contact.email','c.phone','Contact.phone','c.mobile','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','WhatsappInteractionId','all','rows','show','includeAll','options','create','body','params','describe','addMessage','WhatsappMessage','ids','format','include','findAll','addTags','setTags','omit','spread','removeTags','download','unix','root','server','tmp','join','files','attachments','transcript-%d-%s.zip','Contact','firstName','lastName','Attachment','direction','secret','Account','get','mkdirSync','10px','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','<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>','Whatsapp','Owner','closedAt','disposition','Messages','basename','existsSync','createReadStream','createWriteStream','YYYY-MM-DD\x20HH:mm:ss','out','System','renderFile','views','toFile','transcript-','.pdf','err','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','status','end','count','offset','limit','Content-Range','apply','reject','save','update','destroy','sendStatus','error','stack','name','send','Users','map','fullname','TagIds','Tags','forEach','push','then','catch','index','WhatsappInteraction','rawAttributes','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','select','field','color','tools_tags','u.fullname','from','user_has_whatsapp_interactions','users','whatsapp_interactions','left_join','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','expr','parseSearch','conditions','find','unreadMessages','having','`\x20>\x200','operator','value','split','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?','ContactId','buildExpression','type','text','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','$substring','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','start','some','compact','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','isArray','tag','filter','replace','isNumeric','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','SELECT','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','order','contactName','DESC','isEmpty','t.id\x20IN\x20?','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','role','sequelize','toString','keyBy','merge','Account.key'];(function(_0xb0f7c3,_0x4eae95){var _0x28ea68=function(_0x4395a7){while(--_0x4395a7){_0xb0f7c3['push'](_0xb0f7c3['shift']());}};_0x28ea68(++_0x4eae95);}(_0xc2c7,0x134));var _0x7c2c=function(_0x3aca76,_0x440d2e){_0x3aca76=_0x3aca76-0x0;var _0x36273a=_0xc2c7[_0x3aca76];return _0x36273a;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x7c2c('0x0'));var rimraf=require(_0x7c2c('0x1'));var zipdir=require(_0x7c2c('0x2'));var jsonpatch=require(_0x7c2c('0x3'));var rp=require(_0x7c2c('0x4'));var moment=require(_0x7c2c('0x5'));var BPromise=require(_0x7c2c('0x6'));var Mustache=require(_0x7c2c('0x7'));var util=require('util');var path=require('path');var sox=require(_0x7c2c('0x8'));var csv=require(_0x7c2c('0x9'));var ejs=require(_0x7c2c('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x7c2c('0xb'));var deskjs=require(_0x7c2c('0xc'));var toCsv=require(_0x7c2c('0x9'));var querystring=require(_0x7c2c('0xd'));var Papa=require(_0x7c2c('0xe'));var Redis=require('ioredis');var authService=require(_0x7c2c('0xf'));var qs=require(_0x7c2c('0x10'));var as=require(_0x7c2c('0x11'));var hardwareService=require(_0x7c2c('0x12'));var logger=require(_0x7c2c('0x13'))(_0x7c2c('0x14'));var utils=require(_0x7c2c('0x15'));var config=require(_0x7c2c('0x16'));var licenseUtil=require(_0x7c2c('0x17'));var db=require(_0x7c2c('0x18'))['db'];config[_0x7c2c('0x19')]=_[_0x7c2c('0x1a')](config[_0x7c2c('0x19')],{'host':_0x7c2c('0x1b'),'port':0x18eb});var socket=require(_0x7c2c('0x1c'))(new Redis(config[_0x7c2c('0x19')]));require('./whatsappInteraction.socket')['register'](socket);function respondWithStatusCode(_0x102778,_0xd1a3db){_0xd1a3db=_0xd1a3db||0xcc;return function(_0x4678a8){if(_0x4678a8){return _0x102778['sendStatus'](_0xd1a3db);}return _0x102778[_0x7c2c('0x1d')](_0xd1a3db)[_0x7c2c('0x1e')]();};}function respondWithResult(_0x5e55e0,_0x88f54b){_0x88f54b=_0x88f54b||0xc8;return function(_0x5a5fe2){if(_0x5a5fe2){return _0x5e55e0[_0x7c2c('0x1d')](_0x88f54b)['json'](_0x5a5fe2);}};}function respondWithFilteredResult(_0x342ea2,_0x3c948a){return function(_0x14453f){if(_0x14453f){var _0x2a9539=_0x14453f[_0x7c2c('0x1f')],_0x17df4a=_0x3c948a[_0x7c2c('0x20')],_0x26be0f=_0x3c948a[_0x7c2c('0x20')]+_0x3c948a[_0x7c2c('0x21')],_0x2c1378;if(_0x26be0f>=_0x2a9539){_0x26be0f=_0x2a9539;_0x2c1378=0xc8;}else{_0x2c1378=0xce;}_0x342ea2[_0x7c2c('0x1d')](_0x2c1378);return _0x342ea2['set'](_0x7c2c('0x22'),_0x17df4a+'-'+_0x26be0f+'/'+_0x2a9539)['json'](_0x14453f);}return null;};}function patchUpdates(_0x506d47){return function(_0x15ae33){try{jsonpatch[_0x7c2c('0x23')](_0x15ae33,_0x506d47,!![]);}catch(_0x2a9ae2){return BPromise[_0x7c2c('0x24')](_0x2a9ae2);}return _0x15ae33[_0x7c2c('0x25')]();};}function saveUpdates(_0x1883b5,_0xa84620){return function(_0x541368){if(_0x541368){return _0x541368[_0x7c2c('0x26')](_0x1883b5)['then'](function(_0x302c93){return _0x302c93;});}return null;};}function removeEntity(_0x57f510,_0x3d4387){return function(_0x274c3b){if(_0x274c3b){return _0x274c3b[_0x7c2c('0x27')]()['then'](function(){_0x57f510['status'](0xcc)[_0x7c2c('0x1e')]();});}};}function handleEntityNotFound(_0x30c53e,_0x3d2b8d){return function(_0x150690){if(!_0x150690){_0x30c53e[_0x7c2c('0x28')](0x194);}return _0x150690;};}function handleError(_0xa8e145,_0x3f4618){_0x3f4618=_0x3f4618||0x1f4;return function(_0x4b1dd0){logger[_0x7c2c('0x29')](_0x4b1dd0[_0x7c2c('0x2a')]);if(_0x4b1dd0[_0x7c2c('0x2b')]){delete _0x4b1dd0[_0x7c2c('0x2b')];}_0xa8e145[_0x7c2c('0x1d')](_0x3f4618)[_0x7c2c('0x2c')](_0x4b1dd0);};}function getInteractionUsers(_0xf2bfd1,_0x26f472){return new BPromise(function(_0xa040ff,_0x5769ec){try{if(_0x26f472[_0xf2bfd1['id']]){_0xf2bfd1[_0x7c2c('0x2d')]=_[_0x7c2c('0x2e')](_0x26f472[_0xf2bfd1['id']],function(_0x2343f4){return{'id':_0x2343f4['id'],'fullname':_0x2343f4[_0x7c2c('0x2f')]};});}}catch(_0x53ad23){_0x5769ec(_0x53ad23);}_0xa040ff(_0xf2bfd1);});}function getInteractionTags(_0xcb98ba,_0x30dd1c){return new BPromise(function(_0x4192c8,_0x1ef88b){try{if(_0xcb98ba[_0x7c2c('0x30')]){_0xcb98ba[_0x7c2c('0x31')]=[];_0xcb98ba[_0x7c2c('0x30')]['split'](',')[_0x7c2c('0x32')](function(_0x1acf75){_0xcb98ba[_0x7c2c('0x31')][_0x7c2c('0x33')](_0x30dd1c[_0x1acf75]);});}delete _0xcb98ba[_0x7c2c('0x30')];}catch(_0x5147c1){_0x1ef88b(_0x5147c1);}_0x4192c8(_0xcb98ba);});}function updateWhatsappInteraction(_0x47ef3c,_0x7f0e97,_0x5f302e){return new BPromise(function(_0x4b97bb,_0x15ee13){return getInteractionUsers(_0x47ef3c,_0x5f302e)[_0x7c2c('0x34')](function(_0x199b13){return getInteractionTags(_0x199b13,_0x7f0e97);})[_0x7c2c('0x34')](function(_0x536dcf){_0x4b97bb(_0x536dcf);})[_0x7c2c('0x35')](function(_0x38a937){_0x15ee13(_0x38a937);});});}exports[_0x7c2c('0x36')]=function(_0x19783d,_0x204968){var _0x6ef8c4={},_0x18795b={},_0xab5072={'count':0x0,'rows':[]};var _0x5c248e=_[_0x7c2c('0x2e')](db[_0x7c2c('0x37')][_0x7c2c('0x38')],function(_0x2b6a7d){return{'name':_0x2b6a7d['fieldName'],'type':_0x2b6a7d['type'][_0x7c2c('0x39')]};});_0x18795b['model']=_['map'](_0x5c248e,'name');_0x18795b[_0x7c2c('0x3a')]=_[_0x7c2c('0x3b')](_0x19783d[_0x7c2c('0x3a')]);_0x18795b[_0x7c2c('0x3c')]=_[_0x7c2c('0x3d')](_0x18795b[_0x7c2c('0x3e')],_0x18795b[_0x7c2c('0x3a')]);_0x6ef8c4[_0x7c2c('0x3f')]=_[_0x7c2c('0x3d')](_0x18795b[_0x7c2c('0x3e')],qs[_0x7c2c('0x40')](_0x19783d['query']['fields']));_0x6ef8c4[_0x7c2c('0x3f')]=_0x6ef8c4[_0x7c2c('0x3f')][_0x7c2c('0x41')]?_0x6ef8c4[_0x7c2c('0x3f')]:_0x18795b['model'];if(!_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x42')](_0x7c2c('0x43'))){_0x6ef8c4[_0x7c2c('0x21')]=qs[_0x7c2c('0x21')](_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x21')]);_0x6ef8c4[_0x7c2c('0x20')]=qs[_0x7c2c('0x20')](_0x19783d['query'][_0x7c2c('0x20')]);}_0x6ef8c4['order']=qs[_0x7c2c('0x44')](_0x19783d[_0x7c2c('0x3a')]['sort']);_0x6ef8c4[_0x7c2c('0x45')]=qs['filters'](_[_0x7c2c('0x46')](_0x19783d[_0x7c2c('0x3a')],_0x18795b[_0x7c2c('0x3c')]),_0x5c248e);var _0x26351e=[];var _0x4f3948=squel[_0x7c2c('0x47')]()['field']('id')['field'](_0x7c2c('0x2b'))[_0x7c2c('0x48')](_0x7c2c('0x49'))['from'](_0x7c2c('0x4a'));var _0x75c0ab=squel['select']()[_0x7c2c('0x48')]('u.id')[_0x7c2c('0x48')](_0x7c2c('0x4b'))['field']('ui.WhatsappInteractionId')[_0x7c2c('0x4c')](_0x7c2c('0x4d'),'ui')['left_join'](_0x7c2c('0x4e'),'u','u.id\x20=\x20ui.UserId');var _0x51e3b7=squel[_0x7c2c('0x47')]()[_0x7c2c('0x4c')](_0x7c2c('0x4f'),'i')[_0x7c2c('0x50')](_0x7c2c('0x51'),'c',_0x7c2c('0x52'))[_0x7c2c('0x50')](_0x7c2c('0x4e'),'o',_0x7c2c('0x53'))['left_join']('whatsapp_accounts','a',_0x7c2c('0x54'))[_0x7c2c('0x50')](_0x7c2c('0x55'),'me','me.WhatsappInteractionId\x20=\x20i.id')['left_join'](_0x7c2c('0x56'),'it',_0x7c2c('0x57'))[_0x7c2c('0x50')](_0x7c2c('0x4a'),'t','t.id\x20=\x20it.TagId');var _0x4f958d=squel['expr']();var _0xd71ef8=[];var _0x36184a=squel[_0x7c2c('0x58')]();var _0x27a096;if(_0x19783d[_0x7c2c('0x3a')]['search']){_0x27a096=as[_0x7c2c('0x59')](_0x19783d[_0x7c2c('0x3a')]['search']);var _0x19621a=_0x27a096['sqlOperator'];for(var _0xfba6a7=0x0;_0xfba6a7<_0x27a096[_0x7c2c('0x5a')][_0x7c2c('0x41')];_0xfba6a7++){var _0x55e123=_0x27a096['conditions'][_0xfba6a7];var _0x327f3a='i';var _0x5e4bc3=_[_0x7c2c('0x5b')](_0x5c248e,[_0x7c2c('0x2b'),_0x55e123['field']]);if(!_0x5e4bc3){switch(_0x55e123[_0x7c2c('0x48')]){case _0x7c2c('0x5c'):if(_0x55e123['value']==0x1){_0x51e3b7[_0x7c2c('0x5d')]('`'+_0x55e123[_0x7c2c('0x48')]+'`\x20=\x200');}else{_0x51e3b7[_0x7c2c('0x5d')]('`'+_0x55e123[_0x7c2c('0x48')]+_0x7c2c('0x5e'));}break;case'Contact':if(_0x55e123[_0x7c2c('0x5f')]==='$substring'){if(_0x55e123[_0x7c2c('0x60')][_0x7c2c('0x61')]('\x20')['length']>0x1){_0x4f958d[_0x19621a](_0x7c2c('0x62'),qs[_0x7c2c('0x63')](_0x55e123[_0x7c2c('0x60')]),null);}else{var _0x33681b='%'+_0x55e123['value']+'%';_0x4f958d[_0x19621a](_0x7c2c('0x64'),_0x33681b,_0x33681b,_0x33681b);}}else{_0x5e4bc3=_[_0x7c2c('0x5b')](_0x5c248e,['name',_0x7c2c('0x65')]);_0x55e123['field']=_0x7c2c('0x65');_0xb1d1ad=as[_0x7c2c('0x66')](_0x327f3a,_0x5e4bc3[_0x7c2c('0x67')],_0x55e123);_0x4f958d[_0x19621a](_0xb1d1ad[_0x7c2c('0x68')],_0xb1d1ad[_0x7c2c('0x60')]['start'],_0xb1d1ad[_0x7c2c('0x60')][_0x7c2c('0x1e')]);}break;case'Tag':var _0x53025a=_0x55e123['value'][_0x7c2c('0x61')](',')['map'](function(_0x1e61fe){return Number(_0x1e61fe);});_0x53025a['forEach'](function(_0x469515){_0x36184a['or'](_0x7c2c('0x69'),'%,'+_0x469515+',%');});_0xd71ef8=_[_0x7c2c('0x6a')](_0xd71ef8,_0x53025a);break;case _0x7c2c('0x6b'):if(_0x55e123[_0x7c2c('0x5f')]===_0x7c2c('0x6c')){_0x4f958d[_0x19621a](_0x7c2c('0x6d'),'%'+_0x55e123[_0x7c2c('0x60')]+'%',null);}else{_0x5e4bc3=_['find'](_0x5c248e,['name','UserId']);_0x55e123[_0x7c2c('0x48')]=_0x7c2c('0x6e');_0xb1d1ad=as[_0x7c2c('0x66')](_0x327f3a,_0x5e4bc3[_0x7c2c('0x67')],_0x55e123);_0x4f958d[_0x19621a](_0xb1d1ad[_0x7c2c('0x68')],_0xb1d1ad[_0x7c2c('0x60')][_0x7c2c('0x6f')],_0xb1d1ad[_0x7c2c('0x60')]['end']);}break;case'body':_0xb1d1ad=as[_0x7c2c('0x66')]('me',null,_0x55e123);_0x4f958d[_0x19621a](_0xb1d1ad[_0x7c2c('0x68')],_0xb1d1ad['value'][_0x7c2c('0x6f')],_0xb1d1ad['value']['end']);break;}}else{var _0xb1d1ad=as[_0x7c2c('0x66')](_0x327f3a,_0x5e4bc3[_0x7c2c('0x67')],_0x55e123);_0x4f958d[_0x19621a](_0xb1d1ad[_0x7c2c('0x68')],_0xb1d1ad[_0x7c2c('0x60')][_0x7c2c('0x6f')],_0xb1d1ad[_0x7c2c('0x60')][_0x7c2c('0x1e')]);}}}else{var _0xf06cd1=_(_0x19783d[_0x7c2c('0x3a')])[_0x7c2c('0x3b')]()[_0x7c2c('0x2e')](function(_0xbe0568){return _[_0x7c2c('0x70')](_0x5c248e,['name',_0xbe0568])?_0xbe0568:undefined;})[_0x7c2c('0x71')]()['value']();if(!_['isEmpty'](_0xf06cd1)){_0xf06cd1['forEach'](function(_0x4c0d0f){if(_0x4c0d0f===_0x7c2c('0x72')){_0x51e3b7[_0x7c2c('0x45')](_0x7c2c('0x73'),[][_0x7c2c('0x74')](_0x19783d[_0x7c2c('0x3a')][_0x4c0d0f]));}else if(_0x4c0d0f===_0x7c2c('0x75')){var _0x59e46d=JSON[_0x7c2c('0x76')](_0x19783d[_0x7c2c('0x3a')][_0x4c0d0f])[_0x7c2c('0x77')];var _0x21c5ff=JSON[_0x7c2c('0x76')](_0x19783d[_0x7c2c('0x3a')][_0x4c0d0f])['$lte'];_0x51e3b7[_0x7c2c('0x45')](_0x7c2c('0x78'),_0x59e46d,_0x21c5ff);}else{if(_0x19783d['query'][_0x4c0d0f]===_0x7c2c('0x79')){_0x51e3b7[_0x7c2c('0x45')]('i.'+_0x4c0d0f+'\x20IS\x20NULL');}else{_0x51e3b7[_0x7c2c('0x45')]('i.'+_0x4c0d0f+_0x7c2c('0x7a'),_0x19783d['query'][_0x4c0d0f]);}}});}if(_0x19783d['query'][_0x7c2c('0x7b')]){if(_0x19783d['query'][_0x7c2c('0x7b')]==0x1){_0x51e3b7['having'](_0x7c2c('0x7c'));}else{_0x51e3b7[_0x7c2c('0x5d')]('`unreadMessages`\x20>\x200');}}if(_0x19783d[_0x7c2c('0x3a')]['tag']){_0xd71ef8=_[_0x7c2c('0x7d')](_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x7e')])?_0x19783d['query'][_0x7c2c('0x7e')]:new Array(_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x7e')]);_0xd71ef8[_0x7c2c('0x32')](function(_0x5a636c){_0x36184a['or'](_0x7c2c('0x69'),'%,'+_0x5a636c+',%');});}if(_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x7f')]){var _0x1d75ba=_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x7f')][_0x7c2c('0x80')]('\x5c','\x5c\x5c')[_0x7c2c('0x80')](/'/g,'\x27\x27');if(qs[_0x7c2c('0x81')](_0x1d75ba)){_0x4f958d['or']('i.id\x20LIKE\x20?',_0x1d75ba+'%')['or'](_0x7c2c('0x82'),_0x1d75ba+'%');}else{_0x4f958d['or'](_0x7c2c('0x83'),qs['getFullTextValue'](_0x1d75ba))['or'](_0x7c2c('0x84'),_0x1d75ba+'%');}}}_0x51e3b7['where'](_0x4f958d);_0x51e3b7['group'](_0x7c2c('0x85'));var _0x40fc73={'type':db[_0x7c2c('0x86')]['QueryTypes'][_0x7c2c('0x87')],'raw':!![]};var _0x4e672=_0x51e3b7[_0x7c2c('0x88')]();_0x4e672['field'](_0x7c2c('0x85'));_0x4e672[_0x7c2c('0x48')](_0x7c2c('0x89'),_0x7c2c('0x5c'));if(_0x6ef8c4['order']){_0x6ef8c4[_0x7c2c('0x8a')]['forEach'](function(_0x412ad9){var _0x4ee339=_0x412ad9[0x0]===_0x7c2c('0x8b')?_0x412ad9[0x0]:'i.'+_0x412ad9[0x0];_0x51e3b7[_0x7c2c('0x8a')](_0x4ee339,_0x412ad9[0x1]===_0x7c2c('0x8c')?![]:!![]);});}if(!_[_0x7c2c('0x8d')](_0xd71ef8)){_0x51e3b7[_0x7c2c('0x5d')](_0x36184a);_0x4e672[_0x7c2c('0x45')](_0x7c2c('0x8e'),_0xd71ef8);}BPromise['resolve']()[_0x7c2c('0x34')](function(){if(!_0x27a096){if(_0x19783d[_0x7c2c('0x3a')][_0x7c2c('0x72')])return;_0x4e672[_0x7c2c('0x45')](_0x7c2c('0x8f'));_0x51e3b7[_0x7c2c('0x45')](_0x7c2c('0x8f'));return;}if(_0x19783d[_0x7c2c('0x90')]['role']!==_0x7c2c('0x91'))return;return _0x19783d[_0x7c2c('0x90')][_0x7c2c('0x92')]({'attributes':['id'],'raw':!![]})[_0x7c2c('0x34')](function(_0x11e00d){if(_['isEmpty'](_0x11e00d)){_0x4e672[_0x7c2c('0x45')](_0x7c2c('0x93'));_0x51e3b7['where'](_0x7c2c('0x93'));}else{_0x4e672[_0x7c2c('0x45')]('i.WhatsappAccountId\x20IN\x20?',_[_0x7c2c('0x2e')](_0x11e00d,'id'));_0x51e3b7['where'](_0x7c2c('0x73'),_[_0x7c2c('0x2e')](_0x11e00d,'id'));}});})[_0x7c2c('0x34')](function(){if(_0x19783d[_0x7c2c('0x90')][_0x7c2c('0x94')]===_0x7c2c('0x91')&&!_0x27a096&&!_0x19783d[_0x7c2c('0x3a')]['WhatsappAccountId'])return[];return db[_0x7c2c('0x95')][_0x7c2c('0x3a')](_0x4e672['toString'](),_0x40fc73);})[_0x7c2c('0x34')](function(_0x333a76){_0xab5072[_0x7c2c('0x1f')]=_0x333a76[_0x7c2c('0x41')];if(_0xab5072[_0x7c2c('0x1f')]===0x0)return[];return db[_0x7c2c('0x95')][_0x7c2c('0x3a')](_0x4f3948[_0x7c2c('0x96')](),_0x40fc73)[_0x7c2c('0x34')](function(_0x2f5cb0){_0x26351e=_[_0x7c2c('0x97')](_0x2f5cb0,'id');_0x40fc73=_[_0x7c2c('0x98')](_0x40fc73,{'model':db[_0x7c2c('0x37')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x19783d[_0x7c2c('0x3a')]['fields']){_0x6ef8c4[_0x7c2c('0x3f')][_0x7c2c('0x32')](function(_0x551c44){_0x51e3b7[_0x7c2c('0x48')]('i.'+_0x551c44);});}else{_0x51e3b7[_0x7c2c('0x48')](_0x7c2c('0x89'),_0x7c2c('0x5c'));_0x51e3b7[_0x7c2c('0x48')]('a.key',_0x7c2c('0x99'));_0x51e3b7[_0x7c2c('0x48')](_0x7c2c('0x9a'),'Account.mandatoryDisposition');_0x51e3b7[_0x7c2c('0x48')](_0x7c2c('0x9b'),_0x7c2c('0x8b'));_0x51e3b7['field'](_0x7c2c('0x9c'));_0x51e3b7['field'](_0x7c2c('0x9d'),'Contact.firstName');_0x51e3b7['field'](_0x7c2c('0x9e'),_0x7c2c('0x9f'));_0x51e3b7[_0x7c2c('0x48')]('c.email',_0x7c2c('0xa0'));_0x51e3b7[_0x7c2c('0x48')](_0x7c2c('0xa1'),_0x7c2c('0xa2'));_0x51e3b7['field'](_0x7c2c('0xa3'),'Contact.mobile');_0x51e3b7['field']('c.fax','Contact.fax');_0x51e3b7['field'](_0x7c2c('0xa4'),_0x7c2c('0xa5'));_0x51e3b7[_0x7c2c('0x48')](_0x7c2c('0xa6'),_0x7c2c('0xa7'));_0x51e3b7['field'](_0x7c2c('0xa8'),_0x7c2c('0x30'));}if(_0x6ef8c4[_0x7c2c('0x21')])_0x51e3b7[_0x7c2c('0x21')](_0x6ef8c4[_0x7c2c('0x21')]);if(_0x6ef8c4[_0x7c2c('0x20')])_0x51e3b7['offset'](_0x6ef8c4['offset']);return db[_0x7c2c('0x95')][_0x7c2c('0x3a')](_0x51e3b7[_0x7c2c('0x96')](),_0x40fc73);})[_0x7c2c('0x34')](function(_0x587e5a){_0x75c0ab[_0x7c2c('0x45')](_0x7c2c('0xa9'),_[_0x7c2c('0x2e')](_0x587e5a,'id'));return db[_0x7c2c('0x95')][_0x7c2c('0x3a')](_0x75c0ab[_0x7c2c('0x96')](),_0x40fc73)[_0x7c2c('0x34')](function(_0x11057b){var _0x490f01=_['groupBy'](_0x11057b,_0x7c2c('0xaa'));var _0x1abb54=[];_0x587e5a['forEach'](function(_0x34ed53){_0x1abb54['push'](updateWhatsappInteraction(_0x34ed53,_0x26351e,_0x490f01));});return BPromise[_0x7c2c('0xab')](_0x1abb54);});});})['then'](function(_0x40a620){_0xab5072[_0x7c2c('0xac')]=_0x40a620;return _0xab5072;})[_0x7c2c('0x34')](respondWithFilteredResult(_0x204968,_0x6ef8c4))[_0x7c2c('0x35')](handleError(_0x204968,null));};exports[_0x7c2c('0xad')]=function(_0x309051,_0x3f8683){var _0x1eeb00={'raw':![],'where':{'id':_0x309051['params']['id']}},_0x3fd718={};_0x3fd718[_0x7c2c('0x3e')]=_[_0x7c2c('0x3b')](db[_0x7c2c('0x37')]['rawAttributes']);_0x3fd718[_0x7c2c('0x3a')]=_[_0x7c2c('0x3b')](_0x309051['query']);_0x3fd718[_0x7c2c('0x3c')]=_['intersection'](_0x3fd718[_0x7c2c('0x3e')],_0x3fd718['query']);_0x1eeb00[_0x7c2c('0x3f')]=_[_0x7c2c('0x3d')](_0x3fd718[_0x7c2c('0x3e')],qs[_0x7c2c('0x40')](_0x309051['query'][_0x7c2c('0x40')]));_0x1eeb00[_0x7c2c('0x3f')]=_0x1eeb00[_0x7c2c('0x3f')][_0x7c2c('0x41')]?_0x1eeb00[_0x7c2c('0x3f')]:_0x3fd718[_0x7c2c('0x3e')];if(_0x309051['query'][_0x7c2c('0xae')]){_0x1eeb00['include']=[{'all':!![]}];}_0x1eeb00=_[_0x7c2c('0x98')]({},_0x1eeb00,_0x309051[_0x7c2c('0xaf')]);return db['WhatsappInteraction'][_0x7c2c('0x5b')](_0x1eeb00)[_0x7c2c('0x34')](handleEntityNotFound(_0x3f8683,null))[_0x7c2c('0x34')](respondWithResult(_0x3f8683,null))[_0x7c2c('0x35')](handleError(_0x3f8683,null));};exports[_0x7c2c('0xb0')]=function(_0x3f1cff,_0x5768c3){return db['WhatsappInteraction'][_0x7c2c('0xb0')](_0x3f1cff[_0x7c2c('0xb1')],{})[_0x7c2c('0x34')](respondWithResult(_0x5768c3,0xc9))[_0x7c2c('0x35')](handleError(_0x5768c3,null));};exports[_0x7c2c('0x26')]=function(_0x35b914,_0xa3a57e){if(_0x35b914['body']['id']){delete _0x35b914[_0x7c2c('0xb1')]['id'];}return db['WhatsappInteraction']['find']({'where':{'id':_0x35b914[_0x7c2c('0xb2')]['id']}})[_0x7c2c('0x34')](handleEntityNotFound(_0xa3a57e,null))[_0x7c2c('0x34')](saveUpdates(_0x35b914[_0x7c2c('0xb1')],null))['then'](respondWithResult(_0xa3a57e,null))['catch'](handleError(_0xa3a57e,null));};exports[_0x7c2c('0x27')]=function(_0x45a60f,_0x4a0cfb){return db[_0x7c2c('0x37')]['find']({'where':{'id':_0x45a60f['params']['id']}})[_0x7c2c('0x34')](handleEntityNotFound(_0x4a0cfb,null))[_0x7c2c('0x34')](removeEntity(_0x4a0cfb,null))['catch'](handleError(_0x4a0cfb,null));};exports[_0x7c2c('0xb3')]=function(_0xa485db,_0x4ba74c){return db[_0x7c2c('0x37')]['describe']()[_0x7c2c('0x34')](respondWithResult(_0x4ba74c,null))[_0x7c2c('0x35')](handleError(_0x4ba74c,null));};exports[_0x7c2c('0xb4')]=function(_0x2bf94e,_0xa285d5,_0xd97e2){return db[_0x7c2c('0xb5')]['find']({'where':{'id':_0x2bf94e[_0x7c2c('0xb2')]['id']}})['then'](handleEntityNotFound(_0xa285d5,null))[_0x7c2c('0x34')](function(_0x36bf36){if(_0x36bf36){return _0x36bf36[_0x7c2c('0xb4')](_0x2bf94e[_0x7c2c('0xb1')][_0x7c2c('0xb6')],_['omit'](_0x2bf94e[_0x7c2c('0xb1')],[_0x7c2c('0xb6'),'id'])||{});}})['then'](respondWithResult(_0xa285d5,null))[_0x7c2c('0x35')](handleError(_0xa285d5,null));};exports['getMessages']=function(_0x332795,_0x2bcb0c,_0x255d31){var _0x5d03e4={'raw':![],'where':{}};var _0x1732c8={};var _0x33f85d={'count':0x0,'rows':[]};return db[_0x7c2c('0x37')]['findOne']({'where':{'id':_0x332795[_0x7c2c('0xb2')]['id']}})['then'](handleEntityNotFound(_0x2bcb0c,null))[_0x7c2c('0x34')](function(_0x334736){if(_0x334736){_0x1732c8[_0x7c2c('0x3e')]=_[_0x7c2c('0x3b')](db[_0x7c2c('0xb5')][_0x7c2c('0x38')]);_0x1732c8['query']=_[_0x7c2c('0x3b')](_0x332795[_0x7c2c('0x3a')]);_0x1732c8['filters']=_[_0x7c2c('0x3d')](_0x1732c8[_0x7c2c('0x3e')],_0x1732c8[_0x7c2c('0x3a')]);_0x5d03e4[_0x7c2c('0x3f')]=_['intersection'](_0x1732c8['model'],qs[_0x7c2c('0x40')](_0x332795['query']['fields']));_0x5d03e4[_0x7c2c('0x3f')]=_0x5d03e4[_0x7c2c('0x3f')]['length']?_0x5d03e4['attributes']:_0x1732c8['model'];if(!_0x332795[_0x7c2c('0x3a')]['hasOwnProperty']('nolimit')){_0x5d03e4[_0x7c2c('0x21')]=qs['limit'](_0x332795[_0x7c2c('0x3a')][_0x7c2c('0x21')]);_0x5d03e4[_0x7c2c('0x20')]=qs[_0x7c2c('0x20')](_0x332795[_0x7c2c('0x3a')]['offset']);}_0x5d03e4[_0x7c2c('0x8a')]=qs['sort'](_0x332795[_0x7c2c('0x3a')][_0x7c2c('0x44')]);_0x5d03e4[_0x7c2c('0x45')]=qs[_0x7c2c('0x3c')](_[_0x7c2c('0x46')](_0x332795['query'],_0x1732c8['filters']));_0x5d03e4['where']['WhatsappInteractionId']=_0x334736['id'];if(_0x332795[_0x7c2c('0x3a')][_0x7c2c('0x7f')]){_0x5d03e4[_0x7c2c('0x45')]=_[_0x7c2c('0x98')](_0x5d03e4[_0x7c2c('0x45')],{'$or':_[_0x7c2c('0x2e')](_0x5d03e4[_0x7c2c('0x3f')],function(_0x3cae39){var _0x44f523={};_0x44f523[_0x3cae39]={'$like':'%'+_0x332795['query'][_0x7c2c('0x7f')]+'%'};return _0x44f523;})});}if(_0x332795[_0x7c2c('0x3a')][_0x7c2c('0x77')]){var _0x27f1df=_0x332795[_0x7c2c('0x3a')][_0x7c2c('0x77')][_0x7c2c('0x61')](',');var _0x4b8433={};_0x4b8433[_0x27f1df[0x0]]={'$gte':moment(_0x27f1df[0x1])[_0x7c2c('0xb7')]('YYYY-MM-DD\x20HH:mm:ss')};_0x5d03e4['where']=_[_0x7c2c('0x98')](_0x5d03e4[_0x7c2c('0x45')],_0x4b8433);}_0x5d03e4=_['merge']({},_0x5d03e4,_0x332795[_0x7c2c('0xaf')]);return db[_0x7c2c('0xb5')][_0x7c2c('0x1f')]({'where':_0x5d03e4[_0x7c2c('0x45')]})[_0x7c2c('0x34')](function(_0xb76478){_0x33f85d['count']=_0xb76478;if(_0x332795[_0x7c2c('0x3a')][_0x7c2c('0xae')]){_0x5d03e4[_0x7c2c('0xb8')]=[{'all':!![]}];}return db[_0x7c2c('0xb5')][_0x7c2c('0xb9')](_0x5d03e4);})[_0x7c2c('0x34')](function(_0x46448b){_0x33f85d['rows']=_0x46448b;return _0x33f85d;});}})[_0x7c2c('0x34')](respondWithFilteredResult(_0x2bcb0c,_0x5d03e4))[_0x7c2c('0x35')](handleError(_0x2bcb0c,null));};exports[_0x7c2c('0xba')]=function(_0x5ad538,_0x316b34,_0xbf45fe){return db[_0x7c2c('0x37')][_0x7c2c('0x5b')]({'where':{'id':_0x5ad538[_0x7c2c('0xb2')]['id']}})[_0x7c2c('0x34')](handleEntityNotFound(_0x316b34,null))[_0x7c2c('0x34')](function(_0x450016){if(_0x450016){return _0x450016[_0x7c2c('0xbb')](_0x5ad538[_0x7c2c('0xb1')][_0x7c2c('0xb6')],_[_0x7c2c('0xbc')](_0x5ad538[_0x7c2c('0xb1')],[_0x7c2c('0xb6'),'id'])||{})[_0x7c2c('0xbd')](function(){return db['Tag'][_0x7c2c('0xb9')]({'attributes':['id','name',_0x7c2c('0x49')],'where':{'id':_0x5ad538[_0x7c2c('0xb1')]['ids']}});})[_0x7c2c('0x34')](function(_0x14acec){socket['emit']('whatsappInteractionTags:save',{'id':Number(_0x5ad538[_0x7c2c('0xb2')]['id']),'tags':_0x14acec||[]});return{'id':Number(_0x5ad538[_0x7c2c('0xb2')]['id']),'tags':_0x14acec||[]};});}})[_0x7c2c('0x34')](respondWithResult(_0x316b34,null))[_0x7c2c('0x35')](handleError(_0x316b34,null));};exports['removeTags']=function(_0x5749a6,_0x2d813f,_0x168bd1){return db[_0x7c2c('0x37')][_0x7c2c('0x5b')]({'where':{'id':_0x5749a6['params']['id']}})[_0x7c2c('0x34')](handleEntityNotFound(_0x2d813f,null))[_0x7c2c('0x34')](function(_0x317445){if(_0x317445){return _0x317445[_0x7c2c('0xbe')](_0x5749a6[_0x7c2c('0x3a')]['ids']);}})[_0x7c2c('0x34')](respondWithStatusCode(_0x2d813f,null))[_0x7c2c('0x35')](handleError(_0x2d813f,null));};exports[_0x7c2c('0xbf')]=function(_0x2b1004,_0x53acb1){var _0x34d54b=moment()[_0x7c2c('0xc0')]()[_0x7c2c('0x96')]();var _0x54033a=path['join'](config[_0x7c2c('0xc1')],_0x7c2c('0xc2'),'files',_0x7c2c('0xc3'));var _0x3e23a2=path[_0x7c2c('0xc4')](config[_0x7c2c('0xc1')],'server',_0x7c2c('0xc5'),_0x7c2c('0xc6'));var _0x3af921=path[_0x7c2c('0xc4')](_0x54033a,_0x34d54b);var _0xf5234a=util[_0x7c2c('0xb7')](_0x7c2c('0xc7'),_0x2b1004[_0x7c2c('0xb2')]['id'],_0x34d54b);var _0x4af0eb=path[_0x7c2c('0xc4')](_0x54033a,_0xf5234a);var _0x3ab89b=[];_0x3ab89b[_0x7c2c('0x33')]({'model':db[_0x7c2c('0x6b')],'as':_0x7c2c('0x6b'),'attributes':['id',_0x7c2c('0x2f')],'raw':!![]});_0x3ab89b[_0x7c2c('0x33')]({'model':db['CmContact'],'as':_0x7c2c('0xc8'),'attributes':['id',_0x7c2c('0xc9'),_0x7c2c('0xca')],'raw':!![]});if(_0x2b1004['query'][_0x7c2c('0xc6')]){_0x3ab89b[_0x7c2c('0x33')]({'model':db[_0x7c2c('0xcb')],'as':_0x7c2c('0xcb'),'raw':!![]});}var _0x5325fc=[{'model':db[_0x7c2c('0xb5')],'as':'Messages','attributes':['id',_0x7c2c('0xb1'),'createdAt',_0x7c2c('0xcc'),_0x7c2c('0xcd'),_0x7c2c('0x7b')],'include':_0x3ab89b}];_0x5325fc[_0x7c2c('0x33')]({'model':db['WhatsappAccount'],'as':_0x7c2c('0xce'),'attributes':['id','name']});_0x5325fc[_0x7c2c('0x33')]({'model':db[_0x7c2c('0x6b')],'as':'Owner','attributes':['id',_0x7c2c('0x2f')]});return db['WhatsappInteraction']['find']({'where':{'id':_0x2b1004[_0x7c2c('0xb2')]['id']},'include':_0x5325fc})['then'](handleEntityNotFound(_0x53acb1,null))[_0x7c2c('0x34')](function(_0xec14ba){if(_0xec14ba){var _0x431b31=_0xec14ba[_0x7c2c('0xcf')]({'plain':!![]});fs[_0x7c2c('0xd0')](_0x3af921);var _0x5db9cb={'format':'A4','border':_0x7c2c('0xd1'),'header':{'height':_0x7c2c('0xd2'),'contents':{'first':_0x7c2c('0xd3')}},'footer':{'height':'30px','contents':{'default':util[_0x7c2c('0xb7')](_0x7c2c('0xd4'),util[_0x7c2c('0xb7')]('%s\x20#%d',_0x7c2c('0xd5'),_0x431b31['id']),moment()[_0x7c2c('0xb7')]('YYYY-MM-DD')[_0x7c2c('0x96')]())}}};var _0x2f140c={'channel':_0x7c2c('0xd5'),'account':_0x431b31[_0x7c2c('0xce')]['name'],'agent':_0x431b31[_0x7c2c('0xd6')]?_0x431b31[_0x7c2c('0xd6')][_0x7c2c('0x2f')]:'N.A.','createdAt':moment(_0x431b31[_0x7c2c('0x75')])[_0x7c2c('0xb7')]('YYYY-MM-DD\x20HH:mm:ss')[_0x7c2c('0x96')](),'closedAt':_0x431b31['closed']?moment(_0x431b31[_0x7c2c('0xd7')])[_0x7c2c('0xb7')]('YYYY-MM-DD\x20HH:mm:ss')[_0x7c2c('0x96')]():'','disposition':_0x431b31[_0x7c2c('0xd8')],'messages':_(_0x431b31[_0x7c2c('0xd9')])[_0x7c2c('0x7f')]({'secret':![]})[_0x7c2c('0x2e')](function(_0x1396e1){if(_0x1396e1['Attachment']){var _0x152022=path[_0x7c2c('0xc4')](_0x3e23a2,_0x1396e1[_0x7c2c('0xcb')][_0x7c2c('0xda')]);if(fs[_0x7c2c('0xdb')](_0x152022)){fs[_0x7c2c('0xdc')](_0x152022)['pipe'](fs[_0x7c2c('0xdd')](path[_0x7c2c('0xc4')](_0x3af921,_0x1396e1[_0x7c2c('0xcb')][_0x7c2c('0xda')])));}}return{'date':moment(_0x1396e1[_0x7c2c('0x75')])[_0x7c2c('0xb7')](_0x7c2c('0xde'))['toString'](),'sender':_0x1396e1[_0x7c2c('0xcc')]===_0x7c2c('0xdf')?_0x1396e1[_0x7c2c('0x6b')]?_0x1396e1['User'][_0x7c2c('0x2f')]:_0x7c2c('0xe0'):_0x1396e1[_0x7c2c('0xc8')][_0x7c2c('0xc9')]+(_0x1396e1[_0x7c2c('0xc8')][_0x7c2c('0xca')]?'\x20'+_0x1396e1[_0x7c2c('0xc8')][_0x7c2c('0xca')]:''),'body':_0x1396e1[_0x7c2c('0xcb')]?_0x1396e1[_0x7c2c('0xcb')][_0x7c2c('0xda')]:_0x1396e1[_0x7c2c('0xb1')],'direction':_0x1396e1[_0x7c2c('0xcc')]===_0x7c2c('0xdf')?'A':'C','secret':_0x1396e1['secret'],'read':_0x1396e1[_0x7c2c('0x7b')],'attachment':_0x1396e1[_0x7c2c('0xcb')]};})[_0x7c2c('0x60')]()};return ejs[_0x7c2c('0xe1')](path[_0x7c2c('0xc4')](config[_0x7c2c('0xc1')],_0x7c2c('0xc2'),_0x7c2c('0xe2'),'downloadInteraction.html'),{'interaction':_0x2f140c})[_0x7c2c('0x34')](function(_0x545199){return new BPromise(function(_0xbeb3b,_0x22c26b){pdf[_0x7c2c('0xb0')](_0x545199,_0x5db9cb)[_0x7c2c('0xe3')](path['join'](_0x3af921,_0x7c2c('0xe4')+_0x431b31['id']+'-'+_0x34d54b+_0x7c2c('0xe5')),function(_0x1d9da5,_0x230eaa){if(_0x1d9da5)return _0x22c26b(_0x1d9da5);_0xbeb3b(_0x230eaa);});});})[_0x7c2c('0x34')](function(){return new BPromise(function(_0x4a4a2f,_0x2354e9){zipdir(_0x3af921,{'saveTo':_0x4af0eb},function(_0xf60ff2,_0x46a52b){if(_0xf60ff2)return _0x2354e9(_0xf60ff2);return _0x4a4a2f(_0x46a52b);});})[_0x7c2c('0x34')](function(){return new BPromise(function(_0xc21fb5,_0x49fdcd){rimraf(_0x3af921,function(_0x2c88b5){if(_0x2c88b5)_0x49fdcd(_0x2c88b5);return _0xc21fb5();});});})[_0x7c2c('0x34')](function(){return _0x53acb1[_0x7c2c('0xbf')](_0x4af0eb,_0xf5234a,function(_0xe63c5c){if(_0xe63c5c){console['log'](_0x7c2c('0xe6'),_0xe63c5c);}else{fs['unlinkSync'](_0x4af0eb);}});});});}else{return _0x53acb1[_0x7c2c('0x28')](0xc8);}})[_0x7c2c('0x35')](handleError(_0x53acb1,null));};
\ No newline at end of file
+var _0xf777=['pipe','basename','out','System','renderFile','views','downloadInteraction.ejs','transcript-','createPdfFromHTML','log','err','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','fs-extra','squel','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','limit','undefined','count','reject','save','update','then','destroy','error','stack','name','send','Users','map','fullname','TagIds','Tags','split','forEach','push','catch','answered','unmanaged','closed','waiting','talking','UserId','total','index','WhatsappInteraction','fieldName','type','key','model','query','keys','intersection','attributes','length','hasOwnProperty','nolimit','order','where','filters','pick','select','field','color','from','tools_tags','u.id','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','left_join','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','parseSearch','sqlOperator','conditions','find','unreadMessages','value','having','`\x20=\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','text','start','Tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','body','some','compact','isEmpty','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','read','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','filter','replace','isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','Sequelize','QueryTypes','i.id','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','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','role','sequelize','toString','keyBy','merge','fields','a.key','Account.key','a.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.lastName','Contact.email','c.phone','Contact.fax','o.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','groupBy','WhatsappInteractionId','params','rawAttributes','includeAll','options','create','describe','addMessage','WhatsappMessage','ids','sort','YYYY-MM-DD\x20HH:mm:ss','findAll','rows','addTags','setTags','omit','spread','whatsappInteractionTags:save','removeTags','download','join','root','server','files','format','transcript-%d-%s.zip','firstName','lastName','attachments','Attachment','Messages','direction','secret','WhatsappAccount','Account','Owner','mkdirSync','Whatsapp','N.A.','closedAt','disposition','createReadStream'];(function(_0x455680,_0x3891d0){var _0x19d21c=function(_0xa165ee){while(--_0xa165ee){_0x455680['push'](_0x455680['shift']());}};_0x19d21c(++_0x3891d0);}(_0xf777,0x1e9));var _0x7f77=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xf777[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require(_0x7f77('0x0'));var rimraf=require(_0x7f77('0x1'));var zipdir=require(_0x7f77('0x2'));var jsonpatch=require(_0x7f77('0x3'));var rp=require(_0x7f77('0x4'));var moment=require(_0x7f77('0x5'));var BPromise=require(_0x7f77('0x6'));var Mustache=require(_0x7f77('0x7'));var util=require(_0x7f77('0x8'));var path=require('path');var sox=require(_0x7f77('0x9'));var csv=require(_0x7f77('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7f77('0xb'));var _=require('lodash');var squel=require(_0x7f77('0xc'));var crypto=require('crypto');var jsforce=require(_0x7f77('0xd'));var deskjs=require(_0x7f77('0xe'));var toCsv=require(_0x7f77('0xa'));var querystring=require(_0x7f77('0xf'));var Papa=require(_0x7f77('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7f77('0x11'));var as=require(_0x7f77('0x12'));var pdf=require(_0x7f77('0x13'));var hardwareService=require(_0x7f77('0x14'));var logger=require(_0x7f77('0x15'))('api');var utils=require(_0x7f77('0x16'));var config=require(_0x7f77('0x17'));var licenseUtil=require(_0x7f77('0x18'));var db=require(_0x7f77('0x19'))['db'];config[_0x7f77('0x1a')]=_['defaults'](config['redis'],{'host':_0x7f77('0x1b'),'port':0x18eb});var socket=require(_0x7f77('0x1c'))(new Redis(config[_0x7f77('0x1a')]));require(_0x7f77('0x1d'))[_0x7f77('0x1e')](socket);function respondWithStatusCode(_0x194b15,_0x1f0729){_0x1f0729=_0x1f0729||0xcc;return function(_0x2efdd1){if(_0x2efdd1){return _0x194b15[_0x7f77('0x1f')](_0x1f0729);}return _0x194b15[_0x7f77('0x20')](_0x1f0729)[_0x7f77('0x21')]();};}function respondWithResult(_0x29d2cb,_0x186f7a){_0x186f7a=_0x186f7a||0xc8;return function(_0x3f96e9){if(_0x3f96e9){return _0x29d2cb[_0x7f77('0x20')](_0x186f7a)[_0x7f77('0x22')](_0x3f96e9);}};}function respondWithFilteredResult(_0x4a4e3b,_0x5b2c85){return function(_0x32221e){if(_0x32221e){var _0x53ec10=typeof _0x5b2c85[_0x7f77('0x23')]==='undefined'&&typeof _0x5b2c85[_0x7f77('0x24')]===_0x7f77('0x25');var _0x359f63=_0x32221e['count'];var _0x2b5de4=_0x53ec10?0x0:_0x5b2c85[_0x7f77('0x23')];var _0x4d7283=_0x53ec10?_0x32221e[_0x7f77('0x26')]:_0x5b2c85[_0x7f77('0x23')]+_0x5b2c85[_0x7f77('0x24')];var _0x48647f;if(_0x4d7283>=_0x359f63){_0x4d7283=_0x359f63;_0x48647f=0xc8;}else{_0x48647f=0xce;}_0x4a4e3b[_0x7f77('0x20')](_0x48647f);return _0x4a4e3b['set']('Content-Range',_0x2b5de4+'-'+_0x4d7283+'/'+_0x359f63)[_0x7f77('0x22')](_0x32221e);}return null;};}function patchUpdates(_0x30c54c){return function(_0x583faf){try{jsonpatch['apply'](_0x583faf,_0x30c54c,!![]);}catch(_0x2493a0){return BPromise[_0x7f77('0x27')](_0x2493a0);}return _0x583faf[_0x7f77('0x28')]();};}function saveUpdates(_0x596139,_0x5e03a3){return function(_0x13662c){if(_0x13662c){return _0x13662c[_0x7f77('0x29')](_0x596139)[_0x7f77('0x2a')](function(_0x3d66d5){return _0x3d66d5;});}return null;};}function removeEntity(_0xd78c83,_0x110f46){return function(_0x56484c){if(_0x56484c){return _0x56484c[_0x7f77('0x2b')]()['then'](function(){_0xd78c83[_0x7f77('0x20')](0xcc)[_0x7f77('0x21')]();});}};}function handleEntityNotFound(_0x5e119f,_0x2bd7e0){return function(_0x386842){if(!_0x386842){_0x5e119f['sendStatus'](0x194);}return _0x386842;};}function handleError(_0x563d58,_0x53ac60){_0x53ac60=_0x53ac60||0x1f4;return function(_0x341b5a){logger[_0x7f77('0x2c')](_0x341b5a[_0x7f77('0x2d')]);if(_0x341b5a[_0x7f77('0x2e')]){delete _0x341b5a[_0x7f77('0x2e')];}_0x563d58[_0x7f77('0x20')](_0x53ac60)[_0x7f77('0x2f')](_0x341b5a);};}function getInteractionUsers(_0x4dcea4,_0x268c18){return new BPromise(function(_0x26c84c,_0x19d93f){try{if(_0x268c18[_0x4dcea4['id']]){_0x4dcea4[_0x7f77('0x30')]=_[_0x7f77('0x31')](_0x268c18[_0x4dcea4['id']],function(_0x429729){return{'id':_0x429729['id'],'fullname':_0x429729[_0x7f77('0x32')]};});}}catch(_0x4d26b2){_0x19d93f(_0x4d26b2);}_0x26c84c(_0x4dcea4);});}function getInteractionTags(_0x57c638,_0x558a16){return new BPromise(function(_0x11723e,_0x1d6c28){try{if(_0x57c638[_0x7f77('0x33')]){_0x57c638[_0x7f77('0x34')]=[];_0x57c638[_0x7f77('0x33')][_0x7f77('0x35')](',')[_0x7f77('0x36')](function(_0x3a9b6c){_0x57c638[_0x7f77('0x34')][_0x7f77('0x37')](_0x558a16[_0x3a9b6c]);});}delete _0x57c638[_0x7f77('0x33')];}catch(_0x5028d7){_0x1d6c28(_0x5028d7);}_0x11723e(_0x57c638);});}function updateWhatsappInteraction(_0x2a96f2,_0x205061,_0x2a9378){return new BPromise(function(_0x41c413,_0x36b142){return getInteractionUsers(_0x2a96f2,_0x2a9378)[_0x7f77('0x2a')](function(_0x307a71){return getInteractionTags(_0x307a71,_0x205061);})[_0x7f77('0x2a')](function(_0x35f4d0){return getStateInteraction(_0x35f4d0);})[_0x7f77('0x2a')](function(_0x4b1941){_0x41c413(_0x4b1941);})[_0x7f77('0x38')](function(_0x57173c){_0x36b142(_0x57173c);});});}function getStateInteraction(_0x35aa29){return new BPromise(function(_0x277606){_0x35aa29['waiting']=0x0;_0x35aa29['talking']=0x0;_0x35aa29[_0x7f77('0x39')]=0x0;_0x35aa29[_0x7f77('0x3a')]=0x0;_0x35aa29['total']=0x0;if(!_0x35aa29[_0x7f77('0x3b')]&&!_0x35aa29['UserId']){_0x35aa29[_0x7f77('0x3c')]+=0x1;}if(!_0x35aa29[_0x7f77('0x3b')]&&_0x35aa29['UserId']){_0x35aa29[_0x7f77('0x3d')]+=0x1;if(_0x35aa29[_0x7f77('0x3c')]){_0x35aa29[_0x7f77('0x3c')]-=0x1;}}if(_0x35aa29[_0x7f77('0x3b')]&&_0x35aa29[_0x7f77('0x3e')]){_0x35aa29[_0x7f77('0x39')]+=0x1;if(_0x35aa29[_0x7f77('0x3d')]){_0x35aa29[_0x7f77('0x3d')]-=0x1;}}if(_0x35aa29[_0x7f77('0x3b')]&&!_0x35aa29['UserId']){_0x35aa29[_0x7f77('0x3a')]+=0x1;if(_0x35aa29[_0x7f77('0x3c')]){_0x35aa29[_0x7f77('0x3c')]-=0x1;}}_0x35aa29[_0x7f77('0x3f')]+=0x1;_0x277606(_0x35aa29);});}exports[_0x7f77('0x40')]=function(_0x186ca2,_0x5863ad){var _0x41614b={},_0x526dfb={},_0x2fc747={'count':0x0,'rows':[]};var _0x26b1be=_['map'](db[_0x7f77('0x41')]['rawAttributes'],function(_0x1e1ca3){return{'name':_0x1e1ca3[_0x7f77('0x42')],'type':_0x1e1ca3[_0x7f77('0x43')][_0x7f77('0x44')]};});_0x526dfb[_0x7f77('0x45')]=_['map'](_0x26b1be,_0x7f77('0x2e'));_0x526dfb[_0x7f77('0x46')]=_[_0x7f77('0x47')](_0x186ca2[_0x7f77('0x46')]);_0x526dfb['filters']=_[_0x7f77('0x48')](_0x526dfb[_0x7f77('0x45')],_0x526dfb[_0x7f77('0x46')]);_0x41614b['attributes']=_[_0x7f77('0x48')](_0x526dfb[_0x7f77('0x45')],qs['fields'](_0x186ca2[_0x7f77('0x46')]['fields']));_0x41614b['attributes']=_0x41614b[_0x7f77('0x49')][_0x7f77('0x4a')]?_0x41614b['attributes']:_0x526dfb[_0x7f77('0x45')];if(!_0x186ca2[_0x7f77('0x46')][_0x7f77('0x4b')](_0x7f77('0x4c'))){_0x41614b['limit']=qs[_0x7f77('0x24')](_0x186ca2[_0x7f77('0x46')][_0x7f77('0x24')]);_0x41614b[_0x7f77('0x23')]=qs['offset'](_0x186ca2[_0x7f77('0x46')][_0x7f77('0x23')]);}_0x41614b[_0x7f77('0x4d')]=qs['sort'](_0x186ca2[_0x7f77('0x46')]['sort']);_0x41614b[_0x7f77('0x4e')]=qs[_0x7f77('0x4f')](_[_0x7f77('0x50')](_0x186ca2['query'],_0x526dfb['filters']),_0x26b1be);var _0x3f65d8=[];var _0x296152=squel[_0x7f77('0x51')]()[_0x7f77('0x52')]('id')[_0x7f77('0x52')](_0x7f77('0x2e'))[_0x7f77('0x52')](_0x7f77('0x53'))[_0x7f77('0x54')](_0x7f77('0x55'));var _0x34a835=squel[_0x7f77('0x51')]()['field'](_0x7f77('0x56'))[_0x7f77('0x52')](_0x7f77('0x57'))[_0x7f77('0x52')](_0x7f77('0x58'))[_0x7f77('0x54')](_0x7f77('0x59'),'ui')[_0x7f77('0x5a')](_0x7f77('0x5b'),'u',_0x7f77('0x5c'));var _0x1ba85b=squel['select']()[_0x7f77('0x54')](_0x7f77('0x5d'),'i')[_0x7f77('0x5a')](_0x7f77('0x5e'),'c',_0x7f77('0x5f'))['left_join'](_0x7f77('0x5b'),'o','o.id\x20=\x20i.UserId')[_0x7f77('0x5a')](_0x7f77('0x60'),'a',_0x7f77('0x61'))[_0x7f77('0x5a')](_0x7f77('0x62'),'me','me.WhatsappInteractionId\x20=\x20i.id')[_0x7f77('0x5a')]('whatsapp_interaction_has_tags','it',_0x7f77('0x63'))['left_join'](_0x7f77('0x55'),'t',_0x7f77('0x64'));var _0xa31ce6=squel[_0x7f77('0x65')]();var _0x413ea2=[];var _0x55ec4c=squel['expr']();var _0x3de08f;if(_0x186ca2[_0x7f77('0x46')]['search']){_0x3de08f=as[_0x7f77('0x66')](_0x186ca2[_0x7f77('0x46')]['search']);var _0xcf5343=_0x3de08f[_0x7f77('0x67')];for(var _0x30d2c9=0x0;_0x30d2c9<_0x3de08f[_0x7f77('0x68')][_0x7f77('0x4a')];_0x30d2c9++){var _0x401394=_0x3de08f[_0x7f77('0x68')][_0x30d2c9];var _0x5c94d0='i';var _0x149f91=_[_0x7f77('0x69')](_0x26b1be,[_0x7f77('0x2e'),_0x401394['field']]);if(!_0x149f91){switch(_0x401394[_0x7f77('0x52')]){case _0x7f77('0x6a'):if(_0x401394[_0x7f77('0x6b')]==0x1){_0x1ba85b[_0x7f77('0x6c')]('`'+_0x401394['field']+_0x7f77('0x6d'));}else{_0x1ba85b[_0x7f77('0x6c')]('`'+_0x401394[_0x7f77('0x52')]+'`\x20>\x200');}break;case _0x7f77('0x6e'):if(_0x401394[_0x7f77('0x6f')]===_0x7f77('0x70')){if(_0x401394[_0x7f77('0x6b')][_0x7f77('0x35')]('\x20')['length']>0x1){_0xa31ce6[_0xcf5343](_0x7f77('0x71'),qs['getFullTextValue'](_0x401394['value']),null);}else{var _0x15d23f='%'+_0x401394[_0x7f77('0x6b')]+'%';_0xa31ce6[_0xcf5343](_0x7f77('0x72'),_0x15d23f,_0x15d23f,_0x15d23f);}}else{_0x149f91=_[_0x7f77('0x69')](_0x26b1be,[_0x7f77('0x2e'),_0x7f77('0x73')]);_0x401394['field']='ContactId';_0xbcf31c=as[_0x7f77('0x74')](_0x5c94d0,_0x149f91['type'],_0x401394);_0xa31ce6[_0xcf5343](_0xbcf31c[_0x7f77('0x75')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x76')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x21')]);}break;case _0x7f77('0x77'):var _0x281e5f=_0x401394[_0x7f77('0x6b')][_0x7f77('0x35')](',')[_0x7f77('0x31')](function(_0x4b13f2){return Number(_0x4b13f2);});_0x281e5f[_0x7f77('0x36')](function(_0x23ecb2){_0x55ec4c['or'](_0x7f77('0x78'),'%,'+_0x23ecb2+',%');});_0x413ea2=_[_0x7f77('0x79')](_0x413ea2,_0x281e5f);break;case _0x7f77('0x7a'):if(_0x401394[_0x7f77('0x6f')]==='$substring'){_0xa31ce6[_0xcf5343](_0x7f77('0x7b'),'%'+_0x401394[_0x7f77('0x6b')]+'%',null);}else{_0x149f91=_[_0x7f77('0x69')](_0x26b1be,[_0x7f77('0x2e'),_0x7f77('0x3e')]);_0x401394[_0x7f77('0x52')]='UserId';_0xbcf31c=as[_0x7f77('0x74')](_0x5c94d0,_0x149f91[_0x7f77('0x43')],_0x401394);_0xa31ce6[_0xcf5343](_0xbcf31c[_0x7f77('0x75')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x76')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x21')]);}break;case _0x7f77('0x7c'):_0xbcf31c=as[_0x7f77('0x74')]('me',null,_0x401394);_0xa31ce6[_0xcf5343](_0xbcf31c[_0x7f77('0x75')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x76')],_0xbcf31c[_0x7f77('0x6b')][_0x7f77('0x21')]);break;}}else{var _0xbcf31c=as[_0x7f77('0x74')](_0x5c94d0,_0x149f91[_0x7f77('0x43')],_0x401394);_0xa31ce6[_0xcf5343](_0xbcf31c[_0x7f77('0x75')],_0xbcf31c[_0x7f77('0x6b')]['start'],_0xbcf31c['value'][_0x7f77('0x21')]);}}}else{var _0xec1a14=_(_0x186ca2[_0x7f77('0x46')])['keys']()[_0x7f77('0x31')](function(_0x5c95ea){return _[_0x7f77('0x7d')](_0x26b1be,['name',_0x5c95ea])?_0x5c95ea:undefined;})[_0x7f77('0x7e')]()[_0x7f77('0x6b')]();if(!_[_0x7f77('0x7f')](_0xec1a14)){_0xec1a14['forEach'](function(_0x1c1153){if(_0x1c1153===_0x7f77('0x80')){_0x1ba85b[_0x7f77('0x4e')](_0x7f77('0x81'),[][_0x7f77('0x82')](_0x186ca2[_0x7f77('0x46')][_0x1c1153]));}else if(_0x1c1153===_0x7f77('0x83')){var _0x2d9c62=JSON[_0x7f77('0x84')](_0x186ca2[_0x7f77('0x46')][_0x1c1153])[_0x7f77('0x85')];var _0x55910c=JSON[_0x7f77('0x84')](_0x186ca2[_0x7f77('0x46')][_0x1c1153])[_0x7f77('0x86')];_0x1ba85b[_0x7f77('0x4e')](_0x7f77('0x87'),_0x2d9c62,_0x55910c);}else{if(_0x186ca2[_0x7f77('0x46')][_0x1c1153]===_0x7f77('0x88')){_0x1ba85b['where']('i.'+_0x1c1153+'\x20IS\x20NULL');}else{_0x1ba85b[_0x7f77('0x4e')]('i.'+_0x1c1153+_0x7f77('0x89'),_0x186ca2['query'][_0x1c1153]);}}});}if(_0x186ca2[_0x7f77('0x46')][_0x7f77('0x8a')]){if(_0x186ca2[_0x7f77('0x46')]['read']==0x1){_0x1ba85b['having'](_0x7f77('0x8b'));}else{_0x1ba85b[_0x7f77('0x6c')](_0x7f77('0x8c'));}}if(_0x186ca2[_0x7f77('0x46')][_0x7f77('0x8d')]){_0x413ea2=_[_0x7f77('0x8e')](_0x186ca2['query'][_0x7f77('0x8d')])?_0x186ca2['query']['tag']:new Array(_0x186ca2[_0x7f77('0x46')][_0x7f77('0x8d')]);_0x413ea2[_0x7f77('0x36')](function(_0x1113ff){_0x55ec4c['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x1113ff+',%');});}if(_0x186ca2[_0x7f77('0x46')][_0x7f77('0x8f')]){var _0x2248f8=_0x186ca2[_0x7f77('0x46')][_0x7f77('0x8f')][_0x7f77('0x90')]('\x5c','\x5c\x5c')[_0x7f77('0x90')](/'/g,'\x27\x27');if(qs[_0x7f77('0x91')](_0x2248f8)){_0xa31ce6['or'](_0x7f77('0x92'),_0x2248f8+'%')['or'](_0x7f77('0x93'),_0x2248f8+'%');}else{_0xa31ce6['or'](_0x7f77('0x94'),qs[_0x7f77('0x95')](_0x2248f8))['or'](_0x7f77('0x96'),_0x2248f8+'%');}}}_0x1ba85b[_0x7f77('0x4e')](_0xa31ce6);_0x1ba85b[_0x7f77('0x97')]('i.id');var _0x28e8f2={'type':db[_0x7f77('0x98')][_0x7f77('0x99')]['SELECT'],'raw':!![]};var _0x4a1b86=_0x1ba85b['clone']();_0x4a1b86[_0x7f77('0x52')](_0x7f77('0x9a'));_0x4a1b86['field'](_0x7f77('0x9b'),_0x7f77('0x6a'));if(_0x41614b['order']){_0x41614b['order']['forEach'](function(_0x2fb49d){var _0x32005e=_0x2fb49d[0x0]===_0x7f77('0x9c')?_0x2fb49d[0x0]:'i.'+_0x2fb49d[0x0];_0x1ba85b[_0x7f77('0x4d')](_0x32005e,_0x2fb49d[0x1]===_0x7f77('0x9d')?![]:!![]);});}if(!_[_0x7f77('0x7f')](_0x413ea2)){_0x1ba85b[_0x7f77('0x6c')](_0x55ec4c);_0x4a1b86[_0x7f77('0x4e')](_0x7f77('0x9e'),_0x413ea2);}BPromise[_0x7f77('0x9f')]()[_0x7f77('0x2a')](function(){if(!_0x3de08f){if(_0x186ca2[_0x7f77('0x46')]['WhatsappAccountId'])return;_0x4a1b86['where'](_0x7f77('0xa0'));_0x1ba85b[_0x7f77('0x4e')](_0x7f77('0xa0'));return;}if(_0x186ca2[_0x7f77('0xa1')]['role']!==_0x7f77('0xa2'))return;return _0x186ca2[_0x7f77('0xa1')][_0x7f77('0xa3')]({'attributes':['id'],'raw':!![]})[_0x7f77('0x2a')](function(_0x12fb97){if(_[_0x7f77('0x7f')](_0x12fb97)){_0x4a1b86[_0x7f77('0x4e')](_0x7f77('0xa4'));_0x1ba85b[_0x7f77('0x4e')](_0x7f77('0xa4'));}else{_0x4a1b86[_0x7f77('0x4e')](_0x7f77('0x81'),_[_0x7f77('0x31')](_0x12fb97,'id'));_0x1ba85b[_0x7f77('0x4e')](_0x7f77('0x81'),_[_0x7f77('0x31')](_0x12fb97,'id'));}});})[_0x7f77('0x2a')](function(){if(_0x186ca2[_0x7f77('0xa1')][_0x7f77('0xa5')]===_0x7f77('0xa2')&&!_0x3de08f&&!_0x186ca2[_0x7f77('0x46')][_0x7f77('0x80')])return[];return db[_0x7f77('0xa6')][_0x7f77('0x46')](_0x4a1b86[_0x7f77('0xa7')](),_0x28e8f2);})[_0x7f77('0x2a')](function(_0x270592){_0x2fc747['count']=_0x270592[_0x7f77('0x4a')];if(_0x2fc747[_0x7f77('0x26')]===0x0)return[];return db[_0x7f77('0xa6')][_0x7f77('0x46')](_0x296152[_0x7f77('0xa7')](),_0x28e8f2)[_0x7f77('0x2a')](function(_0x362d16){_0x3f65d8=_[_0x7f77('0xa8')](_0x362d16,'id');_0x28e8f2=_[_0x7f77('0xa9')](_0x28e8f2,{'model':db[_0x7f77('0x41')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x186ca2[_0x7f77('0x46')][_0x7f77('0xaa')]){_0x41614b[_0x7f77('0x49')]['forEach'](function(_0x4411fe){_0x1ba85b[_0x7f77('0x52')]('i.'+_0x4411fe);});}else{_0x1ba85b[_0x7f77('0x52')](_0x7f77('0x9b'),'unreadMessages');_0x1ba85b[_0x7f77('0x52')](_0x7f77('0xab'),_0x7f77('0xac'));_0x1ba85b['field'](_0x7f77('0xad'),'Account.mandatoryDisposition');_0x1ba85b['field'](_0x7f77('0xae'),_0x7f77('0x9c'));_0x1ba85b[_0x7f77('0x52')](_0x7f77('0xaf'));_0x1ba85b['field'](_0x7f77('0xb0'),'Contact.firstName');_0x1ba85b[_0x7f77('0x52')]('c.lastName',_0x7f77('0xb1'));_0x1ba85b[_0x7f77('0x52')]('c.email',_0x7f77('0xb2'));_0x1ba85b[_0x7f77('0x52')](_0x7f77('0xb3'),'Contact.phone');_0x1ba85b[_0x7f77('0x52')]('c.mobile','Contact.mobile');_0x1ba85b[_0x7f77('0x52')]('c.fax',_0x7f77('0xb4'));_0x1ba85b[_0x7f77('0x52')](_0x7f77('0xb5'),'Owner.fullname');_0x1ba85b['field'](_0x7f77('0xb6'),'Owner.internal');_0x1ba85b[_0x7f77('0x52')](_0x7f77('0xb7'),'TagIds');}if(_0x41614b[_0x7f77('0x24')])_0x1ba85b[_0x7f77('0x24')](_0x41614b[_0x7f77('0x24')]);if(_0x41614b[_0x7f77('0x23')])_0x1ba85b[_0x7f77('0x23')](_0x41614b[_0x7f77('0x23')]);return db[_0x7f77('0xa6')][_0x7f77('0x46')](_0x1ba85b['toString'](),_0x28e8f2);})[_0x7f77('0x2a')](function(_0x18fd10){if(_0x18fd10['length']>0x0)_0x34a835[_0x7f77('0x4e')]('ui.WhatsappInteractionId\x20IN\x20?',_[_0x7f77('0x31')](_0x18fd10,'id'));return db[_0x7f77('0xa6')][_0x7f77('0x46')](_0x34a835[_0x7f77('0xa7')](),_0x28e8f2)['then'](function(_0x5e4398){var _0x46d184=_[_0x7f77('0xb8')](_0x5e4398,_0x7f77('0xb9'));var _0xfa5c29=[];_0x18fd10[_0x7f77('0x36')](function(_0x411683){_0xfa5c29[_0x7f77('0x37')](updateWhatsappInteraction(_0x411683,_0x3f65d8,_0x46d184));});return BPromise['all'](_0xfa5c29);});});})[_0x7f77('0x2a')](function(_0x3858a4){_0x2fc747['rows']=_0x3858a4;return _0x2fc747;})['then'](respondWithFilteredResult(_0x5863ad,_0x41614b))[_0x7f77('0x38')](handleError(_0x5863ad,null));};exports['show']=function(_0x5240ee,_0x33d928){var _0x2ea72b={'raw':![],'where':{'id':_0x5240ee[_0x7f77('0xba')]['id']}},_0x987285={};_0x987285[_0x7f77('0x45')]=_['keys'](db[_0x7f77('0x41')][_0x7f77('0xbb')]);_0x987285[_0x7f77('0x46')]=_[_0x7f77('0x47')](_0x5240ee[_0x7f77('0x46')]);_0x987285[_0x7f77('0x4f')]=_['intersection'](_0x987285[_0x7f77('0x45')],_0x987285['query']);_0x2ea72b['attributes']=_[_0x7f77('0x48')](_0x987285[_0x7f77('0x45')],qs[_0x7f77('0xaa')](_0x5240ee[_0x7f77('0x46')][_0x7f77('0xaa')]));_0x2ea72b['attributes']=_0x2ea72b['attributes'][_0x7f77('0x4a')]?_0x2ea72b['attributes']:_0x987285['model'];if(_0x5240ee[_0x7f77('0x46')][_0x7f77('0xbc')]){_0x2ea72b['include']=[{'all':!![]}];}_0x2ea72b=_[_0x7f77('0xa9')]({},_0x2ea72b,_0x5240ee[_0x7f77('0xbd')]);return db[_0x7f77('0x41')][_0x7f77('0x69')](_0x2ea72b)[_0x7f77('0x2a')](handleEntityNotFound(_0x33d928,null))[_0x7f77('0x2a')](respondWithResult(_0x33d928,null))[_0x7f77('0x38')](handleError(_0x33d928,null));};exports[_0x7f77('0xbe')]=function(_0x2c5d9f,_0x1f949d){return db[_0x7f77('0x41')][_0x7f77('0xbe')](_0x2c5d9f[_0x7f77('0x7c')],{})[_0x7f77('0x2a')](respondWithResult(_0x1f949d,0xc9))[_0x7f77('0x38')](handleError(_0x1f949d,null));};exports[_0x7f77('0x29')]=function(_0x55d862,_0x2856fe){if(_0x55d862[_0x7f77('0x7c')]['id']){delete _0x55d862['body']['id'];}return db[_0x7f77('0x41')][_0x7f77('0x69')]({'where':{'id':_0x55d862[_0x7f77('0xba')]['id']}})[_0x7f77('0x2a')](handleEntityNotFound(_0x2856fe,null))[_0x7f77('0x2a')](saveUpdates(_0x55d862[_0x7f77('0x7c')],null))['then'](respondWithResult(_0x2856fe,null))['catch'](handleError(_0x2856fe,null));};exports[_0x7f77('0x2b')]=function(_0x17cb6c,_0x24a5c9){return db[_0x7f77('0x41')][_0x7f77('0x69')]({'where':{'id':_0x17cb6c['params']['id']}})[_0x7f77('0x2a')](handleEntityNotFound(_0x24a5c9,null))['then'](removeEntity(_0x24a5c9,null))['catch'](handleError(_0x24a5c9,null));};exports['describe']=function(_0x129dbb,_0x83c787){return db[_0x7f77('0x41')][_0x7f77('0xbf')]()[_0x7f77('0x2a')](respondWithResult(_0x83c787,null))[_0x7f77('0x38')](handleError(_0x83c787,null));};exports[_0x7f77('0xc0')]=function(_0x3d121a,_0x9c4f60,_0x5c9f3b){return db[_0x7f77('0xc1')][_0x7f77('0x69')]({'where':{'id':_0x3d121a['params']['id']}})[_0x7f77('0x2a')](handleEntityNotFound(_0x9c4f60,null))[_0x7f77('0x2a')](function(_0x4beb88){if(_0x4beb88){return _0x4beb88[_0x7f77('0xc0')](_0x3d121a[_0x7f77('0x7c')][_0x7f77('0xc2')],_['omit'](_0x3d121a['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x9c4f60,null))[_0x7f77('0x38')](handleError(_0x9c4f60,null));};exports['getMessages']=function(_0x4aed29,_0x368c9d,_0x30cf66){var _0x49e809={'raw':![],'where':{}};var _0x2ce04f={};var _0x58ecfb={'count':0x0,'rows':[]};return db[_0x7f77('0x41')]['findOne']({'where':{'id':_0x4aed29[_0x7f77('0xba')]['id']}})[_0x7f77('0x2a')](handleEntityNotFound(_0x368c9d,null))[_0x7f77('0x2a')](function(_0x322b64){if(_0x322b64){_0x2ce04f[_0x7f77('0x45')]=_['keys'](db['WhatsappMessage'][_0x7f77('0xbb')]);_0x2ce04f[_0x7f77('0x46')]=_[_0x7f77('0x47')](_0x4aed29[_0x7f77('0x46')]);_0x2ce04f['filters']=_['intersection'](_0x2ce04f[_0x7f77('0x45')],_0x2ce04f['query']);_0x49e809[_0x7f77('0x49')]=_[_0x7f77('0x48')](_0x2ce04f['model'],qs[_0x7f77('0xaa')](_0x4aed29[_0x7f77('0x46')][_0x7f77('0xaa')]));_0x49e809[_0x7f77('0x49')]=_0x49e809[_0x7f77('0x49')][_0x7f77('0x4a')]?_0x49e809[_0x7f77('0x49')]:_0x2ce04f[_0x7f77('0x45')];if(!_0x4aed29['query'][_0x7f77('0x4b')](_0x7f77('0x4c'))){_0x49e809[_0x7f77('0x24')]=qs['limit'](_0x4aed29[_0x7f77('0x46')][_0x7f77('0x24')]);_0x49e809[_0x7f77('0x23')]=qs[_0x7f77('0x23')](_0x4aed29[_0x7f77('0x46')]['offset']);}_0x49e809['order']=qs['sort'](_0x4aed29[_0x7f77('0x46')][_0x7f77('0xc3')]);_0x49e809[_0x7f77('0x4e')]=qs[_0x7f77('0x4f')](_['pick'](_0x4aed29['query'],_0x2ce04f[_0x7f77('0x4f')]));_0x49e809['where']['WhatsappInteractionId']=_0x322b64['id'];if(_0x4aed29[_0x7f77('0x46')][_0x7f77('0x8f')]){_0x49e809[_0x7f77('0x4e')]=_['merge'](_0x49e809['where'],{'$or':_[_0x7f77('0x31')](_0x49e809['attributes'],function(_0x39edec){var _0x5a361f={};_0x5a361f[_0x39edec]={'$like':'%'+_0x4aed29['query']['filter']+'%'};return _0x5a361f;})});}if(_0x4aed29[_0x7f77('0x46')][_0x7f77('0x85')]){var _0x5b5437=_0x4aed29['query'][_0x7f77('0x85')][_0x7f77('0x35')](',');var _0x3f238d={};_0x3f238d[_0x5b5437[0x0]]={'$gte':moment(_0x5b5437[0x1])['format'](_0x7f77('0xc4'))};_0x49e809['where']=_[_0x7f77('0xa9')](_0x49e809['where'],_0x3f238d);}_0x49e809=_[_0x7f77('0xa9')]({},_0x49e809,_0x4aed29[_0x7f77('0xbd')]);return db[_0x7f77('0xc1')][_0x7f77('0x26')]({'where':_0x49e809[_0x7f77('0x4e')]})[_0x7f77('0x2a')](function(_0x2a71aa){_0x58ecfb['count']=_0x2a71aa;if(_0x4aed29[_0x7f77('0x46')][_0x7f77('0xbc')]){_0x49e809['include']=[{'all':!![]}];}return db[_0x7f77('0xc1')][_0x7f77('0xc5')](_0x49e809);})[_0x7f77('0x2a')](function(_0x143236){_0x58ecfb[_0x7f77('0xc6')]=_0x143236;return _0x58ecfb;});}})['then'](respondWithFilteredResult(_0x368c9d,_0x49e809))[_0x7f77('0x38')](handleError(_0x368c9d,null));};exports[_0x7f77('0xc7')]=function(_0x257ea6,_0x4cd505,_0x1e7703){return db[_0x7f77('0x41')][_0x7f77('0x69')]({'where':{'id':_0x257ea6[_0x7f77('0xba')]['id']}})[_0x7f77('0x2a')](handleEntityNotFound(_0x4cd505,null))[_0x7f77('0x2a')](function(_0x4d87a7){if(_0x4d87a7){return _0x4d87a7[_0x7f77('0xc8')](_0x257ea6[_0x7f77('0x7c')][_0x7f77('0xc2')],_[_0x7f77('0xc9')](_0x257ea6[_0x7f77('0x7c')],[_0x7f77('0xc2'),'id'])||{})[_0x7f77('0xca')](function(){return db[_0x7f77('0x77')]['findAll']({'attributes':['id',_0x7f77('0x2e'),_0x7f77('0x53')],'where':{'id':_0x257ea6[_0x7f77('0x7c')]['ids']}});})[_0x7f77('0x2a')](function(_0x230a1c){socket['emit'](_0x7f77('0xcb'),{'id':Number(_0x257ea6[_0x7f77('0xba')]['id']),'tags':_0x230a1c||[]});return{'id':Number(_0x257ea6[_0x7f77('0xba')]['id']),'tags':_0x230a1c||[]};});}})[_0x7f77('0x2a')](respondWithResult(_0x4cd505,null))[_0x7f77('0x38')](handleError(_0x4cd505,null));};exports[_0x7f77('0xcc')]=function(_0xa342b3,_0x40c4c1,_0x71b33e){return db[_0x7f77('0x41')][_0x7f77('0x69')]({'where':{'id':_0xa342b3[_0x7f77('0xba')]['id']}})['then'](handleEntityNotFound(_0x40c4c1,null))[_0x7f77('0x2a')](function(_0x1185fc){if(_0x1185fc){return _0x1185fc['removeTags'](_0xa342b3[_0x7f77('0x46')][_0x7f77('0xc2')]);}})[_0x7f77('0x2a')](respondWithStatusCode(_0x40c4c1,null))[_0x7f77('0x38')](handleError(_0x40c4c1,null));};exports[_0x7f77('0xcd')]=function(_0x4f9a7f,_0x2dbbfb){var _0x12f5d5=moment()['unix']()['toString']();var _0x46d957=path[_0x7f77('0xce')](config[_0x7f77('0xcf')],_0x7f77('0xd0'),_0x7f77('0xd1'),'tmp');var _0x7a63f6=path['join'](config[_0x7f77('0xcf')],_0x7f77('0xd0'),_0x7f77('0xd1'),'attachments');var _0x77030a=path[_0x7f77('0xce')](_0x46d957,_0x12f5d5);var _0x2d3c40=util[_0x7f77('0xd2')](_0x7f77('0xd3'),_0x4f9a7f['params']['id'],_0x12f5d5);var _0x2e2f13=path['join'](_0x46d957,_0x2d3c40);var _0x2a0f30=[];_0x2a0f30[_0x7f77('0x37')]({'model':db[_0x7f77('0x7a')],'as':_0x7f77('0x7a'),'attributes':['id',_0x7f77('0x32')],'raw':!![]});_0x2a0f30[_0x7f77('0x37')]({'model':db['CmContact'],'as':'Contact','attributes':['id',_0x7f77('0xd4'),_0x7f77('0xd5')],'raw':!![]});if(_0x4f9a7f[_0x7f77('0x46')][_0x7f77('0xd6')]){_0x2a0f30[_0x7f77('0x37')]({'model':db[_0x7f77('0xd7')],'as':_0x7f77('0xd7'),'raw':!![]});}var _0x3c93dc=[{'model':db[_0x7f77('0xc1')],'as':_0x7f77('0xd8'),'attributes':['id',_0x7f77('0x7c'),'createdAt',_0x7f77('0xd9'),_0x7f77('0xda'),_0x7f77('0x8a')],'include':_0x2a0f30}];_0x3c93dc['push']({'model':db[_0x7f77('0xdb')],'as':_0x7f77('0xdc'),'attributes':['id','name']});_0x3c93dc[_0x7f77('0x37')]({'model':db[_0x7f77('0x7a')],'as':_0x7f77('0xdd'),'attributes':['id',_0x7f77('0x32')]});return db[_0x7f77('0x41')][_0x7f77('0x69')]({'where':{'id':_0x4f9a7f[_0x7f77('0xba')]['id']},'include':_0x3c93dc})[_0x7f77('0x2a')](handleEntityNotFound(_0x2dbbfb,null))[_0x7f77('0x2a')](function(_0x5d3bd9){if(_0x5d3bd9){var _0x3e1aa8=_0x5d3bd9['get']({'plain':!![]});fs[_0x7f77('0xde')](_0x77030a);var _0xae405f={'channel':_0x7f77('0xdf'),'account':_0x3e1aa8['Account'][_0x7f77('0x2e')],'agent':_0x3e1aa8[_0x7f77('0xdd')]?_0x3e1aa8[_0x7f77('0xdd')]['fullname']:_0x7f77('0xe0'),'createdAt':moment(_0x3e1aa8[_0x7f77('0x83')])[_0x7f77('0xd2')](_0x7f77('0xc4'))[_0x7f77('0xa7')](),'closedAt':_0x3e1aa8['closed']?moment(_0x3e1aa8[_0x7f77('0xe1')])[_0x7f77('0xd2')](_0x7f77('0xc4'))[_0x7f77('0xa7')]():'','disposition':_0x3e1aa8[_0x7f77('0xe2')],'messages':_(_0x3e1aa8[_0x7f77('0xd8')])[_0x7f77('0x8f')]({'secret':![]})[_0x7f77('0x31')](function(_0x5536b2){if(_0x5536b2['Attachment']){var _0xd372e5=path[_0x7f77('0xce')](_0x7a63f6,_0x5536b2['Attachment']['basename']);if(fs['existsSync'](_0xd372e5)){fs[_0x7f77('0xe3')](_0xd372e5)[_0x7f77('0xe4')](fs['createWriteStream'](path[_0x7f77('0xce')](_0x77030a,_0x5536b2[_0x7f77('0xd7')][_0x7f77('0xe5')])));}}return{'date':moment(_0x5536b2[_0x7f77('0x83')])[_0x7f77('0xd2')](_0x7f77('0xc4'))['toString'](),'sender':_0x5536b2['direction']===_0x7f77('0xe6')?_0x5536b2[_0x7f77('0x7a')]?_0x5536b2[_0x7f77('0x7a')][_0x7f77('0x32')]:_0x7f77('0xe7'):_0x5536b2[_0x7f77('0x6e')][_0x7f77('0xd4')]+(_0x5536b2[_0x7f77('0x6e')][_0x7f77('0xd5')]?'\x20'+_0x5536b2[_0x7f77('0x6e')][_0x7f77('0xd5')]:''),'body':_0x5536b2['Attachment']?_0x5536b2[_0x7f77('0xd7')][_0x7f77('0xe5')]:_0x5536b2[_0x7f77('0x7c')],'direction':_0x5536b2[_0x7f77('0xd9')]===_0x7f77('0xe6')?'A':'C','secret':_0x5536b2['secret'],'read':_0x5536b2[_0x7f77('0x8a')],'attachment':_0x5536b2['Attachment']};})['value']()};return ejs[_0x7f77('0xe8')](path[_0x7f77('0xce')](config[_0x7f77('0xcf')],'server',_0x7f77('0xe9'),_0x7f77('0xea')),{'interaction':_0xae405f})[_0x7f77('0x2a')](function(_0x31bc56){var _0x321520=path[_0x7f77('0xce')](_0x77030a,_0x7f77('0xeb')+_0x3e1aa8['id']+'-'+_0x12f5d5+'.pdf');var _0x507f1f={'path':_0x321520,'channel':_0x7f77('0xdf'),'interactionId':_0x3e1aa8['id']};return pdf[_0x7f77('0xec')](_0x31bc56,_0x507f1f);})[_0x7f77('0x2a')](function(){return new BPromise(function(_0x5bb238,_0x335324){zipdir(_0x77030a,{'saveTo':_0x2e2f13},function(_0x2b8b53,_0xc81e58){if(_0x2b8b53)return _0x335324(_0x2b8b53);return _0x5bb238(_0xc81e58);});})[_0x7f77('0x2a')](function(){return new BPromise(function(_0x2af792,_0x531a8e){rimraf(_0x77030a,function(_0x49deab){if(_0x49deab)_0x531a8e(_0x49deab);return _0x2af792();});});})['then'](function(){return _0x2dbbfb[_0x7f77('0xcd')](_0x2e2f13,_0x2d3c40,function(_0x32ad1b){if(_0x32ad1b){console[_0x7f77('0xed')](_0x7f77('0xee'),_0x32ad1b);}else{fs['unlinkSync'](_0x2e2f13);}});});});}else{return _0x2dbbfb['sendStatus'](0xc8);}})[_0x7f77('0x38')](handleError(_0x2dbbfb,null));};
\ No newline at end of file