Built motion from commit (unavailable).|2.3.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 _0x226f=['sortBy','error','lodash','util','models','Interval','findAll','intervals','IntervalId','VoiceExtension','uniq','map','CAST(priority\x20AS\x20UNSIGNED)','then','filter','groupBy','exten','queue','playback','hasOwnProperty','priority','extensions','extension','find','push','Set','format','CDR(type)=%s','type','context','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','VoiceExtensionId','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','createdAt','interval','*,*,*,*','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','toLowerCase','appType','answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','splice','GotoIfTime',',${EXTEN},','concat','Hangup','transaction','destroy'];(function(_0x56e4a3,_0x471885){var _0x318330=function(_0x5613cd){while(--_0x5613cd){_0x56e4a3['push'](_0x56e4a3['shift']());}};_0x318330(++_0x471885);}(_0x226f,0x11e));var _0xf226=function(_0x227383,_0x443562){_0x227383=_0x227383-0x0;var _0x2d3cbc=_0x226f[_0x227383];return _0x2d3cbc;};'use strict';var _=require(_0xf226('0x0'));var util=require(_0xf226('0x1'));function rewrite(_0x597b16,_0x3de09e){var _0x1a43f1=this;return _0x597b16[_0xf226('0x2')][_0xf226('0x3')][_0xf226('0x4')]({'raw':!![]})['then'](function(_0x13faf1){_0x1a43f1[_0xf226('0x5')]=_0x13faf1;return _0x597b16[_0xf226('0x2')]['VoiceExtension']['findAll']({'where':{'IntervalId':_0x3de09e[_0xf226('0x6')]},'raw':!![]});})['then'](function(_0x6aad9a){return _0x597b16[_0xf226('0x2')][_0xf226('0x7')]['findAll']({'where':{'exten':{'$in':_[_0xf226('0x8')](_[_0xf226('0x9')](_0x6aad9a,'exten'))}},'order':[{'raw':_0xf226('0xa')}],'raw':!![]});})[_0xf226('0xb')](function(_0x28ce97){var _0x2e2b88=_[_0xf226('0xc')](_0x28ce97,{'priority':'1'});var _0x3aeae2=_[_0xf226('0xc')](_0x28ce97,{'isApp':0x1});var _0x8c18b0=_[_0xf226('0xd')](_0x3aeae2,_0xf226('0xe'));var _0xaadf2=[_0xf226('0xf'),_0xf226('0x10')];var _0x2376d4=[];var _0x475381=[];for(var _0x58f783 in _0x8c18b0){if(_0x8c18b0[_0xf226('0x11')](_0x58f783)){_0x1a43f1[_0xf226('0x12')]=0x2;_0x1a43f1[_0xf226('0x13')]=[];_0x1a43f1[_0xf226('0x14')]=_[_0xf226('0x15')](_0x2e2b88,{'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')]});_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0]['type'],'app':_0xf226('0x17'),'appdata':util[_0xf226('0x18')](_0xf226('0x19'),_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')]),'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0]['VoiceExtensionId']});if(_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')]==='outbound'){if(_0x1a43f1[_0xf226('0x14')]){_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x1c')+(_0x1a43f1[_0xf226('0x14')][_0xf226('0x1d')]?_0xf226('0x1e')+_0x1a43f1[_0xf226('0x14')][_0xf226('0x1d')]+'}':_0xf226('0x1f')),'context':_0x8c18b0[_0x58f783][0x0]['context'],'exten':_0x8c18b0[_0x58f783][0x0]['exten'],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});}_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':'Set','appdata':'CDR(routeid)='+_0x8c18b0[_0x58f783][0x0]['VoiceExtensionId'],'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0]['exten'],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});var _0x5bbefd=_0x1a43f1[_0xf226('0x12')]++;_0x1a43f1[_0xf226('0x13')]['push']({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x21'),'appdata':_0xf226('0x22')+(_0x5bbefd+0x2)+_0xf226('0x23')+(_0x5bbefd+0x1)+')','context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x5bbefd,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});if(_0x1a43f1[_0xf226('0x14')]){_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0x1a43f1[_0xf226('0x14')][_0xf226('0x1d')]?_0xf226('0x24')+_0x1a43f1[_0xf226('0x14')]['cutdigits']+'}':_0xf226('0x25'),'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x1a43f1['priority']++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});}_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x26')+_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')],'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x1a43f1['priority']++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});if(_0x1a43f1['extension']&&_0x1a43f1[_0xf226('0x14')][_0xf226('0x11')]('recordingFormat')&&_0x1a43f1[_0xf226('0x14')][_0xf226('0x27')]!==_0xf226('0x28')){_0x1a43f1[_0xf226('0x13')]['push']({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':'Set','appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x1a43f1['priority']++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x29')+_0x1a43f1['extension'][_0xf226('0x27')]||_0xf226('0x2a'),'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});}}_0x1a43f1[_0xf226('0x13')]['push']({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':'Set','appdata':_0xf226('0x2b'),'context':_0x8c18b0[_0x58f783][0x0]['context'],'exten':_0x8c18b0[_0x58f783][0x0]['exten'],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x2c'),'context':_0x8c18b0[_0x58f783][0x0]['context'],'exten':_0x8c18b0[_0x58f783][0x0]['exten'],'priority':_0x1a43f1[_0xf226('0x12')]++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});_0x1a43f1[_0xf226('0x13')][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0]['type'],'app':_0xf226('0x17'),'appdata':_0xf226('0x2d'),'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'exten':_0x8c18b0[_0x58f783][0x0]['exten'],'priority':_0x1a43f1['priority']++,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0]['VoiceExtensionId']});for(var _0x3c3725=0x0,_0x970f2a=0x0;_0x3c3725<_0x8c18b0[_0x58f783][_0xf226('0x2e')];_0x3c3725+=0x1,_0x970f2a=0x0){var _0x4ebb82=_0x8c18b0[_0x58f783][_0x3c3725];if(_0x4ebb82[_0xf226('0x1a')]){_0x4ebb82[_0xf226('0x1a')]=_0x4ebb82[_0xf226('0x1a')]['toLowerCase']();}var _0x42217c=[];var _0x5a005e=[];delete _0x4ebb82['id'];delete _0x4ebb82[_0xf226('0x2f')];delete _0x4ebb82['updatedAt'];var _0xdc87e8=_0x4ebb82[_0xf226('0x30')]!==_0xf226('0x31')?[_0x4ebb82['interval']]:_0x4ebb82[_0xf226('0x6')]?_['map'](_[_0xf226('0xc')](_0x1a43f1['intervals'],{'IntervalId':_0x4ebb82[_0xf226('0x6')]}),_0xf226('0x30')):[];if(_0x4ebb82[_0xf226('0x11')]('tag')){if(_0x4ebb82[_0xf226('0x32')]&&_0x4ebb82[_0xf226('0x32')]!=='--'){_0x42217c[_0xf226('0x16')]({'type':_0x4ebb82[_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x33')+_0x4ebb82[_0xf226('0x32')],'context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8[_0xf226('0x2e')]+_0x1a43f1['priority']+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});}}if(_0x4ebb82['type']==='outbound'&&_0x4ebb82[_0xf226('0x11')](_0xf226('0x34'))){if(_0x4ebb82[_0xf226('0x34')]){_0x42217c['push']({'type':_0x4ebb82[_0xf226('0x1a')],'app':_0xf226('0x21'),'appdata':_0xf226('0x35')+_0x4ebb82['callerID']+')','context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8[_0xf226('0x2e')]+_0x1a43f1[_0xf226('0x12')]+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});}else{_0x42217c[_0xf226('0x16')]({'type':_0x4ebb82['type'],'app':'ExecIf','appdata':_0xf226('0x36'),'context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8['length']+_0x1a43f1[_0xf226('0x12')]+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});}}if(_0x4ebb82[_0xf226('0x11')]('answer')){if(_0xaadf2[_0xf226('0x37')](_0x4ebb82[_0xf226('0x38')][_0xf226('0x39')]())>=0x0&&_0x4ebb82[_0xf226('0x3a')]!=='custom'){if(_0x4ebb82[_0xf226('0x3b')]){_0x42217c[_0xf226('0x16')]({'type':_0x4ebb82['type'],'app':_0xf226('0x21'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8['length']+_0x1a43f1[_0xf226('0x12')]+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});_0x42217c[_0xf226('0x16')]({'type':_0x4ebb82[_0xf226('0x1a')],'app':_0xf226('0x17'),'appdata':_0xf226('0x3c'),'context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8[_0xf226('0x2e')]+_0x1a43f1['priority']+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});}else{_0x42217c['push']({'type':_0x4ebb82['type'],'app':_0xf226('0x21'),'appdata':_0xf226('0x3d'),'context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8[_0xf226('0x2e')]+_0x1a43f1[_0xf226('0x12')]+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});_0x42217c['push']({'type':_0x4ebb82[_0xf226('0x1a')],'app':'Set','appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x4ebb82[_0xf226('0x1b')],'exten':_0x4ebb82[_0xf226('0xe')],'priority':_0xdc87e8['length']+_0x1a43f1['priority']+_0x970f2a++,'VoiceExtensionId':_0x4ebb82[_0xf226('0x20')]});}}}for(var _0x2ec7c2=0x0;_0x2ec7c2<_0xdc87e8[_0xf226('0x2e')];_0x2ec7c2+=0x1){var _0x521d7d=_0x1a43f1[_0xf226('0x12')]+_0xdc87e8[_0xf226('0x2e')];var _0x215655=_0x2ec7c2===_0xdc87e8[_0xf226('0x2e')]-0x1?_0x1a43f1['priority']+_0x42217c[_0xf226('0x2e')]+_0x5a005e[_0xf226('0x2e')]+0x2:_0x1a43f1['priority']+_0x2ec7c2+0x1;_0x42217c[_0xf226('0x3e')](_0x2ec7c2,0x0,{'type':_0x4ebb82['type'],'app':_0xf226('0x3f'),'appdata':_0xdc87e8[_0x2ec7c2]+'?'+_0x4ebb82[_0xf226('0x1b')]+_0xf226('0x40')+_0x521d7d+':'+_0x4ebb82[_0xf226('0x1b')]+_0xf226('0x40')+_0x215655,'exten':_0x4ebb82[_0xf226('0xe')],'context':_0x4ebb82[_0xf226('0x1b')],'priority':_0x1a43f1[_0xf226('0x12')]+_0x2ec7c2,'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});}_0x4ebb82[_0xf226('0x12')]=_0x42217c['length']?_['last'](_0x42217c)[_0xf226('0x12')]+0x1:_0x1a43f1['priority'];_0x1a43f1[_0xf226('0x12')]=(_0x5a005e[_0xf226('0x2e')]?_['last'](_0x5a005e)[_0xf226('0x12')]:_0x4ebb82[_0xf226('0x12')])+0x1;_0x1a43f1[_0xf226('0x13')]=_[_0xf226('0x41')](_0x1a43f1[_0xf226('0x13')],_0x42217c,[_0x4ebb82],_0x5a005e);}_0x1a43f1['extensions'][_0xf226('0x16')]({'type':_0x8c18b0[_0x58f783][0x0]['type'],'app':_0xf226('0x42'),'exten':_0x8c18b0[_0x58f783][0x0][_0xf226('0xe')],'context':_0x8c18b0[_0x58f783][0x0][_0xf226('0x1b')],'priority':_0x1a43f1[_0xf226('0x12')],'VoiceExtensionId':_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]});_0x2376d4['push'](_0x8c18b0[_0x58f783][0x0][_0xf226('0x20')]);_0x475381=_['concat'](_0x475381,_0x1a43f1[_0xf226('0x13')]);}}return _0x597b16[_0xf226('0x43')](function(_0x5b9496){return _0x597b16[_0xf226('0x2')]['VoiceExtension'][_0xf226('0x44')]({'where':{'VoiceExtensionId':{'$in':_0x2376d4}},'transaction':_0x5b9496})[_0xf226('0xb')](function(_0x273ca0){return _0x597b16[_0xf226('0x2')]['VoiceExtension']['bulkCreate'](_[_0xf226('0x45')](_0x475381,_0xf226('0x12')),{'transaction':_0x5b9496});});});})['catch'](function(_0x4c3885){console[_0xf226('0x46')](_0x4c3885);});}exports['rewrite']=rewrite;