Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 089a5be..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3d6d=['model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','pick','select','field','from','tools_tags','u.id','u.fullname','ui.WhatsappInteractionId','user_has_whatsapp_interactions','left_join','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','search','parseSearch','sqlOperator','conditions','unreadMessages','having','Contact','operator','$substring','getFullTextValue','value','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','buildExpression','start','union','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','find','UserId','text','body','some','compact','WhatsappAccountId','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20IS\x20NULL','`unreadMessages`\x20>\x200','tag','filter','replace','isNumeric','i.id\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','DESC','t.id\x20IN\x20?','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','role','agent','getWhatsappAccounts','isEmpty','i.WhatsappAccountId\x20IS\x20NULL','user','sequelize','toString','keyBy','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','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','contactName','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.mobile','Contact.mobile','Contact.fax','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','push','all','rows','show','params','includeAll','include','merge','update','addMessage','ids','omit','findOne','WhatsappMessage','$gte','split','YYYY-MM-DD\x20HH:mm:ss','options','findAll','addTags','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','root','files','join','attachments','format','transcript-%d-%s.zip','firstName','lastName','Attachment','Messages','secret','read','Account','Owner','get','mkdirSync','closed','closedAt','disposition','basename','existsSync','createReadStream','pipe','createWriteStream','out','System','direction','renderFile','server','views','transcript-','.pdf','Whatsapp','createPdfFromHTML','log','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../components/export/pdf','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','./whatsappInteraction.socket','register','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','apply','save','then','destroy','error','stack','name','send','Users','map','fullname','forEach','TagIds','catch','index','WhatsappInteraction','rawAttributes','type','key'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x3d6d,0xb3));var _0xd3d6=function(_0x2eb35d,_0x4a7a45){_0x2eb35d=_0x2eb35d-0x0;var _0x1f9854=_0x3d6d[_0x2eb35d];return _0x1f9854;};'use strict';var emlformat=require(_0xd3d6('0x0'));var rimraf=require(_0xd3d6('0x1'));var zipdir=require(_0xd3d6('0x2'));var jsonpatch=require(_0xd3d6('0x3'));var rp=require(_0xd3d6('0x4'));var moment=require(_0xd3d6('0x5'));var BPromise=require(_0xd3d6('0x6'));var Mustache=require(_0xd3d6('0x7'));var util=require(_0xd3d6('0x8'));var path=require(_0xd3d6('0x9'));var sox=require(_0xd3d6('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xd3d6('0xb'));var _=require(_0xd3d6('0xc'));var squel=require(_0xd3d6('0xd'));var crypto=require(_0xd3d6('0xe'));var jsforce=require(_0xd3d6('0xf'));var deskjs=require('desk.js');var toCsv=require(_0xd3d6('0x10'));var querystring=require(_0xd3d6('0x11'));var Papa=require(_0xd3d6('0x12'));var Redis=require(_0xd3d6('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xd3d6('0x14'));var pdf=require(_0xd3d6('0x15'));var hardwareService=require(_0xd3d6('0x16'));var logger=require(_0xd3d6('0x17'))(_0xd3d6('0x18'));var utils=require(_0xd3d6('0x19'));var config=require(_0xd3d6('0x1a'));var licenseUtil=require(_0xd3d6('0x1b'));var db=require(_0xd3d6('0x1c'))['db'];config['redis']=_[_0xd3d6('0x1d')](config[_0xd3d6('0x1e')],{'host':_0xd3d6('0x1f'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd3d6('0x1e')]));require(_0xd3d6('0x20'))[_0xd3d6('0x21')](socket);function respondWithStatusCode(_0x5e21e7,_0x1fcaee){_0x1fcaee=_0x1fcaee||0xcc;return function(_0x33c82c){if(_0x33c82c){return _0x5e21e7[_0xd3d6('0x22')](_0x1fcaee);}return _0x5e21e7[_0xd3d6('0x23')](_0x1fcaee)[_0xd3d6('0x24')]();};}function respondWithResult(_0x38e42f,_0x128bec){_0x128bec=_0x128bec||0xc8;return function(_0x31d4f0){if(_0x31d4f0){return _0x38e42f[_0xd3d6('0x23')](_0x128bec)['json'](_0x31d4f0);}};}function respondWithFilteredResult(_0xaee293,_0x27bac7){return function(_0x173ef4){if(_0x173ef4){var _0x3581bd=typeof _0x27bac7[_0xd3d6('0x25')]===_0xd3d6('0x26')&&typeof _0x27bac7[_0xd3d6('0x27')]===_0xd3d6('0x26');var _0x53bda9=_0x173ef4[_0xd3d6('0x28')];var _0x3a42c9=_0x3581bd?0x0:_0x27bac7[_0xd3d6('0x25')];var _0x4e7fa3=_0x3581bd?_0x173ef4[_0xd3d6('0x28')]:_0x27bac7[_0xd3d6('0x25')]+_0x27bac7[_0xd3d6('0x27')];var _0x44347a;if(_0x4e7fa3>=_0x53bda9){_0x4e7fa3=_0x53bda9;_0x44347a=0xc8;}else{_0x44347a=0xce;}_0xaee293['status'](_0x44347a);return _0xaee293[_0xd3d6('0x29')](_0xd3d6('0x2a'),_0x3a42c9+'-'+_0x4e7fa3+'/'+_0x53bda9)['json'](_0x173ef4);}return null;};}function patchUpdates(_0x3af9da){return function(_0x28d6af){try{jsonpatch[_0xd3d6('0x2b')](_0x28d6af,_0x3af9da,!![]);}catch(_0x548935){return BPromise['reject'](_0x548935);}return _0x28d6af[_0xd3d6('0x2c')]();};}function saveUpdates(_0x11bf1e,_0x28cc88){return function(_0x3c90cd){if(_0x3c90cd){return _0x3c90cd['update'](_0x11bf1e)[_0xd3d6('0x2d')](function(_0x298e3a){return _0x298e3a;});}return null;};}function removeEntity(_0x2ea04a,_0x87e591){return function(_0x4108c2){if(_0x4108c2){return _0x4108c2[_0xd3d6('0x2e')]()[_0xd3d6('0x2d')](function(){_0x2ea04a[_0xd3d6('0x23')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1fa97e,_0x360e43){return function(_0x509f92){if(!_0x509f92){_0x1fa97e[_0xd3d6('0x22')](0x194);}return _0x509f92;};}function handleError(_0x3be627,_0x16ebad){_0x16ebad=_0x16ebad||0x1f4;return function(_0xb0074f){logger[_0xd3d6('0x2f')](_0xb0074f[_0xd3d6('0x30')]);if(_0xb0074f[_0xd3d6('0x31')]){delete _0xb0074f[_0xd3d6('0x31')];}_0x3be627[_0xd3d6('0x23')](_0x16ebad)[_0xd3d6('0x32')](_0xb0074f);};}function getInteractionUsers(_0x55949c,_0x161746){return new BPromise(function(_0x9a861d,_0xe25c7d){try{if(_0x161746[_0x55949c['id']]){_0x55949c[_0xd3d6('0x33')]=_[_0xd3d6('0x34')](_0x161746[_0x55949c['id']],function(_0x9bee76){return{'id':_0x9bee76['id'],'fullname':_0x9bee76[_0xd3d6('0x35')]};});}}catch(_0x5b94ca){_0xe25c7d(_0x5b94ca);}_0x9a861d(_0x55949c);});}function getInteractionTags(_0x4ce84b,_0x280b4c){return new BPromise(function(_0x330ba7,_0xf39aa){try{if(_0x4ce84b['TagIds']){_0x4ce84b['Tags']=[];_0x4ce84b['TagIds']['split'](',')[_0xd3d6('0x36')](function(_0x4db6ea){_0x4ce84b['Tags']['push'](_0x280b4c[_0x4db6ea]);});}delete _0x4ce84b[_0xd3d6('0x37')];}catch(_0x4b05b2){_0xf39aa(_0x4b05b2);}_0x330ba7(_0x4ce84b);});}function updateWhatsappInteraction(_0x5661ef,_0x351a25,_0x493d53){return new BPromise(function(_0x426d66,_0x2b7e74){return getInteractionUsers(_0x5661ef,_0x493d53)[_0xd3d6('0x2d')](function(_0xcfa94){return getInteractionTags(_0xcfa94,_0x351a25);})[_0xd3d6('0x2d')](function(_0x2b1ae0){_0x426d66(_0x2b1ae0);})[_0xd3d6('0x38')](function(_0x5ab865){_0x2b7e74(_0x5ab865);});});}exports[_0xd3d6('0x39')]=function(_0x1805d7,_0x49f50e){var _0x3806df={},_0x50fd51={},_0xe3fe1a={'count':0x0,'rows':[]};var _0xb49bab=_['map'](db[_0xd3d6('0x3a')][_0xd3d6('0x3b')],function(_0x490a67){return{'name':_0x490a67['fieldName'],'type':_0x490a67[_0xd3d6('0x3c')][_0xd3d6('0x3d')]};});_0x50fd51[_0xd3d6('0x3e')]=_[_0xd3d6('0x34')](_0xb49bab,_0xd3d6('0x31'));_0x50fd51[_0xd3d6('0x3f')]=_[_0xd3d6('0x40')](_0x1805d7['query']);_0x50fd51[_0xd3d6('0x41')]=_[_0xd3d6('0x42')](_0x50fd51[_0xd3d6('0x3e')],_0x50fd51[_0xd3d6('0x3f')]);_0x3806df['attributes']=_[_0xd3d6('0x42')](_0x50fd51[_0xd3d6('0x3e')],qs[_0xd3d6('0x43')](_0x1805d7[_0xd3d6('0x3f')]['fields']));_0x3806df[_0xd3d6('0x44')]=_0x3806df[_0xd3d6('0x44')][_0xd3d6('0x45')]?_0x3806df[_0xd3d6('0x44')]:_0x50fd51[_0xd3d6('0x3e')];if(!_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x46')]('nolimit')){_0x3806df[_0xd3d6('0x27')]=qs[_0xd3d6('0x27')](_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x27')]);_0x3806df[_0xd3d6('0x25')]=qs[_0xd3d6('0x25')](_0x1805d7[_0xd3d6('0x3f')]['offset']);}_0x3806df[_0xd3d6('0x47')]=qs[_0xd3d6('0x48')](_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x48')]);_0x3806df[_0xd3d6('0x49')]=qs['filters'](_[_0xd3d6('0x4a')](_0x1805d7[_0xd3d6('0x3f')],_0x50fd51[_0xd3d6('0x41')]),_0xb49bab);var _0x400c9d=[];var _0x363b17=squel[_0xd3d6('0x4b')]()[_0xd3d6('0x4c')]('id')[_0xd3d6('0x4c')](_0xd3d6('0x31'))[_0xd3d6('0x4c')]('color')[_0xd3d6('0x4d')](_0xd3d6('0x4e'));var _0x51485d=squel[_0xd3d6('0x4b')]()[_0xd3d6('0x4c')](_0xd3d6('0x4f'))['field'](_0xd3d6('0x50'))[_0xd3d6('0x4c')](_0xd3d6('0x51'))[_0xd3d6('0x4d')](_0xd3d6('0x52'),'ui')[_0xd3d6('0x53')]('users','u',_0xd3d6('0x54'));var _0x349811=squel[_0xd3d6('0x4b')]()[_0xd3d6('0x4d')](_0xd3d6('0x55'),'i')[_0xd3d6('0x53')](_0xd3d6('0x56'),'c',_0xd3d6('0x57'))[_0xd3d6('0x53')](_0xd3d6('0x58'),'o','o.id\x20=\x20i.UserId')['left_join'](_0xd3d6('0x59'),'a',_0xd3d6('0x5a'))[_0xd3d6('0x53')](_0xd3d6('0x5b'),'me',_0xd3d6('0x5c'))[_0xd3d6('0x53')]('whatsapp_interaction_has_tags','it',_0xd3d6('0x5d'))[_0xd3d6('0x53')](_0xd3d6('0x4e'),'t',_0xd3d6('0x5e'));var _0x55a14c=squel[_0xd3d6('0x5f')]();var _0x138be8=[];var _0x999003=squel[_0xd3d6('0x5f')]();var _0x183a6b;if(_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x60')]){_0x183a6b=as[_0xd3d6('0x61')](_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x60')]);var _0x43b4ff=_0x183a6b[_0xd3d6('0x62')];for(var _0x43537b=0x0;_0x43537b<_0x183a6b[_0xd3d6('0x63')]['length'];_0x43537b++){var _0x2f935a=_0x183a6b[_0xd3d6('0x63')][_0x43537b];var _0x563a3d='i';var _0x211d22=_['find'](_0xb49bab,[_0xd3d6('0x31'),_0x2f935a[_0xd3d6('0x4c')]]);if(!_0x211d22){switch(_0x2f935a['field']){case _0xd3d6('0x64'):if(_0x2f935a['value']==0x1){_0x349811[_0xd3d6('0x65')]('`'+_0x2f935a[_0xd3d6('0x4c')]+'`\x20=\x200');}else{_0x349811[_0xd3d6('0x65')]('`'+_0x2f935a[_0xd3d6('0x4c')]+'`\x20>\x200');}break;case _0xd3d6('0x66'):if(_0x2f935a[_0xd3d6('0x67')]===_0xd3d6('0x68')){if(_0x2f935a['value']['split']('\x20')[_0xd3d6('0x45')]>0x1){_0x55a14c[_0x43b4ff]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xd3d6('0x69')](_0x2f935a[_0xd3d6('0x6a')]),null);}else{var _0x2ed35b='%'+_0x2f935a['value']+'%';_0x55a14c[_0x43b4ff](_0xd3d6('0x6b'),_0x2ed35b,_0x2ed35b,_0x2ed35b);}}else{_0x211d22=_['find'](_0xb49bab,[_0xd3d6('0x31'),_0xd3d6('0x6c')]);_0x2f935a[_0xd3d6('0x4c')]=_0xd3d6('0x6c');_0x5e3223=as[_0xd3d6('0x6d')](_0x563a3d,_0x211d22[_0xd3d6('0x3c')],_0x2f935a);_0x55a14c[_0x43b4ff](_0x5e3223['text'],_0x5e3223[_0xd3d6('0x6a')][_0xd3d6('0x6e')],_0x5e3223[_0xd3d6('0x6a')][_0xd3d6('0x24')]);}break;case'Tag':var _0x3652d0=_0x2f935a[_0xd3d6('0x6a')]['split'](',')[_0xd3d6('0x34')](function(_0x36b8ab){return Number(_0x36b8ab);});_0x3652d0[_0xd3d6('0x36')](function(_0x271b78){_0x999003['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x271b78+',%');});_0x138be8=_[_0xd3d6('0x6f')](_0x138be8,_0x3652d0);break;case _0xd3d6('0x70'):if(_0x2f935a[_0xd3d6('0x67')]===_0xd3d6('0x68')){_0x55a14c[_0x43b4ff](_0xd3d6('0x71'),'%'+_0x2f935a['value']+'%',null);}else{_0x211d22=_[_0xd3d6('0x72')](_0xb49bab,[_0xd3d6('0x31'),_0xd3d6('0x73')]);_0x2f935a['field']=_0xd3d6('0x73');_0x5e3223=as[_0xd3d6('0x6d')](_0x563a3d,_0x211d22[_0xd3d6('0x3c')],_0x2f935a);_0x55a14c[_0x43b4ff](_0x5e3223[_0xd3d6('0x74')],_0x5e3223['value'][_0xd3d6('0x6e')],_0x5e3223[_0xd3d6('0x6a')]['end']);}break;case _0xd3d6('0x75'):_0x5e3223=as[_0xd3d6('0x6d')]('me',null,_0x2f935a);_0x55a14c[_0x43b4ff](_0x5e3223[_0xd3d6('0x74')],_0x5e3223[_0xd3d6('0x6a')]['start'],_0x5e3223[_0xd3d6('0x6a')][_0xd3d6('0x24')]);break;}}else{var _0x5e3223=as['buildExpression'](_0x563a3d,_0x211d22['type'],_0x2f935a);_0x55a14c[_0x43b4ff](_0x5e3223[_0xd3d6('0x74')],_0x5e3223[_0xd3d6('0x6a')][_0xd3d6('0x6e')],_0x5e3223['value'][_0xd3d6('0x24')]);}}}else{var _0x1ca38c=_(_0x1805d7[_0xd3d6('0x3f')])[_0xd3d6('0x40')]()[_0xd3d6('0x34')](function(_0x123759){return _[_0xd3d6('0x76')](_0xb49bab,[_0xd3d6('0x31'),_0x123759])?_0x123759:undefined;})[_0xd3d6('0x77')]()[_0xd3d6('0x6a')]();if(!_['isEmpty'](_0x1ca38c)){_0x1ca38c['forEach'](function(_0x216dc7){if(_0x216dc7===_0xd3d6('0x78')){_0x349811['where'](_0xd3d6('0x79'),[][_0xd3d6('0x7a')](_0x1805d7[_0xd3d6('0x3f')][_0x216dc7]));}else if(_0x216dc7===_0xd3d6('0x7b')){var _0x8eac3d=JSON[_0xd3d6('0x7c')](_0x1805d7[_0xd3d6('0x3f')][_0x216dc7])['$gte'];var _0x3c5acd=JSON[_0xd3d6('0x7c')](_0x1805d7[_0xd3d6('0x3f')][_0x216dc7])[_0xd3d6('0x7d')];_0x349811[_0xd3d6('0x49')](_0xd3d6('0x7e'),_0x8eac3d,_0x3c5acd);}else{if(_0x1805d7[_0xd3d6('0x3f')][_0x216dc7]===_0xd3d6('0x7f')){_0x349811['where']('i.'+_0x216dc7+_0xd3d6('0x80'));}else{_0x349811[_0xd3d6('0x49')]('i.'+_0x216dc7+'\x20=\x20?',_0x1805d7[_0xd3d6('0x3f')][_0x216dc7]);}}});}if(_0x1805d7['query']['read']){if(_0x1805d7[_0xd3d6('0x3f')]['read']==0x1){_0x349811[_0xd3d6('0x65')]('`unreadMessages`\x20=\x200');}else{_0x349811[_0xd3d6('0x65')](_0xd3d6('0x81'));}}if(_0x1805d7[_0xd3d6('0x3f')]['tag']){_0x138be8=_['isArray'](_0x1805d7['query'][_0xd3d6('0x82')])?_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x82')]:new Array(_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x82')]);_0x138be8[_0xd3d6('0x36')](function(_0x398766){_0x999003['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x398766+',%');});}if(_0x1805d7['query'][_0xd3d6('0x83')]){var _0x1638dd=_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x83')][_0xd3d6('0x84')]('\x5c','\x5c\x5c')[_0xd3d6('0x84')](/'/g,'\x27\x27');if(qs[_0xd3d6('0x85')](_0x1638dd)){_0x55a14c['or'](_0xd3d6('0x86'),_0x1638dd+'%')['or']('i.phone\x20LIKE\x20?',_0x1638dd+'%');}else{_0x55a14c['or'](_0xd3d6('0x87'),qs[_0xd3d6('0x69')](_0x1638dd))['or'](_0xd3d6('0x88'),_0x1638dd+'%');}}}_0x349811[_0xd3d6('0x49')](_0x55a14c);_0x349811[_0xd3d6('0x89')](_0xd3d6('0x8a'));var _0x420966={'type':db[_0xd3d6('0x8b')][_0xd3d6('0x8c')][_0xd3d6('0x8d')],'raw':!![]};var _0x32b574=_0x349811[_0xd3d6('0x8e')]();_0x32b574['field'](_0xd3d6('0x8a'));_0x32b574[_0xd3d6('0x4c')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)',_0xd3d6('0x64'));if(_0x3806df[_0xd3d6('0x47')]){_0x3806df['order'][_0xd3d6('0x36')](function(_0x56cbb0){var _0x45904e=_0x56cbb0[0x0]==='contactName'?_0x56cbb0[0x0]:'i.'+_0x56cbb0[0x0];_0x349811[_0xd3d6('0x47')](_0x45904e,_0x56cbb0[0x1]===_0xd3d6('0x8f')?![]:!![]);});}if(!_['isEmpty'](_0x138be8)){_0x349811[_0xd3d6('0x65')](_0x999003);_0x32b574[_0xd3d6('0x49')](_0xd3d6('0x90'),_0x138be8);}BPromise['resolve']()[_0xd3d6('0x2d')](function(){if(!_0x183a6b){if(_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x78')])return;_0x32b574[_0xd3d6('0x49')](_0xd3d6('0x91'));_0x349811[_0xd3d6('0x49')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x1805d7['user'][_0xd3d6('0x92')]!==_0xd3d6('0x93'))return;return _0x1805d7['user'][_0xd3d6('0x94')]({'attributes':['id'],'raw':!![]})[_0xd3d6('0x2d')](function(_0x18ae87){if(_[_0xd3d6('0x95')](_0x18ae87)){_0x32b574[_0xd3d6('0x49')](_0xd3d6('0x96'));_0x349811[_0xd3d6('0x49')](_0xd3d6('0x96'));}else{_0x32b574[_0xd3d6('0x49')](_0xd3d6('0x79'),_['map'](_0x18ae87,'id'));_0x349811['where'](_0xd3d6('0x79'),_[_0xd3d6('0x34')](_0x18ae87,'id'));}});})[_0xd3d6('0x2d')](function(){if(_0x1805d7[_0xd3d6('0x97')][_0xd3d6('0x92')]===_0xd3d6('0x93')&&!_0x183a6b&&!_0x1805d7[_0xd3d6('0x3f')][_0xd3d6('0x78')])return[];return db[_0xd3d6('0x98')]['query'](_0x32b574[_0xd3d6('0x99')](),_0x420966);})['then'](function(_0x38b511){_0xe3fe1a['count']=_0x38b511[_0xd3d6('0x45')];if(_0xe3fe1a['count']===0x0)return[];return db['sequelize'][_0xd3d6('0x3f')](_0x363b17[_0xd3d6('0x99')](),_0x420966)['then'](function(_0x38f759){_0x400c9d=_[_0xd3d6('0x9a')](_0x38f759,'id');_0x420966=_['merge'](_0x420966,{'model':db[_0xd3d6('0x3a')],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x1805d7[_0xd3d6('0x3f')]['fields']){_0x3806df[_0xd3d6('0x44')][_0xd3d6('0x36')](function(_0x26b65c){_0x349811[_0xd3d6('0x4c')]('i.'+_0x26b65c);});}else{_0x349811[_0xd3d6('0x4c')](_0xd3d6('0x9b'),_0xd3d6('0x64'));_0x349811['field'](_0xd3d6('0x9c'),_0xd3d6('0x9d'));_0x349811[_0xd3d6('0x4c')](_0xd3d6('0x9e'),'Account.mandatoryDisposition');_0x349811['field'](_0xd3d6('0x9f'),_0xd3d6('0xa0'));_0x349811['field']('i.*');_0x349811[_0xd3d6('0x4c')](_0xd3d6('0xa1'),'Contact.firstName');_0x349811[_0xd3d6('0x4c')](_0xd3d6('0xa2'),_0xd3d6('0xa3'));_0x349811[_0xd3d6('0x4c')](_0xd3d6('0xa4'),_0xd3d6('0xa5'));_0x349811[_0xd3d6('0x4c')]('c.phone','Contact.phone');_0x349811['field'](_0xd3d6('0xa6'),_0xd3d6('0xa7'));_0x349811[_0xd3d6('0x4c')]('c.fax',_0xd3d6('0xa8'));_0x349811[_0xd3d6('0x4c')]('o.fullname',_0xd3d6('0xa9'));_0x349811['field'](_0xd3d6('0xaa'),_0xd3d6('0xab'));_0x349811[_0xd3d6('0x4c')](_0xd3d6('0xac'),_0xd3d6('0x37'));}if(_0x3806df[_0xd3d6('0x27')])_0x349811['limit'](_0x3806df[_0xd3d6('0x27')]);if(_0x3806df[_0xd3d6('0x25')])_0x349811['offset'](_0x3806df[_0xd3d6('0x25')]);return db[_0xd3d6('0x98')][_0xd3d6('0x3f')](_0x349811[_0xd3d6('0x99')](),_0x420966);})[_0xd3d6('0x2d')](function(_0xdece3c){if(_0xdece3c[_0xd3d6('0x45')]>0x0)_0x51485d[_0xd3d6('0x49')](_0xd3d6('0xad'),_[_0xd3d6('0x34')](_0xdece3c,'id'));return db[_0xd3d6('0x98')][_0xd3d6('0x3f')](_0x51485d[_0xd3d6('0x99')](),_0x420966)[_0xd3d6('0x2d')](function(_0x404937){var _0x455c94=_[_0xd3d6('0xae')](_0x404937,_0xd3d6('0xaf'));var _0x353aeb=[];_0xdece3c[_0xd3d6('0x36')](function(_0x1f1f5f){_0x353aeb[_0xd3d6('0xb0')](updateWhatsappInteraction(_0x1f1f5f,_0x400c9d,_0x455c94));});return BPromise[_0xd3d6('0xb1')](_0x353aeb);});});})[_0xd3d6('0x2d')](function(_0x4359cd){_0xe3fe1a[_0xd3d6('0xb2')]=_0x4359cd;return _0xe3fe1a;})[_0xd3d6('0x2d')](respondWithFilteredResult(_0x49f50e,_0x3806df))[_0xd3d6('0x38')](handleError(_0x49f50e,null));};exports[_0xd3d6('0xb3')]=function(_0x58ebe4,_0xc38a7d){var _0xa9bc1e={'raw':![],'where':{'id':_0x58ebe4[_0xd3d6('0xb4')]['id']}},_0x1b5510={};_0x1b5510[_0xd3d6('0x3e')]=_[_0xd3d6('0x40')](db['WhatsappInteraction'][_0xd3d6('0x3b')]);_0x1b5510[_0xd3d6('0x3f')]=_[_0xd3d6('0x40')](_0x58ebe4[_0xd3d6('0x3f')]);_0x1b5510['filters']=_['intersection'](_0x1b5510[_0xd3d6('0x3e')],_0x1b5510[_0xd3d6('0x3f')]);_0xa9bc1e[_0xd3d6('0x44')]=_['intersection'](_0x1b5510['model'],qs[_0xd3d6('0x43')](_0x58ebe4[_0xd3d6('0x3f')][_0xd3d6('0x43')]));_0xa9bc1e[_0xd3d6('0x44')]=_0xa9bc1e[_0xd3d6('0x44')]['length']?_0xa9bc1e[_0xd3d6('0x44')]:_0x1b5510[_0xd3d6('0x3e')];if(_0x58ebe4['query'][_0xd3d6('0xb5')]){_0xa9bc1e[_0xd3d6('0xb6')]=[{'all':!![]}];}_0xa9bc1e=_[_0xd3d6('0xb7')]({},_0xa9bc1e,_0x58ebe4['options']);return db[_0xd3d6('0x3a')]['find'](_0xa9bc1e)[_0xd3d6('0x2d')](handleEntityNotFound(_0xc38a7d,null))[_0xd3d6('0x2d')](respondWithResult(_0xc38a7d,null))['catch'](handleError(_0xc38a7d,null));};exports['create']=function(_0x517b11,_0xee2f0f){return db[_0xd3d6('0x3a')]['create'](_0x517b11[_0xd3d6('0x75')],{})[_0xd3d6('0x2d')](respondWithResult(_0xee2f0f,0xc9))[_0xd3d6('0x38')](handleError(_0xee2f0f,null));};exports[_0xd3d6('0xb8')]=function(_0x84b895,_0x4044b1){if(_0x84b895[_0xd3d6('0x75')]['id']){delete _0x84b895[_0xd3d6('0x75')]['id'];}return db[_0xd3d6('0x3a')][_0xd3d6('0x72')]({'where':{'id':_0x84b895[_0xd3d6('0xb4')]['id']}})['then'](handleEntityNotFound(_0x4044b1,null))[_0xd3d6('0x2d')](saveUpdates(_0x84b895['body'],null))['then'](respondWithResult(_0x4044b1,null))[_0xd3d6('0x38')](handleError(_0x4044b1,null));};exports[_0xd3d6('0x2e')]=function(_0x5c83ef,_0xbfeaff){return db[_0xd3d6('0x3a')][_0xd3d6('0x72')]({'where':{'id':_0x5c83ef[_0xd3d6('0xb4')]['id']}})['then'](handleEntityNotFound(_0xbfeaff,null))[_0xd3d6('0x2d')](removeEntity(_0xbfeaff,null))[_0xd3d6('0x38')](handleError(_0xbfeaff,null));};exports['describe']=function(_0x4db5c0,_0x5866f8){return db[_0xd3d6('0x3a')]['describe']()['then'](respondWithResult(_0x5866f8,null))[_0xd3d6('0x38')](handleError(_0x5866f8,null));};exports[_0xd3d6('0xb9')]=function(_0x55fe4b,_0x5f00cf,_0x2ca11c){return db['WhatsappMessage']['find']({'where':{'id':_0x55fe4b[_0xd3d6('0xb4')]['id']}})[_0xd3d6('0x2d')](handleEntityNotFound(_0x5f00cf,null))[_0xd3d6('0x2d')](function(_0xa5dd9c){if(_0xa5dd9c){return _0xa5dd9c['addMessage'](_0x55fe4b['body'][_0xd3d6('0xba')],_[_0xd3d6('0xbb')](_0x55fe4b[_0xd3d6('0x75')],[_0xd3d6('0xba'),'id'])||{});}})[_0xd3d6('0x2d')](respondWithResult(_0x5f00cf,null))[_0xd3d6('0x38')](handleError(_0x5f00cf,null));};exports['getMessages']=function(_0x416a7a,_0x26c1cb,_0x1a54ff){var _0x52f576={'raw':![],'where':{}};var _0x3bab21={};var _0x3f85bb={'count':0x0,'rows':[]};return db['WhatsappInteraction'][_0xd3d6('0xbc')]({'where':{'id':_0x416a7a[_0xd3d6('0xb4')]['id']}})[_0xd3d6('0x2d')](handleEntityNotFound(_0x26c1cb,null))['then'](function(_0x4de65c){if(_0x4de65c){_0x3bab21[_0xd3d6('0x3e')]=_[_0xd3d6('0x40')](db[_0xd3d6('0xbd')]['rawAttributes']);_0x3bab21[_0xd3d6('0x3f')]=_['keys'](_0x416a7a[_0xd3d6('0x3f')]);_0x3bab21['filters']=_['intersection'](_0x3bab21[_0xd3d6('0x3e')],_0x3bab21['query']);_0x52f576[_0xd3d6('0x44')]=_[_0xd3d6('0x42')](_0x3bab21[_0xd3d6('0x3e')],qs['fields'](_0x416a7a[_0xd3d6('0x3f')][_0xd3d6('0x43')]));_0x52f576['attributes']=_0x52f576['attributes'][_0xd3d6('0x45')]?_0x52f576[_0xd3d6('0x44')]:_0x3bab21[_0xd3d6('0x3e')];if(!_0x416a7a[_0xd3d6('0x3f')]['hasOwnProperty']('nolimit')){_0x52f576[_0xd3d6('0x27')]=qs[_0xd3d6('0x27')](_0x416a7a[_0xd3d6('0x3f')][_0xd3d6('0x27')]);_0x52f576[_0xd3d6('0x25')]=qs[_0xd3d6('0x25')](_0x416a7a['query'][_0xd3d6('0x25')]);}_0x52f576[_0xd3d6('0x47')]=qs[_0xd3d6('0x48')](_0x416a7a[_0xd3d6('0x3f')][_0xd3d6('0x48')]);_0x52f576[_0xd3d6('0x49')]=qs[_0xd3d6('0x41')](_[_0xd3d6('0x4a')](_0x416a7a[_0xd3d6('0x3f')],_0x3bab21[_0xd3d6('0x41')]));_0x52f576[_0xd3d6('0x49')][_0xd3d6('0xaf')]=_0x4de65c['id'];if(_0x416a7a['query'][_0xd3d6('0x83')]){_0x52f576[_0xd3d6('0x49')]=_[_0xd3d6('0xb7')](_0x52f576['where'],{'$or':_['map'](_0x52f576['attributes'],function(_0x460744){var _0x1569bb={};_0x1569bb[_0x460744]={'$like':'%'+_0x416a7a[_0xd3d6('0x3f')]['filter']+'%'};return _0x1569bb;})});}if(_0x416a7a['query'][_0xd3d6('0xbe')]){var _0xbb13e2=_0x416a7a[_0xd3d6('0x3f')][_0xd3d6('0xbe')][_0xd3d6('0xbf')](',');var _0x302f31={};_0x302f31[_0xbb13e2[0x0]]={'$gte':moment(_0xbb13e2[0x1])['format'](_0xd3d6('0xc0'))};_0x52f576[_0xd3d6('0x49')]=_[_0xd3d6('0xb7')](_0x52f576[_0xd3d6('0x49')],_0x302f31);}_0x52f576=_['merge']({},_0x52f576,_0x416a7a[_0xd3d6('0xc1')]);return db['WhatsappMessage'][_0xd3d6('0x28')]({'where':_0x52f576[_0xd3d6('0x49')]})[_0xd3d6('0x2d')](function(_0x2c10d9){_0x3f85bb[_0xd3d6('0x28')]=_0x2c10d9;if(_0x416a7a[_0xd3d6('0x3f')][_0xd3d6('0xb5')]){_0x52f576['include']=[{'all':!![]}];}return db['WhatsappMessage'][_0xd3d6('0xc2')](_0x52f576);})[_0xd3d6('0x2d')](function(_0x3bf25b){_0x3f85bb[_0xd3d6('0xb2')]=_0x3bf25b;return _0x3f85bb;});}})[_0xd3d6('0x2d')](respondWithFilteredResult(_0x26c1cb,_0x52f576))[_0xd3d6('0x38')](handleError(_0x26c1cb,null));};exports[_0xd3d6('0xc3')]=function(_0x49b672,_0x1f5a4e,_0x56b7bc){return db['WhatsappInteraction'][_0xd3d6('0x72')]({'where':{'id':_0x49b672['params']['id']}})['then'](handleEntityNotFound(_0x1f5a4e,null))['then'](function(_0x140ca6){if(_0x140ca6){return _0x140ca6[_0xd3d6('0xc4')](_0x49b672[_0xd3d6('0x75')][_0xd3d6('0xba')],_[_0xd3d6('0xbb')](_0x49b672['body'],[_0xd3d6('0xba'),'id'])||{})[_0xd3d6('0xc5')](function(){return db[_0xd3d6('0xc6')][_0xd3d6('0xc2')]({'attributes':['id','name',_0xd3d6('0xc7')],'where':{'id':_0x49b672[_0xd3d6('0x75')][_0xd3d6('0xba')]}});})[_0xd3d6('0x2d')](function(_0x299f3d){socket[_0xd3d6('0xc8')](_0xd3d6('0xc9'),{'id':Number(_0x49b672[_0xd3d6('0xb4')]['id']),'tags':_0x299f3d||[]});return{'id':Number(_0x49b672[_0xd3d6('0xb4')]['id']),'tags':_0x299f3d||[]};});}})[_0xd3d6('0x2d')](respondWithResult(_0x1f5a4e,null))[_0xd3d6('0x38')](handleError(_0x1f5a4e,null));};exports[_0xd3d6('0xca')]=function(_0x526b9e,_0x22acca,_0x3f9310){return db['WhatsappInteraction'][_0xd3d6('0x72')]({'where':{'id':_0x526b9e[_0xd3d6('0xb4')]['id']}})['then'](handleEntityNotFound(_0x22acca,null))[_0xd3d6('0x2d')](function(_0x3e2603){if(_0x3e2603){return _0x3e2603[_0xd3d6('0xca')](_0x526b9e[_0xd3d6('0x3f')][_0xd3d6('0xba')]);}})[_0xd3d6('0x2d')](respondWithStatusCode(_0x22acca,null))['catch'](handleError(_0x22acca,null));};exports[_0xd3d6('0xcb')]=function(_0x2bdf80,_0x581c3f){var _0x225733=moment()[_0xd3d6('0xcc')]()[_0xd3d6('0x99')]();var _0x27da93=path['join'](config[_0xd3d6('0xcd')],'server',_0xd3d6('0xce'),'tmp');var _0x5b6e29=path[_0xd3d6('0xcf')](config[_0xd3d6('0xcd')],'server',_0xd3d6('0xce'),_0xd3d6('0xd0'));var _0x27be09=path[_0xd3d6('0xcf')](_0x27da93,_0x225733);var _0x48cdb6=util[_0xd3d6('0xd1')](_0xd3d6('0xd2'),_0x2bdf80[_0xd3d6('0xb4')]['id'],_0x225733);var _0xa7e82b=path[_0xd3d6('0xcf')](_0x27da93,_0x48cdb6);var _0x202990=[];_0x202990[_0xd3d6('0xb0')]({'model':db['User'],'as':_0xd3d6('0x70'),'attributes':['id','fullname'],'raw':!![]});_0x202990[_0xd3d6('0xb0')]({'model':db['CmContact'],'as':_0xd3d6('0x66'),'attributes':['id',_0xd3d6('0xd3'),_0xd3d6('0xd4')],'raw':!![]});if(_0x2bdf80['query'][_0xd3d6('0xd0')]){_0x202990[_0xd3d6('0xb0')]({'model':db[_0xd3d6('0xd5')],'as':_0xd3d6('0xd5'),'raw':!![]});}var _0x333375=[{'model':db['WhatsappMessage'],'as':_0xd3d6('0xd6'),'attributes':['id',_0xd3d6('0x75'),_0xd3d6('0x7b'),'direction',_0xd3d6('0xd7'),_0xd3d6('0xd8')],'include':_0x202990}];_0x333375['push']({'model':db['WhatsappAccount'],'as':_0xd3d6('0xd9'),'attributes':['id','name']});_0x333375[_0xd3d6('0xb0')]({'model':db[_0xd3d6('0x70')],'as':_0xd3d6('0xda'),'attributes':['id',_0xd3d6('0x35')]});return db[_0xd3d6('0x3a')]['find']({'where':{'id':_0x2bdf80[_0xd3d6('0xb4')]['id']},'include':_0x333375})[_0xd3d6('0x2d')](handleEntityNotFound(_0x581c3f,null))[_0xd3d6('0x2d')](function(_0x1672ed){if(_0x1672ed){var _0x2bfeb4=_0x1672ed[_0xd3d6('0xdb')]({'plain':!![]});fs[_0xd3d6('0xdc')](_0x27be09);var _0x13efee={'channel':'Whatsapp','account':_0x2bfeb4[_0xd3d6('0xd9')][_0xd3d6('0x31')],'agent':_0x2bfeb4[_0xd3d6('0xda')]?_0x2bfeb4[_0xd3d6('0xda')]['fullname']:'N.A.','createdAt':moment(_0x2bfeb4['createdAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xd3d6('0x99')](),'closedAt':_0x2bfeb4[_0xd3d6('0xdd')]?moment(_0x2bfeb4[_0xd3d6('0xde')])[_0xd3d6('0xd1')](_0xd3d6('0xc0'))[_0xd3d6('0x99')]():'','disposition':_0x2bfeb4[_0xd3d6('0xdf')],'messages':_(_0x2bfeb4[_0xd3d6('0xd6')])[_0xd3d6('0x83')]({'secret':![]})[_0xd3d6('0x34')](function(_0x1ddf68){if(_0x1ddf68[_0xd3d6('0xd5')]){var _0x418403=path['join'](_0x5b6e29,_0x1ddf68[_0xd3d6('0xd5')][_0xd3d6('0xe0')]);if(fs[_0xd3d6('0xe1')](_0x418403)){fs[_0xd3d6('0xe2')](_0x418403)[_0xd3d6('0xe3')](fs[_0xd3d6('0xe4')](path[_0xd3d6('0xcf')](_0x27be09,_0x1ddf68[_0xd3d6('0xd5')][_0xd3d6('0xe0')])));}}return{'date':moment(_0x1ddf68[_0xd3d6('0x7b')])[_0xd3d6('0xd1')](_0xd3d6('0xc0'))[_0xd3d6('0x99')](),'sender':_0x1ddf68['direction']===_0xd3d6('0xe5')?_0x1ddf68[_0xd3d6('0x70')]?_0x1ddf68[_0xd3d6('0x70')][_0xd3d6('0x35')]:_0xd3d6('0xe6'):_0x1ddf68['Contact'][_0xd3d6('0xd3')]+(_0x1ddf68['Contact'][_0xd3d6('0xd4')]?'\x20'+_0x1ddf68[_0xd3d6('0x66')][_0xd3d6('0xd4')]:''),'body':_0x1ddf68[_0xd3d6('0xd5')]?_0x1ddf68[_0xd3d6('0xd5')]['basename']:_0x1ddf68[_0xd3d6('0x75')],'direction':_0x1ddf68[_0xd3d6('0xe7')]==='out'?'A':'C','secret':_0x1ddf68[_0xd3d6('0xd7')],'read':_0x1ddf68['read'],'attachment':_0x1ddf68[_0xd3d6('0xd5')]};})['value']()};return ejs[_0xd3d6('0xe8')](path[_0xd3d6('0xcf')](config[_0xd3d6('0xcd')],_0xd3d6('0xe9'),_0xd3d6('0xea'),'downloadInteraction.ejs'),{'interaction':_0x13efee})[_0xd3d6('0x2d')](function(_0x3c9b3b){var _0x387903=path[_0xd3d6('0xcf')](_0x27be09,_0xd3d6('0xeb')+_0x2bfeb4['id']+'-'+_0x225733+_0xd3d6('0xec'));var _0x278a83={'path':_0x387903,'channel':_0xd3d6('0xed'),'interactionId':_0x2bfeb4['id']};return pdf[_0xd3d6('0xee')](_0x3c9b3b,_0x278a83);})['then'](function(){return new BPromise(function(_0xa222a3,_0x4d55bd){zipdir(_0x27be09,{'saveTo':_0xa7e82b},function(_0x534600,_0x27306e){if(_0x534600)return _0x4d55bd(_0x534600);return _0xa222a3(_0x27306e);});})[_0xd3d6('0x2d')](function(){return new BPromise(function(_0x424f75,_0x1dd349){rimraf(_0x27be09,function(_0x51a146){if(_0x51a146)_0x1dd349(_0x51a146);return _0x424f75();});});})[_0xd3d6('0x2d')](function(){return _0x581c3f[_0xd3d6('0xcb')](_0xa7e82b,_0x48cdb6,function(_0x23e238){if(_0x23e238){console[_0xd3d6('0xef')]('err',_0x23e238);}else{fs[_0xd3d6('0xf0')](_0xa7e82b);}});});});}else{return _0x581c3f['sendStatus'](0xc8);}})[_0xd3d6('0x38')](handleError(_0x581c3f,null));};
\ No newline at end of file
+var _0xf536=['existsSync','pipe','createWriteStream','System','out','value','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','sendStatus','zip-dir','bluebird','path','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','end','status','json','offset','undefined','limit','count','set','update','then','destroy','error','stack','name','send','map','WhatsappInteraction','rawAttributes','fieldName','type','key','findAll','query','user','catch','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','merge','options','create','body','describe','addMessage','WhatsappMessage','find','omit','ids','getMessages','findOne','hasOwnProperty','nolimit','sort','where','pick','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','rows','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','User','fullname','Contact','firstName','Attachment','Messages','createdAt','direction','secret','read','WhatsappAccount','Account','Owner','mkdirSync','N.A.','closed','closedAt','disposition','basename'];(function(_0x9e97ca,_0x3ad9db){var _0x5d1649=function(_0xcf9dc7){while(--_0xcf9dc7){_0x9e97ca['push'](_0x9e97ca['shift']());}};_0x5d1649(++_0x3ad9db);}(_0xf536,0x106));var _0x6f53=function(_0x565d34,_0x4176da){_0x565d34=_0x565d34-0x0;var _0x3751e7=_0xf536[_0x565d34];return _0x3751e7;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x6f53('0x0'));var moment=require('moment');var BPromise=require(_0x6f53('0x1'));var util=require('util');var path=require(_0x6f53('0x2'));var ejs=require(_0x6f53('0x3'));var fs=require('fs');var _=require(_0x6f53('0x4'));var Redis=require('ioredis');var interaction=require(_0x6f53('0x5'));var qs=require(_0x6f53('0x6'));var pdf=require(_0x6f53('0x7'));var logger=require('../../config/logger')(_0x6f53('0x8'));var config=require('../../config/environment');var db=require(_0x6f53('0x9'))['db'];config[_0x6f53('0xa')]=_[_0x6f53('0xb')](config[_0x6f53('0xa')],{'host':_0x6f53('0xc'),'port':0x18eb});var socket=require(_0x6f53('0xd'))(new Redis(config['redis']));require('./whatsappInteraction.socket')[_0x6f53('0xe')](socket);function respondWithStatusCode(_0x2d11b1,_0x2951d9){_0x2951d9=_0x2951d9||0xcc;return function(_0x2dc75d){if(_0x2dc75d){return _0x2d11b1['sendStatus'](_0x2951d9);}return _0x2d11b1['status'](_0x2951d9)[_0x6f53('0xf')]();};}function respondWithResult(_0x376839,_0x2a64da){_0x2a64da=_0x2a64da||0xc8;return function(_0x2aaa19){if(_0x2aaa19){return _0x376839[_0x6f53('0x10')](_0x2a64da)[_0x6f53('0x11')](_0x2aaa19);}};}function respondWithFilteredResult(_0x575fbc,_0x2e49fa){return function(_0x369ea5){if(_0x369ea5){var _0x957ce6=typeof _0x2e49fa[_0x6f53('0x12')]===_0x6f53('0x13')&&typeof _0x2e49fa[_0x6f53('0x14')]===_0x6f53('0x13');var _0x832520=_0x369ea5[_0x6f53('0x15')];var _0xb71688=_0x957ce6?0x0:_0x2e49fa['offset'];var _0x54b0f4=_0x957ce6?_0x369ea5['count']:_0x2e49fa[_0x6f53('0x12')]+_0x2e49fa['limit'];var _0x556730;if(_0x54b0f4>=_0x832520){_0x54b0f4=_0x832520;_0x556730=0xc8;}else{_0x556730=0xce;}_0x575fbc[_0x6f53('0x10')](_0x556730);return _0x575fbc[_0x6f53('0x16')]('Content-Range',_0xb71688+'-'+_0x54b0f4+'/'+_0x832520)[_0x6f53('0x11')](_0x369ea5);}return null;};}function saveUpdates(_0x5f2ac7){return function(_0x345b94){if(_0x345b94){return _0x345b94[_0x6f53('0x17')](_0x5f2ac7)[_0x6f53('0x18')](function(_0x10bf7b){return _0x10bf7b;});}return null;};}function removeEntity(_0x43d2ab){return function(_0x1f0f4f){if(_0x1f0f4f){return _0x1f0f4f[_0x6f53('0x19')]()[_0x6f53('0x18')](function(){_0x43d2ab[_0x6f53('0x10')](0xcc)[_0x6f53('0xf')]();});}};}function handleEntityNotFound(_0x114e24){return function(_0x5381aa){if(!_0x5381aa){_0x114e24['sendStatus'](0x194);}return _0x5381aa;};}function handleError(_0x43cc6b,_0x34525c){_0x34525c=_0x34525c||0x1f4;return function(_0x496d9a){logger[_0x6f53('0x1a')](_0x496d9a[_0x6f53('0x1b')]);if(_0x496d9a[_0x6f53('0x1c')]){delete _0x496d9a[_0x6f53('0x1c')];}_0x43cc6b['status'](_0x34525c)[_0x6f53('0x1d')](_0x496d9a);};}exports['index']=function(_0x580077,_0x439f68){var _0x41cbd6={};var _0x3e8445=_[_0x6f53('0x1e')](db[_0x6f53('0x1f')][_0x6f53('0x20')],function(_0x253194){return{'name':_0x253194[_0x6f53('0x21')],'type':_0x253194[_0x6f53('0x22')][_0x6f53('0x23')]};});_0x41cbd6=qs['getOptions'](_0x3e8445,_0x580077);return interaction[_0x6f53('0x24')]('whatsapp',_0x580077[_0x6f53('0x25')],_0x580077[_0x6f53('0x26')],_0x41cbd6,_0x3e8445)['then'](respondWithFilteredResult(_0x439f68,_0x41cbd6))[_0x6f53('0x27')](handleError(_0x439f68,null));};exports['show']=function(_0x340209,_0x1f27ba){var _0x3de5ab={'raw':![],'where':{'id':_0x340209[_0x6f53('0x28')]['id']}},_0x134bdd={};_0x134bdd[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x1f')][_0x6f53('0x20')]);_0x134bdd['query']=_[_0x6f53('0x2a')](_0x340209[_0x6f53('0x25')]);_0x134bdd[_0x6f53('0x2b')]=_[_0x6f53('0x2c')](_0x134bdd[_0x6f53('0x29')],_0x134bdd[_0x6f53('0x25')]);_0x3de5ab[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x134bdd['model'],qs[_0x6f53('0x2e')](_0x340209['query'][_0x6f53('0x2e')]));_0x3de5ab[_0x6f53('0x2d')]=_0x3de5ab['attributes'][_0x6f53('0x2f')]?_0x3de5ab[_0x6f53('0x2d')]:_0x134bdd['model'];if(_0x340209['query'][_0x6f53('0x30')]){_0x3de5ab[_0x6f53('0x31')]=[{'all':!![]}];}_0x3de5ab=_[_0x6f53('0x32')]({},_0x3de5ab,_0x340209[_0x6f53('0x33')]);return db['WhatsappInteraction']['find'](_0x3de5ab)[_0x6f53('0x18')](handleEntityNotFound(_0x1f27ba,null))[_0x6f53('0x18')](respondWithResult(_0x1f27ba,null))[_0x6f53('0x27')](handleError(_0x1f27ba,null));};exports['create']=function(_0x143f10,_0x9fdf24){return db['WhatsappInteraction'][_0x6f53('0x34')](_0x143f10[_0x6f53('0x35')],{})[_0x6f53('0x18')](respondWithResult(_0x9fdf24,0xc9))[_0x6f53('0x27')](handleError(_0x9fdf24,null));};exports[_0x6f53('0x17')]=function(_0x3ee064,_0x4edb74){if(_0x3ee064[_0x6f53('0x35')]['id']){delete _0x3ee064[_0x6f53('0x35')]['id'];}return db[_0x6f53('0x1f')]['find']({'where':{'id':_0x3ee064[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x4edb74,null))[_0x6f53('0x18')](saveUpdates(_0x3ee064[_0x6f53('0x35')],null))[_0x6f53('0x18')](respondWithResult(_0x4edb74,null))['catch'](handleError(_0x4edb74,null));};exports[_0x6f53('0x19')]=function(_0x16f855,_0x39479d){return db['WhatsappInteraction']['find']({'where':{'id':_0x16f855[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x39479d,null))[_0x6f53('0x18')](removeEntity(_0x39479d,null))[_0x6f53('0x27')](handleError(_0x39479d,null));};exports[_0x6f53('0x36')]=function(_0x38b37c,_0xdb7a5c){return db[_0x6f53('0x1f')][_0x6f53('0x36')]()[_0x6f53('0x18')](respondWithResult(_0xdb7a5c,null))[_0x6f53('0x27')](handleError(_0xdb7a5c,null));};exports[_0x6f53('0x37')]=function(_0x271838,_0x82585c){return db[_0x6f53('0x38')][_0x6f53('0x39')]({'where':{'id':_0x271838['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x82585c,null))['then'](function(_0x5f4887){if(_0x5f4887){return _0x5f4887[_0x6f53('0x37')](_0x271838['body']['ids'],_[_0x6f53('0x3a')](_0x271838['body'],[_0x6f53('0x3b'),'id'])||{});}})[_0x6f53('0x18')](respondWithResult(_0x82585c,null))[_0x6f53('0x27')](handleError(_0x82585c,null));};exports[_0x6f53('0x3c')]=function(_0x5499a9,_0x526e2c){var _0x14ea14={'raw':![],'where':{}};var _0x190082={};var _0x3193ad={'count':0x0,'rows':[]};return db[_0x6f53('0x1f')][_0x6f53('0x3d')]({'where':{'id':_0x5499a9[_0x6f53('0x28')]['id']}})['then'](handleEntityNotFound(_0x526e2c,null))[_0x6f53('0x18')](function(_0x70ccc0){if(_0x70ccc0){_0x190082[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x38')][_0x6f53('0x20')]);_0x190082[_0x6f53('0x25')]=_['keys'](_0x5499a9[_0x6f53('0x25')]);_0x190082['filters']=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],_0x190082['query']);_0x14ea14[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],qs['fields'](_0x5499a9[_0x6f53('0x25')]['fields']));_0x14ea14[_0x6f53('0x2d')]=_0x14ea14[_0x6f53('0x2d')][_0x6f53('0x2f')]?_0x14ea14[_0x6f53('0x2d')]:_0x190082[_0x6f53('0x29')];if(!_0x5499a9['query'][_0x6f53('0x3e')](_0x6f53('0x3f'))){_0x14ea14[_0x6f53('0x14')]=qs['limit'](_0x5499a9[_0x6f53('0x25')]['limit']);_0x14ea14['offset']=qs['offset'](_0x5499a9['query']['offset']);}_0x14ea14['order']=qs[_0x6f53('0x40')](_0x5499a9[_0x6f53('0x25')]['sort']);_0x14ea14[_0x6f53('0x41')]=qs[_0x6f53('0x2b')](_[_0x6f53('0x42')](_0x5499a9['query'],_0x190082['filters']));_0x14ea14[_0x6f53('0x41')]['WhatsappInteractionId']=_0x70ccc0['id'];if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]){_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],{'$or':_[_0x6f53('0x1e')](_0x14ea14[_0x6f53('0x2d')],function(_0x1a9a4d){var _0x32f2c5={};_0x32f2c5[_0x1a9a4d]={'$like':'%'+_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]+'%'};return _0x32f2c5;})});}if(_0x5499a9[_0x6f53('0x25')]['$gte']){var _0x226746=_0x5499a9['query'][_0x6f53('0x44')][_0x6f53('0x45')](',');var _0x40b1db={};_0x40b1db[_0x226746[0x0]]={'$gte':moment(_0x226746[0x1])[_0x6f53('0x46')](_0x6f53('0x47'))};_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],_0x40b1db);}_0x14ea14=_['merge']({},_0x14ea14,_0x5499a9[_0x6f53('0x33')]);return db[_0x6f53('0x38')][_0x6f53('0x15')]({'where':_0x14ea14[_0x6f53('0x41')]})[_0x6f53('0x18')](function(_0xbabe0f){_0x3193ad[_0x6f53('0x15')]=_0xbabe0f;if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x30')]){_0x14ea14[_0x6f53('0x31')]=[{'all':!![]}];}return db[_0x6f53('0x38')][_0x6f53('0x24')](_0x14ea14);})[_0x6f53('0x18')](function(_0x43b0a6){_0x3193ad[_0x6f53('0x48')]=_0x43b0a6;return _0x3193ad;});}})['then'](respondWithFilteredResult(_0x526e2c,_0x14ea14))['catch'](handleError(_0x526e2c,null));};exports['addTags']=function(_0x1782df,_0x23b697){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x1782df[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x23b697,null))[_0x6f53('0x18')](function(_0x209fb5){if(_0x209fb5){return _0x209fb5[_0x6f53('0x49')](_0x1782df['body']['ids'],_[_0x6f53('0x3a')](_0x1782df[_0x6f53('0x35')],[_0x6f53('0x3b'),'id'])||{})[_0x6f53('0x4a')](function(){return db[_0x6f53('0x4b')]['findAll']({'attributes':['id',_0x6f53('0x1c'),_0x6f53('0x4c')],'where':{'id':_0x1782df[_0x6f53('0x35')][_0x6f53('0x3b')]}});})[_0x6f53('0x18')](function(_0x3d94f0){socket[_0x6f53('0x4d')](_0x6f53('0x4e'),{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]});return{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]};});}})[_0x6f53('0x18')](respondWithResult(_0x23b697,null))[_0x6f53('0x27')](handleError(_0x23b697,null));};exports[_0x6f53('0x4f')]=function(_0x71109b,_0x14f1d2){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x71109b['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x14f1d2,null))['then'](function(_0x31f969){if(_0x31f969){return _0x31f969[_0x6f53('0x4f')](_0x71109b[_0x6f53('0x25')][_0x6f53('0x3b')]);}})['then'](respondWithStatusCode(_0x14f1d2,null))[_0x6f53('0x27')](handleError(_0x14f1d2,null));};exports[_0x6f53('0x50')]=function(_0x490abc,_0x423ab5){var _0x5bd71a=moment()[_0x6f53('0x51')]()[_0x6f53('0x52')]();var _0x27eeaa=path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x57'));var _0x4e086a=path['join'](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x58'));var _0x215834=path[_0x6f53('0x53')](_0x27eeaa,_0x5bd71a);var _0x1a584b=util[_0x6f53('0x46')](_0x6f53('0x59'),_0x490abc[_0x6f53('0x28')]['id'],_0x5bd71a);var _0x5172df=path[_0x6f53('0x53')](_0x27eeaa,_0x1a584b);var _0x33220d=[];_0x33220d[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x5b'),'attributes':['id',_0x6f53('0x5c')],'raw':!![]});_0x33220d[_0x6f53('0x5a')]({'model':db['CmContact'],'as':_0x6f53('0x5d'),'attributes':['id',_0x6f53('0x5e'),'lastName'],'raw':!![]});if(_0x490abc[_0x6f53('0x25')][_0x6f53('0x58')]){_0x33220d['push']({'model':db[_0x6f53('0x5f')],'as':'Attachment','raw':!![]});}var _0x4fbcf6=[{'model':db[_0x6f53('0x38')],'as':_0x6f53('0x60'),'attributes':['id',_0x6f53('0x35'),_0x6f53('0x61'),_0x6f53('0x62'),_0x6f53('0x63'),_0x6f53('0x64')],'include':_0x33220d}];_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x65')],'as':_0x6f53('0x66'),'attributes':['id','name']});_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x67'),'attributes':['id',_0x6f53('0x5c')]});return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x490abc[_0x6f53('0x28')]['id']},'include':_0x4fbcf6})[_0x6f53('0x18')](handleEntityNotFound(_0x423ab5,null))[_0x6f53('0x18')](function(_0x309189){if(_0x309189){var _0x19203e=_0x309189['get']({'plain':!![]});fs[_0x6f53('0x68')](_0x215834);var _0x22f504={'channel':'Whatsapp','account':_0x19203e['Account'][_0x6f53('0x1c')],'agent':_0x19203e['Owner']?_0x19203e[_0x6f53('0x67')][_0x6f53('0x5c')]:_0x6f53('0x69'),'createdAt':moment(_0x19203e['createdAt'])[_0x6f53('0x46')](_0x6f53('0x47'))['toString'](),'closedAt':_0x19203e[_0x6f53('0x6a')]?moment(_0x19203e[_0x6f53('0x6b')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')]():'','disposition':_0x19203e[_0x6f53('0x6c')],'messages':_(_0x19203e[_0x6f53('0x60')])['filter']({'secret':![]})['map'](function(_0x27a1b7){if(_0x27a1b7[_0x6f53('0x5f')]){var _0x5aea7c=path[_0x6f53('0x53')](_0x4e086a,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]);if(fs[_0x6f53('0x6e')](_0x5aea7c)){fs['createReadStream'](_0x5aea7c)[_0x6f53('0x6f')](fs[_0x6f53('0x70')](path[_0x6f53('0x53')](_0x215834,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')])));}}return{'date':moment(_0x27a1b7[_0x6f53('0x61')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')](),'sender':_0x27a1b7[_0x6f53('0x62')]==='out'?_0x27a1b7[_0x6f53('0x5b')]?_0x27a1b7[_0x6f53('0x5b')][_0x6f53('0x5c')]:_0x6f53('0x71'):_0x27a1b7['Contact']['firstName']+(_0x27a1b7[_0x6f53('0x5d')]['lastName']?'\x20'+_0x27a1b7[_0x6f53('0x5d')]['lastName']:''),'body':_0x27a1b7[_0x6f53('0x5f')]?_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]:_0x27a1b7['body'],'direction':_0x27a1b7[_0x6f53('0x62')]===_0x6f53('0x72')?'A':'C','secret':_0x27a1b7[_0x6f53('0x63')],'read':_0x27a1b7[_0x6f53('0x64')],'attachment':_0x27a1b7[_0x6f53('0x5f')]};})[_0x6f53('0x73')]()};return ejs[_0x6f53('0x74')](path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x75'),_0x6f53('0x76')),{'interaction':_0x22f504})[_0x6f53('0x18')](function(_0x5df115){var _0x5163b9=path[_0x6f53('0x53')](_0x215834,_0x6f53('0x77')+_0x19203e['id']+'-'+_0x5bd71a+_0x6f53('0x78'));var _0x23b8d1={'path':_0x5163b9,'channel':'Whatsapp','interactionId':_0x19203e['id']};return pdf[_0x6f53('0x79')](_0x5df115,_0x23b8d1);})[_0x6f53('0x18')](function(){return new BPromise(function(_0x33ac95,_0x1ee07b){zipdir(_0x215834,{'saveTo':_0x5172df},function(_0x127fc1,_0x18f50e){if(_0x127fc1)return _0x1ee07b(_0x127fc1);return _0x33ac95(_0x18f50e);});})[_0x6f53('0x18')](function(){return new BPromise(function(_0x5774ef,_0x1ce885){rimraf(_0x215834,function(_0x515a4c){if(_0x515a4c)_0x1ce885(_0x515a4c);return _0x5774ef();});});})['then'](function(){return _0x423ab5[_0x6f53('0x50')](_0x5172df,_0x1a584b,function(_0x808474){if(_0x808474){console['log'](_0x6f53('0x7a'),_0x808474);}else{fs['unlinkSync'](_0x5172df);}});});});}else{return _0x423ab5[_0x6f53('0x7b')](0xc8);}})[_0x6f53('0x27')](handleError(_0x423ab5,null));};
\ No newline at end of file