Built motion from commit cb845558.|2.6.34
[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 _0x94b1=['options','indexOf','U(xcally-mixmonitor-context)','replace','isEmpty','Interval','interval','IntervalId','then','*,*,*,*','intervals','filter','tag','toLowerCase','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','callerID','NoOp(No\x20number\x20available)','queue','includes','custom','ExecIf','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','splice','GotoIfTime',',${EXTEN},','appType','outboundDial','appdata','agi','XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','priority','last','catch','define','get','concat','Hangup','lodash','exports','models','type','Set','inbound','push','CDR(routeid)=','exten','XCALLY-MOTION-ANSWER=0','context','MONITOR_OPTIONS=ab','outbound','CDR(type)=outbound','${EXTEN:','${EXTEN}','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','cutdigits','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','XCALLY-MOTION-PROGRESS=0','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','trunk','timeout','url','length','name','param','split','phone','prefix'];(function(_0x2df4da,_0x2d68a5){var _0x2d66f2=function(_0x30dc30){while(--_0x30dc30){_0x2df4da['push'](_0x2df4da['shift']());}};_0x2d66f2(++_0x2d68a5);}(_0x94b1,0xbe));var _0x194b=function(_0x5bae89,_0x54ee3b){_0x5bae89=_0x5bae89-0x0;var _0x5d94cc=_0x94b1[_0x5bae89];return _0x5d94cc;};'use strict';var _=require(_0x194b('0x0'));var attributes=require('./voiceExtension.attributes');module[_0x194b('0x1')]=function(_0x57b3fe){var _0x317663=_0x57b3fe[_0x194b('0x2')];function _0x4f7f3a(_0x237ce5){var _0x734a8d=0x2;var _0x39d0ec=[{'type':_0x237ce5[_0x194b('0x3')],'app':_0x194b('0x4'),'appdata':'CDR(type)='+_0x237ce5['type'],'context':_0x237ce5['context'],'exten':_0x237ce5['exten'],'priority':_0x734a8d++,'VoiceExtensionId':_0x237ce5['id']}];if(_0x237ce5[_0x194b('0x3')]===_0x194b('0x5')){_0x39d0ec[_0x194b('0x6')]({'type':'inbound','app':_0x194b('0x4'),'appdata':_0x194b('0x7')+_0x237ce5['id'],'context':_0x237ce5['context'],'exten':_0x237ce5[_0x194b('0x8')],'priority':_0x734a8d++,'VoiceExtensionId':_0x237ce5['id']});}_0x39d0ec[_0x194b('0x6')]({'type':_0x237ce5[_0x194b('0x3')],'app':'Set','appdata':_0x194b('0x9'),'context':_0x237ce5[_0x194b('0xa')],'exten':_0x237ce5[_0x194b('0x8')],'priority':_0x734a8d++,'VoiceExtensionId':_0x237ce5['id']},{'type':_0x237ce5[_0x194b('0x3')],'app':_0x194b('0x4'),'appdata':'XCALLY-MOTION-PROGRESS=0','context':_0x237ce5[_0x194b('0xa')],'exten':_0x237ce5[_0x194b('0x8')],'priority':_0x734a8d++,'VoiceExtensionId':_0x237ce5['id']},{'type':_0x237ce5['type'],'app':_0x194b('0x4'),'appdata':_0x194b('0xb'),'context':_0x237ce5[_0x194b('0xa')],'exten':_0x237ce5[_0x194b('0x8')],'priority':_0x734a8d++,'VoiceExtensionId':_0x237ce5['id']});return _0x39d0ec;}function _0xab1bdf(_0x25b34f){var _0x222888=0x2;var _0x167bf3=[{'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':_0x194b('0xd'),'context':_0x25b34f['context'],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':'Set','appdata':'CDR(destination)='+(_0x25b34f['cutdigits']?_0x194b('0xe')+_0x25b34f['cutdigits']+'}':_0x194b('0xf')),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':'CDR(routeid)='+_0x25b34f['id'],'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':'outbound','app':'ExecIf','appdata':_0x194b('0x10')+(_0x222888+0x2)+_0x194b('0x11')+(_0x222888+0x1)+')','context':_0x25b34f['context'],'exten':_0x25b34f['exten'],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':'Set','appdata':_0x25b34f[_0x194b('0x12')]?_0x194b('0x13')+_0x25b34f[_0x194b('0x12')]+'}':_0x194b('0x14'),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f['exten'],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':_0x194b('0x9'),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f['exten'],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':_0x194b('0x15'),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':'MONITOR_OPTIONS=ab','context':_0x25b34f['context'],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':'outbound','app':_0x194b('0x4'),'appdata':_0x194b('0x16')+_0x25b34f['id'],'context':_0x25b34f['context'],'exten':_0x25b34f['exten'],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']}];if(_0x25b34f[_0x194b('0x17')]('recordingFormat')&&_0x25b34f[_0x194b('0x18')]!==_0x194b('0x19')){_0x167bf3[_0x194b('0x6')]({'type':_0x194b('0xc'),'app':_0x194b('0x4'),'appdata':_0x194b('0x1a'),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f['exten'],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']},{'type':'outbound','app':_0x194b('0x4'),'appdata':_0x194b('0x1b')+_0x25b34f[_0x194b('0x18')]||_0x194b('0x1c'),'context':_0x25b34f[_0x194b('0xa')],'exten':_0x25b34f[_0x194b('0x8')],'priority':_0x222888++,'VoiceExtensionId':_0x25b34f['id']});}return _0x167bf3;}function _0x201f6f(_0x4e2b88,_0x3b0dd0){var _0x49b45b=[{'name':_0x194b('0x1d'),'param':0x0},{'name':_0x194b('0x1e'),'param':0x1},{'name':'options','param':0x2},{'name':_0x194b('0x1f'),'param':0x3}];var _0x2a8f35={};var _0x1e2fa1=_0x3b0dd0['split'](',');var _0x3f69cd=[];for(var _0x25d66c=0x0;_0x25d66c<_0x49b45b[_0x194b('0x20')];_0x25d66c++){switch(_0x49b45b[_0x25d66c][_0x194b('0x21')]){case _0x194b('0x1d'):_0x2a8f35[_0x194b('0x1d')]=_0x1e2fa1[_0x49b45b[_0x25d66c][_0x194b('0x22')]][_0x194b('0x23')]('/')[0x1];_0x2a8f35['phone']=_0x1e2fa1[_0x49b45b[_0x25d66c][_0x194b('0x22')]][_0x194b('0x23')]('/')[0x2];_0x2a8f35['prefix']=_0x2a8f35[_0x194b('0x24')]?_0x2a8f35[_0x194b('0x24')][_0x194b('0x23')]('$')[0x0]:undefined;_0x2a8f35['phone']=_0x4e2b88[_0x194b('0x12')]?(_0x2a8f35[_0x194b('0x25')]||'')+'${EXTEN:'+_0x4e2b88['cutdigits']+'}':(_0x2a8f35[_0x194b('0x25')]||'')+_0x194b('0xf');_0x3f69cd[_0x49b45b[_0x25d66c][_0x194b('0x22')]]=['SIP',_0x2a8f35[_0x194b('0x1d')],_0x2a8f35[_0x194b('0x24')]]['join']('/');break;case'options':_0x2a8f35[_0x194b('0x26')]=_0x1e2fa1[_0x49b45b[_0x25d66c][_0x194b('0x22')]];if(_0x4e2b88[_0x194b('0x18')]!==_0x194b('0x19')){if(_0x2a8f35[_0x194b('0x26')][_0x194b('0x27')](_0x194b('0x28'))<0x0){_0x2a8f35[_0x194b('0x26')]+=_0x194b('0x28');}}else{_0x2a8f35[_0x194b('0x26')]=_0x2a8f35[_0x194b('0x26')][_0x194b('0x29')](_0x194b('0x28'),'');}_0x3f69cd[_0x49b45b[_0x25d66c][_0x194b('0x22')]]=_0x2a8f35[_0x194b('0x26')];break;default:_0x3f69cd[_0x49b45b[_0x25d66c]['param']]=_0x1e2fa1[_0x49b45b[_0x25d66c][_0x194b('0x22')]];}}return _0x3f69cd['join'](',');}function _0x4f00d5(_0x16e18b,_0x1dd87a,_0x4a92f4){return new Promise(function(_0x242eb5,_0x3c1506){var _0x44f3af=[];if(_[_0x194b('0x2a')](_0x1dd87a))return _0x242eb5(_0x44f3af);_0x317663[_0x194b('0x2b')]['findAll']({'attributes':['id',_0x194b('0x2c'),_0x194b('0x2d')],'raw':!![]})[_0x194b('0x2e')](function(_0x2aaf03){for(var _0x1a5652=0x0,_0x39b3c9=0x0;_0x1a5652<_0x1dd87a['length'];_0x1a5652++,_0x39b3c9=0x0){var _0x45615e=_0x1dd87a[_0x1a5652];var _0x1b5be7=[];var _0x5c974a=[];delete _0x45615e['id'];if(_0x45615e[_0x194b('0x2c')]!==_0x194b('0x2f')){_0x45615e[_0x194b('0x30')]=[_0x45615e[_0x194b('0x2c')]];}else{_0x45615e[_0x194b('0x30')]=_0x45615e[_0x194b('0x2d')]?_['map'](_[_0x194b('0x31')](_0x2aaf03,{'IntervalId':_0x45615e[_0x194b('0x2d')]}),'interval'):[];}_0x45615e[_0x194b('0xa')]=_0x16e18b[_0x194b('0xa')];_0x45615e[_0x194b('0x8')]=_0x16e18b[_0x194b('0x8')];if(_0x45615e['type'])_0x45615e[_0x194b('0x3')]=_0x45615e[_0x194b('0x3')]['toLowerCase']();if(_0x16e18b['type']===_0x194b('0xc')){if(_0x45615e['hasOwnProperty'](_0x194b('0x32'))&&_0x45615e[_0x194b('0x32')]&&_0x45615e['tag']!=='--'){_0x1b5be7[_0x194b('0x6')]({'type':_0x45615e[_0x194b('0x3')][_0x194b('0x33')](),'app':_0x194b('0x4'),'appdata':'CDR(tag)='+_0x45615e[_0x194b('0x32')],'context':_0x16e18b[_0x194b('0xa')],'exten':_0x16e18b[_0x194b('0x8')],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});}_0x1b5be7['push']({'type':_0x45615e[_0x194b('0x3')][_0x194b('0x33')](),'app':'ExecIf','appdata':_0x194b('0x34')+(_0x45615e['callerID']?'Set(CALLERID(all)='+_0x45615e[_0x194b('0x35')]+')':_0x194b('0x36')),'context':_0x16e18b[_0x194b('0xa')],'exten':_0x16e18b[_0x194b('0x8')],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});}else{if(_0x45615e[_0x194b('0x17')]('answer')){if([_0x194b('0x37'),'playback'][_0x194b('0x38')](_0x45615e['app'][_0x194b('0x33')]())&&_0x45615e['appType']!==_0x194b('0x39')){if(_0x45615e['answer']){_0x1b5be7[_0x194b('0x6')]({'type':_0x45615e[_0x194b('0x3')][_0x194b('0x33')](),'app':_0x194b('0x3a'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x16e18b[_0x194b('0xa')],'exten':_0x16e18b['exten'],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});_0x1b5be7[_0x194b('0x6')]({'type':_0x45615e['type'][_0x194b('0x33')](),'app':_0x194b('0x4'),'appdata':_0x194b('0x3b'),'context':_0x16e18b['context'],'exten':_0x16e18b[_0x194b('0x8')],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});}else{_0x1b5be7['push']({'type':_0x45615e['type'][_0x194b('0x33')](),'app':_0x194b('0x3a'),'appdata':_0x194b('0x3c'),'context':_0x16e18b[_0x194b('0xa')],'exten':_0x16e18b['exten'],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});_0x1b5be7[_0x194b('0x6')]({'type':_0x45615e['type'][_0x194b('0x33')](),'app':_0x194b('0x4'),'appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x16e18b['context'],'exten':_0x16e18b[_0x194b('0x8')],'priority':_0x45615e[_0x194b('0x30')][_0x194b('0x20')]+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});}}}}for(var _0x3026de=0x0;_0x3026de<_0x45615e['intervals'][_0x194b('0x20')];_0x3026de++){var _0x417549=_0x4a92f4+_0x45615e[_0x194b('0x30')]['length'];var _0x21194a=_0x3026de===_0x45615e['intervals']['length']-0x1?_0x4a92f4+_0x1b5be7[_0x194b('0x20')]+_0x5c974a[_0x194b('0x20')]+0x2:_0x4a92f4+_0x3026de+0x1;_0x1b5be7[_0x194b('0x3d')](_0x3026de,0x0,{'type':_0x16e18b['type'],'app':_0x194b('0x3e'),'appdata':_0x45615e['intervals'][_0x3026de]+'?'+_0x16e18b[_0x194b('0xa')]+_0x194b('0x3f')+_0x417549+':'+_0x16e18b['context']+_0x194b('0x3f')+_0x21194a,'exten':_0x16e18b['exten'],'context':_0x16e18b[_0x194b('0xa')],'priority':_0x4a92f4+_0x3026de,'VoiceExtensionId':_0x16e18b['id']});}if(_0x45615e[_0x194b('0x40')]===_0x194b('0x41')){_0x45615e['appdata']=_0x201f6f(_0x16e18b,_0x45615e[_0x194b('0x42')]);}if(_0x45615e['appType']===_0x194b('0x43')){_0x1b5be7[_0x194b('0x6')]({'type':_0x45615e['type']['toLowerCase'](),'app':'Set','appdata':_0x194b('0x44'),'context':_0x16e18b['context'],'exten':_0x16e18b[_0x194b('0x8')],'priority':_0x45615e['intervals']['length']+_0x4a92f4+_0x39b3c9++,'VoiceExtensionId':_0x16e18b['id']});}_0x45615e[_0x194b('0x45')]=_0x1b5be7[_0x194b('0x20')]?_[_0x194b('0x46')](_0x1b5be7)[_0x194b('0x45')]+0x1:_0x4a92f4;_0x44f3af=_['concat'](_0x44f3af,_0x1b5be7,[_0x45615e],_0x5c974a);_0x4a92f4=_['last'](_0x44f3af)[_0x194b('0x45')]+0x1;}return _0x242eb5(_0x44f3af);})[_0x194b('0x47')](function(_0x444267){_0x3c1506(_0x444267);});});}return _0x57b3fe[_0x194b('0x48')]('VoiceExtension',attributes,{'tableName':'voice_extensions','paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x29028f){var _0x48b4fe=this[_0x194b('0x49')]({'plain':!![]});var _0x5013f4=_0x48b4fe[_0x194b('0x3')]===_0x194b('0xc')?_0xab1bdf(_0x48b4fe):_0x4f7f3a(_0x48b4fe);return _0x4f00d5(_0x48b4fe,_0x29028f,_[_0x194b('0x46')](_0x5013f4)['priority']+0x1)[_0x194b('0x2e')](function(_0x46a5fe){var _0x2843bb=_[_0x194b('0x4a')](_0x5013f4,_0x46a5fe);_0x2843bb['push']({'type':_0x48b4fe[_0x194b('0x3')],'app':_0x194b('0x4b'),'exten':_0x48b4fe[_0x194b('0x8')],'context':_0x48b4fe[_0x194b('0xa')],'priority':_['last'](_0x2843bb)['priority']+0x1,'VoiceExtensionId':_0x48b4fe['id']});return _0x2843bb;});}}});};