2fe3ff4e8db86891103b464e02ebedcde0eee516
[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 _0x885a=['prefix','phone','${EXTEN:','SIP','trunk','join','indexOf','U(xcally-mixmonitor-context)','replace','isEmpty','findAll','interval','IntervalId','*,*,*,*','intervals','map','filter','toLowerCase','tag','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','queue','playback','includes','app','appType','custom','answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','GotoIfTime',',${EXTEN},','appdata','agi','XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','last','priority','catch','define','VoiceExtension','voice_extensions','get','then','concat','Hangup','./voiceExtension.attributes','exports','type','Set','context','exten','alias','NoOp','CDR(routeAlias)=','No\x20alias\x20set','inbound','CDR(routeid)=','push','XCALLY-MOTION-ANSWER=0','MONITOR_OPTIONS=ab','outbound','CDR(type)=outbound','cutdigits','${EXTEN}','ExecIf','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','XCALLY-MOTION-PROGRESS=0','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','wav','options','url','split','length','name','param'];(function(_0x3faa7f,_0x14c60c){var _0x5a2e11=function(_0x1bd4a7){while(--_0x1bd4a7){_0x3faa7f['push'](_0x3faa7f['shift']());}};_0x5a2e11(++_0x14c60c);}(_0x885a,0x180));var _0xa885=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x885a[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var attributes=require(_0xa885('0x0'));module[_0xa885('0x1')]=function(_0x35456c){var _0x2e4bc8=_0x35456c['models'];function _0xcf0656(_0x1c41b5){var _0x2386ec=0x2;var _0x106e16=[{'type':_0x1c41b5[_0xa885('0x2')],'app':_0xa885('0x3'),'appdata':'CDR(type)='+_0x1c41b5[_0xa885('0x2')],'context':_0x1c41b5[_0xa885('0x4')],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']},{'type':_0x1c41b5['type'],'app':_0x1c41b5[_0xa885('0x6')]?_0xa885('0x3'):_0xa885('0x7'),'appdata':_0x1c41b5['alias']?_0xa885('0x8')+_0x1c41b5[_0xa885('0x6')]:_0xa885('0x9'),'context':_0x1c41b5[_0xa885('0x4')],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']}];if(_0x1c41b5[_0xa885('0x2')]===_0xa885('0xa')){_0x106e16['push']({'type':_0xa885('0xa'),'app':_0xa885('0x3'),'appdata':_0xa885('0xb')+_0x1c41b5['id'],'context':_0x1c41b5[_0xa885('0x4')],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']});}_0x106e16[_0xa885('0xc')]({'type':_0x1c41b5[_0xa885('0x2')],'app':'Set','appdata':_0xa885('0xd'),'context':_0x1c41b5[_0xa885('0x4')],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']},{'type':_0x1c41b5[_0xa885('0x2')],'app':_0xa885('0x3'),'appdata':'XCALLY-MOTION-PROGRESS=0','context':_0x1c41b5[_0xa885('0x4')],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']},{'type':_0x1c41b5['type'],'app':_0xa885('0x3'),'appdata':_0xa885('0xe'),'context':_0x1c41b5['context'],'exten':_0x1c41b5[_0xa885('0x5')],'priority':_0x2386ec++,'VoiceExtensionId':_0x1c41b5['id']});return _0x106e16;}function _0x41b3de(_0x5eec42){var _0x20a206=0x2;var _0x543e7a=[{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':_0xa885('0x10'),'context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':'outbound','app':_0x5eec42[_0xa885('0x6')]?_0xa885('0x3'):_0xa885('0x7'),'appdata':_0x5eec42['alias']?_0xa885('0x8')+_0x5eec42[_0xa885('0x6')]:_0xa885('0x9'),'context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':'CDR(destination)='+(_0x5eec42[_0xa885('0x11')]?'${EXTEN:'+_0x5eec42[_0xa885('0x11')]+'}':_0xa885('0x12')),'context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':'CDR(routeid)='+_0x5eec42['id'],'context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':'outbound','app':_0xa885('0x13'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x20a206+0x2)+_0xa885('0x14')+(_0x20a206+0x1)+')','context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':_0x5eec42[_0xa885('0x11')]?_0xa885('0x15')+_0x5eec42[_0xa885('0x11')]+'}':_0xa885('0x16'),'context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42['exten'],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':'outbound','app':'Set','appdata':'XCALLY-MOTION-ANSWER=0','context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':_0xa885('0x17'),'context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42['exten'],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':'Set','appdata':_0xa885('0xe'),'context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':'outbound','app':_0xa885('0x3'),'appdata':_0xa885('0x18')+_0x5eec42['id'],'context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42['exten'],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']}];if(_0x5eec42[_0xa885('0x19')](_0xa885('0x1a'))&&_0x5eec42['recordingFormat']!==_0xa885('0x1b')){_0x543e7a['push']({'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':_0xa885('0x1c'),'context':_0x5eec42['context'],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']},{'type':_0xa885('0xf'),'app':_0xa885('0x3'),'appdata':'_XCALLY_MIXMONITOR_FORMAT='+_0x5eec42[_0xa885('0x1a')]||_0xa885('0x1d'),'context':_0x5eec42[_0xa885('0x4')],'exten':_0x5eec42[_0xa885('0x5')],'priority':_0x20a206++,'VoiceExtensionId':_0x5eec42['id']});}return _0x543e7a;}function _0x3995f0(_0x209758,_0x2a00d4){var _0x457b97=[{'name':'trunk','param':0x0},{'name':'timeout','param':0x1},{'name':_0xa885('0x1e'),'param':0x2},{'name':_0xa885('0x1f'),'param':0x3}];var _0x2e40b6={};var _0x563b5f=_0x2a00d4[_0xa885('0x20')](',');var _0x18d083=[];for(var _0x404afc=0x0;_0x404afc<_0x457b97[_0xa885('0x21')];_0x404afc++){switch(_0x457b97[_0x404afc][_0xa885('0x22')]){case'trunk':_0x2e40b6['trunk']=_0x563b5f[_0x457b97[_0x404afc][_0xa885('0x23')]]['split']('/')[0x1];_0x2e40b6['phone']=_0x563b5f[_0x457b97[_0x404afc][_0xa885('0x23')]]['split']('/')[0x2];_0x2e40b6[_0xa885('0x24')]=_0x2e40b6[_0xa885('0x25')]?_0x2e40b6[_0xa885('0x25')][_0xa885('0x20')]('$')[0x0]:undefined;_0x2e40b6[_0xa885('0x25')]=_0x209758[_0xa885('0x11')]?(_0x2e40b6[_0xa885('0x24')]||'')+_0xa885('0x26')+_0x209758[_0xa885('0x11')]+'}':(_0x2e40b6[_0xa885('0x24')]||'')+'${EXTEN}';_0x18d083[_0x457b97[_0x404afc][_0xa885('0x23')]]=[_0xa885('0x27'),_0x2e40b6[_0xa885('0x28')],_0x2e40b6[_0xa885('0x25')]][_0xa885('0x29')]('/');break;case'options':_0x2e40b6['options']=_0x563b5f[_0x457b97[_0x404afc][_0xa885('0x23')]];if(_0x209758[_0xa885('0x1a')]!==_0xa885('0x1b')){if(_0x2e40b6[_0xa885('0x1e')][_0xa885('0x2a')]('U(xcally-mixmonitor-context)')<0x0){_0x2e40b6[_0xa885('0x1e')]+=_0xa885('0x2b');}}else{_0x2e40b6['options']=_0x2e40b6['options'][_0xa885('0x2c')](_0xa885('0x2b'),'');}_0x18d083[_0x457b97[_0x404afc]['param']]=_0x2e40b6['options'];break;default:_0x18d083[_0x457b97[_0x404afc][_0xa885('0x23')]]=_0x563b5f[_0x457b97[_0x404afc][_0xa885('0x23')]];}}return _0x18d083[_0xa885('0x29')](',');}function _0x5a40d(_0xd9e3f7,_0x13555d,_0x369952){return new Promise(function(_0xb4660d,_0x44469c){var _0x3dcf63=[];if(_[_0xa885('0x2d')](_0x13555d))return _0xb4660d(_0x3dcf63);_0x2e4bc8['Interval'][_0xa885('0x2e')]({'attributes':['id',_0xa885('0x2f'),_0xa885('0x30')],'raw':!![]})['then'](function(_0x47f3b4){for(var _0x187bc5=0x0,_0x28d79d=0x0;_0x187bc5<_0x13555d[_0xa885('0x21')];_0x187bc5++,_0x28d79d=0x0){var _0x5e33be=_0x13555d[_0x187bc5];var _0xdb7929=[];var _0x55635b=[];delete _0x5e33be['id'];if(_0x5e33be[_0xa885('0x2f')]!==_0xa885('0x31')){_0x5e33be['intervals']=[_0x5e33be[_0xa885('0x2f')]];}else{_0x5e33be[_0xa885('0x32')]=_0x5e33be[_0xa885('0x30')]?_[_0xa885('0x33')](_[_0xa885('0x34')](_0x47f3b4,{'IntervalId':_0x5e33be['IntervalId']}),_0xa885('0x2f')):[];}_0x5e33be[_0xa885('0x4')]=_0xd9e3f7[_0xa885('0x4')];_0x5e33be['exten']=_0xd9e3f7['exten'];if(_0x5e33be['type'])_0x5e33be[_0xa885('0x2')]=_0x5e33be[_0xa885('0x2')][_0xa885('0x35')]();if(_0xd9e3f7[_0xa885('0x2')]===_0xa885('0xf')){if(_0x5e33be[_0xa885('0x19')](_0xa885('0x36'))&&_0x5e33be[_0xa885('0x36')]&&_0x5e33be[_0xa885('0x36')]!=='--'){_0xdb7929[_0xa885('0xc')]({'type':_0x5e33be[_0xa885('0x2')]['toLowerCase'](),'app':'Set','appdata':'CDR(tag)='+_0x5e33be[_0xa885('0x36')],'context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7[_0xa885('0x5')],'priority':_0x5e33be[_0xa885('0x32')][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});}_0xdb7929[_0xa885('0xc')]({'type':_0x5e33be[_0xa885('0x2')]['toLowerCase'](),'app':_0xa885('0x13'),'appdata':_0xa885('0x37')+(_0x5e33be[_0xa885('0x38')]?_0xa885('0x39')+_0x5e33be[_0xa885('0x38')]+')':_0xa885('0x3a')),'context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7['exten'],'priority':_0x5e33be[_0xa885('0x32')][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});}else{if(_0x5e33be[_0xa885('0x19')]('answer')){if([_0xa885('0x3b'),_0xa885('0x3c')][_0xa885('0x3d')](_0x5e33be[_0xa885('0x3e')][_0xa885('0x35')]())&&_0x5e33be[_0xa885('0x3f')]!==_0xa885('0x40')){if(_0x5e33be[_0xa885('0x41')]){_0xdb7929['push']({'type':_0x5e33be[_0xa885('0x2')][_0xa885('0x35')](),'app':_0xa885('0x13'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7[_0xa885('0x5')],'priority':_0x5e33be[_0xa885('0x32')][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});_0xdb7929[_0xa885('0xc')]({'type':_0x5e33be[_0xa885('0x2')]['toLowerCase'](),'app':_0xa885('0x3'),'appdata':_0xa885('0x42'),'context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7['exten'],'priority':_0x5e33be[_0xa885('0x32')][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});}else{_0xdb7929[_0xa885('0xc')]({'type':_0x5e33be[_0xa885('0x2')][_0xa885('0x35')](),'app':_0xa885('0x13'),'appdata':_0xa885('0x43'),'context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7[_0xa885('0x5')],'priority':_0x5e33be['intervals'][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});_0xdb7929[_0xa885('0xc')]({'type':_0x5e33be['type']['toLowerCase'](),'app':_0xa885('0x3'),'appdata':_0xa885('0x44'),'context':_0xd9e3f7['context'],'exten':_0xd9e3f7[_0xa885('0x5')],'priority':_0x5e33be[_0xa885('0x32')][_0xa885('0x21')]+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});}}}}for(var _0x35c128=0x0;_0x35c128<_0x5e33be[_0xa885('0x32')][_0xa885('0x21')];_0x35c128++){var _0x1101c3=_0x369952+_0x5e33be['intervals'][_0xa885('0x21')];var _0x318565=_0x35c128===_0x5e33be['intervals'][_0xa885('0x21')]-0x1?_0x369952+_0xdb7929['length']+_0x55635b[_0xa885('0x21')]+0x2:_0x369952+_0x35c128+0x1;_0xdb7929['splice'](_0x35c128,0x0,{'type':_0xd9e3f7[_0xa885('0x2')],'app':_0xa885('0x45'),'appdata':_0x5e33be[_0xa885('0x32')][_0x35c128]+'?'+_0xd9e3f7[_0xa885('0x4')]+',${EXTEN},'+_0x1101c3+':'+_0xd9e3f7[_0xa885('0x4')]+_0xa885('0x46')+_0x318565,'exten':_0xd9e3f7[_0xa885('0x5')],'context':_0xd9e3f7['context'],'priority':_0x369952+_0x35c128,'VoiceExtensionId':_0xd9e3f7['id']});}if(_0x5e33be[_0xa885('0x3f')]==='outboundDial'){_0x5e33be[_0xa885('0x47')]=_0x3995f0(_0xd9e3f7,_0x5e33be[_0xa885('0x47')]);}if(_0x5e33be['appType']===_0xa885('0x48')){_0xdb7929['push']({'type':_0x5e33be[_0xa885('0x2')][_0xa885('0x35')](),'app':'Set','appdata':_0xa885('0x49'),'context':_0xd9e3f7[_0xa885('0x4')],'exten':_0xd9e3f7[_0xa885('0x5')],'priority':_0x5e33be[_0xa885('0x32')]['length']+_0x369952+_0x28d79d++,'VoiceExtensionId':_0xd9e3f7['id']});}_0x5e33be['priority']=_0xdb7929[_0xa885('0x21')]?_[_0xa885('0x4a')](_0xdb7929)['priority']+0x1:_0x369952;_0x3dcf63=_['concat'](_0x3dcf63,_0xdb7929,[_0x5e33be],_0x55635b);_0x369952=_[_0xa885('0x4a')](_0x3dcf63)[_0xa885('0x4b')]+0x1;}return _0xb4660d(_0x3dcf63);})[_0xa885('0x4c')](function(_0x262a0c){_0x44469c(_0x262a0c);});});}return _0x35456c[_0xa885('0x4d')](_0xa885('0x4e'),attributes,{'tableName':_0xa885('0x4f'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x257632){var _0x1e5117=this[_0xa885('0x50')]({'plain':!![]});var _0x1fe57b=_0x1e5117['type']===_0xa885('0xf')?_0x41b3de(_0x1e5117):_0xcf0656(_0x1e5117);return _0x5a40d(_0x1e5117,_0x257632,_[_0xa885('0x4a')](_0x1fe57b)[_0xa885('0x4b')]+0x1)[_0xa885('0x51')](function(_0x1da286){var _0x5cc2cf=_[_0xa885('0x52')](_0x1fe57b,_0x1da286);_0x5cc2cf['push']({'type':_0x1e5117['type'],'app':_0xa885('0x53'),'exten':_0x1e5117[_0xa885('0x5')],'context':_0x1e5117['context'],'priority':_['last'](_0x5cc2cf)[_0xa885('0x4b')]+0x1,'VoiceExtensionId':_0x1e5117['id']});return _0x5cc2cf;});}}});};