6e6711328e512e476b3cc5a89f5f2ad3e8e7e692
[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 _0x869e=['models','VoiceExtension','uniq','map','exten','filter','groupBy','queue','playback','find','extensions','Set','format','CDR(type)=%s','context','priority','type','push','CDR(routeid)=','VoiceExtensionId','extension','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','hasOwnProperty','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','recordingFormat','wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','updatedAt','interval','*,*,*,*','IntervalId','tag','CDR(tag)=','outbound','callerID','answer','indexOf','app','appType','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','concat','bulkCreate','sortBy','catch','error','rewrite','lodash','util','Interval','findAll','then','intervals'];(function(_0x5e2371,_0x1d264e){var _0x1e065b=function(_0x4bcd6a){while(--_0x4bcd6a){_0x5e2371['push'](_0x5e2371['shift']());}};_0x1e065b(++_0x1d264e);}(_0x869e,0x88));var _0xe869=function(_0x2d2e9d,_0x272e3f){_0x2d2e9d=_0x2d2e9d-0x0;var _0x59c748=_0x869e[_0x2d2e9d];return _0x59c748;};'use strict';var _=require(_0xe869('0x0'));var util=require(_0xe869('0x1'));function rewrite(_0x25b267,_0x3066d0){var _0x10540f=this;return _0x25b267['models'][_0xe869('0x2')][_0xe869('0x3')]({'raw':!![]})[_0xe869('0x4')](function(_0x59f7fb){_0x10540f[_0xe869('0x5')]=_0x59f7fb;return _0x25b267[_0xe869('0x6')][_0xe869('0x7')]['findAll']({'where':{'IntervalId':_0x3066d0['IntervalId']},'raw':!![]});})[_0xe869('0x4')](function(_0x2cf24d){return _0x25b267[_0xe869('0x6')][_0xe869('0x7')][_0xe869('0x3')]({'where':{'exten':{'$in':_[_0xe869('0x8')](_[_0xe869('0x9')](_0x2cf24d,_0xe869('0xa')))}},'order':[{'raw':'CAST(priority\x20AS\x20UNSIGNED)'}],'raw':!![]});})['then'](function(_0x36bf9c){var _0x180e34=_[_0xe869('0xb')](_0x36bf9c,{'priority':'1'});var _0x229724=_['filter'](_0x36bf9c,{'isApp':0x1});var _0xc3b70d=_[_0xe869('0xc')](_0x229724,_0xe869('0xa'));var _0x3708d1=[_0xe869('0xd'),_0xe869('0xe')];var _0x55e7b2=[];var _0x5e1884=[];for(var _0xe01acf in _0xc3b70d){if(_0xc3b70d['hasOwnProperty'](_0xe01acf)){_0x10540f['priority']=0x2;_0x10540f['extensions']=[];_0x10540f['extension']=_[_0xe869('0xf')](_0x180e34,{'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')]});_0x10540f[_0xe869('0x10')]['push']({'type':_0xc3b70d[_0xe01acf][0x0]['type'],'app':_0xe869('0x11'),'appdata':util[_0xe869('0x12')](_0xe869('0x13'),_0xc3b70d[_0xe01acf][0x0]['type']),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0]['VoiceExtensionId']});if(_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')]==='inbound'){_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0]['type'],'app':_0xe869('0x11'),'appdata':_0xe869('0x18')+_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')],'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});}else if(_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')]==='outbound'){if(_0x10540f[_0xe869('0x1a')]){_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':'Set','appdata':_0xe869('0x1b')+(_0x10540f[_0xe869('0x1a')][_0xe869('0x1c')]?_0xe869('0x1d')+_0x10540f['extension'][_0xe869('0x1c')]+'}':_0xe869('0x1e')),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});}_0x10540f['extensions']['push']({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':'CDR(routeid)='+_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')],'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f['priority']++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});var _0x56c232=_0x10540f[_0xe869('0x15')]++;_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x1f'),'appdata':_0xe869('0x20')+(_0x56c232+0x2)+_0xe869('0x21')+(_0x56c232+0x1)+')','context':_0xc3b70d[_0xe01acf][0x0]['context'],'exten':_0xc3b70d[_0xe01acf][0x0]['exten'],'priority':_0x56c232,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0]['VoiceExtensionId']});if(_0x10540f['extension']){_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0x10540f[_0xe869('0x1a')][_0xe869('0x1c')]?_0xe869('0x22')+_0x10540f[_0xe869('0x1a')][_0xe869('0x1c')]+'}':_0xe869('0x23'),'context':_0xc3b70d[_0xe01acf][0x0]['context'],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0]['VoiceExtensionId']});}_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0xe869('0x24')+_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')],'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0]['VoiceExtensionId']});if(_0x10540f[_0xe869('0x1a')]&&_0x10540f['extension'][_0xe869('0x25')]('recordingFormat')&&_0x10540f[_0xe869('0x1a')]['recordingFormat']!=='none'){_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0]['type'],'app':_0xe869('0x11'),'appdata':_0xe869('0x26'),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0]['exten'],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0xe869('0x27')+_0x10540f[_0xe869('0x1a')][_0xe869('0x28')]||_0xe869('0x29'),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0]['exten'],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});}}_0x10540f[_0xe869('0x10')]['push']({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0xe869('0x2a'),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});_0x10540f['extensions']['push']({'type':_0xc3b70d[_0xe01acf][0x0]['type'],'app':'Set','appdata':_0xe869('0x2b'),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f[_0xe869('0x15')]++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':'Set','appdata':_0xe869('0x2c'),'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'priority':_0x10540f['priority']++,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0]['VoiceExtensionId']});for(var _0x5497c8=0x0,_0x59fb81=0x0;_0x5497c8<_0xc3b70d[_0xe01acf][_0xe869('0x2d')];_0x5497c8+=0x1,_0x59fb81=0x0){var _0x363457=_0xc3b70d[_0xe01acf][_0x5497c8];if(_0x363457['type']){_0x363457[_0xe869('0x16')]=_0x363457[_0xe869('0x16')][_0xe869('0x2e')]();}var _0x5c63b9=[];var _0x2f1acb=[];delete _0x363457['id'];delete _0x363457[_0xe869('0x2f')];delete _0x363457[_0xe869('0x30')];var _0x50f728=_0x363457[_0xe869('0x31')]!==_0xe869('0x32')?[_0x363457['interval']]:_0x363457[_0xe869('0x33')]?_['map'](_[_0xe869('0xb')](_0x10540f[_0xe869('0x5')],{'IntervalId':_0x363457['IntervalId']}),_0xe869('0x31')):[];if(_0x363457['hasOwnProperty'](_0xe869('0x34'))){if(_0x363457[_0xe869('0x34')]&&_0x363457[_0xe869('0x34')]!=='--'){_0x5c63b9[_0xe869('0x17')]({'type':_0x363457[_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0xe869('0x35')+_0x363457[_0xe869('0x34')],'context':_0x363457['context'],'exten':_0x363457['exten'],'priority':_0x50f728[_0xe869('0x2d')]+_0x10540f['priority']+_0x59fb81++,'VoiceExtensionId':_0x363457[_0xe869('0x19')]});}}if(_0x363457['type']===_0xe869('0x36')&&_0x363457['hasOwnProperty'](_0xe869('0x37'))){if(_0x363457[_0xe869('0x37')]){_0x5c63b9[_0xe869('0x17')]({'type':_0x363457[_0xe869('0x16')],'app':_0xe869('0x1f'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0x363457[_0xe869('0x37')]+')','context':_0x363457['context'],'exten':_0x363457[_0xe869('0xa')],'priority':_0x50f728[_0xe869('0x2d')]+_0x10540f[_0xe869('0x15')]+_0x59fb81++,'VoiceExtensionId':_0x363457[_0xe869('0x19')]});}else{_0x5c63b9[_0xe869('0x17')]({'type':_0x363457[_0xe869('0x16')],'app':_0xe869('0x1f'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','context':_0x363457[_0xe869('0x14')],'exten':_0x363457[_0xe869('0xa')],'priority':_0x50f728[_0xe869('0x2d')]+_0x10540f['priority']+_0x59fb81++,'VoiceExtensionId':_0x363457['VoiceExtensionId']});}}if(_0x363457['hasOwnProperty'](_0xe869('0x38'))){if(_0x3708d1[_0xe869('0x39')](_0x363457[_0xe869('0x3a')]['toLowerCase']())>=0x0&&_0x363457[_0xe869('0x3b')]!=='custom'){if(_0x363457['answer']){_0x5c63b9['push']({'type':_0x363457['type'],'app':_0xe869('0x1f'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x363457['context'],'exten':_0x363457['exten'],'priority':_0x50f728[_0xe869('0x2d')]+_0x10540f['priority']+_0x59fb81++,'VoiceExtensionId':_0x363457[_0xe869('0x19')]});_0x5c63b9[_0xe869('0x17')]({'type':_0x363457[_0xe869('0x16')],'app':_0xe869('0x11'),'appdata':_0xe869('0x3c'),'context':_0x363457[_0xe869('0x14')],'exten':_0x363457[_0xe869('0xa')],'priority':_0x50f728['length']+_0x10540f[_0xe869('0x15')]+_0x59fb81++,'VoiceExtensionId':_0x363457[_0xe869('0x19')]});}else{_0x5c63b9[_0xe869('0x17')]({'type':_0x363457[_0xe869('0x16')],'app':_0xe869('0x1f'),'appdata':_0xe869('0x3d'),'context':_0x363457['context'],'exten':_0x363457[_0xe869('0xa')],'priority':_0x50f728[_0xe869('0x2d')]+_0x10540f['priority']+_0x59fb81++,'VoiceExtensionId':_0x363457['VoiceExtensionId']});_0x5c63b9[_0xe869('0x17')]({'type':_0x363457['type'],'app':_0xe869('0x11'),'appdata':_0xe869('0x3e'),'context':_0x363457[_0xe869('0x14')],'exten':_0x363457[_0xe869('0xa')],'priority':_0x50f728['length']+_0x10540f[_0xe869('0x15')]+_0x59fb81++,'VoiceExtensionId':_0x363457[_0xe869('0x19')]});}}}for(var _0x6fefda=0x0;_0x6fefda<_0x50f728[_0xe869('0x2d')];_0x6fefda+=0x1){var _0x341ca2=_0x10540f[_0xe869('0x15')]+_0x50f728[_0xe869('0x2d')];var _0x1b958b=_0x6fefda===_0x50f728[_0xe869('0x2d')]-0x1?_0x10540f[_0xe869('0x15')]+_0x5c63b9[_0xe869('0x2d')]+_0x2f1acb['length']+0x2:_0x10540f['priority']+_0x6fefda+0x1;_0x5c63b9[_0xe869('0x3f')](_0x6fefda,0x0,{'type':_0x363457[_0xe869('0x16')],'app':'GotoIfTime','appdata':_0x50f728[_0x6fefda]+'?'+_0x363457[_0xe869('0x14')]+_0xe869('0x40')+_0x341ca2+':'+_0x363457[_0xe869('0x14')]+_0xe869('0x40')+_0x1b958b,'exten':_0x363457[_0xe869('0xa')],'context':_0x363457['context'],'priority':_0x10540f[_0xe869('0x15')]+_0x6fefda,'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});}_0x363457[_0xe869('0x15')]=_0x5c63b9[_0xe869('0x2d')]?_['last'](_0x5c63b9)[_0xe869('0x15')]+0x1:_0x10540f['priority'];_0x10540f['priority']=(_0x2f1acb['length']?_['last'](_0x2f1acb)[_0xe869('0x15')]:_0x363457[_0xe869('0x15')])+0x1;_0x10540f[_0xe869('0x10')]=_[_0xe869('0x41')](_0x10540f[_0xe869('0x10')],_0x5c63b9,[_0x363457],_0x2f1acb);}_0x10540f[_0xe869('0x10')][_0xe869('0x17')]({'type':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x16')],'app':'Hangup','exten':_0xc3b70d[_0xe01acf][0x0][_0xe869('0xa')],'context':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x14')],'priority':_0x10540f[_0xe869('0x15')],'VoiceExtensionId':_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]});_0x55e7b2[_0xe869('0x17')](_0xc3b70d[_0xe01acf][0x0][_0xe869('0x19')]);_0x5e1884=_['concat'](_0x5e1884,_0x10540f[_0xe869('0x10')]);}}return _0x25b267['transaction'](function(_0x4ad27a){return _0x25b267[_0xe869('0x6')][_0xe869('0x7')]['destroy']({'where':{'VoiceExtensionId':{'$in':_0x55e7b2}},'transaction':_0x4ad27a})[_0xe869('0x4')](function(_0x1e9c6e){return _0x25b267[_0xe869('0x6')][_0xe869('0x7')][_0xe869('0x42')](_[_0xe869('0x43')](_0x5e1884,_0xe869('0x15')),{'transaction':_0x4ad27a});});});})[_0xe869('0x44')](function(_0x6852b4){console[_0xe869('0x45')](_0x6852b4);});}exports[_0xe869('0x46')]=rewrite;