2bfa0afc7ceb8282296a632405af1686e893243f
[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 _0xf185=['$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','Set(CALLERID(all)=','callerID','NoOp(No\x20number\x20available)','queue','playback','includes','app','appType','custom','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','outboundDial','appdata','priority','last','concat','catch','define','VoiceExtension','voice_extensions','get','Hangup','lodash','exports','models','type','Set','CDR(type)=','context','exten','alias','NoOp','No\x20alias\x20set','inbound','CDR(routeid)=','push','XCALLY-MOTION-ANSWER=0','MONITOR_OPTIONS=ab','outbound','CDR(type)=outbound','CDR(destination)=','cutdigits','${EXTEN}','ExecIf','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','XCALLY-MOTION-PROGRESS=0','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','options','url','split','length','name','trunk','param','phone','prefix','SIP','join','indexOf','U(xcally-mixmonitor-context)','replace','isEmpty','Interval','findAll','interval','IntervalId','then','*,*,*,*','map','toLowerCase','tag','intervals'];(function(_0x4924ae,_0x1dd735){var _0x2238e4=function(_0x48dc88){while(--_0x48dc88){_0x4924ae['push'](_0x4924ae['shift']());}};_0x2238e4(++_0x1dd735);}(_0xf185,0x1be));var _0x5f18=function(_0x21656a,_0x2bce5e){_0x21656a=_0x21656a-0x0;var _0x29ce5a=_0xf185[_0x21656a];return _0x29ce5a;};'use strict';var _=require(_0x5f18('0x0'));var attributes=require('./voiceExtension.attributes');module[_0x5f18('0x1')]=function(_0x34335b){var _0x26ab30=_0x34335b[_0x5f18('0x2')];function _0x40e868(_0x12abae){var _0x529b25=0x2;var _0x33d44f=[{'type':_0x12abae[_0x5f18('0x3')],'app':_0x5f18('0x4'),'appdata':_0x5f18('0x5')+_0x12abae['type'],'context':_0x12abae[_0x5f18('0x6')],'exten':_0x12abae[_0x5f18('0x7')],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']},{'type':_0x12abae['type'],'app':_0x12abae[_0x5f18('0x8')]?'Set':_0x5f18('0x9'),'appdata':_0x12abae[_0x5f18('0x8')]?'CDR(routeAlias)='+_0x12abae[_0x5f18('0x8')]:_0x5f18('0xa'),'context':_0x12abae['context'],'exten':_0x12abae[_0x5f18('0x7')],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']}];if(_0x12abae[_0x5f18('0x3')]==='inbound'){_0x33d44f['push']({'type':_0x5f18('0xb'),'app':_0x5f18('0x4'),'appdata':_0x5f18('0xc')+_0x12abae['id'],'context':_0x12abae['context'],'exten':_0x12abae[_0x5f18('0x7')],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']});}_0x33d44f[_0x5f18('0xd')]({'type':_0x12abae[_0x5f18('0x3')],'app':_0x5f18('0x4'),'appdata':_0x5f18('0xe'),'context':_0x12abae[_0x5f18('0x6')],'exten':_0x12abae[_0x5f18('0x7')],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']},{'type':_0x12abae[_0x5f18('0x3')],'app':_0x5f18('0x4'),'appdata':'XCALLY-MOTION-PROGRESS=0','context':_0x12abae[_0x5f18('0x6')],'exten':_0x12abae['exten'],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']},{'type':_0x12abae['type'],'app':_0x5f18('0x4'),'appdata':_0x5f18('0xf'),'context':_0x12abae[_0x5f18('0x6')],'exten':_0x12abae[_0x5f18('0x7')],'priority':_0x529b25++,'VoiceExtensionId':_0x12abae['id']});return _0x33d44f;}function _0x337ec1(_0x506f4e){var _0x3d61bf=0x2;var _0x45cc93=[{'type':_0x5f18('0x10'),'app':_0x5f18('0x4'),'appdata':_0x5f18('0x11'),'context':_0x506f4e['context'],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':_0x5f18('0x10'),'app':_0x506f4e[_0x5f18('0x8')]?'Set':_0x5f18('0x9'),'appdata':_0x506f4e[_0x5f18('0x8')]?'CDR(routeAlias)='+_0x506f4e['alias']:_0x5f18('0xa'),'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':_0x5f18('0x10'),'app':_0x5f18('0x4'),'appdata':_0x5f18('0x12')+(_0x506f4e['cutdigits']?'${EXTEN:'+_0x506f4e[_0x5f18('0x13')]+'}':_0x5f18('0x14')),'context':_0x506f4e['context'],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':'outbound','app':_0x5f18('0x4'),'appdata':'CDR(routeid)='+_0x506f4e['id'],'context':_0x506f4e['context'],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':'outbound','app':_0x5f18('0x15'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x3d61bf+0x2)+_0x5f18('0x16')+(_0x3d61bf+0x1)+')','context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':_0x5f18('0x10'),'app':'Set','appdata':_0x506f4e[_0x5f18('0x13')]?_0x5f18('0x17')+_0x506f4e[_0x5f18('0x13')]+'}':_0x5f18('0x18'),'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':_0x5f18('0x10'),'app':_0x5f18('0x4'),'appdata':_0x5f18('0xe'),'context':_0x506f4e['context'],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':'outbound','app':'Set','appdata':_0x5f18('0x19'),'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':'outbound','app':'Set','appdata':_0x5f18('0xf'),'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':'outbound','app':_0x5f18('0x4'),'appdata':_0x5f18('0x1a')+_0x506f4e['id'],'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e['exten'],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']}];if(_0x506f4e[_0x5f18('0x1b')](_0x5f18('0x1c'))&&_0x506f4e[_0x5f18('0x1c')]!==_0x5f18('0x1d')){_0x45cc93['push']({'type':_0x5f18('0x10'),'app':'Set','appdata':_0x5f18('0x1e'),'context':_0x506f4e[_0x5f18('0x6')],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']},{'type':_0x5f18('0x10'),'app':_0x5f18('0x4'),'appdata':_0x5f18('0x1f')+_0x506f4e[_0x5f18('0x1c')]||_0x5f18('0x20'),'context':_0x506f4e['context'],'exten':_0x506f4e[_0x5f18('0x7')],'priority':_0x3d61bf++,'VoiceExtensionId':_0x506f4e['id']});}return _0x45cc93;}function _0x548e79(_0x186e65,_0x28cfe2){var _0x224b45=[{'name':'trunk','param':0x0},{'name':'timeout','param':0x1},{'name':_0x5f18('0x21'),'param':0x2},{'name':_0x5f18('0x22'),'param':0x3}];var _0x24fa0f={};var _0x34a15b=_0x28cfe2[_0x5f18('0x23')](',');var _0x2fd94a=[];for(var _0x483217=0x0;_0x483217<_0x224b45[_0x5f18('0x24')];_0x483217++){switch(_0x224b45[_0x483217][_0x5f18('0x25')]){case _0x5f18('0x26'):_0x24fa0f['trunk']=_0x34a15b[_0x224b45[_0x483217][_0x5f18('0x27')]]['split']('/')[0x1];_0x24fa0f['phone']=_0x34a15b[_0x224b45[_0x483217][_0x5f18('0x27')]][_0x5f18('0x23')]('/')[0x2];_0x24fa0f['prefix']=_0x24fa0f[_0x5f18('0x28')]?_0x24fa0f['phone'][_0x5f18('0x23')]('$')[0x0]:undefined;_0x24fa0f[_0x5f18('0x28')]=_0x186e65[_0x5f18('0x13')]?(_0x24fa0f[_0x5f18('0x29')]||'')+'${EXTEN:'+_0x186e65[_0x5f18('0x13')]+'}':(_0x24fa0f[_0x5f18('0x29')]||'')+_0x5f18('0x14');_0x2fd94a[_0x224b45[_0x483217]['param']]=[_0x5f18('0x2a'),_0x24fa0f[_0x5f18('0x26')],_0x24fa0f[_0x5f18('0x28')]][_0x5f18('0x2b')]('/');break;case'options':_0x24fa0f[_0x5f18('0x21')]=_0x34a15b[_0x224b45[_0x483217][_0x5f18('0x27')]];if(_0x186e65[_0x5f18('0x1c')]!=='none'){if(_0x24fa0f['options'][_0x5f18('0x2c')](_0x5f18('0x2d'))<0x0){_0x24fa0f[_0x5f18('0x21')]+=_0x5f18('0x2d');}}else{_0x24fa0f[_0x5f18('0x21')]=_0x24fa0f['options'][_0x5f18('0x2e')](_0x5f18('0x2d'),'');}_0x2fd94a[_0x224b45[_0x483217][_0x5f18('0x27')]]=_0x24fa0f[_0x5f18('0x21')];break;default:_0x2fd94a[_0x224b45[_0x483217]['param']]=_0x34a15b[_0x224b45[_0x483217][_0x5f18('0x27')]];}}return _0x2fd94a[_0x5f18('0x2b')](',');}function _0x4a0c33(_0xec2527,_0x61fe1c,_0xdaf299){return new Promise(function(_0x4bd555,_0xf468cf){var _0x41685b=[];if(_[_0x5f18('0x2f')](_0x61fe1c))return _0x4bd555(_0x41685b);_0x26ab30[_0x5f18('0x30')][_0x5f18('0x31')]({'attributes':['id',_0x5f18('0x32'),_0x5f18('0x33')],'raw':!![]})[_0x5f18('0x34')](function(_0x443910){for(var _0x364455=0x0,_0x1a7098=0x0;_0x364455<_0x61fe1c['length'];_0x364455++,_0x1a7098=0x0){var _0x51695f=_0x61fe1c[_0x364455];var _0x3771b0=[];var _0x267357=[];delete _0x51695f['id'];if(_0x51695f[_0x5f18('0x32')]!==_0x5f18('0x35')){_0x51695f['intervals']=[_0x51695f[_0x5f18('0x32')]];}else{_0x51695f['intervals']=_0x51695f[_0x5f18('0x33')]?_[_0x5f18('0x36')](_['filter'](_0x443910,{'IntervalId':_0x51695f[_0x5f18('0x33')]}),_0x5f18('0x32')):[];}_0x51695f[_0x5f18('0x6')]=_0xec2527[_0x5f18('0x6')];_0x51695f[_0x5f18('0x7')]=_0xec2527[_0x5f18('0x7')];if(_0x51695f[_0x5f18('0x3')])_0x51695f['type']=_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')]();if(_0xec2527[_0x5f18('0x3')]===_0x5f18('0x10')){if(_0x51695f[_0x5f18('0x1b')](_0x5f18('0x38'))&&_0x51695f['tag']&&_0x51695f['tag']!=='--'){_0x3771b0[_0x5f18('0xd')]({'type':_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')](),'app':_0x5f18('0x4'),'appdata':'CDR(tag)='+_0x51695f[_0x5f18('0x38')],'context':_0xec2527[_0x5f18('0x6')],'exten':_0xec2527[_0x5f18('0x7')],'priority':_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});}_0x3771b0[_0x5f18('0xd')]({'type':_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')](),'app':_0x5f18('0x15'),'appdata':_0x5f18('0x3a')+(_0x51695f['callerID']?_0x5f18('0x3b')+_0x51695f[_0x5f18('0x3c')]+')':_0x5f18('0x3d')),'context':_0xec2527['context'],'exten':_0xec2527[_0x5f18('0x7')],'priority':_0x51695f['intervals'][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});}else{if(_0x51695f[_0x5f18('0x1b')]('answer')){if([_0x5f18('0x3e'),_0x5f18('0x3f')][_0x5f18('0x40')](_0x51695f[_0x5f18('0x41')][_0x5f18('0x37')]())&&_0x51695f[_0x5f18('0x42')]!==_0x5f18('0x43')){if(_0x51695f['answer']){_0x3771b0['push']({'type':_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')](),'app':_0x5f18('0x15'),'appdata':_0x5f18('0x44'),'context':_0xec2527['context'],'exten':_0xec2527[_0x5f18('0x7')],'priority':_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});_0x3771b0[_0x5f18('0xd')]({'type':_0x51695f[_0x5f18('0x3')]['toLowerCase'](),'app':_0x5f18('0x4'),'appdata':_0x5f18('0x45'),'context':_0xec2527['context'],'exten':_0xec2527[_0x5f18('0x7')],'priority':_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});}else{_0x3771b0[_0x5f18('0xd')]({'type':_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')](),'app':'ExecIf','appdata':'$[${XCALLY-MOTION-PROGRESS}=0]?Progress','context':_0xec2527['context'],'exten':_0xec2527['exten'],'priority':_0x51695f['intervals'][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});_0x3771b0[_0x5f18('0xd')]({'type':_0x51695f[_0x5f18('0x3')][_0x5f18('0x37')](),'app':_0x5f18('0x4'),'appdata':_0x5f18('0x46'),'context':_0xec2527[_0x5f18('0x6')],'exten':_0xec2527[_0x5f18('0x7')],'priority':_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')]+_0xdaf299+_0x1a7098++,'VoiceExtensionId':_0xec2527['id']});}}}}for(var _0x34d8a8=0x0;_0x34d8a8<_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')];_0x34d8a8++){var _0x591101=_0xdaf299+_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')];var _0x13effa=_0x34d8a8===_0x51695f[_0x5f18('0x39')][_0x5f18('0x24')]-0x1?_0xdaf299+_0x3771b0[_0x5f18('0x24')]+_0x267357[_0x5f18('0x24')]+0x2:_0xdaf299+_0x34d8a8+0x1;_0x3771b0[_0x5f18('0x47')](_0x34d8a8,0x0,{'type':_0xec2527[_0x5f18('0x3')],'app':'GotoIfTime','appdata':_0x51695f[_0x5f18('0x39')][_0x34d8a8]+'?'+_0xec2527[_0x5f18('0x6')]+_0x5f18('0x48')+_0x591101+':'+_0xec2527['context']+_0x5f18('0x48')+_0x13effa,'exten':_0xec2527[_0x5f18('0x7')],'context':_0xec2527['context'],'priority':_0xdaf299+_0x34d8a8,'VoiceExtensionId':_0xec2527['id']});}if(_0x51695f[_0x5f18('0x42')]===_0x5f18('0x49'))_0x51695f[_0x5f18('0x4a')]=_0x548e79(_0xec2527,_0x51695f[_0x5f18('0x4a')]);_0x51695f[_0x5f18('0x4b')]=_0x3771b0[_0x5f18('0x24')]?_[_0x5f18('0x4c')](_0x3771b0)[_0x5f18('0x4b')]+0x1:_0xdaf299;_0x41685b=_[_0x5f18('0x4d')](_0x41685b,_0x3771b0,[_0x51695f],_0x267357);_0xdaf299=_[_0x5f18('0x4c')](_0x41685b)[_0x5f18('0x4b')]+0x1;}return _0x4bd555(_0x41685b);})[_0x5f18('0x4e')](function(_0x22e9e7){_0xf468cf(_0x22e9e7);});});}return _0x34335b[_0x5f18('0x4f')](_0x5f18('0x50'),attributes,{'tableName':_0x5f18('0x51'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x4f8e6e){var _0x48536b=this[_0x5f18('0x52')]({'plain':!![]});var _0x3eac7c=_0x48536b['type']===_0x5f18('0x10')?_0x337ec1(_0x48536b):_0x40e868(_0x48536b);return _0x4a0c33(_0x48536b,_0x4f8e6e,_['last'](_0x3eac7c)['priority']+0x1)[_0x5f18('0x34')](function(_0x5b8591){var _0x5b1580=_[_0x5f18('0x4d')](_0x3eac7c,_0x5b8591);_0x5b1580[_0x5f18('0xd')]({'type':_0x48536b[_0x5f18('0x3')],'app':_0x5f18('0x53'),'exten':_0x48536b[_0x5f18('0x7')],'context':_0x48536b[_0x5f18('0x6')],'priority':_['last'](_0x5b1580)[_0x5f18('0x4b')]+0x1,'VoiceExtensionId':_0x48536b['id']});return _0x5b1580;});}}});};