18 var _0xbcdc=['outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','updatedAt','interval','intervals','tag','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','answer','app','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','Hangup','transaction','destroy','sortBy','catch','error','rewrite','lodash','util','models','Interval','findAll','IntervalId','then','VoiceExtension','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','playback','hasOwnProperty','extensions','extension','find','push','Set','format','CDR(type)=%s','type','context','priority','outbound','CDR(destination)=','cutdigits','${EXTEN:','VoiceExtensionId','CDR(routeid)=','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xbcdc,0xb7));var _0xcbcd=function(_0x57a24d,_0x33ec9d){_0x57a24d=_0x57a24d-0x0;var _0x27dfd0=_0xbcdc[_0x57a24d];return _0x27dfd0;};'use strict';var _=require(_0xcbcd('0x0'));var util=require(_0xcbcd('0x1'));function rewrite(_0x51dc02,_0x3d4a00){var _0x182889=this;return _0x51dc02[_0xcbcd('0x2')][_0xcbcd('0x3')][_0xcbcd('0x4')]({'raw':!![]})['then'](function(_0x24f0ee){_0x182889['intervals']=_0x24f0ee;return _0x51dc02['models']['VoiceExtension'][_0xcbcd('0x4')]({'where':{'IntervalId':_0x3d4a00[_0xcbcd('0x5')]},'raw':!![]});})[_0xcbcd('0x6')](function(_0xe53a49){return _0x51dc02[_0xcbcd('0x2')][_0xcbcd('0x7')][_0xcbcd('0x4')]({'where':{'exten':{'$in':_[_0xcbcd('0x8')](_[_0xcbcd('0x9')](_0xe53a49,_0xcbcd('0xa')))}},'order':[{'raw':_0xcbcd('0xb')}],'raw':!![]});})[_0xcbcd('0x6')](function(_0xcc440d){var _0x3e0e92=_[_0xcbcd('0xc')](_0xcc440d,{'priority':'1'});var _0x48e8af=_[_0xcbcd('0xc')](_0xcc440d,{'isApp':0x1});var _0xf26399=_[_0xcbcd('0xd')](_0x48e8af,_0xcbcd('0xa'));var _0x1bc024=['queue',_0xcbcd('0xe')];var _0x4b9ccb=[];var _0x418a25=[];for(var _0x4363a0 in _0xf26399){if(_0xf26399[_0xcbcd('0xf')](_0x4363a0)){_0x182889['priority']=0x2;_0x182889[_0xcbcd('0x10')]=[];_0x182889[_0xcbcd('0x11')]=_[_0xcbcd('0x12')](_0x3e0e92,{'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')]});_0x182889[_0xcbcd('0x10')][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0]['type'],'app':_0xcbcd('0x14'),'appdata':util[_0xcbcd('0x15')](_0xcbcd('0x16'),_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')]),'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0]['VoiceExtensionId']});if(_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')]===_0xcbcd('0x1a')){if(_0x182889[_0xcbcd('0x11')]){_0x182889['extensions'][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x1b')+(_0x182889[_0xcbcd('0x11')][_0xcbcd('0x1c')]?_0xcbcd('0x1d')+_0x182889[_0xcbcd('0x11')][_0xcbcd('0x1c')]+'}':'${EXTEN}'),'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});}_0x182889[_0xcbcd('0x10')][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0]['type'],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x1f')+_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')],'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0]['VoiceExtensionId']});var _0x30fd64=_0x182889[_0xcbcd('0x19')]++;_0x182889[_0xcbcd('0x10')]['push']({'type':_0xf26399[_0x4363a0][0x0]['type'],'app':_0xcbcd('0x20'),'appdata':_0xcbcd('0x21')+(_0x30fd64+0x2)+_0xcbcd('0x22')+(_0x30fd64+0x1)+')','context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'priority':_0x30fd64,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0]['VoiceExtensionId']});if(_0x182889[_0xcbcd('0x11')]){_0x182889[_0xcbcd('0x10')][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0]['type'],'app':_0xcbcd('0x14'),'appdata':_0x182889[_0xcbcd('0x11')][_0xcbcd('0x1c')]?_0xcbcd('0x23')+_0x182889['extension'][_0xcbcd('0x1c')]+'}':'CDR(prefix)=noprefix','context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});}_0x182889[_0xcbcd('0x10')][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x24')+_0xf26399[_0x4363a0][0x0]['VoiceExtensionId'],'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'priority':_0x182889['priority']++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});if(_0x182889[_0xcbcd('0x11')]&&_0x182889[_0xcbcd('0x11')][_0xcbcd('0xf')]('recordingFormat')&&_0x182889[_0xcbcd('0x11')][_0xcbcd('0x25')]!==_0xcbcd('0x26')){_0x182889[_0xcbcd('0x10')]['push']({'type':_0xf26399[_0x4363a0][0x0]['type'],'app':'Set','appdata':_0xcbcd('0x27'),'context':_0xf26399[_0x4363a0][0x0]['context'],'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});_0x182889['extensions'][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x28')+_0x182889['extension'][_0xcbcd('0x25')]||_0xcbcd('0x29'),'context':_0xf26399[_0x4363a0][0x0]['context'],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});}}_0x182889[_0xcbcd('0x10')]['push']({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x2a'),'context':_0xf26399[_0x4363a0][0x0]['context'],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});_0x182889['extensions']['push']({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x2b'),'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889['priority']++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});_0x182889['extensions'][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x2c'),'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'exten':_0xf26399[_0x4363a0][0x0]['exten'],'priority':_0x182889[_0xcbcd('0x19')]++,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0]['VoiceExtensionId']});for(var _0x5715ea=0x0,_0xefe84c=0x0;_0x5715ea<_0xf26399[_0x4363a0][_0xcbcd('0x2d')];_0x5715ea+=0x1,_0xefe84c=0x0){var _0x124b98=_0xf26399[_0x4363a0][_0x5715ea];if(_0x124b98[_0xcbcd('0x17')]){_0x124b98['type']=_0x124b98['type'][_0xcbcd('0x2e')]();}var _0x525660=[];var _0x38bab4=[];delete _0x124b98['id'];delete _0x124b98[_0xcbcd('0x2f')];delete _0x124b98[_0xcbcd('0x30')];var _0x47855d=_0x124b98[_0xcbcd('0x31')]!=='*,*,*,*'?[_0x124b98[_0xcbcd('0x31')]]:_0x124b98['IntervalId']?_['map'](_[_0xcbcd('0xc')](_0x182889[_0xcbcd('0x32')],{'IntervalId':_0x124b98[_0xcbcd('0x5')]}),_0xcbcd('0x31')):[];if(_0x124b98[_0xcbcd('0xf')](_0xcbcd('0x33'))){if(_0x124b98[_0xcbcd('0x33')]&&_0x124b98[_0xcbcd('0x33')]!=='--'){_0x525660['push']({'type':_0x124b98['type'],'app':'Set','appdata':'CDR(tag)='+_0x124b98[_0xcbcd('0x33')],'context':_0x124b98[_0xcbcd('0x18')],'exten':_0x124b98['exten'],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889[_0xcbcd('0x19')]+_0xefe84c++,'VoiceExtensionId':_0x124b98[_0xcbcd('0x1e')]});}}if(_0x124b98['type']===_0xcbcd('0x1a')&&_0x124b98[_0xcbcd('0xf')](_0xcbcd('0x34'))){if(_0x124b98[_0xcbcd('0x34')]){_0x525660[_0xcbcd('0x13')]({'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x20'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0x124b98['callerID']+')','context':_0x124b98['context'],'exten':_0x124b98[_0xcbcd('0xa')],'priority':_0x47855d['length']+_0x182889[_0xcbcd('0x19')]+_0xefe84c++,'VoiceExtensionId':_0x124b98[_0xcbcd('0x1e')]});}else{_0x525660[_0xcbcd('0x13')]({'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x20'),'appdata':_0xcbcd('0x35'),'context':_0x124b98['context'],'exten':_0x124b98[_0xcbcd('0xa')],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889[_0xcbcd('0x19')]+_0xefe84c++,'VoiceExtensionId':_0x124b98[_0xcbcd('0x1e')]});}}if(_0x124b98['hasOwnProperty'](_0xcbcd('0x36'))){if(_0x1bc024['indexOf'](_0x124b98[_0xcbcd('0x37')][_0xcbcd('0x2e')]())>=0x0&&_0x124b98[_0xcbcd('0x38')]!==_0xcbcd('0x39')){if(_0x124b98[_0xcbcd('0x36')]){_0x525660[_0xcbcd('0x13')]({'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x20'),'appdata':_0xcbcd('0x3a'),'context':_0x124b98[_0xcbcd('0x18')],'exten':_0x124b98['exten'],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889['priority']+_0xefe84c++,'VoiceExtensionId':_0x124b98[_0xcbcd('0x1e')]});_0x525660[_0xcbcd('0x13')]({'type':_0x124b98['type'],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x3b'),'context':_0x124b98[_0xcbcd('0x18')],'exten':_0x124b98[_0xcbcd('0xa')],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889['priority']+_0xefe84c++,'VoiceExtensionId':_0x124b98['VoiceExtensionId']});}else{_0x525660[_0xcbcd('0x13')]({'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x20'),'appdata':_0xcbcd('0x3c'),'context':_0x124b98[_0xcbcd('0x18')],'exten':_0x124b98[_0xcbcd('0xa')],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889[_0xcbcd('0x19')]+_0xefe84c++,'VoiceExtensionId':_0x124b98[_0xcbcd('0x1e')]});_0x525660[_0xcbcd('0x13')]({'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x14'),'appdata':_0xcbcd('0x3d'),'context':_0x124b98[_0xcbcd('0x18')],'exten':_0x124b98[_0xcbcd('0xa')],'priority':_0x47855d[_0xcbcd('0x2d')]+_0x182889['priority']+_0xefe84c++,'VoiceExtensionId':_0x124b98['VoiceExtensionId']});}}}for(var _0x536284=0x0;_0x536284<_0x47855d[_0xcbcd('0x2d')];_0x536284+=0x1){var _0x5a1dd0=_0x182889['priority']+_0x47855d[_0xcbcd('0x2d')];var _0xc5998f=_0x536284===_0x47855d[_0xcbcd('0x2d')]-0x1?_0x182889[_0xcbcd('0x19')]+_0x525660[_0xcbcd('0x2d')]+_0x38bab4[_0xcbcd('0x2d')]+0x2:_0x182889[_0xcbcd('0x19')]+_0x536284+0x1;_0x525660[_0xcbcd('0x3e')](_0x536284,0x0,{'type':_0x124b98[_0xcbcd('0x17')],'app':_0xcbcd('0x3f'),'appdata':_0x47855d[_0x536284]+'?'+_0x124b98[_0xcbcd('0x18')]+_0xcbcd('0x40')+_0x5a1dd0+':'+_0x124b98[_0xcbcd('0x18')]+_0xcbcd('0x40')+_0xc5998f,'exten':_0x124b98[_0xcbcd('0xa')],'context':_0x124b98[_0xcbcd('0x18')],'priority':_0x182889['priority']+_0x536284,'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});}_0x124b98[_0xcbcd('0x19')]=_0x525660[_0xcbcd('0x2d')]?_[_0xcbcd('0x41')](_0x525660)[_0xcbcd('0x19')]+0x1:_0x182889[_0xcbcd('0x19')];_0x182889[_0xcbcd('0x19')]=(_0x38bab4[_0xcbcd('0x2d')]?_[_0xcbcd('0x41')](_0x38bab4)[_0xcbcd('0x19')]:_0x124b98[_0xcbcd('0x19')])+0x1;_0x182889[_0xcbcd('0x10')]=_['concat'](_0x182889[_0xcbcd('0x10')],_0x525660,[_0x124b98],_0x38bab4);}_0x182889[_0xcbcd('0x10')][_0xcbcd('0x13')]({'type':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x17')],'app':_0xcbcd('0x42'),'exten':_0xf26399[_0x4363a0][0x0][_0xcbcd('0xa')],'context':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x18')],'priority':_0x182889[_0xcbcd('0x19')],'VoiceExtensionId':_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]});_0x4b9ccb[_0xcbcd('0x13')](_0xf26399[_0x4363a0][0x0][_0xcbcd('0x1e')]);_0x418a25=_['concat'](_0x418a25,_0x182889[_0xcbcd('0x10')]);}}return _0x51dc02[_0xcbcd('0x43')](function(_0x2e661a){return _0x51dc02['models'][_0xcbcd('0x7')][_0xcbcd('0x44')]({'where':{'VoiceExtensionId':{'$in':_0x4b9ccb}},'transaction':_0x2e661a})[_0xcbcd('0x6')](function(_0x268710){return _0x51dc02[_0xcbcd('0x2')][_0xcbcd('0x7')]['bulkCreate'](_[_0xcbcd('0x45')](_0x418a25,_0xcbcd('0x19')),{'transaction':_0x2e661a});});});})[_0xcbcd('0x46')](function(_0x53bf0c){console[_0xcbcd('0x47')](_0x53bf0c);});}exports[_0xcbcd('0x48')]=rewrite;