Built motion from commit (unavailable).|2.0.72
[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 _0x1400=['destroy','bulkCreate','catch','error','rewrite','util','models','Interval','then','intervals','VoiceExtension','findAll','IntervalId','uniq','map','exten','queue','playback','hasOwnProperty','answer','progress','priority','extensions','push','type','context','format','CDR(type)=%s','VoiceExtensionId','length','createdAt','updatedAt','interval','*,*,*,*','filter','tag','Set','CDR(tag)=','callerID','CALLERID(all)=','indexOf','app','appType','custom','Answer','Progress','record','recordingFormat','MixMonitor','${UNIQUEID}.','StopMixMonitor','splice',',${EXTEN},','last','concat','transaction'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x1400,0x75));var _0x0140=function(_0xfb4365,_0xd18f10){_0xfb4365=_0xfb4365-0x0;var _0x109516=_0x1400[_0xfb4365];return _0x109516;};'use strict';var _=require('lodash');var util=require(_0x0140('0x0'));function rewrite(_0x1d9358,_0x24982c){var _0x35aa13=this;return _0x1d9358[_0x0140('0x1')][_0x0140('0x2')]['findAll']({'raw':!![]})[_0x0140('0x3')](function(_0x2c4143){_0x35aa13[_0x0140('0x4')]=_0x2c4143;return _0x1d9358[_0x0140('0x1')][_0x0140('0x5')][_0x0140('0x6')]({'where':{'IntervalId':_0x24982c[_0x0140('0x7')]},'raw':!![]});})[_0x0140('0x3')](function(_0x436a17){return _0x1d9358[_0x0140('0x1')]['VoiceExtension'][_0x0140('0x6')]({'where':{'exten':{'$in':_[_0x0140('0x8')](_[_0x0140('0x9')](_0x436a17,_0x0140('0xa')))},'isApp':!![]},'order':[{'raw':'CAST(priority\x20AS\x20UNSIGNED)'}],'raw':!![]});})['then'](function(_0x110bce){var _0x5f27fd=_['groupBy'](_0x110bce,'exten');var _0x4b4922=[_0x0140('0xb'),_0x0140('0xc')];var _0xd8a9fc=[];var _0x18ab66=[];for(var _0x4388d5 in _0x5f27fd){if(_0x5f27fd[_0x0140('0xd')](_0x4388d5)){_0x35aa13[_0x0140('0xe')]=![];_0x35aa13[_0x0140('0xf')]=![];_0x35aa13[_0x0140('0x10')]=0x2;_0x35aa13[_0x0140('0x11')]=[];_0x35aa13[_0x0140('0x11')][_0x0140('0x12')]({'type':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x13')],'context':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x14')],'exten':_0x5f27fd[_0x4388d5][0x0][_0x0140('0xa')],'priority':_0x35aa13[_0x0140('0x10')]++,'app':'Set','appdata':util[_0x0140('0x15')](_0x0140('0x16'),_0x5f27fd[_0x4388d5][0x0][_0x0140('0x13')]),'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});for(var _0x571cc7=0x0,_0xd419f7=0x0;_0x571cc7<_0x5f27fd[_0x4388d5][_0x0140('0x18')];_0x571cc7+=0x1,_0xd419f7=0x0){var _0xd89043=_0x5f27fd[_0x4388d5][_0x571cc7];var _0x422f5b=[];var _0x3dd0c6=[];delete _0xd89043['id'];delete _0xd89043[_0x0140('0x19')];delete _0xd89043[_0x0140('0x1a')];var _0x96c7bb=_0xd89043[_0x0140('0x1b')]!==_0x0140('0x1c')?[_0xd89043[_0x0140('0x1b')]]:_0xd89043[_0x0140('0x7')]?_['map'](_[_0x0140('0x1d')](_0x35aa13[_0x0140('0x4')],{'IntervalId':_0xd89043[_0x0140('0x7')]}),_0x0140('0x1b')):[];if(_0xd89043[_0x0140('0xd')](_0x0140('0x1e'))){if(_0xd89043[_0x0140('0x1e')]&&_0xd89043[_0x0140('0x1e')]!=='--'){_0x422f5b[_0x0140('0x12')]({'type':_0xd89043['type'],'app':_0x0140('0x1f'),'appdata':_0x0140('0x20')+_0xd89043[_0x0140('0x1e')],'context':_0xd89043[_0x0140('0x14')],'exten':_0xd89043[_0x0140('0xa')],'priority':_0x96c7bb['length']+_0x35aa13[_0x0140('0x10')]+_0xd419f7++,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}}if(_0xd89043[_0x0140('0xd')](_0x0140('0x21'))){if(_0xd89043['callerID']){_0x422f5b[_0x0140('0x12')]({'type':_0xd89043[_0x0140('0x13')],'app':_0x0140('0x1f'),'appdata':_0x0140('0x22')+_0xd89043[_0x0140('0x21')],'context':_0xd89043[_0x0140('0x14')],'exten':_0xd89043[_0x0140('0xa')],'priority':_0x96c7bb[_0x0140('0x18')]+_0x35aa13[_0x0140('0x10')]+_0xd419f7++,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}}if(_0xd89043['hasOwnProperty'](_0x0140('0xe'))){if(_0x4b4922[_0x0140('0x23')](_0xd89043[_0x0140('0x24')]['toLowerCase']())>=0x0&&_0xd89043[_0x0140('0x25')]!==_0x0140('0x26')){if(!_0x35aa13['answer']&&_0xd89043['answer']){_0x35aa13['answer']=!![];_0x422f5b[_0x0140('0x12')]({'type':_0xd89043['type'],'app':_0x0140('0x27'),'context':_0xd89043[_0x0140('0x14')],'exten':_0xd89043[_0x0140('0xa')],'priority':_0x96c7bb['length']+_0x35aa13[_0x0140('0x10')]+_0xd419f7++,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}if(!_0x35aa13[_0x0140('0xe')]&&!_0x35aa13['progress']&&!_0xd89043['answer']){_0x35aa13[_0x0140('0xf')]=!![];_0x422f5b[_0x0140('0x12')]({'type':_0xd89043[_0x0140('0x13')],'app':_0x0140('0x28'),'context':_0xd89043['context'],'exten':_0xd89043[_0x0140('0xa')],'priority':_0x96c7bb[_0x0140('0x18')]+_0x35aa13[_0x0140('0x10')]+_0xd419f7++,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}}}if(_0xd89043[_0x0140('0xd')](_0x0140('0x29'))&&_0xd89043['hasOwnProperty'](_0x0140('0x2a'))){if(_0xd89043[_0x0140('0x29')]){_0x422f5b[_0x0140('0x12')]({'type':_0xd89043['type'],'app':_0x0140('0x2b'),'appdata':_0x0140('0x2c')+_0xd89043[_0x0140('0x2a')]+',ab','context':_0xd89043['context'],'exten':_0xd89043['exten'],'priority':_0x96c7bb[_0x0140('0x18')]+_0x35aa13[_0x0140('0x10')]+_0xd419f7++,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}}if(_0xd89043[_0x0140('0xd')](_0x0140('0x29'))&&_0xd89043[_0x0140('0xd')]('recordingFormat')){if(_0xd89043['record']){_0x3dd0c6[_0x0140('0x12')]({'type':_0xd89043['type'],'app':_0x0140('0x2d'),'appdata':null,'context':_0xd89043[_0x0140('0x14')],'exten':_0xd89043['exten'],'priority':_0x96c7bb['length']+_0x35aa13['priority']+_0xd419f7++ +0x1,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}}for(var _0x572cf3=0x0;_0x572cf3<_0x96c7bb[_0x0140('0x18')];_0x572cf3+=0x1){var _0x40bf6a=_0x35aa13[_0x0140('0x10')]+_0x96c7bb[_0x0140('0x18')];var _0x3bf1dc=_0x572cf3===_0x96c7bb[_0x0140('0x18')]-0x1?_0x35aa13[_0x0140('0x10')]+_0x422f5b[_0x0140('0x18')]+_0x3dd0c6['length']+0x2:_0x35aa13[_0x0140('0x10')]+_0x572cf3+0x1;_0x422f5b[_0x0140('0x2e')](_0x572cf3,0x0,{'type':_0xd89043[_0x0140('0x13')],'app':'GotoIfTime','appdata':_0x96c7bb[_0x572cf3]+'?'+_0xd89043[_0x0140('0x14')]+_0x0140('0x2f')+_0x40bf6a+':'+_0xd89043[_0x0140('0x14')]+',${EXTEN},'+_0x3bf1dc,'exten':_0xd89043[_0x0140('0xa')],'context':_0xd89043[_0x0140('0x14')],'priority':_0x35aa13[_0x0140('0x10')]+_0x572cf3,'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});}_0xd89043['priority']=_0x422f5b['length']?_[_0x0140('0x30')](_0x422f5b)[_0x0140('0x10')]+0x1:_0x35aa13[_0x0140('0x10')];_0x35aa13[_0x0140('0x10')]=(_0x3dd0c6['length']?_[_0x0140('0x30')](_0x3dd0c6)[_0x0140('0x10')]:_0xd89043[_0x0140('0x10')])+0x1;_0x35aa13['extensions']=_[_0x0140('0x31')](_0x35aa13['extensions'],_0x422f5b,[_0xd89043],_0x3dd0c6);}_0x35aa13['extensions'][_0x0140('0x12')]({'type':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x13')],'app':'Hangup','exten':_0x5f27fd[_0x4388d5][0x0][_0x0140('0xa')],'context':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x14')],'priority':_0x35aa13['priority'],'VoiceExtensionId':_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]});_0xd8a9fc[_0x0140('0x12')](_0x5f27fd[_0x4388d5][0x0][_0x0140('0x17')]);_0x18ab66=_[_0x0140('0x31')](_0x18ab66,_0x35aa13[_0x0140('0x11')]);}}return _0x1d9358[_0x0140('0x32')](function(_0x4cdb0d){return _0x1d9358['models'][_0x0140('0x5')][_0x0140('0x33')]({'where':{'VoiceExtensionId':{'$in':_0xd8a9fc}},'transaction':_0x4cdb0d})['then'](function(_0x526c25){return _0x1d9358[_0x0140('0x1')][_0x0140('0x5')][_0x0140('0x34')](_['sortBy'](_0x18ab66,'priority'),{'transaction':_0x4cdb0d});});});})[_0x0140('0x35')](function(_0xa504e7){console[_0x0140('0x36')](_0xa504e7);});}exports[_0x0140('0x37')]=rewrite;