Built motion from commit 5293bb2a.|2.6.30
[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 _0x7bb0=['):Goto(','CDR(prefix)=${EXTEN:0:','outboundrouteid=','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','updatedAt','interval','*,*,*,*','IntervalId','map','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','appType','custom','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1',',${EXTEN},','last','concat','Hangup','destroy','bulkCreate','catch','error','lodash','util','models','findAll','then','intervals','VoiceExtension','uniq','CAST(priority\x20AS\x20UNSIGNED)','filter','exten','queue','hasOwnProperty','find','extensions','Set','format','CDR(type)=%s','context','priority','VoiceExtensionId','inbound','push','type','CDR(routeid)=','outbound','extension','cutdigits','${EXTEN}','ExecIf'];(function(_0x2fa2b9,_0x289e22){var _0x4d251a=function(_0x519beb){while(--_0x519beb){_0x2fa2b9['push'](_0x2fa2b9['shift']());}};_0x4d251a(++_0x289e22);}(_0x7bb0,0x6e));var _0x07bb=function(_0x445190,_0x49de87){_0x445190=_0x445190-0x0;var _0x23a0c1=_0x7bb0[_0x445190];return _0x23a0c1;};'use strict';var _=require(_0x07bb('0x0'));var util=require(_0x07bb('0x1'));function rewrite(_0x5a21dd,_0x55cc43){var _0x492660=this;return _0x5a21dd[_0x07bb('0x2')]['Interval'][_0x07bb('0x3')]({'raw':!![]})[_0x07bb('0x4')](function(_0x155890){_0x492660[_0x07bb('0x5')]=_0x155890;return _0x5a21dd[_0x07bb('0x2')][_0x07bb('0x6')][_0x07bb('0x3')]({'where':{'IntervalId':_0x55cc43['IntervalId']},'raw':!![]});})['then'](function(_0x36d26f){return _0x5a21dd[_0x07bb('0x2')][_0x07bb('0x6')]['findAll']({'where':{'exten':{'$in':_[_0x07bb('0x7')](_['map'](_0x36d26f,'exten'))}},'order':[{'raw':_0x07bb('0x8')}],'raw':!![]});})[_0x07bb('0x4')](function(_0xad54c3){var _0x1f35eb=_[_0x07bb('0x9')](_0xad54c3,{'priority':'1'});var _0x3ed987=_['filter'](_0xad54c3,{'isApp':0x1});var _0x2d3328=_['groupBy'](_0x3ed987,_0x07bb('0xa'));var _0x3abd7e=[_0x07bb('0xb'),'playback'];var _0x6a3621=[];var _0x446513=[];for(var _0x31b7ac in _0x2d3328){if(_0x2d3328[_0x07bb('0xc')](_0x31b7ac)){_0x492660['priority']=0x2;_0x492660['extensions']=[];_0x492660['extension']=_[_0x07bb('0xd')](_0x1f35eb,{'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')]});_0x492660[_0x07bb('0xe')]['push']({'type':_0x2d3328[_0x31b7ac][0x0]['type'],'app':_0x07bb('0xf'),'appdata':util[_0x07bb('0x10')](_0x07bb('0x11'),_0x2d3328[_0x31b7ac][0x0]['type']),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});if(_0x2d3328[_0x31b7ac][0x0]['type']===_0x07bb('0x15')){_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':'Set','appdata':_0x07bb('0x18')+_0x2d3328[_0x31b7ac][0x0]['VoiceExtensionId'],'context':_0x2d3328[_0x31b7ac][0x0]['context'],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});}else if(_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')]===_0x07bb('0x19')){if(_0x492660['extension']){_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':'CDR(destination)='+(_0x492660[_0x07bb('0x1a')][_0x07bb('0x1b')]?'${EXTEN:'+_0x492660['extension'][_0x07bb('0x1b')]+'}':_0x07bb('0x1c')),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});}_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x18')+_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')],'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0]['exten'],'priority':_0x492660['priority']++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});var _0x9e4f11=_0x492660[_0x07bb('0x13')]++;_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0x1d'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x9e4f11+0x2)+_0x07bb('0x1e')+(_0x9e4f11+0x1)+')','context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x9e4f11,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});if(_0x492660[_0x07bb('0x1a')]){_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0]['type'],'app':_0x07bb('0xf'),'appdata':_0x492660[_0x07bb('0x1a')][_0x07bb('0x1b')]?_0x07bb('0x1f')+_0x492660[_0x07bb('0x1a')][_0x07bb('0x1b')]+'}':'CDR(prefix)=noprefix','context':_0x2d3328[_0x31b7ac][0x0]['context'],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0]['VoiceExtensionId']});}_0x492660[_0x07bb('0xe')]['push']({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x20')+_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')],'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});if(_0x492660['extension']&&_0x492660['extension'][_0x07bb('0xc')](_0x07bb('0x21'))&&_0x492660[_0x07bb('0x1a')][_0x07bb('0x21')]!==_0x07bb('0x22')){_0x492660['extensions'][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x23'),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660['priority']++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});_0x492660['extensions'][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x24')+_0x492660[_0x07bb('0x1a')]['recordingFormat']||_0x07bb('0x25'),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});}}_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0]['type'],'app':_0x07bb('0xf'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0]['VoiceExtensionId']});_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x26'),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});_0x492660['extensions'][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0]['type'],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x27'),'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'exten':_0x2d3328[_0x31b7ac][0x0]['exten'],'priority':_0x492660[_0x07bb('0x13')]++,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});for(var _0x3d659e=0x0,_0xbb5653=0x0;_0x3d659e<_0x2d3328[_0x31b7ac][_0x07bb('0x28')];_0x3d659e+=0x1,_0xbb5653=0x0){var _0x34ea50=_0x2d3328[_0x31b7ac][_0x3d659e];if(_0x34ea50[_0x07bb('0x17')]){_0x34ea50[_0x07bb('0x17')]=_0x34ea50['type'][_0x07bb('0x29')]();}var _0x1fbfa3=[];var _0x217c06=[];delete _0x34ea50['id'];delete _0x34ea50[_0x07bb('0x2a')];delete _0x34ea50[_0x07bb('0x2b')];var _0x3ff988=_0x34ea50[_0x07bb('0x2c')]!==_0x07bb('0x2d')?[_0x34ea50[_0x07bb('0x2c')]]:_0x34ea50[_0x07bb('0x2e')]?_[_0x07bb('0x2f')](_[_0x07bb('0x9')](_0x492660[_0x07bb('0x5')],{'IntervalId':_0x34ea50[_0x07bb('0x2e')]}),_0x07bb('0x2c')):[];if(_0x34ea50[_0x07bb('0xc')](_0x07bb('0x30'))){if(_0x34ea50['tag']&&_0x34ea50[_0x07bb('0x30')]!=='--'){_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':_0x07bb('0xf'),'appdata':_0x07bb('0x31')+_0x34ea50[_0x07bb('0x30')],'context':_0x34ea50['context'],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660[_0x07bb('0x13')]+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});}}if(_0x34ea50[_0x07bb('0x17')]===_0x07bb('0x19')&&_0x34ea50[_0x07bb('0xc')]('callerID')){if(_0x34ea50[_0x07bb('0x32')]){_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':_0x07bb('0x1d'),'appdata':_0x07bb('0x33')+_0x34ea50['callerID']+')','context':_0x34ea50[_0x07bb('0x12')],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660[_0x07bb('0x13')]+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});}else{_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':_0x07bb('0x1d'),'appdata':_0x07bb('0x34'),'context':_0x34ea50[_0x07bb('0x12')],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660[_0x07bb('0x13')]+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});}}if(_0x34ea50[_0x07bb('0xc')]('answer')){if(_0x3abd7e[_0x07bb('0x35')](_0x34ea50[_0x07bb('0x36')]['toLowerCase']())>=0x0&&_0x34ea50[_0x07bb('0x37')]!==_0x07bb('0x38')){if(_0x34ea50[_0x07bb('0x39')]){_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':_0x07bb('0x1d'),'appdata':_0x07bb('0x3a'),'context':_0x34ea50['context'],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660['priority']+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':'Set','appdata':_0x07bb('0x3b'),'context':_0x34ea50[_0x07bb('0x12')],'exten':_0x34ea50['exten'],'priority':_0x3ff988['length']+_0x492660[_0x07bb('0x13')]+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});}else{_0x1fbfa3[_0x07bb('0x16')]({'type':_0x34ea50[_0x07bb('0x17')],'app':_0x07bb('0x1d'),'appdata':_0x07bb('0x3c'),'context':_0x34ea50[_0x07bb('0x12')],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660['priority']+_0xbb5653++,'VoiceExtensionId':_0x34ea50[_0x07bb('0x14')]});_0x1fbfa3['push']({'type':_0x34ea50[_0x07bb('0x17')],'app':'Set','appdata':_0x07bb('0x3d'),'context':_0x34ea50[_0x07bb('0x12')],'exten':_0x34ea50[_0x07bb('0xa')],'priority':_0x3ff988[_0x07bb('0x28')]+_0x492660[_0x07bb('0x13')]+_0xbb5653++,'VoiceExtensionId':_0x34ea50['VoiceExtensionId']});}}}for(var _0x3ca7c1=0x0;_0x3ca7c1<_0x3ff988['length'];_0x3ca7c1+=0x1){var _0x29a3cc=_0x492660[_0x07bb('0x13')]+_0x3ff988[_0x07bb('0x28')];var _0x3073ef=_0x3ca7c1===_0x3ff988[_0x07bb('0x28')]-0x1?_0x492660[_0x07bb('0x13')]+_0x1fbfa3[_0x07bb('0x28')]+_0x217c06[_0x07bb('0x28')]+0x2:_0x492660[_0x07bb('0x13')]+_0x3ca7c1+0x1;_0x1fbfa3['splice'](_0x3ca7c1,0x0,{'type':_0x34ea50[_0x07bb('0x17')],'app':'GotoIfTime','appdata':_0x3ff988[_0x3ca7c1]+'?'+_0x34ea50[_0x07bb('0x12')]+_0x07bb('0x3e')+_0x29a3cc+':'+_0x34ea50['context']+_0x07bb('0x3e')+_0x3073ef,'exten':_0x34ea50[_0x07bb('0xa')],'context':_0x34ea50[_0x07bb('0x12')],'priority':_0x492660[_0x07bb('0x13')]+_0x3ca7c1,'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});}_0x34ea50['priority']=_0x1fbfa3[_0x07bb('0x28')]?_[_0x07bb('0x3f')](_0x1fbfa3)[_0x07bb('0x13')]+0x1:_0x492660[_0x07bb('0x13')];_0x492660[_0x07bb('0x13')]=(_0x217c06[_0x07bb('0x28')]?_['last'](_0x217c06)['priority']:_0x34ea50[_0x07bb('0x13')])+0x1;_0x492660[_0x07bb('0xe')]=_[_0x07bb('0x40')](_0x492660[_0x07bb('0xe')],_0x1fbfa3,[_0x34ea50],_0x217c06);}_0x492660[_0x07bb('0xe')][_0x07bb('0x16')]({'type':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x17')],'app':_0x07bb('0x41'),'exten':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0xa')],'context':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x12')],'priority':_0x492660[_0x07bb('0x13')],'VoiceExtensionId':_0x2d3328[_0x31b7ac][0x0][_0x07bb('0x14')]});_0x6a3621[_0x07bb('0x16')](_0x2d3328[_0x31b7ac][0x0]['VoiceExtensionId']);_0x446513=_[_0x07bb('0x40')](_0x446513,_0x492660[_0x07bb('0xe')]);}}return _0x5a21dd['transaction'](function(_0x3c1da9){return _0x5a21dd[_0x07bb('0x2')][_0x07bb('0x6')][_0x07bb('0x42')]({'where':{'VoiceExtensionId':{'$in':_0x6a3621}},'transaction':_0x3c1da9})[_0x07bb('0x4')](function(_0x22b3aa){return _0x5a21dd[_0x07bb('0x2')][_0x07bb('0x6')][_0x07bb('0x43')](_['sortBy'](_0x446513,_0x07bb('0x13')),{'transaction':_0x3c1da9});});});})[_0x07bb('0x44')](function(_0x52b029){console[_0x07bb('0x45')](_0x52b029);});}exports['rewrite']=rewrite;