Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index 44828b1..9bd9104 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe0a8=['update','describe','addMessage','OpenchannelMessage','ids','getMessages','findOne','hasOwnProperty','nolimit','sort','pick','where','OpenchannelInteractionId','filter','split','YYYY-MM-DD\x20HH:mm:ss','count','rows','addTags','setTags','omit','spread','Tag','emit','openchannelInteractionTags:save','download','toString','join','server','files','tmp','attachments','transcript-%d-%s.zip','User','fullname','push','lastName','Attachment','Messages','createdAt','direction','secret','read','Account','Owner','get','mkdirSync','Openchannel','format','closed','closedAt','threadId','Public','Private','basename','existsSync','createReadStream','pipe','createWriteStream','firstName','Contact','value','views','downloadInteraction.ejs','transcript-','createPdfFromHTML','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','moment','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','api','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','status','json','undefined','limit','offset','set','destroy','then','end','sendStatus','error','name','send','index','map','OpenchannelInteraction','fieldName','type','key','getOptions','findAll','openchannel','query','user','catch','show','from','params','model','keys','rawAttributes','filters','intersection','attributes','fields','length','includeAll','include','merge','options','find','create','body'];(function(_0x2ff6f4,_0x5e96c8){var _0x1caa48=function(_0x48ad9b){while(--_0x48ad9b){_0x2ff6f4['push'](_0x2ff6f4['shift']());}};_0x1caa48(++_0x5e96c8);}(_0xe0a8,0xc6));var _0x8e0a=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0xe0a8[_0x40a045];return _0x1a687c;};'use strict';var rimraf=require(_0x8e0a('0x0'));var zipdir=require(_0x8e0a('0x1'));var moment=require(_0x8e0a('0x2'));var util=require(_0x8e0a('0x3'));var path=require(_0x8e0a('0x4'));var ejs=require(_0x8e0a('0x5'));var fs=require('fs');var _=require(_0x8e0a('0x6'));var Redis=require(_0x8e0a('0x7'));var interaction=require(_0x8e0a('0x8'));var qs=require(_0x8e0a('0x9'));var pdf=require(_0x8e0a('0xa'));var logger=require('../../config/logger')(_0x8e0a('0xb'));var config=require(_0x8e0a('0xc'));var db=require(_0x8e0a('0xd'))['db'];config['redis']=_[_0x8e0a('0xe')](config[_0x8e0a('0xf')],{'host':_0x8e0a('0x10'),'port':0x18eb});var socket=require(_0x8e0a('0x11'))(new Redis(config[_0x8e0a('0xf')]));require('./openchannelInteraction.socket')[_0x8e0a('0x12')](socket);function respondWithStatusCode(_0x568d55,_0x3a4754){_0x3a4754=_0x3a4754||0xcc;return function(_0x4879d9){if(_0x4879d9){return _0x568d55['sendStatus'](_0x3a4754);}return _0x568d55[_0x8e0a('0x13')](_0x3a4754)['end']();};}function respondWithResult(_0x42cecb,_0x1f32f2){_0x1f32f2=_0x1f32f2||0xc8;return function(_0x2d322c){if(_0x2d322c){return _0x42cecb[_0x8e0a('0x13')](_0x1f32f2)[_0x8e0a('0x14')](_0x2d322c);}};}function respondWithFilteredResult(_0x238194,_0x1f91fe){return function(_0x3efb28){if(_0x3efb28){var _0x115bc0=typeof _0x1f91fe['offset']===_0x8e0a('0x15')&&typeof _0x1f91fe[_0x8e0a('0x16')]===_0x8e0a('0x15');var _0xdd304d=_0x3efb28['count'];var _0x4e28b3=_0x115bc0?0x0:_0x1f91fe['offset'];var _0x310ae4=_0x115bc0?_0x3efb28['count']:_0x1f91fe[_0x8e0a('0x17')]+_0x1f91fe[_0x8e0a('0x16')];var _0x317e5a;if(_0x310ae4>=_0xdd304d){_0x310ae4=_0xdd304d;_0x317e5a=0xc8;}else{_0x317e5a=0xce;}_0x238194[_0x8e0a('0x13')](_0x317e5a);return _0x238194[_0x8e0a('0x18')]('Content-Range',_0x4e28b3+'-'+_0x310ae4+'/'+_0xdd304d)[_0x8e0a('0x14')](_0x3efb28);}return null;};}function saveUpdates(_0x172dff){return function(_0xf0d3b8){if(_0xf0d3b8){return _0xf0d3b8['update'](_0x172dff)['then'](function(_0x39fd1f){return _0x39fd1f;});}return null;};}function removeEntity(_0x64c80){return function(_0x42406c){if(_0x42406c){return _0x42406c[_0x8e0a('0x19')]()[_0x8e0a('0x1a')](function(){_0x64c80[_0x8e0a('0x13')](0xcc)[_0x8e0a('0x1b')]();});}};}function handleEntityNotFound(_0x149fa8){return function(_0x41030f){if(!_0x41030f){_0x149fa8[_0x8e0a('0x1c')](0x194);}return _0x41030f;};}function handleError(_0x4ed7d8,_0x5e2409){_0x5e2409=_0x5e2409||0x1f4;return function(_0x5cb69a){logger[_0x8e0a('0x1d')](_0x5cb69a['stack']);if(_0x5cb69a[_0x8e0a('0x1e')]){delete _0x5cb69a['name'];}_0x4ed7d8[_0x8e0a('0x13')](_0x5e2409)[_0x8e0a('0x1f')](_0x5cb69a);};}exports[_0x8e0a('0x20')]=function(_0x4920b9,_0x129573){var _0x521979={};var _0x183cc1=_[_0x8e0a('0x21')](db[_0x8e0a('0x22')]['rawAttributes'],function(_0x233bce){return{'name':_0x233bce[_0x8e0a('0x23')],'type':_0x233bce[_0x8e0a('0x24')][_0x8e0a('0x25')]};});_0x521979=qs[_0x8e0a('0x26')](_0x183cc1,_0x4920b9);return interaction[_0x8e0a('0x27')](_0x8e0a('0x28'),_0x4920b9[_0x8e0a('0x29')],_0x4920b9[_0x8e0a('0x2a')],_0x521979,_0x183cc1)[_0x8e0a('0x1a')](respondWithFilteredResult(_0x129573,_0x521979))[_0x8e0a('0x2b')](handleError(_0x129573,null));};exports[_0x8e0a('0x2c')]=function(_0x49cb7b,_0x502210){var _0x158038={};if(_0x49cb7b[_0x8e0a('0x29')][_0x8e0a('0x24')]&&_0x49cb7b[_0x8e0a('0x29')][_0x8e0a('0x24')]===_0x8e0a('0x2d')){_0x158038[_0x8e0a('0x2d')]=_0x49cb7b['params']['id'];}else{_0x158038['id']=_0x49cb7b[_0x8e0a('0x2e')]['id'];}var _0x1c4cb4={'raw':![],'where':_0x158038},_0x268de8={};_0x268de8[_0x8e0a('0x2f')]=_[_0x8e0a('0x30')](db[_0x8e0a('0x22')][_0x8e0a('0x31')]);_0x268de8[_0x8e0a('0x29')]=_['keys'](_0x49cb7b[_0x8e0a('0x29')]);_0x268de8[_0x8e0a('0x32')]=_[_0x8e0a('0x33')](_0x268de8[_0x8e0a('0x2f')],_0x268de8[_0x8e0a('0x29')]);_0x1c4cb4[_0x8e0a('0x34')]=_[_0x8e0a('0x33')](_0x268de8[_0x8e0a('0x2f')],qs['fields'](_0x49cb7b[_0x8e0a('0x29')][_0x8e0a('0x35')]));_0x1c4cb4[_0x8e0a('0x34')]=_0x1c4cb4[_0x8e0a('0x34')][_0x8e0a('0x36')]?_0x1c4cb4[_0x8e0a('0x34')]:_0x268de8[_0x8e0a('0x2f')];if(_0x49cb7b[_0x8e0a('0x29')][_0x8e0a('0x37')]){_0x1c4cb4[_0x8e0a('0x38')]=[{'all':!![]}];}_0x1c4cb4=_[_0x8e0a('0x39')]({},_0x1c4cb4,_0x49cb7b[_0x8e0a('0x3a')]);return db[_0x8e0a('0x22')][_0x8e0a('0x3b')](_0x1c4cb4)[_0x8e0a('0x1a')](handleEntityNotFound(_0x502210,null))[_0x8e0a('0x1a')](respondWithResult(_0x502210,null))[_0x8e0a('0x2b')](handleError(_0x502210,null));};exports['create']=function(_0x15f5d7,_0x398ad7){return db['OpenchannelInteraction'][_0x8e0a('0x3c')](_0x15f5d7[_0x8e0a('0x3d')],{})[_0x8e0a('0x1a')](respondWithResult(_0x398ad7,0xc9))[_0x8e0a('0x2b')](handleError(_0x398ad7,null));};exports[_0x8e0a('0x3e')]=function(_0x5e386e,_0x41b39d){if(_0x5e386e[_0x8e0a('0x3d')]['id']){delete _0x5e386e['body']['id'];}return db[_0x8e0a('0x22')][_0x8e0a('0x3b')]({'where':{'id':_0x5e386e[_0x8e0a('0x2e')]['id']}})[_0x8e0a('0x1a')](handleEntityNotFound(_0x41b39d,null))['then'](saveUpdates(_0x5e386e[_0x8e0a('0x3d')],null))[_0x8e0a('0x1a')](respondWithResult(_0x41b39d,null))['catch'](handleError(_0x41b39d,null));};exports[_0x8e0a('0x19')]=function(_0x372e9c,_0x44e590){return db[_0x8e0a('0x22')][_0x8e0a('0x3b')]({'where':{'id':_0x372e9c[_0x8e0a('0x2e')]['id']}})['then'](handleEntityNotFound(_0x44e590,null))[_0x8e0a('0x1a')](removeEntity(_0x44e590,null))[_0x8e0a('0x2b')](handleError(_0x44e590,null));};exports[_0x8e0a('0x3f')]=function(_0x2890ef,_0x15ac7){return db[_0x8e0a('0x22')][_0x8e0a('0x3f')]()['then'](respondWithResult(_0x15ac7,null))[_0x8e0a('0x2b')](handleError(_0x15ac7,null));};exports[_0x8e0a('0x40')]=function(_0x36a32f,_0x69e8b){return db[_0x8e0a('0x41')]['find']({'where':{'id':_0x36a32f[_0x8e0a('0x2e')]['id']}})[_0x8e0a('0x1a')](handleEntityNotFound(_0x69e8b,null))[_0x8e0a('0x1a')](function(_0x555b76){if(_0x555b76){return _0x555b76[_0x8e0a('0x40')](_0x36a32f[_0x8e0a('0x3d')][_0x8e0a('0x42')],_['omit'](_0x36a32f[_0x8e0a('0x3d')],['ids','id'])||{});}})[_0x8e0a('0x1a')](respondWithResult(_0x69e8b,null))[_0x8e0a('0x2b')](handleError(_0x69e8b,null));};exports[_0x8e0a('0x43')]=function(_0x1b7f10,_0x14fd3b){var _0x173fef={'raw':![],'where':{}};var _0x1ea8e5={};var _0x4570a1={'count':0x0,'rows':[]};return db[_0x8e0a('0x22')][_0x8e0a('0x44')]({'where':{'id':_0x1b7f10[_0x8e0a('0x2e')]['id']}})['then'](handleEntityNotFound(_0x14fd3b,null))['then'](function(_0x3c26aa){if(_0x3c26aa){_0x1ea8e5[_0x8e0a('0x2f')]=_['keys'](db[_0x8e0a('0x41')][_0x8e0a('0x31')]);_0x1ea8e5[_0x8e0a('0x29')]=_[_0x8e0a('0x30')](_0x1b7f10[_0x8e0a('0x29')]);_0x1ea8e5[_0x8e0a('0x32')]=_[_0x8e0a('0x33')](_0x1ea8e5[_0x8e0a('0x2f')],_0x1ea8e5[_0x8e0a('0x29')]);_0x173fef['attributes']=_[_0x8e0a('0x33')](_0x1ea8e5[_0x8e0a('0x2f')],qs['fields'](_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x35')]));_0x173fef[_0x8e0a('0x34')]=_0x173fef[_0x8e0a('0x34')]['length']?_0x173fef[_0x8e0a('0x34')]:_0x1ea8e5[_0x8e0a('0x2f')];if(!_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x45')](_0x8e0a('0x46'))){_0x173fef[_0x8e0a('0x16')]=qs[_0x8e0a('0x16')](_0x1b7f10['query'][_0x8e0a('0x16')]);_0x173fef[_0x8e0a('0x17')]=qs['offset'](_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x17')]);}_0x173fef['order']=qs[_0x8e0a('0x47')](_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x47')]);_0x173fef['where']=qs['filters'](_[_0x8e0a('0x48')](_0x1b7f10[_0x8e0a('0x29')],_0x1ea8e5[_0x8e0a('0x32')]));_0x173fef[_0x8e0a('0x49')][_0x8e0a('0x4a')]=_0x3c26aa['id'];if(_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x4b')]){_0x173fef['where']=_[_0x8e0a('0x39')](_0x173fef[_0x8e0a('0x49')],{'$or':_['map'](_0x173fef[_0x8e0a('0x34')],function(_0x1b87d9){var _0x5466e6={};_0x5466e6[_0x1b87d9]={'$like':'%'+_0x1b7f10['query']['filter']+'%'};return _0x5466e6;})});}if(_0x1b7f10[_0x8e0a('0x29')]['$gte']){var _0x3cf9f6=_0x1b7f10[_0x8e0a('0x29')]['$gte'][_0x8e0a('0x4c')](',');var _0xe56d8d={};_0xe56d8d[_0x3cf9f6[0x0]]={'$gte':moment(_0x3cf9f6[0x1])['format'](_0x8e0a('0x4d'))};_0x173fef[_0x8e0a('0x49')]=_[_0x8e0a('0x39')](_0x173fef[_0x8e0a('0x49')],_0xe56d8d);}_0x173fef=_[_0x8e0a('0x39')]({},_0x173fef,_0x1b7f10['options']);return db[_0x8e0a('0x41')]['count']({'where':_0x173fef[_0x8e0a('0x49')]})[_0x8e0a('0x1a')](function(_0x28ee12){_0x4570a1[_0x8e0a('0x4e')]=_0x28ee12;if(_0x1b7f10[_0x8e0a('0x29')][_0x8e0a('0x37')]){_0x173fef[_0x8e0a('0x38')]=[{'all':!![]}];}return db[_0x8e0a('0x41')]['findAll'](_0x173fef);})['then'](function(_0x3fc070){_0x4570a1[_0x8e0a('0x4f')]=_0x3fc070;return _0x4570a1;});}})[_0x8e0a('0x1a')](respondWithFilteredResult(_0x14fd3b,_0x173fef))[_0x8e0a('0x2b')](handleError(_0x14fd3b,null));};exports[_0x8e0a('0x50')]=function(_0x17f37d,_0x435ad2){return db[_0x8e0a('0x22')][_0x8e0a('0x3b')]({'where':{'id':_0x17f37d[_0x8e0a('0x2e')]['id']}})[_0x8e0a('0x1a')](handleEntityNotFound(_0x435ad2,null))[_0x8e0a('0x1a')](function(_0xf462dc){if(_0xf462dc){return _0xf462dc[_0x8e0a('0x51')](_0x17f37d[_0x8e0a('0x3d')][_0x8e0a('0x42')],_[_0x8e0a('0x52')](_0x17f37d[_0x8e0a('0x3d')],[_0x8e0a('0x42'),'id'])||{})[_0x8e0a('0x53')](function(){return db[_0x8e0a('0x54')][_0x8e0a('0x27')]({'attributes':['id','name','color'],'where':{'id':_0x17f37d[_0x8e0a('0x3d')]['ids']}});})[_0x8e0a('0x1a')](function(_0x304d59){socket[_0x8e0a('0x55')](_0x8e0a('0x56'),{'id':Number(_0x17f37d[_0x8e0a('0x2e')]['id']),'tags':_0x304d59||[]});return{'id':Number(_0x17f37d[_0x8e0a('0x2e')]['id']),'tags':_0x304d59||[]};});}})[_0x8e0a('0x1a')](respondWithResult(_0x435ad2,null))[_0x8e0a('0x2b')](handleError(_0x435ad2,null));};exports['removeTags']=function(_0x3f8fa0,_0x394d4c){return db[_0x8e0a('0x22')][_0x8e0a('0x3b')]({'where':{'id':_0x3f8fa0[_0x8e0a('0x2e')]['id']}})[_0x8e0a('0x1a')](handleEntityNotFound(_0x394d4c,null))[_0x8e0a('0x1a')](function(_0x17ca5b){if(_0x17ca5b){return _0x17ca5b['removeTags'](_0x3f8fa0[_0x8e0a('0x29')][_0x8e0a('0x42')]);}})[_0x8e0a('0x1a')](respondWithStatusCode(_0x394d4c,null))[_0x8e0a('0x2b')](handleError(_0x394d4c,null));};exports[_0x8e0a('0x57')]=function(_0x834048,_0x386efe){var _0x293b07=moment()['unix']()[_0x8e0a('0x58')]();var _0x3929a3=path[_0x8e0a('0x59')](config['root'],_0x8e0a('0x5a'),_0x8e0a('0x5b'),_0x8e0a('0x5c'));var _0x2cdfe9=path[_0x8e0a('0x59')](config['root'],_0x8e0a('0x5a'),_0x8e0a('0x5b'),_0x8e0a('0x5d'));var _0x2c0fae=path[_0x8e0a('0x59')](_0x3929a3,_0x293b07);var _0xa9fe5a=util['format'](_0x8e0a('0x5e'),_0x834048[_0x8e0a('0x2e')]['id'],_0x293b07);var _0x1cbcd9=path[_0x8e0a('0x59')](_0x3929a3,_0xa9fe5a);var _0x3784c5=[];_0x3784c5['push']({'model':db[_0x8e0a('0x5f')],'as':_0x8e0a('0x5f'),'attributes':['id',_0x8e0a('0x60')],'raw':!![]});_0x3784c5[_0x8e0a('0x61')]({'model':db['CmContact'],'as':'Contact','attributes':['id','firstName',_0x8e0a('0x62')],'raw':!![]});if(_0x834048[_0x8e0a('0x29')][_0x8e0a('0x5d')]){_0x3784c5[_0x8e0a('0x61')]({'model':db[_0x8e0a('0x63')],'as':_0x8e0a('0x63'),'raw':!![]});}var _0x4c1950=[{'model':db[_0x8e0a('0x41')],'as':_0x8e0a('0x64'),'attributes':['id',_0x8e0a('0x3d'),_0x8e0a('0x65'),_0x8e0a('0x66'),_0x8e0a('0x67'),_0x8e0a('0x68')],'include':_0x3784c5}];_0x4c1950[_0x8e0a('0x61')]({'model':db['OpenchannelAccount'],'as':_0x8e0a('0x69'),'attributes':['id','name']});_0x4c1950[_0x8e0a('0x61')]({'model':db[_0x8e0a('0x5f')],'as':_0x8e0a('0x6a'),'attributes':['id',_0x8e0a('0x60')]});return db['OpenchannelInteraction'][_0x8e0a('0x3b')]({'where':{'id':_0x834048[_0x8e0a('0x2e')]['id']},'include':_0x4c1950})[_0x8e0a('0x1a')](handleEntityNotFound(_0x386efe,null))[_0x8e0a('0x1a')](function(_0x36262e){if(_0x36262e){var _0x15465e=_0x36262e[_0x8e0a('0x6b')]({'plain':!![]});fs[_0x8e0a('0x6c')](_0x2c0fae);var _0x18cb5b={'channel':_0x8e0a('0x6d'),'account':_0x15465e[_0x8e0a('0x69')][_0x8e0a('0x1e')],'agent':_0x15465e[_0x8e0a('0x6a')]?_0x15465e[_0x8e0a('0x6a')]['fullname']:'N.A.','createdAt':moment(_0x15465e[_0x8e0a('0x65')])[_0x8e0a('0x6e')](_0x8e0a('0x4d'))[_0x8e0a('0x58')](),'closedAt':_0x15465e[_0x8e0a('0x6f')]?moment(_0x15465e[_0x8e0a('0x70')])[_0x8e0a('0x6e')](_0x8e0a('0x4d'))[_0x8e0a('0x58')]():'','disposition':_0x15465e['disposition'],'visibility':_0x15465e[_0x8e0a('0x71')]?_0x8e0a('0x72'):_0x8e0a('0x73'),'messages':_(_0x15465e[_0x8e0a('0x64')])[_0x8e0a('0x4b')]({'secret':![]})[_0x8e0a('0x21')](function(_0x931e3c){if(_0x931e3c[_0x8e0a('0x63')]){var _0x89f97a=path[_0x8e0a('0x59')](_0x2cdfe9,_0x931e3c[_0x8e0a('0x63')][_0x8e0a('0x74')]);if(fs[_0x8e0a('0x75')](_0x89f97a)){fs[_0x8e0a('0x76')](_0x89f97a)[_0x8e0a('0x77')](fs[_0x8e0a('0x78')](path[_0x8e0a('0x59')](_0x2c0fae,_0x931e3c[_0x8e0a('0x63')][_0x8e0a('0x74')])));}}return{'date':moment(_0x931e3c[_0x8e0a('0x65')])[_0x8e0a('0x6e')](_0x8e0a('0x4d'))['toString'](),'sender':_0x931e3c['direction']==='out'?_0x931e3c[_0x8e0a('0x5f')]?_0x931e3c[_0x8e0a('0x5f')][_0x8e0a('0x60')]:'System':_0x931e3c['Contact'][_0x8e0a('0x79')]+(_0x931e3c['Contact'][_0x8e0a('0x62')]?'\x20'+_0x931e3c[_0x8e0a('0x7a')][_0x8e0a('0x62')]:''),'body':_0x931e3c[_0x8e0a('0x63')]?_0x931e3c[_0x8e0a('0x63')]['basename']:_0x931e3c['body'],'direction':_0x931e3c[_0x8e0a('0x66')]==='out'?'A':'C','secret':_0x931e3c['secret'],'read':_0x931e3c[_0x8e0a('0x68')],'attachment':_0x931e3c['Attachment']};})[_0x8e0a('0x7b')]()};return ejs['renderFile'](path[_0x8e0a('0x59')](config['root'],_0x8e0a('0x5a'),_0x8e0a('0x7c'),_0x8e0a('0x7d')),{'interaction':_0x18cb5b})['then'](function(_0x103209){var _0x4bbbc2=path[_0x8e0a('0x59')](_0x2c0fae,_0x8e0a('0x7e')+_0x15465e['id']+'-'+_0x293b07+'.pdf');var _0x80547a={'path':_0x4bbbc2,'channel':_0x8e0a('0x6d'),'interactionId':_0x15465e['id']};return pdf[_0x8e0a('0x7f')](_0x103209,_0x80547a);})[_0x8e0a('0x1a')](function(){return new Promise(function(_0x4bc0ca,_0x19a3a7){zipdir(_0x2c0fae,{'saveTo':_0x1cbcd9},function(_0x51257e,_0x5f0c0a){if(_0x51257e)return _0x19a3a7(_0x51257e);return _0x4bc0ca(_0x5f0c0a);});})[_0x8e0a('0x1a')](function(){return new Promise(function(_0x50b6b5,_0x156388){rimraf(_0x2c0fae,function(_0x10b0cd){if(_0x10b0cd)_0x156388(_0x10b0cd);return _0x50b6b5();});});})[_0x8e0a('0x1a')](function(){return _0x386efe[_0x8e0a('0x57')](_0x1cbcd9,_0xa9fe5a,function(_0x253f66){if(_0x253f66){logger[_0x8e0a('0x1d')](_0x8e0a('0x80'),_0x253f66);}else{fs[_0x8e0a('0x81')](_0x1cbcd9);}});});});}else{return _0x386efe['sendStatus'](0xc8);}})[_0x8e0a('0x2b')](handleError(_0x386efe,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