7aee92dc77b2eb7a3cc68f2ced79d89335a69d65
[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 _0x8653=['_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-PROGRESS=0','toLowerCase','createdAt','interval','map','intervals','tag','CDR(tag)=','length','callerID','ExecIf','answer','indexOf','app','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','concat','transaction','bulkCreate','sortBy','catch','rewrite','Interval','models','findAll','IntervalId','VoiceExtension','uniq','exten','CAST(priority\x20AS\x20UNSIGNED)','then','filter','groupBy','queue','playback','hasOwnProperty','priority','find','extensions','push','Set','format','context','VoiceExtensionId','type','outbound','extension','CDR(destination)=','cutdigits','${EXTEN}','CDR(routeid)=','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','recordingFormat','none'];(function(_0x3a1064,_0x49498e){var _0x4a873f=function(_0x21bcd4){while(--_0x21bcd4){_0x3a1064['push'](_0x3a1064['shift']());}};_0x4a873f(++_0x49498e);}(_0x8653,0x17a));var _0x3865=function(_0x463f3b,_0x5caef9){_0x463f3b=_0x463f3b-0x0;var _0x3f5d36=_0x8653[_0x463f3b];return _0x3f5d36;};'use strict';var _=require('lodash');var util=require('util');function rewrite(_0x490105,_0x3adb9c){var _0xe40248=this;return _0x490105['models'][_0x3865('0x0')]['findAll']({'raw':!![]})['then'](function(_0x2dffc4){_0xe40248['intervals']=_0x2dffc4;return _0x490105[_0x3865('0x1')]['VoiceExtension'][_0x3865('0x2')]({'where':{'IntervalId':_0x3adb9c[_0x3865('0x3')]},'raw':!![]});})['then'](function(_0x5b23d4){return _0x490105[_0x3865('0x1')][_0x3865('0x4')]['findAll']({'where':{'exten':{'$in':_[_0x3865('0x5')](_['map'](_0x5b23d4,_0x3865('0x6')))}},'order':[{'raw':_0x3865('0x7')}],'raw':!![]});})[_0x3865('0x8')](function(_0x161bad){var _0x238edf=_[_0x3865('0x9')](_0x161bad,{'priority':'1'});var _0xae09be=_[_0x3865('0x9')](_0x161bad,{'isApp':0x1});var _0x591c14=_[_0x3865('0xa')](_0xae09be,_0x3865('0x6'));var _0x2c7b6e=[_0x3865('0xb'),_0x3865('0xc')];var _0x56f4a2=[];var _0x1bfaca=[];for(var _0x44c958 in _0x591c14){if(_0x591c14[_0x3865('0xd')](_0x44c958)){_0xe40248[_0x3865('0xe')]=0x2;_0xe40248['extensions']=[];_0xe40248['extension']=_[_0x3865('0xf')](_0x238edf,{'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')]});_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0]['type'],'app':_0x3865('0x12'),'appdata':util[_0x3865('0x13')]('CDR(type)=%s',_0x591c14[_0x44c958][0x0]['type']),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});if(_0x591c14[_0x44c958][0x0][_0x3865('0x16')]===_0x3865('0x17')){if(_0xe40248[_0x3865('0x18')]){_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0]['type'],'app':_0x3865('0x12'),'appdata':_0x3865('0x19')+(_0xe40248[_0x3865('0x18')][_0x3865('0x1a')]?'${EXTEN:'+_0xe40248[_0x3865('0x18')][_0x3865('0x1a')]+'}':_0x3865('0x1b')),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});}_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0]['type'],'app':_0x3865('0x12'),'appdata':_0x3865('0x1c')+_0x591c14[_0x44c958][0x0]['VoiceExtensionId'],'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0]['exten'],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});var _0x461d31=_0xe40248[_0x3865('0xe')]++;_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0]['type'],'app':'ExecIf','appdata':_0x3865('0x1d')+(_0x461d31+0x2)+_0x3865('0x1e')+(_0x461d31+0x1)+')','context':_0x591c14[_0x44c958][0x0]['context'],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0x461d31,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});if(_0xe40248['extension']){_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':'Set','appdata':_0xe40248[_0x3865('0x18')][_0x3865('0x1a')]?_0x3865('0x1f')+_0xe40248[_0x3865('0x18')]['cutdigits']+'}':_0x3865('0x20'),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});}_0xe40248['extensions'][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':_0x3865('0x21')+_0x591c14[_0x44c958][0x0][_0x3865('0x15')],'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0]['exten'],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});if(_0xe40248[_0x3865('0x18')]&&_0xe40248[_0x3865('0x18')][_0x3865('0xd')](_0x3865('0x22'))&&_0xe40248[_0x3865('0x18')]['recordingFormat']!==_0x3865('0x23')){_0xe40248['extensions'][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':_0x3865('0x24'),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});_0xe40248[_0x3865('0x10')]['push']({'type':_0x591c14[_0x44c958][0x0]['type'],'app':_0x3865('0x12'),'appdata':_0x3865('0x25')+_0xe40248[_0x3865('0x18')][_0x3865('0x22')]||_0x3865('0x26'),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});}}_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248['priority']++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0]['VoiceExtensionId']});_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':_0x3865('0x27'),'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0]['VoiceExtensionId']});_0xe40248[_0x3865('0x10')]['push']({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':'MONITOR_OPTIONS=ab','context':_0x591c14[_0x44c958][0x0]['context'],'exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'priority':_0xe40248[_0x3865('0xe')]++,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});for(var _0x1730fc=0x0,_0xdb0bb3=0x0;_0x1730fc<_0x591c14[_0x44c958]['length'];_0x1730fc+=0x1,_0xdb0bb3=0x0){var _0x4a0dcd=_0x591c14[_0x44c958][_0x1730fc];if(_0x4a0dcd['type']){_0x4a0dcd['type']=_0x4a0dcd[_0x3865('0x16')][_0x3865('0x28')]();}var _0x526b59=[];var _0x3243f3=[];delete _0x4a0dcd['id'];delete _0x4a0dcd[_0x3865('0x29')];delete _0x4a0dcd['updatedAt'];var _0x414154=_0x4a0dcd[_0x3865('0x2a')]!=='*,*,*,*'?[_0x4a0dcd[_0x3865('0x2a')]]:_0x4a0dcd[_0x3865('0x3')]?_[_0x3865('0x2b')](_[_0x3865('0x9')](_0xe40248[_0x3865('0x2c')],{'IntervalId':_0x4a0dcd['IntervalId']}),_0x3865('0x2a')):[];if(_0x4a0dcd['hasOwnProperty'](_0x3865('0x2d'))){if(_0x4a0dcd['tag']&&_0x4a0dcd[_0x3865('0x2d')]!=='--'){_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd[_0x3865('0x16')],'app':_0x3865('0x12'),'appdata':_0x3865('0x2e')+_0x4a0dcd[_0x3865('0x2d')],'context':_0x4a0dcd[_0x3865('0x14')],'exten':_0x4a0dcd[_0x3865('0x6')],'priority':_0x414154[_0x3865('0x2f')]+_0xe40248[_0x3865('0xe')]+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd[_0x3865('0x15')]});}}if(_0x4a0dcd[_0x3865('0x16')]===_0x3865('0x17')&&_0x4a0dcd[_0x3865('0xd')]('callerID')){if(_0x4a0dcd[_0x3865('0x30')]){_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd['type'],'app':_0x3865('0x31'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0x4a0dcd[_0x3865('0x30')]+')','context':_0x4a0dcd[_0x3865('0x14')],'exten':_0x4a0dcd[_0x3865('0x6')],'priority':_0x414154['length']+_0xe40248[_0x3865('0xe')]+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd[_0x3865('0x15')]});}else{_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd[_0x3865('0x16')],'app':_0x3865('0x31'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','context':_0x4a0dcd[_0x3865('0x14')],'exten':_0x4a0dcd[_0x3865('0x6')],'priority':_0x414154[_0x3865('0x2f')]+_0xe40248[_0x3865('0xe')]+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd['VoiceExtensionId']});}}if(_0x4a0dcd[_0x3865('0xd')](_0x3865('0x32'))){if(_0x2c7b6e[_0x3865('0x33')](_0x4a0dcd[_0x3865('0x34')][_0x3865('0x28')]())>=0x0&&_0x4a0dcd[_0x3865('0x35')]!==_0x3865('0x36')){if(_0x4a0dcd[_0x3865('0x32')]){_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd[_0x3865('0x16')],'app':_0x3865('0x31'),'appdata':_0x3865('0x37'),'context':_0x4a0dcd[_0x3865('0x14')],'exten':_0x4a0dcd[_0x3865('0x6')],'priority':_0x414154[_0x3865('0x2f')]+_0xe40248[_0x3865('0xe')]+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd['VoiceExtensionId']});_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd['type'],'app':'Set','appdata':_0x3865('0x38'),'context':_0x4a0dcd['context'],'exten':_0x4a0dcd['exten'],'priority':_0x414154[_0x3865('0x2f')]+_0xe40248['priority']+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd['VoiceExtensionId']});}else{_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd[_0x3865('0x16')],'app':_0x3865('0x31'),'appdata':_0x3865('0x39'),'context':_0x4a0dcd['context'],'exten':_0x4a0dcd[_0x3865('0x6')],'priority':_0x414154['length']+_0xe40248[_0x3865('0xe')]+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd['VoiceExtensionId']});_0x526b59[_0x3865('0x11')]({'type':_0x4a0dcd[_0x3865('0x16')],'app':'Set','appdata':_0x3865('0x3a'),'context':_0x4a0dcd[_0x3865('0x14')],'exten':_0x4a0dcd['exten'],'priority':_0x414154['length']+_0xe40248['priority']+_0xdb0bb3++,'VoiceExtensionId':_0x4a0dcd[_0x3865('0x15')]});}}}for(var _0x14112f=0x0;_0x14112f<_0x414154[_0x3865('0x2f')];_0x14112f+=0x1){var _0x17ec26=_0xe40248['priority']+_0x414154[_0x3865('0x2f')];var _0x45033d=_0x14112f===_0x414154['length']-0x1?_0xe40248[_0x3865('0xe')]+_0x526b59[_0x3865('0x2f')]+_0x3243f3['length']+0x2:_0xe40248['priority']+_0x14112f+0x1;_0x526b59[_0x3865('0x3b')](_0x14112f,0x0,{'type':_0x4a0dcd[_0x3865('0x16')],'app':_0x3865('0x3c'),'appdata':_0x414154[_0x14112f]+'?'+_0x4a0dcd[_0x3865('0x14')]+_0x3865('0x3d')+_0x17ec26+':'+_0x4a0dcd[_0x3865('0x14')]+',${EXTEN},'+_0x45033d,'exten':_0x4a0dcd[_0x3865('0x6')],'context':_0x4a0dcd[_0x3865('0x14')],'priority':_0xe40248[_0x3865('0xe')]+_0x14112f,'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});}_0x4a0dcd['priority']=_0x526b59[_0x3865('0x2f')]?_[_0x3865('0x3e')](_0x526b59)[_0x3865('0xe')]+0x1:_0xe40248[_0x3865('0xe')];_0xe40248['priority']=(_0x3243f3[_0x3865('0x2f')]?_[_0x3865('0x3e')](_0x3243f3)[_0x3865('0xe')]:_0x4a0dcd[_0x3865('0xe')])+0x1;_0xe40248[_0x3865('0x10')]=_[_0x3865('0x3f')](_0xe40248[_0x3865('0x10')],_0x526b59,[_0x4a0dcd],_0x3243f3);}_0xe40248[_0x3865('0x10')][_0x3865('0x11')]({'type':_0x591c14[_0x44c958][0x0][_0x3865('0x16')],'app':'Hangup','exten':_0x591c14[_0x44c958][0x0][_0x3865('0x6')],'context':_0x591c14[_0x44c958][0x0][_0x3865('0x14')],'priority':_0xe40248[_0x3865('0xe')],'VoiceExtensionId':_0x591c14[_0x44c958][0x0][_0x3865('0x15')]});_0x56f4a2['push'](_0x591c14[_0x44c958][0x0][_0x3865('0x15')]);_0x1bfaca=_[_0x3865('0x3f')](_0x1bfaca,_0xe40248[_0x3865('0x10')]);}}return _0x490105[_0x3865('0x40')](function(_0x41435f){return _0x490105[_0x3865('0x1')]['VoiceExtension']['destroy']({'where':{'VoiceExtensionId':{'$in':_0x56f4a2}},'transaction':_0x41435f})[_0x3865('0x8')](function(_0x3e5ad1){return _0x490105[_0x3865('0x1')]['VoiceExtension'][_0x3865('0x41')](_[_0x3865('0x42')](_0x1bfaca,'priority'),{'transaction':_0x41435f});});});})[_0x3865('0x43')](function(_0x3429c2){console['error'](_0x3429c2);});}exports[_0x3865('0x44')]=rewrite;