Built motion from commit 9d5c653a.|2.5.44
[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 _0x49f8=['callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','queue','includes','app','appType','$[${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','catch','define','VoiceExtension','voice_extensions','last','Hangup','lodash','./voiceExtension.attributes','models','type','Set','CDR(type)=','context','alias','NoOp','CDR(routeAlias)=','No\x20alias\x20set','inbound','push','CDR(routeid)=','exten','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','outbound','cutdigits','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','wav','trunk','timeout','options','url','length','param','split','phone','prefix','SIP','U(xcally-mixmonitor-context)','replace','join','Interval','interval','IntervalId','then','*,*,*,*','intervals','map','filter','toLowerCase','hasOwnProperty','tag','CDR(tag)='];(function(_0x252cbe,_0x54f1a1){var _0xf72165=function(_0x548288){while(--_0x548288){_0x252cbe['push'](_0x252cbe['shift']());}};_0xf72165(++_0x54f1a1);}(_0x49f8,0x105));var _0x849f=function(_0x5c6244,_0x112ab8){_0x5c6244=_0x5c6244-0x0;var _0x5800ce=_0x49f8[_0x5c6244];return _0x5800ce;};'use strict';var _=require(_0x849f('0x0'));var attributes=require(_0x849f('0x1'));module['exports']=function(_0x5a4c98){var _0x45d0ec=_0x5a4c98[_0x849f('0x2')];function _0x1bc1f6(_0x4a8e0a){var _0x50f17a=0x2;var _0x4a72fa=[{'type':_0x4a8e0a[_0x849f('0x3')],'app':_0x849f('0x4'),'appdata':_0x849f('0x5')+_0x4a8e0a[_0x849f('0x3')],'context':_0x4a8e0a[_0x849f('0x6')],'exten':_0x4a8e0a['exten'],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']},{'type':_0x4a8e0a['type'],'app':_0x4a8e0a[_0x849f('0x7')]?_0x849f('0x4'):_0x849f('0x8'),'appdata':_0x4a8e0a['alias']?_0x849f('0x9')+_0x4a8e0a[_0x849f('0x7')]:_0x849f('0xa'),'context':_0x4a8e0a['context'],'exten':_0x4a8e0a['exten'],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']}];if(_0x4a8e0a[_0x849f('0x3')]===_0x849f('0xb')){_0x4a72fa[_0x849f('0xc')]({'type':_0x849f('0xb'),'app':_0x849f('0x4'),'appdata':_0x849f('0xd')+_0x4a8e0a['id'],'context':_0x4a8e0a['context'],'exten':_0x4a8e0a[_0x849f('0xe')],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']});}_0x4a72fa['push']({'type':_0x4a8e0a['type'],'app':_0x849f('0x4'),'appdata':_0x849f('0xf'),'context':_0x4a8e0a[_0x849f('0x6')],'exten':_0x4a8e0a['exten'],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']},{'type':_0x4a8e0a[_0x849f('0x3')],'app':_0x849f('0x4'),'appdata':_0x849f('0x10'),'context':_0x4a8e0a[_0x849f('0x6')],'exten':_0x4a8e0a[_0x849f('0xe')],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']},{'type':_0x4a8e0a[_0x849f('0x3')],'app':_0x849f('0x4'),'appdata':_0x849f('0x11'),'context':_0x4a8e0a[_0x849f('0x6')],'exten':_0x4a8e0a[_0x849f('0xe')],'priority':_0x50f17a++,'VoiceExtensionId':_0x4a8e0a['id']});return _0x4a72fa;}function _0x51ea1b(_0x44f21f){var _0x4a0f3e=0x2;var _0x3e7127=[{'type':'outbound','app':_0x849f('0x4'),'appdata':'CDR(type)=outbound','context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x44f21f[_0x849f('0x7')]?'Set':_0x849f('0x8'),'appdata':_0x44f21f[_0x849f('0x7')]?'CDR(routeAlias)='+_0x44f21f[_0x849f('0x7')]:_0x849f('0xa'),'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':'CDR(destination)='+(_0x44f21f[_0x849f('0x13')]?_0x849f('0x14')+_0x44f21f['cutdigits']+'}':_0x849f('0x15')),'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':_0x849f('0xd')+_0x44f21f['id'],'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x16'),'appdata':_0x849f('0x17')+(_0x4a0f3e+0x2)+'):Goto('+(_0x4a0f3e+0x1)+')','context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':'outbound','app':_0x849f('0x4'),'appdata':_0x44f21f[_0x849f('0x13')]?_0x849f('0x18')+_0x44f21f[_0x849f('0x13')]+'}':_0x849f('0x19'),'context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':_0x849f('0xf'),'context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':_0x849f('0x10'),'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':'outbound','app':'Set','appdata':_0x849f('0x11'),'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':'outbound','app':_0x849f('0x4'),'appdata':'outboundrouteid='+_0x44f21f['id'],'context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']}];if(_0x44f21f['hasOwnProperty'](_0x849f('0x1a'))&&_0x44f21f['recordingFormat']!==_0x849f('0x1b')){_0x3e7127[_0x849f('0xc')]({'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':_0x849f('0x1c'),'context':_0x44f21f['context'],'exten':_0x44f21f[_0x849f('0xe')],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']},{'type':_0x849f('0x12'),'app':_0x849f('0x4'),'appdata':'_XCALLY_MIXMONITOR_FORMAT='+_0x44f21f['recordingFormat']||_0x849f('0x1d'),'context':_0x44f21f[_0x849f('0x6')],'exten':_0x44f21f['exten'],'priority':_0x4a0f3e++,'VoiceExtensionId':_0x44f21f['id']});}return _0x3e7127;}function _0x402e65(_0xc5403c,_0x183de4){var _0x375457=[{'name':_0x849f('0x1e'),'param':0x0},{'name':_0x849f('0x1f'),'param':0x1},{'name':_0x849f('0x20'),'param':0x2},{'name':_0x849f('0x21'),'param':0x3}];var _0x4227f1={};var _0x116453=_0x183de4['split'](',');var _0x23bedd=[];for(var _0x4e3c87=0x0;_0x4e3c87<_0x375457[_0x849f('0x22')];_0x4e3c87++){switch(_0x375457[_0x4e3c87]['name']){case'trunk':_0x4227f1[_0x849f('0x1e')]=_0x116453[_0x375457[_0x4e3c87][_0x849f('0x23')]][_0x849f('0x24')]('/')[0x1];_0x4227f1[_0x849f('0x25')]=_0x116453[_0x375457[_0x4e3c87][_0x849f('0x23')]][_0x849f('0x24')]('/')[0x2];_0x4227f1['prefix']=_0x4227f1['phone']?_0x4227f1[_0x849f('0x25')][_0x849f('0x24')]('$')[0x0]:undefined;_0x4227f1['phone']=_0xc5403c[_0x849f('0x13')]?(_0x4227f1[_0x849f('0x26')]||'')+'${EXTEN:'+_0xc5403c[_0x849f('0x13')]+'}':(_0x4227f1[_0x849f('0x26')]||'')+_0x849f('0x15');_0x23bedd[_0x375457[_0x4e3c87][_0x849f('0x23')]]=[_0x849f('0x27'),_0x4227f1[_0x849f('0x1e')],_0x4227f1['phone']]['join']('/');break;case _0x849f('0x20'):_0x4227f1[_0x849f('0x20')]=_0x116453[_0x375457[_0x4e3c87][_0x849f('0x23')]];if(_0xc5403c[_0x849f('0x1a')]!==_0x849f('0x1b')){if(_0x4227f1[_0x849f('0x20')]['indexOf'](_0x849f('0x28'))<0x0){_0x4227f1['options']+=_0x849f('0x28');}}else{_0x4227f1[_0x849f('0x20')]=_0x4227f1[_0x849f('0x20')][_0x849f('0x29')](_0x849f('0x28'),'');}_0x23bedd[_0x375457[_0x4e3c87][_0x849f('0x23')]]=_0x4227f1[_0x849f('0x20')];break;default:_0x23bedd[_0x375457[_0x4e3c87][_0x849f('0x23')]]=_0x116453[_0x375457[_0x4e3c87][_0x849f('0x23')]];}}return _0x23bedd[_0x849f('0x2a')](',');}function _0x398768(_0x3a3583,_0x1277fa,_0x78fcaf){return new Promise(function(_0x366c1a,_0x5d955b){var _0x1a81eb=[];if(_['isEmpty'](_0x1277fa))return _0x366c1a(_0x1a81eb);_0x45d0ec[_0x849f('0x2b')]['findAll']({'attributes':['id',_0x849f('0x2c'),_0x849f('0x2d')],'raw':!![]})[_0x849f('0x2e')](function(_0x25d02b){for(var _0x543ce1=0x0,_0x16a7ea=0x0;_0x543ce1<_0x1277fa[_0x849f('0x22')];_0x543ce1++,_0x16a7ea=0x0){var _0x4e0345=_0x1277fa[_0x543ce1];var _0x39236c=[];var _0x23b655=[];delete _0x4e0345['id'];if(_0x4e0345[_0x849f('0x2c')]!==_0x849f('0x2f')){_0x4e0345[_0x849f('0x30')]=[_0x4e0345[_0x849f('0x2c')]];}else{_0x4e0345[_0x849f('0x30')]=_0x4e0345[_0x849f('0x2d')]?_[_0x849f('0x31')](_[_0x849f('0x32')](_0x25d02b,{'IntervalId':_0x4e0345[_0x849f('0x2d')]}),_0x849f('0x2c')):[];}_0x4e0345['context']=_0x3a3583['context'];_0x4e0345[_0x849f('0xe')]=_0x3a3583[_0x849f('0xe')];if(_0x4e0345[_0x849f('0x3')])_0x4e0345[_0x849f('0x3')]=_0x4e0345[_0x849f('0x3')][_0x849f('0x33')]();if(_0x3a3583['type']===_0x849f('0x12')){if(_0x4e0345[_0x849f('0x34')](_0x849f('0x35'))&&_0x4e0345[_0x849f('0x35')]&&_0x4e0345[_0x849f('0x35')]!=='--'){_0x39236c[_0x849f('0xc')]({'type':_0x4e0345[_0x849f('0x3')]['toLowerCase'](),'app':_0x849f('0x4'),'appdata':_0x849f('0x36')+_0x4e0345[_0x849f('0x35')],'context':_0x3a3583['context'],'exten':_0x3a3583[_0x849f('0xe')],'priority':_0x4e0345[_0x849f('0x30')][_0x849f('0x22')]+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});}_0x39236c[_0x849f('0xc')]({'type':_0x4e0345[_0x849f('0x3')][_0x849f('0x33')](),'app':_0x849f('0x16'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):'+(_0x4e0345[_0x849f('0x37')]?_0x849f('0x38')+_0x4e0345['callerID']+')':_0x849f('0x39')),'context':_0x3a3583[_0x849f('0x6')],'exten':_0x3a3583['exten'],'priority':_0x4e0345['intervals']['length']+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});}else{if(_0x4e0345[_0x849f('0x34')]('answer')){if([_0x849f('0x3a'),'playback'][_0x849f('0x3b')](_0x4e0345[_0x849f('0x3c')][_0x849f('0x33')]())&&_0x4e0345[_0x849f('0x3d')]!=='custom'){if(_0x4e0345['answer']){_0x39236c[_0x849f('0xc')]({'type':_0x4e0345[_0x849f('0x3')][_0x849f('0x33')](),'app':'ExecIf','appdata':_0x849f('0x3e'),'context':_0x3a3583[_0x849f('0x6')],'exten':_0x3a3583[_0x849f('0xe')],'priority':_0x4e0345[_0x849f('0x30')][_0x849f('0x22')]+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});_0x39236c[_0x849f('0xc')]({'type':_0x4e0345[_0x849f('0x3')][_0x849f('0x33')](),'app':_0x849f('0x4'),'appdata':_0x849f('0x3f'),'context':_0x3a3583[_0x849f('0x6')],'exten':_0x3a3583[_0x849f('0xe')],'priority':_0x4e0345[_0x849f('0x30')][_0x849f('0x22')]+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});}else{_0x39236c[_0x849f('0xc')]({'type':_0x4e0345['type']['toLowerCase'](),'app':'ExecIf','appdata':_0x849f('0x40'),'context':_0x3a3583[_0x849f('0x6')],'exten':_0x3a3583['exten'],'priority':_0x4e0345['intervals'][_0x849f('0x22')]+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});_0x39236c[_0x849f('0xc')]({'type':_0x4e0345[_0x849f('0x3')]['toLowerCase'](),'app':_0x849f('0x4'),'appdata':_0x849f('0x41'),'context':_0x3a3583[_0x849f('0x6')],'exten':_0x3a3583['exten'],'priority':_0x4e0345['intervals']['length']+_0x78fcaf+_0x16a7ea++,'VoiceExtensionId':_0x3a3583['id']});}}}}for(var _0x1458a9=0x0;_0x1458a9<_0x4e0345[_0x849f('0x30')][_0x849f('0x22')];_0x1458a9++){var _0x22ae90=_0x78fcaf+_0x4e0345[_0x849f('0x30')][_0x849f('0x22')];var _0x51319a=_0x1458a9===_0x4e0345[_0x849f('0x30')][_0x849f('0x22')]-0x1?_0x78fcaf+_0x39236c[_0x849f('0x22')]+_0x23b655['length']+0x2:_0x78fcaf+_0x1458a9+0x1;_0x39236c[_0x849f('0x42')](_0x1458a9,0x0,{'type':_0x3a3583[_0x849f('0x3')],'app':_0x849f('0x43'),'appdata':_0x4e0345[_0x849f('0x30')][_0x1458a9]+'?'+_0x3a3583[_0x849f('0x6')]+_0x849f('0x44')+_0x22ae90+':'+_0x3a3583[_0x849f('0x6')]+_0x849f('0x44')+_0x51319a,'exten':_0x3a3583[_0x849f('0xe')],'context':_0x3a3583[_0x849f('0x6')],'priority':_0x78fcaf+_0x1458a9,'VoiceExtensionId':_0x3a3583['id']});}if(_0x4e0345[_0x849f('0x3d')]===_0x849f('0x45'))_0x4e0345[_0x849f('0x46')]=_0x402e65(_0x3a3583,_0x4e0345[_0x849f('0x46')]);_0x4e0345[_0x849f('0x47')]=_0x39236c[_0x849f('0x22')]?_['last'](_0x39236c)['priority']+0x1:_0x78fcaf;_0x1a81eb=_[_0x849f('0x48')](_0x1a81eb,_0x39236c,[_0x4e0345],_0x23b655);_0x78fcaf=_['last'](_0x1a81eb)[_0x849f('0x47')]+0x1;}return _0x366c1a(_0x1a81eb);})[_0x849f('0x49')](function(_0x54506c){_0x5d955b(_0x54506c);});});}return _0x5a4c98[_0x849f('0x4a')](_0x849f('0x4b'),attributes,{'tableName':_0x849f('0x4c'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x8850c2){var _0x26a41e=this['get']({'plain':!![]});var _0x5a19a=_0x26a41e[_0x849f('0x3')]===_0x849f('0x12')?_0x51ea1b(_0x26a41e):_0x1bc1f6(_0x26a41e);return _0x398768(_0x26a41e,_0x8850c2,_[_0x849f('0x4d')](_0x5a19a)['priority']+0x1)[_0x849f('0x2e')](function(_0x437b19){var _0x160d3=_[_0x849f('0x48')](_0x5a19a,_0x437b19);_0x160d3[_0x849f('0xc')]({'type':_0x26a41e['type'],'app':_0x849f('0x4e'),'exten':_0x26a41e[_0x849f('0xe')],'context':_0x26a41e['context'],'priority':_['last'](_0x160d3)[_0x849f('0x47')]+0x1,'VoiceExtensionId':_0x26a41e['id']});return _0x160d3;});}}});};