Built motion from commit dbf3a7e2.|2.6.30
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 1a0e97b..9844203 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6334=['../../config/environment','../../mysqldb','redis','localhost','./whatsappInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','then','destroy','error','stack','name','send','index','map','WhatsappInteraction','rawAttributes','fieldName','key','findAll','whatsapp','query','catch','show','params','model','keys','intersection','fields','attributes','includeAll','include','merge','options','find','create','body','update','addMessage','WhatsappMessage','ids','omit','getMessages','findOne','hasOwnProperty','nolimit','filters','pick','where','WhatsappInteractionId','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','addTags','color','emit','removeTags','download','toString','join','root','server','files','attachments','transcript-%d-%s.zip','push','User','CmContact','Contact','firstName','Attachment','Messages','createdAt','direction','read','WhatsappAccount','Account','Owner','fullname','get','mkdirSync','N.A.','closedAt','basename','existsSync','createReadStream','pipe','createWriteStream','out','System','lastName','secret','value','renderFile','views','.pdf','Whatsapp','createPdfFromHTML','log','err','unlinkSync','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api'];(function(_0x359b9f,_0x1b897a){var _0x11d423=function(_0x109619){while(--_0x109619){_0x359b9f['push'](_0x359b9f['shift']());}};_0x11d423(++_0x1b897a);}(_0x6334,0x168));var _0x4633=function(_0x393d69,_0x3a8c83){_0x393d69=_0x393d69-0x0;var _0x3cee37=_0x6334[_0x393d69];return _0x3cee37;};'use strict';var rimraf=require('rimraf');var zipdir=require(_0x4633('0x0'));var moment=require(_0x4633('0x1'));var BPromise=require(_0x4633('0x2'));var util=require(_0x4633('0x3'));var path=require(_0x4633('0x4'));var ejs=require(_0x4633('0x5'));var fs=require('fs');var _=require(_0x4633('0x6'));var Redis=require(_0x4633('0x7'));var interaction=require('../../components/interaction/service');var qs=require(_0x4633('0x8'));var pdf=require(_0x4633('0x9'));var logger=require(_0x4633('0xa'))(_0x4633('0xb'));var config=require(_0x4633('0xc'));var db=require(_0x4633('0xd'))['db'];config[_0x4633('0xe')]=_['defaults'](config[_0x4633('0xe')],{'host':_0x4633('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4633('0xe')]));require(_0x4633('0x10'))[_0x4633('0x11')](socket);function respondWithStatusCode(_0x5778f9,_0x55c622){_0x55c622=_0x55c622||0xcc;return function(_0x224f3b){if(_0x224f3b){return _0x5778f9[_0x4633('0x12')](_0x55c622);}return _0x5778f9[_0x4633('0x13')](_0x55c622)[_0x4633('0x14')]();};}function respondWithResult(_0x196054,_0x2340b3){_0x2340b3=_0x2340b3||0xc8;return function(_0x25f426){if(_0x25f426){return _0x196054[_0x4633('0x13')](_0x2340b3)[_0x4633('0x15')](_0x25f426);}};}function respondWithFilteredResult(_0x587c17,_0x19a89c){return function(_0x32a8d4){if(_0x32a8d4){var _0x35d1bd=typeof _0x19a89c[_0x4633('0x16')]===_0x4633('0x17')&&typeof _0x19a89c[_0x4633('0x18')]===_0x4633('0x17');var _0x43365e=_0x32a8d4[_0x4633('0x19')];var _0xac7758=_0x35d1bd?0x0:_0x19a89c[_0x4633('0x16')];var _0x16eb01=_0x35d1bd?_0x32a8d4['count']:_0x19a89c[_0x4633('0x16')]+_0x19a89c[_0x4633('0x18')];var _0x114960;if(_0x16eb01>=_0x43365e){_0x16eb01=_0x43365e;_0x114960=0xc8;}else{_0x114960=0xce;}_0x587c17[_0x4633('0x13')](_0x114960);return _0x587c17[_0x4633('0x1a')](_0x4633('0x1b'),_0xac7758+'-'+_0x16eb01+'/'+_0x43365e)[_0x4633('0x15')](_0x32a8d4);}return null;};}function saveUpdates(_0x495bf3){return function(_0x131f88){if(_0x131f88){return _0x131f88['update'](_0x495bf3)[_0x4633('0x1c')](function(_0x686372){return _0x686372;});}return null;};}function removeEntity(_0x53a7ad){return function(_0x548739){if(_0x548739){return _0x548739[_0x4633('0x1d')]()['then'](function(){_0x53a7ad['status'](0xcc)[_0x4633('0x14')]();});}};}function handleEntityNotFound(_0x5ef00f){return function(_0x3868c1){if(!_0x3868c1){_0x5ef00f[_0x4633('0x12')](0x194);}return _0x3868c1;};}function handleError(_0xc40abb,_0x2e4b3b){_0x2e4b3b=_0x2e4b3b||0x1f4;return function(_0x19e75d){logger[_0x4633('0x1e')](_0x19e75d[_0x4633('0x1f')]);if(_0x19e75d[_0x4633('0x20')]){delete _0x19e75d[_0x4633('0x20')];}_0xc40abb['status'](_0x2e4b3b)[_0x4633('0x21')](_0x19e75d);};}exports[_0x4633('0x22')]=function(_0x17d319,_0x5ede9a){var _0x382d71={};var _0x562939=_[_0x4633('0x23')](db[_0x4633('0x24')][_0x4633('0x25')],function(_0x348f21){return{'name':_0x348f21[_0x4633('0x26')],'type':_0x348f21['type'][_0x4633('0x27')]};});_0x382d71=qs['getOptions'](_0x562939,_0x17d319);return interaction[_0x4633('0x28')](_0x4633('0x29'),_0x17d319[_0x4633('0x2a')],_0x17d319['user'],_0x382d71,_0x562939)[_0x4633('0x1c')](respondWithFilteredResult(_0x5ede9a,_0x382d71))[_0x4633('0x2b')](handleError(_0x5ede9a,null));};exports[_0x4633('0x2c')]=function(_0x88801a,_0x476908){var _0x3dac85={'raw':![],'where':{'id':_0x88801a[_0x4633('0x2d')]['id']}},_0x2f25b2={};_0x2f25b2[_0x4633('0x2e')]=_[_0x4633('0x2f')](db[_0x4633('0x24')][_0x4633('0x25')]);_0x2f25b2[_0x4633('0x2a')]=_[_0x4633('0x2f')](_0x88801a[_0x4633('0x2a')]);_0x2f25b2['filters']=_[_0x4633('0x30')](_0x2f25b2[_0x4633('0x2e')],_0x2f25b2[_0x4633('0x2a')]);_0x3dac85['attributes']=_[_0x4633('0x30')](_0x2f25b2['model'],qs[_0x4633('0x31')](_0x88801a[_0x4633('0x2a')][_0x4633('0x31')]));_0x3dac85[_0x4633('0x32')]=_0x3dac85[_0x4633('0x32')]['length']?_0x3dac85[_0x4633('0x32')]:_0x2f25b2[_0x4633('0x2e')];if(_0x88801a[_0x4633('0x2a')][_0x4633('0x33')]){_0x3dac85[_0x4633('0x34')]=[{'all':!![]}];}_0x3dac85=_[_0x4633('0x35')]({},_0x3dac85,_0x88801a[_0x4633('0x36')]);return db[_0x4633('0x24')][_0x4633('0x37')](_0x3dac85)[_0x4633('0x1c')](handleEntityNotFound(_0x476908,null))['then'](respondWithResult(_0x476908,null))['catch'](handleError(_0x476908,null));};exports[_0x4633('0x38')]=function(_0x209bf7,_0x23ebc3){return db[_0x4633('0x24')][_0x4633('0x38')](_0x209bf7[_0x4633('0x39')],{})['then'](respondWithResult(_0x23ebc3,0xc9))[_0x4633('0x2b')](handleError(_0x23ebc3,null));};exports[_0x4633('0x3a')]=function(_0x3ceac4,_0x4df5c3){if(_0x3ceac4[_0x4633('0x39')]['id']){delete _0x3ceac4[_0x4633('0x39')]['id'];}return db['WhatsappInteraction'][_0x4633('0x37')]({'where':{'id':_0x3ceac4[_0x4633('0x2d')]['id']}})['then'](handleEntityNotFound(_0x4df5c3,null))[_0x4633('0x1c')](saveUpdates(_0x3ceac4[_0x4633('0x39')],null))['then'](respondWithResult(_0x4df5c3,null))[_0x4633('0x2b')](handleError(_0x4df5c3,null));};exports['destroy']=function(_0x3d46b0,_0x472273){return db[_0x4633('0x24')][_0x4633('0x37')]({'where':{'id':_0x3d46b0[_0x4633('0x2d')]['id']}})[_0x4633('0x1c')](handleEntityNotFound(_0x472273,null))[_0x4633('0x1c')](removeEntity(_0x472273,null))[_0x4633('0x2b')](handleError(_0x472273,null));};exports['describe']=function(_0x9ffaf3,_0x3a7898){return db[_0x4633('0x24')]['describe']()[_0x4633('0x1c')](respondWithResult(_0x3a7898,null))[_0x4633('0x2b')](handleError(_0x3a7898,null));};exports[_0x4633('0x3b')]=function(_0x519259,_0x5a2411){return db[_0x4633('0x3c')][_0x4633('0x37')]({'where':{'id':_0x519259[_0x4633('0x2d')]['id']}})['then'](handleEntityNotFound(_0x5a2411,null))['then'](function(_0x36dc48){if(_0x36dc48){return _0x36dc48[_0x4633('0x3b')](_0x519259[_0x4633('0x39')][_0x4633('0x3d')],_[_0x4633('0x3e')](_0x519259[_0x4633('0x39')],[_0x4633('0x3d'),'id'])||{});}})['then'](respondWithResult(_0x5a2411,null))[_0x4633('0x2b')](handleError(_0x5a2411,null));};exports[_0x4633('0x3f')]=function(_0xd1f6c9,_0x27737b){var _0x18545a={'raw':![],'where':{}};var _0x17318b={};var _0x3e0dcd={'count':0x0,'rows':[]};return db[_0x4633('0x24')][_0x4633('0x40')]({'where':{'id':_0xd1f6c9['params']['id']}})[_0x4633('0x1c')](handleEntityNotFound(_0x27737b,null))[_0x4633('0x1c')](function(_0x30b707){if(_0x30b707){_0x17318b['model']=_[_0x4633('0x2f')](db[_0x4633('0x3c')][_0x4633('0x25')]);_0x17318b[_0x4633('0x2a')]=_[_0x4633('0x2f')](_0xd1f6c9[_0x4633('0x2a')]);_0x17318b['filters']=_[_0x4633('0x30')](_0x17318b[_0x4633('0x2e')],_0x17318b['query']);_0x18545a['attributes']=_[_0x4633('0x30')](_0x17318b[_0x4633('0x2e')],qs[_0x4633('0x31')](_0xd1f6c9[_0x4633('0x2a')][_0x4633('0x31')]));_0x18545a[_0x4633('0x32')]=_0x18545a[_0x4633('0x32')]['length']?_0x18545a[_0x4633('0x32')]:_0x17318b[_0x4633('0x2e')];if(!_0xd1f6c9[_0x4633('0x2a')][_0x4633('0x41')](_0x4633('0x42'))){_0x18545a['limit']=qs[_0x4633('0x18')](_0xd1f6c9['query'][_0x4633('0x18')]);_0x18545a[_0x4633('0x16')]=qs[_0x4633('0x16')](_0xd1f6c9[_0x4633('0x2a')][_0x4633('0x16')]);}_0x18545a['order']=qs['sort'](_0xd1f6c9['query']['sort']);_0x18545a['where']=qs[_0x4633('0x43')](_[_0x4633('0x44')](_0xd1f6c9[_0x4633('0x2a')],_0x17318b[_0x4633('0x43')]));_0x18545a[_0x4633('0x45')][_0x4633('0x46')]=_0x30b707['id'];if(_0xd1f6c9['query'][_0x4633('0x47')]){_0x18545a[_0x4633('0x45')]=_[_0x4633('0x35')](_0x18545a[_0x4633('0x45')],{'$or':_[_0x4633('0x23')](_0x18545a[_0x4633('0x32')],function(_0x3bea1b){var _0x4e3556={};_0x4e3556[_0x3bea1b]={'$like':'%'+_0xd1f6c9[_0x4633('0x2a')][_0x4633('0x47')]+'%'};return _0x4e3556;})});}if(_0xd1f6c9[_0x4633('0x2a')]['$gte']){var _0x266d39=_0xd1f6c9[_0x4633('0x2a')][_0x4633('0x48')][_0x4633('0x49')](',');var _0x31d237={};_0x31d237[_0x266d39[0x0]]={'$gte':moment(_0x266d39[0x1])[_0x4633('0x4a')](_0x4633('0x4b'))};_0x18545a[_0x4633('0x45')]=_[_0x4633('0x35')](_0x18545a[_0x4633('0x45')],_0x31d237);}_0x18545a=_['merge']({},_0x18545a,_0xd1f6c9['options']);return db[_0x4633('0x3c')][_0x4633('0x19')]({'where':_0x18545a[_0x4633('0x45')]})[_0x4633('0x1c')](function(_0x11827b){_0x3e0dcd[_0x4633('0x19')]=_0x11827b;if(_0xd1f6c9['query'][_0x4633('0x33')]){_0x18545a[_0x4633('0x34')]=[{'all':!![]}];}return db[_0x4633('0x3c')]['findAll'](_0x18545a);})[_0x4633('0x1c')](function(_0x5e7fcd){_0x3e0dcd['rows']=_0x5e7fcd;return _0x3e0dcd;});}})[_0x4633('0x1c')](respondWithFilteredResult(_0x27737b,_0x18545a))['catch'](handleError(_0x27737b,null));};exports[_0x4633('0x4c')]=function(_0x347b49,_0x1b36e3){return db[_0x4633('0x24')][_0x4633('0x37')]({'where':{'id':_0x347b49[_0x4633('0x2d')]['id']}})[_0x4633('0x1c')](handleEntityNotFound(_0x1b36e3,null))[_0x4633('0x1c')](function(_0x5d9739){if(_0x5d9739){return _0x5d9739['setTags'](_0x347b49[_0x4633('0x39')]['ids'],_[_0x4633('0x3e')](_0x347b49['body'],[_0x4633('0x3d'),'id'])||{})['spread'](function(){return db['Tag']['findAll']({'attributes':['id',_0x4633('0x20'),_0x4633('0x4d')],'where':{'id':_0x347b49[_0x4633('0x39')][_0x4633('0x3d')]}});})[_0x4633('0x1c')](function(_0x29aa73){socket[_0x4633('0x4e')]('whatsappInteractionTags:save',{'id':Number(_0x347b49[_0x4633('0x2d')]['id']),'tags':_0x29aa73||[]});return{'id':Number(_0x347b49[_0x4633('0x2d')]['id']),'tags':_0x29aa73||[]};});}})[_0x4633('0x1c')](respondWithResult(_0x1b36e3,null))['catch'](handleError(_0x1b36e3,null));};exports[_0x4633('0x4f')]=function(_0x30ea67,_0x412446){return db[_0x4633('0x24')][_0x4633('0x37')]({'where':{'id':_0x30ea67['params']['id']}})['then'](handleEntityNotFound(_0x412446,null))[_0x4633('0x1c')](function(_0x22bec3){if(_0x22bec3){return _0x22bec3[_0x4633('0x4f')](_0x30ea67[_0x4633('0x2a')][_0x4633('0x3d')]);}})['then'](respondWithStatusCode(_0x412446,null))[_0x4633('0x2b')](handleError(_0x412446,null));};exports[_0x4633('0x50')]=function(_0x1b4282,_0x5e4dce){var _0xa76d25=moment()['unix']()[_0x4633('0x51')]();var _0x4c58e0=path[_0x4633('0x52')](config[_0x4633('0x53')],_0x4633('0x54'),_0x4633('0x55'),'tmp');var _0x15bbf5=path[_0x4633('0x52')](config['root'],_0x4633('0x54'),_0x4633('0x55'),_0x4633('0x56'));var _0x4a65aa=path[_0x4633('0x52')](_0x4c58e0,_0xa76d25);var _0x2b977e=util[_0x4633('0x4a')](_0x4633('0x57'),_0x1b4282[_0x4633('0x2d')]['id'],_0xa76d25);var _0x1bef31=path[_0x4633('0x52')](_0x4c58e0,_0x2b977e);var _0x21f971=[];_0x21f971[_0x4633('0x58')]({'model':db[_0x4633('0x59')],'as':_0x4633('0x59'),'attributes':['id','fullname'],'raw':!![]});_0x21f971[_0x4633('0x58')]({'model':db[_0x4633('0x5a')],'as':_0x4633('0x5b'),'attributes':['id',_0x4633('0x5c'),'lastName'],'raw':!![]});if(_0x1b4282['query']['attachments']){_0x21f971[_0x4633('0x58')]({'model':db[_0x4633('0x5d')],'as':_0x4633('0x5d'),'raw':!![]});}var _0x46d557=[{'model':db['WhatsappMessage'],'as':_0x4633('0x5e'),'attributes':['id',_0x4633('0x39'),_0x4633('0x5f'),_0x4633('0x60'),'secret',_0x4633('0x61')],'include':_0x21f971}];_0x46d557[_0x4633('0x58')]({'model':db[_0x4633('0x62')],'as':_0x4633('0x63'),'attributes':['id',_0x4633('0x20')]});_0x46d557['push']({'model':db[_0x4633('0x59')],'as':_0x4633('0x64'),'attributes':['id',_0x4633('0x65')]});return db['WhatsappInteraction'][_0x4633('0x37')]({'where':{'id':_0x1b4282[_0x4633('0x2d')]['id']},'include':_0x46d557})[_0x4633('0x1c')](handleEntityNotFound(_0x5e4dce,null))[_0x4633('0x1c')](function(_0x49d1d3){if(_0x49d1d3){var _0x5dcf31=_0x49d1d3[_0x4633('0x66')]({'plain':!![]});fs[_0x4633('0x67')](_0x4a65aa);var _0x82ec88={'channel':'Whatsapp','account':_0x5dcf31[_0x4633('0x63')]['name'],'agent':_0x5dcf31[_0x4633('0x64')]?_0x5dcf31[_0x4633('0x64')]['fullname']:_0x4633('0x68'),'createdAt':moment(_0x5dcf31[_0x4633('0x5f')])['format'](_0x4633('0x4b'))[_0x4633('0x51')](),'closedAt':_0x5dcf31['closed']?moment(_0x5dcf31[_0x4633('0x69')])[_0x4633('0x4a')](_0x4633('0x4b'))[_0x4633('0x51')]():'','disposition':_0x5dcf31['disposition'],'messages':_(_0x5dcf31[_0x4633('0x5e')])[_0x4633('0x47')]({'secret':![]})[_0x4633('0x23')](function(_0x5bed3d){if(_0x5bed3d[_0x4633('0x5d')]){var _0x1bd452=path[_0x4633('0x52')](_0x15bbf5,_0x5bed3d[_0x4633('0x5d')][_0x4633('0x6a')]);if(fs[_0x4633('0x6b')](_0x1bd452)){fs[_0x4633('0x6c')](_0x1bd452)[_0x4633('0x6d')](fs[_0x4633('0x6e')](path[_0x4633('0x52')](_0x4a65aa,_0x5bed3d['Attachment']['basename'])));}}return{'date':moment(_0x5bed3d[_0x4633('0x5f')])[_0x4633('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x5bed3d['direction']===_0x4633('0x6f')?_0x5bed3d[_0x4633('0x59')]?_0x5bed3d[_0x4633('0x59')][_0x4633('0x65')]:_0x4633('0x70'):_0x5bed3d[_0x4633('0x5b')]['firstName']+(_0x5bed3d[_0x4633('0x5b')]['lastName']?'\x20'+_0x5bed3d[_0x4633('0x5b')][_0x4633('0x71')]:''),'body':_0x5bed3d[_0x4633('0x5d')]?_0x5bed3d[_0x4633('0x5d')]['basename']:_0x5bed3d[_0x4633('0x39')],'direction':_0x5bed3d[_0x4633('0x60')]==='out'?'A':'C','secret':_0x5bed3d[_0x4633('0x72')],'read':_0x5bed3d[_0x4633('0x61')],'attachment':_0x5bed3d[_0x4633('0x5d')]};})[_0x4633('0x73')]()};return ejs[_0x4633('0x74')](path[_0x4633('0x52')](config[_0x4633('0x53')],_0x4633('0x54'),_0x4633('0x75'),'downloadInteraction.ejs'),{'interaction':_0x82ec88})[_0x4633('0x1c')](function(_0x50919a){var _0x10c719=path[_0x4633('0x52')](_0x4a65aa,'transcript-'+_0x5dcf31['id']+'-'+_0xa76d25+_0x4633('0x76'));var _0x23d7a9={'path':_0x10c719,'channel':_0x4633('0x77'),'interactionId':_0x5dcf31['id']};return pdf[_0x4633('0x78')](_0x50919a,_0x23d7a9);})[_0x4633('0x1c')](function(){return new BPromise(function(_0x5aec8d,_0x27714c){zipdir(_0x4a65aa,{'saveTo':_0x1bef31},function(_0x2c150c,_0x1bf46f){if(_0x2c150c)return _0x27714c(_0x2c150c);return _0x5aec8d(_0x1bf46f);});})[_0x4633('0x1c')](function(){return new BPromise(function(_0x7fed8d,_0x60b69d){rimraf(_0x4a65aa,function(_0x10883f){if(_0x10883f)_0x60b69d(_0x10883f);return _0x7fed8d();});});})['then'](function(){return _0x5e4dce['download'](_0x1bef31,_0x2b977e,function(_0x431386){if(_0x431386){console[_0x4633('0x79')](_0x4633('0x7a'),_0x431386);}else{fs[_0x4633('0x7b')](_0x1bef31);}});});});}else{return _0x5e4dce['sendStatus'](0xc8);}})[_0x4633('0x2b')](handleError(_0x5e4dce,null));};
\ No newline at end of file
+var _0x02f9=['secret','read','WhatsappAccount','Account','Owner','get','mkdirSync','Whatsapp','N.A.','YYYY-MM-DD\x20HH:mm:ss','toString','closedAt','createReadStream','pipe','createWriteStream','out','System','direction','value','views','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','log','unlinkSync','rimraf','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','./whatsappInteraction.socket','register','sendStatus','status','json','undefined','limit','count','offset','set','Content-Range','update','then','end','error','stack','name','index','map','WhatsappInteraction','rawAttributes','fieldName','type','key','getOptions','query','user','catch','show','params','model','keys','filters','intersection','attributes','fields','include','options','find','body','destroy','describe','addMessage','WhatsappMessage','ids','omit','getMessages','findOne','length','hasOwnProperty','sort','where','pick','WhatsappInteractionId','filter','merge','$gte','split','format','findAll','rows','addTags','setTags','spread','Tag','emit','whatsappInteractionTags:save','removeTags','download','join','tmp','server','files','attachments','push','User','fullname','CmContact','Contact','lastName','Attachment','Messages','createdAt'];(function(_0x1f8378,_0x54e398){var _0x3a0d83=function(_0x31bcf4){while(--_0x31bcf4){_0x1f8378['push'](_0x1f8378['shift']());}};_0x3a0d83(++_0x54e398);}(_0x02f9,0x19a));var _0x902f=function(_0x13dfac,_0xe5c2f){_0x13dfac=_0x13dfac-0x0;var _0x19f949=_0x02f9[_0x13dfac];return _0x19f949;};'use strict';var rimraf=require(_0x902f('0x0'));var zipdir=require(_0x902f('0x1'));var moment=require(_0x902f('0x2'));var BPromise=require(_0x902f('0x3'));var util=require(_0x902f('0x4'));var path=require(_0x902f('0x5'));var ejs=require(_0x902f('0x6'));var fs=require('fs');var _=require(_0x902f('0x7'));var Redis=require(_0x902f('0x8'));var interaction=require(_0x902f('0x9'));var qs=require(_0x902f('0xa'));var pdf=require(_0x902f('0xb'));var logger=require(_0x902f('0xc'))(_0x902f('0xd'));var config=require(_0x902f('0xe'));var db=require(_0x902f('0xf'))['db'];config[_0x902f('0x10')]=_[_0x902f('0x11')](config[_0x902f('0x10')],{'host':_0x902f('0x12'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x902f('0x10')]));require(_0x902f('0x13'))[_0x902f('0x14')](socket);function respondWithStatusCode(_0x20a854,_0x298bbc){_0x298bbc=_0x298bbc||0xcc;return function(_0x12a480){if(_0x12a480){return _0x20a854[_0x902f('0x15')](_0x298bbc);}return _0x20a854['status'](_0x298bbc)['end']();};}function respondWithResult(_0x18fb2b,_0x8359ac){_0x8359ac=_0x8359ac||0xc8;return function(_0x15ed46){if(_0x15ed46){return _0x18fb2b[_0x902f('0x16')](_0x8359ac)[_0x902f('0x17')](_0x15ed46);}};}function respondWithFilteredResult(_0x4d40a9,_0x4a5d57){return function(_0x4f6efb){if(_0x4f6efb){var _0x425f62=typeof _0x4a5d57['offset']===_0x902f('0x18')&&typeof _0x4a5d57[_0x902f('0x19')]===_0x902f('0x18');var _0x249860=_0x4f6efb[_0x902f('0x1a')];var _0x40bbf2=_0x425f62?0x0:_0x4a5d57[_0x902f('0x1b')];var _0x5e953e=_0x425f62?_0x4f6efb[_0x902f('0x1a')]:_0x4a5d57[_0x902f('0x1b')]+_0x4a5d57[_0x902f('0x19')];var _0x315168;if(_0x5e953e>=_0x249860){_0x5e953e=_0x249860;_0x315168=0xc8;}else{_0x315168=0xce;}_0x4d40a9[_0x902f('0x16')](_0x315168);return _0x4d40a9[_0x902f('0x1c')](_0x902f('0x1d'),_0x40bbf2+'-'+_0x5e953e+'/'+_0x249860)[_0x902f('0x17')](_0x4f6efb);}return null;};}function saveUpdates(_0xf425bb){return function(_0x44efd3){if(_0x44efd3){return _0x44efd3[_0x902f('0x1e')](_0xf425bb)[_0x902f('0x1f')](function(_0x1773f7){return _0x1773f7;});}return null;};}function removeEntity(_0x32e906){return function(_0x7271){if(_0x7271){return _0x7271['destroy']()[_0x902f('0x1f')](function(){_0x32e906['status'](0xcc)[_0x902f('0x20')]();});}};}function handleEntityNotFound(_0x4c2082){return function(_0x58b41d){if(!_0x58b41d){_0x4c2082['sendStatus'](0x194);}return _0x58b41d;};}function handleError(_0x43b838,_0x5b69a4){_0x5b69a4=_0x5b69a4||0x1f4;return function(_0x345c00){logger[_0x902f('0x21')](_0x345c00[_0x902f('0x22')]);if(_0x345c00[_0x902f('0x23')]){delete _0x345c00[_0x902f('0x23')];}_0x43b838[_0x902f('0x16')](_0x5b69a4)['send'](_0x345c00);};}exports[_0x902f('0x24')]=function(_0x333897,_0x34cb41){var _0x2ba602={};var _0x520f91=_[_0x902f('0x25')](db[_0x902f('0x26')][_0x902f('0x27')],function(_0x4276f2){return{'name':_0x4276f2[_0x902f('0x28')],'type':_0x4276f2[_0x902f('0x29')][_0x902f('0x2a')]};});_0x2ba602=qs[_0x902f('0x2b')](_0x520f91,_0x333897);return interaction['findAll']('whatsapp',_0x333897[_0x902f('0x2c')],_0x333897[_0x902f('0x2d')],_0x2ba602,_0x520f91)[_0x902f('0x1f')](respondWithFilteredResult(_0x34cb41,_0x2ba602))[_0x902f('0x2e')](handleError(_0x34cb41,null));};exports[_0x902f('0x2f')]=function(_0x562bd1,_0x5d5b5b){var _0x49803b={'raw':![],'where':{'id':_0x562bd1[_0x902f('0x30')]['id']}},_0x2d3cd7={};_0x2d3cd7[_0x902f('0x31')]=_[_0x902f('0x32')](db['WhatsappInteraction'][_0x902f('0x27')]);_0x2d3cd7[_0x902f('0x2c')]=_[_0x902f('0x32')](_0x562bd1['query']);_0x2d3cd7[_0x902f('0x33')]=_[_0x902f('0x34')](_0x2d3cd7[_0x902f('0x31')],_0x2d3cd7[_0x902f('0x2c')]);_0x49803b[_0x902f('0x35')]=_[_0x902f('0x34')](_0x2d3cd7[_0x902f('0x31')],qs[_0x902f('0x36')](_0x562bd1[_0x902f('0x2c')][_0x902f('0x36')]));_0x49803b[_0x902f('0x35')]=_0x49803b['attributes']['length']?_0x49803b[_0x902f('0x35')]:_0x2d3cd7[_0x902f('0x31')];if(_0x562bd1['query']['includeAll']){_0x49803b[_0x902f('0x37')]=[{'all':!![]}];}_0x49803b=_['merge']({},_0x49803b,_0x562bd1[_0x902f('0x38')]);return db['WhatsappInteraction'][_0x902f('0x39')](_0x49803b)['then'](handleEntityNotFound(_0x5d5b5b,null))[_0x902f('0x1f')](respondWithResult(_0x5d5b5b,null))[_0x902f('0x2e')](handleError(_0x5d5b5b,null));};exports['create']=function(_0x188709,_0x56419c){return db[_0x902f('0x26')]['create'](_0x188709[_0x902f('0x3a')],{})[_0x902f('0x1f')](respondWithResult(_0x56419c,0xc9))[_0x902f('0x2e')](handleError(_0x56419c,null));};exports[_0x902f('0x1e')]=function(_0x5822ba,_0x5c62e6){if(_0x5822ba['body']['id']){delete _0x5822ba[_0x902f('0x3a')]['id'];}return db[_0x902f('0x26')][_0x902f('0x39')]({'where':{'id':_0x5822ba[_0x902f('0x30')]['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x5c62e6,null))['then'](saveUpdates(_0x5822ba[_0x902f('0x3a')],null))['then'](respondWithResult(_0x5c62e6,null))[_0x902f('0x2e')](handleError(_0x5c62e6,null));};exports[_0x902f('0x3b')]=function(_0x46db98,_0x70fbef){return db[_0x902f('0x26')][_0x902f('0x39')]({'where':{'id':_0x46db98[_0x902f('0x30')]['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x70fbef,null))[_0x902f('0x1f')](removeEntity(_0x70fbef,null))[_0x902f('0x2e')](handleError(_0x70fbef,null));};exports['describe']=function(_0x30b1bf,_0x408b05){return db[_0x902f('0x26')][_0x902f('0x3c')]()[_0x902f('0x1f')](respondWithResult(_0x408b05,null))[_0x902f('0x2e')](handleError(_0x408b05,null));};exports[_0x902f('0x3d')]=function(_0x4f76eb,_0x30d109){return db[_0x902f('0x3e')][_0x902f('0x39')]({'where':{'id':_0x4f76eb['params']['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x30d109,null))[_0x902f('0x1f')](function(_0x42bf0a){if(_0x42bf0a){return _0x42bf0a['addMessage'](_0x4f76eb['body'][_0x902f('0x3f')],_[_0x902f('0x40')](_0x4f76eb[_0x902f('0x3a')],[_0x902f('0x3f'),'id'])||{});}})[_0x902f('0x1f')](respondWithResult(_0x30d109,null))[_0x902f('0x2e')](handleError(_0x30d109,null));};exports[_0x902f('0x41')]=function(_0x4c56a4,_0x815de){var _0x37f903={'raw':![],'where':{}};var _0x3f802a={};var _0xf96e50={'count':0x0,'rows':[]};return db[_0x902f('0x26')][_0x902f('0x42')]({'where':{'id':_0x4c56a4[_0x902f('0x30')]['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x815de,null))[_0x902f('0x1f')](function(_0x27fce8){if(_0x27fce8){_0x3f802a['model']=_[_0x902f('0x32')](db[_0x902f('0x3e')][_0x902f('0x27')]);_0x3f802a[_0x902f('0x2c')]=_[_0x902f('0x32')](_0x4c56a4['query']);_0x3f802a[_0x902f('0x33')]=_[_0x902f('0x34')](_0x3f802a[_0x902f('0x31')],_0x3f802a[_0x902f('0x2c')]);_0x37f903['attributes']=_[_0x902f('0x34')](_0x3f802a[_0x902f('0x31')],qs[_0x902f('0x36')](_0x4c56a4[_0x902f('0x2c')][_0x902f('0x36')]));_0x37f903[_0x902f('0x35')]=_0x37f903[_0x902f('0x35')][_0x902f('0x43')]?_0x37f903[_0x902f('0x35')]:_0x3f802a[_0x902f('0x31')];if(!_0x4c56a4[_0x902f('0x2c')][_0x902f('0x44')]('nolimit')){_0x37f903[_0x902f('0x19')]=qs[_0x902f('0x19')](_0x4c56a4[_0x902f('0x2c')]['limit']);_0x37f903[_0x902f('0x1b')]=qs[_0x902f('0x1b')](_0x4c56a4['query'][_0x902f('0x1b')]);}_0x37f903['order']=qs[_0x902f('0x45')](_0x4c56a4['query']['sort']);_0x37f903[_0x902f('0x46')]=qs['filters'](_[_0x902f('0x47')](_0x4c56a4['query'],_0x3f802a['filters']));_0x37f903['where'][_0x902f('0x48')]=_0x27fce8['id'];if(_0x4c56a4[_0x902f('0x2c')][_0x902f('0x49')]){_0x37f903[_0x902f('0x46')]=_[_0x902f('0x4a')](_0x37f903[_0x902f('0x46')],{'$or':_['map'](_0x37f903['attributes'],function(_0x5c4679){var _0x221bce={};_0x221bce[_0x5c4679]={'$like':'%'+_0x4c56a4[_0x902f('0x2c')][_0x902f('0x49')]+'%'};return _0x221bce;})});}if(_0x4c56a4[_0x902f('0x2c')][_0x902f('0x4b')]){var _0x5e498f=_0x4c56a4[_0x902f('0x2c')][_0x902f('0x4b')][_0x902f('0x4c')](',');var _0x355021={};_0x355021[_0x5e498f[0x0]]={'$gte':moment(_0x5e498f[0x1])[_0x902f('0x4d')]('YYYY-MM-DD\x20HH:mm:ss')};_0x37f903[_0x902f('0x46')]=_['merge'](_0x37f903[_0x902f('0x46')],_0x355021);}_0x37f903=_[_0x902f('0x4a')]({},_0x37f903,_0x4c56a4[_0x902f('0x38')]);return db['WhatsappMessage'][_0x902f('0x1a')]({'where':_0x37f903[_0x902f('0x46')]})[_0x902f('0x1f')](function(_0xc94155){_0xf96e50[_0x902f('0x1a')]=_0xc94155;if(_0x4c56a4[_0x902f('0x2c')]['includeAll']){_0x37f903[_0x902f('0x37')]=[{'all':!![]}];}return db[_0x902f('0x3e')][_0x902f('0x4e')](_0x37f903);})[_0x902f('0x1f')](function(_0x22a7bd){_0xf96e50[_0x902f('0x4f')]=_0x22a7bd;return _0xf96e50;});}})['then'](respondWithFilteredResult(_0x815de,_0x37f903))['catch'](handleError(_0x815de,null));};exports[_0x902f('0x50')]=function(_0x2ed10e,_0x21ce48){return db[_0x902f('0x26')][_0x902f('0x39')]({'where':{'id':_0x2ed10e[_0x902f('0x30')]['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x21ce48,null))[_0x902f('0x1f')](function(_0x591d5b){if(_0x591d5b){return _0x591d5b[_0x902f('0x51')](_0x2ed10e[_0x902f('0x3a')][_0x902f('0x3f')],_['omit'](_0x2ed10e['body'],['ids','id'])||{})[_0x902f('0x52')](function(){return db[_0x902f('0x53')][_0x902f('0x4e')]({'attributes':['id',_0x902f('0x23'),'color'],'where':{'id':_0x2ed10e[_0x902f('0x3a')][_0x902f('0x3f')]}});})[_0x902f('0x1f')](function(_0x120bae){socket[_0x902f('0x54')](_0x902f('0x55'),{'id':Number(_0x2ed10e[_0x902f('0x30')]['id']),'tags':_0x120bae||[]});return{'id':Number(_0x2ed10e[_0x902f('0x30')]['id']),'tags':_0x120bae||[]};});}})['then'](respondWithResult(_0x21ce48,null))[_0x902f('0x2e')](handleError(_0x21ce48,null));};exports[_0x902f('0x56')]=function(_0xf9f387,_0x5dfef2){return db[_0x902f('0x26')][_0x902f('0x39')]({'where':{'id':_0xf9f387[_0x902f('0x30')]['id']}})[_0x902f('0x1f')](handleEntityNotFound(_0x5dfef2,null))[_0x902f('0x1f')](function(_0x2ef6ab){if(_0x2ef6ab){return _0x2ef6ab['removeTags'](_0xf9f387[_0x902f('0x2c')][_0x902f('0x3f')]);}})[_0x902f('0x1f')](respondWithStatusCode(_0x5dfef2,null))[_0x902f('0x2e')](handleError(_0x5dfef2,null));};exports[_0x902f('0x57')]=function(_0x573153,_0x442ad4){var _0x3b2e79=moment()['unix']()['toString']();var _0x44a25d=path[_0x902f('0x58')](config['root'],'server','files',_0x902f('0x59'));var _0x4c2a55=path[_0x902f('0x58')](config['root'],_0x902f('0x5a'),_0x902f('0x5b'),_0x902f('0x5c'));var _0x1ac6e5=path[_0x902f('0x58')](_0x44a25d,_0x3b2e79);var _0x241535=util[_0x902f('0x4d')]('transcript-%d-%s.zip',_0x573153['params']['id'],_0x3b2e79);var _0x582221=path[_0x902f('0x58')](_0x44a25d,_0x241535);var _0x2cfb2b=[];_0x2cfb2b[_0x902f('0x5d')]({'model':db[_0x902f('0x5e')],'as':_0x902f('0x5e'),'attributes':['id',_0x902f('0x5f')],'raw':!![]});_0x2cfb2b[_0x902f('0x5d')]({'model':db[_0x902f('0x60')],'as':_0x902f('0x61'),'attributes':['id','firstName',_0x902f('0x62')],'raw':!![]});if(_0x573153[_0x902f('0x2c')][_0x902f('0x5c')]){_0x2cfb2b[_0x902f('0x5d')]({'model':db[_0x902f('0x63')],'as':'Attachment','raw':!![]});}var _0x47fe9f=[{'model':db[_0x902f('0x3e')],'as':_0x902f('0x64'),'attributes':['id',_0x902f('0x3a'),_0x902f('0x65'),'direction',_0x902f('0x66'),_0x902f('0x67')],'include':_0x2cfb2b}];_0x47fe9f[_0x902f('0x5d')]({'model':db[_0x902f('0x68')],'as':_0x902f('0x69'),'attributes':['id',_0x902f('0x23')]});_0x47fe9f[_0x902f('0x5d')]({'model':db[_0x902f('0x5e')],'as':_0x902f('0x6a'),'attributes':['id',_0x902f('0x5f')]});return db['WhatsappInteraction'][_0x902f('0x39')]({'where':{'id':_0x573153['params']['id']},'include':_0x47fe9f})[_0x902f('0x1f')](handleEntityNotFound(_0x442ad4,null))[_0x902f('0x1f')](function(_0x1bbeca){if(_0x1bbeca){var _0x1e9296=_0x1bbeca[_0x902f('0x6b')]({'plain':!![]});fs[_0x902f('0x6c')](_0x1ac6e5);var _0x2c6e3b={'channel':_0x902f('0x6d'),'account':_0x1e9296[_0x902f('0x69')][_0x902f('0x23')],'agent':_0x1e9296[_0x902f('0x6a')]?_0x1e9296[_0x902f('0x6a')][_0x902f('0x5f')]:_0x902f('0x6e'),'createdAt':moment(_0x1e9296['createdAt'])[_0x902f('0x4d')](_0x902f('0x6f'))[_0x902f('0x70')](),'closedAt':_0x1e9296['closed']?moment(_0x1e9296[_0x902f('0x71')])[_0x902f('0x4d')](_0x902f('0x6f'))[_0x902f('0x70')]():'','disposition':_0x1e9296['disposition'],'messages':_(_0x1e9296['Messages'])[_0x902f('0x49')]({'secret':![]})[_0x902f('0x25')](function(_0x40e565){if(_0x40e565[_0x902f('0x63')]){var _0x4390d2=path[_0x902f('0x58')](_0x4c2a55,_0x40e565[_0x902f('0x63')]['basename']);if(fs['existsSync'](_0x4390d2)){fs[_0x902f('0x72')](_0x4390d2)[_0x902f('0x73')](fs[_0x902f('0x74')](path['join'](_0x1ac6e5,_0x40e565[_0x902f('0x63')]['basename'])));}}return{'date':moment(_0x40e565['createdAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0x902f('0x70')](),'sender':_0x40e565['direction']===_0x902f('0x75')?_0x40e565[_0x902f('0x5e')]?_0x40e565[_0x902f('0x5e')]['fullname']:_0x902f('0x76'):_0x40e565['Contact']['firstName']+(_0x40e565[_0x902f('0x61')][_0x902f('0x62')]?'\x20'+_0x40e565[_0x902f('0x61')][_0x902f('0x62')]:''),'body':_0x40e565['Attachment']?_0x40e565[_0x902f('0x63')]['basename']:_0x40e565[_0x902f('0x3a')],'direction':_0x40e565[_0x902f('0x77')]===_0x902f('0x75')?'A':'C','secret':_0x40e565[_0x902f('0x66')],'read':_0x40e565[_0x902f('0x67')],'attachment':_0x40e565[_0x902f('0x63')]};})[_0x902f('0x78')]()};return ejs['renderFile'](path[_0x902f('0x58')](config['root'],_0x902f('0x5a'),_0x902f('0x79'),_0x902f('0x7a')),{'interaction':_0x2c6e3b})[_0x902f('0x1f')](function(_0x80e321){var _0x267b0a=path[_0x902f('0x58')](_0x1ac6e5,_0x902f('0x7b')+_0x1e9296['id']+'-'+_0x3b2e79+_0x902f('0x7c'));var _0x58a3fb={'path':_0x267b0a,'channel':_0x902f('0x6d'),'interactionId':_0x1e9296['id']};return pdf[_0x902f('0x7d')](_0x80e321,_0x58a3fb);})[_0x902f('0x1f')](function(){return new BPromise(function(_0x53d30a,_0x1f17c2){zipdir(_0x1ac6e5,{'saveTo':_0x582221},function(_0x5072e9,_0x39efe8){if(_0x5072e9)return _0x1f17c2(_0x5072e9);return _0x53d30a(_0x39efe8);});})['then'](function(){return new BPromise(function(_0x4ee12a,_0x8fffea){rimraf(_0x1ac6e5,function(_0x1092a8){if(_0x1092a8)_0x8fffea(_0x1092a8);return _0x4ee12a();});});})[_0x902f('0x1f')](function(){return _0x442ad4[_0x902f('0x57')](_0x582221,_0x241535,function(_0x1a6022){if(_0x1a6022){console[_0x902f('0x7e')]('err',_0x1a6022);}else{fs[_0x902f('0x7f')](_0x582221);}});});});}else{return _0x442ad4[_0x902f('0x15')](0xc8);}})['catch'](handleError(_0x442ad4,null));};
\ No newline at end of file