18 var _0x992a=['util','path','ejs','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','./smsInteraction.socket','register','sendStatus','status','offset','undefined','count','limit','set','Content-Range','json','update','then','destroy','end','error','stack','name','index','map','SmsInteraction','rawAttributes','type','key','getOptions','findAll','sms','query','catch','show','params','keys','filters','intersection','model','attributes','fields','length','includeAll','include','find','create','body','describe','SmsMessage','addMessage','ids','omit','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','pick','SmsInteractionId','merge','filter','$gte','split','format','options','rows','addTags','setTags','emit','smsInteractionTags:save','removeTags','download','toString','join','files','tmp','transcript-%d-%s.zip','push','User','CmContact','Contact','Messages','direction','read','SmsAccount','Account','fullname','get','mkdirSync','Sms','Owner','N.A.','createdAt','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','disposition','out','System','firstName','lastName','secret','renderFile','root','views','transcript-','.pdf','unlinkSync','rimraf','zip-dir','moment','bluebird'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x992a,0x1e8));var _0xa992=function(_0x257642,_0x270a80){_0x257642=_0x257642-0x0;var _0x3d813b=_0x992a[_0x257642];return _0x3d813b;};'use strict';var rimraf=require(_0xa992('0x0'));var zipdir=require(_0xa992('0x1'));var moment=require(_0xa992('0x2'));var BPromise=require(_0xa992('0x3'));var util=require(_0xa992('0x4'));var path=require(_0xa992('0x5'));var ejs=require(_0xa992('0x6'));var fs=require('fs');var _=require('lodash');var Redis=require(_0xa992('0x7'));var interaction=require(_0xa992('0x8'));var qs=require(_0xa992('0x9'));var pdf=require(_0xa992('0xa'));var logger=require(_0xa992('0xb'))(_0xa992('0xc'));var config=require(_0xa992('0xd'));var db=require(_0xa992('0xe'))['db'];config[_0xa992('0xf')]=_[_0xa992('0x10')](config[_0xa992('0xf')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa992('0xf')]));require(_0xa992('0x11'))[_0xa992('0x12')](socket);function respondWithStatusCode(_0x12fd22,_0x225983){_0x225983=_0x225983||0xcc;return function(_0x59dcf1){if(_0x59dcf1){return _0x12fd22[_0xa992('0x13')](_0x225983);}return _0x12fd22['status'](_0x225983)['end']();};}function respondWithResult(_0x258cc8,_0x24579f){_0x24579f=_0x24579f||0xc8;return function(_0xb346d6){if(_0xb346d6){return _0x258cc8[_0xa992('0x14')](_0x24579f)['json'](_0xb346d6);}};}function respondWithFilteredResult(_0x11a8df,_0x509c5b){return function(_0x43b0f6){if(_0x43b0f6){var _0x4a0b92=typeof _0x509c5b[_0xa992('0x15')]===_0xa992('0x16')&&typeof _0x509c5b['limit']===_0xa992('0x16');var _0x4ab3a6=_0x43b0f6[_0xa992('0x17')];var _0x252e5c=_0x4a0b92?0x0:_0x509c5b[_0xa992('0x15')];var _0x12f023=_0x4a0b92?_0x43b0f6[_0xa992('0x17')]:_0x509c5b[_0xa992('0x15')]+_0x509c5b[_0xa992('0x18')];var _0x1232f4;if(_0x12f023>=_0x4ab3a6){_0x12f023=_0x4ab3a6;_0x1232f4=0xc8;}else{_0x1232f4=0xce;}_0x11a8df[_0xa992('0x14')](_0x1232f4);return _0x11a8df[_0xa992('0x19')](_0xa992('0x1a'),_0x252e5c+'-'+_0x12f023+'/'+_0x4ab3a6)[_0xa992('0x1b')](_0x43b0f6);}return null;};}function saveUpdates(_0x300070){return function(_0x377d82){if(_0x377d82){return _0x377d82[_0xa992('0x1c')](_0x300070)[_0xa992('0x1d')](function(_0x4c88f6){return _0x4c88f6;});}return null;};}function removeEntity(_0x5c4948){return function(_0x35a1ec){if(_0x35a1ec){return _0x35a1ec[_0xa992('0x1e')]()[_0xa992('0x1d')](function(){_0x5c4948['status'](0xcc)[_0xa992('0x1f')]();});}};}function handleEntityNotFound(_0x4e2c41){return function(_0x1921fb){if(!_0x1921fb){_0x4e2c41[_0xa992('0x13')](0x194);}return _0x1921fb;};}function handleError(_0x4040d1,_0x493de2){_0x493de2=_0x493de2||0x1f4;return function(_0xb4fb29){logger[_0xa992('0x20')](_0xb4fb29[_0xa992('0x21')]);if(_0xb4fb29[_0xa992('0x22')]){delete _0xb4fb29['name'];}_0x4040d1['status'](_0x493de2)['send'](_0xb4fb29);};}exports[_0xa992('0x23')]=function(_0x2dcfe6,_0x49fcca){var _0x48c4fd={};var _0x498ab0=_[_0xa992('0x24')](db[_0xa992('0x25')][_0xa992('0x26')],function(_0x393c02){return{'name':_0x393c02['fieldName'],'type':_0x393c02[_0xa992('0x27')][_0xa992('0x28')]};});_0x48c4fd=qs[_0xa992('0x29')](_0x498ab0,_0x2dcfe6);return interaction[_0xa992('0x2a')](_0xa992('0x2b'),_0x2dcfe6[_0xa992('0x2c')],_0x2dcfe6['user'],_0x48c4fd,_0x498ab0)[_0xa992('0x1d')](respondWithFilteredResult(_0x49fcca,_0x48c4fd))[_0xa992('0x2d')](handleError(_0x49fcca,null));};exports[_0xa992('0x2e')]=function(_0x25af99,_0x34c96d){var _0x902089={'raw':![],'where':{'id':_0x25af99[_0xa992('0x2f')]['id']}},_0x68baef={};_0x68baef['model']=_[_0xa992('0x30')](db[_0xa992('0x25')][_0xa992('0x26')]);_0x68baef[_0xa992('0x2c')]=_[_0xa992('0x30')](_0x25af99['query']);_0x68baef[_0xa992('0x31')]=_[_0xa992('0x32')](_0x68baef[_0xa992('0x33')],_0x68baef['query']);_0x902089[_0xa992('0x34')]=_[_0xa992('0x32')](_0x68baef[_0xa992('0x33')],qs[_0xa992('0x35')](_0x25af99[_0xa992('0x2c')][_0xa992('0x35')]));_0x902089[_0xa992('0x34')]=_0x902089[_0xa992('0x34')][_0xa992('0x36')]?_0x902089[_0xa992('0x34')]:_0x68baef[_0xa992('0x33')];if(_0x25af99[_0xa992('0x2c')][_0xa992('0x37')]){_0x902089[_0xa992('0x38')]=[{'all':!![]}];}_0x902089=_['merge']({},_0x902089,_0x25af99['options']);return db[_0xa992('0x25')][_0xa992('0x39')](_0x902089)['then'](handleEntityNotFound(_0x34c96d,null))[_0xa992('0x1d')](respondWithResult(_0x34c96d,null))[_0xa992('0x2d')](handleError(_0x34c96d,null));};exports['create']=function(_0x3643a0,_0x3d6102){return db[_0xa992('0x25')][_0xa992('0x3a')](_0x3643a0[_0xa992('0x3b')],{})[_0xa992('0x1d')](respondWithResult(_0x3d6102,0xc9))[_0xa992('0x2d')](handleError(_0x3d6102,null));};exports['update']=function(_0x1e11c4,_0x115bb5){if(_0x1e11c4['body']['id']){delete _0x1e11c4[_0xa992('0x3b')]['id'];}return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x1e11c4[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x115bb5,null))['then'](saveUpdates(_0x1e11c4[_0xa992('0x3b')],null))[_0xa992('0x1d')](respondWithResult(_0x115bb5,null))[_0xa992('0x2d')](handleError(_0x115bb5,null));};exports[_0xa992('0x1e')]=function(_0x4af7d9,_0xb7dbb0){return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x4af7d9['params']['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0xb7dbb0,null))['then'](removeEntity(_0xb7dbb0,null))['catch'](handleError(_0xb7dbb0,null));};exports[_0xa992('0x3c')]=function(_0x52b363,_0x533805){return db[_0xa992('0x25')]['describe']()[_0xa992('0x1d')](respondWithResult(_0x533805,null))[_0xa992('0x2d')](handleError(_0x533805,null));};exports['addMessage']=function(_0x521e5c,_0x519bac){return db[_0xa992('0x3d')][_0xa992('0x39')]({'where':{'id':_0x521e5c[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x519bac,null))['then'](function(_0x251843){if(_0x251843){return _0x251843[_0xa992('0x3e')](_0x521e5c['body'][_0xa992('0x3f')],_[_0xa992('0x40')](_0x521e5c['body'],[_0xa992('0x3f'),'id'])||{});}})[_0xa992('0x1d')](respondWithResult(_0x519bac,null))[_0xa992('0x2d')](handleError(_0x519bac,null));};exports[_0xa992('0x41')]=function(_0x1e625e,_0x1810fe){var _0x4bfa61={'raw':![],'where':{}};var _0x181649={};var _0x22ecd1={'count':0x0,'rows':[]};return db[_0xa992('0x25')][_0xa992('0x42')]({'where':{'id':_0x1e625e[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x1810fe,null))[_0xa992('0x1d')](function(_0x40155c){if(_0x40155c){_0x181649[_0xa992('0x33')]=_[_0xa992('0x30')](db[_0xa992('0x3d')]['rawAttributes']);_0x181649[_0xa992('0x2c')]=_[_0xa992('0x30')](_0x1e625e[_0xa992('0x2c')]);_0x181649[_0xa992('0x31')]=_[_0xa992('0x32')](_0x181649[_0xa992('0x33')],_0x181649[_0xa992('0x2c')]);_0x4bfa61['attributes']=_['intersection'](_0x181649['model'],qs[_0xa992('0x35')](_0x1e625e[_0xa992('0x2c')][_0xa992('0x35')]));_0x4bfa61[_0xa992('0x34')]=_0x4bfa61[_0xa992('0x34')]['length']?_0x4bfa61[_0xa992('0x34')]:_0x181649[_0xa992('0x33')];if(!_0x1e625e['query'][_0xa992('0x43')](_0xa992('0x44'))){_0x4bfa61[_0xa992('0x18')]=qs[_0xa992('0x18')](_0x1e625e[_0xa992('0x2c')]['limit']);_0x4bfa61[_0xa992('0x15')]=qs[_0xa992('0x15')](_0x1e625e['query'][_0xa992('0x15')]);}_0x4bfa61[_0xa992('0x45')]=qs[_0xa992('0x46')](_0x1e625e[_0xa992('0x2c')][_0xa992('0x46')]);_0x4bfa61[_0xa992('0x47')]=qs[_0xa992('0x31')](_[_0xa992('0x48')](_0x1e625e[_0xa992('0x2c')],_0x181649[_0xa992('0x31')]));_0x4bfa61[_0xa992('0x47')][_0xa992('0x49')]=_0x40155c['id'];if(_0x1e625e[_0xa992('0x2c')]['filter']){_0x4bfa61[_0xa992('0x47')]=_[_0xa992('0x4a')](_0x4bfa61[_0xa992('0x47')],{'$or':_[_0xa992('0x24')](_0x4bfa61[_0xa992('0x34')],function(_0x21c07e){var _0x4e815e={};_0x4e815e[_0x21c07e]={'$like':'%'+_0x1e625e[_0xa992('0x2c')][_0xa992('0x4b')]+'%'};return _0x4e815e;})});}if(_0x1e625e['query'][_0xa992('0x4c')]){var _0x29e6f2=_0x1e625e['query'][_0xa992('0x4c')][_0xa992('0x4d')](',');var _0x3fdfab={};_0x3fdfab[_0x29e6f2[0x0]]={'$gte':moment(_0x29e6f2[0x1])[_0xa992('0x4e')]('YYYY-MM-DD\x20HH:mm:ss')};_0x4bfa61[_0xa992('0x47')]=_['merge'](_0x4bfa61[_0xa992('0x47')],_0x3fdfab);}_0x4bfa61=_[_0xa992('0x4a')]({},_0x4bfa61,_0x1e625e[_0xa992('0x4f')]);return db[_0xa992('0x3d')]['count']({'where':_0x4bfa61['where']})[_0xa992('0x1d')](function(_0x5a99bc){_0x22ecd1['count']=_0x5a99bc;if(_0x1e625e[_0xa992('0x2c')][_0xa992('0x37')]){_0x4bfa61[_0xa992('0x38')]=[{'all':!![]}];}return db[_0xa992('0x3d')][_0xa992('0x2a')](_0x4bfa61);})[_0xa992('0x1d')](function(_0x52f46f){_0x22ecd1[_0xa992('0x50')]=_0x52f46f;return _0x22ecd1;});}})[_0xa992('0x1d')](respondWithFilteredResult(_0x1810fe,_0x4bfa61))[_0xa992('0x2d')](handleError(_0x1810fe,null));};exports[_0xa992('0x51')]=function(_0x39d69f,_0x2227ab){return db['SmsInteraction']['find']({'where':{'id':_0x39d69f[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x2227ab,null))['then'](function(_0x3a7a46){if(_0x3a7a46){return _0x3a7a46[_0xa992('0x52')](_0x39d69f[_0xa992('0x3b')][_0xa992('0x3f')],_[_0xa992('0x40')](_0x39d69f[_0xa992('0x3b')],[_0xa992('0x3f'),'id'])||{})['spread'](function(){return db['Tag'][_0xa992('0x2a')]({'attributes':['id','name','color'],'where':{'id':_0x39d69f[_0xa992('0x3b')][_0xa992('0x3f')]}});})[_0xa992('0x1d')](function(_0x2294f3){socket[_0xa992('0x53')](_0xa992('0x54'),{'id':Number(_0x39d69f['params']['id']),'tags':_0x2294f3||[]});return{'id':Number(_0x39d69f[_0xa992('0x2f')]['id']),'tags':_0x2294f3||[]};});}})['then'](respondWithResult(_0x2227ab,null))[_0xa992('0x2d')](handleError(_0x2227ab,null));};exports[_0xa992('0x55')]=function(_0x5a9ed9,_0x5210bb){return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x5a9ed9[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x5210bb,null))[_0xa992('0x1d')](function(_0x362de5){if(_0x362de5){return _0x362de5['removeTags'](_0x5a9ed9[_0xa992('0x2c')][_0xa992('0x3f')]);}})[_0xa992('0x1d')](respondWithStatusCode(_0x5210bb,null))[_0xa992('0x2d')](handleError(_0x5210bb,null));};exports[_0xa992('0x56')]=function(_0xc7456f,_0x23d284){var _0x5c0e1f=moment()['unix']()[_0xa992('0x57')]();var _0x758b3c=path[_0xa992('0x58')](config['root'],'server',_0xa992('0x59'),_0xa992('0x5a'));var _0x43f595=path[_0xa992('0x58')](_0x758b3c,_0x5c0e1f);var _0x2bded0=util['format'](_0xa992('0x5b'),_0xc7456f[_0xa992('0x2f')]['id'],_0x5c0e1f);var _0x3e835c=path['join'](_0x758b3c,_0x2bded0);var _0x3ef622=[];_0x3ef622[_0xa992('0x5c')]({'model':db[_0xa992('0x5d')],'as':_0xa992('0x5d'),'attributes':['id','fullname'],'raw':!![]});_0x3ef622[_0xa992('0x5c')]({'model':db[_0xa992('0x5e')],'as':_0xa992('0x5f'),'attributes':['id','firstName','lastName'],'raw':!![]});var _0xf76f23=[{'model':db[_0xa992('0x3d')],'as':_0xa992('0x60'),'attributes':['id',_0xa992('0x3b'),'createdAt',_0xa992('0x61'),'secret',_0xa992('0x62')],'include':_0x3ef622}];_0xf76f23[_0xa992('0x5c')]({'model':db[_0xa992('0x63')],'as':_0xa992('0x64'),'attributes':['id',_0xa992('0x22')]});_0xf76f23['push']({'model':db[_0xa992('0x5d')],'as':'Owner','attributes':['id',_0xa992('0x65')]});return db['SmsInteraction'][_0xa992('0x39')]({'where':{'id':_0xc7456f['params']['id']},'include':_0xf76f23})[_0xa992('0x1d')](handleEntityNotFound(_0x23d284,null))['then'](function(_0x322448){if(_0x322448){var _0x586383=_0x322448[_0xa992('0x66')]({'plain':!![]});fs[_0xa992('0x67')](_0x43f595);var _0x1dd588={'channel':_0xa992('0x68'),'account':_0x586383[_0xa992('0x64')][_0xa992('0x22')],'agent':_0x586383[_0xa992('0x69')]?_0x586383[_0xa992('0x69')]['fullname']:_0xa992('0x6a'),'createdAt':moment(_0x586383[_0xa992('0x6b')])[_0xa992('0x4e')](_0xa992('0x6c'))[_0xa992('0x57')](),'closedAt':_0x586383[_0xa992('0x6d')]?moment(_0x586383[_0xa992('0x6e')])[_0xa992('0x4e')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x586383[_0xa992('0x6f')],'messages':_(_0x586383[_0xa992('0x60')])['filter']({'secret':![]})[_0xa992('0x24')](function(_0x389440){return{'date':moment(_0x389440[_0xa992('0x6b')])[_0xa992('0x4e')](_0xa992('0x6c'))['toString'](),'sender':_0x389440['direction']===_0xa992('0x70')?_0x389440[_0xa992('0x5d')]?_0x389440[_0xa992('0x5d')][_0xa992('0x65')]:_0xa992('0x71'):_0x389440[_0xa992('0x5f')][_0xa992('0x72')]+(_0x389440['Contact'][_0xa992('0x73')]?'\x20'+_0x389440[_0xa992('0x5f')]['lastName']:''),'body':_0x389440[_0xa992('0x3b')],'direction':_0x389440['direction']===_0xa992('0x70')?'A':'C','secret':_0x389440[_0xa992('0x74')],'read':_0x389440[_0xa992('0x62')]};})['value']()};return ejs[_0xa992('0x75')](path[_0xa992('0x58')](config[_0xa992('0x76')],'server',_0xa992('0x77'),'downloadInteraction.ejs'),{'interaction':_0x1dd588})[_0xa992('0x1d')](function(_0x452f01){var _0x596893=path[_0xa992('0x58')](_0x43f595,_0xa992('0x78')+_0x586383['id']+'-'+_0x5c0e1f+_0xa992('0x79'));var _0x14907f={'path':_0x596893,'channel':_0xa992('0x68'),'interactionId':_0x586383['id']};return pdf['createPdfFromHTML'](_0x452f01,_0x14907f);})['then'](function(){return new BPromise(function(_0x1a7c44,_0x19cb8){zipdir(_0x43f595,{'saveTo':_0x3e835c},function(_0x15b516,_0x59a0fc){if(_0x15b516)return _0x19cb8(_0x15b516);return _0x1a7c44(_0x59a0fc);});})['then'](function(){return new BPromise(function(_0x43a233,_0x166072){rimraf(_0x43f595,function(_0x4a0a05){if(_0x4a0a05)_0x166072(_0x4a0a05);return _0x43a233();});});})[_0xa992('0x1d')](function(){return _0x23d284['download'](_0x3e835c,_0x2bded0,function(_0x50c375){if(_0x50c375){console['log']('err',_0x50c375);}else{fs[_0xa992('0x7a')](_0x3e835c);}});});});}else{return _0x23d284[_0xa992('0x13')](0xc8);}})[_0xa992('0x2d')](handleError(_0x23d284,null));};