Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index f80ac07..9bd9104 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 _0x74dd=['json','update','destroy','then','sendStatus','error','name','send','index','map','OpenchannelInteraction','rawAttributes','type','key','getOptions','openchannel','user','show','from','params','model','keys','query','intersection','attributes','fields','length','includeAll','include','merge','options','find','catch','create','body','describe','OpenchannelMessage','ids','getMessages','findOne','filters','nolimit','sort','where','pick','OpenchannelInteractionId','split','format','findAll','rows','addTags','setTags','omit','spread','Tag','color','openchannelInteractionTags:save','removeTags','download','unix','join','files','server','attachments','User','fullname','push','CmContact','Contact','firstName','lastName','Attachment','Messages','createdAt','direction','secret','OpenchannelAccount','Owner','get','mkdirSync','Openchannel','Account','N.A.','YYYY-MM-DD\x20HH:mm:ss','toString','closed','disposition','Public','Private','filter','basename','existsSync','createReadStream','pipe','createWriteStream','out','System','read','value','root','downloadInteraction.ejs','.pdf','createPdfFromHTML','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','moment','util','path','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','status','end','offset','limit','count','Content-Range'];(function(_0x1eca92,_0x1b4071){var _0x2707d9=function(_0x4ce102){while(--_0x4ce102){_0x1eca92['push'](_0x1eca92['shift']());}};_0x2707d9(++_0x1b4071);}(_0x74dd,0x69));var _0xd74d=function(_0x23d0a1,_0x5011a){_0x23d0a1=_0x23d0a1-0x0;var _0x1ef866=_0x74dd[_0x23d0a1];return _0x1ef866;};'use strict';var rimraf=require(_0xd74d('0x0'));var zipdir=require(_0xd74d('0x1'));var moment=require(_0xd74d('0x2'));var util=require(_0xd74d('0x3'));var path=require(_0xd74d('0x4'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var Redis=require(_0xd74d('0x5'));var interaction=require(_0xd74d('0x6'));var qs=require(_0xd74d('0x7'));var pdf=require(_0xd74d('0x8'));var logger=require('../../config/logger')(_0xd74d('0x9'));var config=require(_0xd74d('0xa'));var db=require(_0xd74d('0xb'))['db'];config[_0xd74d('0xc')]=_[_0xd74d('0xd')](config['redis'],{'host':_0xd74d('0xe'),'port':0x18eb});var socket=require(_0xd74d('0xf'))(new Redis(config[_0xd74d('0xc')]));require('./openchannelInteraction.socket')[_0xd74d('0x10')](socket);function respondWithStatusCode(_0x5e0ec1,_0x1aca47){_0x1aca47=_0x1aca47||0xcc;return function(_0x569309){if(_0x569309){return _0x5e0ec1['sendStatus'](_0x1aca47);}return _0x5e0ec1[_0xd74d('0x11')](_0x1aca47)[_0xd74d('0x12')]();};}function respondWithResult(_0x48c801,_0x4f9450){_0x4f9450=_0x4f9450||0xc8;return function(_0x21db7e){if(_0x21db7e){return _0x48c801[_0xd74d('0x11')](_0x4f9450)['json'](_0x21db7e);}};}function respondWithFilteredResult(_0x2e4856,_0xbd5cfb){return function(_0x3c9c9b){if(_0x3c9c9b){var _0x5a9aa8=typeof _0xbd5cfb[_0xd74d('0x13')]==='undefined'&&typeof _0xbd5cfb[_0xd74d('0x14')]==='undefined';var _0x4166ad=_0x3c9c9b[_0xd74d('0x15')];var _0x1c81c4=_0x5a9aa8?0x0:_0xbd5cfb[_0xd74d('0x13')];var _0x5e2457=_0x5a9aa8?_0x3c9c9b[_0xd74d('0x15')]:_0xbd5cfb[_0xd74d('0x13')]+_0xbd5cfb[_0xd74d('0x14')];var _0x4538b7;if(_0x5e2457>=_0x4166ad){_0x5e2457=_0x4166ad;_0x4538b7=0xc8;}else{_0x4538b7=0xce;}_0x2e4856[_0xd74d('0x11')](_0x4538b7);return _0x2e4856['set'](_0xd74d('0x16'),_0x1c81c4+'-'+_0x5e2457+'/'+_0x4166ad)[_0xd74d('0x17')](_0x3c9c9b);}return null;};}function saveUpdates(_0x4580a0){return function(_0x6b13a0){if(_0x6b13a0){return _0x6b13a0[_0xd74d('0x18')](_0x4580a0)['then'](function(_0x400e15){return _0x400e15;});}return null;};}function removeEntity(_0x20583b){return function(_0x558bf2){if(_0x558bf2){return _0x558bf2[_0xd74d('0x19')]()[_0xd74d('0x1a')](function(){_0x20583b[_0xd74d('0x11')](0xcc)[_0xd74d('0x12')]();});}};}function handleEntityNotFound(_0x42e488){return function(_0x381691){if(!_0x381691){_0x42e488[_0xd74d('0x1b')](0x194);}return _0x381691;};}function handleError(_0x4e55d2,_0x1bd0b0){_0x1bd0b0=_0x1bd0b0||0x1f4;return function(_0x1bf1a7){logger[_0xd74d('0x1c')](_0x1bf1a7['stack']);if(_0x1bf1a7['name']){delete _0x1bf1a7[_0xd74d('0x1d')];}_0x4e55d2['status'](_0x1bd0b0)[_0xd74d('0x1e')](_0x1bf1a7);};}exports[_0xd74d('0x1f')]=function(_0x25e5b7,_0x3a9d91){var _0x13485c={};var _0x30bd61=_[_0xd74d('0x20')](db[_0xd74d('0x21')][_0xd74d('0x22')],function(_0x4b9bf1){return{'name':_0x4b9bf1['fieldName'],'type':_0x4b9bf1[_0xd74d('0x23')][_0xd74d('0x24')]};});_0x13485c=qs[_0xd74d('0x25')](_0x30bd61,_0x25e5b7);return interaction['findAll'](_0xd74d('0x26'),_0x25e5b7['query'],_0x25e5b7[_0xd74d('0x27')],_0x13485c,_0x30bd61)['then'](respondWithFilteredResult(_0x3a9d91,_0x13485c))['catch'](handleError(_0x3a9d91,null));};exports[_0xd74d('0x28')]=function(_0x21602e,_0x5d9eee){var _0x43cae4={};if(_0x21602e['query'][_0xd74d('0x23')]&&_0x21602e['query'][_0xd74d('0x23')]==='from'){_0x43cae4[_0xd74d('0x29')]=_0x21602e[_0xd74d('0x2a')]['id'];}else{_0x43cae4['id']=_0x21602e[_0xd74d('0x2a')]['id'];}var _0x10a2ba={'raw':![],'where':_0x43cae4},_0x4945d0={};_0x4945d0[_0xd74d('0x2b')]=_[_0xd74d('0x2c')](db['OpenchannelInteraction'][_0xd74d('0x22')]);_0x4945d0[_0xd74d('0x2d')]=_[_0xd74d('0x2c')](_0x21602e['query']);_0x4945d0['filters']=_[_0xd74d('0x2e')](_0x4945d0[_0xd74d('0x2b')],_0x4945d0[_0xd74d('0x2d')]);_0x10a2ba[_0xd74d('0x2f')]=_['intersection'](_0x4945d0[_0xd74d('0x2b')],qs[_0xd74d('0x30')](_0x21602e[_0xd74d('0x2d')]['fields']));_0x10a2ba[_0xd74d('0x2f')]=_0x10a2ba[_0xd74d('0x2f')][_0xd74d('0x31')]?_0x10a2ba[_0xd74d('0x2f')]:_0x4945d0[_0xd74d('0x2b')];if(_0x21602e[_0xd74d('0x2d')][_0xd74d('0x32')]){_0x10a2ba[_0xd74d('0x33')]=[{'all':!![]}];}_0x10a2ba=_[_0xd74d('0x34')]({},_0x10a2ba,_0x21602e[_0xd74d('0x35')]);return db[_0xd74d('0x21')][_0xd74d('0x36')](_0x10a2ba)['then'](handleEntityNotFound(_0x5d9eee,null))['then'](respondWithResult(_0x5d9eee,null))[_0xd74d('0x37')](handleError(_0x5d9eee,null));};exports[_0xd74d('0x38')]=function(_0x122d84,_0x575dab){return db['OpenchannelInteraction'][_0xd74d('0x38')](_0x122d84[_0xd74d('0x39')],{})[_0xd74d('0x1a')](respondWithResult(_0x575dab,0xc9))[_0xd74d('0x37')](handleError(_0x575dab,null));};exports[_0xd74d('0x18')]=function(_0x446f63,_0x1a9500){if(_0x446f63[_0xd74d('0x39')]['id']){delete _0x446f63[_0xd74d('0x39')]['id'];}return db[_0xd74d('0x21')][_0xd74d('0x36')]({'where':{'id':_0x446f63[_0xd74d('0x2a')]['id']}})['then'](handleEntityNotFound(_0x1a9500,null))[_0xd74d('0x1a')](saveUpdates(_0x446f63[_0xd74d('0x39')],null))[_0xd74d('0x1a')](respondWithResult(_0x1a9500,null))['catch'](handleError(_0x1a9500,null));};exports['destroy']=function(_0x4b469a,_0x51830c){return db[_0xd74d('0x21')][_0xd74d('0x36')]({'where':{'id':_0x4b469a[_0xd74d('0x2a')]['id']}})[_0xd74d('0x1a')](handleEntityNotFound(_0x51830c,null))[_0xd74d('0x1a')](removeEntity(_0x51830c,null))['catch'](handleError(_0x51830c,null));};exports[_0xd74d('0x3a')]=function(_0x4d4405,_0x5ef6cb){return db[_0xd74d('0x21')][_0xd74d('0x3a')]()[_0xd74d('0x1a')](respondWithResult(_0x5ef6cb,null))['catch'](handleError(_0x5ef6cb,null));};exports['addMessage']=function(_0xdfa3b3,_0x46cf3d){return db[_0xd74d('0x3b')]['find']({'where':{'id':_0xdfa3b3[_0xd74d('0x2a')]['id']}})[_0xd74d('0x1a')](handleEntityNotFound(_0x46cf3d,null))[_0xd74d('0x1a')](function(_0x3bac89){if(_0x3bac89){return _0x3bac89['addMessage'](_0xdfa3b3['body'][_0xd74d('0x3c')],_['omit'](_0xdfa3b3[_0xd74d('0x39')],[_0xd74d('0x3c'),'id'])||{});}})[_0xd74d('0x1a')](respondWithResult(_0x46cf3d,null))['catch'](handleError(_0x46cf3d,null));};exports[_0xd74d('0x3d')]=function(_0x45681c,_0x1139df){var _0xe87d04={'raw':![],'where':{}};var _0x1189bc={};var _0xd8c413={'count':0x0,'rows':[]};return db[_0xd74d('0x21')][_0xd74d('0x3e')]({'where':{'id':_0x45681c[_0xd74d('0x2a')]['id']}})['then'](handleEntityNotFound(_0x1139df,null))[_0xd74d('0x1a')](function(_0x25c1fd){if(_0x25c1fd){_0x1189bc['model']=_[_0xd74d('0x2c')](db[_0xd74d('0x3b')][_0xd74d('0x22')]);_0x1189bc[_0xd74d('0x2d')]=_[_0xd74d('0x2c')](_0x45681c[_0xd74d('0x2d')]);_0x1189bc[_0xd74d('0x3f')]=_['intersection'](_0x1189bc[_0xd74d('0x2b')],_0x1189bc[_0xd74d('0x2d')]);_0xe87d04['attributes']=_[_0xd74d('0x2e')](_0x1189bc['model'],qs[_0xd74d('0x30')](_0x45681c['query'][_0xd74d('0x30')]));_0xe87d04[_0xd74d('0x2f')]=_0xe87d04[_0xd74d('0x2f')][_0xd74d('0x31')]?_0xe87d04[_0xd74d('0x2f')]:_0x1189bc['model'];if(!_0x45681c[_0xd74d('0x2d')]['hasOwnProperty'](_0xd74d('0x40'))){_0xe87d04['limit']=qs[_0xd74d('0x14')](_0x45681c['query']['limit']);_0xe87d04['offset']=qs[_0xd74d('0x13')](_0x45681c['query'][_0xd74d('0x13')]);}_0xe87d04['order']=qs['sort'](_0x45681c[_0xd74d('0x2d')][_0xd74d('0x41')]);_0xe87d04[_0xd74d('0x42')]=qs[_0xd74d('0x3f')](_[_0xd74d('0x43')](_0x45681c[_0xd74d('0x2d')],_0x1189bc[_0xd74d('0x3f')]));_0xe87d04[_0xd74d('0x42')][_0xd74d('0x44')]=_0x25c1fd['id'];if(_0x45681c[_0xd74d('0x2d')]['filter']){_0xe87d04['where']=_['merge'](_0xe87d04[_0xd74d('0x42')],{'$or':_[_0xd74d('0x20')](_0xe87d04['attributes'],function(_0x455086){var _0x3c19c3={};_0x3c19c3[_0x455086]={'$like':'%'+_0x45681c[_0xd74d('0x2d')]['filter']+'%'};return _0x3c19c3;})});}if(_0x45681c['query']['$gte']){var _0x2c8d8c=_0x45681c[_0xd74d('0x2d')]['$gte'][_0xd74d('0x45')](',');var _0x6c6d92={};_0x6c6d92[_0x2c8d8c[0x0]]={'$gte':moment(_0x2c8d8c[0x1])[_0xd74d('0x46')]('YYYY-MM-DD\x20HH:mm:ss')};_0xe87d04[_0xd74d('0x42')]=_[_0xd74d('0x34')](_0xe87d04[_0xd74d('0x42')],_0x6c6d92);}_0xe87d04=_['merge']({},_0xe87d04,_0x45681c[_0xd74d('0x35')]);return db[_0xd74d('0x3b')][_0xd74d('0x15')]({'where':_0xe87d04[_0xd74d('0x42')]})[_0xd74d('0x1a')](function(_0x260e65){_0xd8c413['count']=_0x260e65;if(_0x45681c[_0xd74d('0x2d')]['includeAll']){_0xe87d04[_0xd74d('0x33')]=[{'all':!![]}];}return db[_0xd74d('0x3b')][_0xd74d('0x47')](_0xe87d04);})[_0xd74d('0x1a')](function(_0x1ead19){_0xd8c413[_0xd74d('0x48')]=_0x1ead19;return _0xd8c413;});}})[_0xd74d('0x1a')](respondWithFilteredResult(_0x1139df,_0xe87d04))[_0xd74d('0x37')](handleError(_0x1139df,null));};exports[_0xd74d('0x49')]=function(_0x4f93c0,_0x25bb7b){return db[_0xd74d('0x21')][_0xd74d('0x36')]({'where':{'id':_0x4f93c0[_0xd74d('0x2a')]['id']}})['then'](handleEntityNotFound(_0x25bb7b,null))['then'](function(_0x2cd699){if(_0x2cd699){return _0x2cd699[_0xd74d('0x4a')](_0x4f93c0[_0xd74d('0x39')][_0xd74d('0x3c')],_[_0xd74d('0x4b')](_0x4f93c0[_0xd74d('0x39')],['ids','id'])||{})[_0xd74d('0x4c')](function(){return db[_0xd74d('0x4d')][_0xd74d('0x47')]({'attributes':['id',_0xd74d('0x1d'),_0xd74d('0x4e')],'where':{'id':_0x4f93c0['body']['ids']}});})[_0xd74d('0x1a')](function(_0x152785){socket['emit'](_0xd74d('0x4f'),{'id':Number(_0x4f93c0[_0xd74d('0x2a')]['id']),'tags':_0x152785||[]});return{'id':Number(_0x4f93c0[_0xd74d('0x2a')]['id']),'tags':_0x152785||[]};});}})[_0xd74d('0x1a')](respondWithResult(_0x25bb7b,null))[_0xd74d('0x37')](handleError(_0x25bb7b,null));};exports[_0xd74d('0x50')]=function(_0x1aa4ae,_0x22fec3){return db[_0xd74d('0x21')][_0xd74d('0x36')]({'where':{'id':_0x1aa4ae[_0xd74d('0x2a')]['id']}})[_0xd74d('0x1a')](handleEntityNotFound(_0x22fec3,null))[_0xd74d('0x1a')](function(_0x413059){if(_0x413059){return _0x413059[_0xd74d('0x50')](_0x1aa4ae[_0xd74d('0x2d')][_0xd74d('0x3c')]);}})[_0xd74d('0x1a')](respondWithStatusCode(_0x22fec3,null))[_0xd74d('0x37')](handleError(_0x22fec3,null));};exports[_0xd74d('0x51')]=function(_0x334ebe,_0x526938){var _0xb067fb=moment()[_0xd74d('0x52')]()['toString']();var _0x3a552a=path[_0xd74d('0x53')](config['root'],'server',_0xd74d('0x54'),'tmp');var _0x175195=path[_0xd74d('0x53')](config['root'],_0xd74d('0x55'),_0xd74d('0x54'),_0xd74d('0x56'));var _0x51dc19=path[_0xd74d('0x53')](_0x3a552a,_0xb067fb);var _0x9041bc=util[_0xd74d('0x46')]('transcript-%d-%s.zip',_0x334ebe['params']['id'],_0xb067fb);var _0x445dd0=path[_0xd74d('0x53')](_0x3a552a,_0x9041bc);var _0x384b0a=[];_0x384b0a['push']({'model':db[_0xd74d('0x57')],'as':_0xd74d('0x57'),'attributes':['id',_0xd74d('0x58')],'raw':!![]});_0x384b0a[_0xd74d('0x59')]({'model':db[_0xd74d('0x5a')],'as':_0xd74d('0x5b'),'attributes':['id',_0xd74d('0x5c'),_0xd74d('0x5d')],'raw':!![]});if(_0x334ebe[_0xd74d('0x2d')][_0xd74d('0x56')]){_0x384b0a[_0xd74d('0x59')]({'model':db[_0xd74d('0x5e')],'as':_0xd74d('0x5e'),'raw':!![]});}var _0x1bd02c=[{'model':db[_0xd74d('0x3b')],'as':_0xd74d('0x5f'),'attributes':['id',_0xd74d('0x39'),_0xd74d('0x60'),_0xd74d('0x61'),_0xd74d('0x62'),'read'],'include':_0x384b0a}];_0x1bd02c['push']({'model':db[_0xd74d('0x63')],'as':'Account','attributes':['id','name']});_0x1bd02c[_0xd74d('0x59')]({'model':db[_0xd74d('0x57')],'as':_0xd74d('0x64'),'attributes':['id',_0xd74d('0x58')]});return db[_0xd74d('0x21')][_0xd74d('0x36')]({'where':{'id':_0x334ebe['params']['id']},'include':_0x1bd02c})['then'](handleEntityNotFound(_0x526938,null))['then'](function(_0x4917cf){if(_0x4917cf){var _0x145b55=_0x4917cf[_0xd74d('0x65')]({'plain':!![]});fs[_0xd74d('0x66')](_0x51dc19);var _0x5d87ec={'channel':_0xd74d('0x67'),'account':_0x145b55[_0xd74d('0x68')][_0xd74d('0x1d')],'agent':_0x145b55[_0xd74d('0x64')]?_0x145b55['Owner'][_0xd74d('0x58')]:_0xd74d('0x69'),'createdAt':moment(_0x145b55[_0xd74d('0x60')])[_0xd74d('0x46')](_0xd74d('0x6a'))[_0xd74d('0x6b')](),'closedAt':_0x145b55[_0xd74d('0x6c')]?moment(_0x145b55['closedAt'])[_0xd74d('0x46')](_0xd74d('0x6a'))[_0xd74d('0x6b')]():'','disposition':_0x145b55[_0xd74d('0x6d')],'visibility':_0x145b55['threadId']?_0xd74d('0x6e'):_0xd74d('0x6f'),'messages':_(_0x145b55['Messages'])[_0xd74d('0x70')]({'secret':![]})[_0xd74d('0x20')](function(_0x3ece8a){if(_0x3ece8a[_0xd74d('0x5e')]){var _0x45c928=path[_0xd74d('0x53')](_0x175195,_0x3ece8a[_0xd74d('0x5e')][_0xd74d('0x71')]);if(fs[_0xd74d('0x72')](_0x45c928)){fs[_0xd74d('0x73')](_0x45c928)[_0xd74d('0x74')](fs[_0xd74d('0x75')](path[_0xd74d('0x53')](_0x51dc19,_0x3ece8a[_0xd74d('0x5e')][_0xd74d('0x71')])));}}return{'date':moment(_0x3ece8a[_0xd74d('0x60')])[_0xd74d('0x46')](_0xd74d('0x6a'))[_0xd74d('0x6b')](),'sender':_0x3ece8a[_0xd74d('0x61')]===_0xd74d('0x76')?_0x3ece8a[_0xd74d('0x57')]?_0x3ece8a[_0xd74d('0x57')]['fullname']:_0xd74d('0x77'):_0x3ece8a[_0xd74d('0x5b')][_0xd74d('0x5c')]+(_0x3ece8a['Contact'][_0xd74d('0x5d')]?'\x20'+_0x3ece8a[_0xd74d('0x5b')]['lastName']:''),'body':_0x3ece8a[_0xd74d('0x5e')]?_0x3ece8a[_0xd74d('0x5e')][_0xd74d('0x71')]:_0x3ece8a[_0xd74d('0x39')],'direction':_0x3ece8a[_0xd74d('0x61')]===_0xd74d('0x76')?'A':'C','secret':_0x3ece8a[_0xd74d('0x62')],'read':_0x3ece8a[_0xd74d('0x78')],'attachment':_0x3ece8a[_0xd74d('0x5e')]};})[_0xd74d('0x79')]()};return ejs['renderFile'](path['join'](config[_0xd74d('0x7a')],_0xd74d('0x55'),'views',_0xd74d('0x7b')),{'interaction':_0x5d87ec})['then'](function(_0x334a67){var _0xb57cff=path['join'](_0x51dc19,'transcript-'+_0x145b55['id']+'-'+_0xb067fb+_0xd74d('0x7c'));var _0xb0824e={'path':_0xb57cff,'channel':'Openchannel','interactionId':_0x145b55['id']};return pdf[_0xd74d('0x7d')](_0x334a67,_0xb0824e);})['then'](function(){return new Promise(function(_0x27f5f8,_0x550484){zipdir(_0x51dc19,{'saveTo':_0x445dd0},function(_0x5e23d3,_0x358754){if(_0x5e23d3)return _0x550484(_0x5e23d3);return _0x27f5f8(_0x358754);});})[_0xd74d('0x1a')](function(){return new Promise(function(_0x5f4140,_0x51471d){rimraf(_0x51dc19,function(_0x2c3f73){if(_0x2c3f73)_0x51471d(_0x2c3f73);return _0x5f4140();});});})[_0xd74d('0x1a')](function(){return _0x526938[_0xd74d('0x51')](_0x445dd0,_0x9041bc,function(_0x4522b1){if(_0x4522b1){logger[_0xd74d('0x1c')](_0xd74d('0x7e'),_0x4522b1);}else{fs[_0xd74d('0x7f')](_0x445dd0);}});});});}else{return _0x526938[_0xd74d('0x1b')](0xc8);}})[_0xd74d('0x37')](handleError(_0x526938,null));};
\ No newline at end of file