4c80b61418f7a6af2234a1bb16a635cd997a72e5
[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 _0x4a7e=['XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','createdAt','updatedAt','interval','*,*,*,*','intervals','CDR(tag)=','tag','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)=','ExecIf','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','answer','indexOf','toLowerCase','appType','custom','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','splice','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','destroy','bulkCreate','sortBy','error','rewrite','lodash','util','Interval','then','models','VoiceExtension','findAll','IntervalId','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','hasOwnProperty','priority','extensions','extension','find','push','type','format','CDR(type)=%s','VoiceExtensionId','inbound','Set','outbound','CDR(destination)=','cutdigits','${EXTEN:','CDR(routeid)=','context','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','recordingFormat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav'];(function(_0x25408e,_0x457e2d){var _0xd3099d=function(_0x44fe35){while(--_0x44fe35){_0x25408e['push'](_0x25408e['shift']());}};_0xd3099d(++_0x457e2d);}(_0x4a7e,0x1d8));var _0xe4a7=function(_0x3d8c14,_0x2b788e){_0x3d8c14=_0x3d8c14-0x0;var _0x1694fd=_0x4a7e[_0x3d8c14];return _0x1694fd;};'use strict';var _=require(_0xe4a7('0x0'));var util=require(_0xe4a7('0x1'));function rewrite(_0x20c726,_0x31b8ea){var _0x1956a4=this;return _0x20c726['models'][_0xe4a7('0x2')]['findAll']({'raw':!![]})[_0xe4a7('0x3')](function(_0x382981){_0x1956a4['intervals']=_0x382981;return _0x20c726[_0xe4a7('0x4')][_0xe4a7('0x5')][_0xe4a7('0x6')]({'where':{'IntervalId':_0x31b8ea[_0xe4a7('0x7')]},'raw':!![]});})[_0xe4a7('0x3')](function(_0x16e0e6){return _0x20c726[_0xe4a7('0x4')][_0xe4a7('0x5')][_0xe4a7('0x6')]({'where':{'exten':{'$in':_[_0xe4a7('0x8')](_[_0xe4a7('0x9')](_0x16e0e6,_0xe4a7('0xa')))}},'order':[{'raw':_0xe4a7('0xb')}],'raw':!![]});})['then'](function(_0x535b70){var _0x520584=_[_0xe4a7('0xc')](_0x535b70,{'priority':'1'});var _0x1bd86a=_[_0xe4a7('0xc')](_0x535b70,{'isApp':0x1});var _0x1708c3=_['groupBy'](_0x1bd86a,_0xe4a7('0xa'));var _0x2857de=['queue','playback'];var _0x469e24=[];var _0x47aa19=[];for(var _0x554468 in _0x1708c3){if(_0x1708c3[_0xe4a7('0xd')](_0x554468)){_0x1956a4[_0xe4a7('0xe')]=0x2;_0x1956a4[_0xe4a7('0xf')]=[];_0x1956a4[_0xe4a7('0x10')]=_[_0xe4a7('0x11')](_0x520584,{'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')]});_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':'Set','appdata':util[_0xe4a7('0x14')](_0xe4a7('0x15'),_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')]),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});if(_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')]===_0xe4a7('0x17')){_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':'CDR(routeid)='+_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')],'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});}else if(_0x1708c3[_0x554468][0x0]['type']===_0xe4a7('0x19')){if(_0x1956a4[_0xe4a7('0x10')]){_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x1a')+(_0x1956a4[_0xe4a7('0x10')][_0xe4a7('0x1b')]?_0xe4a7('0x1c')+_0x1956a4['extension'][_0xe4a7('0x1b')]+'}':'${EXTEN}'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});}_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x1d')+_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')],'context':_0x1708c3[_0x554468][0x0][_0xe4a7('0x1e')],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});var _0x35f63b=_0x1956a4[_0xe4a7('0xe')]++;_0x1956a4['extensions'][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':'ExecIf','appdata':_0xe4a7('0x1f')+(_0x35f63b+0x2)+_0xe4a7('0x20')+(_0x35f63b+0x1)+')','context':_0x1708c3[_0x554468][0x0][_0xe4a7('0x1e')],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x35f63b,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});if(_0x1956a4[_0xe4a7('0x10')]){_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':'Set','appdata':_0x1956a4[_0xe4a7('0x10')][_0xe4a7('0x1b')]?_0xe4a7('0x21')+_0x1956a4[_0xe4a7('0x10')][_0xe4a7('0x1b')]+'}':_0xe4a7('0x22'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});}_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':'outboundrouteid='+_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')],'context':_0x1708c3[_0x554468][0x0][_0xe4a7('0x1e')],'exten':_0x1708c3[_0x554468][0x0]['exten'],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});if(_0x1956a4[_0xe4a7('0x10')]&&_0x1956a4[_0xe4a7('0x10')]['hasOwnProperty'](_0xe4a7('0x23'))&&_0x1956a4[_0xe4a7('0x10')][_0xe4a7('0x23')]!=='none'){_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':'Set','appdata':_0xe4a7('0x24'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4['priority']++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0]['type'],'app':'Set','appdata':_0xe4a7('0x25')+_0x1956a4[_0xe4a7('0x10')]['recordingFormat']||_0xe4a7('0x26'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});}}_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x27'),'context':_0x1708c3[_0x554468][0x0][_0xe4a7('0x1e')],'exten':_0x1708c3[_0x554468][0x0]['exten'],'priority':_0x1956a4['priority']++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});_0x1956a4['extensions'][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x28'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0][_0xe4a7('0xa')],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0]['VoiceExtensionId']});_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x29'),'context':_0x1708c3[_0x554468][0x0]['context'],'exten':_0x1708c3[_0x554468][0x0]['exten'],'priority':_0x1956a4[_0xe4a7('0xe')]++,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});for(var _0x216148=0x0,_0x38cc39=0x0;_0x216148<_0x1708c3[_0x554468][_0xe4a7('0x2a')];_0x216148+=0x1,_0x38cc39=0x0){var _0x40fb66=_0x1708c3[_0x554468][_0x216148];if(_0x40fb66['type']){_0x40fb66[_0xe4a7('0x13')]=_0x40fb66[_0xe4a7('0x13')]['toLowerCase']();}var _0x37f374=[];var _0x3a00bf=[];delete _0x40fb66['id'];delete _0x40fb66[_0xe4a7('0x2b')];delete _0x40fb66[_0xe4a7('0x2c')];var _0x363a2=_0x40fb66[_0xe4a7('0x2d')]!==_0xe4a7('0x2e')?[_0x40fb66['interval']]:_0x40fb66[_0xe4a7('0x7')]?_[_0xe4a7('0x9')](_[_0xe4a7('0xc')](_0x1956a4[_0xe4a7('0x2f')],{'IntervalId':_0x40fb66[_0xe4a7('0x7')]}),'interval'):[];if(_0x40fb66[_0xe4a7('0xd')]('tag')){if(_0x40fb66['tag']&&_0x40fb66['tag']!=='--'){_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66[_0xe4a7('0x13')],'app':'Set','appdata':_0xe4a7('0x30')+_0x40fb66[_0xe4a7('0x31')],'context':_0x40fb66['context'],'exten':_0x40fb66['exten'],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4[_0xe4a7('0xe')]+_0x38cc39++,'VoiceExtensionId':_0x40fb66['VoiceExtensionId']});}}if(_0x40fb66[_0xe4a7('0x13')]===_0xe4a7('0x19')&&_0x40fb66['hasOwnProperty'](_0xe4a7('0x32'))){if(_0x40fb66[_0xe4a7('0x32')]){_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66['type'],'app':'ExecIf','appdata':_0xe4a7('0x33')+_0x40fb66['callerID']+')','context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4[_0xe4a7('0xe')]+_0x38cc39++,'VoiceExtensionId':_0x40fb66['VoiceExtensionId']});}else{_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66[_0xe4a7('0x13')],'app':_0xe4a7('0x34'),'appdata':_0xe4a7('0x35'),'context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4[_0xe4a7('0xe')]+_0x38cc39++,'VoiceExtensionId':_0x40fb66[_0xe4a7('0x16')]});}}if(_0x40fb66[_0xe4a7('0xd')](_0xe4a7('0x36'))){if(_0x2857de[_0xe4a7('0x37')](_0x40fb66['app'][_0xe4a7('0x38')]())>=0x0&&_0x40fb66[_0xe4a7('0x39')]!==_0xe4a7('0x3a')){if(_0x40fb66[_0xe4a7('0x36')]){_0x37f374['push']({'type':_0x40fb66[_0xe4a7('0x13')],'app':'ExecIf','appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4[_0xe4a7('0xe')]+_0x38cc39++,'VoiceExtensionId':_0x40fb66['VoiceExtensionId']});_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66[_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':_0xe4a7('0x3b'),'context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4['priority']+_0x38cc39++,'VoiceExtensionId':_0x40fb66[_0xe4a7('0x16')]});}else{_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66[_0xe4a7('0x13')],'app':_0xe4a7('0x34'),'appdata':_0xe4a7('0x3c'),'context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4['priority']+_0x38cc39++,'VoiceExtensionId':_0x40fb66[_0xe4a7('0x16')]});_0x37f374[_0xe4a7('0x12')]({'type':_0x40fb66[_0xe4a7('0x13')],'app':_0xe4a7('0x18'),'appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x40fb66[_0xe4a7('0x1e')],'exten':_0x40fb66[_0xe4a7('0xa')],'priority':_0x363a2[_0xe4a7('0x2a')]+_0x1956a4['priority']+_0x38cc39++,'VoiceExtensionId':_0x40fb66[_0xe4a7('0x16')]});}}}for(var _0x4d669f=0x0;_0x4d669f<_0x363a2[_0xe4a7('0x2a')];_0x4d669f+=0x1){var _0x38d4ba=_0x1956a4[_0xe4a7('0xe')]+_0x363a2[_0xe4a7('0x2a')];var _0x339218=_0x4d669f===_0x363a2['length']-0x1?_0x1956a4['priority']+_0x37f374[_0xe4a7('0x2a')]+_0x3a00bf[_0xe4a7('0x2a')]+0x2:_0x1956a4['priority']+_0x4d669f+0x1;_0x37f374[_0xe4a7('0x3d')](_0x4d669f,0x0,{'type':_0x40fb66[_0xe4a7('0x13')],'app':_0xe4a7('0x3e'),'appdata':_0x363a2[_0x4d669f]+'?'+_0x40fb66[_0xe4a7('0x1e')]+_0xe4a7('0x3f')+_0x38d4ba+':'+_0x40fb66[_0xe4a7('0x1e')]+',${EXTEN},'+_0x339218,'exten':_0x40fb66['exten'],'context':_0x40fb66['context'],'priority':_0x1956a4[_0xe4a7('0xe')]+_0x4d669f,'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});}_0x40fb66['priority']=_0x37f374[_0xe4a7('0x2a')]?_[_0xe4a7('0x40')](_0x37f374)[_0xe4a7('0xe')]+0x1:_0x1956a4[_0xe4a7('0xe')];_0x1956a4[_0xe4a7('0xe')]=(_0x3a00bf[_0xe4a7('0x2a')]?_[_0xe4a7('0x40')](_0x3a00bf)[_0xe4a7('0xe')]:_0x40fb66[_0xe4a7('0xe')])+0x1;_0x1956a4[_0xe4a7('0xf')]=_[_0xe4a7('0x41')](_0x1956a4[_0xe4a7('0xf')],_0x37f374,[_0x40fb66],_0x3a00bf);}_0x1956a4[_0xe4a7('0xf')][_0xe4a7('0x12')]({'type':_0x1708c3[_0x554468][0x0][_0xe4a7('0x13')],'app':_0xe4a7('0x42'),'exten':_0x1708c3[_0x554468][0x0]['exten'],'context':_0x1708c3[_0x554468][0x0][_0xe4a7('0x1e')],'priority':_0x1956a4[_0xe4a7('0xe')],'VoiceExtensionId':_0x1708c3[_0x554468][0x0][_0xe4a7('0x16')]});_0x469e24[_0xe4a7('0x12')](_0x1708c3[_0x554468][0x0]['VoiceExtensionId']);_0x47aa19=_[_0xe4a7('0x41')](_0x47aa19,_0x1956a4[_0xe4a7('0xf')]);}}return _0x20c726[_0xe4a7('0x43')](function(_0x6adf78){return _0x20c726[_0xe4a7('0x4')][_0xe4a7('0x5')][_0xe4a7('0x44')]({'where':{'VoiceExtensionId':{'$in':_0x469e24}},'transaction':_0x6adf78})[_0xe4a7('0x3')](function(_0x445677){return _0x20c726[_0xe4a7('0x4')][_0xe4a7('0x5')][_0xe4a7('0x45')](_[_0xe4a7('0x46')](_0x47aa19,'priority'),{'transaction':_0x6adf78});});});})['catch'](function(_0x286abe){console[_0xe4a7('0x47')](_0x286abe);});}exports[_0xe4a7('0x48')]=rewrite;