3df37e4161cbd62e7c2b366c1ce8aefff729af1f
[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 _0xf52c=['):Goto(','CDR(prefix)=${EXTEN:0:','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','toLowerCase','createdAt','updatedAt','*,*,*,*','interval','tag','CDR(tag)=','length','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)=','callerID','answer','indexOf','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','last','Hangup','concat','transaction','destroy','then','bulkCreate','sortBy','catch','rewrite','lodash','util','models','Interval','findAll','intervals','VoiceExtension','IntervalId','uniq','map','exten','filter','groupBy','queue','playback','priority','extensions','extension','find','push','format','CDR(type)=%s','type','context','inbound','Set','CDR(routeid)=','VoiceExtensionId','outbound','cutdigits','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('];(function(_0x433a86,_0x175b5c){var _0x23000c=function(_0x4b1fa0){while(--_0x4b1fa0){_0x433a86['push'](_0x433a86['shift']());}};_0x23000c(++_0x175b5c);}(_0xf52c,0x76));var _0xcf52=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf52c[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xcf52('0x0'));var util=require(_0xcf52('0x1'));function rewrite(_0x96083f,_0x35a958){var _0x3bfda9=this;return _0x96083f[_0xcf52('0x2')][_0xcf52('0x3')][_0xcf52('0x4')]({'raw':!![]})['then'](function(_0x306d10){_0x3bfda9[_0xcf52('0x5')]=_0x306d10;return _0x96083f[_0xcf52('0x2')][_0xcf52('0x6')]['findAll']({'where':{'IntervalId':_0x35a958[_0xcf52('0x7')]},'raw':!![]});})['then'](function(_0x1fee18){return _0x96083f[_0xcf52('0x2')][_0xcf52('0x6')][_0xcf52('0x4')]({'where':{'exten':{'$in':_[_0xcf52('0x8')](_[_0xcf52('0x9')](_0x1fee18,_0xcf52('0xa')))}},'order':[{'raw':'CAST(priority\x20AS\x20UNSIGNED)'}],'raw':!![]});})['then'](function(_0xf164d7){var _0x442694=_['filter'](_0xf164d7,{'priority':'1'});var _0x35fbe6=_[_0xcf52('0xb')](_0xf164d7,{'isApp':0x1});var _0x1c7292=_[_0xcf52('0xc')](_0x35fbe6,_0xcf52('0xa'));var _0x20b395=[_0xcf52('0xd'),_0xcf52('0xe')];var _0xce1763=[];var _0x3340fa=[];for(var _0x50749d in _0x1c7292){if(_0x1c7292['hasOwnProperty'](_0x50749d)){_0x3bfda9[_0xcf52('0xf')]=0x2;_0x3bfda9[_0xcf52('0x10')]=[];_0x3bfda9[_0xcf52('0x11')]=_[_0xcf52('0x12')](_0x442694,{'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')]});_0x3bfda9['extensions'][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0]['type'],'app':'Set','appdata':util[_0xcf52('0x14')](_0xcf52('0x15'),_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')]),'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0]['exten'],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0]['VoiceExtensionId']});if(_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')]===_0xcf52('0x18')){_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x1a')+_0x1c7292[_0x50749d][0x0]['VoiceExtensionId'],'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9['priority']++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});}else if(_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')]===_0xcf52('0x1c')){if(_0x3bfda9['extension']){_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':'CDR(destination)='+(_0x3bfda9[_0xcf52('0x11')][_0xcf52('0x1d')]?_0xcf52('0x1e')+_0x3bfda9[_0xcf52('0x11')][_0xcf52('0x1d')]+'}':_0xcf52('0x1f')),'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});}_0x3bfda9['extensions']['push']({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x1a')+_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')],'context':_0x1c7292[_0x50749d][0x0]['context'],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0]['VoiceExtensionId']});var _0x5b852a=_0x3bfda9[_0xcf52('0xf')]++;_0x3bfda9['extensions'][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0]['type'],'app':_0xcf52('0x20'),'appdata':_0xcf52('0x21')+(_0x5b852a+0x2)+_0xcf52('0x22')+(_0x5b852a+0x1)+')','context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x5b852a,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});if(_0x3bfda9['extension']){_0x3bfda9['extensions'][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0x3bfda9['extension'][_0xcf52('0x1d')]?_0xcf52('0x23')+_0x3bfda9[_0xcf52('0x11')][_0xcf52('0x1d')]+'}':'CDR(prefix)=noprefix','context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});}_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x24')+_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')],'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9['priority']++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});if(_0x3bfda9[_0xcf52('0x11')]&&_0x3bfda9[_0xcf52('0x11')][_0xcf52('0x25')](_0xcf52('0x26'))&&_0x3bfda9[_0xcf52('0x11')]['recordingFormat']!==_0xcf52('0x27')){_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':'Set','appdata':_0xcf52('0x28'),'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});_0x3bfda9[_0xcf52('0x10')]['push']({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x29')+_0x3bfda9[_0xcf52('0x11')][_0xcf52('0x26')]||_0xcf52('0x2a'),'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});}}_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0]['type'],'app':'Set','appdata':_0xcf52('0x2b'),'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'exten':_0x1c7292[_0x50749d][0x0]['exten'],'priority':_0x3bfda9[_0xcf52('0xf')]++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':'Set','appdata':_0xcf52('0x2c'),'context':_0x1c7292[_0x50749d][0x0]['context'],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9['priority']++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0][_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x2d'),'context':_0x1c7292[_0x50749d][0x0]['context'],'exten':_0x1c7292[_0x50749d][0x0][_0xcf52('0xa')],'priority':_0x3bfda9['priority']++,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});for(var _0x1018c3=0x0,_0x3405ef=0x0;_0x1018c3<_0x1c7292[_0x50749d]['length'];_0x1018c3+=0x1,_0x3405ef=0x0){var _0x262c51=_0x1c7292[_0x50749d][_0x1018c3];if(_0x262c51[_0xcf52('0x16')]){_0x262c51['type']=_0x262c51[_0xcf52('0x16')][_0xcf52('0x2e')]();}var _0x25ee5c=[];var _0x2898dc=[];delete _0x262c51['id'];delete _0x262c51[_0xcf52('0x2f')];delete _0x262c51[_0xcf52('0x30')];var _0x121406=_0x262c51['interval']!==_0xcf52('0x31')?[_0x262c51[_0xcf52('0x32')]]:_0x262c51[_0xcf52('0x7')]?_[_0xcf52('0x9')](_[_0xcf52('0xb')](_0x3bfda9[_0xcf52('0x5')],{'IntervalId':_0x262c51[_0xcf52('0x7')]}),_0xcf52('0x32')):[];if(_0x262c51[_0xcf52('0x25')](_0xcf52('0x33'))){if(_0x262c51['tag']&&_0x262c51['tag']!=='--'){_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51[_0xcf52('0x16')],'app':_0xcf52('0x19'),'appdata':_0xcf52('0x34')+_0x262c51[_0xcf52('0x33')],'context':_0x262c51['context'],'exten':_0x262c51[_0xcf52('0xa')],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51[_0xcf52('0x1b')]});}}if(_0x262c51['type']===_0xcf52('0x1c')&&_0x262c51['hasOwnProperty']('callerID')){if(_0x262c51['callerID']){_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51[_0xcf52('0x16')],'app':'ExecIf','appdata':_0xcf52('0x36')+_0x262c51[_0xcf52('0x37')]+')','context':_0x262c51[_0xcf52('0x17')],'exten':_0x262c51[_0xcf52('0xa')],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51[_0xcf52('0x1b')]});}else{_0x25ee5c['push']({'type':_0x262c51[_0xcf52('0x16')],'app':_0xcf52('0x20'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','context':_0x262c51[_0xcf52('0x17')],'exten':_0x262c51[_0xcf52('0xa')],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51[_0xcf52('0x1b')]});}}if(_0x262c51[_0xcf52('0x25')](_0xcf52('0x38'))){if(_0x20b395[_0xcf52('0x39')](_0x262c51['app'][_0xcf52('0x2e')]())>=0x0&&_0x262c51[_0xcf52('0x3a')]!==_0xcf52('0x3b')){if(_0x262c51[_0xcf52('0x38')]){_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51['type'],'app':_0xcf52('0x20'),'appdata':_0xcf52('0x3c'),'context':_0x262c51['context'],'exten':_0x262c51['exten'],'priority':_0x121406['length']+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51['VoiceExtensionId']});_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51['type'],'app':'Set','appdata':_0xcf52('0x3d'),'context':_0x262c51[_0xcf52('0x17')],'exten':_0x262c51[_0xcf52('0xa')],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51['VoiceExtensionId']});}else{_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51[_0xcf52('0x16')],'app':_0xcf52('0x20'),'appdata':_0xcf52('0x3e'),'context':_0x262c51['context'],'exten':_0x262c51['exten'],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51[_0xcf52('0x1b')]});_0x25ee5c[_0xcf52('0x13')]({'type':_0x262c51['type'],'app':'Set','appdata':_0xcf52('0x3f'),'context':_0x262c51[_0xcf52('0x17')],'exten':_0x262c51[_0xcf52('0xa')],'priority':_0x121406[_0xcf52('0x35')]+_0x3bfda9[_0xcf52('0xf')]+_0x3405ef++,'VoiceExtensionId':_0x262c51[_0xcf52('0x1b')]});}}}for(var _0x4b9183=0x0;_0x4b9183<_0x121406[_0xcf52('0x35')];_0x4b9183+=0x1){var _0x2ca6db=_0x3bfda9['priority']+_0x121406[_0xcf52('0x35')];var _0x1dbd6f=_0x4b9183===_0x121406[_0xcf52('0x35')]-0x1?_0x3bfda9[_0xcf52('0xf')]+_0x25ee5c[_0xcf52('0x35')]+_0x2898dc[_0xcf52('0x35')]+0x2:_0x3bfda9[_0xcf52('0xf')]+_0x4b9183+0x1;_0x25ee5c[_0xcf52('0x40')](_0x4b9183,0x0,{'type':_0x262c51[_0xcf52('0x16')],'app':'GotoIfTime','appdata':_0x121406[_0x4b9183]+'?'+_0x262c51[_0xcf52('0x17')]+_0xcf52('0x41')+_0x2ca6db+':'+_0x262c51[_0xcf52('0x17')]+_0xcf52('0x41')+_0x1dbd6f,'exten':_0x262c51[_0xcf52('0xa')],'context':_0x262c51[_0xcf52('0x17')],'priority':_0x3bfda9['priority']+_0x4b9183,'VoiceExtensionId':_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]});}_0x262c51['priority']=_0x25ee5c[_0xcf52('0x35')]?_[_0xcf52('0x42')](_0x25ee5c)[_0xcf52('0xf')]+0x1:_0x3bfda9[_0xcf52('0xf')];_0x3bfda9[_0xcf52('0xf')]=(_0x2898dc[_0xcf52('0x35')]?_[_0xcf52('0x42')](_0x2898dc)['priority']:_0x262c51[_0xcf52('0xf')])+0x1;_0x3bfda9['extensions']=_['concat'](_0x3bfda9[_0xcf52('0x10')],_0x25ee5c,[_0x262c51],_0x2898dc);}_0x3bfda9[_0xcf52('0x10')][_0xcf52('0x13')]({'type':_0x1c7292[_0x50749d][0x0]['type'],'app':_0xcf52('0x43'),'exten':_0x1c7292[_0x50749d][0x0]['exten'],'context':_0x1c7292[_0x50749d][0x0][_0xcf52('0x17')],'priority':_0x3bfda9[_0xcf52('0xf')],'VoiceExtensionId':_0x1c7292[_0x50749d][0x0]['VoiceExtensionId']});_0xce1763[_0xcf52('0x13')](_0x1c7292[_0x50749d][0x0][_0xcf52('0x1b')]);_0x3340fa=_[_0xcf52('0x44')](_0x3340fa,_0x3bfda9[_0xcf52('0x10')]);}}return _0x96083f[_0xcf52('0x45')](function(_0x5a04a1){return _0x96083f[_0xcf52('0x2')][_0xcf52('0x6')][_0xcf52('0x46')]({'where':{'VoiceExtensionId':{'$in':_0xce1763}},'transaction':_0x5a04a1})[_0xcf52('0x47')](function(_0x6f799e){return _0x96083f[_0xcf52('0x2')][_0xcf52('0x6')][_0xcf52('0x48')](_[_0xcf52('0x49')](_0x3340fa,_0xcf52('0xf')),{'transaction':_0x5a04a1});});});})[_0xcf52('0x4a')](function(_0x29efde){console['error'](_0x29efde);});}exports[_0xcf52('0x4b')]=rewrite;