Built motion from commit b58257bb.|2.5.37
[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 _0xb8c8=['format','CDR(type)=%s','type','context','VoiceExtensionId','inbound','CDR(routeid)=','outbound','extension','cutdigits','${EXTEN}','):Goto(','hasOwnProperty','recordingFormat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','length','toLowerCase','createdAt','updatedAt','interval','*,*,*,*','tag','CDR(tag)=','callerID','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):Set(CALLERID(all)=','answer','indexOf','appType','custom','ExecIf','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','splice',',${EXTEN},','last','concat','Hangup','transaction','bulkCreate','catch','error','rewrite','util','models','Interval','findAll','then','intervals','VoiceExtension','IntervalId','map','CAST(priority\x20AS\x20UNSIGNED)','filter','groupBy','exten','queue','priority','extensions','find','push','Set'];(function(_0x2c4468,_0x28dd06){var _0x3ba825=function(_0x1a6f42){while(--_0x1a6f42){_0x2c4468['push'](_0x2c4468['shift']());}};_0x3ba825(++_0x28dd06);}(_0xb8c8,0x6f));var _0x8b8c=function(_0x5d5cbb,_0x195302){_0x5d5cbb=_0x5d5cbb-0x0;var _0x4eaf19=_0xb8c8[_0x5d5cbb];return _0x4eaf19;};'use strict';var _=require('lodash');var util=require(_0x8b8c('0x0'));function rewrite(_0x2a14ad,_0xd2cfb9){var _0x262d96=this;return _0x2a14ad[_0x8b8c('0x1')][_0x8b8c('0x2')][_0x8b8c('0x3')]({'raw':!![]})[_0x8b8c('0x4')](function(_0x1b11ea){_0x262d96[_0x8b8c('0x5')]=_0x1b11ea;return _0x2a14ad[_0x8b8c('0x1')][_0x8b8c('0x6')][_0x8b8c('0x3')]({'where':{'IntervalId':_0xd2cfb9[_0x8b8c('0x7')]},'raw':!![]});})[_0x8b8c('0x4')](function(_0x56608a){return _0x2a14ad[_0x8b8c('0x1')][_0x8b8c('0x6')]['findAll']({'where':{'exten':{'$in':_['uniq'](_[_0x8b8c('0x8')](_0x56608a,'exten'))}},'order':[{'raw':_0x8b8c('0x9')}],'raw':!![]});})[_0x8b8c('0x4')](function(_0x1f9242){var _0x5048a8=_['filter'](_0x1f9242,{'priority':'1'});var _0x33f12b=_[_0x8b8c('0xa')](_0x1f9242,{'isApp':0x1});var _0x424d87=_[_0x8b8c('0xb')](_0x33f12b,_0x8b8c('0xc'));var _0x4b94c7=[_0x8b8c('0xd'),'playback'];var _0x2f2b9a=[];var _0x33ce7e=[];for(var _0x21fa60 in _0x424d87){if(_0x424d87['hasOwnProperty'](_0x21fa60)){_0x262d96[_0x8b8c('0xe')]=0x2;_0x262d96[_0x8b8c('0xf')]=[];_0x262d96['extension']=_[_0x8b8c('0x10')](_0x5048a8,{'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')]});_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0]['type'],'app':_0x8b8c('0x12'),'appdata':util[_0x8b8c('0x13')](_0x8b8c('0x14'),_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')]),'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});if(_0x424d87[_0x21fa60][0x0]['type']===_0x8b8c('0x18')){_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x19')+_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')],'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});}else if(_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')]===_0x8b8c('0x1a')){if(_0x262d96[_0x8b8c('0x1b')]){_0x262d96[_0x8b8c('0xf')]['push']({'type':_0x424d87[_0x21fa60][0x0]['type'],'app':_0x8b8c('0x12'),'appdata':'CDR(destination)='+(_0x262d96['extension'][_0x8b8c('0x1c')]?'${EXTEN:'+_0x262d96['extension']['cutdigits']+'}':_0x8b8c('0x1d')),'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0]['exten'],'priority':_0x262d96['priority']++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});}_0x262d96['extensions'][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x19')+_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')],'context':_0x424d87[_0x21fa60][0x0]['context'],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});var _0x5da49b=_0x262d96[_0x8b8c('0xe')]++;_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0]['type'],'app':'ExecIf','appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x5da49b+0x2)+_0x8b8c('0x1e')+(_0x5da49b+0x1)+')','context':_0x424d87[_0x21fa60][0x0]['context'],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x5da49b,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});if(_0x262d96[_0x8b8c('0x1b')]){_0x262d96['extensions']['push']({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x262d96[_0x8b8c('0x1b')][_0x8b8c('0x1c')]?'CDR(prefix)=${EXTEN:0:'+_0x262d96[_0x8b8c('0x1b')]['cutdigits']+'}':'CDR(prefix)=noprefix','context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96['priority']++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});}_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':'outboundrouteid='+_0x424d87[_0x21fa60][0x0]['VoiceExtensionId'],'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});if(_0x262d96[_0x8b8c('0x1b')]&&_0x262d96['extension'][_0x8b8c('0x1f')](_0x8b8c('0x20'))&&_0x262d96[_0x8b8c('0x1b')]['recordingFormat']!=='none'){_0x262d96['extensions'][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x21'),'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0]['exten'],'priority':_0x262d96['priority']++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});_0x262d96[_0x8b8c('0xf')]['push']({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x22')+_0x262d96[_0x8b8c('0x1b')][_0x8b8c('0x20')]||'wav','context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});}}_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96['priority']++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x23'),'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96['priority']++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});_0x262d96[_0x8b8c('0xf')][_0x8b8c('0x11')]({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x24'),'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'exten':_0x424d87[_0x21fa60][0x0][_0x8b8c('0xc')],'priority':_0x262d96[_0x8b8c('0xe')]++,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x17')]});for(var _0x4cf46f=0x0,_0x4e0d62=0x0;_0x4cf46f<_0x424d87[_0x21fa60][_0x8b8c('0x25')];_0x4cf46f+=0x1,_0x4e0d62=0x0){var _0x459e8d=_0x424d87[_0x21fa60][_0x4cf46f];if(_0x459e8d['type']){_0x459e8d[_0x8b8c('0x15')]=_0x459e8d[_0x8b8c('0x15')][_0x8b8c('0x26')]();}var _0x35cc0f=[];var _0x1d3e68=[];delete _0x459e8d['id'];delete _0x459e8d[_0x8b8c('0x27')];delete _0x459e8d[_0x8b8c('0x28')];var _0xaf6901=_0x459e8d[_0x8b8c('0x29')]!==_0x8b8c('0x2a')?[_0x459e8d['interval']]:_0x459e8d['IntervalId']?_[_0x8b8c('0x8')](_[_0x8b8c('0xa')](_0x262d96[_0x8b8c('0x5')],{'IntervalId':_0x459e8d['IntervalId']}),_0x8b8c('0x29')):[];if(_0x459e8d[_0x8b8c('0x1f')](_0x8b8c('0x2b'))){if(_0x459e8d[_0x8b8c('0x2b')]&&_0x459e8d[_0x8b8c('0x2b')]!=='--'){_0x35cc0f[_0x8b8c('0x11')]({'type':_0x459e8d[_0x8b8c('0x15')],'app':'Set','appdata':_0x8b8c('0x2c')+_0x459e8d[_0x8b8c('0x2b')],'context':_0x459e8d['context'],'exten':_0x459e8d['exten'],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});}}if(_0x459e8d[_0x8b8c('0x15')]===_0x8b8c('0x1a')&&_0x459e8d[_0x8b8c('0x1f')](_0x8b8c('0x2d'))){if(_0x459e8d[_0x8b8c('0x2d')]){_0x35cc0f['push']({'type':_0x459e8d[_0x8b8c('0x15')],'app':'ExecIf','appdata':_0x8b8c('0x2e')+_0x459e8d[_0x8b8c('0x2d')]+')','context':_0x459e8d[_0x8b8c('0x16')],'exten':_0x459e8d[_0x8b8c('0xc')],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});}else{_0x35cc0f[_0x8b8c('0x11')]({'type':_0x459e8d[_0x8b8c('0x15')],'app':'ExecIf','appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):NoOp(No\x20number\x20available)','context':_0x459e8d[_0x8b8c('0x16')],'exten':_0x459e8d[_0x8b8c('0xc')],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});}}if(_0x459e8d[_0x8b8c('0x1f')](_0x8b8c('0x2f'))){if(_0x4b94c7[_0x8b8c('0x30')](_0x459e8d['app']['toLowerCase']())>=0x0&&_0x459e8d[_0x8b8c('0x31')]!==_0x8b8c('0x32')){if(_0x459e8d[_0x8b8c('0x2f')]){_0x35cc0f[_0x8b8c('0x11')]({'type':_0x459e8d[_0x8b8c('0x15')],'app':_0x8b8c('0x33'),'appdata':_0x8b8c('0x34'),'context':_0x459e8d[_0x8b8c('0x16')],'exten':_0x459e8d[_0x8b8c('0xc')],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96['priority']+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});_0x35cc0f['push']({'type':_0x459e8d[_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':_0x8b8c('0x35'),'context':_0x459e8d['context'],'exten':_0x459e8d[_0x8b8c('0xc')],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});}else{_0x35cc0f['push']({'type':_0x459e8d['type'],'app':_0x8b8c('0x33'),'appdata':_0x8b8c('0x36'),'context':_0x459e8d[_0x8b8c('0x16')],'exten':_0x459e8d['exten'],'priority':_0xaf6901['length']+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});_0x35cc0f['push']({'type':_0x459e8d[_0x8b8c('0x15')],'app':_0x8b8c('0x12'),'appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x459e8d[_0x8b8c('0x16')],'exten':_0x459e8d[_0x8b8c('0xc')],'priority':_0xaf6901[_0x8b8c('0x25')]+_0x262d96[_0x8b8c('0xe')]+_0x4e0d62++,'VoiceExtensionId':_0x459e8d[_0x8b8c('0x17')]});}}}for(var _0x532ed4=0x0;_0x532ed4<_0xaf6901[_0x8b8c('0x25')];_0x532ed4+=0x1){var _0x2102ab=_0x262d96[_0x8b8c('0xe')]+_0xaf6901['length'];var _0x34ff55=_0x532ed4===_0xaf6901[_0x8b8c('0x25')]-0x1?_0x262d96['priority']+_0x35cc0f[_0x8b8c('0x25')]+_0x1d3e68[_0x8b8c('0x25')]+0x2:_0x262d96[_0x8b8c('0xe')]+_0x532ed4+0x1;_0x35cc0f[_0x8b8c('0x37')](_0x532ed4,0x0,{'type':_0x459e8d['type'],'app':'GotoIfTime','appdata':_0xaf6901[_0x532ed4]+'?'+_0x459e8d['context']+_0x8b8c('0x38')+_0x2102ab+':'+_0x459e8d[_0x8b8c('0x16')]+_0x8b8c('0x38')+_0x34ff55,'exten':_0x459e8d[_0x8b8c('0xc')],'context':_0x459e8d[_0x8b8c('0x16')],'priority':_0x262d96[_0x8b8c('0xe')]+_0x532ed4,'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});}_0x459e8d[_0x8b8c('0xe')]=_0x35cc0f['length']?_[_0x8b8c('0x39')](_0x35cc0f)['priority']+0x1:_0x262d96['priority'];_0x262d96['priority']=(_0x1d3e68['length']?_['last'](_0x1d3e68)[_0x8b8c('0xe')]:_0x459e8d[_0x8b8c('0xe')])+0x1;_0x262d96['extensions']=_[_0x8b8c('0x3a')](_0x262d96[_0x8b8c('0xf')],_0x35cc0f,[_0x459e8d],_0x1d3e68);}_0x262d96[_0x8b8c('0xf')]['push']({'type':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x15')],'app':_0x8b8c('0x3b'),'exten':_0x424d87[_0x21fa60][0x0]['exten'],'context':_0x424d87[_0x21fa60][0x0][_0x8b8c('0x16')],'priority':_0x262d96['priority'],'VoiceExtensionId':_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']});_0x2f2b9a[_0x8b8c('0x11')](_0x424d87[_0x21fa60][0x0]['VoiceExtensionId']);_0x33ce7e=_[_0x8b8c('0x3a')](_0x33ce7e,_0x262d96[_0x8b8c('0xf')]);}}return _0x2a14ad[_0x8b8c('0x3c')](function(_0x5a1ba2){return _0x2a14ad['models'][_0x8b8c('0x6')]['destroy']({'where':{'VoiceExtensionId':{'$in':_0x2f2b9a}},'transaction':_0x5a1ba2})[_0x8b8c('0x4')](function(_0x392ce4){return _0x2a14ad[_0x8b8c('0x1')][_0x8b8c('0x6')][_0x8b8c('0x3d')](_['sortBy'](_0x33ce7e,'priority'),{'transaction':_0x5a1ba2});});});})[_0x8b8c('0x3e')](function(_0x23787b){console[_0x8b8c('0x3f')](_0x23787b);});}exports[_0x8b8c('0x40')]=rewrite;