61f0d3dec4e17e0d5800fea8ddd2666a88420f1e
[motion2.git] / server / api / voiceExtension / voiceExtension.model.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 _0xe984=['prefix','SIP','join','none','indexOf','U(xcally-mixmonitor-context)','isEmpty','Interval','findAll','interval','then','*,*,*,*','intervals','IntervalId','map','filter','toLowerCase','tag','CDR(tag)=','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','answer','queue','playback','includes','app','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','outboundDial','appdata','priority','concat','last','catch','define','VoiceExtension','voice_extensions','get','Hangup','./voiceExtension.attributes','exports','models','type','CDR(type)=','context','exten','alias','Set','NoOp','CDR(routeAlias)=','No\x20alias\x20set','inbound','push','CDR(routeid)=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','outbound','CDR(type)=outbound','CDR(destination)=','${EXTEN:','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','cutdigits','CDR(prefix)=noprefix','MONITOR_OPTIONS=ab','outboundrouteid=','hasOwnProperty','recordingFormat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','wav','trunk','timeout','options','split','length','name','param','phone'];(function(_0x532850,_0x3a100a){var _0x4ea53f=function(_0x243531){while(--_0x243531){_0x532850['push'](_0x532850['shift']());}};_0x4ea53f(++_0x3a100a);}(_0xe984,0xe2));var _0x4e98=function(_0x2ff762,_0x342c0b){_0x2ff762=_0x2ff762-0x0;var _0x158b02=_0xe984[_0x2ff762];return _0x158b02;};'use strict';var _=require('lodash');var attributes=require(_0x4e98('0x0'));module[_0x4e98('0x1')]=function(_0x1357a2){var _0x162f51=_0x1357a2[_0x4e98('0x2')];function _0x449b1e(_0x2fff79){var _0x22252c=0x2;var _0xfa4cd4=[{'type':_0x2fff79[_0x4e98('0x3')],'app':'Set','appdata':_0x4e98('0x4')+_0x2fff79[_0x4e98('0x3')],'context':_0x2fff79[_0x4e98('0x5')],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']},{'type':_0x2fff79['type'],'app':_0x2fff79[_0x4e98('0x7')]?_0x4e98('0x8'):_0x4e98('0x9'),'appdata':_0x2fff79[_0x4e98('0x7')]?_0x4e98('0xa')+_0x2fff79['alias']:_0x4e98('0xb'),'context':_0x2fff79['context'],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']}];if(_0x2fff79[_0x4e98('0x3')]===_0x4e98('0xc')){_0xfa4cd4[_0x4e98('0xd')]({'type':_0x4e98('0xc'),'app':'Set','appdata':_0x4e98('0xe')+_0x2fff79['id'],'context':_0x2fff79[_0x4e98('0x5')],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']});}_0xfa4cd4['push']({'type':_0x2fff79[_0x4e98('0x3')],'app':'Set','appdata':_0x4e98('0xf'),'context':_0x2fff79[_0x4e98('0x5')],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']},{'type':_0x2fff79[_0x4e98('0x3')],'app':'Set','appdata':_0x4e98('0x10'),'context':_0x2fff79[_0x4e98('0x5')],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']},{'type':_0x2fff79[_0x4e98('0x3')],'app':_0x4e98('0x8'),'appdata':'MONITOR_OPTIONS=ab','context':_0x2fff79[_0x4e98('0x5')],'exten':_0x2fff79[_0x4e98('0x6')],'priority':_0x22252c++,'VoiceExtensionId':_0x2fff79['id']});return _0xfa4cd4;}function _0x26b60a(_0x262f39){var _0x288cb6=0x2;var _0x22c683=[{'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x12'),'context':_0x262f39['context'],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':_0x262f39[_0x4e98('0x7')]?_0x4e98('0x8'):_0x4e98('0x9'),'appdata':_0x262f39[_0x4e98('0x7')]?_0x4e98('0xa')+_0x262f39[_0x4e98('0x7')]:_0x4e98('0xb'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x13')+(_0x262f39['cutdigits']?_0x4e98('0x14')+_0x262f39['cutdigits']+'}':'${EXTEN}'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39['exten'],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':'Set','appdata':_0x4e98('0xe')+_0x262f39['id'],'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39['exten'],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':'outbound','app':_0x4e98('0x15'),'appdata':_0x4e98('0x16')+(_0x288cb6+0x2)+_0x4e98('0x17')+(_0x288cb6+0x1)+')','context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':'Set','appdata':_0x262f39['cutdigits']?_0x4e98('0x18')+_0x262f39[_0x4e98('0x19')]+'}':_0x4e98('0x1a'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0xf'),'context':_0x262f39['context'],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':'outbound','app':'Set','appdata':_0x4e98('0x10'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39['exten'],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x1b'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x1c')+_0x262f39['id'],'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']}];if(_0x262f39[_0x4e98('0x1d')]('recordingFormat')&&_0x262f39[_0x4e98('0x1e')]!=='none'){_0x22c683[_0x4e98('0xd')]({'type':_0x4e98('0x11'),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x1f'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']},{'type':_0x4e98('0x11'),'app':'Set','appdata':'_XCALLY_MIXMONITOR_FORMAT='+_0x262f39[_0x4e98('0x1e')]||_0x4e98('0x20'),'context':_0x262f39[_0x4e98('0x5')],'exten':_0x262f39[_0x4e98('0x6')],'priority':_0x288cb6++,'VoiceExtensionId':_0x262f39['id']});}return _0x22c683;}function _0x136673(_0x39926b,_0x53f115){var _0x23ff24=[{'name':_0x4e98('0x21'),'param':0x0},{'name':_0x4e98('0x22'),'param':0x1},{'name':_0x4e98('0x23'),'param':0x2},{'name':'url','param':0x3}];var _0x51dec2={};var _0x1c76e9=_0x53f115[_0x4e98('0x24')](',');var _0x3a16b1=[];for(var _0x3fc3ca=0x0;_0x3fc3ca<_0x23ff24[_0x4e98('0x25')];_0x3fc3ca++){switch(_0x23ff24[_0x3fc3ca][_0x4e98('0x26')]){case _0x4e98('0x21'):_0x51dec2[_0x4e98('0x21')]=_0x1c76e9[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]][_0x4e98('0x24')]('/')[0x1];_0x51dec2[_0x4e98('0x28')]=_0x1c76e9[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]][_0x4e98('0x24')]('/')[0x2];_0x51dec2['prefix']=_0x51dec2[_0x4e98('0x28')]?_0x51dec2[_0x4e98('0x28')][_0x4e98('0x24')]('$')[0x0]:undefined;_0x51dec2[_0x4e98('0x28')]=_0x39926b['cutdigits']?(_0x51dec2[_0x4e98('0x29')]||'')+'${EXTEN:'+_0x39926b[_0x4e98('0x19')]+'}':(_0x51dec2['prefix']||'')+'${EXTEN}';_0x3a16b1[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]]=[_0x4e98('0x2a'),_0x51dec2['trunk'],_0x51dec2[_0x4e98('0x28')]][_0x4e98('0x2b')]('/');break;case _0x4e98('0x23'):_0x51dec2[_0x4e98('0x23')]=_0x1c76e9[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]];if(_0x39926b[_0x4e98('0x1e')]!==_0x4e98('0x2c')){if(_0x51dec2[_0x4e98('0x23')][_0x4e98('0x2d')](_0x4e98('0x2e'))<0x0){_0x51dec2[_0x4e98('0x23')]+='U(xcally-mixmonitor-context)';}}else{_0x51dec2[_0x4e98('0x23')]=_0x51dec2['options']['replace'](_0x4e98('0x2e'),'');}_0x3a16b1[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]]=_0x51dec2[_0x4e98('0x23')];break;default:_0x3a16b1[_0x23ff24[_0x3fc3ca]['param']]=_0x1c76e9[_0x23ff24[_0x3fc3ca][_0x4e98('0x27')]];}}return _0x3a16b1[_0x4e98('0x2b')](',');}function _0x196683(_0x344eb0,_0x2ad226,_0x401b65){return new Promise(function(_0x336df9,_0x32a7a2){var _0x56d508=[];if(_[_0x4e98('0x2f')](_0x2ad226))return _0x336df9(_0x56d508);_0x162f51[_0x4e98('0x30')][_0x4e98('0x31')]({'attributes':['id',_0x4e98('0x32'),'IntervalId'],'raw':!![]})[_0x4e98('0x33')](function(_0x14f060){for(var _0x54a03d=0x0,_0x12b4a3=0x0;_0x54a03d<_0x2ad226[_0x4e98('0x25')];_0x54a03d++,_0x12b4a3=0x0){var _0x477762=_0x2ad226[_0x54a03d];var _0x4b4eda=[];var _0x284e4c=[];delete _0x477762['id'];if(_0x477762['interval']!==_0x4e98('0x34')){_0x477762[_0x4e98('0x35')]=[_0x477762[_0x4e98('0x32')]];}else{_0x477762[_0x4e98('0x35')]=_0x477762[_0x4e98('0x36')]?_[_0x4e98('0x37')](_[_0x4e98('0x38')](_0x14f060,{'IntervalId':_0x477762['IntervalId']}),'interval'):[];}_0x477762['context']=_0x344eb0['context'];_0x477762['exten']=_0x344eb0['exten'];if(_0x477762[_0x4e98('0x3')])_0x477762[_0x4e98('0x3')]=_0x477762['type'][_0x4e98('0x39')]();if(_0x344eb0[_0x4e98('0x3')]===_0x4e98('0x11')){if(_0x477762[_0x4e98('0x1d')]('tag')&&_0x477762[_0x4e98('0x3a')]&&_0x477762[_0x4e98('0x3a')]!=='--'){_0x4b4eda['push']({'type':_0x477762[_0x4e98('0x3')][_0x4e98('0x39')](),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x3b')+_0x477762['tag'],'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762[_0x4e98('0x35')][_0x4e98('0x25')]+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});}_0x4b4eda[_0x4e98('0xd')]({'type':_0x477762[_0x4e98('0x3')][_0x4e98('0x39')](),'app':_0x4e98('0x15'),'appdata':_0x4e98('0x3c')+(_0x477762[_0x4e98('0x3d')]?_0x4e98('0x3e')+_0x477762['callerID']+')':_0x4e98('0x3f')),'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762['intervals'][_0x4e98('0x25')]+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});}else{if(_0x477762['hasOwnProperty'](_0x4e98('0x40'))){if([_0x4e98('0x41'),_0x4e98('0x42')][_0x4e98('0x43')](_0x477762[_0x4e98('0x44')][_0x4e98('0x39')]())&&_0x477762[_0x4e98('0x45')]!==_0x4e98('0x46')){if(_0x477762[_0x4e98('0x40')]){_0x4b4eda[_0x4e98('0xd')]({'type':_0x477762[_0x4e98('0x3')][_0x4e98('0x39')](),'app':'ExecIf','appdata':_0x4e98('0x47'),'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762['intervals']['length']+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});_0x4b4eda['push']({'type':_0x477762['type'][_0x4e98('0x39')](),'app':_0x4e98('0x8'),'appdata':_0x4e98('0x48'),'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762[_0x4e98('0x35')][_0x4e98('0x25')]+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});}else{_0x4b4eda[_0x4e98('0xd')]({'type':_0x477762[_0x4e98('0x3')][_0x4e98('0x39')](),'app':'ExecIf','appdata':_0x4e98('0x49'),'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762[_0x4e98('0x35')][_0x4e98('0x25')]+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});_0x4b4eda[_0x4e98('0xd')]({'type':_0x477762['type'][_0x4e98('0x39')](),'app':'Set','appdata':_0x4e98('0x4a'),'context':_0x344eb0[_0x4e98('0x5')],'exten':_0x344eb0[_0x4e98('0x6')],'priority':_0x477762[_0x4e98('0x35')][_0x4e98('0x25')]+_0x401b65+_0x12b4a3++,'VoiceExtensionId':_0x344eb0['id']});}}}}for(var _0x99d171=0x0;_0x99d171<_0x477762[_0x4e98('0x35')][_0x4e98('0x25')];_0x99d171++){var _0x21f68c=_0x401b65+_0x477762[_0x4e98('0x35')]['length'];var _0x465337=_0x99d171===_0x477762[_0x4e98('0x35')][_0x4e98('0x25')]-0x1?_0x401b65+_0x4b4eda['length']+_0x284e4c['length']+0x2:_0x401b65+_0x99d171+0x1;_0x4b4eda[_0x4e98('0x4b')](_0x99d171,0x0,{'type':_0x344eb0[_0x4e98('0x3')],'app':_0x4e98('0x4c'),'appdata':_0x477762[_0x4e98('0x35')][_0x99d171]+'?'+_0x344eb0[_0x4e98('0x5')]+_0x4e98('0x4d')+_0x21f68c+':'+_0x344eb0[_0x4e98('0x5')]+',${EXTEN},'+_0x465337,'exten':_0x344eb0[_0x4e98('0x6')],'context':_0x344eb0[_0x4e98('0x5')],'priority':_0x401b65+_0x99d171,'VoiceExtensionId':_0x344eb0['id']});}if(_0x477762[_0x4e98('0x45')]===_0x4e98('0x4e'))_0x477762[_0x4e98('0x4f')]=_0x136673(_0x344eb0,_0x477762[_0x4e98('0x4f')]);_0x477762[_0x4e98('0x50')]=_0x4b4eda['length']?_['last'](_0x4b4eda)[_0x4e98('0x50')]+0x1:_0x401b65;_0x56d508=_[_0x4e98('0x51')](_0x56d508,_0x4b4eda,[_0x477762],_0x284e4c);_0x401b65=_[_0x4e98('0x52')](_0x56d508)['priority']+0x1;}return _0x336df9(_0x56d508);})[_0x4e98('0x53')](function(_0x22e7f2){_0x32a7a2(_0x22e7f2);});});}return _0x1357a2[_0x4e98('0x54')](_0x4e98('0x55'),attributes,{'tableName':_0x4e98('0x56'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x26629e){var _0x1d07c1=this[_0x4e98('0x57')]({'plain':!![]});var _0x3d0a4f=_0x1d07c1[_0x4e98('0x3')]===_0x4e98('0x11')?_0x26b60a(_0x1d07c1):_0x449b1e(_0x1d07c1);return _0x196683(_0x1d07c1,_0x26629e,_[_0x4e98('0x52')](_0x3d0a4f)['priority']+0x1)[_0x4e98('0x33')](function(_0x5a0258){var _0x110ceb=_[_0x4e98('0x51')](_0x3d0a4f,_0x5a0258);_0x110ceb[_0x4e98('0xd')]({'type':_0x1d07c1['type'],'app':_0x4e98('0x58'),'exten':_0x1d07c1[_0x4e98('0x6')],'context':_0x1d07c1[_0x4e98('0x5')],'priority':_['last'](_0x110ceb)['priority']+0x1,'VoiceExtensionId':_0x1d07c1['id']});return _0x110ceb;});}}});};