Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 3061595..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe66b=['destroy','error','stack','name','send','map','WhatsappInteraction','fieldName','type','key','findAll','whatsapp','query','user','catch','show','params','model','keys','rawAttributes','intersection','attributes','fields','includeAll','include','merge','find','create','body','update','describe','addMessage','WhatsappMessage','ids','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','filters','pick','WhatsappInteractionId','filter','$gte','split','format','options','rows','addTags','setTags','spread','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','User','push','CmContact','Contact','firstName','lastName','Attachment','createdAt','secret','WhatsappAccount','Account','Owner','fullname','get','mkdirSync','Whatsapp','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','basename','pipe','createWriteStream','direction','out','System','read','renderFile','views','transcript-','.pdf','log','err','unlinkSync','sendStatus','moment','bluebird','util','path','lodash','ioredis','../../components/interaction/service','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','register','status','end','json','offset','limit','undefined','count','set','Content-Range','then'];(function(_0x2abf59,_0x33a435){var _0x3bc8ce=function(_0x3bd6e8){while(--_0x3bd6e8){_0x2abf59['push'](_0x2abf59['shift']());}};_0x3bc8ce(++_0x33a435);}(_0xe66b,0x65));var _0xbe66=function(_0x25adbd,_0x4f612f){_0x25adbd=_0x25adbd-0x0;var _0x4abc82=_0xe66b[_0x25adbd];return _0x4abc82;};'use strict';var rimraf=require('rimraf');var zipdir=require('zip-dir');var moment=require(_0xbe66('0x0'));var BPromise=require(_0xbe66('0x1'));var util=require(_0xbe66('0x2'));var path=require(_0xbe66('0x3'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xbe66('0x4'));var Redis=require(_0xbe66('0x5'));var interaction=require(_0xbe66('0x6'));var qs=require('../../components/parsers/qs');var pdf=require(_0xbe66('0x7'));var logger=require(_0xbe66('0x8'))(_0xbe66('0x9'));var config=require(_0xbe66('0xa'));var db=require(_0xbe66('0xb'))['db'];config[_0xbe66('0xc')]=_['defaults'](config[_0xbe66('0xc')],{'host':_0xbe66('0xd'),'port':0x18eb});var socket=require(_0xbe66('0xe'))(new Redis(config[_0xbe66('0xc')]));require('./whatsappInteraction.socket')[_0xbe66('0xf')](socket);function respondWithStatusCode(_0x5ccf4f,_0x1d971a){_0x1d971a=_0x1d971a||0xcc;return function(_0x53299d){if(_0x53299d){return _0x5ccf4f['sendStatus'](_0x1d971a);}return _0x5ccf4f[_0xbe66('0x10')](_0x1d971a)[_0xbe66('0x11')]();};}function respondWithResult(_0xfad110,_0xc9af3f){_0xc9af3f=_0xc9af3f||0xc8;return function(_0xb8dcd3){if(_0xb8dcd3){return _0xfad110[_0xbe66('0x10')](_0xc9af3f)[_0xbe66('0x12')](_0xb8dcd3);}};}function respondWithFilteredResult(_0x12382c,_0x57a4b7){return function(_0xf5b4d9){if(_0xf5b4d9){var _0x521afc=typeof _0x57a4b7[_0xbe66('0x13')]==='undefined'&&typeof _0x57a4b7[_0xbe66('0x14')]===_0xbe66('0x15');var _0x334ece=_0xf5b4d9[_0xbe66('0x16')];var _0xd35052=_0x521afc?0x0:_0x57a4b7[_0xbe66('0x13')];var _0x5e7f1f=_0x521afc?_0xf5b4d9[_0xbe66('0x16')]:_0x57a4b7[_0xbe66('0x13')]+_0x57a4b7[_0xbe66('0x14')];var _0x4a00e5;if(_0x5e7f1f>=_0x334ece){_0x5e7f1f=_0x334ece;_0x4a00e5=0xc8;}else{_0x4a00e5=0xce;}_0x12382c[_0xbe66('0x10')](_0x4a00e5);return _0x12382c[_0xbe66('0x17')](_0xbe66('0x18'),_0xd35052+'-'+_0x5e7f1f+'/'+_0x334ece)[_0xbe66('0x12')](_0xf5b4d9);}return null;};}function saveUpdates(_0x23bc5a){return function(_0x42f0b1){if(_0x42f0b1){return _0x42f0b1['update'](_0x23bc5a)[_0xbe66('0x19')](function(_0x2f7ffc){return _0x2f7ffc;});}return null;};}function removeEntity(_0x1c407b){return function(_0x97fb0){if(_0x97fb0){return _0x97fb0[_0xbe66('0x1a')]()[_0xbe66('0x19')](function(){_0x1c407b['status'](0xcc)[_0xbe66('0x11')]();});}};}function handleEntityNotFound(_0x57d136){return function(_0x1eae01){if(!_0x1eae01){_0x57d136['sendStatus'](0x194);}return _0x1eae01;};}function handleError(_0x260c9b,_0xc98735){_0xc98735=_0xc98735||0x1f4;return function(_0x16b295){logger[_0xbe66('0x1b')](_0x16b295[_0xbe66('0x1c')]);if(_0x16b295['name']){delete _0x16b295[_0xbe66('0x1d')];}_0x260c9b[_0xbe66('0x10')](_0xc98735)[_0xbe66('0x1e')](_0x16b295);};}exports['index']=function(_0x1a4909,_0x31f039){var _0xbcdeba={};var _0x410ee5=_[_0xbe66('0x1f')](db[_0xbe66('0x20')]['rawAttributes'],function(_0x479e40){return{'name':_0x479e40[_0xbe66('0x21')],'type':_0x479e40[_0xbe66('0x22')][_0xbe66('0x23')]};});_0xbcdeba=qs['getOptions'](_0x410ee5,_0x1a4909);return interaction[_0xbe66('0x24')](_0xbe66('0x25'),_0x1a4909[_0xbe66('0x26')],_0x1a4909[_0xbe66('0x27')],_0xbcdeba,_0x410ee5)[_0xbe66('0x19')](respondWithFilteredResult(_0x31f039,_0xbcdeba))[_0xbe66('0x28')](handleError(_0x31f039,null));};exports[_0xbe66('0x29')]=function(_0x84f39b,_0x35d6db){var _0x3df376={'raw':![],'where':{'id':_0x84f39b[_0xbe66('0x2a')]['id']}},_0x56eac6={};_0x56eac6[_0xbe66('0x2b')]=_[_0xbe66('0x2c')](db[_0xbe66('0x20')][_0xbe66('0x2d')]);_0x56eac6[_0xbe66('0x26')]=_[_0xbe66('0x2c')](_0x84f39b[_0xbe66('0x26')]);_0x56eac6['filters']=_[_0xbe66('0x2e')](_0x56eac6[_0xbe66('0x2b')],_0x56eac6[_0xbe66('0x26')]);_0x3df376[_0xbe66('0x2f')]=_[_0xbe66('0x2e')](_0x56eac6[_0xbe66('0x2b')],qs['fields'](_0x84f39b[_0xbe66('0x26')][_0xbe66('0x30')]));_0x3df376['attributes']=_0x3df376[_0xbe66('0x2f')]['length']?_0x3df376[_0xbe66('0x2f')]:_0x56eac6[_0xbe66('0x2b')];if(_0x84f39b[_0xbe66('0x26')][_0xbe66('0x31')]){_0x3df376[_0xbe66('0x32')]=[{'all':!![]}];}_0x3df376=_[_0xbe66('0x33')]({},_0x3df376,_0x84f39b['options']);return db[_0xbe66('0x20')][_0xbe66('0x34')](_0x3df376)['then'](handleEntityNotFound(_0x35d6db,null))[_0xbe66('0x19')](respondWithResult(_0x35d6db,null))[_0xbe66('0x28')](handleError(_0x35d6db,null));};exports['create']=function(_0x2c0fb0,_0x4e5bb8){return db[_0xbe66('0x20')][_0xbe66('0x35')](_0x2c0fb0[_0xbe66('0x36')],{})[_0xbe66('0x19')](respondWithResult(_0x4e5bb8,0xc9))[_0xbe66('0x28')](handleError(_0x4e5bb8,null));};exports[_0xbe66('0x37')]=function(_0xe0ad70,_0x3504d3){if(_0xe0ad70[_0xbe66('0x36')]['id']){delete _0xe0ad70[_0xbe66('0x36')]['id'];}return db['WhatsappInteraction'][_0xbe66('0x34')]({'where':{'id':_0xe0ad70[_0xbe66('0x2a')]['id']}})['then'](handleEntityNotFound(_0x3504d3,null))['then'](saveUpdates(_0xe0ad70['body'],null))[_0xbe66('0x19')](respondWithResult(_0x3504d3,null))[_0xbe66('0x28')](handleError(_0x3504d3,null));};exports[_0xbe66('0x1a')]=function(_0x5df799,_0x4ebc2d){return db[_0xbe66('0x20')][_0xbe66('0x34')]({'where':{'id':_0x5df799['params']['id']}})['then'](handleEntityNotFound(_0x4ebc2d,null))['then'](removeEntity(_0x4ebc2d,null))[_0xbe66('0x28')](handleError(_0x4ebc2d,null));};exports[_0xbe66('0x38')]=function(_0x22b697,_0x3b4d78){return db[_0xbe66('0x20')][_0xbe66('0x38')]()[_0xbe66('0x19')](respondWithResult(_0x3b4d78,null))['catch'](handleError(_0x3b4d78,null));};exports[_0xbe66('0x39')]=function(_0x345f21,_0x5439a2){return db[_0xbe66('0x3a')][_0xbe66('0x34')]({'where':{'id':_0x345f21['params']['id']}})['then'](handleEntityNotFound(_0x5439a2,null))[_0xbe66('0x19')](function(_0x2d6450){if(_0x2d6450){return _0x2d6450[_0xbe66('0x39')](_0x345f21[_0xbe66('0x36')][_0xbe66('0x3b')],_['omit'](_0x345f21[_0xbe66('0x36')],[_0xbe66('0x3b'),'id'])||{});}})[_0xbe66('0x19')](respondWithResult(_0x5439a2,null))[_0xbe66('0x28')](handleError(_0x5439a2,null));};exports[_0xbe66('0x3c')]=function(_0x105ec2,_0x5497cf){var _0x2e57d9={'raw':![],'where':{}};var _0x3aac4d={};var _0x403db3={'count':0x0,'rows':[]};return db[_0xbe66('0x20')][_0xbe66('0x3d')]({'where':{'id':_0x105ec2['params']['id']}})[_0xbe66('0x19')](handleEntityNotFound(_0x5497cf,null))[_0xbe66('0x19')](function(_0x3df6bb){if(_0x3df6bb){_0x3aac4d['model']=_['keys'](db['WhatsappMessage'][_0xbe66('0x2d')]);_0x3aac4d[_0xbe66('0x26')]=_[_0xbe66('0x2c')](_0x105ec2['query']);_0x3aac4d['filters']=_[_0xbe66('0x2e')](_0x3aac4d[_0xbe66('0x2b')],_0x3aac4d[_0xbe66('0x26')]);_0x2e57d9['attributes']=_[_0xbe66('0x2e')](_0x3aac4d[_0xbe66('0x2b')],qs[_0xbe66('0x30')](_0x105ec2['query']['fields']));_0x2e57d9[_0xbe66('0x2f')]=_0x2e57d9[_0xbe66('0x2f')]['length']?_0x2e57d9[_0xbe66('0x2f')]:_0x3aac4d[_0xbe66('0x2b')];if(!_0x105ec2[_0xbe66('0x26')][_0xbe66('0x3e')](_0xbe66('0x3f'))){_0x2e57d9[_0xbe66('0x14')]=qs[_0xbe66('0x14')](_0x105ec2[_0xbe66('0x26')]['limit']);_0x2e57d9[_0xbe66('0x13')]=qs[_0xbe66('0x13')](_0x105ec2[_0xbe66('0x26')][_0xbe66('0x13')]);}_0x2e57d9[_0xbe66('0x40')]=qs[_0xbe66('0x41')](_0x105ec2[_0xbe66('0x26')][_0xbe66('0x41')]);_0x2e57d9[_0xbe66('0x42')]=qs[_0xbe66('0x43')](_[_0xbe66('0x44')](_0x105ec2[_0xbe66('0x26')],_0x3aac4d[_0xbe66('0x43')]));_0x2e57d9[_0xbe66('0x42')][_0xbe66('0x45')]=_0x3df6bb['id'];if(_0x105ec2[_0xbe66('0x26')]['filter']){_0x2e57d9[_0xbe66('0x42')]=_[_0xbe66('0x33')](_0x2e57d9[_0xbe66('0x42')],{'$or':_['map'](_0x2e57d9[_0xbe66('0x2f')],function(_0x23c0b5){var _0x39ae8e={};_0x39ae8e[_0x23c0b5]={'$like':'%'+_0x105ec2[_0xbe66('0x26')][_0xbe66('0x46')]+'%'};return _0x39ae8e;})});}if(_0x105ec2['query']['$gte']){var _0x2270b0=_0x105ec2[_0xbe66('0x26')][_0xbe66('0x47')][_0xbe66('0x48')](',');var _0x184b3c={};_0x184b3c[_0x2270b0[0x0]]={'$gte':moment(_0x2270b0[0x1])[_0xbe66('0x49')]('YYYY-MM-DD\x20HH:mm:ss')};_0x2e57d9[_0xbe66('0x42')]=_[_0xbe66('0x33')](_0x2e57d9['where'],_0x184b3c);}_0x2e57d9=_[_0xbe66('0x33')]({},_0x2e57d9,_0x105ec2[_0xbe66('0x4a')]);return db[_0xbe66('0x3a')]['count']({'where':_0x2e57d9[_0xbe66('0x42')]})[_0xbe66('0x19')](function(_0x693dda){_0x403db3[_0xbe66('0x16')]=_0x693dda;if(_0x105ec2[_0xbe66('0x26')][_0xbe66('0x31')]){_0x2e57d9[_0xbe66('0x32')]=[{'all':!![]}];}return db[_0xbe66('0x3a')][_0xbe66('0x24')](_0x2e57d9);})[_0xbe66('0x19')](function(_0x31106c){_0x403db3[_0xbe66('0x4b')]=_0x31106c;return _0x403db3;});}})[_0xbe66('0x19')](respondWithFilteredResult(_0x5497cf,_0x2e57d9))[_0xbe66('0x28')](handleError(_0x5497cf,null));};exports[_0xbe66('0x4c')]=function(_0x40abcd,_0x3ab420){return db[_0xbe66('0x20')]['find']({'where':{'id':_0x40abcd[_0xbe66('0x2a')]['id']}})[_0xbe66('0x19')](handleEntityNotFound(_0x3ab420,null))[_0xbe66('0x19')](function(_0x1ae6c3){if(_0x1ae6c3){return _0x1ae6c3[_0xbe66('0x4d')](_0x40abcd['body'][_0xbe66('0x3b')],_['omit'](_0x40abcd[_0xbe66('0x36')],[_0xbe66('0x3b'),'id'])||{})[_0xbe66('0x4e')](function(){return db['Tag'][_0xbe66('0x24')]({'attributes':['id','name',_0xbe66('0x4f')],'where':{'id':_0x40abcd['body'][_0xbe66('0x3b')]}});})[_0xbe66('0x19')](function(_0x326599){socket[_0xbe66('0x50')](_0xbe66('0x51'),{'id':Number(_0x40abcd['params']['id']),'tags':_0x326599||[]});return{'id':Number(_0x40abcd[_0xbe66('0x2a')]['id']),'tags':_0x326599||[]};});}})[_0xbe66('0x19')](respondWithResult(_0x3ab420,null))[_0xbe66('0x28')](handleError(_0x3ab420,null));};exports[_0xbe66('0x52')]=function(_0x268269,_0x2eb4c8){return db[_0xbe66('0x20')][_0xbe66('0x34')]({'where':{'id':_0x268269[_0xbe66('0x2a')]['id']}})[_0xbe66('0x19')](handleEntityNotFound(_0x2eb4c8,null))[_0xbe66('0x19')](function(_0x5c6306){if(_0x5c6306){return _0x5c6306['removeTags'](_0x268269[_0xbe66('0x26')]['ids']);}})[_0xbe66('0x19')](respondWithStatusCode(_0x2eb4c8,null))['catch'](handleError(_0x2eb4c8,null));};exports[_0xbe66('0x53')]=function(_0x24e1c3,_0x125529){var _0x1e59be=moment()[_0xbe66('0x54')]()[_0xbe66('0x55')]();var _0x5a19f5=path[_0xbe66('0x56')](config[_0xbe66('0x57')],_0xbe66('0x58'),_0xbe66('0x59'),_0xbe66('0x5a'));var _0x3a2f4f=path['join'](config[_0xbe66('0x57')],'server','files',_0xbe66('0x5b'));var _0x20acd3=path[_0xbe66('0x56')](_0x5a19f5,_0x1e59be);var _0x543f93=util[_0xbe66('0x49')](_0xbe66('0x5c'),_0x24e1c3['params']['id'],_0x1e59be);var _0x2cd4ef=path['join'](_0x5a19f5,_0x543f93);var _0x2cd8d8=[];_0x2cd8d8['push']({'model':db[_0xbe66('0x5d')],'as':'User','attributes':['id','fullname'],'raw':!![]});_0x2cd8d8[_0xbe66('0x5e')]({'model':db[_0xbe66('0x5f')],'as':_0xbe66('0x60'),'attributes':['id',_0xbe66('0x61'),_0xbe66('0x62')],'raw':!![]});if(_0x24e1c3['query'][_0xbe66('0x5b')]){_0x2cd8d8['push']({'model':db[_0xbe66('0x63')],'as':_0xbe66('0x63'),'raw':!![]});}var _0x2407e7=[{'model':db['WhatsappMessage'],'as':'Messages','attributes':['id','body',_0xbe66('0x64'),'direction',_0xbe66('0x65'),'read'],'include':_0x2cd8d8}];_0x2407e7[_0xbe66('0x5e')]({'model':db[_0xbe66('0x66')],'as':_0xbe66('0x67'),'attributes':['id',_0xbe66('0x1d')]});_0x2407e7[_0xbe66('0x5e')]({'model':db['User'],'as':_0xbe66('0x68'),'attributes':['id',_0xbe66('0x69')]});return db[_0xbe66('0x20')]['find']({'where':{'id':_0x24e1c3['params']['id']},'include':_0x2407e7})[_0xbe66('0x19')](handleEntityNotFound(_0x125529,null))[_0xbe66('0x19')](function(_0x25e9a2){if(_0x25e9a2){var _0x33ba2f=_0x25e9a2[_0xbe66('0x6a')]({'plain':!![]});fs[_0xbe66('0x6b')](_0x20acd3);var _0x3796d0={'channel':_0xbe66('0x6c'),'account':_0x33ba2f[_0xbe66('0x67')][_0xbe66('0x1d')],'agent':_0x33ba2f[_0xbe66('0x68')]?_0x33ba2f[_0xbe66('0x68')][_0xbe66('0x69')]:'N.A.','createdAt':moment(_0x33ba2f[_0xbe66('0x64')])[_0xbe66('0x49')](_0xbe66('0x6d'))[_0xbe66('0x55')](),'closedAt':_0x33ba2f[_0xbe66('0x6e')]?moment(_0x33ba2f[_0xbe66('0x6f')])[_0xbe66('0x49')](_0xbe66('0x6d'))[_0xbe66('0x55')]():'','disposition':_0x33ba2f['disposition'],'messages':_(_0x33ba2f['Messages'])[_0xbe66('0x46')]({'secret':![]})['map'](function(_0x4d01a7){if(_0x4d01a7['Attachment']){var _0xffb064=path['join'](_0x3a2f4f,_0x4d01a7['Attachment'][_0xbe66('0x70')]);if(fs['existsSync'](_0xffb064)){fs['createReadStream'](_0xffb064)[_0xbe66('0x71')](fs[_0xbe66('0x72')](path[_0xbe66('0x56')](_0x20acd3,_0x4d01a7[_0xbe66('0x63')][_0xbe66('0x70')])));}}return{'date':moment(_0x4d01a7[_0xbe66('0x64')])[_0xbe66('0x49')](_0xbe66('0x6d'))[_0xbe66('0x55')](),'sender':_0x4d01a7[_0xbe66('0x73')]===_0xbe66('0x74')?_0x4d01a7[_0xbe66('0x5d')]?_0x4d01a7[_0xbe66('0x5d')]['fullname']:_0xbe66('0x75'):_0x4d01a7['Contact'][_0xbe66('0x61')]+(_0x4d01a7[_0xbe66('0x60')]['lastName']?'\x20'+_0x4d01a7[_0xbe66('0x60')][_0xbe66('0x62')]:''),'body':_0x4d01a7[_0xbe66('0x63')]?_0x4d01a7[_0xbe66('0x63')][_0xbe66('0x70')]:_0x4d01a7[_0xbe66('0x36')],'direction':_0x4d01a7[_0xbe66('0x73')]===_0xbe66('0x74')?'A':'C','secret':_0x4d01a7['secret'],'read':_0x4d01a7[_0xbe66('0x76')],'attachment':_0x4d01a7[_0xbe66('0x63')]};})['value']()};return ejs[_0xbe66('0x77')](path[_0xbe66('0x56')](config[_0xbe66('0x57')],_0xbe66('0x58'),_0xbe66('0x78'),'downloadInteraction.ejs'),{'interaction':_0x3796d0})[_0xbe66('0x19')](function(_0x5b8698){var _0x5aa3df=path[_0xbe66('0x56')](_0x20acd3,_0xbe66('0x79')+_0x33ba2f['id']+'-'+_0x1e59be+_0xbe66('0x7a'));var _0x45957c={'path':_0x5aa3df,'channel':_0xbe66('0x6c'),'interactionId':_0x33ba2f['id']};return pdf['createPdfFromHTML'](_0x5b8698,_0x45957c);})[_0xbe66('0x19')](function(){return new BPromise(function(_0x51a6ec,_0x170558){zipdir(_0x20acd3,{'saveTo':_0x2cd4ef},function(_0x5e96bb,_0x485cc9){if(_0x5e96bb)return _0x170558(_0x5e96bb);return _0x51a6ec(_0x485cc9);});})[_0xbe66('0x19')](function(){return new BPromise(function(_0x70e34e,_0x2600ce){rimraf(_0x20acd3,function(_0x11d93e){if(_0x11d93e)_0x2600ce(_0x11d93e);return _0x70e34e();});});})['then'](function(){return _0x125529[_0xbe66('0x53')](_0x2cd4ef,_0x543f93,function(_0x523aad){if(_0x523aad){console[_0xbe66('0x7b')](_0xbe66('0x7c'),_0x523aad);}else{fs[_0xbe66('0x7d')](_0x2cd4ef);}});});});}else{return _0x125529[_0xbe66('0x7e')](0xc8);}})[_0xbe66('0x28')](handleError(_0x125529,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