Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 6d9904b..724f602 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbb47=['clone','i.id','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages','DESC','isEmpty','t.id\x20IN\x20?','resolve','WhatsappAccountId','journey','i.WhatsappAccountId\x20IS\x20NOT\x20NULL','user','getWhatsappAccounts','i.WhatsappAccountId\x20IS\x20NULL','sequelize','toString','keyBy','merge','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','i.*','Contact.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','includeAll','options','create','describe','addMessage','ids','omit','getMessages','WhatsappMessage','pick','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','setTags','spread','emit','whatsappInteractionTags:save','removeTags','download','unix','server','files','tmp','join','root','transcript-%d-%s.zip','User','CmContact','lastName','attachments','Attachment','Messages','direction','secret','read','Account','Owner','get','mkdirSync','40px','<div\x20class=\x22header\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<h5>Interaction\x20Transcript</h5>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','30px','<hr\x20class=\x22separator\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22footer\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22left\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22center\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>{{page}}/{{pages}}</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22right\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span>%s</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20</div>','%s\x20#%d','Whatsapp','N.A.','closed','closedAt','basename','existsSync','createReadStream','pipe','createWriteStream','System','firstName','out','renderFile','views','downloadInteraction.html','toFile','transcript-','.pdf','log','err','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','jsforce','desk.js','papaparse','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','status','end','count','offset','set','json','apply','reject','update','then','destroy','sendStatus','error','name','map','fullname','Tags','TagIds','split','forEach','push','catch','WhatsappInteraction','rawAttributes','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','field','color','from','tools_tags','select','u.id','u.fullname','user_has_whatsapp_interactions','left_join','users','u.id\x20=\x20ui.UserId','whatsapp_interactions','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','whatsapp_accounts','a.id\x20=\x20i.WhatsappAccountId','whatsapp_messages','me.WhatsappInteractionId\x20=\x20i.id','whatsapp_interaction_has_tags','it.WhatsappInteractionId\x20=\x20i.id','t.id\x20=\x20it.TagId','expr','sqlOperator','conditions','find','value','having','`\x20=\x200','Contact','operator','$substring','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','start','union','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','buildExpression','body','keys','compact','where','i.WhatsappAccountId\x20IN\x20?','concat','createdAt','$gte','parse','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','`unreadMessages`\x20=\x200','`unreadMessages`\x20>\x200','tag','isArray','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','filter','replace','isNumeric','i.id\x20LIKE\x20?','CONCAT(c.firstName,\x20\x27\x20\x27,\x20c.lastName)\x20LIKE\x20?','group','Sequelize','QueryTypes'];(function(_0x4a42f0,_0x2da65d){var _0x3dc532=function(_0xb60cdf){while(--_0xb60cdf){_0x4a42f0['push'](_0x4a42f0['shift']());}};_0x3dc532(++_0x2da65d);}(_0xbb47,0x6e));var _0x7bb4=function(_0x178668,_0x1ec300){_0x178668=_0x178668-0x0;var _0x26107d=_0xbb47[_0x178668];return _0x26107d;};'use strict';var pdf=require(_0x7bb4('0x0'));var emlformat=require(_0x7bb4('0x1'));var rimraf=require(_0x7bb4('0x2'));var zipdir=require(_0x7bb4('0x3'));var jsonpatch=require(_0x7bb4('0x4'));var rp=require(_0x7bb4('0x5'));var moment=require(_0x7bb4('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x7bb4('0x7'));var util=require(_0x7bb4('0x8'));var path=require('path');var sox=require(_0x7bb4('0x9'));var csv=require(_0x7bb4('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x7bb4('0xb'));var deskjs=require(_0x7bb4('0xc'));var toCsv=require(_0x7bb4('0xa'));var querystring=require('querystring');var Papa=require(_0x7bb4('0xd'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7bb4('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x7bb4('0xf'));var logger=require('../../config/logger')(_0x7bb4('0x10'));var utils=require(_0x7bb4('0x11'));var config=require(_0x7bb4('0x12'));var licenseUtil=require(_0x7bb4('0x13'));var db=require(_0x7bb4('0x14'))['db'];config['redis']=_[_0x7bb4('0x15')](config[_0x7bb4('0x16')],{'host':_0x7bb4('0x17'),'port':0x18eb});var socket=require(_0x7bb4('0x18'))(new Redis(config[_0x7bb4('0x16')]));require('./whatsappInteraction.socket')[_0x7bb4('0x19')](socket);function respondWithStatusCode(_0x1d12b5,_0x48f164){_0x48f164=_0x48f164||0xcc;return function(_0x5b461a){if(_0x5b461a){return _0x1d12b5['sendStatus'](_0x48f164);}return _0x1d12b5[_0x7bb4('0x1a')](_0x48f164)[_0x7bb4('0x1b')]();};}function respondWithResult(_0x5aab28,_0xa07236){_0xa07236=_0xa07236||0xc8;return function(_0x55797e){if(_0x55797e){return _0x5aab28[_0x7bb4('0x1a')](_0xa07236)['json'](_0x55797e);}};}function respondWithFilteredResult(_0x5e7f5d,_0x4250e0){return function(_0x56da52){if(_0x56da52){var _0x1204b7=_0x56da52[_0x7bb4('0x1c')],_0x2315c2=_0x4250e0[_0x7bb4('0x1d')],_0x5ae00b=_0x4250e0[_0x7bb4('0x1d')]+_0x4250e0['limit'],_0x263ea8;if(_0x5ae00b>=_0x1204b7){_0x5ae00b=_0x1204b7;_0x263ea8=0xc8;}else{_0x263ea8=0xce;}_0x5e7f5d[_0x7bb4('0x1a')](_0x263ea8);return _0x5e7f5d[_0x7bb4('0x1e')]('Content-Range',_0x2315c2+'-'+_0x5ae00b+'/'+_0x1204b7)[_0x7bb4('0x1f')](_0x56da52);}return null;};}function patchUpdates(_0x315d3f){return function(_0x2a5992){try{jsonpatch[_0x7bb4('0x20')](_0x2a5992,_0x315d3f,!![]);}catch(_0x4e0c5c){return BPromise[_0x7bb4('0x21')](_0x4e0c5c);}return _0x2a5992['save']();};}function saveUpdates(_0x6c8c90,_0x194bab){return function(_0x2b9806){if(_0x2b9806){return _0x2b9806[_0x7bb4('0x22')](_0x6c8c90)[_0x7bb4('0x23')](function(_0x341204){return _0x341204;});}return null;};}function removeEntity(_0x442e93,_0x23678b){return function(_0x4a2948){if(_0x4a2948){return _0x4a2948[_0x7bb4('0x24')]()[_0x7bb4('0x23')](function(){_0x442e93[_0x7bb4('0x1a')](0xcc)[_0x7bb4('0x1b')]();});}};}function handleEntityNotFound(_0x209597,_0x43d716){return function(_0x41a476){if(!_0x41a476){_0x209597[_0x7bb4('0x25')](0x194);}return _0x41a476;};}function handleError(_0x5b6f7f,_0x1d3e7c){_0x1d3e7c=_0x1d3e7c||0x1f4;return function(_0x154bc5){logger[_0x7bb4('0x26')](_0x154bc5['stack']);if(_0x154bc5[_0x7bb4('0x27')]){delete _0x154bc5[_0x7bb4('0x27')];}_0x5b6f7f[_0x7bb4('0x1a')](_0x1d3e7c)['send'](_0x154bc5);};}function getInteractionUsers(_0x15fce7,_0x2b93a3){return new BPromise(function(_0x1bbc4c,_0x4e9fc0){try{if(_0x2b93a3[_0x15fce7['id']]){_0x15fce7['Users']=_[_0x7bb4('0x28')](_0x2b93a3[_0x15fce7['id']],function(_0x49a81d){return{'id':_0x49a81d['id'],'fullname':_0x49a81d[_0x7bb4('0x29')]};});}}catch(_0x40e9bc){_0x4e9fc0(_0x40e9bc);}_0x1bbc4c(_0x15fce7);});}function getInteractionTags(_0x39d999,_0x56107e){return new BPromise(function(_0x1fa8f6,_0x159a13){try{if(_0x39d999['TagIds']){_0x39d999[_0x7bb4('0x2a')]=[];_0x39d999[_0x7bb4('0x2b')][_0x7bb4('0x2c')](',')[_0x7bb4('0x2d')](function(_0x5232ae){_0x39d999[_0x7bb4('0x2a')][_0x7bb4('0x2e')](_0x56107e[_0x5232ae]);});}delete _0x39d999[_0x7bb4('0x2b')];}catch(_0x17442c){_0x159a13(_0x17442c);}_0x1fa8f6(_0x39d999);});}function updateWhatsappInteraction(_0x57ce38,_0x3a29e8,_0xa3a068){return new BPromise(function(_0xfdeffd,_0x34ed41){return getInteractionUsers(_0x57ce38,_0xa3a068)[_0x7bb4('0x23')](function(_0x57b45c){return getInteractionTags(_0x57b45c,_0x3a29e8);})[_0x7bb4('0x23')](function(_0x17b8bd){_0xfdeffd(_0x17b8bd);})[_0x7bb4('0x2f')](function(_0xde634b){_0x34ed41(_0xde634b);});});}exports['index']=function(_0x2af623,_0x342360){var _0x733e22={},_0x4f600b={},_0x47d1b4={'count':0x0,'rows':[]};var _0x8384c5=_[_0x7bb4('0x28')](db[_0x7bb4('0x30')][_0x7bb4('0x31')],function(_0x338ffd){return{'name':_0x338ffd['fieldName'],'type':_0x338ffd[_0x7bb4('0x32')][_0x7bb4('0x33')]};});_0x4f600b[_0x7bb4('0x34')]=_['map'](_0x8384c5,_0x7bb4('0x27'));_0x4f600b[_0x7bb4('0x35')]=_['keys'](_0x2af623['query']);_0x4f600b[_0x7bb4('0x36')]=_[_0x7bb4('0x37')](_0x4f600b[_0x7bb4('0x34')],_0x4f600b[_0x7bb4('0x35')]);_0x733e22[_0x7bb4('0x38')]=_[_0x7bb4('0x37')](_0x4f600b[_0x7bb4('0x34')],qs[_0x7bb4('0x39')](_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x39')]));_0x733e22[_0x7bb4('0x38')]=_0x733e22[_0x7bb4('0x38')][_0x7bb4('0x3a')]?_0x733e22['attributes']:_0x4f600b['model'];if(!_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x3b')](_0x7bb4('0x3c'))){_0x733e22[_0x7bb4('0x3d')]=qs[_0x7bb4('0x3d')](_0x2af623['query'][_0x7bb4('0x3d')]);_0x733e22['offset']=qs[_0x7bb4('0x1d')](_0x2af623['query']['offset']);}_0x733e22[_0x7bb4('0x3e')]=qs[_0x7bb4('0x3f')](_0x2af623['query'][_0x7bb4('0x3f')]);_0x733e22['where']=qs['filters'](_['pick'](_0x2af623[_0x7bb4('0x35')],_0x4f600b[_0x7bb4('0x36')]),_0x8384c5);var _0x6bcaed=[];var _0x28ed7d=squel['select']()[_0x7bb4('0x40')]('id')[_0x7bb4('0x40')](_0x7bb4('0x27'))[_0x7bb4('0x40')](_0x7bb4('0x41'))[_0x7bb4('0x42')](_0x7bb4('0x43'));var _0x3f89fd=squel[_0x7bb4('0x44')]()[_0x7bb4('0x40')](_0x7bb4('0x45'))[_0x7bb4('0x40')](_0x7bb4('0x46'))[_0x7bb4('0x40')]('ui.WhatsappInteractionId')['from'](_0x7bb4('0x47'),'ui')[_0x7bb4('0x48')](_0x7bb4('0x49'),'u',_0x7bb4('0x4a'));var _0xa24691=squel[_0x7bb4('0x44')]()[_0x7bb4('0x42')](_0x7bb4('0x4b'),'i')['left_join']('cm_contacts','c',_0x7bb4('0x4c'))[_0x7bb4('0x48')](_0x7bb4('0x49'),'o','o.id\x20=\x20i.UserId')[_0x7bb4('0x48')](_0x7bb4('0x4d'),'a',_0x7bb4('0x4e'))['left_join'](_0x7bb4('0x4f'),'me',_0x7bb4('0x50'))[_0x7bb4('0x48')](_0x7bb4('0x51'),'it',_0x7bb4('0x52'))[_0x7bb4('0x48')](_0x7bb4('0x43'),'t',_0x7bb4('0x53'));var _0x2380d0=squel['expr']();var _0x524ad9=[];var _0x17e20c=squel[_0x7bb4('0x54')]();var _0x279883;if(_0x2af623[_0x7bb4('0x35')]['search']){_0x279883=as['parseSearch'](_0x2af623[_0x7bb4('0x35')]['search']);var _0x47fed9=_0x279883[_0x7bb4('0x55')];for(var _0x4619ce=0x0;_0x4619ce<_0x279883[_0x7bb4('0x56')]['length'];_0x4619ce++){var _0x4f95ae=_0x279883[_0x7bb4('0x56')][_0x4619ce];var _0x544e8a='i';var _0x29f150=_[_0x7bb4('0x57')](_0x8384c5,[_0x7bb4('0x27'),_0x4f95ae[_0x7bb4('0x40')]]);if(!_0x29f150){switch(_0x4f95ae['field']){case'unreadMessages':if(_0x4f95ae[_0x7bb4('0x58')]==0x1){_0xa24691[_0x7bb4('0x59')]('`'+_0x4f95ae[_0x7bb4('0x40')]+_0x7bb4('0x5a'));}else{_0xa24691[_0x7bb4('0x59')]('`'+_0x4f95ae[_0x7bb4('0x40')]+'`\x20>\x200');}break;case _0x7bb4('0x5b'):if(_0x4f95ae[_0x7bb4('0x5c')]===_0x7bb4('0x5d')){if(_0x4f95ae[_0x7bb4('0x58')]['split']('\x20')['length']>0x1){_0x2380d0[_0x47fed9](_0x7bb4('0x5e'),qs[_0x7bb4('0x5f')](_0x4f95ae[_0x7bb4('0x58')]),null);}else{var _0x598523='%'+_0x4f95ae[_0x7bb4('0x58')]+'%';_0x2380d0[_0x47fed9](_0x7bb4('0x60'),_0x598523,_0x598523,_0x598523);}}else{_0x29f150=_['find'](_0x8384c5,['name','ContactId']);_0x4f95ae[_0x7bb4('0x40')]=_0x7bb4('0x61');_0x12f341=as['buildExpression'](_0x544e8a,_0x29f150['type'],_0x4f95ae);_0x2380d0[_0x47fed9](_0x12f341[_0x7bb4('0x62')],_0x12f341['value'][_0x7bb4('0x63')],_0x12f341[_0x7bb4('0x58')][_0x7bb4('0x1b')]);}break;case'Tag':var _0x35ae49=_0x4f95ae[_0x7bb4('0x58')][_0x7bb4('0x2c')](',')[_0x7bb4('0x28')](function(_0x130563){return Number(_0x130563);});_0x35ae49['forEach'](function(_0x2849c9){_0x17e20c['or']('CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','%,'+_0x2849c9+',%');});_0x524ad9=_[_0x7bb4('0x64')](_0x524ad9,_0x35ae49);break;case'User':if(_0x4f95ae[_0x7bb4('0x5c')]===_0x7bb4('0x5d')){_0x2380d0[_0x47fed9](_0x7bb4('0x65'),'%'+_0x4f95ae[_0x7bb4('0x58')]+'%',null);}else{_0x29f150=_[_0x7bb4('0x57')](_0x8384c5,[_0x7bb4('0x27'),_0x7bb4('0x66')]);_0x4f95ae[_0x7bb4('0x40')]=_0x7bb4('0x66');_0x12f341=as[_0x7bb4('0x67')](_0x544e8a,_0x29f150[_0x7bb4('0x32')],_0x4f95ae);_0x2380d0[_0x47fed9](_0x12f341[_0x7bb4('0x62')],_0x12f341['value']['start'],_0x12f341[_0x7bb4('0x58')][_0x7bb4('0x1b')]);}break;case _0x7bb4('0x68'):_0x12f341=as[_0x7bb4('0x67')]('me',null,_0x4f95ae);_0x2380d0[_0x47fed9](_0x12f341[_0x7bb4('0x62')],_0x12f341[_0x7bb4('0x58')][_0x7bb4('0x63')],_0x12f341['value'][_0x7bb4('0x1b')]);break;}}else{var _0x12f341=as[_0x7bb4('0x67')](_0x544e8a,_0x29f150[_0x7bb4('0x32')],_0x4f95ae);_0x2380d0[_0x47fed9](_0x12f341[_0x7bb4('0x62')],_0x12f341['value'][_0x7bb4('0x63')],_0x12f341['value'][_0x7bb4('0x1b')]);}}}else{var _0x273304=_(_0x2af623['query'])[_0x7bb4('0x69')]()[_0x7bb4('0x28')](function(_0x2a0b8d){return _['some'](_0x8384c5,[_0x7bb4('0x27'),_0x2a0b8d])?_0x2a0b8d:undefined;})[_0x7bb4('0x6a')]()[_0x7bb4('0x58')]();if(!_['isEmpty'](_0x273304)){_0x273304[_0x7bb4('0x2d')](function(_0x29fbb6){if(_0x29fbb6==='WhatsappAccountId'){_0xa24691[_0x7bb4('0x6b')](_0x7bb4('0x6c'),[][_0x7bb4('0x6d')](_0x2af623[_0x7bb4('0x35')][_0x29fbb6]));}else if(_0x29fbb6===_0x7bb4('0x6e')){var _0x1ff955=JSON['parse'](_0x2af623[_0x7bb4('0x35')][_0x29fbb6])[_0x7bb4('0x6f')];var _0x4f2cab=JSON[_0x7bb4('0x70')](_0x2af623[_0x7bb4('0x35')][_0x29fbb6])[_0x7bb4('0x71')];_0xa24691['where'](_0x7bb4('0x72'),_0x1ff955,_0x4f2cab);}else{if(_0x2af623['query'][_0x29fbb6]===_0x7bb4('0x73')){_0xa24691[_0x7bb4('0x6b')]('i.'+_0x29fbb6+'\x20IS\x20NULL');}else{_0xa24691[_0x7bb4('0x6b')]('i.'+_0x29fbb6+'\x20=\x20?',_0x2af623[_0x7bb4('0x35')][_0x29fbb6]);}}});}if(_0x2af623[_0x7bb4('0x35')]['read']){if(_0x2af623[_0x7bb4('0x35')]['read']==0x1){_0xa24691[_0x7bb4('0x59')](_0x7bb4('0x74'));}else{_0xa24691[_0x7bb4('0x59')](_0x7bb4('0x75'));}}if(_0x2af623['query'][_0x7bb4('0x76')]){_0x524ad9=_[_0x7bb4('0x77')](_0x2af623['query'][_0x7bb4('0x76')])?_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x76')]:new Array(_0x2af623[_0x7bb4('0x35')]['tag']);_0x524ad9[_0x7bb4('0x2d')](function(_0x54b3c8){_0x17e20c['or'](_0x7bb4('0x78'),'%,'+_0x54b3c8+',%');});}if(_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x79')]){var _0x4d2f0b=_0x2af623['query'][_0x7bb4('0x79')][_0x7bb4('0x7a')]('\x5c','\x5c\x5c')[_0x7bb4('0x7a')](/'/g,'\x27\x27');if(qs[_0x7bb4('0x7b')](_0x4d2f0b)){_0x2380d0['or'](_0x7bb4('0x7c'),_0x4d2f0b+'%')['or']('i.phone\x20LIKE\x20?',_0x4d2f0b+'%');}else{_0x2380d0['or']('MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs['getFullTextValue'](_0x4d2f0b))['or'](_0x7bb4('0x7d'),_0x4d2f0b+'%');}}}_0xa24691[_0x7bb4('0x6b')](_0x2380d0);_0xa24691[_0x7bb4('0x7e')]('i.id');var _0x10cd77={'type':db[_0x7bb4('0x7f')][_0x7bb4('0x80')]['SELECT'],'raw':!![]};var _0x114e4a=_0xa24691[_0x7bb4('0x81')]();_0x114e4a[_0x7bb4('0x40')](_0x7bb4('0x82'));_0x114e4a[_0x7bb4('0x40')](_0x7bb4('0x83'),_0x7bb4('0x84'));if(_0x733e22[_0x7bb4('0x3e')]){_0x733e22[_0x7bb4('0x3e')][_0x7bb4('0x2d')](function(_0x2d74fc){_0xa24691[_0x7bb4('0x3e')]('i.'+_0x2d74fc[0x0],_0x2d74fc[0x1]===_0x7bb4('0x85')?![]:!![]);});}if(!_[_0x7bb4('0x86')](_0x524ad9)){_0xa24691[_0x7bb4('0x59')](_0x17e20c);_0x114e4a[_0x7bb4('0x6b')](_0x7bb4('0x87'),_0x524ad9);}BPromise[_0x7bb4('0x88')]()['then'](function(){if(!_0x279883){if(_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x89')]||_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x8a')])return;_0x114e4a['where'](_0x7bb4('0x8b'));_0xa24691[_0x7bb4('0x6b')](_0x7bb4('0x8b'));return;}return _0x2af623[_0x7bb4('0x8c')][_0x7bb4('0x8d')]({'attributes':['id'],'raw':!![]})[_0x7bb4('0x23')](function(_0xf266bc){if(_[_0x7bb4('0x86')](_0xf266bc)){_0x114e4a[_0x7bb4('0x6b')](_0x7bb4('0x8e'));_0xa24691[_0x7bb4('0x6b')](_0x7bb4('0x8e'));}else{_0x114e4a['where'](_0x7bb4('0x6c'),_[_0x7bb4('0x28')](_0xf266bc,'id'));_0xa24691[_0x7bb4('0x6b')]('i.WhatsappAccountId\x20IN\x20?',_[_0x7bb4('0x28')](_0xf266bc,'id'));}});})[_0x7bb4('0x23')](function(){db[_0x7bb4('0x8f')][_0x7bb4('0x35')](_0x114e4a['toString'](),_0x10cd77)[_0x7bb4('0x23')](function(_0x13d107){_0x47d1b4[_0x7bb4('0x1c')]=_0x13d107[_0x7bb4('0x3a')];if(_0x47d1b4['count']===0x0)return[];return db[_0x7bb4('0x8f')][_0x7bb4('0x35')](_0x28ed7d[_0x7bb4('0x90')](),_0x10cd77)[_0x7bb4('0x23')](function(_0x15a4a4){_0x6bcaed=_[_0x7bb4('0x91')](_0x15a4a4,'id');_0x10cd77=_[_0x7bb4('0x92')](_0x10cd77,{'model':db['WhatsappInteraction'],'mapToModel':!![],'raw':!![],'nest':!![]});if(_0x2af623[_0x7bb4('0x35')][_0x7bb4('0x39')]){_0x733e22[_0x7bb4('0x38')][_0x7bb4('0x2d')](function(_0x1440a3){_0xa24691[_0x7bb4('0x40')]('i.'+_0x1440a3);});}else{_0xa24691[_0x7bb4('0x40')](_0x7bb4('0x83'),'unreadMessages');_0xa24691[_0x7bb4('0x40')]('a.key',_0x7bb4('0x93'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0x94'),_0x7bb4('0x95'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0x96'));_0xa24691['field']('c.firstName',_0x7bb4('0x97'));_0xa24691['field'](_0x7bb4('0x98'),_0x7bb4('0x99'));_0xa24691['field'](_0x7bb4('0x9a'),_0x7bb4('0x9b'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0x9c'),_0x7bb4('0x9d'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0x9e'),_0x7bb4('0x9f'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0xa0'),_0x7bb4('0xa1'));_0xa24691[_0x7bb4('0x40')](_0x7bb4('0xa2'),_0x7bb4('0xa3'));_0xa24691['field'](_0x7bb4('0xa4'),_0x7bb4('0xa5'));_0xa24691[_0x7bb4('0x40')]('GROUP_CONCAT(DISTINCT\x20t.id)',_0x7bb4('0x2b'));}if(_0x733e22['limit'])_0xa24691[_0x7bb4('0x3d')](_0x733e22['limit']);if(_0x733e22[_0x7bb4('0x1d')])_0xa24691['offset'](_0x733e22[_0x7bb4('0x1d')]);return db[_0x7bb4('0x8f')][_0x7bb4('0x35')](_0xa24691[_0x7bb4('0x90')](),_0x10cd77);})[_0x7bb4('0x23')](function(_0x4ab6c3){_0x3f89fd[_0x7bb4('0x6b')](_0x7bb4('0xa6'),_[_0x7bb4('0x28')](_0x4ab6c3,'id'));return db['sequelize'][_0x7bb4('0x35')](_0x3f89fd['toString'](),_0x10cd77)[_0x7bb4('0x23')](function(_0x91ca76){var _0x121c3c=_[_0x7bb4('0xa7')](_0x91ca76,_0x7bb4('0xa8'));var _0x3cd176=[];_0x4ab6c3[_0x7bb4('0x2d')](function(_0x4164e0){_0x3cd176[_0x7bb4('0x2e')](updateWhatsappInteraction(_0x4164e0,_0x6bcaed,_0x121c3c));});return BPromise[_0x7bb4('0xa9')](_0x3cd176);});});})['then'](function(_0x40f036){_0x47d1b4[_0x7bb4('0xaa')]=_0x40f036;return _0x47d1b4;})[_0x7bb4('0x23')](respondWithFilteredResult(_0x342360,_0x733e22));})[_0x7bb4('0x2f')](handleError(_0x342360,null));};exports[_0x7bb4('0xab')]=function(_0x268fb4,_0x3c9eb4){var _0x1f382a={'raw':![],'where':{'id':_0x268fb4[_0x7bb4('0xac')]['id']}},_0x44b5ce={};_0x44b5ce['model']=_[_0x7bb4('0x69')](db['WhatsappInteraction'][_0x7bb4('0x31')]);_0x44b5ce[_0x7bb4('0x35')]=_[_0x7bb4('0x69')](_0x268fb4[_0x7bb4('0x35')]);_0x44b5ce[_0x7bb4('0x36')]=_[_0x7bb4('0x37')](_0x44b5ce[_0x7bb4('0x34')],_0x44b5ce[_0x7bb4('0x35')]);_0x1f382a[_0x7bb4('0x38')]=_[_0x7bb4('0x37')](_0x44b5ce[_0x7bb4('0x34')],qs[_0x7bb4('0x39')](_0x268fb4[_0x7bb4('0x35')][_0x7bb4('0x39')]));_0x1f382a[_0x7bb4('0x38')]=_0x1f382a[_0x7bb4('0x38')][_0x7bb4('0x3a')]?_0x1f382a[_0x7bb4('0x38')]:_0x44b5ce[_0x7bb4('0x34')];if(_0x268fb4['query'][_0x7bb4('0xad')]){_0x1f382a['include']=[{'all':!![]}];}_0x1f382a=_[_0x7bb4('0x92')]({},_0x1f382a,_0x268fb4[_0x7bb4('0xae')]);return db[_0x7bb4('0x30')][_0x7bb4('0x57')](_0x1f382a)[_0x7bb4('0x23')](handleEntityNotFound(_0x3c9eb4,null))[_0x7bb4('0x23')](respondWithResult(_0x3c9eb4,null))[_0x7bb4('0x2f')](handleError(_0x3c9eb4,null));};exports[_0x7bb4('0xaf')]=function(_0x110f36,_0x56ea8c){return db[_0x7bb4('0x30')][_0x7bb4('0xaf')](_0x110f36['body'],{})[_0x7bb4('0x23')](respondWithResult(_0x56ea8c,0xc9))[_0x7bb4('0x2f')](handleError(_0x56ea8c,null));};exports[_0x7bb4('0x22')]=function(_0x22d7da,_0x1b50ee){if(_0x22d7da[_0x7bb4('0x68')]['id']){delete _0x22d7da[_0x7bb4('0x68')]['id'];}return db[_0x7bb4('0x30')][_0x7bb4('0x57')]({'where':{'id':_0x22d7da[_0x7bb4('0xac')]['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x1b50ee,null))[_0x7bb4('0x23')](saveUpdates(_0x22d7da[_0x7bb4('0x68')],null))[_0x7bb4('0x23')](respondWithResult(_0x1b50ee,null))[_0x7bb4('0x2f')](handleError(_0x1b50ee,null));};exports[_0x7bb4('0x24')]=function(_0x259cf5,_0x479fb6){return db[_0x7bb4('0x30')]['find']({'where':{'id':_0x259cf5[_0x7bb4('0xac')]['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x479fb6,null))[_0x7bb4('0x23')](removeEntity(_0x479fb6,null))[_0x7bb4('0x2f')](handleError(_0x479fb6,null));};exports[_0x7bb4('0xb0')]=function(_0x20402a,_0x3e0248){return db['WhatsappInteraction'][_0x7bb4('0xb0')]()[_0x7bb4('0x23')](respondWithResult(_0x3e0248,null))[_0x7bb4('0x2f')](handleError(_0x3e0248,null));};exports[_0x7bb4('0xb1')]=function(_0x37627c,_0x1ea8ff,_0x1190e1){return db['WhatsappMessage']['find']({'where':{'id':_0x37627c[_0x7bb4('0xac')]['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x1ea8ff,null))[_0x7bb4('0x23')](function(_0x18eac9){if(_0x18eac9){return _0x18eac9['addMessage'](_0x37627c[_0x7bb4('0x68')][_0x7bb4('0xb2')],_[_0x7bb4('0xb3')](_0x37627c[_0x7bb4('0x68')],[_0x7bb4('0xb2'),'id'])||{});}})[_0x7bb4('0x23')](respondWithResult(_0x1ea8ff,null))[_0x7bb4('0x2f')](handleError(_0x1ea8ff,null));};exports[_0x7bb4('0xb4')]=function(_0x6ffd0e,_0x30be5d,_0x1c5a5d){var _0x577b0f={'raw':![],'where':{}};var _0x57f505={};var _0x296973={'count':0x0,'rows':[]};return db[_0x7bb4('0x30')]['findOne']({'where':{'id':_0x6ffd0e[_0x7bb4('0xac')]['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x30be5d,null))[_0x7bb4('0x23')](function(_0x482d01){if(_0x482d01){_0x57f505['model']=_[_0x7bb4('0x69')](db[_0x7bb4('0xb5')][_0x7bb4('0x31')]);_0x57f505[_0x7bb4('0x35')]=_[_0x7bb4('0x69')](_0x6ffd0e[_0x7bb4('0x35')]);_0x57f505[_0x7bb4('0x36')]=_[_0x7bb4('0x37')](_0x57f505[_0x7bb4('0x34')],_0x57f505[_0x7bb4('0x35')]);_0x577b0f[_0x7bb4('0x38')]=_['intersection'](_0x57f505['model'],qs[_0x7bb4('0x39')](_0x6ffd0e[_0x7bb4('0x35')][_0x7bb4('0x39')]));_0x577b0f[_0x7bb4('0x38')]=_0x577b0f['attributes']['length']?_0x577b0f[_0x7bb4('0x38')]:_0x57f505[_0x7bb4('0x34')];if(!_0x6ffd0e['query']['hasOwnProperty'](_0x7bb4('0x3c'))){_0x577b0f[_0x7bb4('0x3d')]=qs[_0x7bb4('0x3d')](_0x6ffd0e['query'][_0x7bb4('0x3d')]);_0x577b0f[_0x7bb4('0x1d')]=qs[_0x7bb4('0x1d')](_0x6ffd0e['query']['offset']);}_0x577b0f['order']=qs[_0x7bb4('0x3f')](_0x6ffd0e[_0x7bb4('0x35')][_0x7bb4('0x3f')]);_0x577b0f[_0x7bb4('0x6b')]=qs[_0x7bb4('0x36')](_[_0x7bb4('0xb6')](_0x6ffd0e['query'],_0x57f505[_0x7bb4('0x36')]));_0x577b0f[_0x7bb4('0x6b')][_0x7bb4('0xa8')]=_0x482d01['id'];if(_0x6ffd0e[_0x7bb4('0x35')][_0x7bb4('0x79')]){_0x577b0f[_0x7bb4('0x6b')]=_[_0x7bb4('0x92')](_0x577b0f[_0x7bb4('0x6b')],{'$or':_[_0x7bb4('0x28')](_0x577b0f[_0x7bb4('0x38')],function(_0x5922c5){var _0x4577b4={};_0x4577b4[_0x5922c5]={'$like':'%'+_0x6ffd0e[_0x7bb4('0x35')]['filter']+'%'};return _0x4577b4;})});}if(_0x6ffd0e[_0x7bb4('0x35')]['$gte']){var _0x2c79ad=_0x6ffd0e[_0x7bb4('0x35')][_0x7bb4('0x6f')][_0x7bb4('0x2c')](',');var _0x5c0369={};_0x5c0369[_0x2c79ad[0x0]]={'$gte':moment(_0x2c79ad[0x1])[_0x7bb4('0xb7')](_0x7bb4('0xb8'))};_0x577b0f[_0x7bb4('0x6b')]=_['merge'](_0x577b0f[_0x7bb4('0x6b')],_0x5c0369);}_0x577b0f=_[_0x7bb4('0x92')]({},_0x577b0f,_0x6ffd0e[_0x7bb4('0xae')]);return db[_0x7bb4('0xb5')][_0x7bb4('0x1c')]({'where':_0x577b0f[_0x7bb4('0x6b')]})['then'](function(_0x41c1b7){_0x296973[_0x7bb4('0x1c')]=_0x41c1b7;if(_0x6ffd0e[_0x7bb4('0x35')]['includeAll']){_0x577b0f[_0x7bb4('0xb9')]=[{'all':!![]}];}return db['WhatsappMessage'][_0x7bb4('0xba')](_0x577b0f);})[_0x7bb4('0x23')](function(_0x2936a3){_0x296973[_0x7bb4('0xaa')]=_0x2936a3;return _0x296973;});}})[_0x7bb4('0x23')](respondWithFilteredResult(_0x30be5d,_0x577b0f))[_0x7bb4('0x2f')](handleError(_0x30be5d,null));};exports[_0x7bb4('0xbb')]=function(_0x14ed8f,_0x1799e9,_0x123c1f){return db['WhatsappInteraction'][_0x7bb4('0x57')]({'where':{'id':_0x14ed8f[_0x7bb4('0xac')]['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x1799e9,null))[_0x7bb4('0x23')](function(_0x2a9bdb){if(_0x2a9bdb){return _0x2a9bdb[_0x7bb4('0xbc')](_0x14ed8f[_0x7bb4('0x68')][_0x7bb4('0xb2')],_['omit'](_0x14ed8f[_0x7bb4('0x68')],[_0x7bb4('0xb2'),'id'])||{})[_0x7bb4('0xbd')](function(){return db['Tag'][_0x7bb4('0xba')]({'attributes':['id',_0x7bb4('0x27'),'color'],'where':{'id':_0x14ed8f[_0x7bb4('0x68')]['ids']}});})[_0x7bb4('0x23')](function(_0x563da4){socket[_0x7bb4('0xbe')](_0x7bb4('0xbf'),{'id':Number(_0x14ed8f['params']['id']),'tags':_0x563da4||[]});return{'id':Number(_0x14ed8f[_0x7bb4('0xac')]['id']),'tags':_0x563da4||[]};});}})['then'](respondWithResult(_0x1799e9,null))[_0x7bb4('0x2f')](handleError(_0x1799e9,null));};exports[_0x7bb4('0xc0')]=function(_0x2221d4,_0x485459,_0x1be447){return db[_0x7bb4('0x30')]['find']({'where':{'id':_0x2221d4['params']['id']}})[_0x7bb4('0x23')](handleEntityNotFound(_0x485459,null))[_0x7bb4('0x23')](function(_0x7fdb5c){if(_0x7fdb5c){return _0x7fdb5c[_0x7bb4('0xc0')](_0x2221d4[_0x7bb4('0x35')][_0x7bb4('0xb2')]);}})['then'](respondWithStatusCode(_0x485459,null))[_0x7bb4('0x2f')](handleError(_0x485459,null));};exports[_0x7bb4('0xc1')]=function(_0x2dea2a,_0x5f1708){var _0x1168bb=moment()[_0x7bb4('0xc2')]()['toString']();var _0x376932=path['join'](config['root'],_0x7bb4('0xc3'),_0x7bb4('0xc4'),_0x7bb4('0xc5'));var _0x36ad80=path[_0x7bb4('0xc6')](config[_0x7bb4('0xc7')],_0x7bb4('0xc3'),_0x7bb4('0xc4'),'attachments');var _0x121d3c=path['join'](_0x376932,_0x1168bb);var _0x49e5f8=util[_0x7bb4('0xb7')](_0x7bb4('0xc8'),_0x2dea2a[_0x7bb4('0xac')]['id'],_0x1168bb);var _0x5c37c9=path[_0x7bb4('0xc6')](_0x376932,_0x49e5f8);var _0x1cb5b8=[];_0x1cb5b8[_0x7bb4('0x2e')]({'model':db[_0x7bb4('0xc9')],'as':_0x7bb4('0xc9'),'attributes':['id',_0x7bb4('0x29')],'raw':!![]});_0x1cb5b8['push']({'model':db[_0x7bb4('0xca')],'as':_0x7bb4('0x5b'),'attributes':['id','firstName',_0x7bb4('0xcb')],'raw':!![]});if(_0x2dea2a[_0x7bb4('0x35')][_0x7bb4('0xcc')]){_0x1cb5b8[_0x7bb4('0x2e')]({'model':db[_0x7bb4('0xcd')],'as':_0x7bb4('0xcd'),'raw':!![]});}var _0x14df38=[{'model':db[_0x7bb4('0xb5')],'as':_0x7bb4('0xce'),'attributes':['id','body','createdAt',_0x7bb4('0xcf'),_0x7bb4('0xd0'),_0x7bb4('0xd1')],'include':_0x1cb5b8}];_0x14df38[_0x7bb4('0x2e')]({'model':db['WhatsappAccount'],'as':_0x7bb4('0xd2'),'attributes':['id',_0x7bb4('0x27')]});_0x14df38['push']({'model':db[_0x7bb4('0xc9')],'as':_0x7bb4('0xd3'),'attributes':['id','fullname']});return db[_0x7bb4('0x30')][_0x7bb4('0x57')]({'where':{'id':_0x2dea2a[_0x7bb4('0xac')]['id']},'include':_0x14df38})[_0x7bb4('0x23')](handleEntityNotFound(_0x5f1708,null))[_0x7bb4('0x23')](function(_0x10abf3){if(_0x10abf3){var _0x21b9b2=_0x10abf3[_0x7bb4('0xd4')]({'plain':!![]});fs[_0x7bb4('0xd5')](_0x121d3c);var _0x4ee274={'format':'A4','border':'10px','header':{'height':_0x7bb4('0xd6'),'contents':{'first':_0x7bb4('0xd7')}},'footer':{'height':_0x7bb4('0xd8'),'contents':{'default':util[_0x7bb4('0xb7')](_0x7bb4('0xd9'),util[_0x7bb4('0xb7')](_0x7bb4('0xda'),_0x7bb4('0xdb'),_0x21b9b2['id']),moment()['format']('YYYY-MM-DD')['toString']())}}};var _0x13842a={'channel':'Whatsapp','account':_0x21b9b2[_0x7bb4('0xd2')][_0x7bb4('0x27')],'agent':_0x21b9b2['Owner']?_0x21b9b2['Owner'][_0x7bb4('0x29')]:_0x7bb4('0xdc'),'createdAt':moment(_0x21b9b2[_0x7bb4('0x6e')])[_0x7bb4('0xb7')](_0x7bb4('0xb8'))['toString'](),'closedAt':_0x21b9b2[_0x7bb4('0xdd')]?moment(_0x21b9b2[_0x7bb4('0xde')])[_0x7bb4('0xb7')](_0x7bb4('0xb8'))[_0x7bb4('0x90')]():'','disposition':_0x21b9b2['disposition'],'messages':_(_0x21b9b2[_0x7bb4('0xce')])[_0x7bb4('0x79')]({'secret':![]})[_0x7bb4('0x28')](function(_0x4bfd16){if(_0x4bfd16[_0x7bb4('0xcd')]){var _0x6e28b7=path[_0x7bb4('0xc6')](_0x36ad80,_0x4bfd16[_0x7bb4('0xcd')][_0x7bb4('0xdf')]);if(fs[_0x7bb4('0xe0')](_0x6e28b7)){fs[_0x7bb4('0xe1')](_0x6e28b7)[_0x7bb4('0xe2')](fs[_0x7bb4('0xe3')](path[_0x7bb4('0xc6')](_0x121d3c,_0x4bfd16[_0x7bb4('0xcd')][_0x7bb4('0xdf')])));}}return{'date':moment(_0x4bfd16[_0x7bb4('0x6e')])[_0x7bb4('0xb7')](_0x7bb4('0xb8'))[_0x7bb4('0x90')](),'sender':_0x4bfd16[_0x7bb4('0xcf')]==='out'?_0x4bfd16[_0x7bb4('0xc9')]?_0x4bfd16[_0x7bb4('0xc9')]['fullname']:_0x7bb4('0xe4'):_0x4bfd16[_0x7bb4('0x5b')][_0x7bb4('0xe5')]+(_0x4bfd16[_0x7bb4('0x5b')][_0x7bb4('0xcb')]?'\x20'+_0x4bfd16[_0x7bb4('0x5b')][_0x7bb4('0xcb')]:''),'body':_0x4bfd16[_0x7bb4('0xcd')]?_0x4bfd16[_0x7bb4('0xcd')]['basename']:_0x4bfd16[_0x7bb4('0x68')],'direction':_0x4bfd16[_0x7bb4('0xcf')]===_0x7bb4('0xe6')?'A':'C','secret':_0x4bfd16[_0x7bb4('0xd0')],'read':_0x4bfd16[_0x7bb4('0xd1')],'attachment':_0x4bfd16[_0x7bb4('0xcd')]};})[_0x7bb4('0x58')]()};return ejs[_0x7bb4('0xe7')](path[_0x7bb4('0xc6')](config[_0x7bb4('0xc7')],_0x7bb4('0xc3'),_0x7bb4('0xe8'),_0x7bb4('0xe9')),{'interaction':_0x13842a})[_0x7bb4('0x23')](function(_0x5e9e8f){return new BPromise(function(_0xb6f40,_0x417bbb){pdf['create'](_0x5e9e8f,_0x4ee274)[_0x7bb4('0xea')](path[_0x7bb4('0xc6')](_0x121d3c,_0x7bb4('0xeb')+_0x21b9b2['id']+'-'+_0x1168bb+_0x7bb4('0xec')),function(_0x1419e5,_0x1449d8){if(_0x1419e5)return _0x417bbb(_0x1419e5);_0xb6f40(_0x1449d8);});});})[_0x7bb4('0x23')](function(){return new BPromise(function(_0x3bee7b,_0x32d4d6){zipdir(_0x121d3c,{'saveTo':_0x5c37c9},function(_0x45adf2,_0x226bec){if(_0x45adf2)return _0x32d4d6(_0x45adf2);return _0x3bee7b(_0x226bec);});})['then'](function(){return new BPromise(function(_0x1ff8b0,_0x4d1517){rimraf(_0x121d3c,function(_0x39c2b3){if(_0x39c2b3)_0x4d1517(_0x39c2b3);return _0x1ff8b0();});});})[_0x7bb4('0x23')](function(){return _0x5f1708[_0x7bb4('0xc1')](_0x5c37c9,_0x49e5f8,function(_0x567af5){if(_0x567af5){console[_0x7bb4('0xed')](_0x7bb4('0xee'),_0x567af5);}else{fs['unlinkSync'](_0x5c37c9);}});});});}else{return _0x5f1708['sendStatus'](0xc8);}})[_0x7bb4('0x2f')](handleError(_0x5f1708,null));};
\ No newline at end of file
+var _0x71a3=['keys','WhatsappInteraction','intersection','attributes','model','fields','length','includeAll','include','merge','options','create','body','find','destroy','WhatsappMessage','addMessage','ids','findOne','filters','hasOwnProperty','nolimit','order','sort','where','pick','WhatsappInteractionId','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','setTags','omit','Tag','color','emit','whatsappInteractionTags:save','download','unix','toString','join','root','files','tmp','attachments','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','Attachment','Messages','createdAt','direction','read','WhatsappAccount','Account','Owner','mkdirSync','Whatsapp','N.A.','closed','closedAt','existsSync','pipe','createWriteStream','out','System','firstName','lastName','basename','secret','value','server','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','log','unlinkSync','zip-dir','moment','util','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','end','json','offset','limit','undefined','count','status','set','Content-Range','update','then','error','stack','name','send','index','map','rawAttributes','type','key','findAll','whatsapp','query','user','catch','show','params'];(function(_0x28f632,_0x19c6b5){var _0x1bbfa2=function(_0x403808){while(--_0x403808){_0x28f632['push'](_0x28f632['shift']());}};_0x1bbfa2(++_0x19c6b5);}(_0x71a3,0xd4));var _0x371a=function(_0x23b980,_0x57697f){_0x23b980=_0x23b980-0x0;var _0x475354=_0x71a3[_0x23b980];return _0x475354;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x371a('0x0'));var moment=require(_0x371a('0x1'));var BPromise=require('bluebird');var util=require(_0x371a('0x2'));var path=require('path');var ejs=require(_0x371a('0x3'));var fs=require('fs');var _=require(_0x371a('0x4'));var Redis=require(_0x371a('0x5'));var interaction=require(_0x371a('0x6'));var qs=require(_0x371a('0x7'));var pdf=require(_0x371a('0x8'));var logger=require(_0x371a('0x9'))(_0x371a('0xa'));var config=require('../../config/environment');var db=require(_0x371a('0xb'))['db'];config['redis']=_['defaults'](config[_0x371a('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x371a('0xd'))(new Redis(config['redis']));require(_0x371a('0xe'))[_0x371a('0xf')](socket);function respondWithStatusCode(_0x4b1053,_0x140ef8){_0x140ef8=_0x140ef8||0xcc;return function(_0x475f02){if(_0x475f02){return _0x4b1053[_0x371a('0x10')](_0x140ef8);}return _0x4b1053['status'](_0x140ef8)[_0x371a('0x11')]();};}function respondWithResult(_0x56b36c,_0x4ba50d){_0x4ba50d=_0x4ba50d||0xc8;return function(_0x4afb2f){if(_0x4afb2f){return _0x56b36c['status'](_0x4ba50d)[_0x371a('0x12')](_0x4afb2f);}};}function respondWithFilteredResult(_0x13bb89,_0x1d0109){return function(_0x2c8412){if(_0x2c8412){var _0x15ef45=typeof _0x1d0109[_0x371a('0x13')]==='undefined'&&typeof _0x1d0109[_0x371a('0x14')]===_0x371a('0x15');var _0x14d290=_0x2c8412[_0x371a('0x16')];var _0x224252=_0x15ef45?0x0:_0x1d0109[_0x371a('0x13')];var _0x59a4c4=_0x15ef45?_0x2c8412[_0x371a('0x16')]:_0x1d0109[_0x371a('0x13')]+_0x1d0109[_0x371a('0x14')];var _0x10de37;if(_0x59a4c4>=_0x14d290){_0x59a4c4=_0x14d290;_0x10de37=0xc8;}else{_0x10de37=0xce;}_0x13bb89[_0x371a('0x17')](_0x10de37);return _0x13bb89[_0x371a('0x18')](_0x371a('0x19'),_0x224252+'-'+_0x59a4c4+'/'+_0x14d290)['json'](_0x2c8412);}return null;};}function saveUpdates(_0x48acee){return function(_0x2ad3da){if(_0x2ad3da){return _0x2ad3da[_0x371a('0x1a')](_0x48acee)[_0x371a('0x1b')](function(_0x5d7c85){return _0x5d7c85;});}return null;};}function removeEntity(_0x534ba5){return function(_0x18ca74){if(_0x18ca74){return _0x18ca74['destroy']()[_0x371a('0x1b')](function(){_0x534ba5[_0x371a('0x17')](0xcc)[_0x371a('0x11')]();});}};}function handleEntityNotFound(_0x319564){return function(_0x35f633){if(!_0x35f633){_0x319564[_0x371a('0x10')](0x194);}return _0x35f633;};}function handleError(_0xb85239,_0x5ea12e){_0x5ea12e=_0x5ea12e||0x1f4;return function(_0x24e7dd){logger[_0x371a('0x1c')](_0x24e7dd[_0x371a('0x1d')]);if(_0x24e7dd[_0x371a('0x1e')]){delete _0x24e7dd[_0x371a('0x1e')];}_0xb85239['status'](_0x5ea12e)[_0x371a('0x1f')](_0x24e7dd);};}exports[_0x371a('0x20')]=function(_0x184b4d,_0x5b097d){var _0x1be11f={};var _0x2de48=_[_0x371a('0x21')](db['WhatsappInteraction'][_0x371a('0x22')],function(_0x416f62){return{'name':_0x416f62['fieldName'],'type':_0x416f62[_0x371a('0x23')][_0x371a('0x24')]};});_0x1be11f=qs['getOptions'](_0x2de48,_0x184b4d);return interaction[_0x371a('0x25')](_0x371a('0x26'),_0x184b4d[_0x371a('0x27')],_0x184b4d[_0x371a('0x28')],_0x1be11f,_0x2de48)['then'](respondWithFilteredResult(_0x5b097d,_0x1be11f))[_0x371a('0x29')](handleError(_0x5b097d,null));};exports[_0x371a('0x2a')]=function(_0x32c25e,_0x2fce28){var _0xc0449e={'raw':![],'where':{'id':_0x32c25e[_0x371a('0x2b')]['id']}},_0x42d0c0={};_0x42d0c0['model']=_[_0x371a('0x2c')](db[_0x371a('0x2d')][_0x371a('0x22')]);_0x42d0c0[_0x371a('0x27')]=_[_0x371a('0x2c')](_0x32c25e[_0x371a('0x27')]);_0x42d0c0['filters']=_[_0x371a('0x2e')](_0x42d0c0['model'],_0x42d0c0[_0x371a('0x27')]);_0xc0449e[_0x371a('0x2f')]=_[_0x371a('0x2e')](_0x42d0c0[_0x371a('0x30')],qs[_0x371a('0x31')](_0x32c25e[_0x371a('0x27')][_0x371a('0x31')]));_0xc0449e[_0x371a('0x2f')]=_0xc0449e[_0x371a('0x2f')][_0x371a('0x32')]?_0xc0449e['attributes']:_0x42d0c0[_0x371a('0x30')];if(_0x32c25e[_0x371a('0x27')][_0x371a('0x33')]){_0xc0449e[_0x371a('0x34')]=[{'all':!![]}];}_0xc0449e=_[_0x371a('0x35')]({},_0xc0449e,_0x32c25e[_0x371a('0x36')]);return db['WhatsappInteraction']['find'](_0xc0449e)[_0x371a('0x1b')](handleEntityNotFound(_0x2fce28,null))[_0x371a('0x1b')](respondWithResult(_0x2fce28,null))['catch'](handleError(_0x2fce28,null));};exports[_0x371a('0x37')]=function(_0x1d9fc2,_0xf8528d){return db[_0x371a('0x2d')][_0x371a('0x37')](_0x1d9fc2[_0x371a('0x38')],{})[_0x371a('0x1b')](respondWithResult(_0xf8528d,0xc9))[_0x371a('0x29')](handleError(_0xf8528d,null));};exports['update']=function(_0x181d9e,_0x56d78e){if(_0x181d9e['body']['id']){delete _0x181d9e[_0x371a('0x38')]['id'];}return db[_0x371a('0x2d')][_0x371a('0x39')]({'where':{'id':_0x181d9e[_0x371a('0x2b')]['id']}})['then'](handleEntityNotFound(_0x56d78e,null))[_0x371a('0x1b')](saveUpdates(_0x181d9e['body'],null))[_0x371a('0x1b')](respondWithResult(_0x56d78e,null))[_0x371a('0x29')](handleError(_0x56d78e,null));};exports[_0x371a('0x3a')]=function(_0x1076eb,_0x41477b){return db['WhatsappInteraction'][_0x371a('0x39')]({'where':{'id':_0x1076eb[_0x371a('0x2b')]['id']}})[_0x371a('0x1b')](handleEntityNotFound(_0x41477b,null))[_0x371a('0x1b')](removeEntity(_0x41477b,null))['catch'](handleError(_0x41477b,null));};exports['describe']=function(_0x2485e5,_0x112e1f){return db[_0x371a('0x2d')]['describe']()['then'](respondWithResult(_0x112e1f,null))['catch'](handleError(_0x112e1f,null));};exports['addMessage']=function(_0x355ba3,_0x2f044c){return db[_0x371a('0x3b')][_0x371a('0x39')]({'where':{'id':_0x355ba3[_0x371a('0x2b')]['id']}})[_0x371a('0x1b')](handleEntityNotFound(_0x2f044c,null))[_0x371a('0x1b')](function(_0x32f6cf){if(_0x32f6cf){return _0x32f6cf[_0x371a('0x3c')](_0x355ba3['body'][_0x371a('0x3d')],_['omit'](_0x355ba3[_0x371a('0x38')],[_0x371a('0x3d'),'id'])||{});}})[_0x371a('0x1b')](respondWithResult(_0x2f044c,null))[_0x371a('0x29')](handleError(_0x2f044c,null));};exports['getMessages']=function(_0x81e53b,_0x458d59){var _0x455de6={'raw':![],'where':{}};var _0x446f89={};var _0x453744={'count':0x0,'rows':[]};return db[_0x371a('0x2d')][_0x371a('0x3e')]({'where':{'id':_0x81e53b[_0x371a('0x2b')]['id']}})[_0x371a('0x1b')](handleEntityNotFound(_0x458d59,null))[_0x371a('0x1b')](function(_0x5461fc){if(_0x5461fc){_0x446f89[_0x371a('0x30')]=_['keys'](db[_0x371a('0x3b')][_0x371a('0x22')]);_0x446f89[_0x371a('0x27')]=_[_0x371a('0x2c')](_0x81e53b[_0x371a('0x27')]);_0x446f89[_0x371a('0x3f')]=_[_0x371a('0x2e')](_0x446f89[_0x371a('0x30')],_0x446f89[_0x371a('0x27')]);_0x455de6[_0x371a('0x2f')]=_[_0x371a('0x2e')](_0x446f89['model'],qs[_0x371a('0x31')](_0x81e53b[_0x371a('0x27')][_0x371a('0x31')]));_0x455de6[_0x371a('0x2f')]=_0x455de6[_0x371a('0x2f')][_0x371a('0x32')]?_0x455de6['attributes']:_0x446f89[_0x371a('0x30')];if(!_0x81e53b[_0x371a('0x27')][_0x371a('0x40')](_0x371a('0x41'))){_0x455de6['limit']=qs[_0x371a('0x14')](_0x81e53b[_0x371a('0x27')][_0x371a('0x14')]);_0x455de6[_0x371a('0x13')]=qs[_0x371a('0x13')](_0x81e53b[_0x371a('0x27')][_0x371a('0x13')]);}_0x455de6[_0x371a('0x42')]=qs['sort'](_0x81e53b[_0x371a('0x27')][_0x371a('0x43')]);_0x455de6[_0x371a('0x44')]=qs[_0x371a('0x3f')](_[_0x371a('0x45')](_0x81e53b[_0x371a('0x27')],_0x446f89[_0x371a('0x3f')]));_0x455de6['where'][_0x371a('0x46')]=_0x5461fc['id'];if(_0x81e53b['query'][_0x371a('0x47')]){_0x455de6[_0x371a('0x44')]=_[_0x371a('0x35')](_0x455de6[_0x371a('0x44')],{'$or':_[_0x371a('0x21')](_0x455de6[_0x371a('0x2f')],function(_0x2f7b5d){var _0x37127f={};_0x37127f[_0x2f7b5d]={'$like':'%'+_0x81e53b[_0x371a('0x27')][_0x371a('0x47')]+'%'};return _0x37127f;})});}if(_0x81e53b['query'][_0x371a('0x48')]){var _0x3b22dc=_0x81e53b[_0x371a('0x27')][_0x371a('0x48')][_0x371a('0x49')](',');var _0x2b14ea={};_0x2b14ea[_0x3b22dc[0x0]]={'$gte':moment(_0x3b22dc[0x1])[_0x371a('0x4a')](_0x371a('0x4b'))};_0x455de6[_0x371a('0x44')]=_[_0x371a('0x35')](_0x455de6[_0x371a('0x44')],_0x2b14ea);}_0x455de6=_[_0x371a('0x35')]({},_0x455de6,_0x81e53b[_0x371a('0x36')]);return db[_0x371a('0x3b')][_0x371a('0x16')]({'where':_0x455de6[_0x371a('0x44')]})[_0x371a('0x1b')](function(_0x4fe8be){_0x453744[_0x371a('0x16')]=_0x4fe8be;if(_0x81e53b['query']['includeAll']){_0x455de6[_0x371a('0x34')]=[{'all':!![]}];}return db[_0x371a('0x3b')][_0x371a('0x25')](_0x455de6);})['then'](function(_0x5866c1){_0x453744[_0x371a('0x4c')]=_0x5866c1;return _0x453744;});}})[_0x371a('0x1b')](respondWithFilteredResult(_0x458d59,_0x455de6))[_0x371a('0x29')](handleError(_0x458d59,null));};exports[_0x371a('0x4d')]=function(_0x40e675,_0x1198f5){return db['WhatsappInteraction'][_0x371a('0x39')]({'where':{'id':_0x40e675[_0x371a('0x2b')]['id']}})[_0x371a('0x1b')](handleEntityNotFound(_0x1198f5,null))['then'](function(_0x48c5c2){if(_0x48c5c2){return _0x48c5c2[_0x371a('0x4e')](_0x40e675['body'][_0x371a('0x3d')],_[_0x371a('0x4f')](_0x40e675[_0x371a('0x38')],[_0x371a('0x3d'),'id'])||{})['spread'](function(){return db[_0x371a('0x50')][_0x371a('0x25')]({'attributes':['id',_0x371a('0x1e'),_0x371a('0x51')],'where':{'id':_0x40e675[_0x371a('0x38')]['ids']}});})[_0x371a('0x1b')](function(_0xd0f4f){socket[_0x371a('0x52')](_0x371a('0x53'),{'id':Number(_0x40e675[_0x371a('0x2b')]['id']),'tags':_0xd0f4f||[]});return{'id':Number(_0x40e675[_0x371a('0x2b')]['id']),'tags':_0xd0f4f||[]};});}})[_0x371a('0x1b')](respondWithResult(_0x1198f5,null))['catch'](handleError(_0x1198f5,null));};exports['removeTags']=function(_0xbed46d,_0x25235d){return db['WhatsappInteraction'][_0x371a('0x39')]({'where':{'id':_0xbed46d['params']['id']}})[_0x371a('0x1b')](handleEntityNotFound(_0x25235d,null))[_0x371a('0x1b')](function(_0x3b8ece){if(_0x3b8ece){return _0x3b8ece['removeTags'](_0xbed46d[_0x371a('0x27')][_0x371a('0x3d')]);}})[_0x371a('0x1b')](respondWithStatusCode(_0x25235d,null))[_0x371a('0x29')](handleError(_0x25235d,null));};exports[_0x371a('0x54')]=function(_0x508cbf,_0x520592){var _0x5342ee=moment()[_0x371a('0x55')]()[_0x371a('0x56')]();var _0x3314f3=path[_0x371a('0x57')](config[_0x371a('0x58')],'server',_0x371a('0x59'),_0x371a('0x5a'));var _0x3dddbf=path[_0x371a('0x57')](config[_0x371a('0x58')],'server','files',_0x371a('0x5b'));var _0x552018=path[_0x371a('0x57')](_0x3314f3,_0x5342ee);var _0x13e2c0=util['format'](_0x371a('0x5c'),_0x508cbf['params']['id'],_0x5342ee);var _0x237ca2=path[_0x371a('0x57')](_0x3314f3,_0x13e2c0);var _0x94482b=[];_0x94482b[_0x371a('0x5d')]({'model':db[_0x371a('0x5e')],'as':_0x371a('0x5e'),'attributes':['id',_0x371a('0x5f')],'raw':!![]});_0x94482b[_0x371a('0x5d')]({'model':db[_0x371a('0x60')],'as':_0x371a('0x61'),'attributes':['id','firstName','lastName'],'raw':!![]});if(_0x508cbf[_0x371a('0x27')][_0x371a('0x5b')]){_0x94482b[_0x371a('0x5d')]({'model':db[_0x371a('0x62')],'as':_0x371a('0x62'),'raw':!![]});}var _0x18de40=[{'model':db['WhatsappMessage'],'as':_0x371a('0x63'),'attributes':['id','body',_0x371a('0x64'),_0x371a('0x65'),'secret',_0x371a('0x66')],'include':_0x94482b}];_0x18de40[_0x371a('0x5d')]({'model':db[_0x371a('0x67')],'as':_0x371a('0x68'),'attributes':['id',_0x371a('0x1e')]});_0x18de40[_0x371a('0x5d')]({'model':db[_0x371a('0x5e')],'as':_0x371a('0x69'),'attributes':['id',_0x371a('0x5f')]});return db[_0x371a('0x2d')][_0x371a('0x39')]({'where':{'id':_0x508cbf['params']['id']},'include':_0x18de40})['then'](handleEntityNotFound(_0x520592,null))[_0x371a('0x1b')](function(_0x23ba99){if(_0x23ba99){var _0x523fd4=_0x23ba99['get']({'plain':!![]});fs[_0x371a('0x6a')](_0x552018);var _0x5b154c={'channel':_0x371a('0x6b'),'account':_0x523fd4[_0x371a('0x68')][_0x371a('0x1e')],'agent':_0x523fd4[_0x371a('0x69')]?_0x523fd4[_0x371a('0x69')]['fullname']:_0x371a('0x6c'),'createdAt':moment(_0x523fd4[_0x371a('0x64')])['format'](_0x371a('0x4b'))[_0x371a('0x56')](),'closedAt':_0x523fd4[_0x371a('0x6d')]?moment(_0x523fd4[_0x371a('0x6e')])[_0x371a('0x4a')](_0x371a('0x4b'))['toString']():'','disposition':_0x523fd4['disposition'],'messages':_(_0x523fd4[_0x371a('0x63')])[_0x371a('0x47')]({'secret':![]})[_0x371a('0x21')](function(_0x266708){if(_0x266708['Attachment']){var _0x42240d=path[_0x371a('0x57')](_0x3dddbf,_0x266708[_0x371a('0x62')]['basename']);if(fs[_0x371a('0x6f')](_0x42240d)){fs['createReadStream'](_0x42240d)[_0x371a('0x70')](fs[_0x371a('0x71')](path[_0x371a('0x57')](_0x552018,_0x266708[_0x371a('0x62')]['basename'])));}}return{'date':moment(_0x266708[_0x371a('0x64')])[_0x371a('0x4a')](_0x371a('0x4b'))[_0x371a('0x56')](),'sender':_0x266708[_0x371a('0x65')]===_0x371a('0x72')?_0x266708[_0x371a('0x5e')]?_0x266708['User'][_0x371a('0x5f')]:_0x371a('0x73'):_0x266708[_0x371a('0x61')][_0x371a('0x74')]+(_0x266708['Contact'][_0x371a('0x75')]?'\x20'+_0x266708[_0x371a('0x61')]['lastName']:''),'body':_0x266708['Attachment']?_0x266708['Attachment'][_0x371a('0x76')]:_0x266708[_0x371a('0x38')],'direction':_0x266708[_0x371a('0x65')]==='out'?'A':'C','secret':_0x266708[_0x371a('0x77')],'read':_0x266708[_0x371a('0x66')],'attachment':_0x266708[_0x371a('0x62')]};})[_0x371a('0x78')]()};return ejs['renderFile'](path[_0x371a('0x57')](config[_0x371a('0x58')],_0x371a('0x79'),_0x371a('0x7a'),_0x371a('0x7b')),{'interaction':_0x5b154c})['then'](function(_0x63be8){var _0x482b52=path[_0x371a('0x57')](_0x552018,'transcript-'+_0x523fd4['id']+'-'+_0x5342ee+_0x371a('0x7c'));var _0x55575f={'path':_0x482b52,'channel':_0x371a('0x6b'),'interactionId':_0x523fd4['id']};return pdf[_0x371a('0x7d')](_0x63be8,_0x55575f);})[_0x371a('0x1b')](function(){return new BPromise(function(_0x556611,_0x2008a3){zipdir(_0x552018,{'saveTo':_0x237ca2},function(_0x6c13ac,_0x272c2f){if(_0x6c13ac)return _0x2008a3(_0x6c13ac);return _0x556611(_0x272c2f);});})[_0x371a('0x1b')](function(){return new BPromise(function(_0x52cf47,_0x5cb2c1){rimraf(_0x552018,function(_0x155570){if(_0x155570)_0x5cb2c1(_0x155570);return _0x52cf47();});});})[_0x371a('0x1b')](function(){return _0x520592['download'](_0x237ca2,_0x13e2c0,function(_0x5e1caf){if(_0x5e1caf){console[_0x371a('0x7e')]('err',_0x5e1caf);}else{fs[_0x371a('0x7f')](_0x237ca2);}});});});}else{return _0x520592[_0x371a('0x10')](0xc8);}})['catch'](handleError(_0x520592,null));};
\ No newline at end of file