dd09abf51423a850c656965ce3f152897aa9cfac
[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 _0x9a8b=['XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','destroy','bulkCreate','sortBy','catch','error','rewrite','lodash','util','models','Interval','findAll','then','intervals','VoiceExtension','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','queue','playback','hasOwnProperty','priority','extensions','extension','find','push','type','Set','CDR(type)=%s','context','VoiceExtensionId','inbound','outbound','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','CDR(routeid)=','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','recordingFormat','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','interval','*,*,*,*','IntervalId','tag','callerID','ExecIf','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','answer','indexOf','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer'];(function(_0x856e86,_0x3f9c40){var _0x586a43=function(_0x433704){while(--_0x433704){_0x856e86['push'](_0x856e86['shift']());}};_0x586a43(++_0x3f9c40);}(_0x9a8b,0xf1));var _0xb9a8=function(_0x671a5a,_0x18dd89){_0x671a5a=_0x671a5a-0x0;var _0x2bf009=_0x9a8b[_0x671a5a];return _0x2bf009;};'use strict';var _=require(_0xb9a8('0x0'));var util=require(_0xb9a8('0x1'));function rewrite(_0x36225a,_0x407918){var _0x1c6ea3=this;return _0x36225a[_0xb9a8('0x2')][_0xb9a8('0x3')][_0xb9a8('0x4')]({'raw':!![]})[_0xb9a8('0x5')](function(_0x599bfb){_0x1c6ea3[_0xb9a8('0x6')]=_0x599bfb;return _0x36225a[_0xb9a8('0x2')][_0xb9a8('0x7')]['findAll']({'where':{'IntervalId':_0x407918['IntervalId']},'raw':!![]});})[_0xb9a8('0x5')](function(_0x1ab937){return _0x36225a['models'][_0xb9a8('0x7')][_0xb9a8('0x4')]({'where':{'exten':{'$in':_[_0xb9a8('0x8')](_[_0xb9a8('0x9')](_0x1ab937,_0xb9a8('0xa')))}},'order':[{'raw':_0xb9a8('0xb')}],'raw':!![]});})[_0xb9a8('0x5')](function(_0x30038e){var _0xef2d34=_[_0xb9a8('0xc')](_0x30038e,{'priority':'1'});var _0x30c004=_[_0xb9a8('0xc')](_0x30038e,{'isApp':0x1});var _0x2cbe4b=_[_0xb9a8('0xd')](_0x30c004,_0xb9a8('0xa'));var _0x2ea211=[_0xb9a8('0xe'),_0xb9a8('0xf')];var _0x2a690a=[];var _0x327bd7=[];for(var _0x8867ed in _0x2cbe4b){if(_0x2cbe4b[_0xb9a8('0x10')](_0x8867ed)){_0x1c6ea3[_0xb9a8('0x11')]=0x2;_0x1c6ea3[_0xb9a8('0x12')]=[];_0x1c6ea3[_0xb9a8('0x13')]=_[_0xb9a8('0x14')](_0xef2d34,{'exten':_0x2cbe4b[_0x8867ed][0x0]['exten']});_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':util['format'](_0xb9a8('0x18'),_0x2cbe4b[_0x8867ed][0x0]['type']),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0]['exten'],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});if(_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')]===_0xb9a8('0x1b')){_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':'CDR(routeid)='+_0x2cbe4b[_0x8867ed][0x0]['VoiceExtensionId'],'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});}else if(_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')]===_0xb9a8('0x1c')){if(_0x1c6ea3['extension']){_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x1d')+(_0x1c6ea3[_0xb9a8('0x13')][_0xb9a8('0x1e')]?_0xb9a8('0x1f')+_0x1c6ea3[_0xb9a8('0x13')][_0xb9a8('0x1e')]+'}':_0xb9a8('0x20')),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0]['exten'],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});}_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x21')+_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')],'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3['priority']++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});var _0x487a64=_0x1c6ea3['priority']++;_0x1c6ea3['extensions']['push']({'type':_0x2cbe4b[_0x8867ed][0x0]['type'],'app':'ExecIf','appdata':_0xb9a8('0x22')+(_0x487a64+0x2)+_0xb9a8('0x23')+(_0x487a64+0x1)+')','context':_0x2cbe4b[_0x8867ed][0x0]['context'],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x487a64,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});if(_0x1c6ea3[_0xb9a8('0x13')]){_0x1c6ea3['extensions'][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0x1c6ea3[_0xb9a8('0x13')]['cutdigits']?_0xb9a8('0x24')+_0x1c6ea3[_0xb9a8('0x13')]['cutdigits']+'}':_0xb9a8('0x25'),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0]['VoiceExtensionId']});}_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x26')+_0x2cbe4b[_0x8867ed][0x0]['VoiceExtensionId'],'context':_0x2cbe4b[_0x8867ed][0x0]['context'],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3['priority']++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});if(_0x1c6ea3['extension']&&_0x1c6ea3[_0xb9a8('0x13')][_0xb9a8('0x10')](_0xb9a8('0x27'))&&_0x1c6ea3[_0xb9a8('0x13')][_0xb9a8('0x27')]!=='none'){_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0]['type'],'app':_0xb9a8('0x17'),'appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0]['exten'],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});_0x1c6ea3['extensions']['push']({'type':_0x2cbe4b[_0x8867ed][0x0]['type'],'app':'Set','appdata':_0xb9a8('0x28')+_0x1c6ea3['extension'][_0xb9a8('0x27')]||'wav','context':_0x2cbe4b[_0x8867ed][0x0]['context'],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});}}_0x1c6ea3[_0xb9a8('0x12')]['push']({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x29'),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});_0x1c6ea3[_0xb9a8('0x12')]['push']({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x2a'),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3[_0xb9a8('0x11')]++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});_0x1c6ea3['extensions'][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x2b'),'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'priority':_0x1c6ea3['priority']++,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});for(var _0x4f763e=0x0,_0x56270a=0x0;_0x4f763e<_0x2cbe4b[_0x8867ed][_0xb9a8('0x2c')];_0x4f763e+=0x1,_0x56270a=0x0){var _0x5b29cf=_0x2cbe4b[_0x8867ed][_0x4f763e];if(_0x5b29cf[_0xb9a8('0x16')]){_0x5b29cf[_0xb9a8('0x16')]=_0x5b29cf[_0xb9a8('0x16')][_0xb9a8('0x2d')]();}var _0x26f5af=[];var _0x519168=[];delete _0x5b29cf['id'];delete _0x5b29cf[_0xb9a8('0x2e')];delete _0x5b29cf['updatedAt'];var _0x567fb4=_0x5b29cf[_0xb9a8('0x2f')]!==_0xb9a8('0x30')?[_0x5b29cf[_0xb9a8('0x2f')]]:_0x5b29cf[_0xb9a8('0x31')]?_[_0xb9a8('0x9')](_['filter'](_0x1c6ea3[_0xb9a8('0x6')],{'IntervalId':_0x5b29cf[_0xb9a8('0x31')]}),_0xb9a8('0x2f')):[];if(_0x5b29cf[_0xb9a8('0x10')]('tag')){if(_0x5b29cf[_0xb9a8('0x32')]&&_0x5b29cf['tag']!=='--'){_0x26f5af[_0xb9a8('0x15')]({'type':_0x5b29cf[_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':'CDR(tag)='+_0x5b29cf[_0xb9a8('0x32')],'context':_0x5b29cf[_0xb9a8('0x19')],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3[_0xb9a8('0x11')]+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});}}if(_0x5b29cf['type']==='outbound'&&_0x5b29cf['hasOwnProperty'](_0xb9a8('0x33'))){if(_0x5b29cf[_0xb9a8('0x33')]){_0x26f5af['push']({'type':_0x5b29cf[_0xb9a8('0x16')],'app':_0xb9a8('0x34'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)='+_0x5b29cf[_0xb9a8('0x33')]+')','context':_0x5b29cf[_0xb9a8('0x19')],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3[_0xb9a8('0x11')]+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});}else{_0x26f5af['push']({'type':_0x5b29cf[_0xb9a8('0x16')],'app':'ExecIf','appdata':_0xb9a8('0x35'),'context':_0x5b29cf['context'],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3[_0xb9a8('0x11')]+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});}}if(_0x5b29cf[_0xb9a8('0x10')](_0xb9a8('0x36'))){if(_0x2ea211[_0xb9a8('0x37')](_0x5b29cf['app']['toLowerCase']())>=0x0&&_0x5b29cf[_0xb9a8('0x38')]!==_0xb9a8('0x39')){if(_0x5b29cf[_0xb9a8('0x36')]){_0x26f5af['push']({'type':_0x5b29cf['type'],'app':_0xb9a8('0x34'),'appdata':_0xb9a8('0x3a'),'context':_0x5b29cf[_0xb9a8('0x19')],'exten':_0x5b29cf['exten'],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3['priority']+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});_0x26f5af[_0xb9a8('0x15')]({'type':_0x5b29cf[_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x3b'),'context':_0x5b29cf[_0xb9a8('0x19')],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3['priority']+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});}else{_0x26f5af['push']({'type':_0x5b29cf[_0xb9a8('0x16')],'app':'ExecIf','appdata':_0xb9a8('0x3c'),'context':_0x5b29cf['context'],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3[_0xb9a8('0x11')]+_0x56270a++,'VoiceExtensionId':_0x5b29cf[_0xb9a8('0x1a')]});_0x26f5af['push']({'type':_0x5b29cf[_0xb9a8('0x16')],'app':_0xb9a8('0x17'),'appdata':_0xb9a8('0x3d'),'context':_0x5b29cf[_0xb9a8('0x19')],'exten':_0x5b29cf[_0xb9a8('0xa')],'priority':_0x567fb4[_0xb9a8('0x2c')]+_0x1c6ea3[_0xb9a8('0x11')]+_0x56270a++,'VoiceExtensionId':_0x5b29cf['VoiceExtensionId']});}}}for(var _0x72e30a=0x0;_0x72e30a<_0x567fb4[_0xb9a8('0x2c')];_0x72e30a+=0x1){var _0x375d80=_0x1c6ea3[_0xb9a8('0x11')]+_0x567fb4['length'];var _0x3ea9bb=_0x72e30a===_0x567fb4[_0xb9a8('0x2c')]-0x1?_0x1c6ea3[_0xb9a8('0x11')]+_0x26f5af[_0xb9a8('0x2c')]+_0x519168['length']+0x2:_0x1c6ea3[_0xb9a8('0x11')]+_0x72e30a+0x1;_0x26f5af[_0xb9a8('0x3e')](_0x72e30a,0x0,{'type':_0x5b29cf[_0xb9a8('0x16')],'app':_0xb9a8('0x3f'),'appdata':_0x567fb4[_0x72e30a]+'?'+_0x5b29cf['context']+_0xb9a8('0x40')+_0x375d80+':'+_0x5b29cf[_0xb9a8('0x19')]+_0xb9a8('0x40')+_0x3ea9bb,'exten':_0x5b29cf[_0xb9a8('0xa')],'context':_0x5b29cf['context'],'priority':_0x1c6ea3['priority']+_0x72e30a,'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0]['VoiceExtensionId']});}_0x5b29cf['priority']=_0x26f5af[_0xb9a8('0x2c')]?_[_0xb9a8('0x41')](_0x26f5af)['priority']+0x1:_0x1c6ea3['priority'];_0x1c6ea3['priority']=(_0x519168[_0xb9a8('0x2c')]?_[_0xb9a8('0x41')](_0x519168)[_0xb9a8('0x11')]:_0x5b29cf[_0xb9a8('0x11')])+0x1;_0x1c6ea3['extensions']=_[_0xb9a8('0x42')](_0x1c6ea3[_0xb9a8('0x12')],_0x26f5af,[_0x5b29cf],_0x519168);}_0x1c6ea3[_0xb9a8('0x12')][_0xb9a8('0x15')]({'type':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x16')],'app':_0xb9a8('0x43'),'exten':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0xa')],'context':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x19')],'priority':_0x1c6ea3[_0xb9a8('0x11')],'VoiceExtensionId':_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]});_0x2a690a[_0xb9a8('0x15')](_0x2cbe4b[_0x8867ed][0x0][_0xb9a8('0x1a')]);_0x327bd7=_[_0xb9a8('0x42')](_0x327bd7,_0x1c6ea3['extensions']);}}return _0x36225a[_0xb9a8('0x44')](function(_0x30fd5b){return _0x36225a[_0xb9a8('0x2')][_0xb9a8('0x7')][_0xb9a8('0x45')]({'where':{'VoiceExtensionId':{'$in':_0x2a690a}},'transaction':_0x30fd5b})[_0xb9a8('0x5')](function(_0x567451){return _0x36225a[_0xb9a8('0x2')][_0xb9a8('0x7')][_0xb9a8('0x46')](_[_0xb9a8('0x47')](_0x327bd7,_0xb9a8('0x11')),{'transaction':_0x30fd5b});});});})[_0xb9a8('0x48')](function(_0x35398c){console[_0xb9a8('0x49')](_0x35398c);});}exports[_0xb9a8('0x4a')]=rewrite;