Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index d355f05..bed5bd6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x22a5=['downloadInteraction.ejs','createPdfFromHTML','log','err','rimraf','zip-dir','moment','bluebird','util','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','update','then','error','stack','name','index','map','WhatsappInteraction','fieldName','type','key','findAll','whatsapp','user','catch','params','model','keys','rawAttributes','query','filters','intersection','fields','attributes','length','includeAll','include','merge','create','body','find','destroy','describe','WhatsappMessage','addMessage','ids','omit','getMessages','findOne','nolimit','sort','where','WhatsappInteractionId','filter','$gte','format','YYYY-MM-DD\x20HH:mm:ss','options','rows','addTags','setTags','spread','Tag','color','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','push','User','fullname','Contact','firstName','Attachment','Messages','createdAt','direction','secret','read','WhatsappAccount','get','Whatsapp','Account','Owner','N.A.','closedAt','basename','existsSync','createReadStream','pipe','System','lastName','out','value','renderFile','views'];(function(_0x49be84,_0x17546a){var _0x434e3f=function(_0xa4667a){while(--_0xa4667a){_0x49be84['push'](_0x49be84['shift']());}};_0x434e3f(++_0x17546a);}(_0x22a5,0x181));var _0x522a=function(_0x343138,_0x386c81){_0x343138=_0x343138-0x0;var _0x4e40d8=_0x22a5[_0x343138];return _0x4e40d8;};'use strict';var rimraf=require(_0x522a('0x0'));var zipdir=require(_0x522a('0x1'));var moment=require(_0x522a('0x2'));var BPromise=require(_0x522a('0x3'));var util=require(_0x522a('0x4'));var path=require('path');var ejs=require(_0x522a('0x5'));var fs=require('fs');var _=require(_0x522a('0x6'));var Redis=require('ioredis');var interaction=require(_0x522a('0x7'));var qs=require(_0x522a('0x8'));var pdf=require(_0x522a('0x9'));var logger=require(_0x522a('0xa'))(_0x522a('0xb'));var config=require('../../config/environment');var db=require(_0x522a('0xc'))['db'];config[_0x522a('0xd')]=_[_0x522a('0xe')](config['redis'],{'host':_0x522a('0xf'),'port':0x18eb});var socket=require(_0x522a('0x10'))(new Redis(config[_0x522a('0xd')]));require(_0x522a('0x11'))[_0x522a('0x12')](socket);function respondWithStatusCode(_0x145d61,_0x1966c8){_0x1966c8=_0x1966c8||0xcc;return function(_0x44f7be){if(_0x44f7be){return _0x145d61[_0x522a('0x13')](_0x1966c8);}return _0x145d61[_0x522a('0x14')](_0x1966c8)[_0x522a('0x15')]();};}function respondWithResult(_0x133350,_0x2cc22f){_0x2cc22f=_0x2cc22f||0xc8;return function(_0x203dee){if(_0x203dee){return _0x133350['status'](_0x2cc22f)[_0x522a('0x16')](_0x203dee);}};}function respondWithFilteredResult(_0xf112a8,_0x29a4c7){return function(_0x571d6){if(_0x571d6){var _0x23558f=typeof _0x29a4c7[_0x522a('0x17')]==='undefined'&&typeof _0x29a4c7[_0x522a('0x18')]===_0x522a('0x19');var _0x56fc48=_0x571d6[_0x522a('0x1a')];var _0x3f78c3=_0x23558f?0x0:_0x29a4c7['offset'];var _0x1f0657=_0x23558f?_0x571d6[_0x522a('0x1a')]:_0x29a4c7['offset']+_0x29a4c7[_0x522a('0x18')];var _0x395081;if(_0x1f0657>=_0x56fc48){_0x1f0657=_0x56fc48;_0x395081=0xc8;}else{_0x395081=0xce;}_0xf112a8[_0x522a('0x14')](_0x395081);return _0xf112a8[_0x522a('0x1b')](_0x522a('0x1c'),_0x3f78c3+'-'+_0x1f0657+'/'+_0x56fc48)[_0x522a('0x16')](_0x571d6);}return null;};}function saveUpdates(_0x2487d6){return function(_0x5e4d2b){if(_0x5e4d2b){return _0x5e4d2b[_0x522a('0x1d')](_0x2487d6)['then'](function(_0x601b7e){return _0x601b7e;});}return null;};}function removeEntity(_0xfd46f8){return function(_0x7f929d){if(_0x7f929d){return _0x7f929d['destroy']()[_0x522a('0x1e')](function(){_0xfd46f8[_0x522a('0x14')](0xcc)[_0x522a('0x15')]();});}};}function handleEntityNotFound(_0x2bac0e){return function(_0x2b830f){if(!_0x2b830f){_0x2bac0e[_0x522a('0x13')](0x194);}return _0x2b830f;};}function handleError(_0x3b876b,_0x584f6c){_0x584f6c=_0x584f6c||0x1f4;return function(_0x171acd){logger[_0x522a('0x1f')](_0x171acd[_0x522a('0x20')]);if(_0x171acd[_0x522a('0x21')]){delete _0x171acd[_0x522a('0x21')];}_0x3b876b[_0x522a('0x14')](_0x584f6c)['send'](_0x171acd);};}exports[_0x522a('0x22')]=function(_0x4282a5,_0x511fd4){var _0xc664c2={};var _0x4b56d6=_[_0x522a('0x23')](db[_0x522a('0x24')]['rawAttributes'],function(_0x4d92f0){return{'name':_0x4d92f0[_0x522a('0x25')],'type':_0x4d92f0[_0x522a('0x26')][_0x522a('0x27')]};});_0xc664c2=qs['getOptions'](_0x4b56d6,_0x4282a5);return interaction[_0x522a('0x28')](_0x522a('0x29'),_0x4282a5['query'],_0x4282a5[_0x522a('0x2a')],_0xc664c2,_0x4b56d6)['then'](respondWithFilteredResult(_0x511fd4,_0xc664c2))[_0x522a('0x2b')](handleError(_0x511fd4,null));};exports['show']=function(_0x585d64,_0x502007){var _0x24bc57={'raw':![],'where':{'id':_0x585d64[_0x522a('0x2c')]['id']}},_0x3dc214={};_0x3dc214[_0x522a('0x2d')]=_[_0x522a('0x2e')](db[_0x522a('0x24')][_0x522a('0x2f')]);_0x3dc214[_0x522a('0x30')]=_[_0x522a('0x2e')](_0x585d64['query']);_0x3dc214[_0x522a('0x31')]=_[_0x522a('0x32')](_0x3dc214[_0x522a('0x2d')],_0x3dc214[_0x522a('0x30')]);_0x24bc57['attributes']=_[_0x522a('0x32')](_0x3dc214[_0x522a('0x2d')],qs[_0x522a('0x33')](_0x585d64[_0x522a('0x30')][_0x522a('0x33')]));_0x24bc57[_0x522a('0x34')]=_0x24bc57[_0x522a('0x34')][_0x522a('0x35')]?_0x24bc57[_0x522a('0x34')]:_0x3dc214[_0x522a('0x2d')];if(_0x585d64[_0x522a('0x30')][_0x522a('0x36')]){_0x24bc57[_0x522a('0x37')]=[{'all':!![]}];}_0x24bc57=_[_0x522a('0x38')]({},_0x24bc57,_0x585d64['options']);return db[_0x522a('0x24')]['find'](_0x24bc57)[_0x522a('0x1e')](handleEntityNotFound(_0x502007,null))[_0x522a('0x1e')](respondWithResult(_0x502007,null))['catch'](handleError(_0x502007,null));};exports[_0x522a('0x39')]=function(_0x161df6,_0x5e8677){return db[_0x522a('0x24')]['create'](_0x161df6[_0x522a('0x3a')],{})[_0x522a('0x1e')](respondWithResult(_0x5e8677,0xc9))[_0x522a('0x2b')](handleError(_0x5e8677,null));};exports['update']=function(_0x54e709,_0x366bd4){if(_0x54e709[_0x522a('0x3a')]['id']){delete _0x54e709[_0x522a('0x3a')]['id'];}return db[_0x522a('0x24')][_0x522a('0x3b')]({'where':{'id':_0x54e709[_0x522a('0x2c')]['id']}})['then'](handleEntityNotFound(_0x366bd4,null))[_0x522a('0x1e')](saveUpdates(_0x54e709['body'],null))[_0x522a('0x1e')](respondWithResult(_0x366bd4,null))[_0x522a('0x2b')](handleError(_0x366bd4,null));};exports[_0x522a('0x3c')]=function(_0x162371,_0x1d969d){return db[_0x522a('0x24')][_0x522a('0x3b')]({'where':{'id':_0x162371['params']['id']}})[_0x522a('0x1e')](handleEntityNotFound(_0x1d969d,null))['then'](removeEntity(_0x1d969d,null))[_0x522a('0x2b')](handleError(_0x1d969d,null));};exports[_0x522a('0x3d')]=function(_0x279622,_0x28368e){return db[_0x522a('0x24')][_0x522a('0x3d')]()[_0x522a('0x1e')](respondWithResult(_0x28368e,null))[_0x522a('0x2b')](handleError(_0x28368e,null));};exports['addMessage']=function(_0xc54930,_0x556ff4){return db[_0x522a('0x3e')][_0x522a('0x3b')]({'where':{'id':_0xc54930['params']['id']}})[_0x522a('0x1e')](handleEntityNotFound(_0x556ff4,null))[_0x522a('0x1e')](function(_0x46fc6c){if(_0x46fc6c){return _0x46fc6c[_0x522a('0x3f')](_0xc54930[_0x522a('0x3a')][_0x522a('0x40')],_[_0x522a('0x41')](_0xc54930[_0x522a('0x3a')],['ids','id'])||{});}})[_0x522a('0x1e')](respondWithResult(_0x556ff4,null))['catch'](handleError(_0x556ff4,null));};exports[_0x522a('0x42')]=function(_0x551f06,_0x2991dd){var _0x78e396={'raw':![],'where':{}};var _0x3b7bf9={};var _0x16dd26={'count':0x0,'rows':[]};return db['WhatsappInteraction'][_0x522a('0x43')]({'where':{'id':_0x551f06['params']['id']}})[_0x522a('0x1e')](handleEntityNotFound(_0x2991dd,null))[_0x522a('0x1e')](function(_0x261194){if(_0x261194){_0x3b7bf9['model']=_[_0x522a('0x2e')](db[_0x522a('0x3e')]['rawAttributes']);_0x3b7bf9['query']=_[_0x522a('0x2e')](_0x551f06[_0x522a('0x30')]);_0x3b7bf9[_0x522a('0x31')]=_[_0x522a('0x32')](_0x3b7bf9[_0x522a('0x2d')],_0x3b7bf9[_0x522a('0x30')]);_0x78e396[_0x522a('0x34')]=_[_0x522a('0x32')](_0x3b7bf9[_0x522a('0x2d')],qs[_0x522a('0x33')](_0x551f06[_0x522a('0x30')]['fields']));_0x78e396[_0x522a('0x34')]=_0x78e396[_0x522a('0x34')][_0x522a('0x35')]?_0x78e396[_0x522a('0x34')]:_0x3b7bf9[_0x522a('0x2d')];if(!_0x551f06[_0x522a('0x30')]['hasOwnProperty'](_0x522a('0x44'))){_0x78e396[_0x522a('0x18')]=qs[_0x522a('0x18')](_0x551f06['query']['limit']);_0x78e396[_0x522a('0x17')]=qs['offset'](_0x551f06[_0x522a('0x30')]['offset']);}_0x78e396['order']=qs['sort'](_0x551f06['query'][_0x522a('0x45')]);_0x78e396[_0x522a('0x46')]=qs[_0x522a('0x31')](_['pick'](_0x551f06[_0x522a('0x30')],_0x3b7bf9[_0x522a('0x31')]));_0x78e396['where'][_0x522a('0x47')]=_0x261194['id'];if(_0x551f06[_0x522a('0x30')][_0x522a('0x48')]){_0x78e396[_0x522a('0x46')]=_[_0x522a('0x38')](_0x78e396[_0x522a('0x46')],{'$or':_[_0x522a('0x23')](_0x78e396[_0x522a('0x34')],function(_0x26df79){var _0x9c7369={};_0x9c7369[_0x26df79]={'$like':'%'+_0x551f06['query'][_0x522a('0x48')]+'%'};return _0x9c7369;})});}if(_0x551f06[_0x522a('0x30')]['$gte']){var _0x126e86=_0x551f06[_0x522a('0x30')][_0x522a('0x49')]['split'](',');var _0x2d873f={};_0x2d873f[_0x126e86[0x0]]={'$gte':moment(_0x126e86[0x1])[_0x522a('0x4a')](_0x522a('0x4b'))};_0x78e396[_0x522a('0x46')]=_['merge'](_0x78e396[_0x522a('0x46')],_0x2d873f);}_0x78e396=_[_0x522a('0x38')]({},_0x78e396,_0x551f06[_0x522a('0x4c')]);return db[_0x522a('0x3e')][_0x522a('0x1a')]({'where':_0x78e396[_0x522a('0x46')]})['then'](function(_0x304623){_0x16dd26[_0x522a('0x1a')]=_0x304623;if(_0x551f06[_0x522a('0x30')][_0x522a('0x36')]){_0x78e396[_0x522a('0x37')]=[{'all':!![]}];}return db[_0x522a('0x3e')]['findAll'](_0x78e396);})['then'](function(_0x1a1b93){_0x16dd26[_0x522a('0x4d')]=_0x1a1b93;return _0x16dd26;});}})[_0x522a('0x1e')](respondWithFilteredResult(_0x2991dd,_0x78e396))[_0x522a('0x2b')](handleError(_0x2991dd,null));};exports[_0x522a('0x4e')]=function(_0x8252d4,_0x27e69e){return db[_0x522a('0x24')]['find']({'where':{'id':_0x8252d4[_0x522a('0x2c')]['id']}})[_0x522a('0x1e')](handleEntityNotFound(_0x27e69e,null))['then'](function(_0x44a0b0){if(_0x44a0b0){return _0x44a0b0[_0x522a('0x4f')](_0x8252d4[_0x522a('0x3a')][_0x522a('0x40')],_[_0x522a('0x41')](_0x8252d4[_0x522a('0x3a')],[_0x522a('0x40'),'id'])||{})[_0x522a('0x50')](function(){return db[_0x522a('0x51')]['findAll']({'attributes':['id',_0x522a('0x21'),_0x522a('0x52')],'where':{'id':_0x8252d4['body'][_0x522a('0x40')]}});})[_0x522a('0x1e')](function(_0x1cd6f9){socket[_0x522a('0x53')](_0x522a('0x54'),{'id':Number(_0x8252d4[_0x522a('0x2c')]['id']),'tags':_0x1cd6f9||[]});return{'id':Number(_0x8252d4['params']['id']),'tags':_0x1cd6f9||[]};});}})[_0x522a('0x1e')](respondWithResult(_0x27e69e,null))[_0x522a('0x2b')](handleError(_0x27e69e,null));};exports[_0x522a('0x55')]=function(_0x598665,_0x17eaa8){return db['WhatsappInteraction'][_0x522a('0x3b')]({'where':{'id':_0x598665['params']['id']}})[_0x522a('0x1e')](handleEntityNotFound(_0x17eaa8,null))['then'](function(_0x20967a){if(_0x20967a){return _0x20967a['removeTags'](_0x598665[_0x522a('0x30')][_0x522a('0x40')]);}})[_0x522a('0x1e')](respondWithStatusCode(_0x17eaa8,null))[_0x522a('0x2b')](handleError(_0x17eaa8,null));};exports[_0x522a('0x56')]=function(_0x4a3573,_0x58bd52){var _0x288fca=moment()[_0x522a('0x57')]()[_0x522a('0x58')]();var _0x5a4465=path[_0x522a('0x59')](config[_0x522a('0x5a')],_0x522a('0x5b'),_0x522a('0x5c'),_0x522a('0x5d'));var _0x1a06fb=path[_0x522a('0x59')](config[_0x522a('0x5a')],'server',_0x522a('0x5c'),_0x522a('0x5e'));var _0x5442af=path['join'](_0x5a4465,_0x288fca);var _0x1761b0=util[_0x522a('0x4a')]('transcript-%d-%s.zip',_0x4a3573[_0x522a('0x2c')]['id'],_0x288fca);var _0x23e0ba=path[_0x522a('0x59')](_0x5a4465,_0x1761b0);var _0xe8c84a=[];_0xe8c84a[_0x522a('0x5f')]({'model':db['User'],'as':_0x522a('0x60'),'attributes':['id',_0x522a('0x61')],'raw':!![]});_0xe8c84a[_0x522a('0x5f')]({'model':db['CmContact'],'as':_0x522a('0x62'),'attributes':['id',_0x522a('0x63'),'lastName'],'raw':!![]});if(_0x4a3573[_0x522a('0x30')][_0x522a('0x5e')]){_0xe8c84a[_0x522a('0x5f')]({'model':db[_0x522a('0x64')],'as':_0x522a('0x64'),'raw':!![]});}var _0x5c36d7=[{'model':db['WhatsappMessage'],'as':_0x522a('0x65'),'attributes':['id','body',_0x522a('0x66'),_0x522a('0x67'),_0x522a('0x68'),_0x522a('0x69')],'include':_0xe8c84a}];_0x5c36d7['push']({'model':db[_0x522a('0x6a')],'as':'Account','attributes':['id',_0x522a('0x21')]});_0x5c36d7[_0x522a('0x5f')]({'model':db['User'],'as':'Owner','attributes':['id',_0x522a('0x61')]});return db[_0x522a('0x24')][_0x522a('0x3b')]({'where':{'id':_0x4a3573[_0x522a('0x2c')]['id']},'include':_0x5c36d7})[_0x522a('0x1e')](handleEntityNotFound(_0x58bd52,null))[_0x522a('0x1e')](function(_0x5ca68e){if(_0x5ca68e){var _0x27e593=_0x5ca68e[_0x522a('0x6b')]({'plain':!![]});fs['mkdirSync'](_0x5442af);var _0x583283={'channel':_0x522a('0x6c'),'account':_0x27e593[_0x522a('0x6d')][_0x522a('0x21')],'agent':_0x27e593[_0x522a('0x6e')]?_0x27e593['Owner'][_0x522a('0x61')]:_0x522a('0x6f'),'createdAt':moment(_0x27e593[_0x522a('0x66')])['format'](_0x522a('0x4b'))[_0x522a('0x58')](),'closedAt':_0x27e593['closed']?moment(_0x27e593[_0x522a('0x70')])['format'](_0x522a('0x4b'))[_0x522a('0x58')]():'','disposition':_0x27e593['disposition'],'messages':_(_0x27e593[_0x522a('0x65')])['filter']({'secret':![]})[_0x522a('0x23')](function(_0x4631b9){if(_0x4631b9[_0x522a('0x64')]){var _0x5f540a=path[_0x522a('0x59')](_0x1a06fb,_0x4631b9[_0x522a('0x64')][_0x522a('0x71')]);if(fs[_0x522a('0x72')](_0x5f540a)){fs[_0x522a('0x73')](_0x5f540a)[_0x522a('0x74')](fs['createWriteStream'](path[_0x522a('0x59')](_0x5442af,_0x4631b9['Attachment']['basename'])));}}return{'date':moment(_0x4631b9[_0x522a('0x66')])[_0x522a('0x4a')](_0x522a('0x4b'))[_0x522a('0x58')](),'sender':_0x4631b9[_0x522a('0x67')]==='out'?_0x4631b9[_0x522a('0x60')]?_0x4631b9[_0x522a('0x60')][_0x522a('0x61')]:_0x522a('0x75'):_0x4631b9[_0x522a('0x62')][_0x522a('0x63')]+(_0x4631b9[_0x522a('0x62')][_0x522a('0x76')]?'\x20'+_0x4631b9['Contact'][_0x522a('0x76')]:''),'body':_0x4631b9['Attachment']?_0x4631b9[_0x522a('0x64')][_0x522a('0x71')]:_0x4631b9['body'],'direction':_0x4631b9[_0x522a('0x67')]===_0x522a('0x77')?'A':'C','secret':_0x4631b9[_0x522a('0x68')],'read':_0x4631b9[_0x522a('0x69')],'attachment':_0x4631b9[_0x522a('0x64')]};})[_0x522a('0x78')]()};return ejs[_0x522a('0x79')](path['join'](config[_0x522a('0x5a')],'server',_0x522a('0x7a'),_0x522a('0x7b')),{'interaction':_0x583283})['then'](function(_0x30994b){var _0x3dc354=path[_0x522a('0x59')](_0x5442af,'transcript-'+_0x27e593['id']+'-'+_0x288fca+'.pdf');var _0x4176eb={'path':_0x3dc354,'channel':'Whatsapp','interactionId':_0x27e593['id']};return pdf[_0x522a('0x7c')](_0x30994b,_0x4176eb);})[_0x522a('0x1e')](function(){return new BPromise(function(_0x2b2212,_0x1ad8c5){zipdir(_0x5442af,{'saveTo':_0x23e0ba},function(_0x10245e,_0x4dbc7d){if(_0x10245e)return _0x1ad8c5(_0x10245e);return _0x2b2212(_0x4dbc7d);});})[_0x522a('0x1e')](function(){return new BPromise(function(_0x150d02,_0x597ea5){rimraf(_0x5442af,function(_0x161758){if(_0x161758)_0x597ea5(_0x161758);return _0x150d02();});});})[_0x522a('0x1e')](function(){return _0x58bd52[_0x522a('0x56')](_0x23e0ba,_0x1761b0,function(_0x5f0ee0){if(_0x5f0ee0){console[_0x522a('0x7d')](_0x522a('0x7e'),_0x5f0ee0);}else{fs['unlinkSync'](_0x23e0ba);}});});});}else{return _0x58bd52['sendStatus'](0xc8);}})[_0x522a('0x2b')](handleError(_0x58bd52,null));};
\ No newline at end of file
+var _0xfcb2=['includeAll','include','merge','create','update','body','addMessage','WhatsappMessage','find','ids','nolimit','limit','sort','where','WhatsappInteractionId','filter','map','$gte','YYYY-MM-DD\x20HH:mm:ss','options','rows','addTags','setTags','omit','spread','Tag','emit','removeTags','download','unix','toString','join','root','server','files','format','User','fullname','push','CmContact','firstName','attachments','Attachment','Messages','direction','read','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','createdAt','closedAt','disposition','createReadStream','pipe','createWriteStream','out','System','Contact','lastName','basename','secret','value','renderFile','views','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','defaults','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','count','Content-Range','destroy','then','error','stack','name','index','rawAttributes','fieldName','key','getOptions','findAll','whatsapp','query','catch','show','params','model','keys','WhatsappInteraction','filters','intersection','attributes','fields','length'];(function(_0x260223,_0x1deaf3){var _0x4ee3bb=function(_0x35fc9f){while(--_0x35fc9f){_0x260223['push'](_0x260223['shift']());}};_0x4ee3bb(++_0x1deaf3);}(_0xfcb2,0x1be));var _0x2fcb=function(_0x59884f,_0x266770){_0x59884f=_0x59884f-0x0;var _0xcb7fd1=_0xfcb2[_0x59884f];return _0xcb7fd1;};'use strict';var rimraf=require(_0x2fcb('0x0'));var zipdir=require(_0x2fcb('0x1'));var moment=require(_0x2fcb('0x2'));var BPromise=require(_0x2fcb('0x3'));var util=require('util');var path=require(_0x2fcb('0x4'));var ejs=require(_0x2fcb('0x5'));var fs=require('fs');var _=require(_0x2fcb('0x6'));var Redis=require(_0x2fcb('0x7'));var interaction=require(_0x2fcb('0x8'));var qs=require(_0x2fcb('0x9'));var pdf=require(_0x2fcb('0xa'));var logger=require(_0x2fcb('0xb'))(_0x2fcb('0xc'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config['redis']=_[_0x2fcb('0xd')](config[_0x2fcb('0xe')],{'host':_0x2fcb('0xf'),'port':0x18eb});var socket=require(_0x2fcb('0x10'))(new Redis(config['redis']));require(_0x2fcb('0x11'))[_0x2fcb('0x12')](socket);function respondWithStatusCode(_0x444bcb,_0x2172ca){_0x2172ca=_0x2172ca||0xcc;return function(_0x1ffbdd){if(_0x1ffbdd){return _0x444bcb[_0x2fcb('0x13')](_0x2172ca);}return _0x444bcb[_0x2fcb('0x14')](_0x2172ca)[_0x2fcb('0x15')]();};}function respondWithResult(_0x3c47d9,_0x3284dc){_0x3284dc=_0x3284dc||0xc8;return function(_0x38f93c){if(_0x38f93c){return _0x3c47d9[_0x2fcb('0x14')](_0x3284dc)[_0x2fcb('0x16')](_0x38f93c);}};}function respondWithFilteredResult(_0x559a5d,_0x5d94f1){return function(_0x52aae4){if(_0x52aae4){var _0xc68a4e=typeof _0x5d94f1[_0x2fcb('0x17')]==='undefined'&&typeof _0x5d94f1['limit']==='undefined';var _0xb42905=_0x52aae4['count'];var _0x48c2bf=_0xc68a4e?0x0:_0x5d94f1[_0x2fcb('0x17')];var _0x65eb40=_0xc68a4e?_0x52aae4[_0x2fcb('0x18')]:_0x5d94f1[_0x2fcb('0x17')]+_0x5d94f1['limit'];var _0x16deb6;if(_0x65eb40>=_0xb42905){_0x65eb40=_0xb42905;_0x16deb6=0xc8;}else{_0x16deb6=0xce;}_0x559a5d[_0x2fcb('0x14')](_0x16deb6);return _0x559a5d['set'](_0x2fcb('0x19'),_0x48c2bf+'-'+_0x65eb40+'/'+_0xb42905)[_0x2fcb('0x16')](_0x52aae4);}return null;};}function saveUpdates(_0x3f7bdb){return function(_0x8d4f80){if(_0x8d4f80){return _0x8d4f80['update'](_0x3f7bdb)['then'](function(_0x35e0ce){return _0x35e0ce;});}return null;};}function removeEntity(_0x5a1c0c){return function(_0xb74aa7){if(_0xb74aa7){return _0xb74aa7[_0x2fcb('0x1a')]()[_0x2fcb('0x1b')](function(){_0x5a1c0c[_0x2fcb('0x14')](0xcc)[_0x2fcb('0x15')]();});}};}function handleEntityNotFound(_0x15a828){return function(_0xd37b0f){if(!_0xd37b0f){_0x15a828['sendStatus'](0x194);}return _0xd37b0f;};}function handleError(_0x238cfd,_0x52245e){_0x52245e=_0x52245e||0x1f4;return function(_0x43c311){logger[_0x2fcb('0x1c')](_0x43c311[_0x2fcb('0x1d')]);if(_0x43c311[_0x2fcb('0x1e')]){delete _0x43c311[_0x2fcb('0x1e')];}_0x238cfd[_0x2fcb('0x14')](_0x52245e)['send'](_0x43c311);};}exports[_0x2fcb('0x1f')]=function(_0x57f475,_0x250d8e){var _0x175c23={};var _0x40bdf7=_['map'](db['WhatsappInteraction'][_0x2fcb('0x20')],function(_0x4dbcaa){return{'name':_0x4dbcaa[_0x2fcb('0x21')],'type':_0x4dbcaa['type'][_0x2fcb('0x22')]};});_0x175c23=qs[_0x2fcb('0x23')](_0x40bdf7,_0x57f475);return interaction[_0x2fcb('0x24')](_0x2fcb('0x25'),_0x57f475[_0x2fcb('0x26')],_0x57f475['user'],_0x175c23,_0x40bdf7)[_0x2fcb('0x1b')](respondWithFilteredResult(_0x250d8e,_0x175c23))[_0x2fcb('0x27')](handleError(_0x250d8e,null));};exports[_0x2fcb('0x28')]=function(_0x4c772d,_0x5cde93){var _0xe8e05={'raw':![],'where':{'id':_0x4c772d[_0x2fcb('0x29')]['id']}},_0x2e8e03={};_0x2e8e03[_0x2fcb('0x2a')]=_[_0x2fcb('0x2b')](db[_0x2fcb('0x2c')][_0x2fcb('0x20')]);_0x2e8e03[_0x2fcb('0x26')]=_['keys'](_0x4c772d[_0x2fcb('0x26')]);_0x2e8e03[_0x2fcb('0x2d')]=_[_0x2fcb('0x2e')](_0x2e8e03[_0x2fcb('0x2a')],_0x2e8e03[_0x2fcb('0x26')]);_0xe8e05[_0x2fcb('0x2f')]=_[_0x2fcb('0x2e')](_0x2e8e03[_0x2fcb('0x2a')],qs[_0x2fcb('0x30')](_0x4c772d[_0x2fcb('0x26')][_0x2fcb('0x30')]));_0xe8e05[_0x2fcb('0x2f')]=_0xe8e05[_0x2fcb('0x2f')][_0x2fcb('0x31')]?_0xe8e05[_0x2fcb('0x2f')]:_0x2e8e03['model'];if(_0x4c772d[_0x2fcb('0x26')][_0x2fcb('0x32')]){_0xe8e05[_0x2fcb('0x33')]=[{'all':!![]}];}_0xe8e05=_[_0x2fcb('0x34')]({},_0xe8e05,_0x4c772d['options']);return db[_0x2fcb('0x2c')]['find'](_0xe8e05)[_0x2fcb('0x1b')](handleEntityNotFound(_0x5cde93,null))[_0x2fcb('0x1b')](respondWithResult(_0x5cde93,null))['catch'](handleError(_0x5cde93,null));};exports[_0x2fcb('0x35')]=function(_0x32d0ba,_0x1fbcb5){return db[_0x2fcb('0x2c')][_0x2fcb('0x35')](_0x32d0ba['body'],{})['then'](respondWithResult(_0x1fbcb5,0xc9))[_0x2fcb('0x27')](handleError(_0x1fbcb5,null));};exports[_0x2fcb('0x36')]=function(_0x433b7c,_0xe96131){if(_0x433b7c[_0x2fcb('0x37')]['id']){delete _0x433b7c['body']['id'];}return db['WhatsappInteraction']['find']({'where':{'id':_0x433b7c['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0xe96131,null))[_0x2fcb('0x1b')](saveUpdates(_0x433b7c[_0x2fcb('0x37')],null))[_0x2fcb('0x1b')](respondWithResult(_0xe96131,null))[_0x2fcb('0x27')](handleError(_0xe96131,null));};exports['destroy']=function(_0x9380a5,_0x4235cf){return db['WhatsappInteraction']['find']({'where':{'id':_0x9380a5['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x4235cf,null))[_0x2fcb('0x1b')](removeEntity(_0x4235cf,null))['catch'](handleError(_0x4235cf,null));};exports['describe']=function(_0x1bb594,_0x568ac6){return db[_0x2fcb('0x2c')]['describe']()['then'](respondWithResult(_0x568ac6,null))[_0x2fcb('0x27')](handleError(_0x568ac6,null));};exports[_0x2fcb('0x38')]=function(_0x49a192,_0x7204e2){return db[_0x2fcb('0x39')][_0x2fcb('0x3a')]({'where':{'id':_0x49a192[_0x2fcb('0x29')]['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x7204e2,null))[_0x2fcb('0x1b')](function(_0x4e0a84){if(_0x4e0a84){return _0x4e0a84[_0x2fcb('0x38')](_0x49a192[_0x2fcb('0x37')][_0x2fcb('0x3b')],_['omit'](_0x49a192['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x7204e2,null))[_0x2fcb('0x27')](handleError(_0x7204e2,null));};exports['getMessages']=function(_0x36d09f,_0x3e78f0){var _0x18680f={'raw':![],'where':{}};var _0x1e033f={};var _0x5028a0={'count':0x0,'rows':[]};return db['WhatsappInteraction']['findOne']({'where':{'id':_0x36d09f['params']['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0x3e78f0,null))[_0x2fcb('0x1b')](function(_0x1fc275){if(_0x1fc275){_0x1e033f[_0x2fcb('0x2a')]=_['keys'](db[_0x2fcb('0x39')]['rawAttributes']);_0x1e033f['query']=_[_0x2fcb('0x2b')](_0x36d09f[_0x2fcb('0x26')]);_0x1e033f[_0x2fcb('0x2d')]=_['intersection'](_0x1e033f[_0x2fcb('0x2a')],_0x1e033f['query']);_0x18680f[_0x2fcb('0x2f')]=_[_0x2fcb('0x2e')](_0x1e033f[_0x2fcb('0x2a')],qs[_0x2fcb('0x30')](_0x36d09f[_0x2fcb('0x26')]['fields']));_0x18680f[_0x2fcb('0x2f')]=_0x18680f[_0x2fcb('0x2f')][_0x2fcb('0x31')]?_0x18680f['attributes']:_0x1e033f[_0x2fcb('0x2a')];if(!_0x36d09f[_0x2fcb('0x26')]['hasOwnProperty'](_0x2fcb('0x3c'))){_0x18680f[_0x2fcb('0x3d')]=qs[_0x2fcb('0x3d')](_0x36d09f['query'][_0x2fcb('0x3d')]);_0x18680f['offset']=qs[_0x2fcb('0x17')](_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x17')]);}_0x18680f['order']=qs['sort'](_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x3e')]);_0x18680f['where']=qs['filters'](_['pick'](_0x36d09f[_0x2fcb('0x26')],_0x1e033f['filters']));_0x18680f[_0x2fcb('0x3f')][_0x2fcb('0x40')]=_0x1fc275['id'];if(_0x36d09f['query'][_0x2fcb('0x41')]){_0x18680f[_0x2fcb('0x3f')]=_[_0x2fcb('0x34')](_0x18680f[_0x2fcb('0x3f')],{'$or':_[_0x2fcb('0x42')](_0x18680f[_0x2fcb('0x2f')],function(_0x2d6451){var _0x38bb9c={};_0x38bb9c[_0x2d6451]={'$like':'%'+_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x41')]+'%'};return _0x38bb9c;})});}if(_0x36d09f['query'][_0x2fcb('0x43')]){var _0x1b83b2=_0x36d09f[_0x2fcb('0x26')][_0x2fcb('0x43')]['split'](',');var _0x33d4fd={};_0x33d4fd[_0x1b83b2[0x0]]={'$gte':moment(_0x1b83b2[0x1])['format'](_0x2fcb('0x44'))};_0x18680f[_0x2fcb('0x3f')]=_['merge'](_0x18680f[_0x2fcb('0x3f')],_0x33d4fd);}_0x18680f=_[_0x2fcb('0x34')]({},_0x18680f,_0x36d09f[_0x2fcb('0x45')]);return db['WhatsappMessage']['count']({'where':_0x18680f[_0x2fcb('0x3f')]})[_0x2fcb('0x1b')](function(_0x4d6ce8){_0x5028a0[_0x2fcb('0x18')]=_0x4d6ce8;if(_0x36d09f['query'][_0x2fcb('0x32')]){_0x18680f[_0x2fcb('0x33')]=[{'all':!![]}];}return db[_0x2fcb('0x39')][_0x2fcb('0x24')](_0x18680f);})[_0x2fcb('0x1b')](function(_0x4badc9){_0x5028a0[_0x2fcb('0x46')]=_0x4badc9;return _0x5028a0;});}})[_0x2fcb('0x1b')](respondWithFilteredResult(_0x3e78f0,_0x18680f))['catch'](handleError(_0x3e78f0,null));};exports[_0x2fcb('0x47')]=function(_0x107023,_0x1e0562){return db[_0x2fcb('0x2c')]['find']({'where':{'id':_0x107023['params']['id']}})['then'](handleEntityNotFound(_0x1e0562,null))['then'](function(_0x579f51){if(_0x579f51){return _0x579f51[_0x2fcb('0x48')](_0x107023[_0x2fcb('0x37')]['ids'],_[_0x2fcb('0x49')](_0x107023['body'],[_0x2fcb('0x3b'),'id'])||{})[_0x2fcb('0x4a')](function(){return db[_0x2fcb('0x4b')]['findAll']({'attributes':['id','name','color'],'where':{'id':_0x107023['body']['ids']}});})[_0x2fcb('0x1b')](function(_0x12a3ca){socket[_0x2fcb('0x4c')]('whatsappInteractionTags:save',{'id':Number(_0x107023['params']['id']),'tags':_0x12a3ca||[]});return{'id':Number(_0x107023[_0x2fcb('0x29')]['id']),'tags':_0x12a3ca||[]};});}})[_0x2fcb('0x1b')](respondWithResult(_0x1e0562,null))[_0x2fcb('0x27')](handleError(_0x1e0562,null));};exports['removeTags']=function(_0x3b7d70,_0xf1f56){return db['WhatsappInteraction']['find']({'where':{'id':_0x3b7d70[_0x2fcb('0x29')]['id']}})[_0x2fcb('0x1b')](handleEntityNotFound(_0xf1f56,null))[_0x2fcb('0x1b')](function(_0xcd88d5){if(_0xcd88d5){return _0xcd88d5[_0x2fcb('0x4d')](_0x3b7d70[_0x2fcb('0x26')][_0x2fcb('0x3b')]);}})[_0x2fcb('0x1b')](respondWithStatusCode(_0xf1f56,null))[_0x2fcb('0x27')](handleError(_0xf1f56,null));};exports[_0x2fcb('0x4e')]=function(_0x54322e,_0x22d931){var _0x528a79=moment()[_0x2fcb('0x4f')]()[_0x2fcb('0x50')]();var _0x4e1e97=path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x54'),'tmp');var _0x3a40e5=path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x54'),'attachments');var _0x5847a5=path['join'](_0x4e1e97,_0x528a79);var _0xdc0e61=util[_0x2fcb('0x55')]('transcript-%d-%s.zip',_0x54322e[_0x2fcb('0x29')]['id'],_0x528a79);var _0x2bc744=path[_0x2fcb('0x51')](_0x4e1e97,_0xdc0e61);var _0x1a2014=[];_0x1a2014['push']({'model':db[_0x2fcb('0x56')],'as':'User','attributes':['id',_0x2fcb('0x57')],'raw':!![]});_0x1a2014[_0x2fcb('0x58')]({'model':db[_0x2fcb('0x59')],'as':'Contact','attributes':['id',_0x2fcb('0x5a'),'lastName'],'raw':!![]});if(_0x54322e[_0x2fcb('0x26')][_0x2fcb('0x5b')]){_0x1a2014['push']({'model':db['Attachment'],'as':_0x2fcb('0x5c'),'raw':!![]});}var _0x5b86ac=[{'model':db[_0x2fcb('0x39')],'as':_0x2fcb('0x5d'),'attributes':['id',_0x2fcb('0x37'),'createdAt',_0x2fcb('0x5e'),'secret',_0x2fcb('0x5f')],'include':_0x1a2014}];_0x5b86ac['push']({'model':db[_0x2fcb('0x60')],'as':_0x2fcb('0x61'),'attributes':['id',_0x2fcb('0x1e')]});_0x5b86ac['push']({'model':db[_0x2fcb('0x56')],'as':_0x2fcb('0x62'),'attributes':['id','fullname']});return db[_0x2fcb('0x2c')][_0x2fcb('0x3a')]({'where':{'id':_0x54322e[_0x2fcb('0x29')]['id']},'include':_0x5b86ac})[_0x2fcb('0x1b')](handleEntityNotFound(_0x22d931,null))[_0x2fcb('0x1b')](function(_0x1bb583){if(_0x1bb583){var _0x3bfa86=_0x1bb583[_0x2fcb('0x63')]({'plain':!![]});fs[_0x2fcb('0x64')](_0x5847a5);var _0x182c4d={'channel':_0x2fcb('0x65'),'account':_0x3bfa86[_0x2fcb('0x61')][_0x2fcb('0x1e')],'agent':_0x3bfa86[_0x2fcb('0x62')]?_0x3bfa86[_0x2fcb('0x62')][_0x2fcb('0x57')]:_0x2fcb('0x66'),'createdAt':moment(_0x3bfa86[_0x2fcb('0x67')])[_0x2fcb('0x55')](_0x2fcb('0x44'))['toString'](),'closedAt':_0x3bfa86['closed']?moment(_0x3bfa86[_0x2fcb('0x68')])['format'](_0x2fcb('0x44'))[_0x2fcb('0x50')]():'','disposition':_0x3bfa86[_0x2fcb('0x69')],'messages':_(_0x3bfa86['Messages'])['filter']({'secret':![]})['map'](function(_0x491c88){if(_0x491c88[_0x2fcb('0x5c')]){var _0xf4c4eb=path[_0x2fcb('0x51')](_0x3a40e5,_0x491c88['Attachment']['basename']);if(fs['existsSync'](_0xf4c4eb)){fs[_0x2fcb('0x6a')](_0xf4c4eb)[_0x2fcb('0x6b')](fs[_0x2fcb('0x6c')](path[_0x2fcb('0x51')](_0x5847a5,_0x491c88[_0x2fcb('0x5c')]['basename'])));}}return{'date':moment(_0x491c88[_0x2fcb('0x67')])[_0x2fcb('0x55')](_0x2fcb('0x44'))[_0x2fcb('0x50')](),'sender':_0x491c88['direction']===_0x2fcb('0x6d')?_0x491c88[_0x2fcb('0x56')]?_0x491c88['User'][_0x2fcb('0x57')]:_0x2fcb('0x6e'):_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x5a')]+(_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x70')]?'\x20'+_0x491c88[_0x2fcb('0x6f')][_0x2fcb('0x70')]:''),'body':_0x491c88[_0x2fcb('0x5c')]?_0x491c88[_0x2fcb('0x5c')][_0x2fcb('0x71')]:_0x491c88['body'],'direction':_0x491c88[_0x2fcb('0x5e')]===_0x2fcb('0x6d')?'A':'C','secret':_0x491c88[_0x2fcb('0x72')],'read':_0x491c88[_0x2fcb('0x5f')],'attachment':_0x491c88[_0x2fcb('0x5c')]};})[_0x2fcb('0x73')]()};return ejs[_0x2fcb('0x74')](path[_0x2fcb('0x51')](config[_0x2fcb('0x52')],_0x2fcb('0x53'),_0x2fcb('0x75'),'downloadInteraction.ejs'),{'interaction':_0x182c4d})[_0x2fcb('0x1b')](function(_0x28d5ec){var _0x5f0035=path[_0x2fcb('0x51')](_0x5847a5,_0x2fcb('0x76')+_0x3bfa86['id']+'-'+_0x528a79+_0x2fcb('0x77'));var _0x2a4091={'path':_0x5f0035,'channel':_0x2fcb('0x65'),'interactionId':_0x3bfa86['id']};return pdf[_0x2fcb('0x78')](_0x28d5ec,_0x2a4091);})[_0x2fcb('0x1b')](function(){return new BPromise(function(_0x576c1b,_0xf3d19){zipdir(_0x5847a5,{'saveTo':_0x2bc744},function(_0xabe564,_0x56d876){if(_0xabe564)return _0xf3d19(_0xabe564);return _0x576c1b(_0x56d876);});})[_0x2fcb('0x1b')](function(){return new BPromise(function(_0x17b10c,_0x3cde11){rimraf(_0x5847a5,function(_0x5b19d8){if(_0x5b19d8)_0x3cde11(_0x5b19d8);return _0x17b10c();});});})[_0x2fcb('0x1b')](function(){return _0x22d931['download'](_0x2bc744,_0xdc0e61,function(_0x2e1a1d){if(_0x2e1a1d){console[_0x2fcb('0x79')](_0x2fcb('0x7a'),_0x2e1a1d);}else{fs[_0x2fcb('0x7b')](_0x2bc744);}});});});}else{return _0x22d931['sendStatus'](0xc8);}})[_0x2fcb('0x27')](handleError(_0x22d931,null));};
\ No newline at end of file