Built motion from commit (unavailable).|2.0.76
[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 _0x1b0f=['${UNIQUEID}.',',ab','StopMixMonitor','splice','GotoIfTime',',${EXTEN},','last','concat','Hangup','transaction','bulkCreate','sortBy','catch','error','rewrite','lodash','util','Interval','findAll','models','VoiceExtension','then','map','exten','CAST(priority\x20AS\x20UNSIGNED)','queue','hasOwnProperty','answer','progress','priority','extensions','push','type','context','Set','VoiceExtensionId','length','createdAt','updatedAt','interval','*,*,*,*','filter','intervals','IntervalId','tag','CDR(tag)=','callerID','indexOf','app','toLowerCase','appType','custom','Answer','Progress','recordingFormat','record'];(function(_0xfed031,_0x23c5e8){var _0x3ac165=function(_0x525bc1){while(--_0x525bc1){_0xfed031['push'](_0xfed031['shift']());}};_0x3ac165(++_0x23c5e8);}(_0x1b0f,0x1cf));var _0xf1b0=function(_0x35bdbc,_0x2beb9a){_0x35bdbc=_0x35bdbc-0x0;var _0x5c8b04=_0x1b0f[_0x35bdbc];return _0x5c8b04;};'use strict';var _=require(_0xf1b0('0x0'));var util=require(_0xf1b0('0x1'));function rewrite(_0x14b7f4,_0x4ded80){var _0xf678f9=this;return _0x14b7f4['models'][_0xf1b0('0x2')][_0xf1b0('0x3')]({'raw':!![]})['then'](function(_0x8651be){_0xf678f9['intervals']=_0x8651be;return _0x14b7f4[_0xf1b0('0x4')][_0xf1b0('0x5')][_0xf1b0('0x3')]({'where':{'IntervalId':_0x4ded80['IntervalId']},'raw':!![]});})[_0xf1b0('0x6')](function(_0x31b11e){return _0x14b7f4[_0xf1b0('0x4')][_0xf1b0('0x5')]['findAll']({'where':{'exten':{'$in':_['uniq'](_[_0xf1b0('0x7')](_0x31b11e,_0xf1b0('0x8')))},'isApp':!![]},'order':[{'raw':_0xf1b0('0x9')}],'raw':!![]});})['then'](function(_0x2b3f2c){var _0x3f7800=_['groupBy'](_0x2b3f2c,_0xf1b0('0x8'));var _0x6dd0e3=[_0xf1b0('0xa'),'playback'];var _0x6c6b59=[];var _0x2bb5ea=[];for(var _0x20e38e in _0x3f7800){if(_0x3f7800[_0xf1b0('0xb')](_0x20e38e)){_0xf678f9[_0xf1b0('0xc')]=![];_0xf678f9[_0xf1b0('0xd')]=![];_0xf678f9[_0xf1b0('0xe')]=0x2;_0xf678f9[_0xf1b0('0xf')]=[];_0xf678f9['extensions'][_0xf1b0('0x10')]({'type':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x11')],'context':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x12')],'exten':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x8')],'priority':_0xf678f9['priority']++,'app':_0xf1b0('0x13'),'appdata':util['format']('CDR(type)=%s',_0x3f7800[_0x20e38e][0x0]['type']),'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});for(var _0x2bddf9=0x0,_0x380471=0x0;_0x2bddf9<_0x3f7800[_0x20e38e][_0xf1b0('0x15')];_0x2bddf9+=0x1,_0x380471=0x0){var _0x17b180=_0x3f7800[_0x20e38e][_0x2bddf9];var _0x58561a=[];var _0x8caa7b=[];delete _0x17b180['id'];delete _0x17b180[_0xf1b0('0x16')];delete _0x17b180[_0xf1b0('0x17')];var _0x2bf13e=_0x17b180[_0xf1b0('0x18')]!==_0xf1b0('0x19')?[_0x17b180[_0xf1b0('0x18')]]:_0x17b180['IntervalId']?_[_0xf1b0('0x7')](_[_0xf1b0('0x1a')](_0xf678f9[_0xf1b0('0x1b')],{'IntervalId':_0x17b180[_0xf1b0('0x1c')]}),_0xf1b0('0x18')):[];if(_0x17b180[_0xf1b0('0xb')](_0xf1b0('0x1d'))){if(_0x17b180[_0xf1b0('0x1d')]&&_0x17b180['tag']!=='--'){_0x58561a[_0xf1b0('0x10')]({'type':_0x17b180[_0xf1b0('0x11')],'app':'Set','appdata':_0xf1b0('0x1e')+_0x17b180[_0xf1b0('0x1d')],'context':_0x17b180[_0xf1b0('0x12')],'exten':_0x17b180[_0xf1b0('0x8')],'priority':_0x2bf13e[_0xf1b0('0x15')]+_0xf678f9[_0xf1b0('0xe')]+_0x380471++,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}}if(_0x17b180[_0xf1b0('0xb')]('callerID')){if(_0x17b180[_0xf1b0('0x1f')]){_0x58561a['push']({'type':_0x17b180[_0xf1b0('0x11')],'app':'Set','appdata':'CALLERID(all)='+_0x17b180['callerID'],'context':_0x17b180[_0xf1b0('0x12')],'exten':_0x17b180[_0xf1b0('0x8')],'priority':_0x2bf13e['length']+_0xf678f9[_0xf1b0('0xe')]+_0x380471++,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}}if(_0x17b180[_0xf1b0('0xb')]('answer')){if(_0x6dd0e3[_0xf1b0('0x20')](_0x17b180[_0xf1b0('0x21')][_0xf1b0('0x22')]())>=0x0&&_0x17b180[_0xf1b0('0x23')]!==_0xf1b0('0x24')){if(!_0xf678f9[_0xf1b0('0xc')]&&_0x17b180[_0xf1b0('0xc')]){_0xf678f9['answer']=!![];_0x58561a[_0xf1b0('0x10')]({'type':_0x17b180['type'],'app':_0xf1b0('0x25'),'context':_0x17b180['context'],'exten':_0x17b180['exten'],'priority':_0x2bf13e[_0xf1b0('0x15')]+_0xf678f9[_0xf1b0('0xe')]+_0x380471++,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}if(!_0xf678f9[_0xf1b0('0xc')]&&!_0xf678f9[_0xf1b0('0xd')]&&!_0x17b180[_0xf1b0('0xc')]){_0xf678f9[_0xf1b0('0xd')]=!![];_0x58561a[_0xf1b0('0x10')]({'type':_0x17b180[_0xf1b0('0x11')],'app':_0xf1b0('0x26'),'context':_0x17b180[_0xf1b0('0x12')],'exten':_0x17b180[_0xf1b0('0x8')],'priority':_0x2bf13e[_0xf1b0('0x15')]+_0xf678f9[_0xf1b0('0xe')]+_0x380471++,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}}}if(_0x17b180[_0xf1b0('0xb')]('record')&&_0x17b180[_0xf1b0('0xb')](_0xf1b0('0x27'))){if(_0x17b180[_0xf1b0('0x28')]){_0x58561a[_0xf1b0('0x10')]({'type':_0x17b180[_0xf1b0('0x11')],'app':'MixMonitor','appdata':_0xf1b0('0x29')+_0x17b180[_0xf1b0('0x27')]+_0xf1b0('0x2a'),'context':_0x17b180[_0xf1b0('0x12')],'exten':_0x17b180[_0xf1b0('0x8')],'priority':_0x2bf13e[_0xf1b0('0x15')]+_0xf678f9[_0xf1b0('0xe')]+_0x380471++,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}}if(_0x17b180['hasOwnProperty'](_0xf1b0('0x28'))&&_0x17b180['hasOwnProperty']('recordingFormat')){if(_0x17b180[_0xf1b0('0x28')]){_0x8caa7b[_0xf1b0('0x10')]({'type':_0x17b180[_0xf1b0('0x11')],'app':_0xf1b0('0x2b'),'appdata':null,'context':_0x17b180[_0xf1b0('0x12')],'exten':_0x17b180[_0xf1b0('0x8')],'priority':_0x2bf13e[_0xf1b0('0x15')]+_0xf678f9['priority']+_0x380471++ +0x1,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0]['VoiceExtensionId']});}}for(var _0x55d160=0x0;_0x55d160<_0x2bf13e[_0xf1b0('0x15')];_0x55d160+=0x1){var _0x108d68=_0xf678f9[_0xf1b0('0xe')]+_0x2bf13e[_0xf1b0('0x15')];var _0x1ec72b=_0x55d160===_0x2bf13e[_0xf1b0('0x15')]-0x1?_0xf678f9[_0xf1b0('0xe')]+_0x58561a[_0xf1b0('0x15')]+_0x8caa7b[_0xf1b0('0x15')]+0x2:_0xf678f9[_0xf1b0('0xe')]+_0x55d160+0x1;_0x58561a[_0xf1b0('0x2c')](_0x55d160,0x0,{'type':_0x17b180[_0xf1b0('0x11')],'app':_0xf1b0('0x2d'),'appdata':_0x2bf13e[_0x55d160]+'?'+_0x17b180[_0xf1b0('0x12')]+_0xf1b0('0x2e')+_0x108d68+':'+_0x17b180[_0xf1b0('0x12')]+_0xf1b0('0x2e')+_0x1ec72b,'exten':_0x17b180['exten'],'context':_0x17b180[_0xf1b0('0x12')],'priority':_0xf678f9[_0xf1b0('0xe')]+_0x55d160,'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});}_0x17b180['priority']=_0x58561a['length']?_['last'](_0x58561a)[_0xf1b0('0xe')]+0x1:_0xf678f9[_0xf1b0('0xe')];_0xf678f9['priority']=(_0x8caa7b[_0xf1b0('0x15')]?_[_0xf1b0('0x2f')](_0x8caa7b)[_0xf1b0('0xe')]:_0x17b180[_0xf1b0('0xe')])+0x1;_0xf678f9[_0xf1b0('0xf')]=_[_0xf1b0('0x30')](_0xf678f9[_0xf1b0('0xf')],_0x58561a,[_0x17b180],_0x8caa7b);}_0xf678f9[_0xf1b0('0xf')]['push']({'type':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x11')],'app':_0xf1b0('0x31'),'exten':_0x3f7800[_0x20e38e][0x0]['exten'],'context':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x12')],'priority':_0xf678f9['priority'],'VoiceExtensionId':_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]});_0x6c6b59[_0xf1b0('0x10')](_0x3f7800[_0x20e38e][0x0][_0xf1b0('0x14')]);_0x2bb5ea=_[_0xf1b0('0x30')](_0x2bb5ea,_0xf678f9[_0xf1b0('0xf')]);}}return _0x14b7f4[_0xf1b0('0x32')](function(_0x22feae){return _0x14b7f4[_0xf1b0('0x4')][_0xf1b0('0x5')]['destroy']({'where':{'VoiceExtensionId':{'$in':_0x6c6b59}},'transaction':_0x22feae})['then'](function(_0x393d9f){return _0x14b7f4[_0xf1b0('0x4')][_0xf1b0('0x5')][_0xf1b0('0x33')](_[_0xf1b0('0x34')](_0x2bb5ea,'priority'),{'transaction':_0x22feae});});});})[_0xf1b0('0x35')](function(_0xe8830a){console[_0xf1b0('0x36')](_0xe8830a);});}exports[_0xf1b0('0x37')]=rewrite;