3fa62e07d8487800a29b85efa5e67af38b18ddd5
[motion2.git] / server / components / extensions / rewrite.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x153f=['filter','groupBy','queue','playback','hasOwnProperty','extensions','extension','find','push','type','Set','CDR(type)=%s','context','priority','VoiceExtensionId','outbound','CDR(destination)=','cutdigits','${EXTEN:','CDR(routeid)=','ExecIf','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-PROGRESS=0','length','toLowerCase','createdAt','updatedAt','interval','*,*,*,*','tag','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','app','custom','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','destroy','bulkCreate','sortBy','catch','error','rewrite','lodash','util','models','Interval','then','intervals','VoiceExtension','findAll','IntervalId','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)'];(function(_0xcd384d,_0x2672cb){var _0x49c0c0=function(_0x15d033){while(--_0x15d033){_0xcd384d['push'](_0xcd384d['shift']());}};_0x49c0c0(++_0x2672cb);}(_0x153f,0x15b));var _0xf153=function(_0x5dffc5,_0x6e84e6){_0x5dffc5=_0x5dffc5-0x0;var _0x206712=_0x153f[_0x5dffc5];return _0x206712;};'use strict';var _=require(_0xf153('0x0'));var util=require(_0xf153('0x1'));function rewrite(_0xde7eae,_0x44cea3){var _0x2afb9a=this;return _0xde7eae[_0xf153('0x2')][_0xf153('0x3')]['findAll']({'raw':!![]})[_0xf153('0x4')](function(_0x5c49c7){_0x2afb9a[_0xf153('0x5')]=_0x5c49c7;return _0xde7eae[_0xf153('0x2')][_0xf153('0x6')][_0xf153('0x7')]({'where':{'IntervalId':_0x44cea3[_0xf153('0x8')]},'raw':!![]});})['then'](function(_0x17ba96){return _0xde7eae[_0xf153('0x2')][_0xf153('0x6')][_0xf153('0x7')]({'where':{'exten':{'$in':_[_0xf153('0x9')](_[_0xf153('0xa')](_0x17ba96,_0xf153('0xb')))}},'order':[{'raw':_0xf153('0xc')}],'raw':!![]});})[_0xf153('0x4')](function(_0xeaccb0){var _0x5c8ae9=_[_0xf153('0xd')](_0xeaccb0,{'priority':'1'});var _0x1c8de7=_[_0xf153('0xd')](_0xeaccb0,{'isApp':0x1});var _0x493324=_[_0xf153('0xe')](_0x1c8de7,_0xf153('0xb'));var _0x65756d=[_0xf153('0xf'),_0xf153('0x10')];var _0x107d31=[];var _0x3f915c=[];for(var _0x1d54c4 in _0x493324){if(_0x493324[_0xf153('0x11')](_0x1d54c4)){_0x2afb9a['priority']=0x2;_0x2afb9a[_0xf153('0x12')]=[];_0x2afb9a[_0xf153('0x13')]=_[_0xf153('0x14')](_0x5c8ae9,{'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')]});_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':util['format'](_0xf153('0x18'),_0x493324[_0x1d54c4][0x0]['type']),'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});if(_0x493324[_0x1d54c4][0x0]['type']===_0xf153('0x1c')){if(_0x2afb9a[_0xf153('0x13')]){_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x1d')+(_0x2afb9a[_0xf153('0x13')][_0xf153('0x1e')]?_0xf153('0x1f')+_0x2afb9a[_0xf153('0x13')][_0xf153('0x1e')]+'}':'${EXTEN}'),'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});}_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x20')+_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')],'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});var _0xe490f8=_0x2afb9a[_0xf153('0x1a')]++;_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x21'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0xe490f8+0x2)+_0xf153('0x22')+(_0xe490f8+0x1)+')','context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0]['exten'],'priority':_0xe490f8,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});if(_0x2afb9a[_0xf153('0x13')]){_0x2afb9a['extensions'][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0x2afb9a[_0xf153('0x13')][_0xf153('0x1e')]?_0xf153('0x23')+_0x2afb9a[_0xf153('0x13')][_0xf153('0x1e')]+'}':_0xf153('0x24'),'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0]['VoiceExtensionId']});}_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':'outboundrouteid='+_0x493324[_0x1d54c4][0x0]['VoiceExtensionId'],'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0]['exten'],'priority':_0x2afb9a['priority']++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});if(_0x2afb9a['extension']&&_0x2afb9a[_0xf153('0x13')]['hasOwnProperty'](_0xf153('0x25'))&&_0x2afb9a[_0xf153('0x13')]['recordingFormat']!==_0xf153('0x26')){_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x27'),'context':_0x493324[_0x1d54c4][0x0]['context'],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a['priority']++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x28')+_0x2afb9a['extension'][_0xf153('0x25')]||_0xf153('0x29'),'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0]['exten'],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});}}_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a['priority']++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x2a'),'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'exten':_0x493324[_0x1d54c4][0x0]['exten'],'priority':_0x2afb9a[_0xf153('0x1a')]++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});_0x2afb9a[_0xf153('0x12')][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':'MONITOR_OPTIONS=ab','context':_0x493324[_0x1d54c4][0x0]['context'],'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'priority':_0x2afb9a['priority']++,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});for(var _0x36c456=0x0,_0x31ec0f=0x0;_0x36c456<_0x493324[_0x1d54c4][_0xf153('0x2b')];_0x36c456+=0x1,_0x31ec0f=0x0){var _0xd516d0=_0x493324[_0x1d54c4][_0x36c456];if(_0xd516d0[_0xf153('0x16')]){_0xd516d0['type']=_0xd516d0['type'][_0xf153('0x2c')]();}var _0x25960d=[];var _0x4a7712=[];delete _0xd516d0['id'];delete _0xd516d0[_0xf153('0x2d')];delete _0xd516d0[_0xf153('0x2e')];var _0x1edf65=_0xd516d0[_0xf153('0x2f')]!==_0xf153('0x30')?[_0xd516d0[_0xf153('0x2f')]]:_0xd516d0[_0xf153('0x8')]?_[_0xf153('0xa')](_[_0xf153('0xd')](_0x2afb9a[_0xf153('0x5')],{'IntervalId':_0xd516d0[_0xf153('0x8')]}),_0xf153('0x2f')):[];if(_0xd516d0['hasOwnProperty'](_0xf153('0x31'))){if(_0xd516d0[_0xf153('0x31')]&&_0xd516d0[_0xf153('0x31')]!=='--'){_0x25960d['push']({'type':_0xd516d0[_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':'CDR(tag)='+_0xd516d0[_0xf153('0x31')],'context':_0xd516d0['context'],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65[_0xf153('0x2b')]+_0x2afb9a[_0xf153('0x1a')]+_0x31ec0f++,'VoiceExtensionId':_0xd516d0['VoiceExtensionId']});}}if(_0xd516d0[_0xf153('0x16')]===_0xf153('0x1c')&&_0xd516d0[_0xf153('0x11')](_0xf153('0x32'))){if(_0xd516d0[_0xf153('0x32')]){_0x25960d['push']({'type':_0xd516d0[_0xf153('0x16')],'app':_0xf153('0x21'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0xd516d0[_0xf153('0x32')]+')','context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65['length']+_0x2afb9a[_0xf153('0x1a')]+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});}else{_0x25960d[_0xf153('0x15')]({'type':_0xd516d0[_0xf153('0x16')],'app':_0xf153('0x21'),'appdata':_0xf153('0x33'),'context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65[_0xf153('0x2b')]+_0x2afb9a['priority']+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});}}if(_0xd516d0['hasOwnProperty']('answer')){if(_0x65756d['indexOf'](_0xd516d0[_0xf153('0x34')][_0xf153('0x2c')]())>=0x0&&_0xd516d0['appType']!==_0xf153('0x35')){if(_0xd516d0[_0xf153('0x36')]){_0x25960d['push']({'type':_0xd516d0[_0xf153('0x16')],'app':_0xf153('0x21'),'appdata':_0xf153('0x37'),'context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65[_0xf153('0x2b')]+_0x2afb9a['priority']+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});_0x25960d[_0xf153('0x15')]({'type':_0xd516d0['type'],'app':'Set','appdata':_0xf153('0x38'),'context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65[_0xf153('0x2b')]+_0x2afb9a[_0xf153('0x1a')]+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});}else{_0x25960d['push']({'type':_0xd516d0[_0xf153('0x16')],'app':'ExecIf','appdata':_0xf153('0x39'),'context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0[_0xf153('0xb')],'priority':_0x1edf65['length']+_0x2afb9a[_0xf153('0x1a')]+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});_0x25960d[_0xf153('0x15')]({'type':_0xd516d0[_0xf153('0x16')],'app':_0xf153('0x17'),'appdata':_0xf153('0x3a'),'context':_0xd516d0[_0xf153('0x19')],'exten':_0xd516d0['exten'],'priority':_0x1edf65[_0xf153('0x2b')]+_0x2afb9a[_0xf153('0x1a')]+_0x31ec0f++,'VoiceExtensionId':_0xd516d0[_0xf153('0x1b')]});}}}for(var _0x5673f5=0x0;_0x5673f5<_0x1edf65[_0xf153('0x2b')];_0x5673f5+=0x1){var _0x87af73=_0x2afb9a[_0xf153('0x1a')]+_0x1edf65[_0xf153('0x2b')];var _0x368ac1=_0x5673f5===_0x1edf65[_0xf153('0x2b')]-0x1?_0x2afb9a[_0xf153('0x1a')]+_0x25960d[_0xf153('0x2b')]+_0x4a7712['length']+0x2:_0x2afb9a[_0xf153('0x1a')]+_0x5673f5+0x1;_0x25960d[_0xf153('0x3b')](_0x5673f5,0x0,{'type':_0xd516d0['type'],'app':_0xf153('0x3c'),'appdata':_0x1edf65[_0x5673f5]+'?'+_0xd516d0[_0xf153('0x19')]+_0xf153('0x3d')+_0x87af73+':'+_0xd516d0[_0xf153('0x19')]+_0xf153('0x3d')+_0x368ac1,'exten':_0xd516d0[_0xf153('0xb')],'context':_0xd516d0[_0xf153('0x19')],'priority':_0x2afb9a[_0xf153('0x1a')]+_0x5673f5,'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});}_0xd516d0[_0xf153('0x1a')]=_0x25960d[_0xf153('0x2b')]?_['last'](_0x25960d)[_0xf153('0x1a')]+0x1:_0x2afb9a[_0xf153('0x1a')];_0x2afb9a['priority']=(_0x4a7712[_0xf153('0x2b')]?_[_0xf153('0x3e')](_0x4a7712)[_0xf153('0x1a')]:_0xd516d0[_0xf153('0x1a')])+0x1;_0x2afb9a[_0xf153('0x12')]=_[_0xf153('0x3f')](_0x2afb9a[_0xf153('0x12')],_0x25960d,[_0xd516d0],_0x4a7712);}_0x2afb9a['extensions'][_0xf153('0x15')]({'type':_0x493324[_0x1d54c4][0x0][_0xf153('0x16')],'app':_0xf153('0x40'),'exten':_0x493324[_0x1d54c4][0x0][_0xf153('0xb')],'context':_0x493324[_0x1d54c4][0x0][_0xf153('0x19')],'priority':_0x2afb9a[_0xf153('0x1a')],'VoiceExtensionId':_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]});_0x107d31[_0xf153('0x15')](_0x493324[_0x1d54c4][0x0][_0xf153('0x1b')]);_0x3f915c=_['concat'](_0x3f915c,_0x2afb9a[_0xf153('0x12')]);}}return _0xde7eae[_0xf153('0x41')](function(_0x4afdc4){return _0xde7eae[_0xf153('0x2')]['VoiceExtension'][_0xf153('0x42')]({'where':{'VoiceExtensionId':{'$in':_0x107d31}},'transaction':_0x4afdc4})[_0xf153('0x4')](function(_0x4ec6ad){return _0xde7eae[_0xf153('0x2')]['VoiceExtension'][_0xf153('0x43')](_[_0xf153('0x44')](_0x3f915c,_0xf153('0x1a')),{'transaction':_0x4afdc4});});});})[_0xf153('0x45')](function(_0x4ad773){console[_0xf153('0x46')](_0x4ad773);});}exports[_0xf153('0x47')]=rewrite;