Built motion from commit (unavailable).|2.5.4
[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 _0x838f=['wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','createdAt','updatedAt','interval','*,*,*,*','map','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)','answer','indexOf','appType','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','destroy','bulkCreate','sortBy','catch','error','rewrite','lodash','util','models','Interval','findAll','then','intervals','IntervalId','VoiceExtension','exten','filter','groupBy','queue','playback','hasOwnProperty','priority','extensions','extension','find','push','type','format','CDR(type)=%s','context','outbound','Set','${EXTEN:','cutdigits','${EXTEN}','VoiceExtensionId','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT='];(function(_0x486b00,_0x501df5){var _0x47ea82=function(_0x997782){while(--_0x997782){_0x486b00['push'](_0x486b00['shift']());}};_0x47ea82(++_0x501df5);}(_0x838f,0x101));var _0xf838=function(_0x45bde9,_0x1c32c1){_0x45bde9=_0x45bde9-0x0;var _0x5b1a16=_0x838f[_0x45bde9];return _0x5b1a16;};'use strict';var _=require(_0xf838('0x0'));var util=require(_0xf838('0x1'));function rewrite(_0xace182,_0x38783d){var _0x3569ac=this;return _0xace182[_0xf838('0x2')][_0xf838('0x3')][_0xf838('0x4')]({'raw':!![]})[_0xf838('0x5')](function(_0x285cb4){_0x3569ac[_0xf838('0x6')]=_0x285cb4;return _0xace182[_0xf838('0x2')]['VoiceExtension']['findAll']({'where':{'IntervalId':_0x38783d[_0xf838('0x7')]},'raw':!![]});})[_0xf838('0x5')](function(_0x31688b){return _0xace182['models'][_0xf838('0x8')][_0xf838('0x4')]({'where':{'exten':{'$in':_['uniq'](_['map'](_0x31688b,_0xf838('0x9')))}},'order':[{'raw':'CAST(priority\x20AS\x20UNSIGNED)'}],'raw':!![]});})[_0xf838('0x5')](function(_0x3d398b){var _0x5ddc67=_['filter'](_0x3d398b,{'priority':'1'});var _0x50a885=_[_0xf838('0xa')](_0x3d398b,{'isApp':0x1});var _0x4bd73f=_[_0xf838('0xb')](_0x50a885,_0xf838('0x9'));var _0xeaba9b=[_0xf838('0xc'),_0xf838('0xd')];var _0x575b79=[];var _0x2fd65a=[];for(var _0x9b216b in _0x4bd73f){if(_0x4bd73f[_0xf838('0xe')](_0x9b216b)){_0x3569ac[_0xf838('0xf')]=0x2;_0x3569ac[_0xf838('0x10')]=[];_0x3569ac[_0xf838('0x11')]=_[_0xf838('0x12')](_0x5ddc67,{'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')]});_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':'Set','appdata':util[_0xf838('0x15')](_0xf838('0x16'),_0x4bd73f[_0x9b216b][0x0]['type']),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0]['VoiceExtensionId']});if(_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')]===_0xf838('0x18')){if(_0x3569ac[_0xf838('0x11')]){_0x3569ac['extensions']['push']({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':'CDR(destination)='+(_0x3569ac[_0xf838('0x11')]['cutdigits']?_0xf838('0x1a')+_0x3569ac[_0xf838('0x11')][_0xf838('0x1b')]+'}':_0xf838('0x1c')),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac[_0xf838('0xf')]++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0]['VoiceExtensionId']});}_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':'CDR(routeid)='+_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')],'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});var _0x43a049=_0x3569ac[_0xf838('0xf')]++;_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0]['type'],'app':_0xf838('0x1e'),'appdata':_0xf838('0x1f')+(_0x43a049+0x2)+'):Goto('+(_0x43a049+0x1)+')','context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'priority':_0x43a049,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});if(_0x3569ac[_0xf838('0x11')]){_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':'Set','appdata':_0x3569ac[_0xf838('0x11')]['cutdigits']?_0xf838('0x20')+_0x3569ac[_0xf838('0x11')][_0xf838('0x1b')]+'}':_0xf838('0x21'),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});}_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0]['type'],'app':_0xf838('0x19'),'appdata':_0xf838('0x22')+_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')],'context':_0x4bd73f[_0x9b216b][0x0]['context'],'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});if(_0x3569ac['extension']&&_0x3569ac[_0xf838('0x11')][_0xf838('0xe')](_0xf838('0x23'))&&_0x3569ac[_0xf838('0x11')][_0xf838('0x23')]!==_0xf838('0x24')){_0x3569ac['extensions']['push']({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x25'),'context':_0x4bd73f[_0x9b216b][0x0]['context'],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac[_0xf838('0xf')]++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':'Set','appdata':_0xf838('0x26')+_0x3569ac[_0xf838('0x11')][_0xf838('0x23')]||_0xf838('0x27'),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'priority':_0x3569ac[_0xf838('0xf')]++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});}}_0x3569ac['extensions']['push']({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x28'),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0]['VoiceExtensionId']});_0x3569ac['extensions']['push']({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':'Set','appdata':_0xf838('0x29'),'context':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x17')],'exten':_0x4bd73f[_0x9b216b][0x0]['exten'],'priority':_0x3569ac[_0xf838('0xf')]++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});_0x3569ac[_0xf838('0x10')][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x2a'),'context':_0x4bd73f[_0x9b216b][0x0]['context'],'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'priority':_0x3569ac['priority']++,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});for(var _0x4f07f8=0x0,_0x1b6afd=0x0;_0x4f07f8<_0x4bd73f[_0x9b216b][_0xf838('0x2b')];_0x4f07f8+=0x1,_0x1b6afd=0x0){var _0x515e55=_0x4bd73f[_0x9b216b][_0x4f07f8];if(_0x515e55['type']){_0x515e55['type']=_0x515e55[_0xf838('0x14')]['toLowerCase']();}var _0x500a27=[];var _0x368c96=[];delete _0x515e55['id'];delete _0x515e55[_0xf838('0x2c')];delete _0x515e55[_0xf838('0x2d')];var _0x4d86b0=_0x515e55[_0xf838('0x2e')]!==_0xf838('0x2f')?[_0x515e55[_0xf838('0x2e')]]:_0x515e55[_0xf838('0x7')]?_[_0xf838('0x30')](_[_0xf838('0xa')](_0x3569ac[_0xf838('0x6')],{'IntervalId':_0x515e55[_0xf838('0x7')]}),_0xf838('0x2e')):[];if(_0x515e55[_0xf838('0xe')]('tag')){if(_0x515e55[_0xf838('0x31')]&&_0x515e55['tag']!=='--'){_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x32')+_0x515e55[_0xf838('0x31')],'context':_0x515e55[_0xf838('0x17')],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0[_0xf838('0x2b')]+_0x3569ac[_0xf838('0xf')]+_0x1b6afd++,'VoiceExtensionId':_0x515e55[_0xf838('0x1d')]});}}if(_0x515e55[_0xf838('0x14')]===_0xf838('0x18')&&_0x515e55[_0xf838('0xe')](_0xf838('0x33'))){if(_0x515e55['callerID']){_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x1e'),'appdata':_0xf838('0x34')+_0x515e55[_0xf838('0x33')]+')','context':_0x515e55['context'],'exten':_0x515e55['exten'],'priority':_0x4d86b0[_0xf838('0x2b')]+_0x3569ac['priority']+_0x1b6afd++,'VoiceExtensionId':_0x515e55['VoiceExtensionId']});}else{_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x1e'),'appdata':_0xf838('0x35'),'context':_0x515e55[_0xf838('0x17')],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0[_0xf838('0x2b')]+_0x3569ac['priority']+_0x1b6afd++,'VoiceExtensionId':_0x515e55['VoiceExtensionId']});}}if(_0x515e55[_0xf838('0xe')](_0xf838('0x36'))){if(_0xeaba9b[_0xf838('0x37')](_0x515e55['app']['toLowerCase']())>=0x0&&_0x515e55[_0xf838('0x38')]!=='custom'){if(_0x515e55['answer']){_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x1e'),'appdata':_0xf838('0x39'),'context':_0x515e55[_0xf838('0x17')],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0['length']+_0x3569ac['priority']+_0x1b6afd++,'VoiceExtensionId':_0x515e55[_0xf838('0x1d')]});_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x3a'),'context':_0x515e55['context'],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0['length']+_0x3569ac[_0xf838('0xf')]+_0x1b6afd++,'VoiceExtensionId':_0x515e55[_0xf838('0x1d')]});}else{_0x500a27[_0xf838('0x13')]({'type':_0x515e55['type'],'app':_0xf838('0x1e'),'appdata':_0xf838('0x3b'),'context':_0x515e55[_0xf838('0x17')],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0[_0xf838('0x2b')]+_0x3569ac[_0xf838('0xf')]+_0x1b6afd++,'VoiceExtensionId':_0x515e55['VoiceExtensionId']});_0x500a27[_0xf838('0x13')]({'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x19'),'appdata':_0xf838('0x3c'),'context':_0x515e55[_0xf838('0x17')],'exten':_0x515e55[_0xf838('0x9')],'priority':_0x4d86b0[_0xf838('0x2b')]+_0x3569ac[_0xf838('0xf')]+_0x1b6afd++,'VoiceExtensionId':_0x515e55[_0xf838('0x1d')]});}}}for(var _0x14d0e8=0x0;_0x14d0e8<_0x4d86b0[_0xf838('0x2b')];_0x14d0e8+=0x1){var _0x14263a=_0x3569ac['priority']+_0x4d86b0[_0xf838('0x2b')];var _0x236903=_0x14d0e8===_0x4d86b0[_0xf838('0x2b')]-0x1?_0x3569ac[_0xf838('0xf')]+_0x500a27[_0xf838('0x2b')]+_0x368c96[_0xf838('0x2b')]+0x2:_0x3569ac[_0xf838('0xf')]+_0x14d0e8+0x1;_0x500a27[_0xf838('0x3d')](_0x14d0e8,0x0,{'type':_0x515e55[_0xf838('0x14')],'app':_0xf838('0x3e'),'appdata':_0x4d86b0[_0x14d0e8]+'?'+_0x515e55[_0xf838('0x17')]+_0xf838('0x3f')+_0x14263a+':'+_0x515e55['context']+_0xf838('0x3f')+_0x236903,'exten':_0x515e55[_0xf838('0x9')],'context':_0x515e55[_0xf838('0x17')],'priority':_0x3569ac[_0xf838('0xf')]+_0x14d0e8,'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]});}_0x515e55[_0xf838('0xf')]=_0x500a27[_0xf838('0x2b')]?_[_0xf838('0x40')](_0x500a27)['priority']+0x1:_0x3569ac['priority'];_0x3569ac['priority']=(_0x368c96[_0xf838('0x2b')]?_[_0xf838('0x40')](_0x368c96)[_0xf838('0xf')]:_0x515e55[_0xf838('0xf')])+0x1;_0x3569ac[_0xf838('0x10')]=_[_0xf838('0x41')](_0x3569ac[_0xf838('0x10')],_0x500a27,[_0x515e55],_0x368c96);}_0x3569ac['extensions'][_0xf838('0x13')]({'type':_0x4bd73f[_0x9b216b][0x0]['type'],'app':_0xf838('0x42'),'exten':_0x4bd73f[_0x9b216b][0x0][_0xf838('0x9')],'context':_0x4bd73f[_0x9b216b][0x0]['context'],'priority':_0x3569ac['priority'],'VoiceExtensionId':_0x4bd73f[_0x9b216b][0x0]['VoiceExtensionId']});_0x575b79['push'](_0x4bd73f[_0x9b216b][0x0][_0xf838('0x1d')]);_0x2fd65a=_[_0xf838('0x41')](_0x2fd65a,_0x3569ac[_0xf838('0x10')]);}}return _0xace182[_0xf838('0x43')](function(_0x52be4e){return _0xace182[_0xf838('0x2')][_0xf838('0x8')][_0xf838('0x44')]({'where':{'VoiceExtensionId':{'$in':_0x575b79}},'transaction':_0x52be4e})[_0xf838('0x5')](function(_0x4f1b24){return _0xace182['models'][_0xf838('0x8')][_0xf838('0x45')](_[_0xf838('0x46')](_0x2fd65a,_0xf838('0xf')),{'transaction':_0x52be4e});});});})[_0xf838('0x47')](function(_0x18f29d){console[_0xf838('0x48')](_0x18f29d);});}exports[_0xf838('0x49')]=rewrite;