Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index f80ac07..c5e5835 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x92ed=['params','keys','filters','model','attributes','intersection','fields','length','includeAll','merge','options','find','catch','create','body','destroy','describe','addMessage','ids','getMessages','findOne','OpenchannelMessage','hasOwnProperty','order','sort','where','pick','filter','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','rows','addTags','omit','Tag','color','emit','openchannelInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','User','fullname','push','CmContact','Contact','lastName','Attachment','Messages','createdAt','direction','secret','read','OpenchannelAccount','Account','Owner','get','Openchannel','closed','closedAt','disposition','threadId','Public','basename','existsSync','createReadStream','pipe','createWriteStream','System','firstName','value','renderFile','downloadInteraction.ejs','transcript-','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','util','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../mysqldb','defaults','localhost','redis','register','sendStatus','status','offset','limit','undefined','count','Content-Range','update','then','end','error','stack','name','send','map','OpenchannelInteraction','rawAttributes','fieldName','key','getOptions','openchannel','query','type','from'];(function(_0x5b5d0a,_0x1ad092){var _0x9777f6=function(_0x4d938e){while(--_0x4d938e){_0x5b5d0a['push'](_0x5b5d0a['shift']());}};_0x9777f6(++_0x1ad092);}(_0x92ed,0xd5));var _0xd92e=function(_0x52d481,_0x5cef5c){_0x52d481=_0x52d481-0x0;var _0x3c4aa7=_0x92ed[_0x52d481];return _0x3c4aa7;};'use strict';var rimraf=require(_0xd92e('0x0'));var zipdir=require(_0xd92e('0x1'));var moment=require('moment');var util=require(_0xd92e('0x2'));var path=require('path');var ejs=require('ejs');var fs=require('fs');var _=require(_0xd92e('0x3'));var Redis=require(_0xd92e('0x4'));var interaction=require(_0xd92e('0x5'));var qs=require(_0xd92e('0x6'));var pdf=require(_0xd92e('0x7'));var logger=require(_0xd92e('0x8'))(_0xd92e('0x9'));var config=require('../../config/environment');var db=require(_0xd92e('0xa'))['db'];config['redis']=_[_0xd92e('0xb')](config['redis'],{'host':_0xd92e('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd92e('0xd')]));require('./openchannelInteraction.socket')[_0xd92e('0xe')](socket);function respondWithStatusCode(_0x48acb0,_0x3b0e3a){_0x3b0e3a=_0x3b0e3a||0xcc;return function(_0x465956){if(_0x465956){return _0x48acb0[_0xd92e('0xf')](_0x3b0e3a);}return _0x48acb0[_0xd92e('0x10')](_0x3b0e3a)['end']();};}function respondWithResult(_0x638d3c,_0x2662ec){_0x2662ec=_0x2662ec||0xc8;return function(_0x424203){if(_0x424203){return _0x638d3c[_0xd92e('0x10')](_0x2662ec)['json'](_0x424203);}};}function respondWithFilteredResult(_0x2c2254,_0x2b4706){return function(_0x376281){if(_0x376281){var _0x257ba0=typeof _0x2b4706[_0xd92e('0x11')]==='undefined'&&typeof _0x2b4706[_0xd92e('0x12')]===_0xd92e('0x13');var _0x1972d8=_0x376281[_0xd92e('0x14')];var _0x430770=_0x257ba0?0x0:_0x2b4706[_0xd92e('0x11')];var _0x5a6469=_0x257ba0?_0x376281[_0xd92e('0x14')]:_0x2b4706[_0xd92e('0x11')]+_0x2b4706[_0xd92e('0x12')];var _0x28a11d;if(_0x5a6469>=_0x1972d8){_0x5a6469=_0x1972d8;_0x28a11d=0xc8;}else{_0x28a11d=0xce;}_0x2c2254[_0xd92e('0x10')](_0x28a11d);return _0x2c2254['set'](_0xd92e('0x15'),_0x430770+'-'+_0x5a6469+'/'+_0x1972d8)['json'](_0x376281);}return null;};}function saveUpdates(_0x503c8f){return function(_0x5e8cfc){if(_0x5e8cfc){return _0x5e8cfc[_0xd92e('0x16')](_0x503c8f)['then'](function(_0x430f9f){return _0x430f9f;});}return null;};}function removeEntity(_0x7fac90){return function(_0x1ac62b){if(_0x1ac62b){return _0x1ac62b['destroy']()[_0xd92e('0x17')](function(){_0x7fac90['status'](0xcc)[_0xd92e('0x18')]();});}};}function handleEntityNotFound(_0x3670be){return function(_0x29c14b){if(!_0x29c14b){_0x3670be[_0xd92e('0xf')](0x194);}return _0x29c14b;};}function handleError(_0x19ffc3,_0x3ad458){_0x3ad458=_0x3ad458||0x1f4;return function(_0x4cfa82){logger[_0xd92e('0x19')](_0x4cfa82[_0xd92e('0x1a')]);if(_0x4cfa82[_0xd92e('0x1b')]){delete _0x4cfa82[_0xd92e('0x1b')];}_0x19ffc3[_0xd92e('0x10')](_0x3ad458)[_0xd92e('0x1c')](_0x4cfa82);};}exports['index']=function(_0x3869e3,_0xb2bbe7){var _0x310c13={};var _0x2304a6=_[_0xd92e('0x1d')](db[_0xd92e('0x1e')][_0xd92e('0x1f')],function(_0x438df4){return{'name':_0x438df4[_0xd92e('0x20')],'type':_0x438df4['type'][_0xd92e('0x21')]};});_0x310c13=qs[_0xd92e('0x22')](_0x2304a6,_0x3869e3);return interaction['findAll'](_0xd92e('0x23'),_0x3869e3[_0xd92e('0x24')],_0x3869e3['user'],_0x310c13,_0x2304a6)['then'](respondWithFilteredResult(_0xb2bbe7,_0x310c13))['catch'](handleError(_0xb2bbe7,null));};exports['show']=function(_0x1073ca,_0x97800c){var _0x462d5c={};if(_0x1073ca[_0xd92e('0x24')][_0xd92e('0x25')]&&_0x1073ca[_0xd92e('0x24')][_0xd92e('0x25')]==='from'){_0x462d5c[_0xd92e('0x26')]=_0x1073ca[_0xd92e('0x27')]['id'];}else{_0x462d5c['id']=_0x1073ca[_0xd92e('0x27')]['id'];}var _0x2c208d={'raw':![],'where':_0x462d5c},_0x110cab={};_0x110cab['model']=_[_0xd92e('0x28')](db[_0xd92e('0x1e')]['rawAttributes']);_0x110cab[_0xd92e('0x24')]=_[_0xd92e('0x28')](_0x1073ca[_0xd92e('0x24')]);_0x110cab[_0xd92e('0x29')]=_['intersection'](_0x110cab[_0xd92e('0x2a')],_0x110cab[_0xd92e('0x24')]);_0x2c208d[_0xd92e('0x2b')]=_[_0xd92e('0x2c')](_0x110cab[_0xd92e('0x2a')],qs[_0xd92e('0x2d')](_0x1073ca[_0xd92e('0x24')][_0xd92e('0x2d')]));_0x2c208d[_0xd92e('0x2b')]=_0x2c208d['attributes'][_0xd92e('0x2e')]?_0x2c208d['attributes']:_0x110cab[_0xd92e('0x2a')];if(_0x1073ca['query'][_0xd92e('0x2f')]){_0x2c208d['include']=[{'all':!![]}];}_0x2c208d=_[_0xd92e('0x30')]({},_0x2c208d,_0x1073ca[_0xd92e('0x31')]);return db[_0xd92e('0x1e')][_0xd92e('0x32')](_0x2c208d)['then'](handleEntityNotFound(_0x97800c,null))[_0xd92e('0x17')](respondWithResult(_0x97800c,null))[_0xd92e('0x33')](handleError(_0x97800c,null));};exports[_0xd92e('0x34')]=function(_0x5b059c,_0x11bba4){return db['OpenchannelInteraction'][_0xd92e('0x34')](_0x5b059c[_0xd92e('0x35')],{})['then'](respondWithResult(_0x11bba4,0xc9))[_0xd92e('0x33')](handleError(_0x11bba4,null));};exports[_0xd92e('0x16')]=function(_0x96099,_0x9c48c){if(_0x96099['body']['id']){delete _0x96099[_0xd92e('0x35')]['id'];}return db[_0xd92e('0x1e')][_0xd92e('0x32')]({'where':{'id':_0x96099[_0xd92e('0x27')]['id']}})[_0xd92e('0x17')](handleEntityNotFound(_0x9c48c,null))['then'](saveUpdates(_0x96099[_0xd92e('0x35')],null))[_0xd92e('0x17')](respondWithResult(_0x9c48c,null))['catch'](handleError(_0x9c48c,null));};exports[_0xd92e('0x36')]=function(_0x371545,_0x3ccfd0){return db['OpenchannelInteraction']['find']({'where':{'id':_0x371545[_0xd92e('0x27')]['id']}})['then'](handleEntityNotFound(_0x3ccfd0,null))[_0xd92e('0x17')](removeEntity(_0x3ccfd0,null))[_0xd92e('0x33')](handleError(_0x3ccfd0,null));};exports[_0xd92e('0x37')]=function(_0xa044ec,_0x1a7b36){return db[_0xd92e('0x1e')]['describe']()[_0xd92e('0x17')](respondWithResult(_0x1a7b36,null))[_0xd92e('0x33')](handleError(_0x1a7b36,null));};exports[_0xd92e('0x38')]=function(_0x4f30d5,_0x12ccab){return db['OpenchannelMessage']['find']({'where':{'id':_0x4f30d5[_0xd92e('0x27')]['id']}})[_0xd92e('0x17')](handleEntityNotFound(_0x12ccab,null))[_0xd92e('0x17')](function(_0x5c0626){if(_0x5c0626){return _0x5c0626[_0xd92e('0x38')](_0x4f30d5[_0xd92e('0x35')][_0xd92e('0x39')],_['omit'](_0x4f30d5['body'],['ids','id'])||{});}})[_0xd92e('0x17')](respondWithResult(_0x12ccab,null))['catch'](handleError(_0x12ccab,null));};exports[_0xd92e('0x3a')]=function(_0x584244,_0x2e223f){var _0xa0bc3a={'raw':![],'where':{}};var _0x107196={};var _0x3e3ec0={'count':0x0,'rows':[]};return db['OpenchannelInteraction'][_0xd92e('0x3b')]({'where':{'id':_0x584244[_0xd92e('0x27')]['id']}})['then'](handleEntityNotFound(_0x2e223f,null))[_0xd92e('0x17')](function(_0x52b9cd){if(_0x52b9cd){_0x107196[_0xd92e('0x2a')]=_['keys'](db[_0xd92e('0x3c')][_0xd92e('0x1f')]);_0x107196[_0xd92e('0x24')]=_[_0xd92e('0x28')](_0x584244['query']);_0x107196[_0xd92e('0x29')]=_[_0xd92e('0x2c')](_0x107196[_0xd92e('0x2a')],_0x107196[_0xd92e('0x24')]);_0xa0bc3a[_0xd92e('0x2b')]=_[_0xd92e('0x2c')](_0x107196[_0xd92e('0x2a')],qs[_0xd92e('0x2d')](_0x584244['query'][_0xd92e('0x2d')]));_0xa0bc3a[_0xd92e('0x2b')]=_0xa0bc3a[_0xd92e('0x2b')][_0xd92e('0x2e')]?_0xa0bc3a[_0xd92e('0x2b')]:_0x107196[_0xd92e('0x2a')];if(!_0x584244[_0xd92e('0x24')][_0xd92e('0x3d')]('nolimit')){_0xa0bc3a[_0xd92e('0x12')]=qs[_0xd92e('0x12')](_0x584244[_0xd92e('0x24')]['limit']);_0xa0bc3a['offset']=qs['offset'](_0x584244['query']['offset']);}_0xa0bc3a[_0xd92e('0x3e')]=qs[_0xd92e('0x3f')](_0x584244['query'][_0xd92e('0x3f')]);_0xa0bc3a[_0xd92e('0x40')]=qs['filters'](_[_0xd92e('0x41')](_0x584244[_0xd92e('0x24')],_0x107196[_0xd92e('0x29')]));_0xa0bc3a[_0xd92e('0x40')]['OpenchannelInteractionId']=_0x52b9cd['id'];if(_0x584244['query']['filter']){_0xa0bc3a[_0xd92e('0x40')]=_[_0xd92e('0x30')](_0xa0bc3a[_0xd92e('0x40')],{'$or':_[_0xd92e('0x1d')](_0xa0bc3a[_0xd92e('0x2b')],function(_0xb9e20){var _0x2440c8={};_0x2440c8[_0xb9e20]={'$like':'%'+_0x584244[_0xd92e('0x24')][_0xd92e('0x42')]+'%'};return _0x2440c8;})});}if(_0x584244[_0xd92e('0x24')][_0xd92e('0x43')]){var _0x1c1e6d=_0x584244[_0xd92e('0x24')][_0xd92e('0x43')][_0xd92e('0x44')](',');var _0x843b38={};_0x843b38[_0x1c1e6d[0x0]]={'$gte':moment(_0x1c1e6d[0x1])[_0xd92e('0x45')](_0xd92e('0x46'))};_0xa0bc3a[_0xd92e('0x40')]=_[_0xd92e('0x30')](_0xa0bc3a[_0xd92e('0x40')],_0x843b38);}_0xa0bc3a=_['merge']({},_0xa0bc3a,_0x584244[_0xd92e('0x31')]);return db[_0xd92e('0x3c')][_0xd92e('0x14')]({'where':_0xa0bc3a[_0xd92e('0x40')]})[_0xd92e('0x17')](function(_0x538e6c){_0x3e3ec0[_0xd92e('0x14')]=_0x538e6c;if(_0x584244[_0xd92e('0x24')][_0xd92e('0x2f')]){_0xa0bc3a[_0xd92e('0x47')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0xd92e('0x48')](_0xa0bc3a);})[_0xd92e('0x17')](function(_0x3dd77e){_0x3e3ec0[_0xd92e('0x49')]=_0x3dd77e;return _0x3e3ec0;});}})[_0xd92e('0x17')](respondWithFilteredResult(_0x2e223f,_0xa0bc3a))[_0xd92e('0x33')](handleError(_0x2e223f,null));};exports[_0xd92e('0x4a')]=function(_0x222510,_0x5e2094){return db[_0xd92e('0x1e')]['find']({'where':{'id':_0x222510['params']['id']}})[_0xd92e('0x17')](handleEntityNotFound(_0x5e2094,null))['then'](function(_0x14dc9e){if(_0x14dc9e){return _0x14dc9e['setTags'](_0x222510[_0xd92e('0x35')][_0xd92e('0x39')],_[_0xd92e('0x4b')](_0x222510['body'],[_0xd92e('0x39'),'id'])||{})['spread'](function(){return db[_0xd92e('0x4c')][_0xd92e('0x48')]({'attributes':['id','name',_0xd92e('0x4d')],'where':{'id':_0x222510[_0xd92e('0x35')][_0xd92e('0x39')]}});})[_0xd92e('0x17')](function(_0x5340f0){socket[_0xd92e('0x4e')](_0xd92e('0x4f'),{'id':Number(_0x222510[_0xd92e('0x27')]['id']),'tags':_0x5340f0||[]});return{'id':Number(_0x222510[_0xd92e('0x27')]['id']),'tags':_0x5340f0||[]};});}})[_0xd92e('0x17')](respondWithResult(_0x5e2094,null))[_0xd92e('0x33')](handleError(_0x5e2094,null));};exports[_0xd92e('0x50')]=function(_0x4ad788,_0x373f47){return db[_0xd92e('0x1e')][_0xd92e('0x32')]({'where':{'id':_0x4ad788['params']['id']}})[_0xd92e('0x17')](handleEntityNotFound(_0x373f47,null))['then'](function(_0x468ced){if(_0x468ced){return _0x468ced[_0xd92e('0x50')](_0x4ad788['query'][_0xd92e('0x39')]);}})[_0xd92e('0x17')](respondWithStatusCode(_0x373f47,null))[_0xd92e('0x33')](handleError(_0x373f47,null));};exports[_0xd92e('0x51')]=function(_0x2b1b83,_0x1a6e01){var _0x575c7c=moment()[_0xd92e('0x52')]()[_0xd92e('0x53')]();var _0x18a856=path[_0xd92e('0x54')](config[_0xd92e('0x55')],_0xd92e('0x56'),_0xd92e('0x57'),_0xd92e('0x58'));var _0x368ce6=path['join'](config['root'],_0xd92e('0x56'),_0xd92e('0x57'),_0xd92e('0x59'));var _0x53c517=path['join'](_0x18a856,_0x575c7c);var _0x50dfa8=util[_0xd92e('0x45')](_0xd92e('0x5a'),_0x2b1b83[_0xd92e('0x27')]['id'],_0x575c7c);var _0x583c0b=path[_0xd92e('0x54')](_0x18a856,_0x50dfa8);var _0x532be6=[];_0x532be6['push']({'model':db[_0xd92e('0x5b')],'as':_0xd92e('0x5b'),'attributes':['id',_0xd92e('0x5c')],'raw':!![]});_0x532be6[_0xd92e('0x5d')]({'model':db[_0xd92e('0x5e')],'as':_0xd92e('0x5f'),'attributes':['id','firstName',_0xd92e('0x60')],'raw':!![]});if(_0x2b1b83[_0xd92e('0x24')]['attachments']){_0x532be6[_0xd92e('0x5d')]({'model':db[_0xd92e('0x61')],'as':_0xd92e('0x61'),'raw':!![]});}var _0x5b98d0=[{'model':db[_0xd92e('0x3c')],'as':_0xd92e('0x62'),'attributes':['id',_0xd92e('0x35'),_0xd92e('0x63'),_0xd92e('0x64'),_0xd92e('0x65'),_0xd92e('0x66')],'include':_0x532be6}];_0x5b98d0[_0xd92e('0x5d')]({'model':db[_0xd92e('0x67')],'as':_0xd92e('0x68'),'attributes':['id','name']});_0x5b98d0[_0xd92e('0x5d')]({'model':db[_0xd92e('0x5b')],'as':_0xd92e('0x69'),'attributes':['id',_0xd92e('0x5c')]});return db['OpenchannelInteraction'][_0xd92e('0x32')]({'where':{'id':_0x2b1b83[_0xd92e('0x27')]['id']},'include':_0x5b98d0})['then'](handleEntityNotFound(_0x1a6e01,null))[_0xd92e('0x17')](function(_0x31b8cc){if(_0x31b8cc){var _0x228ccb=_0x31b8cc[_0xd92e('0x6a')]({'plain':!![]});fs['mkdirSync'](_0x53c517);var _0x10c702={'channel':_0xd92e('0x6b'),'account':_0x228ccb[_0xd92e('0x68')]['name'],'agent':_0x228ccb[_0xd92e('0x69')]?_0x228ccb['Owner']['fullname']:'N.A.','createdAt':moment(_0x228ccb['createdAt'])['format'](_0xd92e('0x46'))[_0xd92e('0x53')](),'closedAt':_0x228ccb[_0xd92e('0x6c')]?moment(_0x228ccb[_0xd92e('0x6d')])[_0xd92e('0x45')](_0xd92e('0x46'))[_0xd92e('0x53')]():'','disposition':_0x228ccb[_0xd92e('0x6e')],'visibility':_0x228ccb[_0xd92e('0x6f')]?_0xd92e('0x70'):'Private','messages':_(_0x228ccb[_0xd92e('0x62')])[_0xd92e('0x42')]({'secret':![]})[_0xd92e('0x1d')](function(_0x236439){if(_0x236439[_0xd92e('0x61')]){var _0xf2a0f1=path[_0xd92e('0x54')](_0x368ce6,_0x236439[_0xd92e('0x61')][_0xd92e('0x71')]);if(fs[_0xd92e('0x72')](_0xf2a0f1)){fs[_0xd92e('0x73')](_0xf2a0f1)[_0xd92e('0x74')](fs[_0xd92e('0x75')](path[_0xd92e('0x54')](_0x53c517,_0x236439[_0xd92e('0x61')]['basename'])));}}return{'date':moment(_0x236439['createdAt'])[_0xd92e('0x45')](_0xd92e('0x46'))['toString'](),'sender':_0x236439['direction']==='out'?_0x236439[_0xd92e('0x5b')]?_0x236439[_0xd92e('0x5b')][_0xd92e('0x5c')]:_0xd92e('0x76'):_0x236439[_0xd92e('0x5f')][_0xd92e('0x77')]+(_0x236439['Contact'][_0xd92e('0x60')]?'\x20'+_0x236439[_0xd92e('0x5f')][_0xd92e('0x60')]:''),'body':_0x236439['Attachment']?_0x236439[_0xd92e('0x61')][_0xd92e('0x71')]:_0x236439['body'],'direction':_0x236439[_0xd92e('0x64')]==='out'?'A':'C','secret':_0x236439['secret'],'read':_0x236439[_0xd92e('0x66')],'attachment':_0x236439[_0xd92e('0x61')]};})[_0xd92e('0x78')]()};return ejs[_0xd92e('0x79')](path[_0xd92e('0x54')](config['root'],_0xd92e('0x56'),'views',_0xd92e('0x7a')),{'interaction':_0x10c702})[_0xd92e('0x17')](function(_0x46af5f){var _0x38e1bd=path[_0xd92e('0x54')](_0x53c517,_0xd92e('0x7b')+_0x228ccb['id']+'-'+_0x575c7c+'.pdf');var _0x353d32={'path':_0x38e1bd,'channel':_0xd92e('0x6b'),'interactionId':_0x228ccb['id']};return pdf['createPdfFromHTML'](_0x46af5f,_0x353d32);})[_0xd92e('0x17')](function(){return new Promise(function(_0x1480a0,_0x59ec27){zipdir(_0x53c517,{'saveTo':_0x583c0b},function(_0x177a96,_0x42e13b){if(_0x177a96)return _0x59ec27(_0x177a96);return _0x1480a0(_0x42e13b);});})[_0xd92e('0x17')](function(){return new Promise(function(_0x3f89e7,_0x1000ef){rimraf(_0x53c517,function(_0x140c83){if(_0x140c83)_0x1000ef(_0x140c83);return _0x3f89e7();});});})['then'](function(){return _0x1a6e01[_0xd92e('0x51')](_0x583c0b,_0x50dfa8,function(_0x5f4fa5){if(_0x5f4fa5){logger[_0xd92e('0x19')](_0xd92e('0x7c'),_0x5f4fa5);}else{fs[_0xd92e('0x7d')](_0x583c0b);}});});});}else{return _0x1a6e01[_0xd92e('0xf')](0xc8);}})[_0xd92e('0x33')](handleError(_0x1a6e01,null));};
\ No newline at end of file
+var _0x131d=['create','body','describe','addMessage','OpenchannelMessage','ids','omit','findOne','nolimit','order','sort','where','OpenchannelInteractionId','merge','map','filter','$gte','split','format','findAll','rows','addTags','spread','emit','openchannelInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','tmp','attachments','transcript-%d-%s.zip','push','User','CmContact','Contact','firstName','Attachment','Messages','read','OpenchannelAccount','Owner','fullname','get','Openchannel','Account','N.A.','createdAt','YYYY-MM-DD\x20HH:mm:ss','disposition','threadId','Public','basename','existsSync','pipe','createWriteStream','direction','out','lastName','secret','value','renderFile','views','downloadInteraction.ejs','transcript-','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','moment','path','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','localhost','./openchannelInteraction.socket','register','sendStatus','end','offset','undefined','limit','count','set','json','update','then','destroy','status','error','stack','name','send','OpenchannelInteraction','rawAttributes','fieldName','getOptions','catch','query','type','from','params','model','keys','filters','intersection','attributes','fields','length','includeAll','include','options','find'];(function(_0x5f09c5,_0x2bfca0){var _0x426ad9=function(_0x18fe5f){while(--_0x18fe5f){_0x5f09c5['push'](_0x5f09c5['shift']());}};_0x426ad9(++_0x2bfca0);}(_0x131d,0x1bb));var _0xd131=function(_0x30a931,_0x440026){_0x30a931=_0x30a931-0x0;var _0x5b7ab1=_0x131d[_0x30a931];return _0x5b7ab1;};'use strict';var rimraf=require(_0xd131('0x0'));var zipdir=require(_0xd131('0x1'));var moment=require(_0xd131('0x2'));var util=require('util');var path=require(_0xd131('0x3'));var ejs=require(_0xd131('0x4'));var fs=require('fs');var _=require(_0xd131('0x5'));var Redis=require('ioredis');var interaction=require(_0xd131('0x6'));var qs=require(_0xd131('0x7'));var pdf=require(_0xd131('0x8'));var logger=require(_0xd131('0x9'))('api');var config=require(_0xd131('0xa'));var db=require(_0xd131('0xb'))['db'];config[_0xd131('0xc')]=_[_0xd131('0xd')](config['redis'],{'host':_0xd131('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd131('0xc')]));require(_0xd131('0xf'))[_0xd131('0x10')](socket);function respondWithStatusCode(_0x3a65b2,_0x4df969){_0x4df969=_0x4df969||0xcc;return function(_0x450c71){if(_0x450c71){return _0x3a65b2[_0xd131('0x11')](_0x4df969);}return _0x3a65b2['status'](_0x4df969)[_0xd131('0x12')]();};}function respondWithResult(_0x5ebf0d,_0x5e6c99){_0x5e6c99=_0x5e6c99||0xc8;return function(_0x22c16d){if(_0x22c16d){return _0x5ebf0d['status'](_0x5e6c99)['json'](_0x22c16d);}};}function respondWithFilteredResult(_0x598205,_0x13dbf0){return function(_0x3bf713){if(_0x3bf713){var _0x332f4a=typeof _0x13dbf0[_0xd131('0x13')]===_0xd131('0x14')&&typeof _0x13dbf0[_0xd131('0x15')]===_0xd131('0x14');var _0xd88b2a=_0x3bf713[_0xd131('0x16')];var _0x38bb78=_0x332f4a?0x0:_0x13dbf0[_0xd131('0x13')];var _0x5a6b9f=_0x332f4a?_0x3bf713['count']:_0x13dbf0[_0xd131('0x13')]+_0x13dbf0['limit'];var _0x35151c;if(_0x5a6b9f>=_0xd88b2a){_0x5a6b9f=_0xd88b2a;_0x35151c=0xc8;}else{_0x35151c=0xce;}_0x598205['status'](_0x35151c);return _0x598205[_0xd131('0x17')]('Content-Range',_0x38bb78+'-'+_0x5a6b9f+'/'+_0xd88b2a)[_0xd131('0x18')](_0x3bf713);}return null;};}function saveUpdates(_0x123d8d){return function(_0x5b14d5){if(_0x5b14d5){return _0x5b14d5[_0xd131('0x19')](_0x123d8d)[_0xd131('0x1a')](function(_0x5b3df0){return _0x5b3df0;});}return null;};}function removeEntity(_0x492c63){return function(_0x3994a5){if(_0x3994a5){return _0x3994a5[_0xd131('0x1b')]()[_0xd131('0x1a')](function(){_0x492c63[_0xd131('0x1c')](0xcc)[_0xd131('0x12')]();});}};}function handleEntityNotFound(_0x3b6663){return function(_0x198818){if(!_0x198818){_0x3b6663['sendStatus'](0x194);}return _0x198818;};}function handleError(_0x1ca180,_0x275ec5){_0x275ec5=_0x275ec5||0x1f4;return function(_0x3914dc){logger[_0xd131('0x1d')](_0x3914dc[_0xd131('0x1e')]);if(_0x3914dc[_0xd131('0x1f')]){delete _0x3914dc[_0xd131('0x1f')];}_0x1ca180[_0xd131('0x1c')](_0x275ec5)[_0xd131('0x20')](_0x3914dc);};}exports['index']=function(_0x2a3bef,_0x51b9ed){var _0x390124={};var _0x414e85=_['map'](db[_0xd131('0x21')][_0xd131('0x22')],function(_0x1eb6df){return{'name':_0x1eb6df[_0xd131('0x23')],'type':_0x1eb6df['type']['key']};});_0x390124=qs[_0xd131('0x24')](_0x414e85,_0x2a3bef);return interaction['findAll']('openchannel',_0x2a3bef['query'],_0x2a3bef['user'],_0x390124,_0x414e85)[_0xd131('0x1a')](respondWithFilteredResult(_0x51b9ed,_0x390124))[_0xd131('0x25')](handleError(_0x51b9ed,null));};exports['show']=function(_0x46a3e3,_0x60e287){var _0x2a986e={};if(_0x46a3e3[_0xd131('0x26')][_0xd131('0x27')]&&_0x46a3e3[_0xd131('0x26')][_0xd131('0x27')]===_0xd131('0x28')){_0x2a986e['from']=_0x46a3e3[_0xd131('0x29')]['id'];}else{_0x2a986e['id']=_0x46a3e3['params']['id'];}var _0x4c16b3={'raw':![],'where':_0x2a986e},_0x454025={};_0x454025[_0xd131('0x2a')]=_[_0xd131('0x2b')](db[_0xd131('0x21')][_0xd131('0x22')]);_0x454025[_0xd131('0x26')]=_[_0xd131('0x2b')](_0x46a3e3['query']);_0x454025[_0xd131('0x2c')]=_[_0xd131('0x2d')](_0x454025[_0xd131('0x2a')],_0x454025[_0xd131('0x26')]);_0x4c16b3[_0xd131('0x2e')]=_['intersection'](_0x454025['model'],qs[_0xd131('0x2f')](_0x46a3e3[_0xd131('0x26')]['fields']));_0x4c16b3[_0xd131('0x2e')]=_0x4c16b3[_0xd131('0x2e')][_0xd131('0x30')]?_0x4c16b3[_0xd131('0x2e')]:_0x454025['model'];if(_0x46a3e3[_0xd131('0x26')][_0xd131('0x31')]){_0x4c16b3[_0xd131('0x32')]=[{'all':!![]}];}_0x4c16b3=_['merge']({},_0x4c16b3,_0x46a3e3[_0xd131('0x33')]);return db[_0xd131('0x21')][_0xd131('0x34')](_0x4c16b3)['then'](handleEntityNotFound(_0x60e287,null))[_0xd131('0x1a')](respondWithResult(_0x60e287,null))['catch'](handleError(_0x60e287,null));};exports[_0xd131('0x35')]=function(_0x3032b7,_0x4aed13){return db[_0xd131('0x21')][_0xd131('0x35')](_0x3032b7[_0xd131('0x36')],{})[_0xd131('0x1a')](respondWithResult(_0x4aed13,0xc9))[_0xd131('0x25')](handleError(_0x4aed13,null));};exports[_0xd131('0x19')]=function(_0x48839c,_0x15accc){if(_0x48839c['body']['id']){delete _0x48839c[_0xd131('0x36')]['id'];}return db[_0xd131('0x21')][_0xd131('0x34')]({'where':{'id':_0x48839c[_0xd131('0x29')]['id']}})['then'](handleEntityNotFound(_0x15accc,null))['then'](saveUpdates(_0x48839c[_0xd131('0x36')],null))['then'](respondWithResult(_0x15accc,null))[_0xd131('0x25')](handleError(_0x15accc,null));};exports[_0xd131('0x1b')]=function(_0x2d495e,_0x1f1905){return db[_0xd131('0x21')][_0xd131('0x34')]({'where':{'id':_0x2d495e[_0xd131('0x29')]['id']}})[_0xd131('0x1a')](handleEntityNotFound(_0x1f1905,null))[_0xd131('0x1a')](removeEntity(_0x1f1905,null))[_0xd131('0x25')](handleError(_0x1f1905,null));};exports[_0xd131('0x37')]=function(_0x371de1,_0x2d2c94){return db['OpenchannelInteraction'][_0xd131('0x37')]()[_0xd131('0x1a')](respondWithResult(_0x2d2c94,null))[_0xd131('0x25')](handleError(_0x2d2c94,null));};exports[_0xd131('0x38')]=function(_0x2e1e59,_0x43f6bb){return db[_0xd131('0x39')]['find']({'where':{'id':_0x2e1e59[_0xd131('0x29')]['id']}})['then'](handleEntityNotFound(_0x43f6bb,null))[_0xd131('0x1a')](function(_0x394c4a){if(_0x394c4a){return _0x394c4a[_0xd131('0x38')](_0x2e1e59[_0xd131('0x36')][_0xd131('0x3a')],_[_0xd131('0x3b')](_0x2e1e59[_0xd131('0x36')],[_0xd131('0x3a'),'id'])||{});}})[_0xd131('0x1a')](respondWithResult(_0x43f6bb,null))['catch'](handleError(_0x43f6bb,null));};exports['getMessages']=function(_0x138716,_0x42f0ad){var _0x7eaa94={'raw':![],'where':{}};var _0x435c2c={};var _0x516ca7={'count':0x0,'rows':[]};return db[_0xd131('0x21')][_0xd131('0x3c')]({'where':{'id':_0x138716[_0xd131('0x29')]['id']}})['then'](handleEntityNotFound(_0x42f0ad,null))[_0xd131('0x1a')](function(_0x5c07bf){if(_0x5c07bf){_0x435c2c[_0xd131('0x2a')]=_['keys'](db[_0xd131('0x39')][_0xd131('0x22')]);_0x435c2c[_0xd131('0x26')]=_[_0xd131('0x2b')](_0x138716[_0xd131('0x26')]);_0x435c2c[_0xd131('0x2c')]=_[_0xd131('0x2d')](_0x435c2c[_0xd131('0x2a')],_0x435c2c[_0xd131('0x26')]);_0x7eaa94[_0xd131('0x2e')]=_[_0xd131('0x2d')](_0x435c2c[_0xd131('0x2a')],qs['fields'](_0x138716[_0xd131('0x26')][_0xd131('0x2f')]));_0x7eaa94['attributes']=_0x7eaa94[_0xd131('0x2e')]['length']?_0x7eaa94[_0xd131('0x2e')]:_0x435c2c[_0xd131('0x2a')];if(!_0x138716[_0xd131('0x26')]['hasOwnProperty'](_0xd131('0x3d'))){_0x7eaa94['limit']=qs[_0xd131('0x15')](_0x138716['query'][_0xd131('0x15')]);_0x7eaa94['offset']=qs['offset'](_0x138716[_0xd131('0x26')]['offset']);}_0x7eaa94[_0xd131('0x3e')]=qs[_0xd131('0x3f')](_0x138716[_0xd131('0x26')]['sort']);_0x7eaa94[_0xd131('0x40')]=qs[_0xd131('0x2c')](_['pick'](_0x138716[_0xd131('0x26')],_0x435c2c[_0xd131('0x2c')]));_0x7eaa94[_0xd131('0x40')][_0xd131('0x41')]=_0x5c07bf['id'];if(_0x138716['query']['filter']){_0x7eaa94[_0xd131('0x40')]=_[_0xd131('0x42')](_0x7eaa94[_0xd131('0x40')],{'$or':_[_0xd131('0x43')](_0x7eaa94[_0xd131('0x2e')],function(_0x374ef8){var _0xa06027={};_0xa06027[_0x374ef8]={'$like':'%'+_0x138716['query'][_0xd131('0x44')]+'%'};return _0xa06027;})});}if(_0x138716['query'][_0xd131('0x45')]){var _0x3cffa3=_0x138716[_0xd131('0x26')][_0xd131('0x45')][_0xd131('0x46')](',');var _0x233413={};_0x233413[_0x3cffa3[0x0]]={'$gte':moment(_0x3cffa3[0x1])[_0xd131('0x47')]('YYYY-MM-DD\x20HH:mm:ss')};_0x7eaa94[_0xd131('0x40')]=_['merge'](_0x7eaa94[_0xd131('0x40')],_0x233413);}_0x7eaa94=_[_0xd131('0x42')]({},_0x7eaa94,_0x138716[_0xd131('0x33')]);return db['OpenchannelMessage'][_0xd131('0x16')]({'where':_0x7eaa94[_0xd131('0x40')]})[_0xd131('0x1a')](function(_0xfad45d){_0x516ca7[_0xd131('0x16')]=_0xfad45d;if(_0x138716[_0xd131('0x26')][_0xd131('0x31')]){_0x7eaa94[_0xd131('0x32')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0xd131('0x48')](_0x7eaa94);})[_0xd131('0x1a')](function(_0x36393d){_0x516ca7[_0xd131('0x49')]=_0x36393d;return _0x516ca7;});}})[_0xd131('0x1a')](respondWithFilteredResult(_0x42f0ad,_0x7eaa94))[_0xd131('0x25')](handleError(_0x42f0ad,null));};exports[_0xd131('0x4a')]=function(_0x5a82a4,_0x3b2199){return db[_0xd131('0x21')][_0xd131('0x34')]({'where':{'id':_0x5a82a4[_0xd131('0x29')]['id']}})[_0xd131('0x1a')](handleEntityNotFound(_0x3b2199,null))[_0xd131('0x1a')](function(_0x1f1b39){if(_0x1f1b39){return _0x1f1b39['setTags'](_0x5a82a4[_0xd131('0x36')]['ids'],_[_0xd131('0x3b')](_0x5a82a4['body'],[_0xd131('0x3a'),'id'])||{})[_0xd131('0x4b')](function(){return db['Tag'][_0xd131('0x48')]({'attributes':['id','name','color'],'where':{'id':_0x5a82a4[_0xd131('0x36')][_0xd131('0x3a')]}});})[_0xd131('0x1a')](function(_0x59e5b2){socket[_0xd131('0x4c')](_0xd131('0x4d'),{'id':Number(_0x5a82a4[_0xd131('0x29')]['id']),'tags':_0x59e5b2||[]});return{'id':Number(_0x5a82a4[_0xd131('0x29')]['id']),'tags':_0x59e5b2||[]};});}})['then'](respondWithResult(_0x3b2199,null))[_0xd131('0x25')](handleError(_0x3b2199,null));};exports[_0xd131('0x4e')]=function(_0x209e33,_0x5f46c2){return db[_0xd131('0x21')][_0xd131('0x34')]({'where':{'id':_0x209e33[_0xd131('0x29')]['id']}})[_0xd131('0x1a')](handleEntityNotFound(_0x5f46c2,null))[_0xd131('0x1a')](function(_0x4d5fe8){if(_0x4d5fe8){return _0x4d5fe8[_0xd131('0x4e')](_0x209e33['query'][_0xd131('0x3a')]);}})['then'](respondWithStatusCode(_0x5f46c2,null))['catch'](handleError(_0x5f46c2,null));};exports[_0xd131('0x4f')]=function(_0x437d43,_0x5d6774){var _0x213aa2=moment()[_0xd131('0x50')]()[_0xd131('0x51')]();var _0x194809=path[_0xd131('0x52')](config[_0xd131('0x53')],_0xd131('0x54'),_0xd131('0x55'),_0xd131('0x56'));var _0xdc7009=path[_0xd131('0x52')](config[_0xd131('0x53')],_0xd131('0x54'),_0xd131('0x55'),_0xd131('0x57'));var _0x31e6d1=path[_0xd131('0x52')](_0x194809,_0x213aa2);var _0x14353c=util['format'](_0xd131('0x58'),_0x437d43[_0xd131('0x29')]['id'],_0x213aa2);var _0x4354c9=path['join'](_0x194809,_0x14353c);var _0x27cbcc=[];_0x27cbcc[_0xd131('0x59')]({'model':db[_0xd131('0x5a')],'as':_0xd131('0x5a'),'attributes':['id','fullname'],'raw':!![]});_0x27cbcc[_0xd131('0x59')]({'model':db[_0xd131('0x5b')],'as':_0xd131('0x5c'),'attributes':['id',_0xd131('0x5d'),'lastName'],'raw':!![]});if(_0x437d43[_0xd131('0x26')][_0xd131('0x57')]){_0x27cbcc['push']({'model':db[_0xd131('0x5e')],'as':'Attachment','raw':!![]});}var _0xb09ed7=[{'model':db[_0xd131('0x39')],'as':_0xd131('0x5f'),'attributes':['id',_0xd131('0x36'),'createdAt','direction','secret',_0xd131('0x60')],'include':_0x27cbcc}];_0xb09ed7[_0xd131('0x59')]({'model':db[_0xd131('0x61')],'as':'Account','attributes':['id',_0xd131('0x1f')]});_0xb09ed7['push']({'model':db[_0xd131('0x5a')],'as':_0xd131('0x62'),'attributes':['id',_0xd131('0x63')]});return db[_0xd131('0x21')][_0xd131('0x34')]({'where':{'id':_0x437d43['params']['id']},'include':_0xb09ed7})[_0xd131('0x1a')](handleEntityNotFound(_0x5d6774,null))[_0xd131('0x1a')](function(_0x255125){if(_0x255125){var _0x1a656e=_0x255125[_0xd131('0x64')]({'plain':!![]});fs['mkdirSync'](_0x31e6d1);var _0x800225={'channel':_0xd131('0x65'),'account':_0x1a656e[_0xd131('0x66')][_0xd131('0x1f')],'agent':_0x1a656e[_0xd131('0x62')]?_0x1a656e[_0xd131('0x62')][_0xd131('0x63')]:_0xd131('0x67'),'createdAt':moment(_0x1a656e[_0xd131('0x68')])[_0xd131('0x47')]('YYYY-MM-DD\x20HH:mm:ss')[_0xd131('0x51')](),'closedAt':_0x1a656e['closed']?moment(_0x1a656e['closedAt'])[_0xd131('0x47')](_0xd131('0x69'))['toString']():'','disposition':_0x1a656e[_0xd131('0x6a')],'visibility':_0x1a656e[_0xd131('0x6b')]?_0xd131('0x6c'):'Private','messages':_(_0x1a656e[_0xd131('0x5f')])[_0xd131('0x44')]({'secret':![]})[_0xd131('0x43')](function(_0x11eab3){if(_0x11eab3['Attachment']){var _0x5d7287=path[_0xd131('0x52')](_0xdc7009,_0x11eab3[_0xd131('0x5e')][_0xd131('0x6d')]);if(fs[_0xd131('0x6e')](_0x5d7287)){fs['createReadStream'](_0x5d7287)[_0xd131('0x6f')](fs[_0xd131('0x70')](path[_0xd131('0x52')](_0x31e6d1,_0x11eab3[_0xd131('0x5e')][_0xd131('0x6d')])));}}return{'date':moment(_0x11eab3['createdAt'])['format']('YYYY-MM-DD\x20HH:mm:ss')[_0xd131('0x51')](),'sender':_0x11eab3[_0xd131('0x71')]===_0xd131('0x72')?_0x11eab3['User']?_0x11eab3[_0xd131('0x5a')][_0xd131('0x63')]:'System':_0x11eab3[_0xd131('0x5c')][_0xd131('0x5d')]+(_0x11eab3[_0xd131('0x5c')]['lastName']?'\x20'+_0x11eab3['Contact'][_0xd131('0x73')]:''),'body':_0x11eab3['Attachment']?_0x11eab3[_0xd131('0x5e')][_0xd131('0x6d')]:_0x11eab3[_0xd131('0x36')],'direction':_0x11eab3[_0xd131('0x71')]==='out'?'A':'C','secret':_0x11eab3[_0xd131('0x74')],'read':_0x11eab3[_0xd131('0x60')],'attachment':_0x11eab3[_0xd131('0x5e')]};})[_0xd131('0x75')]()};return ejs[_0xd131('0x76')](path[_0xd131('0x52')](config[_0xd131('0x53')],_0xd131('0x54'),_0xd131('0x77'),_0xd131('0x78')),{'interaction':_0x800225})['then'](function(_0x8cd253){var _0x583434=path[_0xd131('0x52')](_0x31e6d1,_0xd131('0x79')+_0x1a656e['id']+'-'+_0x213aa2+'.pdf');var _0x553eb2={'path':_0x583434,'channel':'Openchannel','interactionId':_0x1a656e['id']};return pdf['createPdfFromHTML'](_0x8cd253,_0x553eb2);})[_0xd131('0x1a')](function(){return new Promise(function(_0x27aad0,_0x1958b8){zipdir(_0x31e6d1,{'saveTo':_0x4354c9},function(_0x4409f3,_0x18b4f5){if(_0x4409f3)return _0x1958b8(_0x4409f3);return _0x27aad0(_0x18b4f5);});})[_0xd131('0x1a')](function(){return new Promise(function(_0x2ff22d,_0x38ac91){rimraf(_0x31e6d1,function(_0x378d46){if(_0x378d46)_0x38ac91(_0x378d46);return _0x2ff22d();});});})[_0xd131('0x1a')](function(){return _0x5d6774[_0xd131('0x4f')](_0x4354c9,_0x14353c,function(_0x1a3caf){if(_0x1a3caf){logger[_0xd131('0x1d')](_0xd131('0x7a'),_0x1a3caf);}else{fs[_0xd131('0x7b')](_0x4354c9);}});});});}else{return _0x5d6774['sendStatus'](0xc8);}})[_0xd131('0x25')](handleError(_0x5d6774,null));};
\ No newline at end of file