7cfa9aa1e99c53691e8e44c5d1653ceff67221c5
[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 _0x75a2=['IntervalId','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','playback','priority','extensions','find','type','Set','format','CDR(type)=%s','context','VoiceExtensionId','inbound','push','CDR(routeid)=','outbound','cutdigits','${EXTEN:','extension','${EXTEN}','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-ANSWER=0','MONITOR_OPTIONS=ab','length','createdAt','*,*,*,*','interval','map','tag','CDR(tag)=','callerID','ExecIf','$[${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','toLowerCase','custom','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-PROGRESS=1','GotoIfTime',',${EXTEN},','last','concat','transaction','destroy','bulkCreate','sortBy','catch','error','rewrite','lodash','util','models','Interval','findAll','then','intervals','VoiceExtension'];(function(_0x16e29c,_0x474035){var _0x589e32=function(_0x1924cc){while(--_0x1924cc){_0x16e29c['push'](_0x16e29c['shift']());}};_0x589e32(++_0x474035);}(_0x75a2,0x11c));var _0x275a=function(_0x2eb69e,_0x4893af){_0x2eb69e=_0x2eb69e-0x0;var _0x3e21b9=_0x75a2[_0x2eb69e];return _0x3e21b9;};'use strict';var _=require(_0x275a('0x0'));var util=require(_0x275a('0x1'));function rewrite(_0x54e032,_0x3157f0){var _0x382e3d=this;return _0x54e032[_0x275a('0x2')][_0x275a('0x3')][_0x275a('0x4')]({'raw':!![]})[_0x275a('0x5')](function(_0x4fea95){_0x382e3d[_0x275a('0x6')]=_0x4fea95;return _0x54e032['models'][_0x275a('0x7')][_0x275a('0x4')]({'where':{'IntervalId':_0x3157f0[_0x275a('0x8')]},'raw':!![]});})[_0x275a('0x5')](function(_0x4a20f8){return _0x54e032['models']['VoiceExtension'][_0x275a('0x4')]({'where':{'exten':{'$in':_['uniq'](_['map'](_0x4a20f8,_0x275a('0x9')))}},'order':[{'raw':_0x275a('0xa')}],'raw':!![]});})[_0x275a('0x5')](function(_0x2d1fe6){var _0x13b1fa=_[_0x275a('0xb')](_0x2d1fe6,{'priority':'1'});var _0x19cd2a=_[_0x275a('0xb')](_0x2d1fe6,{'isApp':0x1});var _0x35a35f=_[_0x275a('0xc')](_0x19cd2a,_0x275a('0x9'));var _0x2e488c=['queue',_0x275a('0xd')];var _0x3d30e5=[];var _0x505284=[];for(var _0x3d2cd3 in _0x35a35f){if(_0x35a35f['hasOwnProperty'](_0x3d2cd3)){_0x382e3d[_0x275a('0xe')]=0x2;_0x382e3d[_0x275a('0xf')]=[];_0x382e3d['extension']=_[_0x275a('0x10')](_0x13b1fa,{'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')]});_0x382e3d[_0x275a('0xf')]['push']({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':util[_0x275a('0x13')](_0x275a('0x14'),_0x35a35f[_0x3d2cd3][0x0]['type']),'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});if(_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')]===_0x275a('0x17')){_0x382e3d['extensions'][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':_0x275a('0x19')+_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')],'context':_0x35a35f[_0x3d2cd3][0x0]['context'],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});}else if(_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')]===_0x275a('0x1a')){if(_0x382e3d['extension']){_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':'CDR(destination)='+(_0x382e3d['extension'][_0x275a('0x1b')]?_0x275a('0x1c')+_0x382e3d[_0x275a('0x1d')][_0x275a('0x1b')]+'}':_0x275a('0x1e')),'context':_0x35a35f[_0x3d2cd3][0x0]['context'],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0]['VoiceExtensionId']});}_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':_0x275a('0x19')+_0x35a35f[_0x3d2cd3][0x0]['VoiceExtensionId'],'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0]['VoiceExtensionId']});var _0x47528d=_0x382e3d[_0x275a('0xe')]++;_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':'ExecIf','appdata':_0x275a('0x1f')+(_0x47528d+0x2)+_0x275a('0x20')+(_0x47528d+0x1)+')','context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x47528d,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});if(_0x382e3d[_0x275a('0x1d')]){_0x382e3d['extensions'][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':_0x382e3d[_0x275a('0x1d')][_0x275a('0x1b')]?_0x275a('0x21')+_0x382e3d[_0x275a('0x1d')][_0x275a('0x1b')]+'}':_0x275a('0x22'),'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0]['exten'],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});}_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':_0x275a('0x23')+_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')],'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});if(_0x382e3d['extension']&&_0x382e3d[_0x275a('0x1d')][_0x275a('0x24')](_0x275a('0x25'))&&_0x382e3d[_0x275a('0x1d')][_0x275a('0x25')]!==_0x275a('0x26')){_0x382e3d['extensions'][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':_0x275a('0x27'),'context':_0x35a35f[_0x3d2cd3][0x0]['context'],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d['priority']++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0]['VoiceExtensionId']});_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':_0x275a('0x28')+_0x382e3d[_0x275a('0x1d')][_0x275a('0x25')]||_0x275a('0x29'),'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});}}_0x382e3d[_0x275a('0xf')]['push']({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':_0x275a('0x2a'),'context':_0x35a35f[_0x3d2cd3][0x0]['context'],'exten':_0x35a35f[_0x3d2cd3][0x0]['exten'],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0]['VoiceExtensionId']});_0x382e3d[_0x275a('0xf')]['push']({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':'XCALLY-MOTION-PROGRESS=0','context':_0x35a35f[_0x3d2cd3][0x0]['context'],'exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});_0x382e3d['extensions'][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0]['type'],'app':_0x275a('0x12'),'appdata':_0x275a('0x2b'),'context':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x15')],'exten':_0x35a35f[_0x3d2cd3][0x0]['exten'],'priority':_0x382e3d[_0x275a('0xe')]++,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});for(var _0x216e2a=0x0,_0x4485db=0x0;_0x216e2a<_0x35a35f[_0x3d2cd3][_0x275a('0x2c')];_0x216e2a+=0x1,_0x4485db=0x0){var _0x1c5dde=_0x35a35f[_0x3d2cd3][_0x216e2a];if(_0x1c5dde[_0x275a('0x11')]){_0x1c5dde[_0x275a('0x11')]=_0x1c5dde[_0x275a('0x11')]['toLowerCase']();}var _0x3a87cd=[];var _0x29168f=[];delete _0x1c5dde['id'];delete _0x1c5dde[_0x275a('0x2d')];delete _0x1c5dde['updatedAt'];var _0x5b5a9d=_0x1c5dde['interval']!==_0x275a('0x2e')?[_0x1c5dde[_0x275a('0x2f')]]:_0x1c5dde['IntervalId']?_[_0x275a('0x30')](_['filter'](_0x382e3d[_0x275a('0x6')],{'IntervalId':_0x1c5dde['IntervalId']}),_0x275a('0x2f')):[];if(_0x1c5dde[_0x275a('0x24')](_0x275a('0x31'))){if(_0x1c5dde[_0x275a('0x31')]&&_0x1c5dde['tag']!=='--'){_0x3a87cd[_0x275a('0x18')]({'type':_0x1c5dde['type'],'app':_0x275a('0x12'),'appdata':_0x275a('0x32')+_0x1c5dde[_0x275a('0x31')],'context':_0x1c5dde['context'],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d['length']+_0x382e3d[_0x275a('0xe')]+_0x4485db++,'VoiceExtensionId':_0x1c5dde['VoiceExtensionId']});}}if(_0x1c5dde[_0x275a('0x11')]===_0x275a('0x1a')&&_0x1c5dde[_0x275a('0x24')](_0x275a('0x33'))){if(_0x1c5dde[_0x275a('0x33')]){_0x3a87cd['push']({'type':_0x1c5dde[_0x275a('0x11')],'app':_0x275a('0x34'),'appdata':_0x275a('0x35')+_0x1c5dde[_0x275a('0x33')]+')','context':_0x1c5dde[_0x275a('0x15')],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d['length']+_0x382e3d[_0x275a('0xe')]+_0x4485db++,'VoiceExtensionId':_0x1c5dde[_0x275a('0x16')]});}else{_0x3a87cd[_0x275a('0x18')]({'type':_0x1c5dde[_0x275a('0x11')],'app':'ExecIf','appdata':_0x275a('0x36'),'context':_0x1c5dde['context'],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d[_0x275a('0x2c')]+_0x382e3d[_0x275a('0xe')]+_0x4485db++,'VoiceExtensionId':_0x1c5dde[_0x275a('0x16')]});}}if(_0x1c5dde[_0x275a('0x24')]('answer')){if(_0x2e488c[_0x275a('0x37')](_0x1c5dde[_0x275a('0x38')][_0x275a('0x39')]())>=0x0&&_0x1c5dde['appType']!==_0x275a('0x3a')){if(_0x1c5dde[_0x275a('0x3b')]){_0x3a87cd[_0x275a('0x18')]({'type':_0x1c5dde['type'],'app':_0x275a('0x34'),'appdata':_0x275a('0x3c'),'context':_0x1c5dde['context'],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d[_0x275a('0x2c')]+_0x382e3d['priority']+_0x4485db++,'VoiceExtensionId':_0x1c5dde[_0x275a('0x16')]});_0x3a87cd[_0x275a('0x18')]({'type':_0x1c5dde[_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':'XCALLY-MOTION-ANSWER=1','context':_0x1c5dde[_0x275a('0x15')],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d[_0x275a('0x2c')]+_0x382e3d[_0x275a('0xe')]+_0x4485db++,'VoiceExtensionId':_0x1c5dde[_0x275a('0x16')]});}else{_0x3a87cd['push']({'type':_0x1c5dde['type'],'app':_0x275a('0x34'),'appdata':'$[${XCALLY-MOTION-PROGRESS}=0]?Progress','context':_0x1c5dde['context'],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d['length']+_0x382e3d[_0x275a('0xe')]+_0x4485db++,'VoiceExtensionId':_0x1c5dde['VoiceExtensionId']});_0x3a87cd[_0x275a('0x18')]({'type':_0x1c5dde[_0x275a('0x11')],'app':_0x275a('0x12'),'appdata':_0x275a('0x3d'),'context':_0x1c5dde[_0x275a('0x15')],'exten':_0x1c5dde[_0x275a('0x9')],'priority':_0x5b5a9d[_0x275a('0x2c')]+_0x382e3d['priority']+_0x4485db++,'VoiceExtensionId':_0x1c5dde[_0x275a('0x16')]});}}}for(var _0x58a1b3=0x0;_0x58a1b3<_0x5b5a9d[_0x275a('0x2c')];_0x58a1b3+=0x1){var _0x729210=_0x382e3d[_0x275a('0xe')]+_0x5b5a9d['length'];var _0x5c234e=_0x58a1b3===_0x5b5a9d[_0x275a('0x2c')]-0x1?_0x382e3d[_0x275a('0xe')]+_0x3a87cd[_0x275a('0x2c')]+_0x29168f[_0x275a('0x2c')]+0x2:_0x382e3d[_0x275a('0xe')]+_0x58a1b3+0x1;_0x3a87cd['splice'](_0x58a1b3,0x0,{'type':_0x1c5dde[_0x275a('0x11')],'app':_0x275a('0x3e'),'appdata':_0x5b5a9d[_0x58a1b3]+'?'+_0x1c5dde['context']+',${EXTEN},'+_0x729210+':'+_0x1c5dde['context']+_0x275a('0x3f')+_0x5c234e,'exten':_0x1c5dde['exten'],'context':_0x1c5dde[_0x275a('0x15')],'priority':_0x382e3d[_0x275a('0xe')]+_0x58a1b3,'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});}_0x1c5dde[_0x275a('0xe')]=_0x3a87cd[_0x275a('0x2c')]?_[_0x275a('0x40')](_0x3a87cd)['priority']+0x1:_0x382e3d[_0x275a('0xe')];_0x382e3d[_0x275a('0xe')]=(_0x29168f[_0x275a('0x2c')]?_['last'](_0x29168f)['priority']:_0x1c5dde[_0x275a('0xe')])+0x1;_0x382e3d['extensions']=_[_0x275a('0x41')](_0x382e3d[_0x275a('0xf')],_0x3a87cd,[_0x1c5dde],_0x29168f);}_0x382e3d[_0x275a('0xf')][_0x275a('0x18')]({'type':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x11')],'app':'Hangup','exten':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x9')],'context':_0x35a35f[_0x3d2cd3][0x0]['context'],'priority':_0x382e3d[_0x275a('0xe')],'VoiceExtensionId':_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]});_0x3d30e5[_0x275a('0x18')](_0x35a35f[_0x3d2cd3][0x0][_0x275a('0x16')]);_0x505284=_[_0x275a('0x41')](_0x505284,_0x382e3d[_0x275a('0xf')]);}}return _0x54e032[_0x275a('0x42')](function(_0x2f9fd9){return _0x54e032[_0x275a('0x2')]['VoiceExtension'][_0x275a('0x43')]({'where':{'VoiceExtensionId':{'$in':_0x3d30e5}},'transaction':_0x2f9fd9})[_0x275a('0x5')](function(_0x211381){return _0x54e032[_0x275a('0x2')]['VoiceExtension'][_0x275a('0x44')](_[_0x275a('0x45')](_0x505284,'priority'),{'transaction':_0x2f9fd9});});});})[_0x275a('0x46')](function(_0x159fb9){console[_0x275a('0x47')](_0x159fb9);});}exports[_0x275a('0x48')]=rewrite;