24f4ae43240dcbdceb893281af141a77bde40d18
[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 _0x8ff5=['intervals','filter','toLowerCase','tag','CDR(tag)=','length','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','Set(CALLERID(all)=','callerID','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','splice','GotoIfTime',',${EXTEN},','outboundDial','appdata','agi','last','priority','concat','catch','define','VoiceExtension','get','lodash','./voiceExtension.attributes','exports','models','type','Set','context','exten','alias','CDR(routeAlias)=','push','inbound','CDR(routeid)=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','CDR(type)=outbound','outbound','NoOp','No\x20alias\x20set','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','trunk','timeout','options','url','name','param','split','phone','prefix','SIP','indexOf','U(xcally-mixmonitor-context)','replace','join','Interval','findAll','interval','IntervalId','then','*,*,*,*'];(function(_0x5354d8,_0x3f1060){var _0x346a36=function(_0x26b27f){while(--_0x26b27f){_0x5354d8['push'](_0x5354d8['shift']());}};_0x346a36(++_0x3f1060);}(_0x8ff5,0x78));var _0x58ff=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0x8ff5[_0x199572];return _0x13cfa3;};'use strict';var _=require(_0x58ff('0x0'));var attributes=require(_0x58ff('0x1'));module[_0x58ff('0x2')]=function(_0x477887){var _0x415e82=_0x477887[_0x58ff('0x3')];function _0x50d564(_0x1009be){var _0x75f931=0x2;var _0x4d0046=[{'type':_0x1009be[_0x58ff('0x4')],'app':_0x58ff('0x5'),'appdata':'CDR(type)='+_0x1009be[_0x58ff('0x4')],'context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be[_0x58ff('0x7')],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']},{'type':_0x1009be[_0x58ff('0x4')],'app':_0x1009be[_0x58ff('0x8')]?'Set':'NoOp','appdata':_0x1009be[_0x58ff('0x8')]?_0x58ff('0x9')+_0x1009be[_0x58ff('0x8')]:'No\x20alias\x20set','context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be['exten'],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']}];if(_0x1009be['type']==='inbound'){_0x4d0046[_0x58ff('0xa')]({'type':_0x58ff('0xb'),'app':_0x58ff('0x5'),'appdata':_0x58ff('0xc')+_0x1009be['id'],'context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be[_0x58ff('0x7')],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']});}_0x4d0046['push']({'type':_0x1009be['type'],'app':_0x58ff('0x5'),'appdata':_0x58ff('0xd'),'context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be['exten'],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']},{'type':_0x1009be[_0x58ff('0x4')],'app':_0x58ff('0x5'),'appdata':_0x58ff('0xe'),'context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be[_0x58ff('0x7')],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']},{'type':_0x1009be[_0x58ff('0x4')],'app':'Set','appdata':_0x58ff('0xf'),'context':_0x1009be[_0x58ff('0x6')],'exten':_0x1009be[_0x58ff('0x7')],'priority':_0x75f931++,'VoiceExtensionId':_0x1009be['id']});return _0x4d0046;}function _0xae006b(_0xc1a41e){var _0x1c43fa=0x2;var _0x538400=[{'type':'outbound','app':_0x58ff('0x5'),'appdata':_0x58ff('0x10'),'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0xc1a41e[_0x58ff('0x8')]?'Set':_0x58ff('0x12'),'appdata':_0xc1a41e[_0x58ff('0x8')]?'CDR(routeAlias)='+_0xc1a41e[_0x58ff('0x8')]:_0x58ff('0x13'),'context':_0xc1a41e['context'],'exten':_0xc1a41e['exten'],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0x58ff('0x5'),'appdata':_0x58ff('0x14')+(_0xc1a41e[_0x58ff('0x15')]?_0x58ff('0x16')+_0xc1a41e[_0x58ff('0x15')]+'}':_0x58ff('0x17')),'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':'outbound','app':'Set','appdata':_0x58ff('0xc')+_0xc1a41e['id'],'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0x58ff('0x18'),'appdata':_0x58ff('0x19')+(_0x1c43fa+0x2)+_0x58ff('0x1a')+(_0x1c43fa+0x1)+')','context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':'outbound','app':_0x58ff('0x5'),'appdata':_0xc1a41e[_0x58ff('0x15')]?_0x58ff('0x1b')+_0xc1a41e[_0x58ff('0x15')]+'}':_0x58ff('0x1c'),'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0x58ff('0x5'),'appdata':'XCALLY-MOTION-ANSWER=0','context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':'Set','appdata':_0x58ff('0xe'),'context':_0xc1a41e['context'],'exten':_0xc1a41e['exten'],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0x58ff('0x5'),'appdata':_0x58ff('0xf'),'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':_0x58ff('0x11'),'app':_0x58ff('0x5'),'appdata':'outboundrouteid='+_0xc1a41e['id'],'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e['exten'],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']}];if(_0xc1a41e[_0x58ff('0x1d')](_0x58ff('0x1e'))&&_0xc1a41e[_0x58ff('0x1e')]!==_0x58ff('0x1f')){_0x538400[_0x58ff('0xa')]({'type':'outbound','app':_0x58ff('0x5'),'appdata':_0x58ff('0x20'),'context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']},{'type':'outbound','app':_0x58ff('0x5'),'appdata':_0x58ff('0x21')+_0xc1a41e[_0x58ff('0x1e')]||'wav','context':_0xc1a41e[_0x58ff('0x6')],'exten':_0xc1a41e[_0x58ff('0x7')],'priority':_0x1c43fa++,'VoiceExtensionId':_0xc1a41e['id']});}return _0x538400;}function _0x4cbda5(_0x2cddfd,_0x3d4af2){var _0x3a11aa=[{'name':_0x58ff('0x22'),'param':0x0},{'name':_0x58ff('0x23'),'param':0x1},{'name':_0x58ff('0x24'),'param':0x2},{'name':_0x58ff('0x25'),'param':0x3}];var _0x46f80f={};var _0x117b45=_0x3d4af2['split'](',');var _0x433269=[];for(var _0x5d8af5=0x0;_0x5d8af5<_0x3a11aa['length'];_0x5d8af5++){switch(_0x3a11aa[_0x5d8af5][_0x58ff('0x26')]){case'trunk':_0x46f80f['trunk']=_0x117b45[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]][_0x58ff('0x28')]('/')[0x1];_0x46f80f['phone']=_0x117b45[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]][_0x58ff('0x28')]('/')[0x2];_0x46f80f['prefix']=_0x46f80f[_0x58ff('0x29')]?_0x46f80f['phone'][_0x58ff('0x28')]('$')[0x0]:undefined;_0x46f80f[_0x58ff('0x29')]=_0x2cddfd[_0x58ff('0x15')]?(_0x46f80f[_0x58ff('0x2a')]||'')+'${EXTEN:'+_0x2cddfd[_0x58ff('0x15')]+'}':(_0x46f80f[_0x58ff('0x2a')]||'')+_0x58ff('0x17');_0x433269[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]]=[_0x58ff('0x2b'),_0x46f80f['trunk'],_0x46f80f[_0x58ff('0x29')]]['join']('/');break;case'options':_0x46f80f[_0x58ff('0x24')]=_0x117b45[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]];if(_0x2cddfd[_0x58ff('0x1e')]!==_0x58ff('0x1f')){if(_0x46f80f[_0x58ff('0x24')][_0x58ff('0x2c')](_0x58ff('0x2d'))<0x0){_0x46f80f['options']+='U(xcally-mixmonitor-context)';}}else{_0x46f80f[_0x58ff('0x24')]=_0x46f80f[_0x58ff('0x24')][_0x58ff('0x2e')](_0x58ff('0x2d'),'');}_0x433269[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]]=_0x46f80f['options'];break;default:_0x433269[_0x3a11aa[_0x5d8af5][_0x58ff('0x27')]]=_0x117b45[_0x3a11aa[_0x5d8af5]['param']];}}return _0x433269[_0x58ff('0x2f')](',');}function _0x1182d8(_0x56bc48,_0x593539,_0x37c53){return new Promise(function(_0x210a95,_0xe8a8a3){var _0x47652c=[];if(_['isEmpty'](_0x593539))return _0x210a95(_0x47652c);_0x415e82[_0x58ff('0x30')][_0x58ff('0x31')]({'attributes':['id',_0x58ff('0x32'),_0x58ff('0x33')],'raw':!![]})[_0x58ff('0x34')](function(_0x982303){for(var _0x16e8a0=0x0,_0x36bccd=0x0;_0x16e8a0<_0x593539['length'];_0x16e8a0++,_0x36bccd=0x0){var _0x373f34=_0x593539[_0x16e8a0];var _0x370b6d=[];var _0x54a9ae=[];delete _0x373f34['id'];if(_0x373f34[_0x58ff('0x32')]!==_0x58ff('0x35')){_0x373f34[_0x58ff('0x36')]=[_0x373f34[_0x58ff('0x32')]];}else{_0x373f34['intervals']=_0x373f34[_0x58ff('0x33')]?_['map'](_[_0x58ff('0x37')](_0x982303,{'IntervalId':_0x373f34['IntervalId']}),'interval'):[];}_0x373f34[_0x58ff('0x6')]=_0x56bc48[_0x58ff('0x6')];_0x373f34['exten']=_0x56bc48[_0x58ff('0x7')];if(_0x373f34[_0x58ff('0x4')])_0x373f34['type']=_0x373f34[_0x58ff('0x4')][_0x58ff('0x38')]();if(_0x56bc48['type']===_0x58ff('0x11')){if(_0x373f34[_0x58ff('0x1d')](_0x58ff('0x39'))&&_0x373f34[_0x58ff('0x39')]&&_0x373f34['tag']!=='--'){_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34[_0x58ff('0x4')][_0x58ff('0x38')](),'app':'Set','appdata':_0x58ff('0x3a')+_0x373f34[_0x58ff('0x39')],'context':_0x56bc48[_0x58ff('0x6')],'exten':_0x56bc48[_0x58ff('0x7')],'priority':_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')]+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});}_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34[_0x58ff('0x4')][_0x58ff('0x38')](),'app':_0x58ff('0x18'),'appdata':_0x58ff('0x3c')+(_0x373f34['callerID']?_0x58ff('0x3d')+_0x373f34[_0x58ff('0x3e')]+')':_0x58ff('0x3f')),'context':_0x56bc48[_0x58ff('0x6')],'exten':_0x56bc48[_0x58ff('0x7')],'priority':_0x373f34[_0x58ff('0x36')]['length']+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});}else{if(_0x373f34[_0x58ff('0x1d')](_0x58ff('0x40'))){if([_0x58ff('0x41'),_0x58ff('0x42')][_0x58ff('0x43')](_0x373f34[_0x58ff('0x44')][_0x58ff('0x38')]())&&_0x373f34[_0x58ff('0x45')]!==_0x58ff('0x46')){if(_0x373f34[_0x58ff('0x40')]){_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34[_0x58ff('0x4')]['toLowerCase'](),'app':_0x58ff('0x18'),'appdata':_0x58ff('0x47'),'context':_0x56bc48['context'],'exten':_0x56bc48['exten'],'priority':_0x373f34['intervals'][_0x58ff('0x3b')]+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34[_0x58ff('0x4')]['toLowerCase'](),'app':_0x58ff('0x5'),'appdata':_0x58ff('0x48'),'context':_0x56bc48['context'],'exten':_0x56bc48['exten'],'priority':_0x373f34[_0x58ff('0x36')]['length']+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});}else{_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34['type']['toLowerCase'](),'app':_0x58ff('0x18'),'appdata':_0x58ff('0x49'),'context':_0x56bc48['context'],'exten':_0x56bc48[_0x58ff('0x7')],'priority':_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')]+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});_0x370b6d['push']({'type':_0x373f34[_0x58ff('0x4')][_0x58ff('0x38')](),'app':_0x58ff('0x5'),'appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x56bc48[_0x58ff('0x6')],'exten':_0x56bc48[_0x58ff('0x7')],'priority':_0x373f34[_0x58ff('0x36')]['length']+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});}}}}for(var _0x5161b8=0x0;_0x5161b8<_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')];_0x5161b8++){var _0x3e2824=_0x37c53+_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')];var _0x5ee3de=_0x5161b8===_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')]-0x1?_0x37c53+_0x370b6d[_0x58ff('0x3b')]+_0x54a9ae[_0x58ff('0x3b')]+0x2:_0x37c53+_0x5161b8+0x1;_0x370b6d[_0x58ff('0x4a')](_0x5161b8,0x0,{'type':_0x56bc48['type'],'app':_0x58ff('0x4b'),'appdata':_0x373f34[_0x58ff('0x36')][_0x5161b8]+'?'+_0x56bc48['context']+_0x58ff('0x4c')+_0x3e2824+':'+_0x56bc48[_0x58ff('0x6')]+_0x58ff('0x4c')+_0x5ee3de,'exten':_0x56bc48[_0x58ff('0x7')],'context':_0x56bc48[_0x58ff('0x6')],'priority':_0x37c53+_0x5161b8,'VoiceExtensionId':_0x56bc48['id']});}if(_0x373f34[_0x58ff('0x45')]===_0x58ff('0x4d')){_0x373f34[_0x58ff('0x4e')]=_0x4cbda5(_0x56bc48,_0x373f34[_0x58ff('0x4e')]);}if(_0x373f34[_0x58ff('0x45')]===_0x58ff('0x4f')){_0x370b6d[_0x58ff('0xa')]({'type':_0x373f34['type'][_0x58ff('0x38')](),'app':'Set','appdata':'XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','context':_0x56bc48[_0x58ff('0x6')],'exten':_0x56bc48['exten'],'priority':_0x373f34[_0x58ff('0x36')][_0x58ff('0x3b')]+_0x37c53+_0x36bccd++,'VoiceExtensionId':_0x56bc48['id']});}_0x373f34['priority']=_0x370b6d[_0x58ff('0x3b')]?_[_0x58ff('0x50')](_0x370b6d)[_0x58ff('0x51')]+0x1:_0x37c53;_0x47652c=_[_0x58ff('0x52')](_0x47652c,_0x370b6d,[_0x373f34],_0x54a9ae);_0x37c53=_[_0x58ff('0x50')](_0x47652c)[_0x58ff('0x51')]+0x1;}return _0x210a95(_0x47652c);})[_0x58ff('0x53')](function(_0x518d99){_0xe8a8a3(_0x518d99);});});}return _0x477887[_0x58ff('0x54')](_0x58ff('0x55'),attributes,{'tableName':'voice_extensions','paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x41ecb2){var _0x190d43=this[_0x58ff('0x56')]({'plain':!![]});var _0x1debb1=_0x190d43[_0x58ff('0x4')]===_0x58ff('0x11')?_0xae006b(_0x190d43):_0x50d564(_0x190d43);return _0x1182d8(_0x190d43,_0x41ecb2,_['last'](_0x1debb1)[_0x58ff('0x51')]+0x1)[_0x58ff('0x34')](function(_0x5841e5){var _0x3781dc=_[_0x58ff('0x52')](_0x1debb1,_0x5841e5);_0x3781dc[_0x58ff('0xa')]({'type':_0x190d43['type'],'app':'Hangup','exten':_0x190d43[_0x58ff('0x7')],'context':_0x190d43[_0x58ff('0x6')],'priority':_['last'](_0x3781dc)[_0x58ff('0x51')]+0x1,'VoiceExtensionId':_0x190d43['id']});return _0x3781dc;});}}});};