Built motion from commit (unavailable).|2.5.4
[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 _0x8bc9=['$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','last','Hangup','concat','transaction','destroy','bulkCreate','sortBy','error','lodash','util','models','Interval','then','intervals','VoiceExtension','findAll','IntervalId','uniq','map','exten','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','queue','playback','hasOwnProperty','priority','extension','find','extensions','push','format','CDR(type)=%s','type','VoiceExtensionId','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','context','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','recordingFormat','Set','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','createdAt','updatedAt','interval','*,*,*,*','tag','length','outbound','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)','answer','app','toLowerCase','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1'];(function(_0x3c31b2,_0x3796b7){var _0xca9321=function(_0x414124){while(--_0x414124){_0x3c31b2['push'](_0x3c31b2['shift']());}};_0xca9321(++_0x3796b7);}(_0x8bc9,0x1c3));var _0x98bc=function(_0x4dde7d,_0x19dee5){_0x4dde7d=_0x4dde7d-0x0;var _0x3967a0=_0x8bc9[_0x4dde7d];return _0x3967a0;};'use strict';var _=require(_0x98bc('0x0'));var util=require(_0x98bc('0x1'));function rewrite(_0x5359e3,_0x12fd71){var _0x1a560a=this;return _0x5359e3[_0x98bc('0x2')][_0x98bc('0x3')]['findAll']({'raw':!![]})[_0x98bc('0x4')](function(_0x210369){_0x1a560a[_0x98bc('0x5')]=_0x210369;return _0x5359e3[_0x98bc('0x2')][_0x98bc('0x6')][_0x98bc('0x7')]({'where':{'IntervalId':_0x12fd71[_0x98bc('0x8')]},'raw':!![]});})[_0x98bc('0x4')](function(_0x1d277a){return _0x5359e3[_0x98bc('0x2')][_0x98bc('0x6')][_0x98bc('0x7')]({'where':{'exten':{'$in':_[_0x98bc('0x9')](_[_0x98bc('0xa')](_0x1d277a,_0x98bc('0xb')))}},'order':[{'raw':_0x98bc('0xc')}],'raw':!![]});})[_0x98bc('0x4')](function(_0x455c99){var _0x1b4265=_[_0x98bc('0xd')](_0x455c99,{'priority':'1'});var _0x496b97=_[_0x98bc('0xd')](_0x455c99,{'isApp':0x1});var _0x38923e=_[_0x98bc('0xe')](_0x496b97,_0x98bc('0xb'));var _0x2effc5=[_0x98bc('0xf'),_0x98bc('0x10')];var _0x29ec30=[];var _0x2e4de0=[];for(var _0x5eabda in _0x38923e){if(_0x38923e[_0x98bc('0x11')](_0x5eabda)){_0x1a560a[_0x98bc('0x12')]=0x2;_0x1a560a['extensions']=[];_0x1a560a[_0x98bc('0x13')]=_[_0x98bc('0x14')](_0x1b4265,{'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')]});_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0]['type'],'app':'Set','appdata':util[_0x98bc('0x17')](_0x98bc('0x18'),_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')]),'context':_0x38923e[_0x5eabda][0x0]['context'],'exten':_0x38923e[_0x5eabda][0x0]['exten'],'priority':_0x1a560a[_0x98bc('0x12')]++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});if(_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')]==='outbound'){if(_0x1a560a['extension']){_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':'Set','appdata':_0x98bc('0x1b')+(_0x1a560a[_0x98bc('0x13')][_0x98bc('0x1c')]?_0x98bc('0x1d')+_0x1a560a[_0x98bc('0x13')][_0x98bc('0x1c')]+'}':_0x98bc('0x1e')),'context':_0x38923e[_0x5eabda][0x0]['context'],'exten':_0x38923e[_0x5eabda][0x0]['exten'],'priority':_0x1a560a['priority']++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});}_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':'Set','appdata':'CDR(routeid)='+_0x38923e[_0x5eabda][0x0]['VoiceExtensionId'],'context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a['priority']++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});var _0x5ae04e=_0x1a560a[_0x98bc('0x12')]++;_0x1a560a['extensions']['push']({'type':_0x38923e[_0x5eabda][0x0]['type'],'app':_0x98bc('0x20'),'appdata':_0x98bc('0x21')+(_0x5ae04e+0x2)+_0x98bc('0x22')+(_0x5ae04e+0x1)+')','context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x5ae04e,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});if(_0x1a560a[_0x98bc('0x13')]){_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':'Set','appdata':_0x1a560a['extension'][_0x98bc('0x1c')]?_0x98bc('0x23')+_0x1a560a[_0x98bc('0x13')][_0x98bc('0x1c')]+'}':_0x98bc('0x24'),'context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a['priority']++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0]['VoiceExtensionId']});}_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':'Set','appdata':_0x98bc('0x25')+_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')],'context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a['priority']++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});if(_0x1a560a['extension']&&_0x1a560a[_0x98bc('0x13')][_0x98bc('0x11')](_0x98bc('0x26'))&&_0x1a560a[_0x98bc('0x13')][_0x98bc('0x26')]!=='none'){_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':'Set','appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a[_0x98bc('0x12')]++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':_0x98bc('0x27'),'appdata':_0x98bc('0x28')+_0x1a560a[_0x98bc('0x13')][_0x98bc('0x26')]||'wav','context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a['priority']++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});}}_0x1a560a['extensions'][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':_0x98bc('0x27'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a[_0x98bc('0x12')]++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0]['VoiceExtensionId']});_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':_0x98bc('0x27'),'appdata':_0x98bc('0x29'),'context':_0x38923e[_0x5eabda][0x0]['context'],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a[_0x98bc('0x12')]++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});_0x1a560a[_0x98bc('0x15')]['push']({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':_0x98bc('0x27'),'appdata':_0x98bc('0x2a'),'context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'priority':_0x1a560a[_0x98bc('0x12')]++,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});for(var _0x44bec1=0x0,_0x42de21=0x0;_0x44bec1<_0x38923e[_0x5eabda]['length'];_0x44bec1+=0x1,_0x42de21=0x0){var _0x300a06=_0x38923e[_0x5eabda][_0x44bec1];if(_0x300a06['type']){_0x300a06[_0x98bc('0x19')]=_0x300a06[_0x98bc('0x19')]['toLowerCase']();}var _0x40dbf8=[];var _0xbdc418=[];delete _0x300a06['id'];delete _0x300a06[_0x98bc('0x2b')];delete _0x300a06[_0x98bc('0x2c')];var _0x3c70e9=_0x300a06[_0x98bc('0x2d')]!==_0x98bc('0x2e')?[_0x300a06[_0x98bc('0x2d')]]:_0x300a06[_0x98bc('0x8')]?_[_0x98bc('0xa')](_[_0x98bc('0xd')](_0x1a560a[_0x98bc('0x5')],{'IntervalId':_0x300a06[_0x98bc('0x8')]}),_0x98bc('0x2d')):[];if(_0x300a06[_0x98bc('0x11')](_0x98bc('0x2f'))){if(_0x300a06['tag']&&_0x300a06['tag']!=='--'){_0x40dbf8[_0x98bc('0x16')]({'type':_0x300a06[_0x98bc('0x19')],'app':'Set','appdata':'CDR(tag)='+_0x300a06[_0x98bc('0x2f')],'context':_0x300a06['context'],'exten':_0x300a06[_0x98bc('0xb')],'priority':_0x3c70e9[_0x98bc('0x30')]+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06[_0x98bc('0x1a')]});}}if(_0x300a06[_0x98bc('0x19')]===_0x98bc('0x31')&&_0x300a06[_0x98bc('0x11')](_0x98bc('0x32'))){if(_0x300a06[_0x98bc('0x32')]){_0x40dbf8[_0x98bc('0x16')]({'type':_0x300a06[_0x98bc('0x19')],'app':'ExecIf','appdata':_0x98bc('0x33')+_0x300a06[_0x98bc('0x32')]+')','context':_0x300a06[_0x98bc('0x1f')],'exten':_0x300a06[_0x98bc('0xb')],'priority':_0x3c70e9[_0x98bc('0x30')]+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06[_0x98bc('0x1a')]});}else{_0x40dbf8['push']({'type':_0x300a06[_0x98bc('0x19')],'app':_0x98bc('0x20'),'appdata':_0x98bc('0x34'),'context':_0x300a06[_0x98bc('0x1f')],'exten':_0x300a06[_0x98bc('0xb')],'priority':_0x3c70e9[_0x98bc('0x30')]+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06['VoiceExtensionId']});}}if(_0x300a06[_0x98bc('0x11')](_0x98bc('0x35'))){if(_0x2effc5['indexOf'](_0x300a06[_0x98bc('0x36')][_0x98bc('0x37')]())>=0x0&&_0x300a06[_0x98bc('0x38')]!==_0x98bc('0x39')){if(_0x300a06[_0x98bc('0x35')]){_0x40dbf8[_0x98bc('0x16')]({'type':_0x300a06[_0x98bc('0x19')],'app':_0x98bc('0x20'),'appdata':_0x98bc('0x3a'),'context':_0x300a06[_0x98bc('0x1f')],'exten':_0x300a06['exten'],'priority':_0x3c70e9[_0x98bc('0x30')]+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06['VoiceExtensionId']});_0x40dbf8['push']({'type':_0x300a06[_0x98bc('0x19')],'app':'Set','appdata':_0x98bc('0x3b'),'context':_0x300a06[_0x98bc('0x1f')],'exten':_0x300a06[_0x98bc('0xb')],'priority':_0x3c70e9['length']+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06['VoiceExtensionId']});}else{_0x40dbf8['push']({'type':_0x300a06['type'],'app':_0x98bc('0x20'),'appdata':_0x98bc('0x3c'),'context':_0x300a06['context'],'exten':_0x300a06['exten'],'priority':_0x3c70e9['length']+_0x1a560a['priority']+_0x42de21++,'VoiceExtensionId':_0x300a06[_0x98bc('0x1a')]});_0x40dbf8[_0x98bc('0x16')]({'type':_0x300a06['type'],'app':_0x98bc('0x27'),'appdata':_0x98bc('0x3d'),'context':_0x300a06[_0x98bc('0x1f')],'exten':_0x300a06[_0x98bc('0xb')],'priority':_0x3c70e9[_0x98bc('0x30')]+_0x1a560a[_0x98bc('0x12')]+_0x42de21++,'VoiceExtensionId':_0x300a06[_0x98bc('0x1a')]});}}}for(var _0x48c086=0x0;_0x48c086<_0x3c70e9[_0x98bc('0x30')];_0x48c086+=0x1){var _0x313932=_0x1a560a[_0x98bc('0x12')]+_0x3c70e9[_0x98bc('0x30')];var _0x484341=_0x48c086===_0x3c70e9['length']-0x1?_0x1a560a[_0x98bc('0x12')]+_0x40dbf8['length']+_0xbdc418[_0x98bc('0x30')]+0x2:_0x1a560a['priority']+_0x48c086+0x1;_0x40dbf8[_0x98bc('0x3e')](_0x48c086,0x0,{'type':_0x300a06['type'],'app':_0x98bc('0x3f'),'appdata':_0x3c70e9[_0x48c086]+'?'+_0x300a06[_0x98bc('0x1f')]+_0x98bc('0x40')+_0x313932+':'+_0x300a06[_0x98bc('0x1f')]+_0x98bc('0x40')+_0x484341,'exten':_0x300a06[_0x98bc('0xb')],'context':_0x300a06[_0x98bc('0x1f')],'priority':_0x1a560a['priority']+_0x48c086,'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});}_0x300a06[_0x98bc('0x12')]=_0x40dbf8[_0x98bc('0x30')]?_['last'](_0x40dbf8)[_0x98bc('0x12')]+0x1:_0x1a560a[_0x98bc('0x12')];_0x1a560a[_0x98bc('0x12')]=(_0xbdc418[_0x98bc('0x30')]?_[_0x98bc('0x41')](_0xbdc418)[_0x98bc('0x12')]:_0x300a06[_0x98bc('0x12')])+0x1;_0x1a560a['extensions']=_['concat'](_0x1a560a['extensions'],_0x40dbf8,[_0x300a06],_0xbdc418);}_0x1a560a[_0x98bc('0x15')][_0x98bc('0x16')]({'type':_0x38923e[_0x5eabda][0x0][_0x98bc('0x19')],'app':_0x98bc('0x42'),'exten':_0x38923e[_0x5eabda][0x0][_0x98bc('0xb')],'context':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1f')],'priority':_0x1a560a[_0x98bc('0x12')],'VoiceExtensionId':_0x38923e[_0x5eabda][0x0][_0x98bc('0x1a')]});_0x29ec30[_0x98bc('0x16')](_0x38923e[_0x5eabda][0x0]['VoiceExtensionId']);_0x2e4de0=_[_0x98bc('0x43')](_0x2e4de0,_0x1a560a[_0x98bc('0x15')]);}}return _0x5359e3[_0x98bc('0x44')](function(_0x20fa67){return _0x5359e3[_0x98bc('0x2')][_0x98bc('0x6')][_0x98bc('0x45')]({'where':{'VoiceExtensionId':{'$in':_0x29ec30}},'transaction':_0x20fa67})['then'](function(_0x10d9ea){return _0x5359e3[_0x98bc('0x2')][_0x98bc('0x6')][_0x98bc('0x46')](_[_0x98bc('0x47')](_0x2e4de0,'priority'),{'transaction':_0x20fa67});});});})['catch'](function(_0x2a4e01){console[_0x98bc('0x48')](_0x2a4e01);});}exports['rewrite']=rewrite;