Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 7a84eaa..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb7b4=['offset','sort','pick','where','WhatsappInteractionId','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','includeAll','rows','addTags','setTags','spread','Tag','color','emit','removeTags','download','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','firstName','lastName','attachments','Attachment','Messages','createdAt','direction','read','Account','Owner','N.A.','toString','closed','closedAt','disposition','basename','existsSync','pipe','out','System','secret','renderFile','views','.pdf','Whatsapp','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','path','ejs','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','register','sendStatus','status','end','json','undefined','limit','count','set','Content-Range','update','then','destroy','stack','name','index','map','rawAttributes','fieldName','type','findAll','whatsapp','catch','show','params','keys','WhatsappInteraction','query','filters','intersection','model','attributes','fields','include','merge','options','find','create','body','addMessage','WhatsappMessage','ids','omit','getMessages','length','hasOwnProperty','nolimit'];(function(_0x2808e2,_0x2570fe){var _0x57088f=function(_0x488583){while(--_0x488583){_0x2808e2['push'](_0x2808e2['shift']());}};_0x57088f(++_0x2570fe);}(_0xb7b4,0x1ad));var _0x4b7b=function(_0x385f0e,_0xa10008){_0x385f0e=_0x385f0e-0x0;var _0x41d183=_0xb7b4[_0x385f0e];return _0x41d183;};'use strict';var rimraf=require(_0x4b7b('0x0'));var zipdir=require(_0x4b7b('0x1'));var moment=require(_0x4b7b('0x2'));var BPromise=require('bluebird');var util=require('util');var path=require(_0x4b7b('0x3'));var ejs=require(_0x4b7b('0x4'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x4b7b('0x5'));var interaction=require(_0x4b7b('0x6'));var qs=require(_0x4b7b('0x7'));var pdf=require(_0x4b7b('0x8'));var logger=require(_0x4b7b('0x9'))(_0x4b7b('0xa'));var config=require(_0x4b7b('0xb'));var db=require(_0x4b7b('0xc'))['db'];config[_0x4b7b('0xd')]=_[_0x4b7b('0xe')](config[_0x4b7b('0xd')],{'host':_0x4b7b('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4b7b('0xd')]));require('./whatsappInteraction.socket')[_0x4b7b('0x10')](socket);function respondWithStatusCode(_0x873075,_0x27414b){_0x27414b=_0x27414b||0xcc;return function(_0x5b457f){if(_0x5b457f){return _0x873075[_0x4b7b('0x11')](_0x27414b);}return _0x873075[_0x4b7b('0x12')](_0x27414b)[_0x4b7b('0x13')]();};}function respondWithResult(_0x31f453,_0x469122){_0x469122=_0x469122||0xc8;return function(_0x272280){if(_0x272280){return _0x31f453[_0x4b7b('0x12')](_0x469122)[_0x4b7b('0x14')](_0x272280);}};}function respondWithFilteredResult(_0x24a13b,_0x5e3510){return function(_0x477bb6){if(_0x477bb6){var _0x136e86=typeof _0x5e3510['offset']===_0x4b7b('0x15')&&typeof _0x5e3510[_0x4b7b('0x16')]===_0x4b7b('0x15');var _0x33a7f8=_0x477bb6[_0x4b7b('0x17')];var _0x35a13b=_0x136e86?0x0:_0x5e3510['offset'];var _0x411284=_0x136e86?_0x477bb6['count']:_0x5e3510['offset']+_0x5e3510[_0x4b7b('0x16')];var _0x216b12;if(_0x411284>=_0x33a7f8){_0x411284=_0x33a7f8;_0x216b12=0xc8;}else{_0x216b12=0xce;}_0x24a13b[_0x4b7b('0x12')](_0x216b12);return _0x24a13b[_0x4b7b('0x18')](_0x4b7b('0x19'),_0x35a13b+'-'+_0x411284+'/'+_0x33a7f8)[_0x4b7b('0x14')](_0x477bb6);}return null;};}function saveUpdates(_0x590f83){return function(_0x209215){if(_0x209215){return _0x209215[_0x4b7b('0x1a')](_0x590f83)[_0x4b7b('0x1b')](function(_0x54ef79){return _0x54ef79;});}return null;};}function removeEntity(_0x1a4365){return function(_0x5dcf02){if(_0x5dcf02){return _0x5dcf02[_0x4b7b('0x1c')]()[_0x4b7b('0x1b')](function(){_0x1a4365[_0x4b7b('0x12')](0xcc)[_0x4b7b('0x13')]();});}};}function handleEntityNotFound(_0x918d1b){return function(_0x4bf891){if(!_0x4bf891){_0x918d1b[_0x4b7b('0x11')](0x194);}return _0x4bf891;};}function handleError(_0x59c6bd,_0x4660ea){_0x4660ea=_0x4660ea||0x1f4;return function(_0x70f4fa){logger['error'](_0x70f4fa[_0x4b7b('0x1d')]);if(_0x70f4fa[_0x4b7b('0x1e')]){delete _0x70f4fa[_0x4b7b('0x1e')];}_0x59c6bd[_0x4b7b('0x12')](_0x4660ea)['send'](_0x70f4fa);};}exports[_0x4b7b('0x1f')]=function(_0xfa7452,_0x44925d){var _0x2cf184={};var _0x10ec6b=_[_0x4b7b('0x20')](db['WhatsappInteraction'][_0x4b7b('0x21')],function(_0xa683b4){return{'name':_0xa683b4[_0x4b7b('0x22')],'type':_0xa683b4[_0x4b7b('0x23')]['key']};});_0x2cf184=qs['getOptions'](_0x10ec6b,_0xfa7452);return interaction[_0x4b7b('0x24')](_0x4b7b('0x25'),_0xfa7452['query'],_0xfa7452['user'],_0x2cf184,_0x10ec6b)[_0x4b7b('0x1b')](respondWithFilteredResult(_0x44925d,_0x2cf184))[_0x4b7b('0x26')](handleError(_0x44925d,null));};exports[_0x4b7b('0x27')]=function(_0x4d0df2,_0x59c9e2){var _0x228e96={'raw':![],'where':{'id':_0x4d0df2[_0x4b7b('0x28')]['id']}},_0x1c61d0={};_0x1c61d0['model']=_[_0x4b7b('0x29')](db[_0x4b7b('0x2a')]['rawAttributes']);_0x1c61d0['query']=_[_0x4b7b('0x29')](_0x4d0df2[_0x4b7b('0x2b')]);_0x1c61d0[_0x4b7b('0x2c')]=_[_0x4b7b('0x2d')](_0x1c61d0[_0x4b7b('0x2e')],_0x1c61d0[_0x4b7b('0x2b')]);_0x228e96[_0x4b7b('0x2f')]=_[_0x4b7b('0x2d')](_0x1c61d0[_0x4b7b('0x2e')],qs[_0x4b7b('0x30')](_0x4d0df2[_0x4b7b('0x2b')][_0x4b7b('0x30')]));_0x228e96[_0x4b7b('0x2f')]=_0x228e96[_0x4b7b('0x2f')]['length']?_0x228e96['attributes']:_0x1c61d0[_0x4b7b('0x2e')];if(_0x4d0df2[_0x4b7b('0x2b')]['includeAll']){_0x228e96[_0x4b7b('0x31')]=[{'all':!![]}];}_0x228e96=_[_0x4b7b('0x32')]({},_0x228e96,_0x4d0df2[_0x4b7b('0x33')]);return db[_0x4b7b('0x2a')][_0x4b7b('0x34')](_0x228e96)[_0x4b7b('0x1b')](handleEntityNotFound(_0x59c9e2,null))[_0x4b7b('0x1b')](respondWithResult(_0x59c9e2,null))['catch'](handleError(_0x59c9e2,null));};exports['create']=function(_0x4d611e,_0x5253d0){return db['WhatsappInteraction'][_0x4b7b('0x35')](_0x4d611e[_0x4b7b('0x36')],{})[_0x4b7b('0x1b')](respondWithResult(_0x5253d0,0xc9))[_0x4b7b('0x26')](handleError(_0x5253d0,null));};exports[_0x4b7b('0x1a')]=function(_0x1c1c63,_0xa2c747){if(_0x1c1c63[_0x4b7b('0x36')]['id']){delete _0x1c1c63[_0x4b7b('0x36')]['id'];}return db[_0x4b7b('0x2a')][_0x4b7b('0x34')]({'where':{'id':_0x1c1c63[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0xa2c747,null))[_0x4b7b('0x1b')](saveUpdates(_0x1c1c63[_0x4b7b('0x36')],null))[_0x4b7b('0x1b')](respondWithResult(_0xa2c747,null))[_0x4b7b('0x26')](handleError(_0xa2c747,null));};exports[_0x4b7b('0x1c')]=function(_0x5edc33,_0x59f0df){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x5edc33[_0x4b7b('0x28')]['id']}})['then'](handleEntityNotFound(_0x59f0df,null))[_0x4b7b('0x1b')](removeEntity(_0x59f0df,null))[_0x4b7b('0x26')](handleError(_0x59f0df,null));};exports['describe']=function(_0x6a496e,_0x14d02d){return db['WhatsappInteraction']['describe']()[_0x4b7b('0x1b')](respondWithResult(_0x14d02d,null))[_0x4b7b('0x26')](handleError(_0x14d02d,null));};exports[_0x4b7b('0x37')]=function(_0x5d9516,_0x509ff8){return db[_0x4b7b('0x38')][_0x4b7b('0x34')]({'where':{'id':_0x5d9516[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x509ff8,null))['then'](function(_0x18bb41){if(_0x18bb41){return _0x18bb41[_0x4b7b('0x37')](_0x5d9516[_0x4b7b('0x36')][_0x4b7b('0x39')],_[_0x4b7b('0x3a')](_0x5d9516[_0x4b7b('0x36')],[_0x4b7b('0x39'),'id'])||{});}})[_0x4b7b('0x1b')](respondWithResult(_0x509ff8,null))['catch'](handleError(_0x509ff8,null));};exports[_0x4b7b('0x3b')]=function(_0x2a60b0,_0x112cd1){var _0x3d4716={'raw':![],'where':{}};var _0x50dd4f={};var _0x4bd6a3={'count':0x0,'rows':[]};return db[_0x4b7b('0x2a')]['findOne']({'where':{'id':_0x2a60b0[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x112cd1,null))[_0x4b7b('0x1b')](function(_0x387ce2){if(_0x387ce2){_0x50dd4f['model']=_[_0x4b7b('0x29')](db[_0x4b7b('0x38')]['rawAttributes']);_0x50dd4f[_0x4b7b('0x2b')]=_[_0x4b7b('0x29')](_0x2a60b0['query']);_0x50dd4f[_0x4b7b('0x2c')]=_[_0x4b7b('0x2d')](_0x50dd4f[_0x4b7b('0x2e')],_0x50dd4f['query']);_0x3d4716[_0x4b7b('0x2f')]=_[_0x4b7b('0x2d')](_0x50dd4f['model'],qs['fields'](_0x2a60b0['query'][_0x4b7b('0x30')]));_0x3d4716[_0x4b7b('0x2f')]=_0x3d4716[_0x4b7b('0x2f')][_0x4b7b('0x3c')]?_0x3d4716[_0x4b7b('0x2f')]:_0x50dd4f['model'];if(!_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x3d')](_0x4b7b('0x3e'))){_0x3d4716[_0x4b7b('0x16')]=qs['limit'](_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x16')]);_0x3d4716[_0x4b7b('0x3f')]=qs[_0x4b7b('0x3f')](_0x2a60b0['query'][_0x4b7b('0x3f')]);}_0x3d4716['order']=qs['sort'](_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x40')]);_0x3d4716['where']=qs[_0x4b7b('0x2c')](_[_0x4b7b('0x41')](_0x2a60b0[_0x4b7b('0x2b')],_0x50dd4f[_0x4b7b('0x2c')]));_0x3d4716[_0x4b7b('0x42')][_0x4b7b('0x43')]=_0x387ce2['id'];if(_0x2a60b0[_0x4b7b('0x2b')]['filter']){_0x3d4716[_0x4b7b('0x42')]=_[_0x4b7b('0x32')](_0x3d4716[_0x4b7b('0x42')],{'$or':_[_0x4b7b('0x20')](_0x3d4716[_0x4b7b('0x2f')],function(_0x4dd54a){var _0x83e4e4={};_0x83e4e4[_0x4dd54a]={'$like':'%'+_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x44')]+'%'};return _0x83e4e4;})});}if(_0x2a60b0['query'][_0x4b7b('0x45')]){var _0xf62d79=_0x2a60b0[_0x4b7b('0x2b')]['$gte'][_0x4b7b('0x46')](',');var _0xdd0c0f={};_0xdd0c0f[_0xf62d79[0x0]]={'$gte':moment(_0xf62d79[0x1])[_0x4b7b('0x47')](_0x4b7b('0x48'))};_0x3d4716[_0x4b7b('0x42')]=_[_0x4b7b('0x32')](_0x3d4716['where'],_0xdd0c0f);}_0x3d4716=_['merge']({},_0x3d4716,_0x2a60b0[_0x4b7b('0x33')]);return db['WhatsappMessage'][_0x4b7b('0x17')]({'where':_0x3d4716[_0x4b7b('0x42')]})[_0x4b7b('0x1b')](function(_0x25caf1){_0x4bd6a3[_0x4b7b('0x17')]=_0x25caf1;if(_0x2a60b0[_0x4b7b('0x2b')][_0x4b7b('0x49')]){_0x3d4716[_0x4b7b('0x31')]=[{'all':!![]}];}return db[_0x4b7b('0x38')][_0x4b7b('0x24')](_0x3d4716);})[_0x4b7b('0x1b')](function(_0x10002e){_0x4bd6a3[_0x4b7b('0x4a')]=_0x10002e;return _0x4bd6a3;});}})[_0x4b7b('0x1b')](respondWithFilteredResult(_0x112cd1,_0x3d4716))[_0x4b7b('0x26')](handleError(_0x112cd1,null));};exports[_0x4b7b('0x4b')]=function(_0x53888d,_0x42c481){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x53888d[_0x4b7b('0x28')]['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x42c481,null))[_0x4b7b('0x1b')](function(_0x51e7da){if(_0x51e7da){return _0x51e7da[_0x4b7b('0x4c')](_0x53888d['body']['ids'],_['omit'](_0x53888d[_0x4b7b('0x36')],[_0x4b7b('0x39'),'id'])||{})[_0x4b7b('0x4d')](function(){return db[_0x4b7b('0x4e')]['findAll']({'attributes':['id','name',_0x4b7b('0x4f')],'where':{'id':_0x53888d[_0x4b7b('0x36')][_0x4b7b('0x39')]}});})[_0x4b7b('0x1b')](function(_0x43fd8b){socket[_0x4b7b('0x50')]('whatsappInteractionTags:save',{'id':Number(_0x53888d[_0x4b7b('0x28')]['id']),'tags':_0x43fd8b||[]});return{'id':Number(_0x53888d[_0x4b7b('0x28')]['id']),'tags':_0x43fd8b||[]};});}})[_0x4b7b('0x1b')](respondWithResult(_0x42c481,null))[_0x4b7b('0x26')](handleError(_0x42c481,null));};exports[_0x4b7b('0x51')]=function(_0x5bd219,_0x339543){return db['WhatsappInteraction'][_0x4b7b('0x34')]({'where':{'id':_0x5bd219['params']['id']}})[_0x4b7b('0x1b')](handleEntityNotFound(_0x339543,null))[_0x4b7b('0x1b')](function(_0x2a53bf){if(_0x2a53bf){return _0x2a53bf[_0x4b7b('0x51')](_0x5bd219[_0x4b7b('0x2b')][_0x4b7b('0x39')]);}})['then'](respondWithStatusCode(_0x339543,null))[_0x4b7b('0x26')](handleError(_0x339543,null));};exports[_0x4b7b('0x52')]=function(_0x4b2e11,_0x1db915){var _0x24dbe2=moment()['unix']()['toString']();var _0x44a893=path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x56'),_0x4b7b('0x57'));var _0x43a93e=path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x56'),'attachments');var _0x58a96c=path[_0x4b7b('0x53')](_0x44a893,_0x24dbe2);var _0x515f6e=util[_0x4b7b('0x47')](_0x4b7b('0x58'),_0x4b2e11['params']['id'],_0x24dbe2);var _0x35148a=path[_0x4b7b('0x53')](_0x44a893,_0x515f6e);var _0x2a1270=[];_0x2a1270[_0x4b7b('0x59')]({'model':db[_0x4b7b('0x5a')],'as':_0x4b7b('0x5a'),'attributes':['id',_0x4b7b('0x5b')],'raw':!![]});_0x2a1270['push']({'model':db[_0x4b7b('0x5c')],'as':_0x4b7b('0x5d'),'attributes':['id',_0x4b7b('0x5e'),_0x4b7b('0x5f')],'raw':!![]});if(_0x4b2e11[_0x4b7b('0x2b')][_0x4b7b('0x60')]){_0x2a1270['push']({'model':db['Attachment'],'as':_0x4b7b('0x61'),'raw':!![]});}var _0x40bb8d=[{'model':db[_0x4b7b('0x38')],'as':_0x4b7b('0x62'),'attributes':['id',_0x4b7b('0x36'),_0x4b7b('0x63'),_0x4b7b('0x64'),'secret',_0x4b7b('0x65')],'include':_0x2a1270}];_0x40bb8d[_0x4b7b('0x59')]({'model':db['WhatsappAccount'],'as':_0x4b7b('0x66'),'attributes':['id',_0x4b7b('0x1e')]});_0x40bb8d['push']({'model':db['User'],'as':_0x4b7b('0x67'),'attributes':['id','fullname']});return db[_0x4b7b('0x2a')][_0x4b7b('0x34')]({'where':{'id':_0x4b2e11[_0x4b7b('0x28')]['id']},'include':_0x40bb8d})[_0x4b7b('0x1b')](handleEntityNotFound(_0x1db915,null))['then'](function(_0x258ed5){if(_0x258ed5){var _0x157097=_0x258ed5['get']({'plain':!![]});fs['mkdirSync'](_0x58a96c);var _0x532807={'channel':'Whatsapp','account':_0x157097['Account'][_0x4b7b('0x1e')],'agent':_0x157097['Owner']?_0x157097[_0x4b7b('0x67')][_0x4b7b('0x5b')]:_0x4b7b('0x68'),'createdAt':moment(_0x157097['createdAt'])[_0x4b7b('0x47')]('YYYY-MM-DD\x20HH:mm:ss')[_0x4b7b('0x69')](),'closedAt':_0x157097[_0x4b7b('0x6a')]?moment(_0x157097[_0x4b7b('0x6b')])[_0x4b7b('0x47')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x157097[_0x4b7b('0x6c')],'messages':_(_0x157097[_0x4b7b('0x62')])[_0x4b7b('0x44')]({'secret':![]})['map'](function(_0x169058){if(_0x169058['Attachment']){var _0x36ace4=path['join'](_0x43a93e,_0x169058[_0x4b7b('0x61')][_0x4b7b('0x6d')]);if(fs[_0x4b7b('0x6e')](_0x36ace4)){fs['createReadStream'](_0x36ace4)[_0x4b7b('0x6f')](fs['createWriteStream'](path['join'](_0x58a96c,_0x169058[_0x4b7b('0x61')][_0x4b7b('0x6d')])));}}return{'date':moment(_0x169058[_0x4b7b('0x63')])['format']('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'sender':_0x169058[_0x4b7b('0x64')]===_0x4b7b('0x70')?_0x169058[_0x4b7b('0x5a')]?_0x169058['User']['fullname']:_0x4b7b('0x71'):_0x169058[_0x4b7b('0x5d')][_0x4b7b('0x5e')]+(_0x169058[_0x4b7b('0x5d')][_0x4b7b('0x5f')]?'\x20'+_0x169058['Contact'][_0x4b7b('0x5f')]:''),'body':_0x169058[_0x4b7b('0x61')]?_0x169058[_0x4b7b('0x61')]['basename']:_0x169058[_0x4b7b('0x36')],'direction':_0x169058[_0x4b7b('0x64')]===_0x4b7b('0x70')?'A':'C','secret':_0x169058[_0x4b7b('0x72')],'read':_0x169058[_0x4b7b('0x65')],'attachment':_0x169058[_0x4b7b('0x61')]};})['value']()};return ejs[_0x4b7b('0x73')](path[_0x4b7b('0x53')](config[_0x4b7b('0x54')],_0x4b7b('0x55'),_0x4b7b('0x74'),'downloadInteraction.ejs'),{'interaction':_0x532807})[_0x4b7b('0x1b')](function(_0x607106){var _0x508946=path[_0x4b7b('0x53')](_0x58a96c,'transcript-'+_0x157097['id']+'-'+_0x24dbe2+_0x4b7b('0x75'));var _0x382fdb={'path':_0x508946,'channel':_0x4b7b('0x76'),'interactionId':_0x157097['id']};return pdf[_0x4b7b('0x77')](_0x607106,_0x382fdb);})[_0x4b7b('0x1b')](function(){return new BPromise(function(_0xa2cc74,_0x43ffc6){zipdir(_0x58a96c,{'saveTo':_0x35148a},function(_0x10e810,_0x335583){if(_0x10e810)return _0x43ffc6(_0x10e810);return _0xa2cc74(_0x335583);});})[_0x4b7b('0x1b')](function(){return new BPromise(function(_0x26988e,_0x50e139){rimraf(_0x58a96c,function(_0x21cf63){if(_0x21cf63)_0x50e139(_0x21cf63);return _0x26988e();});});})[_0x4b7b('0x1b')](function(){return _0x1db915[_0x4b7b('0x52')](_0x35148a,_0x515f6e,function(_0x282ec9){if(_0x282ec9){console[_0x4b7b('0x78')](_0x4b7b('0x79'),_0x282ec9);}else{fs[_0x4b7b('0x7a')](_0x35148a);}});});});}else{return _0x1db915['sendStatus'](0xc8);}})[_0x4b7b('0x26')](handleError(_0x1db915,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