Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.controller.js
index 1e5ae8f..36629f4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4cbd=['tmp','root','attachments','format','transcript-%d-%s.zip','push','User','fullname','Contact','firstName','lastName','Attachment','Messages','createdAt','direction','secret','read','WhatsappAccount','Account','Owner','mkdirSync','Whatsapp','N.A.','closed','closedAt','disposition','basename','existsSync','createReadStream','pipe','out','value','renderFile','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','rimraf','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','sendStatus','end','status','json','offset','undefined','count','limit','set','Content-Range','update','then','destroy','error','stack','name','send','index','map','WhatsappInteraction','rawAttributes','fieldName','key','findAll','whatsapp','query','user','show','params','model','keys','filters','attributes','intersection','fields','length','includeAll','include','options','catch','create','body','find','describe','addMessage','WhatsappMessage','omit','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','pick','WhatsappInteractionId','filter','merge','$gte','split','YYYY-MM-DD\x20HH:mm:ss','rows','addTags','ids','spread','emit','whatsappInteractionTags:save','removeTags','download','unix','toString','join','server','files'];(function(_0x159b72,_0x183756){var _0x4fa7b7=function(_0x43e36b){while(--_0x43e36b){_0x159b72['push'](_0x159b72['shift']());}};_0x4fa7b7(++_0x183756);}(_0x4cbd,0xa9));var _0xd4cb=function(_0x45ef14,_0x834d23){_0x45ef14=_0x45ef14-0x0;var _0x161624=_0x4cbd[_0x45ef14];return _0x161624;};'use strict';var rimraf=require(_0xd4cb('0x0'));var zipdir=require(_0xd4cb('0x1'));var moment=require(_0xd4cb('0x2'));var BPromise=require(_0xd4cb('0x3'));var util=require(_0xd4cb('0x4'));var path=require(_0xd4cb('0x5'));var ejs=require(_0xd4cb('0x6'));var fs=require('fs');var _=require(_0xd4cb('0x7'));var Redis=require(_0xd4cb('0x8'));var interaction=require(_0xd4cb('0x9'));var qs=require('../../components/parsers/qs');var pdf=require(_0xd4cb('0xa'));var logger=require(_0xd4cb('0xb'))(_0xd4cb('0xc'));var config=require(_0xd4cb('0xd'));var db=require(_0xd4cb('0xe'))['db'];config[_0xd4cb('0xf')]=_[_0xd4cb('0x10')](config[_0xd4cb('0xf')],{'host':_0xd4cb('0x11'),'port':0x18eb});var socket=require(_0xd4cb('0x12'))(new Redis(config[_0xd4cb('0xf')]));require(_0xd4cb('0x13'))[_0xd4cb('0x14')](socket);function respondWithStatusCode(_0x5cdbf9,_0x49c764){_0x49c764=_0x49c764||0xcc;return function(_0x25237b){if(_0x25237b){return _0x5cdbf9[_0xd4cb('0x15')](_0x49c764);}return _0x5cdbf9['status'](_0x49c764)[_0xd4cb('0x16')]();};}function respondWithResult(_0x5f1909,_0x1cd17b){_0x1cd17b=_0x1cd17b||0xc8;return function(_0x189655){if(_0x189655){return _0x5f1909[_0xd4cb('0x17')](_0x1cd17b)[_0xd4cb('0x18')](_0x189655);}};}function respondWithFilteredResult(_0x34bc16,_0x243821){return function(_0x37ba00){if(_0x37ba00){var _0x2e6d3c=typeof _0x243821[_0xd4cb('0x19')]==='undefined'&&typeof _0x243821['limit']===_0xd4cb('0x1a');var _0x5c68c1=_0x37ba00[_0xd4cb('0x1b')];var _0x142a99=_0x2e6d3c?0x0:_0x243821[_0xd4cb('0x19')];var _0x580233=_0x2e6d3c?_0x37ba00[_0xd4cb('0x1b')]:_0x243821[_0xd4cb('0x19')]+_0x243821[_0xd4cb('0x1c')];var _0x5dcd89;if(_0x580233>=_0x5c68c1){_0x580233=_0x5c68c1;_0x5dcd89=0xc8;}else{_0x5dcd89=0xce;}_0x34bc16['status'](_0x5dcd89);return _0x34bc16[_0xd4cb('0x1d')](_0xd4cb('0x1e'),_0x142a99+'-'+_0x580233+'/'+_0x5c68c1)[_0xd4cb('0x18')](_0x37ba00);}return null;};}function saveUpdates(_0x3c2d65){return function(_0x2eb10d){if(_0x2eb10d){return _0x2eb10d[_0xd4cb('0x1f')](_0x3c2d65)[_0xd4cb('0x20')](function(_0x39f5a4){return _0x39f5a4;});}return null;};}function removeEntity(_0x37de2a){return function(_0x4f123a){if(_0x4f123a){return _0x4f123a[_0xd4cb('0x21')]()[_0xd4cb('0x20')](function(){_0x37de2a[_0xd4cb('0x17')](0xcc)[_0xd4cb('0x16')]();});}};}function handleEntityNotFound(_0x2a1570){return function(_0x15fd65){if(!_0x15fd65){_0x2a1570[_0xd4cb('0x15')](0x194);}return _0x15fd65;};}function handleError(_0x4757bf,_0x116dae){_0x116dae=_0x116dae||0x1f4;return function(_0x4b5395){logger[_0xd4cb('0x22')](_0x4b5395[_0xd4cb('0x23')]);if(_0x4b5395[_0xd4cb('0x24')]){delete _0x4b5395[_0xd4cb('0x24')];}_0x4757bf[_0xd4cb('0x17')](_0x116dae)[_0xd4cb('0x25')](_0x4b5395);};}exports[_0xd4cb('0x26')]=function(_0x381c8f,_0x157e48){var _0x16eb10={};var _0x32234a=_[_0xd4cb('0x27')](db[_0xd4cb('0x28')][_0xd4cb('0x29')],function(_0x49a014){return{'name':_0x49a014[_0xd4cb('0x2a')],'type':_0x49a014['type'][_0xd4cb('0x2b')]};});_0x16eb10=qs['getOptions'](_0x32234a,_0x381c8f);return interaction[_0xd4cb('0x2c')](_0xd4cb('0x2d'),_0x381c8f[_0xd4cb('0x2e')],_0x381c8f[_0xd4cb('0x2f')],_0x16eb10,_0x32234a)[_0xd4cb('0x20')](respondWithFilteredResult(_0x157e48,_0x16eb10))['catch'](handleError(_0x157e48,null));};exports[_0xd4cb('0x30')]=function(_0x2fca1a,_0x332849){var _0x5b42cb={'raw':![],'where':{'id':_0x2fca1a[_0xd4cb('0x31')]['id']}},_0x5415d2={};_0x5415d2[_0xd4cb('0x32')]=_[_0xd4cb('0x33')](db['WhatsappInteraction'][_0xd4cb('0x29')]);_0x5415d2['query']=_[_0xd4cb('0x33')](_0x2fca1a['query']);_0x5415d2[_0xd4cb('0x34')]=_['intersection'](_0x5415d2[_0xd4cb('0x32')],_0x5415d2[_0xd4cb('0x2e')]);_0x5b42cb[_0xd4cb('0x35')]=_[_0xd4cb('0x36')](_0x5415d2['model'],qs[_0xd4cb('0x37')](_0x2fca1a[_0xd4cb('0x2e')][_0xd4cb('0x37')]));_0x5b42cb[_0xd4cb('0x35')]=_0x5b42cb[_0xd4cb('0x35')][_0xd4cb('0x38')]?_0x5b42cb[_0xd4cb('0x35')]:_0x5415d2[_0xd4cb('0x32')];if(_0x2fca1a['query'][_0xd4cb('0x39')]){_0x5b42cb[_0xd4cb('0x3a')]=[{'all':!![]}];}_0x5b42cb=_['merge']({},_0x5b42cb,_0x2fca1a[_0xd4cb('0x3b')]);return db['WhatsappInteraction']['find'](_0x5b42cb)[_0xd4cb('0x20')](handleEntityNotFound(_0x332849,null))[_0xd4cb('0x20')](respondWithResult(_0x332849,null))[_0xd4cb('0x3c')](handleError(_0x332849,null));};exports[_0xd4cb('0x3d')]=function(_0x5310d9,_0x22ccaa){return db[_0xd4cb('0x28')]['create'](_0x5310d9[_0xd4cb('0x3e')],{})[_0xd4cb('0x20')](respondWithResult(_0x22ccaa,0xc9))[_0xd4cb('0x3c')](handleError(_0x22ccaa,null));};exports[_0xd4cb('0x1f')]=function(_0x22e06e,_0x192f98){if(_0x22e06e[_0xd4cb('0x3e')]['id']){delete _0x22e06e['body']['id'];}return db['WhatsappInteraction'][_0xd4cb('0x3f')]({'where':{'id':_0x22e06e[_0xd4cb('0x31')]['id']}})[_0xd4cb('0x20')](handleEntityNotFound(_0x192f98,null))[_0xd4cb('0x20')](saveUpdates(_0x22e06e[_0xd4cb('0x3e')],null))[_0xd4cb('0x20')](respondWithResult(_0x192f98,null))[_0xd4cb('0x3c')](handleError(_0x192f98,null));};exports[_0xd4cb('0x21')]=function(_0x65ad35,_0x12fb86){return db[_0xd4cb('0x28')][_0xd4cb('0x3f')]({'where':{'id':_0x65ad35[_0xd4cb('0x31')]['id']}})[_0xd4cb('0x20')](handleEntityNotFound(_0x12fb86,null))['then'](removeEntity(_0x12fb86,null))[_0xd4cb('0x3c')](handleError(_0x12fb86,null));};exports[_0xd4cb('0x40')]=function(_0x20af6a,_0x13141b){return db[_0xd4cb('0x28')][_0xd4cb('0x40')]()[_0xd4cb('0x20')](respondWithResult(_0x13141b,null))[_0xd4cb('0x3c')](handleError(_0x13141b,null));};exports[_0xd4cb('0x41')]=function(_0x58a106,_0x57e495){return db[_0xd4cb('0x42')][_0xd4cb('0x3f')]({'where':{'id':_0x58a106[_0xd4cb('0x31')]['id']}})['then'](handleEntityNotFound(_0x57e495,null))[_0xd4cb('0x20')](function(_0x2caff5){if(_0x2caff5){return _0x2caff5[_0xd4cb('0x41')](_0x58a106['body']['ids'],_[_0xd4cb('0x43')](_0x58a106[_0xd4cb('0x3e')],['ids','id'])||{});}})[_0xd4cb('0x20')](respondWithResult(_0x57e495,null))[_0xd4cb('0x3c')](handleError(_0x57e495,null));};exports[_0xd4cb('0x44')]=function(_0x3f3dbd,_0x53ca57){var _0x5c654={'raw':![],'where':{}};var _0x4ff1e0={};var _0x3db277={'count':0x0,'rows':[]};return db[_0xd4cb('0x28')][_0xd4cb('0x45')]({'where':{'id':_0x3f3dbd[_0xd4cb('0x31')]['id']}})[_0xd4cb('0x20')](handleEntityNotFound(_0x53ca57,null))['then'](function(_0x3a9212){if(_0x3a9212){_0x4ff1e0[_0xd4cb('0x32')]=_['keys'](db[_0xd4cb('0x42')][_0xd4cb('0x29')]);_0x4ff1e0[_0xd4cb('0x2e')]=_[_0xd4cb('0x33')](_0x3f3dbd[_0xd4cb('0x2e')]);_0x4ff1e0[_0xd4cb('0x34')]=_['intersection'](_0x4ff1e0[_0xd4cb('0x32')],_0x4ff1e0[_0xd4cb('0x2e')]);_0x5c654[_0xd4cb('0x35')]=_['intersection'](_0x4ff1e0[_0xd4cb('0x32')],qs[_0xd4cb('0x37')](_0x3f3dbd[_0xd4cb('0x2e')]['fields']));_0x5c654[_0xd4cb('0x35')]=_0x5c654[_0xd4cb('0x35')][_0xd4cb('0x38')]?_0x5c654[_0xd4cb('0x35')]:_0x4ff1e0[_0xd4cb('0x32')];if(!_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x46')](_0xd4cb('0x47'))){_0x5c654[_0xd4cb('0x1c')]=qs[_0xd4cb('0x1c')](_0x3f3dbd['query'][_0xd4cb('0x1c')]);_0x5c654[_0xd4cb('0x19')]=qs['offset'](_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x19')]);}_0x5c654[_0xd4cb('0x48')]=qs[_0xd4cb('0x49')](_0x3f3dbd['query'][_0xd4cb('0x49')]);_0x5c654[_0xd4cb('0x4a')]=qs[_0xd4cb('0x34')](_[_0xd4cb('0x4b')](_0x3f3dbd[_0xd4cb('0x2e')],_0x4ff1e0['filters']));_0x5c654[_0xd4cb('0x4a')][_0xd4cb('0x4c')]=_0x3a9212['id'];if(_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x4d')]){_0x5c654[_0xd4cb('0x4a')]=_[_0xd4cb('0x4e')](_0x5c654['where'],{'$or':_['map'](_0x5c654[_0xd4cb('0x35')],function(_0x1e198c){var _0x209d47={};_0x209d47[_0x1e198c]={'$like':'%'+_0x3f3dbd['query'][_0xd4cb('0x4d')]+'%'};return _0x209d47;})});}if(_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x4f')]){var _0x3a421f=_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x4f')][_0xd4cb('0x50')](',');var _0x4df481={};_0x4df481[_0x3a421f[0x0]]={'$gte':moment(_0x3a421f[0x1])['format'](_0xd4cb('0x51'))};_0x5c654[_0xd4cb('0x4a')]=_[_0xd4cb('0x4e')](_0x5c654[_0xd4cb('0x4a')],_0x4df481);}_0x5c654=_['merge']({},_0x5c654,_0x3f3dbd[_0xd4cb('0x3b')]);return db[_0xd4cb('0x42')][_0xd4cb('0x1b')]({'where':_0x5c654[_0xd4cb('0x4a')]})[_0xd4cb('0x20')](function(_0x4b09ce){_0x3db277[_0xd4cb('0x1b')]=_0x4b09ce;if(_0x3f3dbd[_0xd4cb('0x2e')][_0xd4cb('0x39')]){_0x5c654[_0xd4cb('0x3a')]=[{'all':!![]}];}return db[_0xd4cb('0x42')][_0xd4cb('0x2c')](_0x5c654);})['then'](function(_0x415559){_0x3db277[_0xd4cb('0x52')]=_0x415559;return _0x3db277;});}})[_0xd4cb('0x20')](respondWithFilteredResult(_0x53ca57,_0x5c654))[_0xd4cb('0x3c')](handleError(_0x53ca57,null));};exports[_0xd4cb('0x53')]=function(_0x262f71,_0x36be80){return db[_0xd4cb('0x28')][_0xd4cb('0x3f')]({'where':{'id':_0x262f71[_0xd4cb('0x31')]['id']}})[_0xd4cb('0x20')](handleEntityNotFound(_0x36be80,null))['then'](function(_0x3a0d36){if(_0x3a0d36){return _0x3a0d36['setTags'](_0x262f71[_0xd4cb('0x3e')][_0xd4cb('0x54')],_[_0xd4cb('0x43')](_0x262f71[_0xd4cb('0x3e')],[_0xd4cb('0x54'),'id'])||{})[_0xd4cb('0x55')](function(){return db['Tag'][_0xd4cb('0x2c')]({'attributes':['id',_0xd4cb('0x24'),'color'],'where':{'id':_0x262f71['body'][_0xd4cb('0x54')]}});})[_0xd4cb('0x20')](function(_0x13ce62){socket[_0xd4cb('0x56')](_0xd4cb('0x57'),{'id':Number(_0x262f71['params']['id']),'tags':_0x13ce62||[]});return{'id':Number(_0x262f71[_0xd4cb('0x31')]['id']),'tags':_0x13ce62||[]};});}})['then'](respondWithResult(_0x36be80,null))[_0xd4cb('0x3c')](handleError(_0x36be80,null));};exports['removeTags']=function(_0x12197a,_0x3ef46e){return db['WhatsappInteraction'][_0xd4cb('0x3f')]({'where':{'id':_0x12197a[_0xd4cb('0x31')]['id']}})[_0xd4cb('0x20')](handleEntityNotFound(_0x3ef46e,null))[_0xd4cb('0x20')](function(_0x197163){if(_0x197163){return _0x197163[_0xd4cb('0x58')](_0x12197a['query'][_0xd4cb('0x54')]);}})[_0xd4cb('0x20')](respondWithStatusCode(_0x3ef46e,null))[_0xd4cb('0x3c')](handleError(_0x3ef46e,null));};exports[_0xd4cb('0x59')]=function(_0x11a801,_0x262b66){var _0x26a234=moment()[_0xd4cb('0x5a')]()[_0xd4cb('0x5b')]();var _0x38b14e=path[_0xd4cb('0x5c')](config['root'],_0xd4cb('0x5d'),_0xd4cb('0x5e'),_0xd4cb('0x5f'));var _0x561426=path['join'](config[_0xd4cb('0x60')],_0xd4cb('0x5d'),'files',_0xd4cb('0x61'));var _0x484218=path[_0xd4cb('0x5c')](_0x38b14e,_0x26a234);var _0x29663c=util[_0xd4cb('0x62')](_0xd4cb('0x63'),_0x11a801['params']['id'],_0x26a234);var _0x4ddd41=path['join'](_0x38b14e,_0x29663c);var _0x1deff7=[];_0x1deff7[_0xd4cb('0x64')]({'model':db[_0xd4cb('0x65')],'as':_0xd4cb('0x65'),'attributes':['id',_0xd4cb('0x66')],'raw':!![]});_0x1deff7[_0xd4cb('0x64')]({'model':db['CmContact'],'as':_0xd4cb('0x67'),'attributes':['id',_0xd4cb('0x68'),_0xd4cb('0x69')],'raw':!![]});if(_0x11a801[_0xd4cb('0x2e')][_0xd4cb('0x61')]){_0x1deff7[_0xd4cb('0x64')]({'model':db[_0xd4cb('0x6a')],'as':_0xd4cb('0x6a'),'raw':!![]});}var _0x2f08b1=[{'model':db['WhatsappMessage'],'as':_0xd4cb('0x6b'),'attributes':['id','body',_0xd4cb('0x6c'),_0xd4cb('0x6d'),_0xd4cb('0x6e'),_0xd4cb('0x6f')],'include':_0x1deff7}];_0x2f08b1[_0xd4cb('0x64')]({'model':db[_0xd4cb('0x70')],'as':_0xd4cb('0x71'),'attributes':['id','name']});_0x2f08b1[_0xd4cb('0x64')]({'model':db['User'],'as':_0xd4cb('0x72'),'attributes':['id',_0xd4cb('0x66')]});return db[_0xd4cb('0x28')][_0xd4cb('0x3f')]({'where':{'id':_0x11a801[_0xd4cb('0x31')]['id']},'include':_0x2f08b1})[_0xd4cb('0x20')](handleEntityNotFound(_0x262b66,null))[_0xd4cb('0x20')](function(_0xa72b42){if(_0xa72b42){var _0xf39e05=_0xa72b42['get']({'plain':!![]});fs[_0xd4cb('0x73')](_0x484218);var _0x1dc212={'channel':_0xd4cb('0x74'),'account':_0xf39e05[_0xd4cb('0x71')][_0xd4cb('0x24')],'agent':_0xf39e05[_0xd4cb('0x72')]?_0xf39e05[_0xd4cb('0x72')]['fullname']:_0xd4cb('0x75'),'createdAt':moment(_0xf39e05['createdAt'])[_0xd4cb('0x62')]('YYYY-MM-DD\x20HH:mm:ss')[_0xd4cb('0x5b')](),'closedAt':_0xf39e05[_0xd4cb('0x76')]?moment(_0xf39e05[_0xd4cb('0x77')])[_0xd4cb('0x62')]('YYYY-MM-DD\x20HH:mm:ss')[_0xd4cb('0x5b')]():'','disposition':_0xf39e05[_0xd4cb('0x78')],'messages':_(_0xf39e05[_0xd4cb('0x6b')])['filter']({'secret':![]})[_0xd4cb('0x27')](function(_0x4a8106){if(_0x4a8106[_0xd4cb('0x6a')]){var _0x53cbe1=path[_0xd4cb('0x5c')](_0x561426,_0x4a8106[_0xd4cb('0x6a')][_0xd4cb('0x79')]);if(fs[_0xd4cb('0x7a')](_0x53cbe1)){fs[_0xd4cb('0x7b')](_0x53cbe1)[_0xd4cb('0x7c')](fs['createWriteStream'](path[_0xd4cb('0x5c')](_0x484218,_0x4a8106[_0xd4cb('0x6a')][_0xd4cb('0x79')])));}}return{'date':moment(_0x4a8106[_0xd4cb('0x6c')])[_0xd4cb('0x62')](_0xd4cb('0x51'))[_0xd4cb('0x5b')](),'sender':_0x4a8106[_0xd4cb('0x6d')]===_0xd4cb('0x7d')?_0x4a8106[_0xd4cb('0x65')]?_0x4a8106['User'][_0xd4cb('0x66')]:'System':_0x4a8106[_0xd4cb('0x67')][_0xd4cb('0x68')]+(_0x4a8106[_0xd4cb('0x67')]['lastName']?'\x20'+_0x4a8106[_0xd4cb('0x67')]['lastName']:''),'body':_0x4a8106[_0xd4cb('0x6a')]?_0x4a8106[_0xd4cb('0x6a')][_0xd4cb('0x79')]:_0x4a8106[_0xd4cb('0x3e')],'direction':_0x4a8106[_0xd4cb('0x6d')]==='out'?'A':'C','secret':_0x4a8106[_0xd4cb('0x6e')],'read':_0x4a8106[_0xd4cb('0x6f')],'attachment':_0x4a8106[_0xd4cb('0x6a')]};})[_0xd4cb('0x7e')]()};return ejs[_0xd4cb('0x7f')](path['join'](config['root'],_0xd4cb('0x5d'),_0xd4cb('0x80'),_0xd4cb('0x81')),{'interaction':_0x1dc212})[_0xd4cb('0x20')](function(_0x21c58f){var _0xadb75c=path[_0xd4cb('0x5c')](_0x484218,'transcript-'+_0xf39e05['id']+'-'+_0x26a234+_0xd4cb('0x82'));var _0x1040c9={'path':_0xadb75c,'channel':_0xd4cb('0x74'),'interactionId':_0xf39e05['id']};return pdf[_0xd4cb('0x83')](_0x21c58f,_0x1040c9);})[_0xd4cb('0x20')](function(){return new BPromise(function(_0x2bc2ea,_0x103280){zipdir(_0x484218,{'saveTo':_0x4ddd41},function(_0x2d2580,_0x2387f1){if(_0x2d2580)return _0x103280(_0x2d2580);return _0x2bc2ea(_0x2387f1);});})[_0xd4cb('0x20')](function(){return new BPromise(function(_0x4a0f0b,_0x8d24e7){rimraf(_0x484218,function(_0x358176){if(_0x358176)_0x8d24e7(_0x358176);return _0x4a0f0b();});});})['then'](function(){return _0x262b66[_0xd4cb('0x59')](_0x4ddd41,_0x29663c,function(_0x16ad18){if(_0x16ad18){console['log']('err',_0x16ad18);}else{fs['unlinkSync'](_0x4ddd41);}});});});}else{return _0x262b66[_0xd4cb('0x15')](0xc8);}})[_0xd4cb('0x3c')](handleError(_0x262b66,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