Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 1ec91e1..7a84eaa 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1f13=['isNumeric','i.id\x20LIKE\x20?','i.phone\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','i.id','Sequelize','QueryTypes','clone','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','contactName','DESC','t.id\x20IN\x20?','resolve','user','role','agent','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','toString','sequelize','keyBy','merge','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','c.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','ui.WhatsappInteractionId\x20IN\x20?','groupBy','WhatsappInteractionId','all','rows','show','params','rawAttributes','includeAll','options','catch','create','destroy','describe','addMessage','WhatsappMessage','getMessages','findOne','hasOwnProperty','pick','include','addTags','ids','omit','spread','findAll','emit','whatsappInteractionTags:save','removeTags','join','server','files','tmp','root','attachments','format','firstName','lastName','Attachment','direction','secret','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','closedAt','Messages','basename','existsSync','createReadStream','pipe','createWriteStream','out','System','renderFile','views','downloadInteraction.html','transcript-','.pdf','createPdfFromHTML','download','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','end','status','json','count','offset','limit','set','reject','update','then','error','stack','name','send','Users','fullname','TagIds','Tags','split','forEach','push','map','WhatsappInteraction','fieldName','key','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort','field','color','from','tools_tags','select','u.id','ui.WhatsappInteractionId','left_join','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','expr','search','parseSearch','conditions','value','`\x20=\x200','having','`\x20>\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','find','ContactId','text','start','Tag','User','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','type','body','keys','some','compact','isEmpty','WhatsappAccountId','where','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','parse','$gte','$lte','\x20IS\x20NULL','read','`unreadMessages`\x20=\x200','tag','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace'];(function(_0x5b30ff,_0x5303eb){var _0x40b976=function(_0x24199c){while(--_0x24199c){_0x5b30ff['push'](_0x5b30ff['shift']());}};_0x40b976(++_0x5303eb);}(_0x1f13,0x70));var _0x31f1=function(_0x51cee2,_0x25a976){_0x51cee2=_0x51cee2-0x0;var _0x12cb54=_0x1f13[_0x51cee2];return _0x12cb54;};'use strict';var emlformat=require(_0x31f1('0x0'));var rimraf=require(_0x31f1('0x1'));var zipdir=require(_0x31f1('0x2'));var jsonpatch=require(_0x31f1('0x3'));var rp=require(_0x31f1('0x4'));var moment=require(_0x31f1('0x5'));var BPromise=require(_0x31f1('0x6'));var Mustache=require(_0x31f1('0x7'));var util=require(_0x31f1('0x8'));var path=require(_0x31f1('0x9'));var sox=require(_0x31f1('0xa'));var csv=require(_0x31f1('0xb'));var ejs=require(_0x31f1('0xc'));var fs=require('fs');var fs_extra=require(_0x31f1('0xd'));var _=require('lodash');var squel=require(_0x31f1('0xe'));var crypto=require(_0x31f1('0xf'));var jsforce=require(_0x31f1('0x10'));var deskjs=require(_0x31f1('0x11'));var toCsv=require(_0x31f1('0xb'));var querystring=require(_0x31f1('0x12'));var Papa=require('papaparse');var Redis=require(_0x31f1('0x13'));var authService=require(_0x31f1('0x14'));var qs=require(_0x31f1('0x15'));var as=require(_0x31f1('0x16'));var pdf=require('../../components/export/pdf');var hardwareService=require(_0x31f1('0x17'));var logger=require(_0x31f1('0x18'))(_0x31f1('0x19'));var utils=require('../../config/utils');var config=require(_0x31f1('0x1a'));var licenseUtil=require(_0x31f1('0x1b'));var db=require(_0x31f1('0x1c'))['db'];config[_0x31f1('0x1d')]=_[_0x31f1('0x1e')](config[_0x31f1('0x1d')],{'host':_0x31f1('0x1f'),'port':0x18eb});var socket=require(_0x31f1('0x20'))(new Redis(config['redis']));require('./whatsappInteraction.socket')[_0x31f1('0x21')](socket);function respondWithStatusCode(_0x4aef29,_0x3a53fe){_0x3a53fe=_0x3a53fe||0xcc;return function(_0x59ba94){if(_0x59ba94){return _0x4aef29[_0x31f1('0x22')](_0x3a53fe);}return _0x4aef29['status'](_0x3a53fe)[_0x31f1('0x23')]();};}function respondWithResult(_0x16fb84,_0x482c26){_0x482c26=_0x482c26||0xc8;return function(_0x4853d8){if(_0x4853d8){return _0x16fb84[_0x31f1('0x24')](_0x482c26)[_0x31f1('0x25')](_0x4853d8);}};}function respondWithFilteredResult(_0xb5dba2,_0x4a8180){return function(_0xbd4a19){if(_0xbd4a19){var _0x5e536c=_0xbd4a19[_0x31f1('0x26')],_0x440bb3=_0x4a8180[_0x31f1('0x27')],_0x32ed53=_0x4a8180[_0x31f1('0x27')]+_0x4a8180[_0x31f1('0x28')],_0x7a3a73;if(_0x32ed53>=_0x5e536c){_0x32ed53=_0x5e536c;_0x7a3a73=0xc8;}else{_0x7a3a73=0xce;}_0xb5dba2[_0x31f1('0x24')](_0x7a3a73);return _0xb5dba2[_0x31f1('0x29')]('Content-Range',_0x440bb3+'-'+_0x32ed53+'/'+_0x5e536c)[_0x31f1('0x25')](_0xbd4a19);}return null;};}function patchUpdates(_0x1d78e0){return function(_0x375e6f){try{jsonpatch['apply'](_0x375e6f,_0x1d78e0,!![]);}catch(_0x258584){return BPromise[_0x31f1('0x2a')](_0x258584);}return _0x375e6f['save']();};}function saveUpdates(_0x9ea9f2,_0x16662d){return function(_0x2f8e31){if(_0x2f8e31){return _0x2f8e31[_0x31f1('0x2b')](_0x9ea9f2)[_0x31f1('0x2c')](function(_0x5ac727){return _0x5ac727;});}return null;};}function removeEntity(_0x19a362,_0x175a47){return function(_0x76935a){if(_0x76935a){return _0x76935a['destroy']()[_0x31f1('0x2c')](function(){_0x19a362['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xcafa5d,_0x40f5ab){return function(_0x308198){if(!_0x308198){_0xcafa5d['sendStatus'](0x194);}return _0x308198;};}function handleError(_0x287965,_0x4020ae){_0x4020ae=_0x4020ae||0x1f4;return function(_0x511986){logger[_0x31f1('0x2d')](_0x511986[_0x31f1('0x2e')]);if(_0x511986['name']){delete _0x511986[_0x31f1('0x2f')];}_0x287965[_0x31f1('0x24')](_0x4020ae)[_0x31f1('0x30')](_0x511986);};}function getInteractionUsers(_0x24e15d,_0x3b67f8){return new BPromise(function(_0x3c127e,_0x33816f){try{if(_0x3b67f8[_0x24e15d['id']]){_0x24e15d[_0x31f1('0x31')]=_['map'](_0x3b67f8[_0x24e15d['id']],function(_0x554e24){return{'id':_0x554e24['id'],'fullname':_0x554e24[_0x31f1('0x32')]};});}}catch(_0x253a58){_0x33816f(_0x253a58);}_0x3c127e(_0x24e15d);});}function getInteractionTags(_0x2de8c2,_0x3574ce){return new BPromise(function(_0x2ee559,_0x3c7168){try{if(_0x2de8c2[_0x31f1('0x33')]){_0x2de8c2[_0x31f1('0x34')]=[];_0x2de8c2[_0x31f1('0x33')][_0x31f1('0x35')](',')[_0x31f1('0x36')](function(_0x3409c9){_0x2de8c2[_0x31f1('0x34')][_0x31f1('0x37')](_0x3574ce[_0x3409c9]);});}delete _0x2de8c2['TagIds'];}catch(_0xd054d9){_0x3c7168(_0xd054d9);}_0x2ee559(_0x2de8c2);});}function updateWhatsappInteraction(_0x5d8cd9,_0x210777,_0x57fd76){return new BPromise(function(_0x399c9b,_0xf0b25a){return getInteractionUsers(_0x5d8cd9,_0x57fd76)['then'](function(_0x162a29){return getInteractionTags(_0x162a29,_0x210777);})['then'](function(_0x15e721){_0x399c9b(_0x15e721);})['catch'](function(_0x2502b0){_0xf0b25a(_0x2502b0);});});}exports['index']=function(_0x3ac074,_0x53cd37){var _0x12f71f={},_0x1bd2bb={},_0x325857={'count':0x0,'rows':[]};var _0x55a59a=_[_0x31f1('0x38')](db[_0x31f1('0x39')]['rawAttributes'],function(_0x24b857){return{'name':_0x24b857[_0x31f1('0x3a')],'type':_0x24b857['type'][_0x31f1('0x3b')]};});_0x1bd2bb[_0x31f1('0x3c')]=_[_0x31f1('0x38')](_0x55a59a,_0x31f1('0x2f'));_0x1bd2bb[_0x31f1('0x3d')]=_['keys'](_0x3ac074[_0x31f1('0x3d')]);_0x1bd2bb[_0x31f1('0x3e')]=_[_0x31f1('0x3f')](_0x1bd2bb[_0x31f1('0x3c')],_0x1bd2bb['query']);_0x12f71f[_0x31f1('0x40')]=_[_0x31f1('0x3f')](_0x1bd2bb[_0x31f1('0x3c')],qs[_0x31f1('0x41')](_0x3ac074[_0x31f1('0x3d')]['fields']));_0x12f71f[_0x31f1('0x40')]=_0x12f71f[_0x31f1('0x40')][_0x31f1('0x42')]?_0x12f71f[_0x31f1('0x40')]:_0x1bd2bb[_0x31f1('0x3c')];if(!_0x3ac074[_0x31f1('0x3d')]['hasOwnProperty'](_0x31f1('0x43'))){_0x12f71f['limit']=qs[_0x31f1('0x28')](_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x28')]);_0x12f71f[_0x31f1('0x27')]=qs[_0x31f1('0x27')](_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x27')]);}_0x12f71f[_0x31f1('0x44')]=qs[_0x31f1('0x45')](_0x3ac074['query'][_0x31f1('0x45')]);_0x12f71f['where']=qs[_0x31f1('0x3e')](_['pick'](_0x3ac074['query'],_0x1bd2bb['filters']),_0x55a59a);var _0x57194a=[];var _0x7bd528=squel['select']()['field']('id')[_0x31f1('0x46')](_0x31f1('0x2f'))[_0x31f1('0x46')](_0x31f1('0x47'))[_0x31f1('0x48')](_0x31f1('0x49'));var _0x53fc4e=squel[_0x31f1('0x4a')]()[_0x31f1('0x46')](_0x31f1('0x4b'))['field']('u.fullname')[_0x31f1('0x46')](_0x31f1('0x4c'))[_0x31f1('0x48')]('user_has_whatsapp_interactions','ui')[_0x31f1('0x4d')](_0x31f1('0x4e'),'u',_0x31f1('0x4f'));var _0x39f9ac=squel['select']()[_0x31f1('0x48')](_0x31f1('0x50'),'i')[_0x31f1('0x4d')](_0x31f1('0x51'),'c',_0x31f1('0x52'))[_0x31f1('0x4d')](_0x31f1('0x4e'),'o',_0x31f1('0x53'))['left_join'](_0x31f1('0x54'),'a',_0x31f1('0x55'))[_0x31f1('0x4d')](_0x31f1('0x56'),'me',_0x31f1('0x57'))[_0x31f1('0x4d')](_0x31f1('0x58'),'it',_0x31f1('0x59'))[_0x31f1('0x4d')](_0x31f1('0x49'),'t','t.id\x20=\x20it.TagId');var _0x136bd0=squel[_0x31f1('0x5a')]();var _0x2d1a43=[];var _0x14fc8d=squel['expr']();var _0x327050;if(_0x3ac074['query'][_0x31f1('0x5b')]){_0x327050=as[_0x31f1('0x5c')](_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x5b')]);var _0xedb3c=_0x327050['sqlOperator'];for(var _0x37c3dc=0x0;_0x37c3dc<_0x327050[_0x31f1('0x5d')][_0x31f1('0x42')];_0x37c3dc++){var _0x617245=_0x327050[_0x31f1('0x5d')][_0x37c3dc];var _0x45b919='i';var _0x2fe619=_['find'](_0x55a59a,[_0x31f1('0x2f'),_0x617245['field']]);if(!_0x2fe619){switch(_0x617245[_0x31f1('0x46')]){case'unreadMessages':if(_0x617245[_0x31f1('0x5e')]==0x1){_0x39f9ac['having']('`'+_0x617245[_0x31f1('0x46')]+_0x31f1('0x5f'));}else{_0x39f9ac[_0x31f1('0x60')]('`'+_0x617245[_0x31f1('0x46')]+_0x31f1('0x61'));}break;case _0x31f1('0x62'):if(_0x617245[_0x31f1('0x63')]===_0x31f1('0x64')){if(_0x617245[_0x31f1('0x5e')][_0x31f1('0x35')]('\x20')[_0x31f1('0x42')]>0x1){_0x136bd0[_0xedb3c](_0x31f1('0x65'),qs['getFullTextValue'](_0x617245['value']),null);}else{var _0x23cca0='%'+_0x617245[_0x31f1('0x5e')]+'%';_0x136bd0[_0xedb3c](_0x31f1('0x66'),_0x23cca0,_0x23cca0,_0x23cca0);}}else{_0x2fe619=_[_0x31f1('0x67')](_0x55a59a,[_0x31f1('0x2f'),_0x31f1('0x68')]);_0x617245[_0x31f1('0x46')]='ContactId';_0x118b7f=as['buildExpression'](_0x45b919,_0x2fe619['type'],_0x617245);_0x136bd0[_0xedb3c](_0x118b7f[_0x31f1('0x69')],_0x118b7f['value'][_0x31f1('0x6a')],_0x118b7f[_0x31f1('0x5e')][_0x31f1('0x23')]);}break;case _0x31f1('0x6b'):var _0x370b70=_0x617245[_0x31f1('0x5e')]['split'](',')[_0x31f1('0x38')](function(_0x2bd01e){return Number(_0x2bd01e);});_0x370b70[_0x31f1('0x36')](function(_0x4538df){_0x14fc8d['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x4538df+',%');});_0x2d1a43=_['union'](_0x2d1a43,_0x370b70);break;case _0x31f1('0x6c'):if(_0x617245[_0x31f1('0x63')]==='$substring'){_0x136bd0[_0xedb3c](_0x31f1('0x6d'),'%'+_0x617245[_0x31f1('0x5e')]+'%',null);}else{_0x2fe619=_[_0x31f1('0x67')](_0x55a59a,[_0x31f1('0x2f'),_0x31f1('0x6e')]);_0x617245[_0x31f1('0x46')]=_0x31f1('0x6e');_0x118b7f=as[_0x31f1('0x6f')](_0x45b919,_0x2fe619[_0x31f1('0x70')],_0x617245);_0x136bd0[_0xedb3c](_0x118b7f['text'],_0x118b7f[_0x31f1('0x5e')][_0x31f1('0x6a')],_0x118b7f[_0x31f1('0x5e')][_0x31f1('0x23')]);}break;case _0x31f1('0x71'):_0x118b7f=as[_0x31f1('0x6f')]('me',null,_0x617245);_0x136bd0[_0xedb3c](_0x118b7f[_0x31f1('0x69')],_0x118b7f['value'][_0x31f1('0x6a')],_0x118b7f[_0x31f1('0x5e')][_0x31f1('0x23')]);break;}}else{var _0x118b7f=as[_0x31f1('0x6f')](_0x45b919,_0x2fe619[_0x31f1('0x70')],_0x617245);_0x136bd0[_0xedb3c](_0x118b7f[_0x31f1('0x69')],_0x118b7f['value']['start'],_0x118b7f['value'][_0x31f1('0x23')]);}}}else{var _0x3852b1=_(_0x3ac074['query'])[_0x31f1('0x72')]()[_0x31f1('0x38')](function(_0x17db64){return _[_0x31f1('0x73')](_0x55a59a,[_0x31f1('0x2f'),_0x17db64])?_0x17db64:undefined;})[_0x31f1('0x74')]()[_0x31f1('0x5e')]();if(!_[_0x31f1('0x75')](_0x3852b1)){_0x3852b1[_0x31f1('0x36')](function(_0x111556){if(_0x111556===_0x31f1('0x76')){_0x39f9ac[_0x31f1('0x77')](_0x31f1('0x78'),[][_0x31f1('0x79')](_0x3ac074[_0x31f1('0x3d')][_0x111556]));}else if(_0x111556===_0x31f1('0x7a')){var _0x595652=JSON[_0x31f1('0x7b')](_0x3ac074['query'][_0x111556])[_0x31f1('0x7c')];var _0x4e6669=JSON['parse'](_0x3ac074[_0x31f1('0x3d')][_0x111556])[_0x31f1('0x7d')];_0x39f9ac[_0x31f1('0x77')]('i.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x595652,_0x4e6669);}else{if(_0x3ac074[_0x31f1('0x3d')][_0x111556]==='null'){_0x39f9ac[_0x31f1('0x77')]('i.'+_0x111556+_0x31f1('0x7e'));}else{_0x39f9ac[_0x31f1('0x77')]('i.'+_0x111556+'\x20=\x20?',_0x3ac074[_0x31f1('0x3d')][_0x111556]);}}});}if(_0x3ac074[_0x31f1('0x3d')]['read']){if(_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x7f')]==0x1){_0x39f9ac[_0x31f1('0x60')](_0x31f1('0x80'));}else{_0x39f9ac['having']('`unreadMessages`\x20>\x200');}}if(_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x81')]){_0x2d1a43=_['isArray'](_0x3ac074[_0x31f1('0x3d')]['tag'])?_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x81')]:new Array(_0x3ac074['query'][_0x31f1('0x81')]);_0x2d1a43[_0x31f1('0x36')](function(_0x4aa393){_0x14fc8d['or'](_0x31f1('0x82'),'%,'+_0x4aa393+',%');});}if(_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x83')]){var _0x6bbe3a=_0x3ac074['query'][_0x31f1('0x83')][_0x31f1('0x84')]('\x5c','\x5c\x5c')[_0x31f1('0x84')](/'/g,'\x27\x27');if(qs[_0x31f1('0x85')](_0x6bbe3a)){_0x136bd0['or'](_0x31f1('0x86'),_0x6bbe3a+'%')['or'](_0x31f1('0x87'),_0x6bbe3a+'%');}else{_0x136bd0['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x6bbe3a))['or'](_0x31f1('0x88'),_0x6bbe3a+'%');}}}_0x39f9ac[_0x31f1('0x77')](_0x136bd0);_0x39f9ac[_0x31f1('0x89')](_0x31f1('0x8a'));var _0x18a907={'type':db[_0x31f1('0x8b')][_0x31f1('0x8c')]['SELECT'],'raw':!![]};var _0x42f4a4=_0x39f9ac[_0x31f1('0x8d')]();_0x42f4a4[_0x31f1('0x46')](_0x31f1('0x8a'));_0x42f4a4[_0x31f1('0x46')](_0x31f1('0x8e'),_0x31f1('0x8f'));if(_0x12f71f['order']){_0x12f71f['order'][_0x31f1('0x36')](function(_0xf56691){var _0x4606ba=_0xf56691[0x0]===_0x31f1('0x90')?_0xf56691[0x0]:'i.'+_0xf56691[0x0];_0x39f9ac[_0x31f1('0x44')](_0x4606ba,_0xf56691[0x1]===_0x31f1('0x91')?![]:!![]);});}if(!_['isEmpty'](_0x2d1a43)){_0x39f9ac[_0x31f1('0x60')](_0x14fc8d);_0x42f4a4[_0x31f1('0x77')](_0x31f1('0x92'),_0x2d1a43);}BPromise[_0x31f1('0x93')]()[_0x31f1('0x2c')](function(){if(!_0x327050){if(_0x3ac074['query'][_0x31f1('0x76')])return;_0x42f4a4[_0x31f1('0x77')]('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');_0x39f9ac['where']('i.WhatsappAccountId\x20IS\x20NOT\x20NULL');return;}if(_0x3ac074[_0x31f1('0x94')][_0x31f1('0x95')]!==_0x31f1('0x96'))return;return _0x3ac074[_0x31f1('0x94')][_0x31f1('0x97')]({'attributes':['id'],'raw':!![]})['then'](function(_0x545d7b){if(_[_0x31f1('0x75')](_0x545d7b)){_0x42f4a4[_0x31f1('0x77')](_0x31f1('0x98'));_0x39f9ac[_0x31f1('0x77')](_0x31f1('0x98'));}else{_0x42f4a4[_0x31f1('0x77')]('i.WhatsappAccountId\x20IN\x20?',_[_0x31f1('0x38')](_0x545d7b,'id'));_0x39f9ac[_0x31f1('0x77')](_0x31f1('0x78'),_[_0x31f1('0x38')](_0x545d7b,'id'));}});})[_0x31f1('0x2c')](function(){if(_0x3ac074['user'][_0x31f1('0x95')]===_0x31f1('0x96')&&!_0x327050&&!_0x3ac074[_0x31f1('0x3d')]['WhatsappAccountId'])return[];return db['sequelize'][_0x31f1('0x3d')](_0x42f4a4[_0x31f1('0x99')](),_0x18a907);})[_0x31f1('0x2c')](function(_0x41ca8f){_0x325857[_0x31f1('0x26')]=_0x41ca8f['length'];if(_0x325857[_0x31f1('0x26')]===0x0)return[];return db[_0x31f1('0x9a')][_0x31f1('0x3d')](_0x7bd528[_0x31f1('0x99')](),_0x18a907)[_0x31f1('0x2c')](function(_0x3e531f){_0x57194a=_[_0x31f1('0x9b')](_0x3e531f,'id');_0x18a907=_[_0x31f1('0x9c')](_0x18a907,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x3ac074[_0x31f1('0x3d')][_0x31f1('0x41')]){_0x12f71f[_0x31f1('0x40')][_0x31f1('0x36')](function(_0x473135){_0x39f9ac['field']('i.'+_0x473135);});}else{_0x39f9ac[_0x31f1('0x46')](_0x31f1('0x8e'),_0x31f1('0x8f'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0x9d'),_0x31f1('0x9e'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0x9f'),_0x31f1('0xa0'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa1'),_0x31f1('0x90'));_0x39f9ac['field']('i.*');_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa2'),'Contact.firstName');_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa3'),_0x31f1('0xa4'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa5'),_0x31f1('0xa6'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa7'),_0x31f1('0xa8'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xa9'),_0x31f1('0xaa'));_0x39f9ac['field'](_0x31f1('0xab'),_0x31f1('0xac'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xad'),_0x31f1('0xae'));_0x39f9ac[_0x31f1('0x46')](_0x31f1('0xaf'),_0x31f1('0xb0'));_0x39f9ac[_0x31f1('0x46')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x31f1('0x33'));}if(_0x12f71f[_0x31f1('0x28')])_0x39f9ac[_0x31f1('0x28')](_0x12f71f[_0x31f1('0x28')]);if(_0x12f71f[_0x31f1('0x27')])_0x39f9ac[_0x31f1('0x27')](_0x12f71f['offset']);return db['sequelize'][_0x31f1('0x3d')](_0x39f9ac[_0x31f1('0x99')](),_0x18a907);})[_0x31f1('0x2c')](function(_0x342d8f){_0x53fc4e[_0x31f1('0x77')](_0x31f1('0xb1'),_[_0x31f1('0x38')](_0x342d8f,'id'));return db[_0x31f1('0x9a')][_0x31f1('0x3d')](_0x53fc4e[_0x31f1('0x99')](),_0x18a907)['then'](function(_0x53214d){var _0x10b4c1=_[_0x31f1('0xb2')](_0x53214d,_0x31f1('0xb3'));var _0x2d863d=[];_0x342d8f[_0x31f1('0x36')](function(_0xe2379a){_0x2d863d[_0x31f1('0x37')](updateWhatsappInteraction(_0xe2379a,_0x57194a,_0x10b4c1));});return BPromise[_0x31f1('0xb4')](_0x2d863d);});});})[_0x31f1('0x2c')](function(_0x45dce7){_0x325857[_0x31f1('0xb5')]=_0x45dce7;return _0x325857;})[_0x31f1('0x2c')](respondWithFilteredResult(_0x53cd37,_0x12f71f))['catch'](handleError(_0x53cd37,null));};exports[_0x31f1('0xb6')]=function(_0x5d3d91,_0x92c4b8){var _0x105959={'raw':![],'where':{'id':_0x5d3d91[_0x31f1('0xb7')]['id']}},_0x5dd7f4={};_0x5dd7f4[_0x31f1('0x3c')]=_[_0x31f1('0x72')](db['WhatsappInteraction'][_0x31f1('0xb8')]);_0x5dd7f4[_0x31f1('0x3d')]=_[_0x31f1('0x72')](_0x5d3d91[_0x31f1('0x3d')]);_0x5dd7f4[_0x31f1('0x3e')]=_[_0x31f1('0x3f')](_0x5dd7f4[_0x31f1('0x3c')],_0x5dd7f4['query']);_0x105959[_0x31f1('0x40')]=_[_0x31f1('0x3f')](_0x5dd7f4[_0x31f1('0x3c')],qs[_0x31f1('0x41')](_0x5d3d91[_0x31f1('0x3d')][_0x31f1('0x41')]));_0x105959[_0x31f1('0x40')]=_0x105959[_0x31f1('0x40')][_0x31f1('0x42')]?_0x105959[_0x31f1('0x40')]:_0x5dd7f4['model'];if(_0x5d3d91['query'][_0x31f1('0xb9')]){_0x105959['include']=[{'all':!![]}];}_0x105959=_[_0x31f1('0x9c')]({},_0x105959,_0x5d3d91[_0x31f1('0xba')]);return db[_0x31f1('0x39')][_0x31f1('0x67')](_0x105959)['then'](handleEntityNotFound(_0x92c4b8,null))['then'](respondWithResult(_0x92c4b8,null))[_0x31f1('0xbb')](handleError(_0x92c4b8,null));};exports[_0x31f1('0xbc')]=function(_0x4ab9cc,_0x4511bb){return db[_0x31f1('0x39')][_0x31f1('0xbc')](_0x4ab9cc[_0x31f1('0x71')],{})['then'](respondWithResult(_0x4511bb,0xc9))[_0x31f1('0xbb')](handleError(_0x4511bb,null));};exports[_0x31f1('0x2b')]=function(_0x433319,_0x26085c){if(_0x433319[_0x31f1('0x71')]['id']){delete _0x433319[_0x31f1('0x71')]['id'];}return db[_0x31f1('0x39')]['find']({'where':{'id':_0x433319[_0x31f1('0xb7')]['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0x26085c,null))[_0x31f1('0x2c')](saveUpdates(_0x433319[_0x31f1('0x71')],null))[_0x31f1('0x2c')](respondWithResult(_0x26085c,null))[_0x31f1('0xbb')](handleError(_0x26085c,null));};exports[_0x31f1('0xbd')]=function(_0x3289c3,_0x9cac93){return db[_0x31f1('0x39')][_0x31f1('0x67')]({'where':{'id':_0x3289c3['params']['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0x9cac93,null))[_0x31f1('0x2c')](removeEntity(_0x9cac93,null))[_0x31f1('0xbb')](handleError(_0x9cac93,null));};exports['describe']=function(_0x28635d,_0x3d835c){return db['WhatsappInteraction'][_0x31f1('0xbe')]()[_0x31f1('0x2c')](respondWithResult(_0x3d835c,null))[_0x31f1('0xbb')](handleError(_0x3d835c,null));};exports[_0x31f1('0xbf')]=function(_0x50967d,_0xd0633b,_0x1d22f2){return db[_0x31f1('0xc0')][_0x31f1('0x67')]({'where':{'id':_0x50967d['params']['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0xd0633b,null))['then'](function(_0x26fa3a){if(_0x26fa3a){return _0x26fa3a[_0x31f1('0xbf')](_0x50967d[_0x31f1('0x71')]['ids'],_['omit'](_0x50967d[_0x31f1('0x71')],['ids','id'])||{});}})[_0x31f1('0x2c')](respondWithResult(_0xd0633b,null))[_0x31f1('0xbb')](handleError(_0xd0633b,null));};exports[_0x31f1('0xc1')]=function(_0x36a0d4,_0x27f158,_0x5b80d5){var _0x5bd95f={'raw':![],'where':{}};var _0x1f16fe={};var _0x34e25d={'count':0x0,'rows':[]};return db[_0x31f1('0x39')][_0x31f1('0xc2')]({'where':{'id':_0x36a0d4['params']['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0x27f158,null))[_0x31f1('0x2c')](function(_0x53840e){if(_0x53840e){_0x1f16fe['model']=_['keys'](db[_0x31f1('0xc0')][_0x31f1('0xb8')]);_0x1f16fe[_0x31f1('0x3d')]=_[_0x31f1('0x72')](_0x36a0d4['query']);_0x1f16fe['filters']=_[_0x31f1('0x3f')](_0x1f16fe[_0x31f1('0x3c')],_0x1f16fe[_0x31f1('0x3d')]);_0x5bd95f[_0x31f1('0x40')]=_[_0x31f1('0x3f')](_0x1f16fe[_0x31f1('0x3c')],qs[_0x31f1('0x41')](_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x41')]));_0x5bd95f['attributes']=_0x5bd95f[_0x31f1('0x40')][_0x31f1('0x42')]?_0x5bd95f[_0x31f1('0x40')]:_0x1f16fe['model'];if(!_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0xc3')]('nolimit')){_0x5bd95f[_0x31f1('0x28')]=qs['limit'](_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x28')]);_0x5bd95f[_0x31f1('0x27')]=qs[_0x31f1('0x27')](_0x36a0d4[_0x31f1('0x3d')]['offset']);}_0x5bd95f[_0x31f1('0x44')]=qs[_0x31f1('0x45')](_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x45')]);_0x5bd95f[_0x31f1('0x77')]=qs[_0x31f1('0x3e')](_[_0x31f1('0xc4')](_0x36a0d4[_0x31f1('0x3d')],_0x1f16fe[_0x31f1('0x3e')]));_0x5bd95f[_0x31f1('0x77')][_0x31f1('0xb3')]=_0x53840e['id'];if(_0x36a0d4[_0x31f1('0x3d')]['filter']){_0x5bd95f[_0x31f1('0x77')]=_['merge'](_0x5bd95f['where'],{'$or':_[_0x31f1('0x38')](_0x5bd95f[_0x31f1('0x40')],function(_0x459a26){var _0x3355a7={};_0x3355a7[_0x459a26]={'$like':'%'+_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x83')]+'%'};return _0x3355a7;})});}if(_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x7c')]){var _0x5c4f26=_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0x7c')][_0x31f1('0x35')](',');var _0x1a989e={};_0x1a989e[_0x5c4f26[0x0]]={'$gte':moment(_0x5c4f26[0x1])['format']('YYYY-MM-DD\x20HH:mm:ss')};_0x5bd95f[_0x31f1('0x77')]=_['merge'](_0x5bd95f[_0x31f1('0x77')],_0x1a989e);}_0x5bd95f=_['merge']({},_0x5bd95f,_0x36a0d4[_0x31f1('0xba')]);return db['WhatsappMessage'][_0x31f1('0x26')]({'where':_0x5bd95f[_0x31f1('0x77')]})['then'](function(_0x4468e8){_0x34e25d[_0x31f1('0x26')]=_0x4468e8;if(_0x36a0d4[_0x31f1('0x3d')][_0x31f1('0xb9')]){_0x5bd95f[_0x31f1('0xc5')]=[{'all':!![]}];}return db[_0x31f1('0xc0')]['findAll'](_0x5bd95f);})[_0x31f1('0x2c')](function(_0xa61b8){_0x34e25d[_0x31f1('0xb5')]=_0xa61b8;return _0x34e25d;});}})[_0x31f1('0x2c')](respondWithFilteredResult(_0x27f158,_0x5bd95f))[_0x31f1('0xbb')](handleError(_0x27f158,null));};exports[_0x31f1('0xc6')]=function(_0x5b51b3,_0x1a5449,_0xc07a8a){return db[_0x31f1('0x39')][_0x31f1('0x67')]({'where':{'id':_0x5b51b3['params']['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0x1a5449,null))[_0x31f1('0x2c')](function(_0x323ba2){if(_0x323ba2){return _0x323ba2['setTags'](_0x5b51b3[_0x31f1('0x71')][_0x31f1('0xc7')],_[_0x31f1('0xc8')](_0x5b51b3[_0x31f1('0x71')],[_0x31f1('0xc7'),'id'])||{})[_0x31f1('0xc9')](function(){return db[_0x31f1('0x6b')][_0x31f1('0xca')]({'attributes':['id','name','color'],'where':{'id':_0x5b51b3[_0x31f1('0x71')][_0x31f1('0xc7')]}});})[_0x31f1('0x2c')](function(_0x322386){socket[_0x31f1('0xcb')](_0x31f1('0xcc'),{'id':Number(_0x5b51b3[_0x31f1('0xb7')]['id']),'tags':_0x322386||[]});return{'id':Number(_0x5b51b3['params']['id']),'tags':_0x322386||[]};});}})['then'](respondWithResult(_0x1a5449,null))[_0x31f1('0xbb')](handleError(_0x1a5449,null));};exports[_0x31f1('0xcd')]=function(_0x5e4587,_0x12304c,_0x25d397){return db[_0x31f1('0x39')][_0x31f1('0x67')]({'where':{'id':_0x5e4587[_0x31f1('0xb7')]['id']}})[_0x31f1('0x2c')](handleEntityNotFound(_0x12304c,null))[_0x31f1('0x2c')](function(_0x5408b7){if(_0x5408b7){return _0x5408b7[_0x31f1('0xcd')](_0x5e4587[_0x31f1('0x3d')]['ids']);}})[_0x31f1('0x2c')](respondWithStatusCode(_0x12304c,null))[_0x31f1('0xbb')](handleError(_0x12304c,null));};exports['download']=function(_0x70c3ab,_0x4fec7f){var _0x1599b8=moment()['unix']()[_0x31f1('0x99')]();var _0x588634=path[_0x31f1('0xce')](config['root'],_0x31f1('0xcf'),_0x31f1('0xd0'),_0x31f1('0xd1'));var _0x476e94=path[_0x31f1('0xce')](config[_0x31f1('0xd2')],_0x31f1('0xcf'),_0x31f1('0xd0'),_0x31f1('0xd3'));var _0x230088=path['join'](_0x588634,_0x1599b8);var _0xaf07a7=util[_0x31f1('0xd4')]('transcript-%d-%s.zip',_0x70c3ab[_0x31f1('0xb7')]['id'],_0x1599b8);var _0x2a4a1d=path[_0x31f1('0xce')](_0x588634,_0xaf07a7);var _0x236623=[];_0x236623[_0x31f1('0x37')]({'model':db[_0x31f1('0x6c')],'as':_0x31f1('0x6c'),'attributes':['id','fullname'],'raw':!![]});_0x236623['push']({'model':db['CmContact'],'as':_0x31f1('0x62'),'attributes':['id',_0x31f1('0xd5'),_0x31f1('0xd6')],'raw':!![]});if(_0x70c3ab[_0x31f1('0x3d')][_0x31f1('0xd3')]){_0x236623[_0x31f1('0x37')]({'model':db[_0x31f1('0xd7')],'as':_0x31f1('0xd7'),'raw':!![]});}var _0x469865=[{'model':db[_0x31f1('0xc0')],'as':'Messages','attributes':['id','body','createdAt',_0x31f1('0xd8'),_0x31f1('0xd9'),_0x31f1('0x7f')],'include':_0x236623}];_0x469865[_0x31f1('0x37')]({'model':db[_0x31f1('0xda')],'as':_0x31f1('0xdb'),'attributes':['id',_0x31f1('0x2f')]});_0x469865[_0x31f1('0x37')]({'model':db[_0x31f1('0x6c')],'as':_0x31f1('0xdc'),'attributes':['id',_0x31f1('0x32')]});return db[_0x31f1('0x39')]['find']({'where':{'id':_0x70c3ab[_0x31f1('0xb7')]['id']},'include':_0x469865})[_0x31f1('0x2c')](handleEntityNotFound(_0x4fec7f,null))['then'](function(_0x4c4ade){if(_0x4c4ade){var _0x1323cc=_0x4c4ade[_0x31f1('0xdd')]({'plain':!![]});fs[_0x31f1('0xde')](_0x230088);var _0x28bc13={'channel':_0x31f1('0xdf'),'account':_0x1323cc['Account'][_0x31f1('0x2f')],'agent':_0x1323cc[_0x31f1('0xdc')]?_0x1323cc[_0x31f1('0xdc')][_0x31f1('0x32')]:_0x31f1('0xe0'),'createdAt':moment(_0x1323cc[_0x31f1('0x7a')])[_0x31f1('0xd4')](_0x31f1('0xe1'))[_0x31f1('0x99')](),'closedAt':_0x1323cc['closed']?moment(_0x1323cc[_0x31f1('0xe2')])[_0x31f1('0xd4')](_0x31f1('0xe1'))[_0x31f1('0x99')]():'','disposition':_0x1323cc['disposition'],'messages':_(_0x1323cc[_0x31f1('0xe3')])['filter']({'secret':![]})[_0x31f1('0x38')](function(_0x5c55f8){if(_0x5c55f8[_0x31f1('0xd7')]){var _0x340de8=path['join'](_0x476e94,_0x5c55f8['Attachment'][_0x31f1('0xe4')]);if(fs[_0x31f1('0xe5')](_0x340de8)){fs[_0x31f1('0xe6')](_0x340de8)[_0x31f1('0xe7')](fs[_0x31f1('0xe8')](path[_0x31f1('0xce')](_0x230088,_0x5c55f8[_0x31f1('0xd7')]['basename'])));}}return{'date':moment(_0x5c55f8[_0x31f1('0x7a')])[_0x31f1('0xd4')]('YYYY-MM-DD\x20HH:mm:ss')[_0x31f1('0x99')](),'sender':_0x5c55f8['direction']===_0x31f1('0xe9')?_0x5c55f8['User']?_0x5c55f8[_0x31f1('0x6c')][_0x31f1('0x32')]:_0x31f1('0xea'):_0x5c55f8[_0x31f1('0x62')]['firstName']+(_0x5c55f8[_0x31f1('0x62')][_0x31f1('0xd6')]?'\x20'+_0x5c55f8['Contact']['lastName']:''),'body':_0x5c55f8['Attachment']?_0x5c55f8[_0x31f1('0xd7')][_0x31f1('0xe4')]:_0x5c55f8[_0x31f1('0x71')],'direction':_0x5c55f8[_0x31f1('0xd8')]===_0x31f1('0xe9')?'A':'C','secret':_0x5c55f8['secret'],'read':_0x5c55f8['read'],'attachment':_0x5c55f8[_0x31f1('0xd7')]};})[_0x31f1('0x5e')]()};return ejs[_0x31f1('0xeb')](path['join'](config['root'],'server',_0x31f1('0xec'),_0x31f1('0xed')),{'interaction':_0x28bc13})[_0x31f1('0x2c')](function(_0x4d0ef4){var _0x35d3b3=path[_0x31f1('0xce')](_0x230088,_0x31f1('0xee')+_0x1323cc['id']+'-'+_0x1599b8+_0x31f1('0xef'));var _0x3b8a9d={'path':_0x35d3b3,'channel':_0x31f1('0xdf'),'interactionId':_0x1323cc['id']};return pdf[_0x31f1('0xf0')](_0x4d0ef4,_0x3b8a9d);})[_0x31f1('0x2c')](function(){return new BPromise(function(_0x16013e,_0x5d7e9d){zipdir(_0x230088,{'saveTo':_0x2a4a1d},function(_0x2ef1e9,_0x56564c){if(_0x2ef1e9)return _0x5d7e9d(_0x2ef1e9);return _0x16013e(_0x56564c);});})[_0x31f1('0x2c')](function(){return new BPromise(function(_0x1fad4c,_0xdf0f9e){rimraf(_0x230088,function(_0x1b86c2){if(_0x1b86c2)_0xdf0f9e(_0x1b86c2);return _0x1fad4c();});});})['then'](function(){return _0x4fec7f[_0x31f1('0xf1')](_0x2a4a1d,_0xaf07a7,function(_0x304420){if(_0x304420){console[_0x31f1('0xf2')](_0x31f1('0xf3'),_0x304420);}else{fs[_0x31f1('0xf4')](_0x2a4a1d);}});});});}else{return _0x4fec7f[_0x31f1('0x22')](0xc8);}})[_0x31f1('0xbb')](handleError(_0x4fec7f,null));};
\ No newline at end of file
+var _0xb7b4=['offset','sort','pick','where','WhatsappInteractionId','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','rows','addTags','setTags','spread','Tag','color','emit','removeTags','download','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','firstName','lastName','attachments','Attachment','Messages','createdAt','direction','read','Account','Owner','N.A.','toString','closed','closedAt','disposition','basename','existsSync','pipe','out','System','secret','renderFile','views','.pdf','Whatsapp','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','path','ejs','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','register','sendStatus','status','end','json','undefined','limit','count','set','Content-Range','update','then','destroy','stack','name','index','map','rawAttributes','fieldName','type','findAll','whatsapp','catch','show','params','keys','WhatsappInteraction','query','filters','intersection','model','attributes','fields','include','merge','options','find','create','body','addMessage','WhatsappMessage','ids','omit','getMessages','length','hasOwnProperty','nolimit'];(function(_0x2808e2,_0x2570fe){var _0x57088f=function(_0x488583){while(--_0x488583){_0x2808e2['push'](_0x2808e2['shift']());}};_0x57088f(++_0x2570fe);}(_0xb7b4,0x1ad));var _0x4b7b=function(_0x385f0e,_0xa10008){_0x385f0e=_0x385f0e-0x0;var _0x41d183=_0xb7b4[_0x385f0e];return _0x41d183;};'use strict';var rimraf=require(_0x4b7b('0x0'));var zipdir=require(_0x4b7b('0x1'));var moment=require(_0x4b7b('0x2'));var BPromise=require('bluebird');var util=require('util');var path=require(_0x4b7b('0x3'));var ejs=require(_0x4b7b('0x4'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x4b7b('0x5'));var interaction=require(_0x4b7b('0x6'));var qs=require(_0x4b7b('0x7'));var pdf=require(_0x4b7b('0x8'));var logger=require(_0x4b7b('0x9'))(_0x4b7b('0xa'));var config=require(_0x4b7b('0xb'));var db=require(_0x4b7b('0xc'))['db'];config[_0x4b7b('0xd')]=_[_0x4b7b('0xe')](config[_0x4b7b('0xd')],{'host':_0x4b7b('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4b7b('0xd')]));require('./whatsappInteraction.socket')[_0x4b7b('0x10')](socket);function respondWithStatusCode(_0x873075,_0x27414b){_0x27414b=_0x27414b||0xcc;return function(_0x5b457f){if(_0x5b457f){return _0x873075[_0x4b7b('0x11')](_0x27414b);}return _0x873075[_0x4b7b('0x12')](_0x27414b)[_0x4b7b('0x13')]();};}function respondWithResult(_0x31f453,_0x469122){_0x469122=_0x469122||0xc8;return function(_0x272280){if(_0x272280){return _0x31f453[_0x4b7b('0x12')](_0x469122)[_0x4b7b('0x14')](_0x272280);}};}function respondWithFilteredResult(_0x24a13b,_0x5e3510){return function(_0x477bb6){if(_0x477bb6){var _0x136e86=typeof _0x5e3510['offset']===_0x4b7b('0x15')&&typeof _0x5e3510[_0x4b7b('0x16')]===_0x4b7b('0x15');var _0x33a7f8=_0x477bb6[_0x4b7b('0x17')];var _0x35a13b=_0x136e86?0x0:_0x5e3510['offset'];var _0x411284=_0x136e86?_0x477bb6['count']:_0x5e3510['offset']+_0x5e3510[_0x4b7b('0x16')];var _0x216b12;if(_0x411284>=_0x33a7f8){_0x411284=_0x33a7f8;_0x216b12=0xc8;}else{_0x216b12=0xce;}_0x24a13b[_0x4b7b('0x12')](_0x216b12);return _0x24a13b[_0x4b7b('0x18')](_0x4b7b('0x19'),_0x35a13b+'-'+_0x411284+'/'+_0x33a7f8)[_0x4b7b('0x14')](_0x477bb6);}return null;};}function saveUpdates(_0x590f83){return function(_0x209215){if(_0x209215){return _0x209215[_0x4b7b('0x1a')](_0x590f83)[_0x4b7b('0x1b')](function(_0x54ef79){return _0x54ef79;});}return null;};}function removeEntity(_0x1a4365){return function(_0x5dcf02){if(_0x5dcf02){return _0x5dcf02[_0x4b7b('0x1c')]()[_0x4b7b('0x1b')](function(){_0x1a4365[_0x4b7b('0x12')](0xcc)[_0x4b7b('0x13')]();});}};}function handleEntityNotFound(_0x918d1b){return function(_0x4bf891){if(!_0x4bf891){_0x918d1b[_0x4b7b('0x11')](0x194);}return _0x4bf891;};}function handleError(_0x59c6bd,_0x4660ea){_0x4660ea=_0x4660ea||0x1f4;return function(_0x70f4fa){logger['error'](_0x70f4fa[_0x4b7b('0x1d')]);if(_0x70f4fa[_0x4b7b('0x1e')]){delete _0x70f4fa[_0x4b7b('0x1e')];}_0x59c6bd[_0x4b7b('0x12')](_0x4660ea)['send'](_0x70f4fa);};}exports[_0x4b7b('0x1f')]=function(_0xfa7452,_0x44925d){var _0x2cf184={};var _0x10ec6b=_[_0x4b7b('0x20')](db['WhatsappInteraction'][_0x4b7b('0x21')],function(_0xa683b4){return{'name':_0xa683b4[_0x4b7b('0x22')],'type':_0xa683b4[_0x4b7b('0x23')]['key']};});_0x2cf184=qs['getOptions'](_0x10ec6b,_0xfa7452);return interaction[_0x4b7b('0x24')](_0x4b7b('0x25'),_0xfa7452['query'],_0xfa7452['user'],_0x2cf184,_0x10ec6b)[_0x4b7b('0x1b')](respondWithFilteredResult(_0x44925d,_0x2cf184))[_0x4b7b('0x26')](handleError(_0x44925d,null));};exports[_0x4b7b('0x27')]=function(_0x4d0df2,_0x59c9e2){var _0x228e96={'raw':![],'where':{'id':_0x4d0df2[_0x4b7b('0x28')]['id']}},_0x1c61d0={};_0x1c61d0['model']=_[_0x4b7b('0x29')](db[_0x4b7b('0x2a')]['rawAttributes']);_0x1c61d0['query']=_[_0x4b7b('0x29')](_0x4d0df2[_0x4b7b('0x2b')]);_0x1c61d0[_0x4b7b('0x2c')]=_[_0x4b7b('0x2d')](_0x1c61d0[_0x4b7b('0x2e')],_0x1c61d0[_0x4b7b('0x2b')]);_0x228e96[_0x4b7b('0x2f')]=_[_0x4b7b('0x2d')](_0x1c61d0[_0x4b7b('0x2e')],qs[_0x4b7b('0x30')](_0x4d0df2[_0x4b7b('0x2b')][_0x4b7b('0x30')]));_0x228e96[_0x4b7b('0x2f')]=_0x228e96[_0x4b7b('0x2f')]['length']?_0x228e96['attributes']:_0x1c61d0[_0x4b7b('0x2e')];if(_0x4d0df2[_0x4b7b('0x2b')]['includeAll']){_0x228e96[_0x4b7b('0x31')]=[{'all':!![]}];}_0x228e96=_[_0x4b7b('0x32')]({},_0x228e96,_0x4d0df2[_0x4b7b('0x33')]);return db[_0x4b7b('0x2a')][_0x4b7b('0x34')](_0x228e96)[_0x4b7b('0x1b')](handleEntityNotFound(_0x59c9e2,null))[_0x4b7b('0x1b')](respondWithResult(_0x59c9e2,null))['catch'](handleError(_0x59c9e2,null));};exports['create']=function(_0x4d611e,_0x5253d0){return db['WhatsappInteraction'][_0x4b7b('0x35')](_0x4d611e[_0x4b7b('0x36')],{})[_0x4b7b('0x1b')](respondWithResult(_0x5253d0,0xc9))[_0x4b7b('0x26')](handleError(_0x5253d0,null));};exports[_0x4b7b('0x1a')]=function(_0x1c1c63,_0xa2c747){if(_0x1c1c63[_0x4b7b('0x36')]['id']){delete _0x1c1c63[_0x4b7b('0x36')]['id'];}return db[_0x4b7b('0x2a')][_0x4b7b('0x34')]({'where':{'id':_0x1c1c63[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0xa2c747,null))[_0x4b7b('0x1b')](saveUpdates(_0x1c1c63[_0x4b7b('0x36')],null))[_0x4b7b('0x1b')](respondWithResult(_0xa2c747,null))[_0x4b7b('0x26')](handleError(_0xa2c747,null));};exports[_0x4b7b('0x1c')]=function(_0x5edc33,_0x59f0df){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x5edc33[_0x4b7b('0x28')]['id']}})['then'](handleEntityNotFound(_0x59f0df,null))[_0x4b7b('0x1b')](removeEntity(_0x59f0df,null))[_0x4b7b('0x26')](handleError(_0x59f0df,null));};exports['describe']=function(_0x6a496e,_0x14d02d){return db['WhatsappInteraction']['describe']()[_0x4b7b('0x1b')](respondWithResult(_0x14d02d,null))[_0x4b7b('0x26')](handleError(_0x14d02d,null));};exports[_0x4b7b('0x37')]=function(_0x5d9516,_0x509ff8){return db[_0x4b7b('0x38')][_0x4b7b('0x34')]({'where':{'id':_0x5d9516[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x509ff8,null))['then'](function(_0x18bb41){if(_0x18bb41){return _0x18bb41[_0x4b7b('0x37')](_0x5d9516[_0x4b7b('0x36')][_0x4b7b('0x39')],_[_0x4b7b('0x3a')](_0x5d9516[_0x4b7b('0x36')],[_0x4b7b('0x39'),'id'])||{});}})[_0x4b7b('0x1b')](respondWithResult(_0x509ff8,null))['catch'](handleError(_0x509ff8,null));};exports[_0x4b7b('0x3b')]=function(_0x2a60b0,_0x112cd1){var _0x3d4716={'raw':![],'where':{}};var _0x50dd4f={};var _0x4bd6a3={'count':0x0,'rows':[]};return db[_0x4b7b('0x2a')]['findOne']({'where':{'id':_0x2a60b0[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x112cd1,null))[_0x4b7b('0x1b')](function(_0x387ce2){if(_0x387ce2){_0x50dd4f['model']=_[_0x4b7b('0x29')](db[_0x4b7b('0x38')]['rawAttributes']);_0x50dd4f[_0x4b7b('0x2b')]=_[_0x4b7b('0x29')](_0x2a60b0['query']);_0x50dd4f[_0x4b7b('0x2c')]=_[_0x4b7b('0x2d')](_0x50dd4f[_0x4b7b('0x2e')],_0x50dd4f['query']);_0x3d4716[_0x4b7b('0x2f')]=_[_0x4b7b('0x2d')](_0x50dd4f['model'],qs['fields'](_0x2a60b0['query'][_0x4b7b('0x30')]));_0x3d4716[_0x4b7b('0x2f')]=_0x3d4716[_0x4b7b('0x2f')][_0x4b7b('0x3c')]?_0x3d4716[_0x4b7b('0x2f')]:_0x50dd4f['model'];if(!_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x3d')](_0x4b7b('0x3e'))){_0x3d4716[_0x4b7b('0x16')]=qs['limit'](_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x16')]);_0x3d4716[_0x4b7b('0x3f')]=qs[_0x4b7b('0x3f')](_0x2a60b0['query'][_0x4b7b('0x3f')]);}_0x3d4716['order']=qs['sort'](_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x40')]);_0x3d4716['where']=qs[_0x4b7b('0x2c')](_[_0x4b7b('0x41')](_0x2a60b0[_0x4b7b('0x2b')],_0x50dd4f[_0x4b7b('0x2c')]));_0x3d4716[_0x4b7b('0x42')][_0x4b7b('0x43')]=_0x387ce2['id'];if(_0x2a60b0[_0x4b7b('0x2b')]['filter']){_0x3d4716[_0x4b7b('0x42')]=_[_0x4b7b('0x32')](_0x3d4716[_0x4b7b('0x42')],{'$or':_[_0x4b7b('0x20')](_0x3d4716[_0x4b7b('0x2f')],function(_0x4dd54a){var _0x83e4e4={};_0x83e4e4[_0x4dd54a]={'$like':'%'+_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x44')]+'%'};return _0x83e4e4;})});}if(_0x2a60b0['query'][_0x4b7b('0x45')]){var _0xf62d79=_0x2a60b0[_0x4b7b('0x2b')]['$gte'][_0x4b7b('0x46')](',');var _0xdd0c0f={};_0xdd0c0f[_0xf62d79[0x0]]={'$gte':moment(_0xf62d79[0x1])[_0x4b7b('0x47')](_0x4b7b('0x48'))};_0x3d4716[_0x4b7b('0x42')]=_[_0x4b7b('0x32')](_0x3d4716['where'],_0xdd0c0f);}_0x3d4716=_['merge']({},_0x3d4716,_0x2a60b0[_0x4b7b('0x33')]);return db['WhatsappMessage'][_0x4b7b('0x17')]({'where':_0x3d4716[_0x4b7b('0x42')]})[_0x4b7b('0x1b')](function(_0x25caf1){_0x4bd6a3[_0x4b7b('0x17')]=_0x25caf1;if(_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x49')]){_0x3d4716[_0x4b7b('0x31')]=[{'all':!![]}];}return db[_0x4b7b('0x38')][_0x4b7b('0x24')](_0x3d4716);})[_0x4b7b('0x1b')](function(_0x10002e){_0x4bd6a3[_0x4b7b('0x4a')]=_0x10002e;return _0x4bd6a3;});}})[_0x4b7b('0x1b')](respondWithFilteredResult(_0x112cd1,_0x3d4716))[_0x4b7b('0x26')](handleError(_0x112cd1,null));};exports[_0x4b7b('0x4b')]=function(_0x53888d,_0x42c481){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x53888d[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x42c481,null))[_0x4b7b('0x1b')](function(_0x51e7da){if(_0x51e7da){return _0x51e7da[_0x4b7b('0x4c')](_0x53888d['body']['ids'],_['omit'](_0x53888d[_0x4b7b('0x36')],[_0x4b7b('0x39'),'id'])||{})[_0x4b7b('0x4d')](function(){return db[_0x4b7b('0x4e')]['findAll']({'attributes':['id','name',_0x4b7b('0x4f')],'where':{'id':_0x53888d[_0x4b7b('0x36')][_0x4b7b('0x39')]}});})[_0x4b7b('0x1b')](function(_0x43fd8b){socket[_0x4b7b('0x50')]('whatsappInteractionTags:save',{'id':Number(_0x53888d[_0x4b7b('0x28')]['id']),'tags':_0x43fd8b||[]});return{'id':Number(_0x53888d[_0x4b7b('0x28')]['id']),'tags':_0x43fd8b||[]};});}})[_0x4b7b('0x1b')](respondWithResult(_0x42c481,null))[_0x4b7b('0x26')](handleError(_0x42c481,null));};exports[_0x4b7b('0x51')]=function(_0x5bd219,_0x339543){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x5bd219['params']['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x339543,null))[_0x4b7b('0x1b')](function(_0x2a53bf){if(_0x2a53bf){return _0x2a53bf[_0x4b7b('0x51')](_0x5bd219[_0x4b7b('0x2b')][_0x4b7b('0x39')]);}})['then'](respondWithStatusCode(_0x339543,null))[_0x4b7b('0x26')](handleError(_0x339543,null));};exports[_0x4b7b('0x52')]=function(_0x4b2e11,_0x1db915){var _0x24dbe2=moment()['unix']()['toString']();var _0x44a893=path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x56'),_0x4b7b('0x57'));var _0x43a93e=path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x56'),'attachments');var _0x58a96c=path[_0x4b7b('0x53')](_0x44a893,_0x24dbe2);var _0x515f6e=util[_0x4b7b('0x47')](_0x4b7b('0x58'),_0x4b2e11['params']['id'],_0x24dbe2);var _0x35148a=path[_0x4b7b('0x53')](_0x44a893,_0x515f6e);var _0x2a1270=[];_0x2a1270[_0x4b7b('0x59')]({'model':db[_0x4b7b('0x5a')],'as':_0x4b7b('0x5a'),'attributes':['id',_0x4b7b('0x5b')],'raw':!![]});_0x2a1270['push']({'model':db[_0x4b7b('0x5c')],'as':_0x4b7b('0x5d'),'attributes':['id',_0x4b7b('0x5e'),_0x4b7b('0x5f')],'raw':!![]});if(_0x4b2e11[_0x4b7b('0x2b')][_0x4b7b('0x60')]){_0x2a1270['push']({'model':db['Attachment'],'as':_0x4b7b('0x61'),'raw':!![]});}var _0x40bb8d=[{'model':db[_0x4b7b('0x38')],'as':_0x4b7b('0x62'),'attributes':['id',_0x4b7b('0x36'),_0x4b7b('0x63'),_0x4b7b('0x64'),'secret',_0x4b7b('0x65')],'include':_0x2a1270}];_0x40bb8d[_0x4b7b('0x59')]({'model':db['WhatsappAccount'],'as':_0x4b7b('0x66'),'attributes':['id',_0x4b7b('0x1e')]});_0x40bb8d['push']({'model':db['User'],'as':_0x4b7b('0x67'),'attributes':['id','fullname']});return db[_0x4b7b('0x2a')][_0x4b7b('0x34')]({'where':{'id':_0x4b2e11[_0x4b7b('0x28')]['id']},'include':_0x40bb8d})[_0x4b7b('0x1b')](handleEntityNotFound(_0x1db915,null))['then'](function(_0x258ed5){if(_0x258ed5){var _0x157097=_0x258ed5['get']({'plain':!![]});fs['mkdirSync'](_0x58a96c);var _0x532807={'channel':'Whatsapp','account':_0x157097['Account'][_0x4b7b('0x1e')],'agent':_0x157097['Owner']?_0x157097[_0x4b7b('0x67')][_0x4b7b('0x5b')]:_0x4b7b('0x68'),'createdAt':moment(_0x157097['createdAt'])[_0x4b7b('0x47')]('YYYY-MM-DD\x20HH:mm:ss')[_0x4b7b('0x69')](),'closedAt':_0x157097[_0x4b7b('0x6a')]?moment(_0x157097[_0x4b7b('0x6b')])[_0x4b7b('0x47')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x157097[_0x4b7b('0x6c')],'messages':_(_0x157097[_0x4b7b('0x62')])[_0x4b7b('0x44')]({'secret':![]})['map'](function(_0x169058){if(_0x169058['Attachment']){var _0x36ace4=path['join'](_0x43a93e,_0x169058[_0x4b7b('0x61')][_0x4b7b('0x6d')]);if(fs[_0x4b7b('0x6e')](_0x36ace4)){fs['createReadStream'](_0x36ace4)[_0x4b7b('0x6f')](fs['createWriteStream'](path['join'](_0x58a96c,_0x169058[_0x4b7b('0x61')][_0x4b7b('0x6d')])));}}return{'date':moment(_0x169058[_0x4b7b('0x63')])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x169058[_0x4b7b('0x64')]===_0x4b7b('0x70')?_0x169058[_0x4b7b('0x5a')]?_0x169058['User']['fullname']:_0x4b7b('0x71'):_0x169058[_0x4b7b('0x5d')][_0x4b7b('0x5e')]+(_0x169058[_0x4b7b('0x5d')][_0x4b7b('0x5f')]?'\x20'+_0x169058['Contact'][_0x4b7b('0x5f')]:''),'body':_0x169058[_0x4b7b('0x61')]?_0x169058[_0x4b7b('0x61')]['basename']:_0x169058[_0x4b7b('0x36')],'direction':_0x169058[_0x4b7b('0x64')]===_0x4b7b('0x70')?'A':'C','secret':_0x169058[_0x4b7b('0x72')],'read':_0x169058[_0x4b7b('0x65')],'attachment':_0x169058[_0x4b7b('0x61')]};})['value']()};return ejs[_0x4b7b('0x73')](path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x74'),'downloadInteraction.ejs'),{'interaction':_0x532807})[_0x4b7b('0x1b')](function(_0x607106){var _0x508946=path[_0x4b7b('0x53')](_0x58a96c,'transcript-'+_0x157097['id']+'-'+_0x24dbe2+_0x4b7b('0x75'));var _0x382fdb={'path':_0x508946,'channel':_0x4b7b('0x76'),'interactionId':_0x157097['id']};return pdf[_0x4b7b('0x77')](_0x607106,_0x382fdb);})[_0x4b7b('0x1b')](function(){return new BPromise(function(_0xa2cc74,_0x43ffc6){zipdir(_0x58a96c,{'saveTo':_0x35148a},function(_0x10e810,_0x335583){if(_0x10e810)return _0x43ffc6(_0x10e810);return _0xa2cc74(_0x335583);});})[_0x4b7b('0x1b')](function(){return new BPromise(function(_0x26988e,_0x50e139){rimraf(_0x58a96c,function(_0x21cf63){if(_0x21cf63)_0x50e139(_0x21cf63);return _0x26988e();});});})[_0x4b7b('0x1b')](function(){return _0x1db915[_0x4b7b('0x52')](_0x35148a,_0x515f6e,function(_0x282ec9){if(_0x282ec9){console[_0x4b7b('0x78')](_0x4b7b('0x79'),_0x282ec9);}else{fs[_0x4b7b('0x7a')](_0x35148a);}});});});}else{return _0x1db915['sendStatus'](0xc8);}})[_0x4b7b('0x26')](handleError(_0x1db915,null));};
\ No newline at end of file