Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.controller.js
index 5786d43..06a80b6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb5c0=['transcript-%d-%s.zip','User','fullname','push','Contact','firstName','Attachment','Messages','createdAt','direction','secret','read','OpenchannelAccount','Account','Owner','get','mkdirSync','Openchannel','YYYY-MM-DD\x20HH:mm:ss','closedAt','disposition','threadId','Public','Private','basename','createReadStream','pipe','createWriteStream','System','lastName','out','renderFile','views','downloadInteraction.ejs','.pdf','createPdfFromHTML','error','Unable\x20to\x20delete\x20zip\x20file','unlinkSync','rimraf','zip-dir','moment','util','path','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','redis','defaults','localhost','socket.io-emitter','./openchannelInteraction.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','update','then','stack','name','index','map','OpenchannelInteraction','type','key','getOptions','findAll','openchannel','user','catch','show','query','from','params','rawAttributes','keys','filters','intersection','model','attributes','fields','length','includeAll','merge','find','create','body','destroy','describe','addMessage','ids','omit','getMessages','findOne','hasOwnProperty','order','sort','pick','where','filter','$gte','split','format','options','OpenchannelMessage','include','rows','addTags','Tag','emit','openchannelInteractionTags:save','removeTags','download','unix','toString','join','root','server','files','attachments'];(function(_0x341e16,_0x5b7929){var _0x5f3224=function(_0x58002c){while(--_0x58002c){_0x341e16['push'](_0x341e16['shift']());}};_0x5f3224(++_0x5b7929);}(_0xb5c0,0x1ad));var _0x0b5c=function(_0x4e62ed,_0x3ba0c0){_0x4e62ed=_0x4e62ed-0x0;var _0x528c21=_0xb5c0[_0x4e62ed];return _0x528c21;};'use strict';var rimraf=require(_0x0b5c('0x0'));var zipdir=require(_0x0b5c('0x1'));var moment=require(_0x0b5c('0x2'));var util=require(_0x0b5c('0x3'));var path=require(_0x0b5c('0x4'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var Redis=require(_0x0b5c('0x5'));var interaction=require(_0x0b5c('0x6'));var qs=require(_0x0b5c('0x7'));var pdf=require(_0x0b5c('0x8'));var logger=require(_0x0b5c('0x9'))(_0x0b5c('0xa'));var config=require(_0x0b5c('0xb'));var db=require('../../mysqldb')['db'];config[_0x0b5c('0xc')]=_[_0x0b5c('0xd')](config[_0x0b5c('0xc')],{'host':_0x0b5c('0xe'),'port':0x18eb});var socket=require(_0x0b5c('0xf'))(new Redis(config[_0x0b5c('0xc')]));require(_0x0b5c('0x10'))[_0x0b5c('0x11')](socket);function respondWithStatusCode(_0x1172a0,_0xfe4af){_0xfe4af=_0xfe4af||0xcc;return function(_0x1cb8e6){if(_0x1cb8e6){return _0x1172a0[_0x0b5c('0x12')](_0xfe4af);}return _0x1172a0[_0x0b5c('0x13')](_0xfe4af)[_0x0b5c('0x14')]();};}function respondWithResult(_0x8d7678,_0x11c1bf){_0x11c1bf=_0x11c1bf||0xc8;return function(_0xbf08b9){if(_0xbf08b9){return _0x8d7678['status'](_0x11c1bf)[_0x0b5c('0x15')](_0xbf08b9);}};}function respondWithFilteredResult(_0xbd113b,_0x56fa9b){return function(_0xe638c3){if(_0xe638c3){var _0x559f8c=typeof _0x56fa9b[_0x0b5c('0x16')]===_0x0b5c('0x17')&&typeof _0x56fa9b[_0x0b5c('0x18')]==='undefined';var _0x485d4b=_0xe638c3[_0x0b5c('0x19')];var _0x3a8452=_0x559f8c?0x0:_0x56fa9b[_0x0b5c('0x16')];var _0x221c61=_0x559f8c?_0xe638c3[_0x0b5c('0x19')]:_0x56fa9b[_0x0b5c('0x16')]+_0x56fa9b[_0x0b5c('0x18')];var _0x222e36;if(_0x221c61>=_0x485d4b){_0x221c61=_0x485d4b;_0x222e36=0xc8;}else{_0x222e36=0xce;}_0xbd113b[_0x0b5c('0x13')](_0x222e36);return _0xbd113b[_0x0b5c('0x1a')]('Content-Range',_0x3a8452+'-'+_0x221c61+'/'+_0x485d4b)[_0x0b5c('0x15')](_0xe638c3);}return null;};}function saveUpdates(_0x911d){return function(_0x2a0e5d){if(_0x2a0e5d){return _0x2a0e5d[_0x0b5c('0x1b')](_0x911d)[_0x0b5c('0x1c')](function(_0x5798f7){return _0x5798f7;});}return null;};}function removeEntity(_0x287cb9){return function(_0x424a05){if(_0x424a05){return _0x424a05['destroy']()[_0x0b5c('0x1c')](function(){_0x287cb9[_0x0b5c('0x13')](0xcc)[_0x0b5c('0x14')]();});}};}function handleEntityNotFound(_0x528839){return function(_0x532efa){if(!_0x532efa){_0x528839[_0x0b5c('0x12')](0x194);}return _0x532efa;};}function handleError(_0x5aa2af,_0x7039f8){_0x7039f8=_0x7039f8||0x1f4;return function(_0x476313){logger['error'](_0x476313[_0x0b5c('0x1d')]);if(_0x476313[_0x0b5c('0x1e')]){delete _0x476313[_0x0b5c('0x1e')];}_0x5aa2af[_0x0b5c('0x13')](_0x7039f8)['send'](_0x476313);};}exports[_0x0b5c('0x1f')]=function(_0x49e3be,_0x593a1c){var _0x218694={};var _0x5029b7=_[_0x0b5c('0x20')](db[_0x0b5c('0x21')]['rawAttributes'],function(_0x498330){return{'name':_0x498330['fieldName'],'type':_0x498330[_0x0b5c('0x22')][_0x0b5c('0x23')]};});_0x218694=qs[_0x0b5c('0x24')](_0x5029b7,_0x49e3be);return interaction[_0x0b5c('0x25')](_0x0b5c('0x26'),_0x49e3be['query'],_0x49e3be[_0x0b5c('0x27')],_0x218694,_0x5029b7)['then'](respondWithFilteredResult(_0x593a1c,_0x218694))[_0x0b5c('0x28')](handleError(_0x593a1c,null));};exports[_0x0b5c('0x29')]=function(_0x2d17b2,_0xb41269){var _0xd30c03={};if(_0x2d17b2[_0x0b5c('0x2a')][_0x0b5c('0x22')]&&_0x2d17b2[_0x0b5c('0x2a')][_0x0b5c('0x22')]==='from'){_0xd30c03[_0x0b5c('0x2b')]=_0x2d17b2[_0x0b5c('0x2c')]['id'];}else{_0xd30c03['id']=_0x2d17b2[_0x0b5c('0x2c')]['id'];}var _0x1aa63c={'raw':![],'where':_0xd30c03},_0x441906={};_0x441906['model']=_['keys'](db[_0x0b5c('0x21')][_0x0b5c('0x2d')]);_0x441906[_0x0b5c('0x2a')]=_[_0x0b5c('0x2e')](_0x2d17b2[_0x0b5c('0x2a')]);_0x441906[_0x0b5c('0x2f')]=_[_0x0b5c('0x30')](_0x441906[_0x0b5c('0x31')],_0x441906[_0x0b5c('0x2a')]);_0x1aa63c[_0x0b5c('0x32')]=_[_0x0b5c('0x30')](_0x441906[_0x0b5c('0x31')],qs[_0x0b5c('0x33')](_0x2d17b2[_0x0b5c('0x2a')]['fields']));_0x1aa63c[_0x0b5c('0x32')]=_0x1aa63c['attributes'][_0x0b5c('0x34')]?_0x1aa63c[_0x0b5c('0x32')]:_0x441906[_0x0b5c('0x31')];if(_0x2d17b2[_0x0b5c('0x2a')][_0x0b5c('0x35')]){_0x1aa63c['include']=[{'all':!![]}];}_0x1aa63c=_[_0x0b5c('0x36')]({},_0x1aa63c,_0x2d17b2['options']);return db[_0x0b5c('0x21')][_0x0b5c('0x37')](_0x1aa63c)[_0x0b5c('0x1c')](handleEntityNotFound(_0xb41269,null))[_0x0b5c('0x1c')](respondWithResult(_0xb41269,null))[_0x0b5c('0x28')](handleError(_0xb41269,null));};exports[_0x0b5c('0x38')]=function(_0x56c9f5,_0x51a1b9){return db[_0x0b5c('0x21')][_0x0b5c('0x38')](_0x56c9f5['body'],{})[_0x0b5c('0x1c')](respondWithResult(_0x51a1b9,0xc9))[_0x0b5c('0x28')](handleError(_0x51a1b9,null));};exports['update']=function(_0x289e78,_0x2b1280){if(_0x289e78['body']['id']){delete _0x289e78[_0x0b5c('0x39')]['id'];}return db['OpenchannelInteraction']['find']({'where':{'id':_0x289e78[_0x0b5c('0x2c')]['id']}})[_0x0b5c('0x1c')](handleEntityNotFound(_0x2b1280,null))[_0x0b5c('0x1c')](saveUpdates(_0x289e78[_0x0b5c('0x39')],null))[_0x0b5c('0x1c')](respondWithResult(_0x2b1280,null))['catch'](handleError(_0x2b1280,null));};exports[_0x0b5c('0x3a')]=function(_0x51fd2b,_0x193a6b){return db[_0x0b5c('0x21')][_0x0b5c('0x37')]({'where':{'id':_0x51fd2b[_0x0b5c('0x2c')]['id']}})['then'](handleEntityNotFound(_0x193a6b,null))[_0x0b5c('0x1c')](removeEntity(_0x193a6b,null))['catch'](handleError(_0x193a6b,null));};exports[_0x0b5c('0x3b')]=function(_0x962d31,_0xe52698){return db[_0x0b5c('0x21')]['describe']()[_0x0b5c('0x1c')](respondWithResult(_0xe52698,null))['catch'](handleError(_0xe52698,null));};exports[_0x0b5c('0x3c')]=function(_0x505643,_0x4ca7d5){return db['OpenchannelMessage'][_0x0b5c('0x37')]({'where':{'id':_0x505643[_0x0b5c('0x2c')]['id']}})[_0x0b5c('0x1c')](handleEntityNotFound(_0x4ca7d5,null))['then'](function(_0x56e971){if(_0x56e971){return _0x56e971[_0x0b5c('0x3c')](_0x505643[_0x0b5c('0x39')][_0x0b5c('0x3d')],_[_0x0b5c('0x3e')](_0x505643['body'],['ids','id'])||{});}})[_0x0b5c('0x1c')](respondWithResult(_0x4ca7d5,null))[_0x0b5c('0x28')](handleError(_0x4ca7d5,null));};exports[_0x0b5c('0x3f')]=function(_0x59b0e2,_0x314ba4){var _0x1807bb={'raw':![],'where':{}};var _0x26867c={};var _0x2a0416={'count':0x0,'rows':[]};return db[_0x0b5c('0x21')][_0x0b5c('0x40')]({'where':{'id':_0x59b0e2[_0x0b5c('0x2c')]['id']}})[_0x0b5c('0x1c')](handleEntityNotFound(_0x314ba4,null))[_0x0b5c('0x1c')](function(_0x3cb30a){if(_0x3cb30a){_0x26867c[_0x0b5c('0x31')]=_['keys'](db['OpenchannelMessage'][_0x0b5c('0x2d')]);_0x26867c[_0x0b5c('0x2a')]=_[_0x0b5c('0x2e')](_0x59b0e2['query']);_0x26867c[_0x0b5c('0x2f')]=_[_0x0b5c('0x30')](_0x26867c[_0x0b5c('0x31')],_0x26867c[_0x0b5c('0x2a')]);_0x1807bb[_0x0b5c('0x32')]=_[_0x0b5c('0x30')](_0x26867c[_0x0b5c('0x31')],qs['fields'](_0x59b0e2[_0x0b5c('0x2a')]['fields']));_0x1807bb[_0x0b5c('0x32')]=_0x1807bb['attributes'][_0x0b5c('0x34')]?_0x1807bb['attributes']:_0x26867c[_0x0b5c('0x31')];if(!_0x59b0e2['query'][_0x0b5c('0x41')]('nolimit')){_0x1807bb[_0x0b5c('0x18')]=qs[_0x0b5c('0x18')](_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x18')]);_0x1807bb['offset']=qs['offset'](_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x16')]);}_0x1807bb[_0x0b5c('0x42')]=qs[_0x0b5c('0x43')](_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x43')]);_0x1807bb['where']=qs[_0x0b5c('0x2f')](_[_0x0b5c('0x44')](_0x59b0e2[_0x0b5c('0x2a')],_0x26867c[_0x0b5c('0x2f')]));_0x1807bb[_0x0b5c('0x45')]['OpenchannelInteractionId']=_0x3cb30a['id'];if(_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x46')]){_0x1807bb[_0x0b5c('0x45')]=_[_0x0b5c('0x36')](_0x1807bb['where'],{'$or':_[_0x0b5c('0x20')](_0x1807bb[_0x0b5c('0x32')],function(_0x3e078d){var _0x257d14={};_0x257d14[_0x3e078d]={'$like':'%'+_0x59b0e2['query'][_0x0b5c('0x46')]+'%'};return _0x257d14;})});}if(_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x47')]){var _0x2f3445=_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x47')][_0x0b5c('0x48')](',');var _0x409407={};_0x409407[_0x2f3445[0x0]]={'$gte':moment(_0x2f3445[0x1])[_0x0b5c('0x49')]('YYYY-MM-DD\x20HH:mm:ss')};_0x1807bb['where']=_['merge'](_0x1807bb['where'],_0x409407);}_0x1807bb=_[_0x0b5c('0x36')]({},_0x1807bb,_0x59b0e2[_0x0b5c('0x4a')]);return db[_0x0b5c('0x4b')]['count']({'where':_0x1807bb['where']})['then'](function(_0x972c31){_0x2a0416[_0x0b5c('0x19')]=_0x972c31;if(_0x59b0e2[_0x0b5c('0x2a')][_0x0b5c('0x35')]){_0x1807bb[_0x0b5c('0x4c')]=[{'all':!![]}];}return db['OpenchannelMessage'][_0x0b5c('0x25')](_0x1807bb);})[_0x0b5c('0x1c')](function(_0x265f74){_0x2a0416[_0x0b5c('0x4d')]=_0x265f74;return _0x2a0416;});}})['then'](respondWithFilteredResult(_0x314ba4,_0x1807bb))[_0x0b5c('0x28')](handleError(_0x314ba4,null));};exports[_0x0b5c('0x4e')]=function(_0x5af1cc,_0x5d9e87){return db[_0x0b5c('0x21')][_0x0b5c('0x37')]({'where':{'id':_0x5af1cc[_0x0b5c('0x2c')]['id']}})[_0x0b5c('0x1c')](handleEntityNotFound(_0x5d9e87,null))[_0x0b5c('0x1c')](function(_0x329fc6){if(_0x329fc6){return _0x329fc6['setTags'](_0x5af1cc['body']['ids'],_[_0x0b5c('0x3e')](_0x5af1cc['body'],[_0x0b5c('0x3d'),'id'])||{})['spread'](function(){return db[_0x0b5c('0x4f')][_0x0b5c('0x25')]({'attributes':['id',_0x0b5c('0x1e'),'color'],'where':{'id':_0x5af1cc[_0x0b5c('0x39')][_0x0b5c('0x3d')]}});})['then'](function(_0x1a8e48){socket[_0x0b5c('0x50')](_0x0b5c('0x51'),{'id':Number(_0x5af1cc[_0x0b5c('0x2c')]['id']),'tags':_0x1a8e48||[]});return{'id':Number(_0x5af1cc[_0x0b5c('0x2c')]['id']),'tags':_0x1a8e48||[]};});}})[_0x0b5c('0x1c')](respondWithResult(_0x5d9e87,null))[_0x0b5c('0x28')](handleError(_0x5d9e87,null));};exports[_0x0b5c('0x52')]=function(_0x4ebb05,_0x5d3724){return db['OpenchannelInteraction'][_0x0b5c('0x37')]({'where':{'id':_0x4ebb05[_0x0b5c('0x2c')]['id']}})[_0x0b5c('0x1c')](handleEntityNotFound(_0x5d3724,null))[_0x0b5c('0x1c')](function(_0x2aa968){if(_0x2aa968){return _0x2aa968[_0x0b5c('0x52')](_0x4ebb05[_0x0b5c('0x2a')][_0x0b5c('0x3d')]);}})[_0x0b5c('0x1c')](respondWithStatusCode(_0x5d3724,null))[_0x0b5c('0x28')](handleError(_0x5d3724,null));};exports[_0x0b5c('0x53')]=function(_0xef070a,_0x571a39){var _0xc819f5=moment()[_0x0b5c('0x54')]()[_0x0b5c('0x55')]();var _0x44d404=path[_0x0b5c('0x56')](config[_0x0b5c('0x57')],_0x0b5c('0x58'),_0x0b5c('0x59'),'tmp');var _0xf90168=path[_0x0b5c('0x56')](config[_0x0b5c('0x57')],_0x0b5c('0x58'),_0x0b5c('0x59'),_0x0b5c('0x5a'));var _0x4381ad=path[_0x0b5c('0x56')](_0x44d404,_0xc819f5);var _0x15ca7a=util[_0x0b5c('0x49')](_0x0b5c('0x5b'),_0xef070a['params']['id'],_0xc819f5);var _0x53c6bd=path[_0x0b5c('0x56')](_0x44d404,_0x15ca7a);var _0x336140=[];_0x336140['push']({'model':db[_0x0b5c('0x5c')],'as':'User','attributes':['id',_0x0b5c('0x5d')],'raw':!![]});_0x336140[_0x0b5c('0x5e')]({'model':db['CmContact'],'as':_0x0b5c('0x5f'),'attributes':['id',_0x0b5c('0x60'),'lastName'],'raw':!![]});if(_0xef070a[_0x0b5c('0x2a')][_0x0b5c('0x5a')]){_0x336140[_0x0b5c('0x5e')]({'model':db[_0x0b5c('0x61')],'as':_0x0b5c('0x61'),'raw':!![]});}var _0x436b03=[{'model':db[_0x0b5c('0x4b')],'as':_0x0b5c('0x62'),'attributes':['id',_0x0b5c('0x39'),_0x0b5c('0x63'),_0x0b5c('0x64'),_0x0b5c('0x65'),_0x0b5c('0x66')],'include':_0x336140}];_0x436b03[_0x0b5c('0x5e')]({'model':db[_0x0b5c('0x67')],'as':_0x0b5c('0x68'),'attributes':['id',_0x0b5c('0x1e')]});_0x436b03[_0x0b5c('0x5e')]({'model':db[_0x0b5c('0x5c')],'as':_0x0b5c('0x69'),'attributes':['id',_0x0b5c('0x5d')]});return db[_0x0b5c('0x21')][_0x0b5c('0x37')]({'where':{'id':_0xef070a[_0x0b5c('0x2c')]['id']},'include':_0x436b03})['then'](handleEntityNotFound(_0x571a39,null))[_0x0b5c('0x1c')](function(_0x470dbc){if(_0x470dbc){var _0x3ca102=_0x470dbc[_0x0b5c('0x6a')]({'plain':!![]});fs[_0x0b5c('0x6b')](_0x4381ad);var _0x3bc028={'channel':_0x0b5c('0x6c'),'account':_0x3ca102['Account']['name'],'agent':_0x3ca102[_0x0b5c('0x69')]?_0x3ca102[_0x0b5c('0x69')][_0x0b5c('0x5d')]:'N.A.','createdAt':moment(_0x3ca102['createdAt'])[_0x0b5c('0x49')](_0x0b5c('0x6d'))[_0x0b5c('0x55')](),'closedAt':_0x3ca102['closed']?moment(_0x3ca102[_0x0b5c('0x6e')])['format'](_0x0b5c('0x6d'))['toString']():'','disposition':_0x3ca102[_0x0b5c('0x6f')],'visibility':_0x3ca102[_0x0b5c('0x70')]?_0x0b5c('0x71'):_0x0b5c('0x72'),'messages':_(_0x3ca102[_0x0b5c('0x62')])[_0x0b5c('0x46')]({'secret':![]})[_0x0b5c('0x20')](function(_0x2b3923){if(_0x2b3923[_0x0b5c('0x61')]){var _0x3c1114=path['join'](_0xf90168,_0x2b3923[_0x0b5c('0x61')][_0x0b5c('0x73')]);if(fs['existsSync'](_0x3c1114)){fs[_0x0b5c('0x74')](_0x3c1114)[_0x0b5c('0x75')](fs[_0x0b5c('0x76')](path[_0x0b5c('0x56')](_0x4381ad,_0x2b3923[_0x0b5c('0x61')][_0x0b5c('0x73')])));}}return{'date':moment(_0x2b3923[_0x0b5c('0x63')])[_0x0b5c('0x49')](_0x0b5c('0x6d'))['toString'](),'sender':_0x2b3923[_0x0b5c('0x64')]==='out'?_0x2b3923[_0x0b5c('0x5c')]?_0x2b3923[_0x0b5c('0x5c')][_0x0b5c('0x5d')]:_0x0b5c('0x77'):_0x2b3923[_0x0b5c('0x5f')][_0x0b5c('0x60')]+(_0x2b3923[_0x0b5c('0x5f')][_0x0b5c('0x78')]?'\x20'+_0x2b3923['Contact'][_0x0b5c('0x78')]:''),'body':_0x2b3923[_0x0b5c('0x61')]?_0x2b3923[_0x0b5c('0x61')]['basename']:_0x2b3923[_0x0b5c('0x39')],'direction':_0x2b3923[_0x0b5c('0x64')]===_0x0b5c('0x79')?'A':'C','secret':_0x2b3923[_0x0b5c('0x65')],'read':_0x2b3923[_0x0b5c('0x66')],'attachment':_0x2b3923[_0x0b5c('0x61')]};})['value']()};return ejs[_0x0b5c('0x7a')](path['join'](config[_0x0b5c('0x57')],_0x0b5c('0x58'),_0x0b5c('0x7b'),_0x0b5c('0x7c')),{'interaction':_0x3bc028})[_0x0b5c('0x1c')](function(_0x23a6e9){var _0x4a9f31=path[_0x0b5c('0x56')](_0x4381ad,'transcript-'+_0x3ca102['id']+'-'+_0xc819f5+_0x0b5c('0x7d'));var _0x3e3da4={'path':_0x4a9f31,'channel':_0x0b5c('0x6c'),'interactionId':_0x3ca102['id']};return pdf[_0x0b5c('0x7e')](_0x23a6e9,_0x3e3da4);})[_0x0b5c('0x1c')](function(){return new Promise(function(_0x413bca,_0x1b161b){zipdir(_0x4381ad,{'saveTo':_0x53c6bd},function(_0x46a4fb,_0x28a2c1){if(_0x46a4fb)return _0x1b161b(_0x46a4fb);return _0x413bca(_0x28a2c1);});})[_0x0b5c('0x1c')](function(){return new Promise(function(_0x3034d4,_0x3bd988){rimraf(_0x4381ad,function(_0xbb73a0){if(_0xbb73a0)_0x3bd988(_0xbb73a0);return _0x3034d4();});});})[_0x0b5c('0x1c')](function(){return _0x571a39['download'](_0x53c6bd,_0x15ca7a,function(_0x268ecf){if(_0x268ecf){logger[_0x0b5c('0x7f')](_0x0b5c('0x80'),_0x268ecf);}else{fs[_0x0b5c('0x81')](_0x53c6bd);}});});});}else{return _0x571a39[_0x0b5c('0x12')](0xc8);}})[_0x0b5c('0x28')](handleError(_0x571a39,null));};
\ No newline at end of file
+var _0xb41e=['N.A.','createdAt','closed','closedAt','toString','disposition','Private','Attachment','basename','existsSync','createReadStream','pipe','createWriteStream','System','out','value','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','Unable\x20to\x20delete\x20zip\x20file','rimraf','moment','util','ejs','lodash','../../components/interaction/service','../../components/parsers/qs','api','../../config/environment','../../mysqldb','defaults','redis','./openchannelInteraction.socket','register','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','then','error','stack','name','send','index','map','OpenchannelInteraction','rawAttributes','fieldName','type','key','openchannel','query','catch','show','from','params','model','keys','intersection','attributes','fields','length','find','create','body','describe','addMessage','OpenchannelMessage','omit','ids','getMessages','filters','nolimit','order','sort','where','pick','filter','merge','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','include','findAll','rows','addTags','spread','Tag','color','emit','openchannelInteractionTags:save','removeTags','download','unix','root','server','files','tmp','join','transcript-%d-%s.zip','push','User','fullname','Contact','firstName','lastName','attachments','Messages','direction','secret','read','Account','Owner','get','mkdirSync','Openchannel'];(function(_0x32bcda,_0x156e9c){var _0x4e6191=function(_0xcbf3a0){while(--_0xcbf3a0){_0x32bcda['push'](_0x32bcda['shift']());}};_0x4e6191(++_0x156e9c);}(_0xb41e,0x93));var _0xeb41=function(_0x23882c,_0x29825f){_0x23882c=_0x23882c-0x0;var _0x2e2f05=_0xb41e[_0x23882c];return _0x2e2f05;};'use strict';var rimraf=require(_0xeb41('0x0'));var zipdir=require('zip-dir');var moment=require(_0xeb41('0x1'));var util=require(_0xeb41('0x2'));var path=require('path');var ejs=require(_0xeb41('0x3'));var fs=require('fs');var _=require(_0xeb41('0x4'));var Redis=require('ioredis');var interaction=require(_0xeb41('0x5'));var qs=require(_0xeb41('0x6'));var pdf=require('../../components/export/pdf');var logger=require('../../config/logger')(_0xeb41('0x7'));var config=require(_0xeb41('0x8'));var db=require(_0xeb41('0x9'))['db'];config['redis']=_[_0xeb41('0xa')](config[_0xeb41('0xb')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xeb41('0xc'))[_0xeb41('0xd')](socket);function respondWithStatusCode(_0x51bc45,_0x4dc8f6){_0x4dc8f6=_0x4dc8f6||0xcc;return function(_0x568487){if(_0x568487){return _0x51bc45[_0xeb41('0xe')](_0x4dc8f6);}return _0x51bc45['status'](_0x4dc8f6)[_0xeb41('0xf')]();};}function respondWithResult(_0x2bd962,_0x13eb4c){_0x13eb4c=_0x13eb4c||0xc8;return function(_0x44827d){if(_0x44827d){return _0x2bd962[_0xeb41('0x10')](_0x13eb4c)[_0xeb41('0x11')](_0x44827d);}};}function respondWithFilteredResult(_0x53458f,_0x1d7cab){return function(_0x5df582){if(_0x5df582){var _0x3ab41b=typeof _0x1d7cab[_0xeb41('0x12')]===_0xeb41('0x13')&&typeof _0x1d7cab[_0xeb41('0x14')]===_0xeb41('0x13');var _0x3c4a48=_0x5df582[_0xeb41('0x15')];var _0x17e5f0=_0x3ab41b?0x0:_0x1d7cab[_0xeb41('0x12')];var _0x73f7a8=_0x3ab41b?_0x5df582[_0xeb41('0x15')]:_0x1d7cab['offset']+_0x1d7cab[_0xeb41('0x14')];var _0x580209;if(_0x73f7a8>=_0x3c4a48){_0x73f7a8=_0x3c4a48;_0x580209=0xc8;}else{_0x580209=0xce;}_0x53458f[_0xeb41('0x10')](_0x580209);return _0x53458f[_0xeb41('0x16')](_0xeb41('0x17'),_0x17e5f0+'-'+_0x73f7a8+'/'+_0x3c4a48)[_0xeb41('0x11')](_0x5df582);}return null;};}function saveUpdates(_0x52039e){return function(_0x2787ff){if(_0x2787ff){return _0x2787ff[_0xeb41('0x18')](_0x52039e)['then'](function(_0x46f694){return _0x46f694;});}return null;};}function removeEntity(_0x394be7){return function(_0x3000aa){if(_0x3000aa){return _0x3000aa[_0xeb41('0x19')]()[_0xeb41('0x1a')](function(){_0x394be7[_0xeb41('0x10')](0xcc)[_0xeb41('0xf')]();});}};}function handleEntityNotFound(_0x277aa2){return function(_0x3d5a14){if(!_0x3d5a14){_0x277aa2[_0xeb41('0xe')](0x194);}return _0x3d5a14;};}function handleError(_0x14d195,_0x28bc5f){_0x28bc5f=_0x28bc5f||0x1f4;return function(_0x2d29ea){logger[_0xeb41('0x1b')](_0x2d29ea[_0xeb41('0x1c')]);if(_0x2d29ea[_0xeb41('0x1d')]){delete _0x2d29ea[_0xeb41('0x1d')];}_0x14d195['status'](_0x28bc5f)[_0xeb41('0x1e')](_0x2d29ea);};}exports[_0xeb41('0x1f')]=function(_0x22ba73,_0x5a6195){var _0x2e4719={};var _0x24682d=_[_0xeb41('0x20')](db[_0xeb41('0x21')][_0xeb41('0x22')],function(_0xd966bc){return{'name':_0xd966bc[_0xeb41('0x23')],'type':_0xd966bc[_0xeb41('0x24')][_0xeb41('0x25')]};});_0x2e4719=qs['getOptions'](_0x24682d,_0x22ba73);return interaction['findAll'](_0xeb41('0x26'),_0x22ba73[_0xeb41('0x27')],_0x22ba73['user'],_0x2e4719,_0x24682d)[_0xeb41('0x1a')](respondWithFilteredResult(_0x5a6195,_0x2e4719))[_0xeb41('0x28')](handleError(_0x5a6195,null));};exports[_0xeb41('0x29')]=function(_0x5463ec,_0xa0c498){var _0x5ad5c4={};if(_0x5463ec[_0xeb41('0x27')][_0xeb41('0x24')]&&_0x5463ec[_0xeb41('0x27')][_0xeb41('0x24')]==='from'){_0x5ad5c4[_0xeb41('0x2a')]=_0x5463ec[_0xeb41('0x2b')]['id'];}else{_0x5ad5c4['id']=_0x5463ec[_0xeb41('0x2b')]['id'];}var _0x28226d={'raw':![],'where':_0x5ad5c4},_0x595ee7={};_0x595ee7[_0xeb41('0x2c')]=_[_0xeb41('0x2d')](db['OpenchannelInteraction']['rawAttributes']);_0x595ee7['query']=_[_0xeb41('0x2d')](_0x5463ec[_0xeb41('0x27')]);_0x595ee7['filters']=_[_0xeb41('0x2e')](_0x595ee7['model'],_0x595ee7[_0xeb41('0x27')]);_0x28226d[_0xeb41('0x2f')]=_['intersection'](_0x595ee7[_0xeb41('0x2c')],qs[_0xeb41('0x30')](_0x5463ec[_0xeb41('0x27')]['fields']));_0x28226d['attributes']=_0x28226d[_0xeb41('0x2f')][_0xeb41('0x31')]?_0x28226d[_0xeb41('0x2f')]:_0x595ee7['model'];if(_0x5463ec[_0xeb41('0x27')]['includeAll']){_0x28226d['include']=[{'all':!![]}];}_0x28226d=_['merge']({},_0x28226d,_0x5463ec['options']);return db[_0xeb41('0x21')][_0xeb41('0x32')](_0x28226d)[_0xeb41('0x1a')](handleEntityNotFound(_0xa0c498,null))[_0xeb41('0x1a')](respondWithResult(_0xa0c498,null))['catch'](handleError(_0xa0c498,null));};exports[_0xeb41('0x33')]=function(_0x11fcbe,_0x7f8c08){return db[_0xeb41('0x21')][_0xeb41('0x33')](_0x11fcbe[_0xeb41('0x34')],{})[_0xeb41('0x1a')](respondWithResult(_0x7f8c08,0xc9))['catch'](handleError(_0x7f8c08,null));};exports[_0xeb41('0x18')]=function(_0x3763a8,_0x32d858){if(_0x3763a8['body']['id']){delete _0x3763a8[_0xeb41('0x34')]['id'];}return db[_0xeb41('0x21')]['find']({'where':{'id':_0x3763a8[_0xeb41('0x2b')]['id']}})['then'](handleEntityNotFound(_0x32d858,null))[_0xeb41('0x1a')](saveUpdates(_0x3763a8[_0xeb41('0x34')],null))[_0xeb41('0x1a')](respondWithResult(_0x32d858,null))['catch'](handleError(_0x32d858,null));};exports[_0xeb41('0x19')]=function(_0xecf132,_0x37f545){return db['OpenchannelInteraction']['find']({'where':{'id':_0xecf132[_0xeb41('0x2b')]['id']}})[_0xeb41('0x1a')](handleEntityNotFound(_0x37f545,null))[_0xeb41('0x1a')](removeEntity(_0x37f545,null))[_0xeb41('0x28')](handleError(_0x37f545,null));};exports[_0xeb41('0x35')]=function(_0xb9745,_0x4fa0e8){return db[_0xeb41('0x21')][_0xeb41('0x35')]()[_0xeb41('0x1a')](respondWithResult(_0x4fa0e8,null))[_0xeb41('0x28')](handleError(_0x4fa0e8,null));};exports[_0xeb41('0x36')]=function(_0x15f6e6,_0x51799a){return db[_0xeb41('0x37')][_0xeb41('0x32')]({'where':{'id':_0x15f6e6[_0xeb41('0x2b')]['id']}})[_0xeb41('0x1a')](handleEntityNotFound(_0x51799a,null))[_0xeb41('0x1a')](function(_0x22e171){if(_0x22e171){return _0x22e171[_0xeb41('0x36')](_0x15f6e6[_0xeb41('0x34')]['ids'],_[_0xeb41('0x38')](_0x15f6e6[_0xeb41('0x34')],[_0xeb41('0x39'),'id'])||{});}})[_0xeb41('0x1a')](respondWithResult(_0x51799a,null))['catch'](handleError(_0x51799a,null));};exports[_0xeb41('0x3a')]=function(_0x2dd518,_0x1e1371){var _0x2485e8={'raw':![],'where':{}};var _0x5edce3={};var _0x18f0f2={'count':0x0,'rows':[]};return db['OpenchannelInteraction']['findOne']({'where':{'id':_0x2dd518[_0xeb41('0x2b')]['id']}})['then'](handleEntityNotFound(_0x1e1371,null))['then'](function(_0xb23b58){if(_0xb23b58){_0x5edce3[_0xeb41('0x2c')]=_['keys'](db['OpenchannelMessage'][_0xeb41('0x22')]);_0x5edce3[_0xeb41('0x27')]=_[_0xeb41('0x2d')](_0x2dd518[_0xeb41('0x27')]);_0x5edce3[_0xeb41('0x3b')]=_[_0xeb41('0x2e')](_0x5edce3[_0xeb41('0x2c')],_0x5edce3[_0xeb41('0x27')]);_0x2485e8[_0xeb41('0x2f')]=_[_0xeb41('0x2e')](_0x5edce3[_0xeb41('0x2c')],qs['fields'](_0x2dd518['query'][_0xeb41('0x30')]));_0x2485e8['attributes']=_0x2485e8[_0xeb41('0x2f')][_0xeb41('0x31')]?_0x2485e8['attributes']:_0x5edce3[_0xeb41('0x2c')];if(!_0x2dd518['query']['hasOwnProperty'](_0xeb41('0x3c'))){_0x2485e8[_0xeb41('0x14')]=qs[_0xeb41('0x14')](_0x2dd518[_0xeb41('0x27')][_0xeb41('0x14')]);_0x2485e8['offset']=qs[_0xeb41('0x12')](_0x2dd518[_0xeb41('0x27')][_0xeb41('0x12')]);}_0x2485e8[_0xeb41('0x3d')]=qs[_0xeb41('0x3e')](_0x2dd518['query'][_0xeb41('0x3e')]);_0x2485e8[_0xeb41('0x3f')]=qs['filters'](_[_0xeb41('0x40')](_0x2dd518[_0xeb41('0x27')],_0x5edce3[_0xeb41('0x3b')]));_0x2485e8[_0xeb41('0x3f')]['OpenchannelInteractionId']=_0xb23b58['id'];if(_0x2dd518[_0xeb41('0x27')][_0xeb41('0x41')]){_0x2485e8['where']=_[_0xeb41('0x42')](_0x2485e8['where'],{'$or':_[_0xeb41('0x20')](_0x2485e8[_0xeb41('0x2f')],function(_0x15f9c0){var _0x48745f={};_0x48745f[_0x15f9c0]={'$like':'%'+_0x2dd518[_0xeb41('0x27')][_0xeb41('0x41')]+'%'};return _0x48745f;})});}if(_0x2dd518[_0xeb41('0x27')][_0xeb41('0x43')]){var _0x1583b0=_0x2dd518['query'][_0xeb41('0x43')][_0xeb41('0x44')](',');var _0x286dec={};_0x286dec[_0x1583b0[0x0]]={'$gte':moment(_0x1583b0[0x1])[_0xeb41('0x45')](_0xeb41('0x46'))};_0x2485e8[_0xeb41('0x3f')]=_['merge'](_0x2485e8[_0xeb41('0x3f')],_0x286dec);}_0x2485e8=_[_0xeb41('0x42')]({},_0x2485e8,_0x2dd518['options']);return db[_0xeb41('0x37')][_0xeb41('0x15')]({'where':_0x2485e8['where']})[_0xeb41('0x1a')](function(_0x493434){_0x18f0f2['count']=_0x493434;if(_0x2dd518[_0xeb41('0x27')]['includeAll']){_0x2485e8[_0xeb41('0x47')]=[{'all':!![]}];}return db[_0xeb41('0x37')][_0xeb41('0x48')](_0x2485e8);})[_0xeb41('0x1a')](function(_0x211784){_0x18f0f2[_0xeb41('0x49')]=_0x211784;return _0x18f0f2;});}})['then'](respondWithFilteredResult(_0x1e1371,_0x2485e8))[_0xeb41('0x28')](handleError(_0x1e1371,null));};exports[_0xeb41('0x4a')]=function(_0x41759f,_0x44f9df){return db['OpenchannelInteraction']['find']({'where':{'id':_0x41759f['params']['id']}})['then'](handleEntityNotFound(_0x44f9df,null))[_0xeb41('0x1a')](function(_0x27c637){if(_0x27c637){return _0x27c637['setTags'](_0x41759f[_0xeb41('0x34')][_0xeb41('0x39')],_[_0xeb41('0x38')](_0x41759f[_0xeb41('0x34')],['ids','id'])||{})[_0xeb41('0x4b')](function(){return db[_0xeb41('0x4c')][_0xeb41('0x48')]({'attributes':['id',_0xeb41('0x1d'),_0xeb41('0x4d')],'where':{'id':_0x41759f[_0xeb41('0x34')][_0xeb41('0x39')]}});})[_0xeb41('0x1a')](function(_0x43d0d0){socket[_0xeb41('0x4e')](_0xeb41('0x4f'),{'id':Number(_0x41759f[_0xeb41('0x2b')]['id']),'tags':_0x43d0d0||[]});return{'id':Number(_0x41759f[_0xeb41('0x2b')]['id']),'tags':_0x43d0d0||[]};});}})['then'](respondWithResult(_0x44f9df,null))[_0xeb41('0x28')](handleError(_0x44f9df,null));};exports[_0xeb41('0x50')]=function(_0x370c13,_0x46ae75){return db[_0xeb41('0x21')][_0xeb41('0x32')]({'where':{'id':_0x370c13[_0xeb41('0x2b')]['id']}})['then'](handleEntityNotFound(_0x46ae75,null))[_0xeb41('0x1a')](function(_0xc615cc){if(_0xc615cc){return _0xc615cc[_0xeb41('0x50')](_0x370c13[_0xeb41('0x27')]['ids']);}})[_0xeb41('0x1a')](respondWithStatusCode(_0x46ae75,null))[_0xeb41('0x28')](handleError(_0x46ae75,null));};exports[_0xeb41('0x51')]=function(_0x2ff436,_0x27da16){var _0x16f7be=moment()[_0xeb41('0x52')]()['toString']();var _0x17da7e=path['join'](config[_0xeb41('0x53')],_0xeb41('0x54'),_0xeb41('0x55'),_0xeb41('0x56'));var _0x586936=path[_0xeb41('0x57')](config[_0xeb41('0x53')],'server',_0xeb41('0x55'),'attachments');var _0x71d2f2=path[_0xeb41('0x57')](_0x17da7e,_0x16f7be);var _0x272c08=util[_0xeb41('0x45')](_0xeb41('0x58'),_0x2ff436[_0xeb41('0x2b')]['id'],_0x16f7be);var _0x57be94=path['join'](_0x17da7e,_0x272c08);var _0x1eebde=[];_0x1eebde[_0xeb41('0x59')]({'model':db['User'],'as':_0xeb41('0x5a'),'attributes':['id',_0xeb41('0x5b')],'raw':!![]});_0x1eebde[_0xeb41('0x59')]({'model':db['CmContact'],'as':_0xeb41('0x5c'),'attributes':['id',_0xeb41('0x5d'),_0xeb41('0x5e')],'raw':!![]});if(_0x2ff436[_0xeb41('0x27')][_0xeb41('0x5f')]){_0x1eebde[_0xeb41('0x59')]({'model':db['Attachment'],'as':'Attachment','raw':!![]});}var _0x146908=[{'model':db[_0xeb41('0x37')],'as':_0xeb41('0x60'),'attributes':['id',_0xeb41('0x34'),'createdAt',_0xeb41('0x61'),_0xeb41('0x62'),_0xeb41('0x63')],'include':_0x1eebde}];_0x146908[_0xeb41('0x59')]({'model':db['OpenchannelAccount'],'as':_0xeb41('0x64'),'attributes':['id',_0xeb41('0x1d')]});_0x146908[_0xeb41('0x59')]({'model':db[_0xeb41('0x5a')],'as':_0xeb41('0x65'),'attributes':['id','fullname']});return db[_0xeb41('0x21')]['find']({'where':{'id':_0x2ff436['params']['id']},'include':_0x146908})['then'](handleEntityNotFound(_0x27da16,null))[_0xeb41('0x1a')](function(_0x22a242){if(_0x22a242){var _0x192625=_0x22a242[_0xeb41('0x66')]({'plain':!![]});fs[_0xeb41('0x67')](_0x71d2f2);var _0x1e8c1d={'channel':_0xeb41('0x68'),'account':_0x192625[_0xeb41('0x64')]['name'],'agent':_0x192625['Owner']?_0x192625['Owner'][_0xeb41('0x5b')]:_0xeb41('0x69'),'createdAt':moment(_0x192625[_0xeb41('0x6a')])['format'](_0xeb41('0x46'))['toString'](),'closedAt':_0x192625[_0xeb41('0x6b')]?moment(_0x192625[_0xeb41('0x6c')])[_0xeb41('0x45')](_0xeb41('0x46'))[_0xeb41('0x6d')]():'','disposition':_0x192625[_0xeb41('0x6e')],'visibility':_0x192625['threadId']?'Public':_0xeb41('0x6f'),'messages':_(_0x192625[_0xeb41('0x60')])[_0xeb41('0x41')]({'secret':![]})[_0xeb41('0x20')](function(_0x49a2a2){if(_0x49a2a2[_0xeb41('0x70')]){var _0x21da42=path[_0xeb41('0x57')](_0x586936,_0x49a2a2['Attachment'][_0xeb41('0x71')]);if(fs[_0xeb41('0x72')](_0x21da42)){fs[_0xeb41('0x73')](_0x21da42)[_0xeb41('0x74')](fs[_0xeb41('0x75')](path[_0xeb41('0x57')](_0x71d2f2,_0x49a2a2[_0xeb41('0x70')][_0xeb41('0x71')])));}}return{'date':moment(_0x49a2a2[_0xeb41('0x6a')])['format'](_0xeb41('0x46'))[_0xeb41('0x6d')](),'sender':_0x49a2a2[_0xeb41('0x61')]==='out'?_0x49a2a2['User']?_0x49a2a2[_0xeb41('0x5a')][_0xeb41('0x5b')]:_0xeb41('0x76'):_0x49a2a2[_0xeb41('0x5c')][_0xeb41('0x5d')]+(_0x49a2a2['Contact'][_0xeb41('0x5e')]?'\x20'+_0x49a2a2['Contact']['lastName']:''),'body':_0x49a2a2[_0xeb41('0x70')]?_0x49a2a2['Attachment'][_0xeb41('0x71')]:_0x49a2a2[_0xeb41('0x34')],'direction':_0x49a2a2['direction']===_0xeb41('0x77')?'A':'C','secret':_0x49a2a2['secret'],'read':_0x49a2a2[_0xeb41('0x63')],'attachment':_0x49a2a2[_0xeb41('0x70')]};})[_0xeb41('0x78')]()};return ejs['renderFile'](path[_0xeb41('0x57')](config[_0xeb41('0x53')],_0xeb41('0x54'),'views',_0xeb41('0x79')),{'interaction':_0x1e8c1d})[_0xeb41('0x1a')](function(_0x407c49){var _0x4c98c5=path[_0xeb41('0x57')](_0x71d2f2,_0xeb41('0x7a')+_0x192625['id']+'-'+_0x16f7be+_0xeb41('0x7b'));var _0x31d9eb={'path':_0x4c98c5,'channel':_0xeb41('0x68'),'interactionId':_0x192625['id']};return pdf[_0xeb41('0x7c')](_0x407c49,_0x31d9eb);})[_0xeb41('0x1a')](function(){return new Promise(function(_0xc6263a,_0x2b6b16){zipdir(_0x71d2f2,{'saveTo':_0x57be94},function(_0xdd83ed,_0x1d9406){if(_0xdd83ed)return _0x2b6b16(_0xdd83ed);return _0xc6263a(_0x1d9406);});})[_0xeb41('0x1a')](function(){return new Promise(function(_0x361e55,_0x1dc752){rimraf(_0x71d2f2,function(_0x2a043d){if(_0x2a043d)_0x1dc752(_0x2a043d);return _0x361e55();});});})[_0xeb41('0x1a')](function(){return _0x27da16[_0xeb41('0x51')](_0x57be94,_0x272c08,function(_0xf6efc7){if(_0xf6efc7){logger[_0xeb41('0x1b')](_0xeb41('0x7d'),_0xf6efc7);}else{fs['unlinkSync'](_0x57be94);}});});});}else{return _0x27da16[_0xeb41('0xe')](0xc8);}})[_0xeb41('0x28')](handleError(_0x27da16,null));};
\ No newline at end of file