Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 7ec3fcd..bdf6b89 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x24dd=['direction','read','Account','Owner','get','mkdirSync','Sms','N.A.','closed','closedAt','disposition','Messages','out','System','Contact','secret','value','renderFile','downloadInteraction.ejs','.pdf','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','util','path','lodash','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','./smsInteraction.socket','register','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','then','end','error','stack','name','send','index','map','SmsInteraction','type','sms','catch','show','keys','rawAttributes','query','filters','intersection','attributes','fields','length','model','includeAll','options','find','create','body','params','describe','addMessage','SmsMessage','ids','omit','findOne','hasOwnProperty','nolimit','sort','where','SmsInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','addTags','setTags','spread','Tag','color','emit','removeTags','download','toString','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','firstName','lastName','createdAt'];(function(_0x4b2680,_0x1c92ad){var _0x40f43f=function(_0x2d7cb2){while(--_0x2d7cb2){_0x4b2680['push'](_0x4b2680['shift']());}};_0x40f43f(++_0x1c92ad);}(_0x24dd,0x109));var _0xd24d=function(_0x247fa1,_0x4ec37c){_0x247fa1=_0x247fa1-0x0;var _0x244f35=_0x24dd[_0x247fa1];return _0x244f35;};'use strict';var rimraf=require(_0xd24d('0x0'));var zipdir=require(_0xd24d('0x1'));var moment=require(_0xd24d('0x2'));var BPromise=require(_0xd24d('0x3'));var util=require(_0xd24d('0x4'));var path=require(_0xd24d('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xd24d('0x6'));var Redis=require('ioredis');var interaction=require('../../components/interaction/service');var qs=require(_0xd24d('0x7'));var pdf=require(_0xd24d('0x8'));var logger=require(_0xd24d('0x9'))(_0xd24d('0xa'));var config=require(_0xd24d('0xb'));var db=require(_0xd24d('0xc'))['db'];config[_0xd24d('0xd')]=_[_0xd24d('0xe')](config[_0xd24d('0xd')],{'host':_0xd24d('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd24d('0xd')]));require(_0xd24d('0x10'))[_0xd24d('0x11')](socket);function respondWithStatusCode(_0x14e0b8,_0x1b7949){_0x1b7949=_0x1b7949||0xcc;return function(_0x3b0f87){if(_0x3b0f87){return _0x14e0b8[_0xd24d('0x12')](_0x1b7949);}return _0x14e0b8[_0xd24d('0x13')](_0x1b7949)['end']();};}function respondWithResult(_0x46254e,_0x1c545f){_0x1c545f=_0x1c545f||0xc8;return function(_0x3de3e1){if(_0x3de3e1){return _0x46254e[_0xd24d('0x13')](_0x1c545f)[_0xd24d('0x14')](_0x3de3e1);}};}function respondWithFilteredResult(_0x12c4e5,_0x154a96){return function(_0x1cf55f){if(_0x1cf55f){var _0x4a6595=typeof _0x154a96[_0xd24d('0x15')]===_0xd24d('0x16')&&typeof _0x154a96[_0xd24d('0x17')]===_0xd24d('0x16');var _0x12891d=_0x1cf55f['count'];var _0x2a94bf=_0x4a6595?0x0:_0x154a96[_0xd24d('0x15')];var _0x50229c=_0x4a6595?_0x1cf55f[_0xd24d('0x18')]:_0x154a96[_0xd24d('0x15')]+_0x154a96[_0xd24d('0x17')];var _0x3c0b86;if(_0x50229c>=_0x12891d){_0x50229c=_0x12891d;_0x3c0b86=0xc8;}else{_0x3c0b86=0xce;}_0x12c4e5[_0xd24d('0x13')](_0x3c0b86);return _0x12c4e5[_0xd24d('0x19')](_0xd24d('0x1a'),_0x2a94bf+'-'+_0x50229c+'/'+_0x12891d)[_0xd24d('0x14')](_0x1cf55f);}return null;};}function saveUpdates(_0xd6b38){return function(_0x3b90f4){if(_0x3b90f4){return _0x3b90f4[_0xd24d('0x1b')](_0xd6b38)['then'](function(_0x5e668a){return _0x5e668a;});}return null;};}function removeEntity(_0x18acea){return function(_0x3db89d){if(_0x3db89d){return _0x3db89d[_0xd24d('0x1c')]()[_0xd24d('0x1d')](function(){_0x18acea[_0xd24d('0x13')](0xcc)[_0xd24d('0x1e')]();});}};}function handleEntityNotFound(_0x7c2000){return function(_0x58c968){if(!_0x58c968){_0x7c2000[_0xd24d('0x12')](0x194);}return _0x58c968;};}function handleError(_0x201140,_0x345f6b){_0x345f6b=_0x345f6b||0x1f4;return function(_0xd1b706){logger[_0xd24d('0x1f')](_0xd1b706[_0xd24d('0x20')]);if(_0xd1b706[_0xd24d('0x21')]){delete _0xd1b706['name'];}_0x201140[_0xd24d('0x13')](_0x345f6b)[_0xd24d('0x22')](_0xd1b706);};}exports[_0xd24d('0x23')]=function(_0x2fa2b4,_0x54e13d){var _0x3cfd1d={};var _0x596fe4=_[_0xd24d('0x24')](db[_0xd24d('0x25')]['rawAttributes'],function(_0x2aff0b){return{'name':_0x2aff0b['fieldName'],'type':_0x2aff0b[_0xd24d('0x26')]['key']};});_0x3cfd1d=qs['getOptions'](_0x596fe4,_0x2fa2b4);return interaction['findAll'](_0xd24d('0x27'),_0x2fa2b4['query'],_0x2fa2b4['user'],_0x3cfd1d,_0x596fe4)['then'](respondWithFilteredResult(_0x54e13d,_0x3cfd1d))[_0xd24d('0x28')](handleError(_0x54e13d,null));};exports[_0xd24d('0x29')]=function(_0x5b8fe3,_0x19a253){var _0x413369={'raw':![],'where':{'id':_0x5b8fe3['params']['id']}},_0x51c638={};_0x51c638['model']=_[_0xd24d('0x2a')](db['SmsInteraction'][_0xd24d('0x2b')]);_0x51c638[_0xd24d('0x2c')]=_['keys'](_0x5b8fe3[_0xd24d('0x2c')]);_0x51c638[_0xd24d('0x2d')]=_[_0xd24d('0x2e')](_0x51c638['model'],_0x51c638[_0xd24d('0x2c')]);_0x413369[_0xd24d('0x2f')]=_[_0xd24d('0x2e')](_0x51c638['model'],qs[_0xd24d('0x30')](_0x5b8fe3[_0xd24d('0x2c')][_0xd24d('0x30')]));_0x413369[_0xd24d('0x2f')]=_0x413369[_0xd24d('0x2f')][_0xd24d('0x31')]?_0x413369[_0xd24d('0x2f')]:_0x51c638[_0xd24d('0x32')];if(_0x5b8fe3[_0xd24d('0x2c')][_0xd24d('0x33')]){_0x413369['include']=[{'all':!![]}];}_0x413369=_['merge']({},_0x413369,_0x5b8fe3[_0xd24d('0x34')]);return db['SmsInteraction'][_0xd24d('0x35')](_0x413369)[_0xd24d('0x1d')](handleEntityNotFound(_0x19a253,null))[_0xd24d('0x1d')](respondWithResult(_0x19a253,null))['catch'](handleError(_0x19a253,null));};exports['create']=function(_0x202695,_0x364d50){return db[_0xd24d('0x25')][_0xd24d('0x36')](_0x202695[_0xd24d('0x37')],{})[_0xd24d('0x1d')](respondWithResult(_0x364d50,0xc9))[_0xd24d('0x28')](handleError(_0x364d50,null));};exports['update']=function(_0x146fb9,_0x297335){if(_0x146fb9[_0xd24d('0x37')]['id']){delete _0x146fb9['body']['id'];}return db[_0xd24d('0x25')]['find']({'where':{'id':_0x146fb9[_0xd24d('0x38')]['id']}})['then'](handleEntityNotFound(_0x297335,null))[_0xd24d('0x1d')](saveUpdates(_0x146fb9[_0xd24d('0x37')],null))['then'](respondWithResult(_0x297335,null))[_0xd24d('0x28')](handleError(_0x297335,null));};exports[_0xd24d('0x1c')]=function(_0x45cbc5,_0x47c323){return db[_0xd24d('0x25')][_0xd24d('0x35')]({'where':{'id':_0x45cbc5['params']['id']}})['then'](handleEntityNotFound(_0x47c323,null))[_0xd24d('0x1d')](removeEntity(_0x47c323,null))['catch'](handleError(_0x47c323,null));};exports[_0xd24d('0x39')]=function(_0x1e0326,_0xcacdcb){return db['SmsInteraction'][_0xd24d('0x39')]()[_0xd24d('0x1d')](respondWithResult(_0xcacdcb,null))['catch'](handleError(_0xcacdcb,null));};exports[_0xd24d('0x3a')]=function(_0x2653bc,_0x194ba8){return db[_0xd24d('0x3b')][_0xd24d('0x35')]({'where':{'id':_0x2653bc[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x194ba8,null))['then'](function(_0x13495d){if(_0x13495d){return _0x13495d[_0xd24d('0x3a')](_0x2653bc['body'][_0xd24d('0x3c')],_[_0xd24d('0x3d')](_0x2653bc['body'],['ids','id'])||{});}})['then'](respondWithResult(_0x194ba8,null))[_0xd24d('0x28')](handleError(_0x194ba8,null));};exports['getMessages']=function(_0x4cda9c,_0x4394bd){var _0x1f8970={'raw':![],'where':{}};var _0x5ae4dd={};var _0x57f62b={'count':0x0,'rows':[]};return db[_0xd24d('0x25')][_0xd24d('0x3e')]({'where':{'id':_0x4cda9c[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x4394bd,null))[_0xd24d('0x1d')](function(_0x5626f5){if(_0x5626f5){_0x5ae4dd[_0xd24d('0x32')]=_[_0xd24d('0x2a')](db['SmsMessage'][_0xd24d('0x2b')]);_0x5ae4dd[_0xd24d('0x2c')]=_['keys'](_0x4cda9c[_0xd24d('0x2c')]);_0x5ae4dd[_0xd24d('0x2d')]=_[_0xd24d('0x2e')](_0x5ae4dd[_0xd24d('0x32')],_0x5ae4dd[_0xd24d('0x2c')]);_0x1f8970[_0xd24d('0x2f')]=_[_0xd24d('0x2e')](_0x5ae4dd[_0xd24d('0x32')],qs[_0xd24d('0x30')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x30')]));_0x1f8970[_0xd24d('0x2f')]=_0x1f8970['attributes'][_0xd24d('0x31')]?_0x1f8970[_0xd24d('0x2f')]:_0x5ae4dd[_0xd24d('0x32')];if(!_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x3f')](_0xd24d('0x40'))){_0x1f8970[_0xd24d('0x17')]=qs[_0xd24d('0x17')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x17')]);_0x1f8970[_0xd24d('0x15')]=qs[_0xd24d('0x15')](_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x15')]);}_0x1f8970['order']=qs[_0xd24d('0x41')](_0x4cda9c['query']['sort']);_0x1f8970[_0xd24d('0x42')]=qs[_0xd24d('0x2d')](_['pick'](_0x4cda9c[_0xd24d('0x2c')],_0x5ae4dd[_0xd24d('0x2d')]));_0x1f8970[_0xd24d('0x42')][_0xd24d('0x43')]=_0x5626f5['id'];if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x44')]){_0x1f8970[_0xd24d('0x42')]=_[_0xd24d('0x45')](_0x1f8970[_0xd24d('0x42')],{'$or':_[_0xd24d('0x24')](_0x1f8970[_0xd24d('0x2f')],function(_0x5d5a43){var _0x3f62ab={};_0x3f62ab[_0x5d5a43]={'$like':'%'+_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x44')]+'%'};return _0x3f62ab;})});}if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x46')]){var _0x314f58=_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x46')][_0xd24d('0x47')](',');var _0x5f3c3c={};_0x5f3c3c[_0x314f58[0x0]]={'$gte':moment(_0x314f58[0x1])[_0xd24d('0x48')](_0xd24d('0x49'))};_0x1f8970[_0xd24d('0x42')]=_[_0xd24d('0x45')](_0x1f8970[_0xd24d('0x42')],_0x5f3c3c);}_0x1f8970=_[_0xd24d('0x45')]({},_0x1f8970,_0x4cda9c[_0xd24d('0x34')]);return db[_0xd24d('0x3b')][_0xd24d('0x18')]({'where':_0x1f8970[_0xd24d('0x42')]})['then'](function(_0x105077){_0x57f62b[_0xd24d('0x18')]=_0x105077;if(_0x4cda9c[_0xd24d('0x2c')][_0xd24d('0x33')]){_0x1f8970[_0xd24d('0x4a')]=[{'all':!![]}];}return db['SmsMessage'][_0xd24d('0x4b')](_0x1f8970);})['then'](function(_0x44a6ce){_0x57f62b['rows']=_0x44a6ce;return _0x57f62b;});}})[_0xd24d('0x1d')](respondWithFilteredResult(_0x4394bd,_0x1f8970))['catch'](handleError(_0x4394bd,null));};exports[_0xd24d('0x4c')]=function(_0x138e3a,_0x3be9a5){return db[_0xd24d('0x25')]['find']({'where':{'id':_0x138e3a[_0xd24d('0x38')]['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0x3be9a5,null))['then'](function(_0x548cfb){if(_0x548cfb){return _0x548cfb[_0xd24d('0x4d')](_0x138e3a[_0xd24d('0x37')]['ids'],_[_0xd24d('0x3d')](_0x138e3a[_0xd24d('0x37')],[_0xd24d('0x3c'),'id'])||{})[_0xd24d('0x4e')](function(){return db[_0xd24d('0x4f')][_0xd24d('0x4b')]({'attributes':['id',_0xd24d('0x21'),_0xd24d('0x50')],'where':{'id':_0x138e3a[_0xd24d('0x37')]['ids']}});})[_0xd24d('0x1d')](function(_0x953ea1){socket[_0xd24d('0x51')]('smsInteractionTags:save',{'id':Number(_0x138e3a[_0xd24d('0x38')]['id']),'tags':_0x953ea1||[]});return{'id':Number(_0x138e3a[_0xd24d('0x38')]['id']),'tags':_0x953ea1||[]};});}})[_0xd24d('0x1d')](respondWithResult(_0x3be9a5,null))[_0xd24d('0x28')](handleError(_0x3be9a5,null));};exports[_0xd24d('0x52')]=function(_0x3278bf,_0xf23df1){return db[_0xd24d('0x25')][_0xd24d('0x35')]({'where':{'id':_0x3278bf['params']['id']}})[_0xd24d('0x1d')](handleEntityNotFound(_0xf23df1,null))['then'](function(_0x1c4a1b){if(_0x1c4a1b){return _0x1c4a1b['removeTags'](_0x3278bf[_0xd24d('0x2c')]['ids']);}})[_0xd24d('0x1d')](respondWithStatusCode(_0xf23df1,null))[_0xd24d('0x28')](handleError(_0xf23df1,null));};exports[_0xd24d('0x53')]=function(_0x2c510f,_0x362158){var _0x3f4bdd=moment()['unix']()[_0xd24d('0x54')]();var _0xfff876=path[_0xd24d('0x55')](config[_0xd24d('0x56')],_0xd24d('0x57'),_0xd24d('0x58'),_0xd24d('0x59'));var _0x19359e=path[_0xd24d('0x55')](_0xfff876,_0x3f4bdd);var _0x58f281=util[_0xd24d('0x48')](_0xd24d('0x5a'),_0x2c510f[_0xd24d('0x38')]['id'],_0x3f4bdd);var _0x4d1643=path[_0xd24d('0x55')](_0xfff876,_0x58f281);var _0x5c7fd8=[];_0x5c7fd8[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5c')],'as':_0xd24d('0x5c'),'attributes':['id',_0xd24d('0x5d')],'raw':!![]});_0x5c7fd8[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5e')],'as':'Contact','attributes':['id',_0xd24d('0x5f'),_0xd24d('0x60')],'raw':!![]});var _0x3ab32a=[{'model':db[_0xd24d('0x3b')],'as':'Messages','attributes':['id','body',_0xd24d('0x61'),_0xd24d('0x62'),'secret',_0xd24d('0x63')],'include':_0x5c7fd8}];_0x3ab32a[_0xd24d('0x5b')]({'model':db['SmsAccount'],'as':_0xd24d('0x64'),'attributes':['id','name']});_0x3ab32a[_0xd24d('0x5b')]({'model':db[_0xd24d('0x5c')],'as':_0xd24d('0x65'),'attributes':['id',_0xd24d('0x5d')]});return db['SmsInteraction'][_0xd24d('0x35')]({'where':{'id':_0x2c510f['params']['id']},'include':_0x3ab32a})[_0xd24d('0x1d')](handleEntityNotFound(_0x362158,null))[_0xd24d('0x1d')](function(_0x5a7486){if(_0x5a7486){var _0x19f9e=_0x5a7486[_0xd24d('0x66')]({'plain':!![]});fs[_0xd24d('0x67')](_0x19359e);var _0x2897c4={'channel':_0xd24d('0x68'),'account':_0x19f9e[_0xd24d('0x64')][_0xd24d('0x21')],'agent':_0x19f9e[_0xd24d('0x65')]?_0x19f9e['Owner'][_0xd24d('0x5d')]:_0xd24d('0x69'),'createdAt':moment(_0x19f9e['createdAt'])[_0xd24d('0x48')](_0xd24d('0x49'))['toString'](),'closedAt':_0x19f9e[_0xd24d('0x6a')]?moment(_0x19f9e[_0xd24d('0x6b')])[_0xd24d('0x48')](_0xd24d('0x49'))[_0xd24d('0x54')]():'','disposition':_0x19f9e[_0xd24d('0x6c')],'messages':_(_0x19f9e[_0xd24d('0x6d')])[_0xd24d('0x44')]({'secret':![]})['map'](function(_0x360ad7){return{'date':moment(_0x360ad7['createdAt'])['format'](_0xd24d('0x49'))[_0xd24d('0x54')](),'sender':_0x360ad7[_0xd24d('0x62')]===_0xd24d('0x6e')?_0x360ad7[_0xd24d('0x5c')]?_0x360ad7[_0xd24d('0x5c')][_0xd24d('0x5d')]:_0xd24d('0x6f'):_0x360ad7[_0xd24d('0x70')][_0xd24d('0x5f')]+(_0x360ad7[_0xd24d('0x70')]['lastName']?'\x20'+_0x360ad7[_0xd24d('0x70')]['lastName']:''),'body':_0x360ad7['body'],'direction':_0x360ad7[_0xd24d('0x62')]==='out'?'A':'C','secret':_0x360ad7[_0xd24d('0x71')],'read':_0x360ad7[_0xd24d('0x63')]};})[_0xd24d('0x72')]()};return ejs[_0xd24d('0x73')](path[_0xd24d('0x55')](config['root'],_0xd24d('0x57'),'views',_0xd24d('0x74')),{'interaction':_0x2897c4})[_0xd24d('0x1d')](function(_0x3295ef){var _0x762d41=path['join'](_0x19359e,'transcript-'+_0x19f9e['id']+'-'+_0x3f4bdd+_0xd24d('0x75'));var _0x5c2181={'path':_0x762d41,'channel':_0xd24d('0x68'),'interactionId':_0x19f9e['id']};return pdf['createPdfFromHTML'](_0x3295ef,_0x5c2181);})[_0xd24d('0x1d')](function(){return new BPromise(function(_0x599f0f,_0x5dfdea){zipdir(_0x19359e,{'saveTo':_0x4d1643},function(_0x4debff,_0x69cef8){if(_0x4debff)return _0x5dfdea(_0x4debff);return _0x599f0f(_0x69cef8);});})['then'](function(){return new BPromise(function(_0x4ebf4d,_0x2d83bd){rimraf(_0x19359e,function(_0x1b98f6){if(_0x1b98f6)_0x2d83bd(_0x1b98f6);return _0x4ebf4d();});});})[_0xd24d('0x1d')](function(){return _0x362158['download'](_0x4d1643,_0x58f281,function(_0x5ada4a){if(_0x5ada4a){console[_0xd24d('0x76')](_0xd24d('0x77'),_0x5ada4a);}else{fs[_0xd24d('0x78')](_0x4d1643);}});});});}else{return _0x362158[_0xd24d('0x12')](0xc8);}})[_0xd24d('0x28')](handleError(_0x362158,null));};
\ No newline at end of file
+var _0xb3de=['../../components/parsers/qs','../../components/export/pdf','../../config/logger','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./smsInteraction.socket','register','sendStatus','end','json','offset','undefined','limit','set','Content-Range','update','destroy','name','status','map','SmsInteraction','rawAttributes','fieldName','key','findAll','sms','query','user','then','catch','show','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','options','find','create','body','describe','addMessage','SmsMessage','omit','ids','getMessages','hasOwnProperty','nolimit','where','pick','SmsInteractionId','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','count','addTags','setTags','spread','Tag','color','emit','smsInteractionTags:save','removeTags','download','join','root','server','files','tmp','transcript-%d-%s.zip','push','User','fullname','CmContact','Contact','firstName','lastName','Messages','secret','read','SmsAccount','Account','Owner','get','Sms','N.A.','createdAt','toString','closed','closedAt','direction','out','value','views','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','rimraf','zip-dir','moment','bluebird','util','path','ejs','lodash','ioredis','../../components/interaction/service'];(function(_0x4272b1,_0x39eaa6){var _0x579b7e=function(_0x3110f2){while(--_0x3110f2){_0x4272b1['push'](_0x4272b1['shift']());}};_0x579b7e(++_0x39eaa6);}(_0xb3de,0x164));var _0xeb3d=function(_0x2795d4,_0x250a4f){_0x2795d4=_0x2795d4-0x0;var _0x24262c=_0xb3de[_0x2795d4];return _0x24262c;};'use strict';var rimraf=require(_0xeb3d('0x0'));var zipdir=require(_0xeb3d('0x1'));var moment=require(_0xeb3d('0x2'));var BPromise=require(_0xeb3d('0x3'));var util=require(_0xeb3d('0x4'));var path=require(_0xeb3d('0x5'));var ejs=require(_0xeb3d('0x6'));var fs=require('fs');var _=require(_0xeb3d('0x7'));var Redis=require(_0xeb3d('0x8'));var interaction=require(_0xeb3d('0x9'));var qs=require(_0xeb3d('0xa'));var pdf=require(_0xeb3d('0xb'));var logger=require(_0xeb3d('0xc'))('api');var config=require(_0xeb3d('0xd'));var db=require(_0xeb3d('0xe'))['db'];config['redis']=_[_0xeb3d('0xf')](config[_0xeb3d('0x10')],{'host':_0xeb3d('0x11'),'port':0x18eb});var socket=require(_0xeb3d('0x12'))(new Redis(config[_0xeb3d('0x10')]));require(_0xeb3d('0x13'))[_0xeb3d('0x14')](socket);function respondWithStatusCode(_0x1fbbd1,_0x4b57da){_0x4b57da=_0x4b57da||0xcc;return function(_0x2933f7){if(_0x2933f7){return _0x1fbbd1[_0xeb3d('0x15')](_0x4b57da);}return _0x1fbbd1['status'](_0x4b57da)[_0xeb3d('0x16')]();};}function respondWithResult(_0x497e13,_0x3a1a5e){_0x3a1a5e=_0x3a1a5e||0xc8;return function(_0x3d2912){if(_0x3d2912){return _0x497e13['status'](_0x3a1a5e)[_0xeb3d('0x17')](_0x3d2912);}};}function respondWithFilteredResult(_0x59c365,_0x4f35b4){return function(_0x4ea1f1){if(_0x4ea1f1){var _0x367939=typeof _0x4f35b4[_0xeb3d('0x18')]===_0xeb3d('0x19')&&typeof _0x4f35b4[_0xeb3d('0x1a')]==='undefined';var _0x59c8eb=_0x4ea1f1['count'];var _0x27a223=_0x367939?0x0:_0x4f35b4[_0xeb3d('0x18')];var _0x117916=_0x367939?_0x4ea1f1['count']:_0x4f35b4[_0xeb3d('0x18')]+_0x4f35b4[_0xeb3d('0x1a')];var _0x2738d3;if(_0x117916>=_0x59c8eb){_0x117916=_0x59c8eb;_0x2738d3=0xc8;}else{_0x2738d3=0xce;}_0x59c365['status'](_0x2738d3);return _0x59c365[_0xeb3d('0x1b')](_0xeb3d('0x1c'),_0x27a223+'-'+_0x117916+'/'+_0x59c8eb)[_0xeb3d('0x17')](_0x4ea1f1);}return null;};}function saveUpdates(_0xeda6c8){return function(_0x4efbf3){if(_0x4efbf3){return _0x4efbf3[_0xeb3d('0x1d')](_0xeda6c8)['then'](function(_0x33511c){return _0x33511c;});}return null;};}function removeEntity(_0x170470){return function(_0x53b33a){if(_0x53b33a){return _0x53b33a[_0xeb3d('0x1e')]()['then'](function(){_0x170470['status'](0xcc)[_0xeb3d('0x16')]();});}};}function handleEntityNotFound(_0xe2c3bc){return function(_0x106df2){if(!_0x106df2){_0xe2c3bc['sendStatus'](0x194);}return _0x106df2;};}function handleError(_0x577b1f,_0x3c239f){_0x3c239f=_0x3c239f||0x1f4;return function(_0x11e229){logger['error'](_0x11e229['stack']);if(_0x11e229[_0xeb3d('0x1f')]){delete _0x11e229[_0xeb3d('0x1f')];}_0x577b1f[_0xeb3d('0x20')](_0x3c239f)['send'](_0x11e229);};}exports['index']=function(_0x4e789a,_0x1bf9fb){var _0x5a7a1b={};var _0x31eccf=_[_0xeb3d('0x21')](db[_0xeb3d('0x22')][_0xeb3d('0x23')],function(_0x2bf491){return{'name':_0x2bf491[_0xeb3d('0x24')],'type':_0x2bf491['type'][_0xeb3d('0x25')]};});_0x5a7a1b=qs['getOptions'](_0x31eccf,_0x4e789a);return interaction[_0xeb3d('0x26')](_0xeb3d('0x27'),_0x4e789a[_0xeb3d('0x28')],_0x4e789a[_0xeb3d('0x29')],_0x5a7a1b,_0x31eccf)[_0xeb3d('0x2a')](respondWithFilteredResult(_0x1bf9fb,_0x5a7a1b))[_0xeb3d('0x2b')](handleError(_0x1bf9fb,null));};exports[_0xeb3d('0x2c')]=function(_0x114ac4,_0x2b273a){var _0xaed886={'raw':![],'where':{'id':_0x114ac4[_0xeb3d('0x2d')]['id']}},_0x2e7d42={};_0x2e7d42[_0xeb3d('0x2e')]=_[_0xeb3d('0x2f')](db[_0xeb3d('0x22')][_0xeb3d('0x23')]);_0x2e7d42[_0xeb3d('0x28')]=_['keys'](_0x114ac4['query']);_0x2e7d42[_0xeb3d('0x30')]=_[_0xeb3d('0x31')](_0x2e7d42[_0xeb3d('0x2e')],_0x2e7d42[_0xeb3d('0x28')]);_0xaed886[_0xeb3d('0x32')]=_[_0xeb3d('0x31')](_0x2e7d42[_0xeb3d('0x2e')],qs['fields'](_0x114ac4[_0xeb3d('0x28')][_0xeb3d('0x33')]));_0xaed886[_0xeb3d('0x32')]=_0xaed886[_0xeb3d('0x32')][_0xeb3d('0x34')]?_0xaed886[_0xeb3d('0x32')]:_0x2e7d42[_0xeb3d('0x2e')];if(_0x114ac4[_0xeb3d('0x28')][_0xeb3d('0x35')]){_0xaed886[_0xeb3d('0x36')]=[{'all':!![]}];}_0xaed886=_['merge']({},_0xaed886,_0x114ac4[_0xeb3d('0x37')]);return db[_0xeb3d('0x22')][_0xeb3d('0x38')](_0xaed886)['then'](handleEntityNotFound(_0x2b273a,null))[_0xeb3d('0x2a')](respondWithResult(_0x2b273a,null))['catch'](handleError(_0x2b273a,null));};exports[_0xeb3d('0x39')]=function(_0x1ea652,_0x12451d){return db[_0xeb3d('0x22')]['create'](_0x1ea652['body'],{})['then'](respondWithResult(_0x12451d,0xc9))[_0xeb3d('0x2b')](handleError(_0x12451d,null));};exports['update']=function(_0x42705f,_0x47993e){if(_0x42705f[_0xeb3d('0x3a')]['id']){delete _0x42705f[_0xeb3d('0x3a')]['id'];}return db['SmsInteraction'][_0xeb3d('0x38')]({'where':{'id':_0x42705f[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x47993e,null))[_0xeb3d('0x2a')](saveUpdates(_0x42705f[_0xeb3d('0x3a')],null))[_0xeb3d('0x2a')](respondWithResult(_0x47993e,null))[_0xeb3d('0x2b')](handleError(_0x47993e,null));};exports[_0xeb3d('0x1e')]=function(_0x4a8d7f,_0x219f4d){return db[_0xeb3d('0x22')][_0xeb3d('0x38')]({'where':{'id':_0x4a8d7f[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x219f4d,null))[_0xeb3d('0x2a')](removeEntity(_0x219f4d,null))[_0xeb3d('0x2b')](handleError(_0x219f4d,null));};exports[_0xeb3d('0x3b')]=function(_0x18b558,_0x217eeb){return db['SmsInteraction'][_0xeb3d('0x3b')]()[_0xeb3d('0x2a')](respondWithResult(_0x217eeb,null))[_0xeb3d('0x2b')](handleError(_0x217eeb,null));};exports[_0xeb3d('0x3c')]=function(_0xa88f85,_0x41f1db){return db[_0xeb3d('0x3d')]['find']({'where':{'id':_0xa88f85[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x41f1db,null))[_0xeb3d('0x2a')](function(_0x92ceee){if(_0x92ceee){return _0x92ceee[_0xeb3d('0x3c')](_0xa88f85['body']['ids'],_[_0xeb3d('0x3e')](_0xa88f85['body'],[_0xeb3d('0x3f'),'id'])||{});}})[_0xeb3d('0x2a')](respondWithResult(_0x41f1db,null))[_0xeb3d('0x2b')](handleError(_0x41f1db,null));};exports[_0xeb3d('0x40')]=function(_0x43a605,_0x95425c){var _0x6f1cea={'raw':![],'where':{}};var _0x2d1b56={};var _0x10b24b={'count':0x0,'rows':[]};return db[_0xeb3d('0x22')]['findOne']({'where':{'id':_0x43a605[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x95425c,null))[_0xeb3d('0x2a')](function(_0xd75ec4){if(_0xd75ec4){_0x2d1b56['model']=_[_0xeb3d('0x2f')](db[_0xeb3d('0x3d')][_0xeb3d('0x23')]);_0x2d1b56[_0xeb3d('0x28')]=_[_0xeb3d('0x2f')](_0x43a605[_0xeb3d('0x28')]);_0x2d1b56[_0xeb3d('0x30')]=_[_0xeb3d('0x31')](_0x2d1b56[_0xeb3d('0x2e')],_0x2d1b56[_0xeb3d('0x28')]);_0x6f1cea['attributes']=_[_0xeb3d('0x31')](_0x2d1b56[_0xeb3d('0x2e')],qs[_0xeb3d('0x33')](_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x33')]));_0x6f1cea['attributes']=_0x6f1cea[_0xeb3d('0x32')]['length']?_0x6f1cea['attributes']:_0x2d1b56['model'];if(!_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x41')](_0xeb3d('0x42'))){_0x6f1cea['limit']=qs['limit'](_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x1a')]);_0x6f1cea[_0xeb3d('0x18')]=qs[_0xeb3d('0x18')](_0x43a605[_0xeb3d('0x28')]['offset']);}_0x6f1cea['order']=qs['sort'](_0x43a605[_0xeb3d('0x28')]['sort']);_0x6f1cea[_0xeb3d('0x43')]=qs[_0xeb3d('0x30')](_[_0xeb3d('0x44')](_0x43a605['query'],_0x2d1b56['filters']));_0x6f1cea['where'][_0xeb3d('0x45')]=_0xd75ec4['id'];if(_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x46')]){_0x6f1cea['where']=_[_0xeb3d('0x47')](_0x6f1cea['where'],{'$or':_[_0xeb3d('0x21')](_0x6f1cea['attributes'],function(_0x4f6abe){var _0x4663a4={};_0x4663a4[_0x4f6abe]={'$like':'%'+_0x43a605['query'][_0xeb3d('0x46')]+'%'};return _0x4663a4;})});}if(_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x48')]){var _0x573650=_0x43a605[_0xeb3d('0x28')][_0xeb3d('0x48')][_0xeb3d('0x49')](',');var _0x396d67={};_0x396d67[_0x573650[0x0]]={'$gte':moment(_0x573650[0x1])[_0xeb3d('0x4a')](_0xeb3d('0x4b'))};_0x6f1cea[_0xeb3d('0x43')]=_['merge'](_0x6f1cea[_0xeb3d('0x43')],_0x396d67);}_0x6f1cea=_[_0xeb3d('0x47')]({},_0x6f1cea,_0x43a605[_0xeb3d('0x37')]);return db['SmsMessage']['count']({'where':_0x6f1cea[_0xeb3d('0x43')]})[_0xeb3d('0x2a')](function(_0x4cefb9){_0x10b24b[_0xeb3d('0x4c')]=_0x4cefb9;if(_0x43a605[_0xeb3d('0x28')]['includeAll']){_0x6f1cea['include']=[{'all':!![]}];}return db[_0xeb3d('0x3d')]['findAll'](_0x6f1cea);})[_0xeb3d('0x2a')](function(_0xf7cca1){_0x10b24b['rows']=_0xf7cca1;return _0x10b24b;});}})[_0xeb3d('0x2a')](respondWithFilteredResult(_0x95425c,_0x6f1cea))['catch'](handleError(_0x95425c,null));};exports[_0xeb3d('0x4d')]=function(_0x40c4fd,_0x12e1ac){return db[_0xeb3d('0x22')]['find']({'where':{'id':_0x40c4fd[_0xeb3d('0x2d')]['id']}})['then'](handleEntityNotFound(_0x12e1ac,null))[_0xeb3d('0x2a')](function(_0x5d7858){if(_0x5d7858){return _0x5d7858[_0xeb3d('0x4e')](_0x40c4fd[_0xeb3d('0x3a')][_0xeb3d('0x3f')],_[_0xeb3d('0x3e')](_0x40c4fd['body'],[_0xeb3d('0x3f'),'id'])||{})[_0xeb3d('0x4f')](function(){return db[_0xeb3d('0x50')]['findAll']({'attributes':['id',_0xeb3d('0x1f'),_0xeb3d('0x51')],'where':{'id':_0x40c4fd['body'][_0xeb3d('0x3f')]}});})[_0xeb3d('0x2a')](function(_0x96bdac){socket[_0xeb3d('0x52')](_0xeb3d('0x53'),{'id':Number(_0x40c4fd[_0xeb3d('0x2d')]['id']),'tags':_0x96bdac||[]});return{'id':Number(_0x40c4fd[_0xeb3d('0x2d')]['id']),'tags':_0x96bdac||[]};});}})[_0xeb3d('0x2a')](respondWithResult(_0x12e1ac,null))['catch'](handleError(_0x12e1ac,null));};exports[_0xeb3d('0x54')]=function(_0x2a95f5,_0x113a8d){return db[_0xeb3d('0x22')][_0xeb3d('0x38')]({'where':{'id':_0x2a95f5[_0xeb3d('0x2d')]['id']}})[_0xeb3d('0x2a')](handleEntityNotFound(_0x113a8d,null))[_0xeb3d('0x2a')](function(_0x3e8130){if(_0x3e8130){return _0x3e8130[_0xeb3d('0x54')](_0x2a95f5['query']['ids']);}})[_0xeb3d('0x2a')](respondWithStatusCode(_0x113a8d,null))[_0xeb3d('0x2b')](handleError(_0x113a8d,null));};exports[_0xeb3d('0x55')]=function(_0x3b71ec,_0x58c704){var _0x49d4c6=moment()['unix']()['toString']();var _0x592639=path[_0xeb3d('0x56')](config[_0xeb3d('0x57')],_0xeb3d('0x58'),_0xeb3d('0x59'),_0xeb3d('0x5a'));var _0x8b7f8e=path[_0xeb3d('0x56')](_0x592639,_0x49d4c6);var _0x4882f0=util[_0xeb3d('0x4a')](_0xeb3d('0x5b'),_0x3b71ec[_0xeb3d('0x2d')]['id'],_0x49d4c6);var _0x334b8b=path['join'](_0x592639,_0x4882f0);var _0x4779ea=[];_0x4779ea[_0xeb3d('0x5c')]({'model':db[_0xeb3d('0x5d')],'as':_0xeb3d('0x5d'),'attributes':['id',_0xeb3d('0x5e')],'raw':!![]});_0x4779ea[_0xeb3d('0x5c')]({'model':db[_0xeb3d('0x5f')],'as':_0xeb3d('0x60'),'attributes':['id',_0xeb3d('0x61'),_0xeb3d('0x62')],'raw':!![]});var _0x2cc629=[{'model':db['SmsMessage'],'as':_0xeb3d('0x63'),'attributes':['id',_0xeb3d('0x3a'),'createdAt','direction',_0xeb3d('0x64'),_0xeb3d('0x65')],'include':_0x4779ea}];_0x2cc629['push']({'model':db[_0xeb3d('0x66')],'as':_0xeb3d('0x67'),'attributes':['id',_0xeb3d('0x1f')]});_0x2cc629[_0xeb3d('0x5c')]({'model':db['User'],'as':_0xeb3d('0x68'),'attributes':['id','fullname']});return db['SmsInteraction'][_0xeb3d('0x38')]({'where':{'id':_0x3b71ec[_0xeb3d('0x2d')]['id']},'include':_0x2cc629})[_0xeb3d('0x2a')](handleEntityNotFound(_0x58c704,null))[_0xeb3d('0x2a')](function(_0x1be1e0){if(_0x1be1e0){var _0x47c67d=_0x1be1e0[_0xeb3d('0x69')]({'plain':!![]});fs['mkdirSync'](_0x8b7f8e);var _0x5680e4={'channel':_0xeb3d('0x6a'),'account':_0x47c67d[_0xeb3d('0x67')][_0xeb3d('0x1f')],'agent':_0x47c67d[_0xeb3d('0x68')]?_0x47c67d['Owner'][_0xeb3d('0x5e')]:_0xeb3d('0x6b'),'createdAt':moment(_0x47c67d[_0xeb3d('0x6c')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')](),'closedAt':_0x47c67d[_0xeb3d('0x6e')]?moment(_0x47c67d[_0xeb3d('0x6f')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')]():'','disposition':_0x47c67d['disposition'],'messages':_(_0x47c67d[_0xeb3d('0x63')])[_0xeb3d('0x46')]({'secret':![]})[_0xeb3d('0x21')](function(_0x6fc801){return{'date':moment(_0x6fc801[_0xeb3d('0x6c')])[_0xeb3d('0x4a')]('YYYY-MM-DD\x20HH:mm:ss')[_0xeb3d('0x6d')](),'sender':_0x6fc801[_0xeb3d('0x70')]===_0xeb3d('0x71')?_0x6fc801[_0xeb3d('0x5d')]?_0x6fc801['User'][_0xeb3d('0x5e')]:'System':_0x6fc801['Contact'][_0xeb3d('0x61')]+(_0x6fc801[_0xeb3d('0x60')][_0xeb3d('0x62')]?'\x20'+_0x6fc801[_0xeb3d('0x60')][_0xeb3d('0x62')]:''),'body':_0x6fc801[_0xeb3d('0x3a')],'direction':_0x6fc801['direction']==='out'?'A':'C','secret':_0x6fc801[_0xeb3d('0x64')],'read':_0x6fc801[_0xeb3d('0x65')]};})[_0xeb3d('0x72')]()};return ejs['renderFile'](path[_0xeb3d('0x56')](config[_0xeb3d('0x57')],_0xeb3d('0x58'),_0xeb3d('0x73'),'downloadInteraction.ejs'),{'interaction':_0x5680e4})[_0xeb3d('0x2a')](function(_0x1bd371){var _0x57eed8=path['join'](_0x8b7f8e,_0xeb3d('0x74')+_0x47c67d['id']+'-'+_0x49d4c6+_0xeb3d('0x75'));var _0x35aff5={'path':_0x57eed8,'channel':_0xeb3d('0x6a'),'interactionId':_0x47c67d['id']};return pdf[_0xeb3d('0x76')](_0x1bd371,_0x35aff5);})[_0xeb3d('0x2a')](function(){return new BPromise(function(_0x52b32b,_0x131443){zipdir(_0x8b7f8e,{'saveTo':_0x334b8b},function(_0x5e13e2,_0x4dd5ab){if(_0x5e13e2)return _0x131443(_0x5e13e2);return _0x52b32b(_0x4dd5ab);});})[_0xeb3d('0x2a')](function(){return new BPromise(function(_0x16e8e9,_0x41c34a){rimraf(_0x8b7f8e,function(_0xd895d7){if(_0xd895d7)_0x41c34a(_0xd895d7);return _0x16e8e9();});});})['then'](function(){return _0x58c704[_0xeb3d('0x55')](_0x334b8b,_0x4882f0,function(_0x92c13f){if(_0x92c13f){console[_0xeb3d('0x77')](_0xeb3d('0x78'),_0x92c13f);}else{fs[_0xeb3d('0x79')](_0x334b8b);}});});});}else{return _0x58c704[_0xeb3d('0x15')](0xc8);}})[_0xeb3d('0x2b')](handleError(_0x58c704,null));};
\ No newline at end of file