18 var _0x54b6=['queue','extensions','extension','find','type','CDR(type)=%s','priority','VoiceExtensionId','inbound','Set','context','outbound','push','cutdigits','${EXTEN:','CDR(routeid)=','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','CDR(prefix)=${EXTEN:0:','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','toLowerCase','createdAt','updatedAt','interval','*,*,*,*','hasOwnProperty','tag','CDR(tag)=','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)=','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','indexOf','app','appType','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','length','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','last','concat','Hangup','transaction','destroy','then','bulkCreate','catch','error','rewrite','util','Interval','findAll','intervals','VoiceExtension','IntervalId','models','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy'];(function(_0x5cb430,_0xfc6ea7){var _0x7bbff6=function(_0x2bddcb){while(--_0x2bddcb){_0x5cb430['push'](_0x5cb430['shift']());}};_0x7bbff6(++_0xfc6ea7);}(_0x54b6,0x156));var _0x654b=function(_0x49c057,_0xc808ed){_0x49c057=_0x49c057-0x0;var _0xd8f0e6=_0x54b6[_0x49c057];return _0xd8f0e6;};'use strict';var _=require('lodash');var util=require(_0x654b('0x0'));function rewrite(_0x4aa7f3,_0x2cfe10){var _0x3a6cb3=this;return _0x4aa7f3['models'][_0x654b('0x1')][_0x654b('0x2')]({'raw':!![]})['then'](function(_0x29d709){_0x3a6cb3[_0x654b('0x3')]=_0x29d709;return _0x4aa7f3['models'][_0x654b('0x4')]['findAll']({'where':{'IntervalId':_0x2cfe10[_0x654b('0x5')]},'raw':!![]});})['then'](function(_0x27a178){return _0x4aa7f3[_0x654b('0x6')][_0x654b('0x4')][_0x654b('0x2')]({'where':{'exten':{'$in':_[_0x654b('0x7')](_[_0x654b('0x8')](_0x27a178,_0x654b('0x9')))}},'order':[{'raw':_0x654b('0xa')}],'raw':!![]});})['then'](function(_0x226fb8){var _0x474a24=_[_0x654b('0xb')](_0x226fb8,{'priority':'1'});var _0x2c92b8=_[_0x654b('0xb')](_0x226fb8,{'isApp':0x1});var _0x3d45d3=_[_0x654b('0xc')](_0x2c92b8,'exten');var _0x2881c7=[_0x654b('0xd'),'playback'];var _0x486c6b=[];var _0x3932d1=[];for(var _0x544078 in _0x3d45d3){if(_0x3d45d3['hasOwnProperty'](_0x544078)){_0x3a6cb3['priority']=0x2;_0x3a6cb3[_0x654b('0xe')]=[];_0x3a6cb3[_0x654b('0xf')]=_[_0x654b('0x10')](_0x474a24,{'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')]});_0x3a6cb3['extensions']['push']({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':'Set','appdata':util['format'](_0x654b('0x12'),_0x3d45d3[_0x544078][0x0][_0x654b('0x11')]),'context':_0x3d45d3[_0x544078][0x0]['context'],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});if(_0x3d45d3[_0x544078][0x0][_0x654b('0x11')]===_0x654b('0x15')){_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0]['type'],'app':_0x654b('0x16'),'appdata':'CDR(routeid)='+_0x3d45d3[_0x544078][0x0][_0x654b('0x14')],'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0]['exten'],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});}else if(_0x3d45d3[_0x544078][0x0][_0x654b('0x11')]===_0x654b('0x18')){if(_0x3a6cb3['extension']){_0x3a6cb3[_0x654b('0xe')][_0x654b('0x19')]({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':_0x654b('0x16'),'appdata':'CDR(destination)='+(_0x3a6cb3[_0x654b('0xf')][_0x654b('0x1a')]?_0x654b('0x1b')+_0x3a6cb3[_0x654b('0xf')][_0x654b('0x1a')]+'}':'${EXTEN}'),'context':_0x3d45d3[_0x544078][0x0]['context'],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});}_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0]['type'],'app':_0x654b('0x16'),'appdata':_0x654b('0x1c')+_0x3d45d3[_0x544078][0x0][_0x654b('0x14')],'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});var _0x4bc7d2=_0x3a6cb3[_0x654b('0x13')]++;_0x3a6cb3[_0x654b('0xe')][_0x654b('0x19')]({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':_0x654b('0x1d'),'appdata':_0x654b('0x1e')+(_0x4bc7d2+0x2)+'):Goto('+(_0x4bc7d2+0x1)+')','context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x4bc7d2,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0]['VoiceExtensionId']});if(_0x3a6cb3[_0x654b('0xf')]){_0x3a6cb3['extensions']['push']({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':_0x654b('0x16'),'appdata':_0x3a6cb3[_0x654b('0xf')]['cutdigits']?_0x654b('0x1f')+_0x3a6cb3['extension'][_0x654b('0x1a')]+'}':'CDR(prefix)=noprefix','context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0]['exten'],'priority':_0x3a6cb3['priority']++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});}_0x3a6cb3[_0x654b('0xe')][_0x654b('0x19')]({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':'Set','appdata':_0x654b('0x20')+_0x3d45d3[_0x544078][0x0][_0x654b('0x14')],'context':_0x3d45d3[_0x544078][0x0]['context'],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});if(_0x3a6cb3[_0x654b('0xf')]&&_0x3a6cb3[_0x654b('0xf')]['hasOwnProperty'](_0x654b('0x21'))&&_0x3a6cb3[_0x654b('0xf')]['recordingFormat']!==_0x654b('0x22')){_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':_0x654b('0x16'),'appdata':_0x654b('0x23'),'context':_0x3d45d3[_0x544078][0x0]['context'],'exten':_0x3d45d3[_0x544078][0x0]['exten'],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});_0x3a6cb3[_0x654b('0xe')][_0x654b('0x19')]({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':'Set','appdata':_0x654b('0x24')+_0x3a6cb3[_0x654b('0xf')][_0x654b('0x21')]||'wav','context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0]['exten'],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});}}_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0]['type'],'app':_0x654b('0x16'),'appdata':_0x654b('0x25'),'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0]['exten'],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0]['VoiceExtensionId']});_0x3a6cb3['extensions'][_0x654b('0x19')]({'type':_0x3d45d3[_0x544078][0x0][_0x654b('0x11')],'app':'Set','appdata':_0x654b('0x26'),'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3[_0x654b('0x13')]++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0]['VoiceExtensionId']});_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0]['type'],'app':_0x654b('0x16'),'appdata':_0x654b('0x27'),'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'priority':_0x3a6cb3['priority']++,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});for(var _0x445764=0x0,_0x54ea26=0x0;_0x445764<_0x3d45d3[_0x544078]['length'];_0x445764+=0x1,_0x54ea26=0x0){var _0x24de77=_0x3d45d3[_0x544078][_0x445764];if(_0x24de77[_0x654b('0x11')]){_0x24de77['type']=_0x24de77[_0x654b('0x11')][_0x654b('0x28')]();}var _0x22ecb2=[];var _0x4251be=[];delete _0x24de77['id'];delete _0x24de77[_0x654b('0x29')];delete _0x24de77[_0x654b('0x2a')];var _0x5f4272=_0x24de77[_0x654b('0x2b')]!==_0x654b('0x2c')?[_0x24de77['interval']]:_0x24de77[_0x654b('0x5')]?_[_0x654b('0x8')](_[_0x654b('0xb')](_0x3a6cb3[_0x654b('0x3')],{'IntervalId':_0x24de77[_0x654b('0x5')]}),'interval'):[];if(_0x24de77[_0x654b('0x2d')](_0x654b('0x2e'))){if(_0x24de77['tag']&&_0x24de77[_0x654b('0x2e')]!=='--'){_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77[_0x654b('0x11')],'app':_0x654b('0x16'),'appdata':_0x654b('0x2f')+_0x24de77[_0x654b('0x2e')],'context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272['length']+_0x3a6cb3['priority']+_0x54ea26++,'VoiceExtensionId':_0x24de77['VoiceExtensionId']});}}if(_0x24de77[_0x654b('0x11')]==='outbound'&&_0x24de77[_0x654b('0x2d')](_0x654b('0x30'))){if(_0x24de77[_0x654b('0x30')]){_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77['type'],'app':_0x654b('0x1d'),'appdata':_0x654b('0x31')+_0x24de77[_0x654b('0x30')]+')','context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272['length']+_0x3a6cb3[_0x654b('0x13')]+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});}else{_0x22ecb2['push']({'type':_0x24de77[_0x654b('0x11')],'app':_0x654b('0x1d'),'appdata':_0x654b('0x32'),'context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272['length']+_0x3a6cb3[_0x654b('0x13')]+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});}}if(_0x24de77[_0x654b('0x2d')]('answer')){if(_0x2881c7[_0x654b('0x33')](_0x24de77[_0x654b('0x34')][_0x654b('0x28')]())>=0x0&&_0x24de77[_0x654b('0x35')]!=='custom'){if(_0x24de77[_0x654b('0x36')]){_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77[_0x654b('0x11')],'app':_0x654b('0x1d'),'appdata':_0x654b('0x37'),'context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272[_0x654b('0x38')]+_0x3a6cb3['priority']+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77[_0x654b('0x11')],'app':_0x654b('0x16'),'appdata':'XCALLY-MOTION-ANSWER=1','context':_0x24de77['context'],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272[_0x654b('0x38')]+_0x3a6cb3['priority']+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});}else{_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77[_0x654b('0x11')],'app':_0x654b('0x1d'),'appdata':_0x654b('0x39'),'context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77[_0x654b('0x9')],'priority':_0x5f4272[_0x654b('0x38')]+_0x3a6cb3[_0x654b('0x13')]+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});_0x22ecb2[_0x654b('0x19')]({'type':_0x24de77[_0x654b('0x11')],'app':'Set','appdata':_0x654b('0x3a'),'context':_0x24de77[_0x654b('0x17')],'exten':_0x24de77['exten'],'priority':_0x5f4272[_0x654b('0x38')]+_0x3a6cb3['priority']+_0x54ea26++,'VoiceExtensionId':_0x24de77[_0x654b('0x14')]});}}}for(var _0x4429ad=0x0;_0x4429ad<_0x5f4272[_0x654b('0x38')];_0x4429ad+=0x1){var _0x556198=_0x3a6cb3[_0x654b('0x13')]+_0x5f4272[_0x654b('0x38')];var _0x22846c=_0x4429ad===_0x5f4272[_0x654b('0x38')]-0x1?_0x3a6cb3[_0x654b('0x13')]+_0x22ecb2[_0x654b('0x38')]+_0x4251be['length']+0x2:_0x3a6cb3[_0x654b('0x13')]+_0x4429ad+0x1;_0x22ecb2[_0x654b('0x3b')](_0x4429ad,0x0,{'type':_0x24de77[_0x654b('0x11')],'app':'GotoIfTime','appdata':_0x5f4272[_0x4429ad]+'?'+_0x24de77[_0x654b('0x17')]+_0x654b('0x3c')+_0x556198+':'+_0x24de77[_0x654b('0x17')]+_0x654b('0x3c')+_0x22846c,'exten':_0x24de77[_0x654b('0x9')],'context':_0x24de77[_0x654b('0x17')],'priority':_0x3a6cb3[_0x654b('0x13')]+_0x4429ad,'VoiceExtensionId':_0x3d45d3[_0x544078][0x0]['VoiceExtensionId']});}_0x24de77[_0x654b('0x13')]=_0x22ecb2[_0x654b('0x38')]?_[_0x654b('0x3d')](_0x22ecb2)[_0x654b('0x13')]+0x1:_0x3a6cb3[_0x654b('0x13')];_0x3a6cb3[_0x654b('0x13')]=(_0x4251be['length']?_[_0x654b('0x3d')](_0x4251be)[_0x654b('0x13')]:_0x24de77[_0x654b('0x13')])+0x1;_0x3a6cb3['extensions']=_[_0x654b('0x3e')](_0x3a6cb3['extensions'],_0x22ecb2,[_0x24de77],_0x4251be);}_0x3a6cb3[_0x654b('0xe')]['push']({'type':_0x3d45d3[_0x544078][0x0]['type'],'app':_0x654b('0x3f'),'exten':_0x3d45d3[_0x544078][0x0][_0x654b('0x9')],'context':_0x3d45d3[_0x544078][0x0][_0x654b('0x17')],'priority':_0x3a6cb3[_0x654b('0x13')],'VoiceExtensionId':_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]});_0x486c6b['push'](_0x3d45d3[_0x544078][0x0][_0x654b('0x14')]);_0x3932d1=_['concat'](_0x3932d1,_0x3a6cb3[_0x654b('0xe')]);}}return _0x4aa7f3[_0x654b('0x40')](function(_0xa20e3c){return _0x4aa7f3[_0x654b('0x6')][_0x654b('0x4')][_0x654b('0x41')]({'where':{'VoiceExtensionId':{'$in':_0x486c6b}},'transaction':_0xa20e3c})[_0x654b('0x42')](function(_0x12e23a){return _0x4aa7f3[_0x654b('0x6')][_0x654b('0x4')][_0x654b('0x43')](_['sortBy'](_0x3932d1,_0x654b('0x13')),{'transaction':_0xa20e3c});});});})[_0x654b('0x44')](function(_0x2956dd){console[_0x654b('0x45')](_0x2956dd);});}exports[_0x654b('0x46')]=rewrite;