2281f9d649fd09d3cf55f38a711f313a25fc6796
[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 _0x38ad=['CDR(tag)=','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','answer','indexOf','app','appType','custom','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','concat','transaction','destroy','bulkCreate','error','rewrite','lodash','util','models','Interval','findAll','then','intervals','VoiceExtension','IntervalId','uniq','exten','CAST(priority\x20AS\x20UNSIGNED)','playback','hasOwnProperty','priority','extensions','extension','find','push','format','CDR(type)=%s','type','context','VoiceExtensionId','outbound','Set','CDR(destination)=','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','cutdigits','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','interval','*,*,*,*','filter','tag'];(function(_0x541095,_0x582b30){var _0x5a2c40=function(_0xb7650f){while(--_0xb7650f){_0x541095['push'](_0x541095['shift']());}};_0x5a2c40(++_0x582b30);}(_0x38ad,0x16e));var _0xd38a=function(_0x5d97f5,_0x37925f){_0x5d97f5=_0x5d97f5-0x0;var _0xbd6f8f=_0x38ad[_0x5d97f5];return _0xbd6f8f;};'use strict';var _=require(_0xd38a('0x0'));var util=require(_0xd38a('0x1'));function rewrite(_0x364e20,_0x15b03e){var _0x2408a0=this;return _0x364e20[_0xd38a('0x2')][_0xd38a('0x3')][_0xd38a('0x4')]({'raw':!![]})[_0xd38a('0x5')](function(_0x1b3662){_0x2408a0[_0xd38a('0x6')]=_0x1b3662;return _0x364e20['models'][_0xd38a('0x7')][_0xd38a('0x4')]({'where':{'IntervalId':_0x15b03e[_0xd38a('0x8')]},'raw':!![]});})['then'](function(_0x125db4){return _0x364e20['models']['VoiceExtension'][_0xd38a('0x4')]({'where':{'exten':{'$in':_[_0xd38a('0x9')](_['map'](_0x125db4,_0xd38a('0xa')))}},'order':[{'raw':_0xd38a('0xb')}],'raw':!![]});})[_0xd38a('0x5')](function(_0x5a4e59){var _0x242ba4=_['filter'](_0x5a4e59,{'priority':'1'});var _0xb9ae9c=_['filter'](_0x5a4e59,{'isApp':0x1});var _0x1044e9=_['groupBy'](_0xb9ae9c,_0xd38a('0xa'));var _0x437e4e=['queue',_0xd38a('0xc')];var _0x185a0f=[];var _0x1be4f2=[];for(var _0x1408fd in _0x1044e9){if(_0x1044e9[_0xd38a('0xd')](_0x1408fd)){_0x2408a0[_0xd38a('0xe')]=0x2;_0x2408a0[_0xd38a('0xf')]=[];_0x2408a0[_0xd38a('0x10')]=_[_0xd38a('0x11')](_0x242ba4,{'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')]});_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0]['type'],'app':'Set','appdata':util[_0xd38a('0x13')](_0xd38a('0x14'),_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')]),'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});if(_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')]===_0xd38a('0x18')){if(_0x2408a0['extension']){_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x1a')+(_0x2408a0[_0xd38a('0x10')]['cutdigits']?_0xd38a('0x1b')+_0x2408a0[_0xd38a('0x10')]['cutdigits']+'}':_0xd38a('0x1c')),'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0['priority']++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});}_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0]['type'],'app':'Set','appdata':'CDR(routeid)='+_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')],'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});var _0x41e37b=_0x2408a0[_0xd38a('0xe')]++;_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x1d'),'appdata':_0xd38a('0x1e')+(_0x41e37b+0x2)+_0xd38a('0x1f')+(_0x41e37b+0x1)+')','context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x41e37b,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});if(_0x2408a0[_0xd38a('0x10')]){_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0]['type'],'app':_0xd38a('0x19'),'appdata':_0x2408a0[_0xd38a('0x10')][_0xd38a('0x20')]?'CDR(prefix)=${EXTEN:0:'+_0x2408a0[_0xd38a('0x10')][_0xd38a('0x20')]+'}':'CDR(prefix)=noprefix','context':_0x1044e9[_0x1408fd][0x0]['context'],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0]['VoiceExtensionId']});}_0x2408a0[_0xd38a('0xf')]['push']({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x21')+_0x1044e9[_0x1408fd][0x0]['VoiceExtensionId'],'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});if(_0x2408a0[_0xd38a('0x10')]&&_0x2408a0[_0xd38a('0x10')][_0xd38a('0xd')](_0xd38a('0x22'))&&_0x2408a0['extension'][_0xd38a('0x22')]!==_0xd38a('0x23')){_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0]['type'],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x24'),'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0]['VoiceExtensionId']});_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':'Set','appdata':_0xd38a('0x25')+_0x2408a0[_0xd38a('0x10')][_0xd38a('0x22')]||'wav','context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0[_0xd38a('0xe')]++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});}}_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x26'),'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0['priority']++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x27'),'context':_0x1044e9[_0x1408fd][0x0]['context'],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0['priority']++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0]['VoiceExtensionId']});_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x28'),'context':_0x1044e9[_0x1408fd][0x0]['context'],'exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'priority':_0x2408a0['priority']++,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});for(var _0x1f988b=0x0,_0x55db8c=0x0;_0x1f988b<_0x1044e9[_0x1408fd][_0xd38a('0x29')];_0x1f988b+=0x1,_0x55db8c=0x0){var _0x367a3d=_0x1044e9[_0x1408fd][_0x1f988b];if(_0x367a3d['type']){_0x367a3d['type']=_0x367a3d[_0xd38a('0x15')][_0xd38a('0x2a')]();}var _0x5b6a3a=[];var _0x6fa582=[];delete _0x367a3d['id'];delete _0x367a3d[_0xd38a('0x2b')];delete _0x367a3d['updatedAt'];var _0x5aa3fd=_0x367a3d[_0xd38a('0x2c')]!==_0xd38a('0x2d')?[_0x367a3d[_0xd38a('0x2c')]]:_0x367a3d[_0xd38a('0x8')]?_['map'](_[_0xd38a('0x2e')](_0x2408a0[_0xd38a('0x6')],{'IntervalId':_0x367a3d[_0xd38a('0x8')]}),_0xd38a('0x2c')):[];if(_0x367a3d[_0xd38a('0xd')](_0xd38a('0x2f'))){if(_0x367a3d[_0xd38a('0x2f')]&&_0x367a3d['tag']!=='--'){_0x5b6a3a[_0xd38a('0x12')]({'type':_0x367a3d['type'],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x30')+_0x367a3d[_0xd38a('0x2f')],'context':_0x367a3d['context'],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});}}if(_0x367a3d['type']==='outbound'&&_0x367a3d[_0xd38a('0xd')](_0xd38a('0x31'))){if(_0x367a3d[_0xd38a('0x31')]){_0x5b6a3a['push']({'type':_0x367a3d[_0xd38a('0x15')],'app':_0xd38a('0x1d'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0x367a3d[_0xd38a('0x31')]+')','context':_0x367a3d[_0xd38a('0x16')],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});}else{_0x5b6a3a[_0xd38a('0x12')]({'type':_0x367a3d['type'],'app':_0xd38a('0x1d'),'appdata':_0xd38a('0x32'),'context':_0x367a3d[_0xd38a('0x16')],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});}}if(_0x367a3d[_0xd38a('0xd')](_0xd38a('0x33'))){if(_0x437e4e[_0xd38a('0x34')](_0x367a3d[_0xd38a('0x35')][_0xd38a('0x2a')]())>=0x0&&_0x367a3d[_0xd38a('0x36')]!==_0xd38a('0x37')){if(_0x367a3d['answer']){_0x5b6a3a[_0xd38a('0x12')]({'type':_0x367a3d[_0xd38a('0x15')],'app':_0xd38a('0x1d'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x367a3d[_0xd38a('0x16')],'exten':_0x367a3d['exten'],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});_0x5b6a3a[_0xd38a('0x12')]({'type':_0x367a3d[_0xd38a('0x15')],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x38'),'context':_0x367a3d[_0xd38a('0x16')],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});}else{_0x5b6a3a[_0xd38a('0x12')]({'type':_0x367a3d[_0xd38a('0x15')],'app':_0xd38a('0x1d'),'appdata':_0xd38a('0x39'),'context':_0x367a3d['context'],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});_0x5b6a3a['push']({'type':_0x367a3d['type'],'app':_0xd38a('0x19'),'appdata':_0xd38a('0x3a'),'context':_0x367a3d[_0xd38a('0x16')],'exten':_0x367a3d[_0xd38a('0xa')],'priority':_0x5aa3fd[_0xd38a('0x29')]+_0x2408a0[_0xd38a('0xe')]+_0x55db8c++,'VoiceExtensionId':_0x367a3d[_0xd38a('0x17')]});}}}for(var _0x3414e8=0x0;_0x3414e8<_0x5aa3fd[_0xd38a('0x29')];_0x3414e8+=0x1){var _0x55537c=_0x2408a0[_0xd38a('0xe')]+_0x5aa3fd[_0xd38a('0x29')];var _0x3e4100=_0x3414e8===_0x5aa3fd[_0xd38a('0x29')]-0x1?_0x2408a0[_0xd38a('0xe')]+_0x5b6a3a[_0xd38a('0x29')]+_0x6fa582['length']+0x2:_0x2408a0['priority']+_0x3414e8+0x1;_0x5b6a3a[_0xd38a('0x3b')](_0x3414e8,0x0,{'type':_0x367a3d[_0xd38a('0x15')],'app':_0xd38a('0x3c'),'appdata':_0x5aa3fd[_0x3414e8]+'?'+_0x367a3d[_0xd38a('0x16')]+_0xd38a('0x3d')+_0x55537c+':'+_0x367a3d['context']+_0xd38a('0x3d')+_0x3e4100,'exten':_0x367a3d[_0xd38a('0xa')],'context':_0x367a3d[_0xd38a('0x16')],'priority':_0x2408a0[_0xd38a('0xe')]+_0x3414e8,'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});}_0x367a3d[_0xd38a('0xe')]=_0x5b6a3a[_0xd38a('0x29')]?_['last'](_0x5b6a3a)[_0xd38a('0xe')]+0x1:_0x2408a0['priority'];_0x2408a0[_0xd38a('0xe')]=(_0x6fa582[_0xd38a('0x29')]?_[_0xd38a('0x3e')](_0x6fa582)[_0xd38a('0xe')]:_0x367a3d[_0xd38a('0xe')])+0x1;_0x2408a0[_0xd38a('0xf')]=_[_0xd38a('0x3f')](_0x2408a0[_0xd38a('0xf')],_0x5b6a3a,[_0x367a3d],_0x6fa582);}_0x2408a0[_0xd38a('0xf')][_0xd38a('0x12')]({'type':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x15')],'app':'Hangup','exten':_0x1044e9[_0x1408fd][0x0][_0xd38a('0xa')],'context':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x16')],'priority':_0x2408a0['priority'],'VoiceExtensionId':_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]});_0x185a0f[_0xd38a('0x12')](_0x1044e9[_0x1408fd][0x0][_0xd38a('0x17')]);_0x1be4f2=_[_0xd38a('0x3f')](_0x1be4f2,_0x2408a0[_0xd38a('0xf')]);}}return _0x364e20[_0xd38a('0x40')](function(_0x127c54){return _0x364e20[_0xd38a('0x2')][_0xd38a('0x7')][_0xd38a('0x41')]({'where':{'VoiceExtensionId':{'$in':_0x185a0f}},'transaction':_0x127c54})[_0xd38a('0x5')](function(_0x49d622){return _0x364e20[_0xd38a('0x2')]['VoiceExtension'][_0xd38a('0x42')](_['sortBy'](_0x1be4f2,_0xd38a('0xe')),{'transaction':_0x127c54});});});})['catch'](function(_0x118a89){console[_0xd38a('0x43')](_0x118a89);});}exports[_0xd38a('0x44')]=rewrite;