Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 6d9904b..36629f4 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 _0xf536=['existsSync','pipe','createWriteStream','System','out','value','renderFile','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','err','sendStatus','zip-dir','bluebird','path','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','end','status','json','offset','undefined','limit','count','set','update','then','destroy','error','stack','name','send','map','WhatsappInteraction','rawAttributes','fieldName','type','key','findAll','query','user','catch','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','merge','options','create','body','describe','addMessage','WhatsappMessage','find','omit','ids','getMessages','findOne','hasOwnProperty','nolimit','sort','where','pick','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','rows','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','User','fullname','Contact','firstName','Attachment','Messages','createdAt','direction','secret','read','WhatsappAccount','Account','Owner','mkdirSync','N.A.','closed','closedAt','disposition','basename'];(function(_0x9e97ca,_0x3ad9db){var _0x5d1649=function(_0xcf9dc7){while(--_0xcf9dc7){_0x9e97ca['push'](_0x9e97ca['shift']());}};_0x5d1649(++_0x3ad9db);}(_0xf536,0x106));var _0x6f53=function(_0x565d34,_0x4176da){_0x565d34=_0x565d34-0x0;var _0x3751e7=_0xf536[_0x565d34];return _0x3751e7;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x6f53('0x0'));var moment=require('moment');var BPromise=require(_0x6f53('0x1'));var util=require('util');var path=require(_0x6f53('0x2'));var ejs=require(_0x6f53('0x3'));var fs=require('fs');var _=require(_0x6f53('0x4'));var Redis=require('ioredis');var interaction=require(_0x6f53('0x5'));var qs=require(_0x6f53('0x6'));var pdf=require(_0x6f53('0x7'));var logger=require('../../config/logger')(_0x6f53('0x8'));var config=require('../../config/environment');var db=require(_0x6f53('0x9'))['db'];config[_0x6f53('0xa')]=_[_0x6f53('0xb')](config[_0x6f53('0xa')],{'host':_0x6f53('0xc'),'port':0x18eb});var socket=require(_0x6f53('0xd'))(new Redis(config['redis']));require('./whatsappInteraction.socket')[_0x6f53('0xe')](socket);function respondWithStatusCode(_0x2d11b1,_0x2951d9){_0x2951d9=_0x2951d9||0xcc;return function(_0x2dc75d){if(_0x2dc75d){return _0x2d11b1['sendStatus'](_0x2951d9);}return _0x2d11b1['status'](_0x2951d9)[_0x6f53('0xf')]();};}function respondWithResult(_0x376839,_0x2a64da){_0x2a64da=_0x2a64da||0xc8;return function(_0x2aaa19){if(_0x2aaa19){return _0x376839[_0x6f53('0x10')](_0x2a64da)[_0x6f53('0x11')](_0x2aaa19);}};}function respondWithFilteredResult(_0x575fbc,_0x2e49fa){return function(_0x369ea5){if(_0x369ea5){var _0x957ce6=typeof _0x2e49fa[_0x6f53('0x12')]===_0x6f53('0x13')&&typeof _0x2e49fa[_0x6f53('0x14')]===_0x6f53('0x13');var _0x832520=_0x369ea5[_0x6f53('0x15')];var _0xb71688=_0x957ce6?0x0:_0x2e49fa['offset'];var _0x54b0f4=_0x957ce6?_0x369ea5['count']:_0x2e49fa[_0x6f53('0x12')]+_0x2e49fa['limit'];var _0x556730;if(_0x54b0f4>=_0x832520){_0x54b0f4=_0x832520;_0x556730=0xc8;}else{_0x556730=0xce;}_0x575fbc[_0x6f53('0x10')](_0x556730);return _0x575fbc[_0x6f53('0x16')]('Content-Range',_0xb71688+'-'+_0x54b0f4+'/'+_0x832520)[_0x6f53('0x11')](_0x369ea5);}return null;};}function saveUpdates(_0x5f2ac7){return function(_0x345b94){if(_0x345b94){return _0x345b94[_0x6f53('0x17')](_0x5f2ac7)[_0x6f53('0x18')](function(_0x10bf7b){return _0x10bf7b;});}return null;};}function removeEntity(_0x43d2ab){return function(_0x1f0f4f){if(_0x1f0f4f){return _0x1f0f4f[_0x6f53('0x19')]()[_0x6f53('0x18')](function(){_0x43d2ab[_0x6f53('0x10')](0xcc)[_0x6f53('0xf')]();});}};}function handleEntityNotFound(_0x114e24){return function(_0x5381aa){if(!_0x5381aa){_0x114e24['sendStatus'](0x194);}return _0x5381aa;};}function handleError(_0x43cc6b,_0x34525c){_0x34525c=_0x34525c||0x1f4;return function(_0x496d9a){logger[_0x6f53('0x1a')](_0x496d9a[_0x6f53('0x1b')]);if(_0x496d9a[_0x6f53('0x1c')]){delete _0x496d9a[_0x6f53('0x1c')];}_0x43cc6b['status'](_0x34525c)[_0x6f53('0x1d')](_0x496d9a);};}exports['index']=function(_0x580077,_0x439f68){var _0x41cbd6={};var _0x3e8445=_[_0x6f53('0x1e')](db[_0x6f53('0x1f')][_0x6f53('0x20')],function(_0x253194){return{'name':_0x253194[_0x6f53('0x21')],'type':_0x253194[_0x6f53('0x22')][_0x6f53('0x23')]};});_0x41cbd6=qs['getOptions'](_0x3e8445,_0x580077);return interaction[_0x6f53('0x24')]('whatsapp',_0x580077[_0x6f53('0x25')],_0x580077[_0x6f53('0x26')],_0x41cbd6,_0x3e8445)['then'](respondWithFilteredResult(_0x439f68,_0x41cbd6))[_0x6f53('0x27')](handleError(_0x439f68,null));};exports['show']=function(_0x340209,_0x1f27ba){var _0x3de5ab={'raw':![],'where':{'id':_0x340209[_0x6f53('0x28')]['id']}},_0x134bdd={};_0x134bdd[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x1f')][_0x6f53('0x20')]);_0x134bdd['query']=_[_0x6f53('0x2a')](_0x340209[_0x6f53('0x25')]);_0x134bdd[_0x6f53('0x2b')]=_[_0x6f53('0x2c')](_0x134bdd[_0x6f53('0x29')],_0x134bdd[_0x6f53('0x25')]);_0x3de5ab[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x134bdd['model'],qs[_0x6f53('0x2e')](_0x340209['query'][_0x6f53('0x2e')]));_0x3de5ab[_0x6f53('0x2d')]=_0x3de5ab['attributes'][_0x6f53('0x2f')]?_0x3de5ab[_0x6f53('0x2d')]:_0x134bdd['model'];if(_0x340209['query'][_0x6f53('0x30')]){_0x3de5ab[_0x6f53('0x31')]=[{'all':!![]}];}_0x3de5ab=_[_0x6f53('0x32')]({},_0x3de5ab,_0x340209[_0x6f53('0x33')]);return db['WhatsappInteraction']['find'](_0x3de5ab)[_0x6f53('0x18')](handleEntityNotFound(_0x1f27ba,null))[_0x6f53('0x18')](respondWithResult(_0x1f27ba,null))[_0x6f53('0x27')](handleError(_0x1f27ba,null));};exports['create']=function(_0x143f10,_0x9fdf24){return db['WhatsappInteraction'][_0x6f53('0x34')](_0x143f10[_0x6f53('0x35')],{})[_0x6f53('0x18')](respondWithResult(_0x9fdf24,0xc9))[_0x6f53('0x27')](handleError(_0x9fdf24,null));};exports[_0x6f53('0x17')]=function(_0x3ee064,_0x4edb74){if(_0x3ee064[_0x6f53('0x35')]['id']){delete _0x3ee064[_0x6f53('0x35')]['id'];}return db[_0x6f53('0x1f')]['find']({'where':{'id':_0x3ee064[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x4edb74,null))[_0x6f53('0x18')](saveUpdates(_0x3ee064[_0x6f53('0x35')],null))[_0x6f53('0x18')](respondWithResult(_0x4edb74,null))['catch'](handleError(_0x4edb74,null));};exports[_0x6f53('0x19')]=function(_0x16f855,_0x39479d){return db['WhatsappInteraction']['find']({'where':{'id':_0x16f855[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x39479d,null))[_0x6f53('0x18')](removeEntity(_0x39479d,null))[_0x6f53('0x27')](handleError(_0x39479d,null));};exports[_0x6f53('0x36')]=function(_0x38b37c,_0xdb7a5c){return db[_0x6f53('0x1f')][_0x6f53('0x36')]()[_0x6f53('0x18')](respondWithResult(_0xdb7a5c,null))[_0x6f53('0x27')](handleError(_0xdb7a5c,null));};exports[_0x6f53('0x37')]=function(_0x271838,_0x82585c){return db[_0x6f53('0x38')][_0x6f53('0x39')]({'where':{'id':_0x271838['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x82585c,null))['then'](function(_0x5f4887){if(_0x5f4887){return _0x5f4887[_0x6f53('0x37')](_0x271838['body']['ids'],_[_0x6f53('0x3a')](_0x271838['body'],[_0x6f53('0x3b'),'id'])||{});}})[_0x6f53('0x18')](respondWithResult(_0x82585c,null))[_0x6f53('0x27')](handleError(_0x82585c,null));};exports[_0x6f53('0x3c')]=function(_0x5499a9,_0x526e2c){var _0x14ea14={'raw':![],'where':{}};var _0x190082={};var _0x3193ad={'count':0x0,'rows':[]};return db[_0x6f53('0x1f')][_0x6f53('0x3d')]({'where':{'id':_0x5499a9[_0x6f53('0x28')]['id']}})['then'](handleEntityNotFound(_0x526e2c,null))[_0x6f53('0x18')](function(_0x70ccc0){if(_0x70ccc0){_0x190082[_0x6f53('0x29')]=_[_0x6f53('0x2a')](db[_0x6f53('0x38')][_0x6f53('0x20')]);_0x190082[_0x6f53('0x25')]=_['keys'](_0x5499a9[_0x6f53('0x25')]);_0x190082['filters']=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],_0x190082['query']);_0x14ea14[_0x6f53('0x2d')]=_[_0x6f53('0x2c')](_0x190082[_0x6f53('0x29')],qs['fields'](_0x5499a9[_0x6f53('0x25')]['fields']));_0x14ea14[_0x6f53('0x2d')]=_0x14ea14[_0x6f53('0x2d')][_0x6f53('0x2f')]?_0x14ea14[_0x6f53('0x2d')]:_0x190082[_0x6f53('0x29')];if(!_0x5499a9['query'][_0x6f53('0x3e')](_0x6f53('0x3f'))){_0x14ea14[_0x6f53('0x14')]=qs['limit'](_0x5499a9[_0x6f53('0x25')]['limit']);_0x14ea14['offset']=qs['offset'](_0x5499a9['query']['offset']);}_0x14ea14['order']=qs[_0x6f53('0x40')](_0x5499a9[_0x6f53('0x25')]['sort']);_0x14ea14[_0x6f53('0x41')]=qs[_0x6f53('0x2b')](_[_0x6f53('0x42')](_0x5499a9['query'],_0x190082['filters']));_0x14ea14[_0x6f53('0x41')]['WhatsappInteractionId']=_0x70ccc0['id'];if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]){_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],{'$or':_[_0x6f53('0x1e')](_0x14ea14[_0x6f53('0x2d')],function(_0x1a9a4d){var _0x32f2c5={};_0x32f2c5[_0x1a9a4d]={'$like':'%'+_0x5499a9[_0x6f53('0x25')][_0x6f53('0x43')]+'%'};return _0x32f2c5;})});}if(_0x5499a9[_0x6f53('0x25')]['$gte']){var _0x226746=_0x5499a9['query'][_0x6f53('0x44')][_0x6f53('0x45')](',');var _0x40b1db={};_0x40b1db[_0x226746[0x0]]={'$gte':moment(_0x226746[0x1])[_0x6f53('0x46')](_0x6f53('0x47'))};_0x14ea14[_0x6f53('0x41')]=_[_0x6f53('0x32')](_0x14ea14['where'],_0x40b1db);}_0x14ea14=_['merge']({},_0x14ea14,_0x5499a9[_0x6f53('0x33')]);return db[_0x6f53('0x38')][_0x6f53('0x15')]({'where':_0x14ea14[_0x6f53('0x41')]})[_0x6f53('0x18')](function(_0xbabe0f){_0x3193ad[_0x6f53('0x15')]=_0xbabe0f;if(_0x5499a9[_0x6f53('0x25')][_0x6f53('0x30')]){_0x14ea14[_0x6f53('0x31')]=[{'all':!![]}];}return db[_0x6f53('0x38')][_0x6f53('0x24')](_0x14ea14);})[_0x6f53('0x18')](function(_0x43b0a6){_0x3193ad[_0x6f53('0x48')]=_0x43b0a6;return _0x3193ad;});}})['then'](respondWithFilteredResult(_0x526e2c,_0x14ea14))['catch'](handleError(_0x526e2c,null));};exports['addTags']=function(_0x1782df,_0x23b697){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x1782df[_0x6f53('0x28')]['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x23b697,null))[_0x6f53('0x18')](function(_0x209fb5){if(_0x209fb5){return _0x209fb5[_0x6f53('0x49')](_0x1782df['body']['ids'],_[_0x6f53('0x3a')](_0x1782df[_0x6f53('0x35')],[_0x6f53('0x3b'),'id'])||{})[_0x6f53('0x4a')](function(){return db[_0x6f53('0x4b')]['findAll']({'attributes':['id',_0x6f53('0x1c'),_0x6f53('0x4c')],'where':{'id':_0x1782df[_0x6f53('0x35')][_0x6f53('0x3b')]}});})[_0x6f53('0x18')](function(_0x3d94f0){socket[_0x6f53('0x4d')](_0x6f53('0x4e'),{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]});return{'id':Number(_0x1782df[_0x6f53('0x28')]['id']),'tags':_0x3d94f0||[]};});}})[_0x6f53('0x18')](respondWithResult(_0x23b697,null))[_0x6f53('0x27')](handleError(_0x23b697,null));};exports[_0x6f53('0x4f')]=function(_0x71109b,_0x14f1d2){return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x71109b['params']['id']}})[_0x6f53('0x18')](handleEntityNotFound(_0x14f1d2,null))['then'](function(_0x31f969){if(_0x31f969){return _0x31f969[_0x6f53('0x4f')](_0x71109b[_0x6f53('0x25')][_0x6f53('0x3b')]);}})['then'](respondWithStatusCode(_0x14f1d2,null))[_0x6f53('0x27')](handleError(_0x14f1d2,null));};exports[_0x6f53('0x50')]=function(_0x490abc,_0x423ab5){var _0x5bd71a=moment()[_0x6f53('0x51')]()[_0x6f53('0x52')]();var _0x27eeaa=path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x57'));var _0x4e086a=path['join'](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x56'),_0x6f53('0x58'));var _0x215834=path[_0x6f53('0x53')](_0x27eeaa,_0x5bd71a);var _0x1a584b=util[_0x6f53('0x46')](_0x6f53('0x59'),_0x490abc[_0x6f53('0x28')]['id'],_0x5bd71a);var _0x5172df=path[_0x6f53('0x53')](_0x27eeaa,_0x1a584b);var _0x33220d=[];_0x33220d[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x5b'),'attributes':['id',_0x6f53('0x5c')],'raw':!![]});_0x33220d[_0x6f53('0x5a')]({'model':db['CmContact'],'as':_0x6f53('0x5d'),'attributes':['id',_0x6f53('0x5e'),'lastName'],'raw':!![]});if(_0x490abc[_0x6f53('0x25')][_0x6f53('0x58')]){_0x33220d['push']({'model':db[_0x6f53('0x5f')],'as':'Attachment','raw':!![]});}var _0x4fbcf6=[{'model':db[_0x6f53('0x38')],'as':_0x6f53('0x60'),'attributes':['id',_0x6f53('0x35'),_0x6f53('0x61'),_0x6f53('0x62'),_0x6f53('0x63'),_0x6f53('0x64')],'include':_0x33220d}];_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x65')],'as':_0x6f53('0x66'),'attributes':['id','name']});_0x4fbcf6[_0x6f53('0x5a')]({'model':db[_0x6f53('0x5b')],'as':_0x6f53('0x67'),'attributes':['id',_0x6f53('0x5c')]});return db[_0x6f53('0x1f')][_0x6f53('0x39')]({'where':{'id':_0x490abc[_0x6f53('0x28')]['id']},'include':_0x4fbcf6})[_0x6f53('0x18')](handleEntityNotFound(_0x423ab5,null))[_0x6f53('0x18')](function(_0x309189){if(_0x309189){var _0x19203e=_0x309189['get']({'plain':!![]});fs[_0x6f53('0x68')](_0x215834);var _0x22f504={'channel':'Whatsapp','account':_0x19203e['Account'][_0x6f53('0x1c')],'agent':_0x19203e['Owner']?_0x19203e[_0x6f53('0x67')][_0x6f53('0x5c')]:_0x6f53('0x69'),'createdAt':moment(_0x19203e['createdAt'])[_0x6f53('0x46')](_0x6f53('0x47'))['toString'](),'closedAt':_0x19203e[_0x6f53('0x6a')]?moment(_0x19203e[_0x6f53('0x6b')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')]():'','disposition':_0x19203e[_0x6f53('0x6c')],'messages':_(_0x19203e[_0x6f53('0x60')])['filter']({'secret':![]})['map'](function(_0x27a1b7){if(_0x27a1b7[_0x6f53('0x5f')]){var _0x5aea7c=path[_0x6f53('0x53')](_0x4e086a,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]);if(fs[_0x6f53('0x6e')](_0x5aea7c)){fs['createReadStream'](_0x5aea7c)[_0x6f53('0x6f')](fs[_0x6f53('0x70')](path[_0x6f53('0x53')](_0x215834,_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')])));}}return{'date':moment(_0x27a1b7[_0x6f53('0x61')])[_0x6f53('0x46')](_0x6f53('0x47'))[_0x6f53('0x52')](),'sender':_0x27a1b7[_0x6f53('0x62')]==='out'?_0x27a1b7[_0x6f53('0x5b')]?_0x27a1b7[_0x6f53('0x5b')][_0x6f53('0x5c')]:_0x6f53('0x71'):_0x27a1b7['Contact']['firstName']+(_0x27a1b7[_0x6f53('0x5d')]['lastName']?'\x20'+_0x27a1b7[_0x6f53('0x5d')]['lastName']:''),'body':_0x27a1b7[_0x6f53('0x5f')]?_0x27a1b7[_0x6f53('0x5f')][_0x6f53('0x6d')]:_0x27a1b7['body'],'direction':_0x27a1b7[_0x6f53('0x62')]===_0x6f53('0x72')?'A':'C','secret':_0x27a1b7[_0x6f53('0x63')],'read':_0x27a1b7[_0x6f53('0x64')],'attachment':_0x27a1b7[_0x6f53('0x5f')]};})[_0x6f53('0x73')]()};return ejs[_0x6f53('0x74')](path[_0x6f53('0x53')](config[_0x6f53('0x54')],_0x6f53('0x55'),_0x6f53('0x75'),_0x6f53('0x76')),{'interaction':_0x22f504})[_0x6f53('0x18')](function(_0x5df115){var _0x5163b9=path[_0x6f53('0x53')](_0x215834,_0x6f53('0x77')+_0x19203e['id']+'-'+_0x5bd71a+_0x6f53('0x78'));var _0x23b8d1={'path':_0x5163b9,'channel':'Whatsapp','interactionId':_0x19203e['id']};return pdf[_0x6f53('0x79')](_0x5df115,_0x23b8d1);})[_0x6f53('0x18')](function(){return new BPromise(function(_0x33ac95,_0x1ee07b){zipdir(_0x215834,{'saveTo':_0x5172df},function(_0x127fc1,_0x18f50e){if(_0x127fc1)return _0x1ee07b(_0x127fc1);return _0x33ac95(_0x18f50e);});})[_0x6f53('0x18')](function(){return new BPromise(function(_0x5774ef,_0x1ce885){rimraf(_0x215834,function(_0x515a4c){if(_0x515a4c)_0x1ce885(_0x515a4c);return _0x5774ef();});});})['then'](function(){return _0x423ab5[_0x6f53('0x50')](_0x5172df,_0x1a584b,function(_0x808474){if(_0x808474){console['log'](_0x6f53('0x7a'),_0x808474);}else{fs['unlinkSync'](_0x5172df);}});});});}else{return _0x423ab5[_0x6f53('0x7b')](0xc8);}})[_0x6f53('0x27')](handleError(_0x423ab5,null));};
\ No newline at end of file