Built motion from commit 7158bc59.|2.5.42
[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 _0x1134=['then','findAll','VoiceExtension','uniq','map','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','exten','queue','playback','hasOwnProperty','priority','extensions','extension','format','CDR(type)=%s','type','inbound','push','Set','CDR(routeid)=','VoiceExtensionId','context','outbound','cutdigits','${EXTEN:','ExecIf','):Goto(','CDR(prefix)=${EXTEN:0:','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','updatedAt','*,*,*,*','interval','IntervalId','intervals','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)','app','custom','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1',',${EXTEN},','last','concat','Hangup','transaction','destroy','bulkCreate','sortBy','error','rewrite','lodash','models','Interval'];(function(_0x45afc1,_0x52a029){var _0x182539=function(_0x547e72){while(--_0x547e72){_0x45afc1['push'](_0x45afc1['shift']());}};_0x182539(++_0x52a029);}(_0x1134,0x1e0));var _0x4113=function(_0x3c65cc,_0x1104b3){_0x3c65cc=_0x3c65cc-0x0;var _0x21a62d=_0x1134[_0x3c65cc];return _0x21a62d;};'use strict';var _=require(_0x4113('0x0'));var util=require('util');function rewrite(_0x1de27f,_0x53aa53){var _0x525949=this;return _0x1de27f[_0x4113('0x1')][_0x4113('0x2')]['findAll']({'raw':!![]})[_0x4113('0x3')](function(_0x4edb52){_0x525949['intervals']=_0x4edb52;return _0x1de27f['models']['VoiceExtension'][_0x4113('0x4')]({'where':{'IntervalId':_0x53aa53['IntervalId']},'raw':!![]});})['then'](function(_0x3671c5){return _0x1de27f[_0x4113('0x1')][_0x4113('0x5')][_0x4113('0x4')]({'where':{'exten':{'$in':_[_0x4113('0x6')](_[_0x4113('0x7')](_0x3671c5,'exten'))}},'order':[{'raw':_0x4113('0x8')}],'raw':!![]});})['then'](function(_0x5c0ee0){var _0x3c7ab9=_[_0x4113('0x9')](_0x5c0ee0,{'priority':'1'});var _0x24ae61=_[_0x4113('0x9')](_0x5c0ee0,{'isApp':0x1});var _0x2aeb91=_[_0x4113('0xa')](_0x24ae61,_0x4113('0xb'));var _0x126d71=[_0x4113('0xc'),_0x4113('0xd')];var _0x217b4a=[];var _0x48847a=[];for(var _0x340422 in _0x2aeb91){if(_0x2aeb91[_0x4113('0xe')](_0x340422)){_0x525949[_0x4113('0xf')]=0x2;_0x525949[_0x4113('0x10')]=[];_0x525949[_0x4113('0x11')]=_['find'](_0x3c7ab9,{'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')]});_0x525949[_0x4113('0x10')]['push']({'type':_0x2aeb91[_0x340422][0x0]['type'],'app':'Set','appdata':util[_0x4113('0x12')](_0x4113('0x13'),_0x2aeb91[_0x340422][0x0][_0x4113('0x14')]),'context':_0x2aeb91[_0x340422][0x0]['context'],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0]['VoiceExtensionId']});if(_0x2aeb91[_0x340422][0x0]['type']===_0x4113('0x15')){_0x525949['extensions'][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0]['type'],'app':_0x4113('0x17'),'appdata':_0x4113('0x18')+_0x2aeb91[_0x340422][0x0][_0x4113('0x19')],'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});}else if(_0x2aeb91[_0x340422][0x0][_0x4113('0x14')]===_0x4113('0x1b')){if(_0x525949['extension']){_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0]['type'],'app':'Set','appdata':'CDR(destination)='+(_0x525949[_0x4113('0x11')][_0x4113('0x1c')]?_0x4113('0x1d')+_0x525949['extension'][_0x4113('0x1c')]+'}':'${EXTEN}'),'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x525949['priority']++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});}_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':_0x4113('0x18')+_0x2aeb91[_0x340422][0x0][_0x4113('0x19')],'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});var _0x5be9b2=_0x525949[_0x4113('0xf')]++;_0x525949['extensions'][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x1e'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x5be9b2+0x2)+_0x4113('0x1f')+(_0x5be9b2+0x1)+')','context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x5be9b2,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});if(_0x525949[_0x4113('0x11')]){_0x525949['extensions'][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0]['type'],'app':'Set','appdata':_0x525949[_0x4113('0x11')]['cutdigits']?_0x4113('0x20')+_0x525949[_0x4113('0x11')][_0x4113('0x1c')]+'}':'CDR(prefix)=noprefix','context':_0x2aeb91[_0x340422][0x0]['context'],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949['priority']++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});}_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':_0x4113('0x21')+_0x2aeb91[_0x340422][0x0][_0x4113('0x19')],'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});if(_0x525949[_0x4113('0x11')]&&_0x525949['extension']['hasOwnProperty'](_0x4113('0x22'))&&_0x525949[_0x4113('0x11')][_0x4113('0x22')]!==_0x4113('0x23')){_0x525949['extensions']['push']({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949['priority']++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});_0x525949['extensions'][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':_0x4113('0x24')+_0x525949['extension'][_0x4113('0x22')]||'wav','context':_0x2aeb91[_0x340422][0x0]['context'],'exten':_0x2aeb91[_0x340422][0x0]['exten'],'priority':_0x525949['priority']++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0]['VoiceExtensionId']});}}_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':'Set','appdata':_0x4113('0x25'),'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});_0x525949[_0x4113('0x10')]['push']({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':_0x4113('0x26'),'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0]['type'],'app':_0x4113('0x17'),'appdata':_0x4113('0x27'),'context':_0x2aeb91[_0x340422][0x0][_0x4113('0x1a')],'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'priority':_0x525949[_0x4113('0xf')]++,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});for(var _0x392ef2=0x0,_0x2d97ac=0x0;_0x392ef2<_0x2aeb91[_0x340422][_0x4113('0x28')];_0x392ef2+=0x1,_0x2d97ac=0x0){var _0xa656cf=_0x2aeb91[_0x340422][_0x392ef2];if(_0xa656cf[_0x4113('0x14')]){_0xa656cf[_0x4113('0x14')]=_0xa656cf[_0x4113('0x14')][_0x4113('0x29')]();}var _0x171c1e=[];var _0x2977a3=[];delete _0xa656cf['id'];delete _0xa656cf[_0x4113('0x2a')];delete _0xa656cf[_0x4113('0x2b')];var _0x513837=_0xa656cf['interval']!==_0x4113('0x2c')?[_0xa656cf[_0x4113('0x2d')]]:_0xa656cf[_0x4113('0x2e')]?_[_0x4113('0x7')](_[_0x4113('0x9')](_0x525949[_0x4113('0x2f')],{'IntervalId':_0xa656cf['IntervalId']}),_0x4113('0x2d')):[];if(_0xa656cf[_0x4113('0xe')]('tag')){if(_0xa656cf[_0x4113('0x30')]&&_0xa656cf['tag']!=='--'){_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf[_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':'CDR(tag)='+_0xa656cf[_0x4113('0x30')],'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf['exten'],'priority':_0x513837['length']+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf[_0x4113('0x19')]});}}if(_0xa656cf[_0x4113('0x14')]===_0x4113('0x1b')&&_0xa656cf[_0x4113('0xe')]('callerID')){if(_0xa656cf[_0x4113('0x31')]){_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf[_0x4113('0x14')],'app':_0x4113('0x1e'),'appdata':_0x4113('0x32')+_0xa656cf[_0x4113('0x31')]+')','context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf[_0x4113('0xb')],'priority':_0x513837[_0x4113('0x28')]+_0x525949['priority']+_0x2d97ac++,'VoiceExtensionId':_0xa656cf['VoiceExtensionId']});}else{_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf['type'],'app':_0x4113('0x1e'),'appdata':_0x4113('0x33'),'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf['exten'],'priority':_0x513837[_0x4113('0x28')]+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf[_0x4113('0x19')]});}}if(_0xa656cf['hasOwnProperty']('answer')){if(_0x126d71['indexOf'](_0xa656cf[_0x4113('0x34')]['toLowerCase']())>=0x0&&_0xa656cf['appType']!==_0x4113('0x35')){if(_0xa656cf[_0x4113('0x36')]){_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf['type'],'app':'ExecIf','appdata':_0x4113('0x37'),'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf[_0x4113('0xb')],'priority':_0x513837[_0x4113('0x28')]+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf[_0x4113('0x19')]});_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf[_0x4113('0x14')],'app':_0x4113('0x17'),'appdata':_0x4113('0x38'),'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf[_0x4113('0xb')],'priority':_0x513837[_0x4113('0x28')]+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf[_0x4113('0x19')]});}else{_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf[_0x4113('0x14')],'app':_0x4113('0x1e'),'appdata':_0x4113('0x39'),'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf[_0x4113('0xb')],'priority':_0x513837[_0x4113('0x28')]+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf['VoiceExtensionId']});_0x171c1e[_0x4113('0x16')]({'type':_0xa656cf['type'],'app':_0x4113('0x17'),'appdata':_0x4113('0x3a'),'context':_0xa656cf[_0x4113('0x1a')],'exten':_0xa656cf[_0x4113('0xb')],'priority':_0x513837[_0x4113('0x28')]+_0x525949[_0x4113('0xf')]+_0x2d97ac++,'VoiceExtensionId':_0xa656cf[_0x4113('0x19')]});}}}for(var _0x521bbd=0x0;_0x521bbd<_0x513837['length'];_0x521bbd+=0x1){var _0x4409e7=_0x525949[_0x4113('0xf')]+_0x513837['length'];var _0x8e8207=_0x521bbd===_0x513837['length']-0x1?_0x525949[_0x4113('0xf')]+_0x171c1e[_0x4113('0x28')]+_0x2977a3[_0x4113('0x28')]+0x2:_0x525949[_0x4113('0xf')]+_0x521bbd+0x1;_0x171c1e['splice'](_0x521bbd,0x0,{'type':_0xa656cf[_0x4113('0x14')],'app':'GotoIfTime','appdata':_0x513837[_0x521bbd]+'?'+_0xa656cf[_0x4113('0x1a')]+',${EXTEN},'+_0x4409e7+':'+_0xa656cf[_0x4113('0x1a')]+_0x4113('0x3b')+_0x8e8207,'exten':_0xa656cf[_0x4113('0xb')],'context':_0xa656cf[_0x4113('0x1a')],'priority':_0x525949[_0x4113('0xf')]+_0x521bbd,'VoiceExtensionId':_0x2aeb91[_0x340422][0x0][_0x4113('0x19')]});}_0xa656cf[_0x4113('0xf')]=_0x171c1e[_0x4113('0x28')]?_[_0x4113('0x3c')](_0x171c1e)[_0x4113('0xf')]+0x1:_0x525949[_0x4113('0xf')];_0x525949[_0x4113('0xf')]=(_0x2977a3[_0x4113('0x28')]?_[_0x4113('0x3c')](_0x2977a3)[_0x4113('0xf')]:_0xa656cf['priority'])+0x1;_0x525949['extensions']=_[_0x4113('0x3d')](_0x525949[_0x4113('0x10')],_0x171c1e,[_0xa656cf],_0x2977a3);}_0x525949[_0x4113('0x10')][_0x4113('0x16')]({'type':_0x2aeb91[_0x340422][0x0][_0x4113('0x14')],'app':_0x4113('0x3e'),'exten':_0x2aeb91[_0x340422][0x0][_0x4113('0xb')],'context':_0x2aeb91[_0x340422][0x0]['context'],'priority':_0x525949['priority'],'VoiceExtensionId':_0x2aeb91[_0x340422][0x0]['VoiceExtensionId']});_0x217b4a['push'](_0x2aeb91[_0x340422][0x0]['VoiceExtensionId']);_0x48847a=_[_0x4113('0x3d')](_0x48847a,_0x525949[_0x4113('0x10')]);}}return _0x1de27f[_0x4113('0x3f')](function(_0x2996dd){return _0x1de27f['models'][_0x4113('0x5')][_0x4113('0x40')]({'where':{'VoiceExtensionId':{'$in':_0x217b4a}},'transaction':_0x2996dd})[_0x4113('0x3')](function(_0x9cb899){return _0x1de27f['models'][_0x4113('0x5')][_0x4113('0x41')](_[_0x4113('0x42')](_0x48847a,_0x4113('0xf')),{'transaction':_0x2996dd});});});})['catch'](function(_0x24a67b){console[_0x4113('0x43')](_0x24a67b);});}exports[_0x4113('0x44')]=rewrite;