Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index a04e4b0..33bacd0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa321=['whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','find','having','`\x20=\x200','`\x20>\x200','Contact','$substring','value','getFullTextValue','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?','keys','some','isEmpty','i.WhatsappAccountId\x20IN\x20?','concat','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','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)','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','SELECT','clone','unreadMessages','contactName','DESC','t.id\x20IN\x20?','resolve','WhatsappAccountId','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','role','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','toString','count','sequelize','keyBy','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','a.key','Account.key','Account.mandatoryDisposition','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','o.fullname','Owner.fullname','o.internal','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','rows','show','params','includeAll','include','merge','create','body','describe','addMessage','omit','findOne','WhatsappMessage','nolimit','format','YYYY-MM-DD\x20HH:mm:ss','options','addTags','setTags','ids','spread','emit','whatsappInteractionTags:save','removeTags','download','unix','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','fullname','CmContact','lastName','Attachment','createdAt','secret','WhatsappAccount','Account','get','mkdirSync','Whatsapp','Owner','N.A.','closedAt','disposition','basename','existsSync','createReadStream','createWriteStream','direction','out','firstName','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','fs-extra','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','sendStatus','status','json','offset','undefined','limit','Content-Range','apply','save','update','end','error','stack','name','send','Users','map','split','forEach','Tags','push','then','catch','talking','answered','unmanaged','closed','UserId','waiting','total','index','WhatsappInteraction','rawAttributes','type','key','model','intersection','attributes','fields','query','length','hasOwnProperty','order','sort','where','filters','pick','select','field','color','from','u.id','u.fullname','ui.WhatsappInteractionId','left_join','users','u.id\x20=\x20ui.UserId','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','whatsapp_accounts','whatsapp_messages'];(function(_0x5906a5,_0x48af0a){var _0x1b9a31=function(_0x4b72ac){while(--_0x4b72ac){_0x5906a5['push'](_0x5906a5['shift']());}};_0x1b9a31(++_0x48af0a);}(_0xa321,0x9d));var _0x1a32=function(_0x40162a,_0x265b0c){_0x40162a=_0x40162a-0x0;var _0x488161=_0xa321[_0x40162a];return _0x488161;};'use strict';var emlformat=require(_0x1a32('0x0'));var rimraf=require(_0x1a32('0x1'));var zipdir=require(_0x1a32('0x2'));var jsonpatch=require(_0x1a32('0x3'));var rp=require('request-promise');var moment=require(_0x1a32('0x4'));var BPromise=require(_0x1a32('0x5'));var Mustache=require('mustache');var util=require(_0x1a32('0x6'));var path=require(_0x1a32('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1a32('0x8'));var _=require('lodash');var squel=require(_0x1a32('0x9'));var crypto=require(_0x1a32('0xa'));var jsforce=require(_0x1a32('0xb'));var deskjs=require(_0x1a32('0xc'));var toCsv=require(_0x1a32('0xd'));var querystring=require('querystring');var Papa=require(_0x1a32('0xe'));var Redis=require(_0x1a32('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x1a32('0x10'));var as=require(_0x1a32('0x11'));var pdf=require(_0x1a32('0x12'));var hardwareService=require(_0x1a32('0x13'));var logger=require(_0x1a32('0x14'))(_0x1a32('0x15'));var utils=require('../../config/utils');var config=require(_0x1a32('0x16'));var licenseUtil=require(_0x1a32('0x17'));var db=require(_0x1a32('0x18'))['db'];config['redis']=_[_0x1a32('0x19')](config[_0x1a32('0x1a')],{'host':_0x1a32('0x1b'),'port':0x18eb});var socket=require(_0x1a32('0x1c'))(new Redis(config[_0x1a32('0x1a')]));require('./whatsappInteraction.socket')[_0x1a32('0x1d')](socket);function respondWithStatusCode(_0x456e81,_0x1838d2){_0x1838d2=_0x1838d2||0xcc;return function(_0x268b0a){if(_0x268b0a){return _0x456e81[_0x1a32('0x1e')](_0x1838d2);}return _0x456e81[_0x1a32('0x1f')](_0x1838d2)['end']();};}function respondWithResult(_0x29c53d,_0x463763){_0x463763=_0x463763||0xc8;return function(_0x47bb8e){if(_0x47bb8e){return _0x29c53d[_0x1a32('0x1f')](_0x463763)[_0x1a32('0x20')](_0x47bb8e);}};}function respondWithFilteredResult(_0x2cac28,_0x3b2983){return function(_0x43404b){if(_0x43404b){var _0x303afb=typeof _0x3b2983[_0x1a32('0x21')]===_0x1a32('0x22')&&typeof _0x3b2983[_0x1a32('0x23')]===_0x1a32('0x22');var _0x2f6381=_0x43404b['count'];var _0x3231b2=_0x303afb?0x0:_0x3b2983[_0x1a32('0x21')];var _0x235fd0=_0x303afb?_0x43404b['count']:_0x3b2983[_0x1a32('0x21')]+_0x3b2983[_0x1a32('0x23')];var _0x4af60a;if(_0x235fd0>=_0x2f6381){_0x235fd0=_0x2f6381;_0x4af60a=0xc8;}else{_0x4af60a=0xce;}_0x2cac28[_0x1a32('0x1f')](_0x4af60a);return _0x2cac28['set'](_0x1a32('0x24'),_0x3231b2+'-'+_0x235fd0+'/'+_0x2f6381)[_0x1a32('0x20')](_0x43404b);}return null;};}function patchUpdates(_0x4bbf42){return function(_0x2765e2){try{jsonpatch[_0x1a32('0x25')](_0x2765e2,_0x4bbf42,!![]);}catch(_0x2c93b0){return BPromise['reject'](_0x2c93b0);}return _0x2765e2[_0x1a32('0x26')]();};}function saveUpdates(_0x1fe746,_0x4bf0a0){return function(_0x372b95){if(_0x372b95){return _0x372b95[_0x1a32('0x27')](_0x1fe746)['then'](function(_0x41c892){return _0x41c892;});}return null;};}function removeEntity(_0x4b3b33,_0x4c183c){return function(_0x5edf08){if(_0x5edf08){return _0x5edf08['destroy']()['then'](function(){_0x4b3b33[_0x1a32('0x1f')](0xcc)[_0x1a32('0x28')]();});}};}function handleEntityNotFound(_0x4771b7,_0x2094fa){return function(_0x382b3c){if(!_0x382b3c){_0x4771b7[_0x1a32('0x1e')](0x194);}return _0x382b3c;};}function handleError(_0x19e0e6,_0x2edc3e){_0x2edc3e=_0x2edc3e||0x1f4;return function(_0x48d69d){logger[_0x1a32('0x29')](_0x48d69d[_0x1a32('0x2a')]);if(_0x48d69d[_0x1a32('0x2b')]){delete _0x48d69d[_0x1a32('0x2b')];}_0x19e0e6[_0x1a32('0x1f')](_0x2edc3e)[_0x1a32('0x2c')](_0x48d69d);};}function getInteractionUsers(_0x821dbf,_0x1211e2){return new BPromise(function(_0x3bc28a,_0x54b122){try{if(_0x1211e2[_0x821dbf['id']]){_0x821dbf[_0x1a32('0x2d')]=_[_0x1a32('0x2e')](_0x1211e2[_0x821dbf['id']],function(_0x4f2dfc){return{'id':_0x4f2dfc['id'],'fullname':_0x4f2dfc['fullname']};});}}catch(_0xd3bf6e){_0x54b122(_0xd3bf6e);}_0x3bc28a(_0x821dbf);});}function getInteractionTags(_0x582606,_0x5b9f13){return new BPromise(function(_0x1d874e,_0x4ef9fd){try{if(_0x582606['TagIds']){_0x582606['Tags']=[];_0x582606['TagIds'][_0x1a32('0x2f')](',')[_0x1a32('0x30')](function(_0x7c255c){_0x582606[_0x1a32('0x31')][_0x1a32('0x32')](_0x5b9f13[_0x7c255c]);});}delete _0x582606['TagIds'];}catch(_0x53a6c7){_0x4ef9fd(_0x53a6c7);}_0x1d874e(_0x582606);});}function updateWhatsappInteraction(_0x3d6385,_0x4f430c,_0xd2455c){return new BPromise(function(_0x1b7d21,_0xfb0096){return getInteractionUsers(_0x3d6385,_0xd2455c)['then'](function(_0x24afda){return getInteractionTags(_0x24afda,_0x4f430c);})[_0x1a32('0x33')](function(_0x2121e2){return getStateInteraction(_0x2121e2);})[_0x1a32('0x33')](function(_0x3acb50){_0x1b7d21(_0x3acb50);})[_0x1a32('0x34')](function(_0x365ad9){_0xfb0096(_0x365ad9);});});}function getStateInteraction(_0x2e4b5c){return new BPromise(function(_0x1b0b1e){_0x2e4b5c['waiting']=0x0;_0x2e4b5c[_0x1a32('0x35')]=0x0;_0x2e4b5c[_0x1a32('0x36')]=0x0;_0x2e4b5c[_0x1a32('0x37')]=0x0;_0x2e4b5c['total']=0x0;if(!_0x2e4b5c[_0x1a32('0x38')]&&!_0x2e4b5c[_0x1a32('0x39')]){_0x2e4b5c[_0x1a32('0x3a')]+=0x1;}if(!_0x2e4b5c[_0x1a32('0x38')]&&_0x2e4b5c[_0x1a32('0x39')]){_0x2e4b5c[_0x1a32('0x35')]+=0x1;if(_0x2e4b5c[_0x1a32('0x3a')]){_0x2e4b5c[_0x1a32('0x3a')]-=0x1;}}if(_0x2e4b5c[_0x1a32('0x38')]&&_0x2e4b5c[_0x1a32('0x39')]){_0x2e4b5c[_0x1a32('0x36')]+=0x1;if(_0x2e4b5c[_0x1a32('0x35')]){_0x2e4b5c[_0x1a32('0x35')]-=0x1;}}if(_0x2e4b5c[_0x1a32('0x38')]&&!_0x2e4b5c[_0x1a32('0x39')]){_0x2e4b5c['unmanaged']+=0x1;if(_0x2e4b5c['waiting']){_0x2e4b5c['waiting']-=0x1;}}_0x2e4b5c[_0x1a32('0x3b')]+=0x1;_0x1b0b1e(_0x2e4b5c);});}exports[_0x1a32('0x3c')]=function(_0x1f1a98,_0x1745bd){var _0xeb42f7={},_0x54150d={},_0x14b8de={'count':0x0,'rows':[]};var _0x9638ff=_[_0x1a32('0x2e')](db[_0x1a32('0x3d')][_0x1a32('0x3e')],function(_0x466fab){return{'name':_0x466fab['fieldName'],'type':_0x466fab[_0x1a32('0x3f')][_0x1a32('0x40')]};});_0x54150d[_0x1a32('0x41')]=_[_0x1a32('0x2e')](_0x9638ff,_0x1a32('0x2b'));_0x54150d['query']=_['keys'](_0x1f1a98['query']);_0x54150d['filters']=_[_0x1a32('0x42')](_0x54150d[_0x1a32('0x41')],_0x54150d['query']);_0xeb42f7[_0x1a32('0x43')]=_[_0x1a32('0x42')](_0x54150d[_0x1a32('0x41')],qs[_0x1a32('0x44')](_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x44')]));_0xeb42f7[_0x1a32('0x43')]=_0xeb42f7[_0x1a32('0x43')][_0x1a32('0x46')]?_0xeb42f7[_0x1a32('0x43')]:_0x54150d[_0x1a32('0x41')];if(!_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x47')]('nolimit')){_0xeb42f7[_0x1a32('0x23')]=qs['limit'](_0x1f1a98['query'][_0x1a32('0x23')]);_0xeb42f7['offset']=qs[_0x1a32('0x21')](_0x1f1a98['query'][_0x1a32('0x21')]);}_0xeb42f7[_0x1a32('0x48')]=qs[_0x1a32('0x49')](_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x49')]);_0xeb42f7[_0x1a32('0x4a')]=qs[_0x1a32('0x4b')](_[_0x1a32('0x4c')](_0x1f1a98[_0x1a32('0x45')],_0x54150d['filters']),_0x9638ff);var _0x3e0bad=[];var _0x1514ef=squel[_0x1a32('0x4d')]()['field']('id')[_0x1a32('0x4e')](_0x1a32('0x2b'))[_0x1a32('0x4e')](_0x1a32('0x4f'))[_0x1a32('0x50')]('tools_tags');var _0x31e568=squel[_0x1a32('0x4d')]()[_0x1a32('0x4e')](_0x1a32('0x51'))[_0x1a32('0x4e')](_0x1a32('0x52'))[_0x1a32('0x4e')](_0x1a32('0x53'))[_0x1a32('0x50')]('user_has_whatsapp_interactions','ui')[_0x1a32('0x54')](_0x1a32('0x55'),'u',_0x1a32('0x56'));var _0x4a0042=squel[_0x1a32('0x4d')]()[_0x1a32('0x50')]('whatsapp_interactions','i')[_0x1a32('0x54')](_0x1a32('0x57'),'c',_0x1a32('0x58'))['left_join'](_0x1a32('0x55'),'o',_0x1a32('0x59'))['left_join'](_0x1a32('0x5a'),'a','a.id\x20=\x20i.WhatsappAccountId')['left_join'](_0x1a32('0x5b'),'me','me.WhatsappInteractionId\x20=\x20i.id')['left_join'](_0x1a32('0x5c'),'it',_0x1a32('0x5d'))[_0x1a32('0x54')](_0x1a32('0x5e'),'t',_0x1a32('0x5f'));var _0x698ad2=squel[_0x1a32('0x60')]();var _0x484224=[];var _0x49ed24=squel[_0x1a32('0x60')]();var _0x572e54;if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x61')]){_0x572e54=as[_0x1a32('0x62')](_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x61')]);var _0x54566a=_0x572e54[_0x1a32('0x63')];for(var _0x2b77f9=0x0;_0x2b77f9<_0x572e54[_0x1a32('0x64')]['length'];_0x2b77f9++){var _0x5ea389=_0x572e54['conditions'][_0x2b77f9];var _0x29a0b9='i';var _0x41f088=_[_0x1a32('0x65')](_0x9638ff,[_0x1a32('0x2b'),_0x5ea389[_0x1a32('0x4e')]]);if(!_0x41f088){switch(_0x5ea389[_0x1a32('0x4e')]){case'unreadMessages':if(_0x5ea389['value']==0x1){_0x4a0042[_0x1a32('0x66')]('`'+_0x5ea389[_0x1a32('0x4e')]+_0x1a32('0x67'));}else{_0x4a0042[_0x1a32('0x66')]('`'+_0x5ea389[_0x1a32('0x4e')]+_0x1a32('0x68'));}break;case _0x1a32('0x69'):if(_0x5ea389['operator']===_0x1a32('0x6a')){if(_0x5ea389[_0x1a32('0x6b')][_0x1a32('0x2f')]('\x20')[_0x1a32('0x46')]>0x1){_0x698ad2[_0x54566a]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0x1a32('0x6c')](_0x5ea389[_0x1a32('0x6b')]),null);}else{var _0x5c1cb6='%'+_0x5ea389[_0x1a32('0x6b')]+'%';_0x698ad2[_0x54566a](_0x1a32('0x6d'),_0x5c1cb6,_0x5c1cb6,_0x5c1cb6);}}else{_0x41f088=_[_0x1a32('0x65')](_0x9638ff,[_0x1a32('0x2b'),_0x1a32('0x6e')]);_0x5ea389[_0x1a32('0x4e')]=_0x1a32('0x6e');_0x557074=as[_0x1a32('0x6f')](_0x29a0b9,_0x41f088[_0x1a32('0x3f')],_0x5ea389);_0x698ad2[_0x54566a](_0x557074[_0x1a32('0x70')],_0x557074['value'][_0x1a32('0x71')],_0x557074[_0x1a32('0x6b')]['end']);}break;case _0x1a32('0x72'):var _0x6532b1=_0x5ea389['value']['split'](',')[_0x1a32('0x2e')](function(_0x3f0803){return Number(_0x3f0803);});_0x6532b1[_0x1a32('0x30')](function(_0x32b3cb){_0x49ed24['or'](_0x1a32('0x73'),'%,'+_0x32b3cb+',%');});_0x484224=_[_0x1a32('0x74')](_0x484224,_0x6532b1);break;case _0x1a32('0x75'):if(_0x5ea389['operator']===_0x1a32('0x6a')){_0x698ad2[_0x54566a](_0x1a32('0x76'),'%'+_0x5ea389['value']+'%',null);}else{_0x41f088=_[_0x1a32('0x65')](_0x9638ff,[_0x1a32('0x2b'),_0x1a32('0x39')]);_0x5ea389[_0x1a32('0x4e')]=_0x1a32('0x39');_0x557074=as[_0x1a32('0x6f')](_0x29a0b9,_0x41f088[_0x1a32('0x3f')],_0x5ea389);_0x698ad2[_0x54566a](_0x557074[_0x1a32('0x70')],_0x557074[_0x1a32('0x6b')][_0x1a32('0x71')],_0x557074[_0x1a32('0x6b')][_0x1a32('0x28')]);}break;case'body':_0x557074=as['buildExpression']('me',null,_0x5ea389);_0x698ad2[_0x54566a](_0x557074[_0x1a32('0x70')],_0x557074[_0x1a32('0x6b')][_0x1a32('0x71')],_0x557074[_0x1a32('0x6b')][_0x1a32('0x28')]);break;}}else{var _0x557074=as['buildExpression'](_0x29a0b9,_0x41f088[_0x1a32('0x3f')],_0x5ea389);_0x698ad2[_0x54566a](_0x557074[_0x1a32('0x70')],_0x557074['value'][_0x1a32('0x71')],_0x557074[_0x1a32('0x6b')][_0x1a32('0x28')]);}}}else{var _0x5d2de7=_(_0x1f1a98['query'])[_0x1a32('0x77')]()[_0x1a32('0x2e')](function(_0x1b7a9e){return _[_0x1a32('0x78')](_0x9638ff,[_0x1a32('0x2b'),_0x1b7a9e])?_0x1b7a9e:undefined;})['compact']()['value']();if(!_[_0x1a32('0x79')](_0x5d2de7)){_0x5d2de7[_0x1a32('0x30')](function(_0x297a79){if(_0x297a79==='WhatsappAccountId'){_0x4a0042[_0x1a32('0x4a')](_0x1a32('0x7a'),[][_0x1a32('0x7b')](_0x1f1a98['query'][_0x297a79]));}else if(_0x297a79==='createdAt'){var _0x53e980=JSON[_0x1a32('0x7c')](_0x1f1a98[_0x1a32('0x45')][_0x297a79])[_0x1a32('0x7d')];var _0x4c4b23=JSON[_0x1a32('0x7c')](_0x1f1a98[_0x1a32('0x45')][_0x297a79])[_0x1a32('0x7e')];_0x4a0042[_0x1a32('0x4a')](_0x1a32('0x7f'),_0x53e980,_0x4c4b23);}else{if(_0x1f1a98[_0x1a32('0x45')][_0x297a79]===_0x1a32('0x80')){_0x4a0042[_0x1a32('0x4a')]('i.'+_0x297a79+_0x1a32('0x81'));}else{_0x4a0042[_0x1a32('0x4a')]('i.'+_0x297a79+'\x20=\x20?',_0x1f1a98[_0x1a32('0x45')][_0x297a79]);}}});}if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x82')]){if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x82')]==0x1){_0x4a0042[_0x1a32('0x66')](_0x1a32('0x83'));}else{_0x4a0042[_0x1a32('0x66')](_0x1a32('0x84'));}}if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x85')]){_0x484224=_[_0x1a32('0x86')](_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x85')])?_0x1f1a98['query'][_0x1a32('0x85')]:new Array(_0x1f1a98[_0x1a32('0x45')]['tag']);_0x484224['forEach'](function(_0x104ddb){_0x49ed24['or'](_0x1a32('0x73'),'%,'+_0x104ddb+',%');});}if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x87')]){var _0x152d98=_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x87')][_0x1a32('0x88')]('\x5c','\x5c\x5c')[_0x1a32('0x88')](/'/g,'\x27\x27');if(qs[_0x1a32('0x89')](_0x152d98)){_0x698ad2['or'](_0x1a32('0x8a'),_0x152d98+'%')['or'](_0x1a32('0x8b'),_0x152d98+'%');}else{_0x698ad2['or'](_0x1a32('0x8c'),qs[_0x1a32('0x6c')](_0x152d98))['or'](_0x1a32('0x8d'),_0x152d98+'%');}}}_0x4a0042[_0x1a32('0x4a')](_0x698ad2);_0x4a0042[_0x1a32('0x8e')](_0x1a32('0x8f'));var _0x3b6d11={'type':db[_0x1a32('0x90')][_0x1a32('0x91')][_0x1a32('0x92')],'raw':!![]};var _0x38ec64=_0x4a0042[_0x1a32('0x93')]();_0x38ec64['field']('i.id');_0x38ec64[_0x1a32('0x4e')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0x1a32('0x94'));if(_0xeb42f7[_0x1a32('0x48')]){_0xeb42f7[_0x1a32('0x48')][_0x1a32('0x30')](function(_0x17d6e9){var _0x33beff=_0x17d6e9[0x0]===_0x1a32('0x95')?_0x17d6e9[0x0]:'i.'+_0x17d6e9[0x0];_0x4a0042['order'](_0x33beff,_0x17d6e9[0x1]===_0x1a32('0x96')?![]:!![]);});}if(!_[_0x1a32('0x79')](_0x484224)){_0x4a0042[_0x1a32('0x66')](_0x49ed24);_0x38ec64[_0x1a32('0x4a')](_0x1a32('0x97'),_0x484224);}BPromise[_0x1a32('0x98')]()[_0x1a32('0x33')](function(){if(!_0x572e54){if(_0x1f1a98[_0x1a32('0x45')][_0x1a32('0x99')])return;_0x38ec64[_0x1a32('0x4a')](_0x1a32('0x9a'));_0x4a0042['where']('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x1f1a98[_0x1a32('0x9b')][_0x1a32('0x9c')]!==_0x1a32('0x9d'))return;return _0x1f1a98[_0x1a32('0x9b')][_0x1a32('0x9e')]({'attributes':['id'],'raw':!![]})[_0x1a32('0x33')](function(_0x346493){if(_[_0x1a32('0x79')](_0x346493)){_0x38ec64['where']('i.WhatsappAccountId\x20IS\x20NULL');_0x4a0042[_0x1a32('0x4a')](_0x1a32('0x9f'));}else{_0x38ec64[_0x1a32('0x4a')]('i.WhatsappAccountId\x20IN\x20?',_[_0x1a32('0x2e')](_0x346493,'id'));_0x4a0042['where'](_0x1a32('0x7a'),_['map'](_0x346493,'id'));}});})[_0x1a32('0x33')](function(){if(_0x1f1a98[_0x1a32('0x9b')][_0x1a32('0x9c')]===_0x1a32('0x9d')&&!_0x572e54&&!_0x1f1a98[_0x1a32('0x45')]['WhatsappAccountId'])return[];return db['sequelize'][_0x1a32('0x45')](_0x38ec64[_0x1a32('0xa0')](),_0x3b6d11);})[_0x1a32('0x33')](function(_0xbdd559){_0x14b8de[_0x1a32('0xa1')]=_0xbdd559[_0x1a32('0x46')];if(_0x14b8de[_0x1a32('0xa1')]===0x0)return[];return db[_0x1a32('0xa2')]['query'](_0x1514ef[_0x1a32('0xa0')](),_0x3b6d11)[_0x1a32('0x33')](function(_0x52b52b){_0x3e0bad=_[_0x1a32('0xa3')](_0x52b52b,'id');_0x3b6d11=_['merge'](_0x3b6d11,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1f1a98[_0x1a32('0x45')]['fields']){_0xeb42f7[_0x1a32('0x43')][_0x1a32('0x30')](function(_0x510be6){_0x4a0042[_0x1a32('0x4e')]('i.'+_0x510be6);});}else{_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xa4'),_0x1a32('0x94'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xa5'),_0x1a32('0xa6'));_0x4a0042[_0x1a32('0x4e')]('a.mandatoryDisposition',_0x1a32('0xa7'));_0x4a0042[_0x1a32('0x4e')]('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',_0x1a32('0x95'));_0x4a0042['field'](_0x1a32('0xa8'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xa9'),_0x1a32('0xaa'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xab'),_0x1a32('0xac'));_0x4a0042['field'](_0x1a32('0xad'),_0x1a32('0xae'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xaf'),_0x1a32('0xb0'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xb1'),'Contact.mobile');_0x4a0042[_0x1a32('0x4e')]('c.fax','Contact.fax');_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xb2'),_0x1a32('0xb3'));_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xb4'),'Owner.internal');_0x4a0042[_0x1a32('0x4e')](_0x1a32('0xb5'),_0x1a32('0xb6'));}if(_0xeb42f7[_0x1a32('0x23')])_0x4a0042[_0x1a32('0x23')](_0xeb42f7[_0x1a32('0x23')]);if(_0xeb42f7['offset'])_0x4a0042['offset'](_0xeb42f7[_0x1a32('0x21')]);return db[_0x1a32('0xa2')][_0x1a32('0x45')](_0x4a0042[_0x1a32('0xa0')](),_0x3b6d11);})[_0x1a32('0x33')](function(_0x8fd415){if(_0x8fd415['length']>0x0)_0x31e568[_0x1a32('0x4a')](_0x1a32('0xb7'),_[_0x1a32('0x2e')](_0x8fd415,'id'));return db['sequelize'][_0x1a32('0x45')](_0x31e568['toString'](),_0x3b6d11)[_0x1a32('0x33')](function(_0x2c4ca7){var _0x48f101=_[_0x1a32('0xb8')](_0x2c4ca7,_0x1a32('0xb9'));var _0x536d69=[];_0x8fd415[_0x1a32('0x30')](function(_0x21adac){_0x536d69[_0x1a32('0x32')](updateWhatsappInteraction(_0x21adac,_0x3e0bad,_0x48f101));});return BPromise[_0x1a32('0xba')](_0x536d69);});});})[_0x1a32('0x33')](function(_0x27c971){_0x14b8de[_0x1a32('0xbb')]=_0x27c971;return _0x14b8de;})[_0x1a32('0x33')](respondWithFilteredResult(_0x1745bd,_0xeb42f7))[_0x1a32('0x34')](handleError(_0x1745bd,null));};exports[_0x1a32('0xbc')]=function(_0x2596ea,_0x5bee01){var _0x371964={'raw':![],'where':{'id':_0x2596ea[_0x1a32('0xbd')]['id']}},_0x3d67d1={};_0x3d67d1[_0x1a32('0x41')]=_[_0x1a32('0x77')](db[_0x1a32('0x3d')][_0x1a32('0x3e')]);_0x3d67d1[_0x1a32('0x45')]=_[_0x1a32('0x77')](_0x2596ea[_0x1a32('0x45')]);_0x3d67d1[_0x1a32('0x4b')]=_[_0x1a32('0x42')](_0x3d67d1['model'],_0x3d67d1['query']);_0x371964[_0x1a32('0x43')]=_[_0x1a32('0x42')](_0x3d67d1['model'],qs['fields'](_0x2596ea[_0x1a32('0x45')][_0x1a32('0x44')]));_0x371964[_0x1a32('0x43')]=_0x371964['attributes'][_0x1a32('0x46')]?_0x371964[_0x1a32('0x43')]:_0x3d67d1['model'];if(_0x2596ea['query'][_0x1a32('0xbe')]){_0x371964[_0x1a32('0xbf')]=[{'all':!![]}];}_0x371964=_[_0x1a32('0xc0')]({},_0x371964,_0x2596ea['options']);return db[_0x1a32('0x3d')][_0x1a32('0x65')](_0x371964)[_0x1a32('0x33')](handleEntityNotFound(_0x5bee01,null))['then'](respondWithResult(_0x5bee01,null))[_0x1a32('0x34')](handleError(_0x5bee01,null));};exports[_0x1a32('0xc1')]=function(_0x15ca3f,_0x329457){return db[_0x1a32('0x3d')][_0x1a32('0xc1')](_0x15ca3f[_0x1a32('0xc2')],{})[_0x1a32('0x33')](respondWithResult(_0x329457,0xc9))[_0x1a32('0x34')](handleError(_0x329457,null));};exports[_0x1a32('0x27')]=function(_0x2b02b1,_0x49100a){if(_0x2b02b1['body']['id']){delete _0x2b02b1['body']['id'];}return db[_0x1a32('0x3d')][_0x1a32('0x65')]({'where':{'id':_0x2b02b1['params']['id']}})[_0x1a32('0x33')](handleEntityNotFound(_0x49100a,null))[_0x1a32('0x33')](saveUpdates(_0x2b02b1['body'],null))[_0x1a32('0x33')](respondWithResult(_0x49100a,null))['catch'](handleError(_0x49100a,null));};exports['destroy']=function(_0xa1d6c7,_0x2f6182){return db[_0x1a32('0x3d')][_0x1a32('0x65')]({'where':{'id':_0xa1d6c7[_0x1a32('0xbd')]['id']}})[_0x1a32('0x33')](handleEntityNotFound(_0x2f6182,null))[_0x1a32('0x33')](removeEntity(_0x2f6182,null))[_0x1a32('0x34')](handleError(_0x2f6182,null));};exports[_0x1a32('0xc3')]=function(_0x4d9048,_0x539f6d){return db['WhatsappInteraction'][_0x1a32('0xc3')]()['then'](respondWithResult(_0x539f6d,null))[_0x1a32('0x34')](handleError(_0x539f6d,null));};exports[_0x1a32('0xc4')]=function(_0x47c2d5,_0x809276,_0x4e22c3){return db['WhatsappMessage']['find']({'where':{'id':_0x47c2d5[_0x1a32('0xbd')]['id']}})['then'](handleEntityNotFound(_0x809276,null))[_0x1a32('0x33')](function(_0x4bd898){if(_0x4bd898){return _0x4bd898[_0x1a32('0xc4')](_0x47c2d5['body']['ids'],_[_0x1a32('0xc5')](_0x47c2d5['body'],['ids','id'])||{});}})[_0x1a32('0x33')](respondWithResult(_0x809276,null))['catch'](handleError(_0x809276,null));};exports['getMessages']=function(_0x689c9f,_0x1faf0d,_0x23468d){var _0x2e3339={'raw':![],'where':{}};var _0x339ff4={};var _0x4ade0a={'count':0x0,'rows':[]};return db[_0x1a32('0x3d')][_0x1a32('0xc6')]({'where':{'id':_0x689c9f['params']['id']}})[_0x1a32('0x33')](handleEntityNotFound(_0x1faf0d,null))[_0x1a32('0x33')](function(_0x44383e){if(_0x44383e){_0x339ff4[_0x1a32('0x41')]=_[_0x1a32('0x77')](db[_0x1a32('0xc7')][_0x1a32('0x3e')]);_0x339ff4['query']=_[_0x1a32('0x77')](_0x689c9f[_0x1a32('0x45')]);_0x339ff4[_0x1a32('0x4b')]=_[_0x1a32('0x42')](_0x339ff4[_0x1a32('0x41')],_0x339ff4[_0x1a32('0x45')]);_0x2e3339[_0x1a32('0x43')]=_['intersection'](_0x339ff4[_0x1a32('0x41')],qs[_0x1a32('0x44')](_0x689c9f[_0x1a32('0x45')]['fields']));_0x2e3339[_0x1a32('0x43')]=_0x2e3339[_0x1a32('0x43')]['length']?_0x2e3339['attributes']:_0x339ff4[_0x1a32('0x41')];if(!_0x689c9f[_0x1a32('0x45')][_0x1a32('0x47')](_0x1a32('0xc8'))){_0x2e3339['limit']=qs['limit'](_0x689c9f['query'][_0x1a32('0x23')]);_0x2e3339[_0x1a32('0x21')]=qs[_0x1a32('0x21')](_0x689c9f[_0x1a32('0x45')][_0x1a32('0x21')]);}_0x2e3339[_0x1a32('0x48')]=qs[_0x1a32('0x49')](_0x689c9f[_0x1a32('0x45')][_0x1a32('0x49')]);_0x2e3339['where']=qs[_0x1a32('0x4b')](_['pick'](_0x689c9f['query'],_0x339ff4['filters']));_0x2e3339[_0x1a32('0x4a')][_0x1a32('0xb9')]=_0x44383e['id'];if(_0x689c9f['query'][_0x1a32('0x87')]){_0x2e3339[_0x1a32('0x4a')]=_[_0x1a32('0xc0')](_0x2e3339['where'],{'$or':_[_0x1a32('0x2e')](_0x2e3339[_0x1a32('0x43')],function(_0x318a38){var _0x49fc5f={};_0x49fc5f[_0x318a38]={'$like':'%'+_0x689c9f[_0x1a32('0x45')][_0x1a32('0x87')]+'%'};return _0x49fc5f;})});}if(_0x689c9f['query'][_0x1a32('0x7d')]){var _0x20a65b=_0x689c9f[_0x1a32('0x45')][_0x1a32('0x7d')]['split'](',');var _0xc1ceca={};_0xc1ceca[_0x20a65b[0x0]]={'$gte':moment(_0x20a65b[0x1])[_0x1a32('0xc9')](_0x1a32('0xca'))};_0x2e3339[_0x1a32('0x4a')]=_[_0x1a32('0xc0')](_0x2e3339[_0x1a32('0x4a')],_0xc1ceca);}_0x2e3339=_[_0x1a32('0xc0')]({},_0x2e3339,_0x689c9f[_0x1a32('0xcb')]);return db[_0x1a32('0xc7')][_0x1a32('0xa1')]({'where':_0x2e3339['where']})[_0x1a32('0x33')](function(_0x3b6648){_0x4ade0a[_0x1a32('0xa1')]=_0x3b6648;if(_0x689c9f[_0x1a32('0x45')][_0x1a32('0xbe')]){_0x2e3339[_0x1a32('0xbf')]=[{'all':!![]}];}return db['WhatsappMessage']['findAll'](_0x2e3339);})[_0x1a32('0x33')](function(_0x1a840b){_0x4ade0a['rows']=_0x1a840b;return _0x4ade0a;});}})[_0x1a32('0x33')](respondWithFilteredResult(_0x1faf0d,_0x2e3339))['catch'](handleError(_0x1faf0d,null));};exports[_0x1a32('0xcc')]=function(_0x235067,_0x4f06d5,_0x52069b){return db['WhatsappInteraction'][_0x1a32('0x65')]({'where':{'id':_0x235067[_0x1a32('0xbd')]['id']}})[_0x1a32('0x33')](handleEntityNotFound(_0x4f06d5,null))['then'](function(_0x21ee15){if(_0x21ee15){return _0x21ee15[_0x1a32('0xcd')](_0x235067['body'][_0x1a32('0xce')],_[_0x1a32('0xc5')](_0x235067[_0x1a32('0xc2')],[_0x1a32('0xce'),'id'])||{})[_0x1a32('0xcf')](function(){return db[_0x1a32('0x72')]['findAll']({'attributes':['id',_0x1a32('0x2b'),_0x1a32('0x4f')],'where':{'id':_0x235067['body'][_0x1a32('0xce')]}});})['then'](function(_0x42096e){socket[_0x1a32('0xd0')](_0x1a32('0xd1'),{'id':Number(_0x235067[_0x1a32('0xbd')]['id']),'tags':_0x42096e||[]});return{'id':Number(_0x235067['params']['id']),'tags':_0x42096e||[]};});}})[_0x1a32('0x33')](respondWithResult(_0x4f06d5,null))[_0x1a32('0x34')](handleError(_0x4f06d5,null));};exports[_0x1a32('0xd2')]=function(_0x4b3ad1,_0x285481,_0x41ecbc){return db[_0x1a32('0x3d')][_0x1a32('0x65')]({'where':{'id':_0x4b3ad1[_0x1a32('0xbd')]['id']}})[_0x1a32('0x33')](handleEntityNotFound(_0x285481,null))['then'](function(_0x28f562){if(_0x28f562){return _0x28f562['removeTags'](_0x4b3ad1[_0x1a32('0x45')][_0x1a32('0xce')]);}})[_0x1a32('0x33')](respondWithStatusCode(_0x285481,null))[_0x1a32('0x34')](handleError(_0x285481,null));};exports[_0x1a32('0xd3')]=function(_0x48ad34,_0x5229e4){var _0x353e57=moment()[_0x1a32('0xd4')]()[_0x1a32('0xa0')]();var _0x406141=path[_0x1a32('0xd5')](config[_0x1a32('0xd6')],_0x1a32('0xd7'),_0x1a32('0xd8'),_0x1a32('0xd9'));var _0xed6ca2=path['join'](config[_0x1a32('0xd6')],'server','files',_0x1a32('0xda'));var _0x30b6a4=path[_0x1a32('0xd5')](_0x406141,_0x353e57);var _0xc36f07=util[_0x1a32('0xc9')](_0x1a32('0xdb'),_0x48ad34[_0x1a32('0xbd')]['id'],_0x353e57);var _0x32c043=path[_0x1a32('0xd5')](_0x406141,_0xc36f07);var _0x3e9b7d=[];_0x3e9b7d[_0x1a32('0x32')]({'model':db[_0x1a32('0x75')],'as':_0x1a32('0x75'),'attributes':['id',_0x1a32('0xdc')],'raw':!![]});_0x3e9b7d['push']({'model':db[_0x1a32('0xdd')],'as':'Contact','attributes':['id','firstName',_0x1a32('0xde')],'raw':!![]});if(_0x48ad34[_0x1a32('0x45')][_0x1a32('0xda')]){_0x3e9b7d[_0x1a32('0x32')]({'model':db[_0x1a32('0xdf')],'as':_0x1a32('0xdf'),'raw':!![]});}var _0x5df506=[{'model':db[_0x1a32('0xc7')],'as':'Messages','attributes':['id',_0x1a32('0xc2'),_0x1a32('0xe0'),'direction',_0x1a32('0xe1'),_0x1a32('0x82')],'include':_0x3e9b7d}];_0x5df506[_0x1a32('0x32')]({'model':db[_0x1a32('0xe2')],'as':_0x1a32('0xe3'),'attributes':['id','name']});_0x5df506[_0x1a32('0x32')]({'model':db[_0x1a32('0x75')],'as':'Owner','attributes':['id',_0x1a32('0xdc')]});return db[_0x1a32('0x3d')][_0x1a32('0x65')]({'where':{'id':_0x48ad34[_0x1a32('0xbd')]['id']},'include':_0x5df506})[_0x1a32('0x33')](handleEntityNotFound(_0x5229e4,null))[_0x1a32('0x33')](function(_0xbbd6e1){if(_0xbbd6e1){var _0x3ebff3=_0xbbd6e1[_0x1a32('0xe4')]({'plain':!![]});fs[_0x1a32('0xe5')](_0x30b6a4);var _0x3a2c05={'channel':_0x1a32('0xe6'),'account':_0x3ebff3[_0x1a32('0xe3')][_0x1a32('0x2b')],'agent':_0x3ebff3[_0x1a32('0xe7')]?_0x3ebff3[_0x1a32('0xe7')]['fullname']:_0x1a32('0xe8'),'createdAt':moment(_0x3ebff3['createdAt'])['format'](_0x1a32('0xca'))[_0x1a32('0xa0')](),'closedAt':_0x3ebff3['closed']?moment(_0x3ebff3[_0x1a32('0xe9')])[_0x1a32('0xc9')](_0x1a32('0xca'))[_0x1a32('0xa0')]():'','disposition':_0x3ebff3[_0x1a32('0xea')],'messages':_(_0x3ebff3['Messages'])[_0x1a32('0x87')]({'secret':![]})['map'](function(_0x49557b){if(_0x49557b[_0x1a32('0xdf')]){var _0x2e841b=path[_0x1a32('0xd5')](_0xed6ca2,_0x49557b[_0x1a32('0xdf')][_0x1a32('0xeb')]);if(fs[_0x1a32('0xec')](_0x2e841b)){fs[_0x1a32('0xed')](_0x2e841b)['pipe'](fs[_0x1a32('0xee')](path[_0x1a32('0xd5')](_0x30b6a4,_0x49557b[_0x1a32('0xdf')][_0x1a32('0xeb')])));}}return{'date':moment(_0x49557b[_0x1a32('0xe0')])[_0x1a32('0xc9')]('YYYY-MM-DD\x20HH:mm:ss')[_0x1a32('0xa0')](),'sender':_0x49557b[_0x1a32('0xef')]===_0x1a32('0xf0')?_0x49557b[_0x1a32('0x75')]?_0x49557b[_0x1a32('0x75')][_0x1a32('0xdc')]:'System':_0x49557b[_0x1a32('0x69')][_0x1a32('0xf1')]+(_0x49557b[_0x1a32('0x69')]['lastName']?'\x20'+_0x49557b[_0x1a32('0x69')]['lastName']:''),'body':_0x49557b[_0x1a32('0xdf')]?_0x49557b[_0x1a32('0xdf')][_0x1a32('0xeb')]:_0x49557b['body'],'direction':_0x49557b[_0x1a32('0xef')]===_0x1a32('0xf0')?'A':'C','secret':_0x49557b[_0x1a32('0xe1')],'read':_0x49557b[_0x1a32('0x82')],'attachment':_0x49557b['Attachment']};})['value']()};return ejs['renderFile'](path[_0x1a32('0xd5')](config[_0x1a32('0xd6')],'server',_0x1a32('0xf2'),_0x1a32('0xf3')),{'interaction':_0x3a2c05})[_0x1a32('0x33')](function(_0x40b13b){var _0x49f417=path['join'](_0x30b6a4,_0x1a32('0xf4')+_0x3ebff3['id']+'-'+_0x353e57+_0x1a32('0xf5'));var _0xad17fd={'path':_0x49f417,'channel':_0x1a32('0xe6'),'interactionId':_0x3ebff3['id']};return pdf[_0x1a32('0xf6')](_0x40b13b,_0xad17fd);})['then'](function(){return new BPromise(function(_0x57f957,_0x51d19a){zipdir(_0x30b6a4,{'saveTo':_0x32c043},function(_0x4b7ae2,_0x4d3a3c){if(_0x4b7ae2)return _0x51d19a(_0x4b7ae2);return _0x57f957(_0x4d3a3c);});})[_0x1a32('0x33')](function(){return new BPromise(function(_0x33ca16,_0x4db394){rimraf(_0x30b6a4,function(_0x502c49){if(_0x502c49)_0x4db394(_0x502c49);return _0x33ca16();});});})[_0x1a32('0x33')](function(){return _0x5229e4[_0x1a32('0xd3')](_0x32c043,_0xc36f07,function(_0x4d46a8){if(_0x4d46a8){console['log'](_0x1a32('0xf7'),_0x4d46a8);}else{fs[_0x1a32('0xf8')](_0x32c043);}});});});}else{return _0x5229e4[_0x1a32('0x1e')](0xc8);}})[_0x1a32('0x34')](handleError(_0x5229e4,null));};
\ No newline at end of file
+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