Built motion from commit (unavailable).|2.5.1
[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 _0x9227=['exten','queue','playback','hasOwnProperty','priority','extensions','find','push','type','CDR(type)=%s','VoiceExtensionId','outbound','extension','CDR(destination)=','cutdigits','${EXTEN}','context','CDR(routeid)=','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','Set','outboundrouteid=','recordingFormat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','updatedAt','interval','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','appType','custom','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','destroy','sortBy','catch','error','rewrite','lodash','models','Interval','findAll','then','intervals','VoiceExtension','IntervalId','map','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy'];(function(_0x96f83,_0x91fa77){var _0x111a7a=function(_0x899fb5){while(--_0x899fb5){_0x96f83['push'](_0x96f83['shift']());}};_0x111a7a(++_0x91fa77);}(_0x9227,0xc3));var _0x7922=function(_0x19a771,_0x1e6163){_0x19a771=_0x19a771-0x0;var _0x41dc89=_0x9227[_0x19a771];return _0x41dc89;};'use strict';var _=require(_0x7922('0x0'));var util=require('util');function rewrite(_0x26532e,_0x22b565){var _0x11000e=this;return _0x26532e[_0x7922('0x1')][_0x7922('0x2')][_0x7922('0x3')]({'raw':!![]})[_0x7922('0x4')](function(_0x29fb1e){_0x11000e[_0x7922('0x5')]=_0x29fb1e;return _0x26532e[_0x7922('0x1')][_0x7922('0x6')][_0x7922('0x3')]({'where':{'IntervalId':_0x22b565[_0x7922('0x7')]},'raw':!![]});})[_0x7922('0x4')](function(_0x4e36e4){return _0x26532e[_0x7922('0x1')]['VoiceExtension']['findAll']({'where':{'exten':{'$in':_['uniq'](_[_0x7922('0x8')](_0x4e36e4,'exten'))}},'order':[{'raw':_0x7922('0x9')}],'raw':!![]});})['then'](function(_0x5aeca6){var _0x744fba=_['filter'](_0x5aeca6,{'priority':'1'});var _0x425db3=_[_0x7922('0xa')](_0x5aeca6,{'isApp':0x1});var _0x5019bf=_[_0x7922('0xb')](_0x425db3,_0x7922('0xc'));var _0x97dc0e=[_0x7922('0xd'),_0x7922('0xe')];var _0x1ecc84=[];var _0x4be919=[];for(var _0x57b3ca in _0x5019bf){if(_0x5019bf[_0x7922('0xf')](_0x57b3ca)){_0x11000e[_0x7922('0x10')]=0x2;_0x11000e[_0x7922('0x11')]=[];_0x11000e['extension']=_[_0x7922('0x12')](_0x744fba,{'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')]});_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':util['format'](_0x7922('0x15'),_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')]),'context':_0x5019bf[_0x57b3ca][0x0]['context'],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});if(_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')]===_0x7922('0x17')){if(_0x11000e[_0x7922('0x18')]){_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':_0x7922('0x19')+(_0x11000e[_0x7922('0x18')][_0x7922('0x1a')]?'${EXTEN:'+_0x11000e[_0x7922('0x18')][_0x7922('0x1a')]+'}':_0x7922('0x1b')),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});}_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':_0x7922('0x1d')+_0x5019bf[_0x57b3ca][0x0]['VoiceExtensionId'],'context':_0x5019bf[_0x57b3ca][0x0]['context'],'exten':_0x5019bf[_0x57b3ca][0x0]['exten'],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});var _0x2c5f36=_0x11000e['priority']++;_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'ExecIf','appdata':_0x7922('0x1e')+(_0x2c5f36+0x2)+_0x7922('0x1f')+(_0x2c5f36+0x1)+')','context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x2c5f36,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});if(_0x11000e[_0x7922('0x18')]){_0x11000e['extensions']['push']({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':_0x11000e[_0x7922('0x18')]['cutdigits']?_0x7922('0x20')+_0x11000e[_0x7922('0x18')][_0x7922('0x1a')]+'}':'CDR(prefix)=noprefix','context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0]['exten'],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});}_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':_0x7922('0x21'),'appdata':_0x7922('0x22')+_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')],'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});if(_0x11000e[_0x7922('0x18')]&&_0x11000e[_0x7922('0x18')][_0x7922('0xf')](_0x7922('0x23'))&&_0x11000e[_0x7922('0x18')]['recordingFormat']!=='none'){_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':_0x7922('0x24'),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e['priority']++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});_0x11000e[_0x7922('0x11')]['push']({'type':_0x5019bf[_0x57b3ca][0x0]['type'],'app':'Set','appdata':_0x7922('0x25')+_0x11000e[_0x7922('0x18')][_0x7922('0x23')]||_0x7922('0x26'),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});}}_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':_0x7922('0x21'),'appdata':_0x7922('0x27'),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0]['exten'],'priority':_0x11000e[_0x7922('0x10')]++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x14')],'app':'Set','appdata':_0x7922('0x28'),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e['priority']++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]});_0x11000e[_0x7922('0x11')]['push']({'type':_0x5019bf[_0x57b3ca][0x0]['type'],'app':'Set','appdata':_0x7922('0x29'),'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'exten':_0x5019bf[_0x57b3ca][0x0][_0x7922('0xc')],'priority':_0x11000e['priority']++,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0]['VoiceExtensionId']});for(var _0x16ff3d=0x0,_0x1b3b5e=0x0;_0x16ff3d<_0x5019bf[_0x57b3ca][_0x7922('0x2a')];_0x16ff3d+=0x1,_0x1b3b5e=0x0){var _0xf23893=_0x5019bf[_0x57b3ca][_0x16ff3d];if(_0xf23893[_0x7922('0x14')]){_0xf23893[_0x7922('0x14')]=_0xf23893[_0x7922('0x14')]['toLowerCase']();}var _0x5da427=[];var _0x14820c=[];delete _0xf23893['id'];delete _0xf23893['createdAt'];delete _0xf23893[_0x7922('0x2b')];var _0xfe7f22=_0xf23893[_0x7922('0x2c')]!=='*,*,*,*'?[_0xf23893[_0x7922('0x2c')]]:_0xf23893[_0x7922('0x7')]?_[_0x7922('0x8')](_['filter'](_0x11000e[_0x7922('0x5')],{'IntervalId':_0xf23893['IntervalId']}),_0x7922('0x2c')):[];if(_0xf23893[_0x7922('0xf')](_0x7922('0x2d'))){if(_0xf23893[_0x7922('0x2d')]&&_0xf23893[_0x7922('0x2d')]!=='--'){_0x5da427[_0x7922('0x13')]({'type':_0xf23893[_0x7922('0x14')],'app':_0x7922('0x21'),'appdata':_0x7922('0x2e')+_0xf23893['tag'],'context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893[_0x7922('0xc')],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893['VoiceExtensionId']});}}if(_0xf23893[_0x7922('0x14')]===_0x7922('0x17')&&_0xf23893[_0x7922('0xf')](_0x7922('0x2f'))){if(_0xf23893[_0x7922('0x2f')]){_0x5da427['push']({'type':_0xf23893[_0x7922('0x14')],'app':_0x7922('0x30'),'appdata':_0x7922('0x31')+_0xf23893[_0x7922('0x2f')]+')','context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893['exten'],'priority':_0xfe7f22['length']+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});}else{_0x5da427['push']({'type':_0xf23893[_0x7922('0x14')],'app':_0x7922('0x30'),'appdata':_0x7922('0x32'),'context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893[_0x7922('0xc')],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});}}if(_0xf23893[_0x7922('0xf')]('answer')){if(_0x97dc0e[_0x7922('0x33')](_0xf23893['app']['toLowerCase']())>=0x0&&_0xf23893[_0x7922('0x34')]!==_0x7922('0x35')){if(_0xf23893[_0x7922('0x36')]){_0x5da427[_0x7922('0x13')]({'type':_0xf23893[_0x7922('0x14')],'app':_0x7922('0x30'),'appdata':_0x7922('0x37'),'context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893[_0x7922('0xc')],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});_0x5da427[_0x7922('0x13')]({'type':_0xf23893[_0x7922('0x14')],'app':_0x7922('0x21'),'appdata':'XCALLY-MOTION-ANSWER=1','context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893['exten'],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});}else{_0x5da427[_0x7922('0x13')]({'type':_0xf23893['type'],'app':_0x7922('0x30'),'appdata':_0x7922('0x38'),'context':_0xf23893[_0x7922('0x1c')],'exten':_0xf23893[_0x7922('0xc')],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});_0x5da427[_0x7922('0x13')]({'type':_0xf23893[_0x7922('0x14')],'app':'Set','appdata':_0x7922('0x39'),'context':_0xf23893['context'],'exten':_0xf23893[_0x7922('0xc')],'priority':_0xfe7f22[_0x7922('0x2a')]+_0x11000e[_0x7922('0x10')]+_0x1b3b5e++,'VoiceExtensionId':_0xf23893[_0x7922('0x16')]});}}}for(var _0x40a328=0x0;_0x40a328<_0xfe7f22[_0x7922('0x2a')];_0x40a328+=0x1){var _0x7f9827=_0x11000e['priority']+_0xfe7f22[_0x7922('0x2a')];var _0x5a8f9d=_0x40a328===_0xfe7f22[_0x7922('0x2a')]-0x1?_0x11000e['priority']+_0x5da427[_0x7922('0x2a')]+_0x14820c[_0x7922('0x2a')]+0x2:_0x11000e['priority']+_0x40a328+0x1;_0x5da427['splice'](_0x40a328,0x0,{'type':_0xf23893['type'],'app':_0x7922('0x3a'),'appdata':_0xfe7f22[_0x40a328]+'?'+_0xf23893['context']+_0x7922('0x3b')+_0x7f9827+':'+_0xf23893[_0x7922('0x1c')]+_0x7922('0x3b')+_0x5a8f9d,'exten':_0xf23893[_0x7922('0xc')],'context':_0xf23893[_0x7922('0x1c')],'priority':_0x11000e[_0x7922('0x10')]+_0x40a328,'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0]['VoiceExtensionId']});}_0xf23893[_0x7922('0x10')]=_0x5da427[_0x7922('0x2a')]?_[_0x7922('0x3c')](_0x5da427)['priority']+0x1:_0x11000e[_0x7922('0x10')];_0x11000e['priority']=(_0x14820c['length']?_[_0x7922('0x3c')](_0x14820c)['priority']:_0xf23893[_0x7922('0x10')])+0x1;_0x11000e[_0x7922('0x11')]=_[_0x7922('0x3d')](_0x11000e[_0x7922('0x11')],_0x5da427,[_0xf23893],_0x14820c);}_0x11000e[_0x7922('0x11')][_0x7922('0x13')]({'type':_0x5019bf[_0x57b3ca][0x0]['type'],'app':_0x7922('0x3e'),'exten':_0x5019bf[_0x57b3ca][0x0]['exten'],'context':_0x5019bf[_0x57b3ca][0x0][_0x7922('0x1c')],'priority':_0x11000e[_0x7922('0x10')],'VoiceExtensionId':_0x5019bf[_0x57b3ca][0x0]['VoiceExtensionId']});_0x1ecc84[_0x7922('0x13')](_0x5019bf[_0x57b3ca][0x0][_0x7922('0x16')]);_0x4be919=_[_0x7922('0x3d')](_0x4be919,_0x11000e['extensions']);}}return _0x26532e[_0x7922('0x3f')](function(_0x5759ad){return _0x26532e[_0x7922('0x1')][_0x7922('0x6')][_0x7922('0x40')]({'where':{'VoiceExtensionId':{'$in':_0x1ecc84}},'transaction':_0x5759ad})[_0x7922('0x4')](function(_0x37ef17){return _0x26532e['models'][_0x7922('0x6')]['bulkCreate'](_[_0x7922('0x41')](_0x4be919,_0x7922('0x10')),{'transaction':_0x5759ad});});});})[_0x7922('0x42')](function(_0x1371b8){console[_0x7922('0x43')](_0x1371b8);});}exports[_0x7922('0x44')]=rewrite;