0e7327a8822acbaefe8c902c1403c1067546499c
[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 _0x5dd1=['lodash','./voiceExtension.attributes','models','type','Set','CDR(type)=','context','exten','alias','CDR(routeAlias)=','No\x20alias\x20set','inbound','push','XCALLY-MOTION-ANSWER=0','outbound','CDR(type)=outbound','NoOp','CDR(destination)=','cutdigits','${EXTEN:','ExecIf','):Goto(','CDR(prefix)=noprefix','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','timeout','options','split','length','name','trunk','param','phone','prefix','${EXTEN}','SIP','join','indexOf','U(xcally-mixmonitor-context)','replace','isEmpty','Interval','interval','IntervalId','then','filter','toLowerCase','tag','CDR(tag)=','intervals','callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','playback','includes','app','appType','answer','XCALLY-MOTION-ANSWER=1','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime','appdata','XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','priority','last','concat','catch','VoiceExtension','voice_extensions','get','Hangup'];(function(_0x35885a,_0x42fed7){var _0xe86249=function(_0x98edb3){while(--_0x98edb3){_0x35885a['push'](_0x35885a['shift']());}};_0xe86249(++_0x42fed7);}(_0x5dd1,0xed));var _0x15dd=function(_0x43dbe9,_0xf43a4a){_0x43dbe9=_0x43dbe9-0x0;var _0x11a746=_0x5dd1[_0x43dbe9];return _0x11a746;};'use strict';var _=require(_0x15dd('0x0'));var attributes=require(_0x15dd('0x1'));module['exports']=function(_0x4282d9){var _0x3e5b75=_0x4282d9[_0x15dd('0x2')];function _0x3247f3(_0x3fd855){var _0x1572e5=0x2;var _0x1e4d7e=[{'type':_0x3fd855[_0x15dd('0x3')],'app':_0x15dd('0x4'),'appdata':_0x15dd('0x5')+_0x3fd855[_0x15dd('0x3')],'context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']},{'type':_0x3fd855['type'],'app':_0x3fd855[_0x15dd('0x8')]?_0x15dd('0x4'):'NoOp','appdata':_0x3fd855['alias']?_0x15dd('0x9')+_0x3fd855[_0x15dd('0x8')]:_0x15dd('0xa'),'context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']}];if(_0x3fd855[_0x15dd('0x3')]===_0x15dd('0xb')){_0x1e4d7e['push']({'type':_0x15dd('0xb'),'app':'Set','appdata':'CDR(routeid)='+_0x3fd855['id'],'context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']});}_0x1e4d7e[_0x15dd('0xc')]({'type':_0x3fd855[_0x15dd('0x3')],'app':'Set','appdata':_0x15dd('0xd'),'context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']},{'type':_0x3fd855[_0x15dd('0x3')],'app':'Set','appdata':'XCALLY-MOTION-PROGRESS=0','context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']},{'type':_0x3fd855['type'],'app':_0x15dd('0x4'),'appdata':'MONITOR_OPTIONS=ab','context':_0x3fd855[_0x15dd('0x6')],'exten':_0x3fd855[_0x15dd('0x7')],'priority':_0x1572e5++,'VoiceExtensionId':_0x3fd855['id']});return _0x1e4d7e;}function _0x2c6610(_0x2583fe){var _0x3938ea=0x2;var _0x4f65ec=[{'type':_0x15dd('0xe'),'app':'Set','appdata':_0x15dd('0xf'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':'outbound','app':_0x2583fe[_0x15dd('0x8')]?'Set':_0x15dd('0x10'),'appdata':_0x2583fe[_0x15dd('0x8')]?'CDR(routeAlias)='+_0x2583fe[_0x15dd('0x8')]:_0x15dd('0xa'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe['exten'],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':'outbound','app':_0x15dd('0x4'),'appdata':_0x15dd('0x11')+(_0x2583fe[_0x15dd('0x12')]?_0x15dd('0x13')+_0x2583fe[_0x15dd('0x12')]+'}':'${EXTEN}'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe['exten'],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':_0x15dd('0x4'),'appdata':'CDR(routeid)='+_0x2583fe['id'],'context':_0x2583fe['context'],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':_0x15dd('0x14'),'appdata':'$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto('+(_0x3938ea+0x2)+_0x15dd('0x15')+(_0x3938ea+0x1)+')','context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':_0x15dd('0x4'),'appdata':_0x2583fe['cutdigits']?'CDR(prefix)=${EXTEN:0:'+_0x2583fe['cutdigits']+'}':_0x15dd('0x16'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe['exten'],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':'outbound','app':_0x15dd('0x4'),'appdata':_0x15dd('0xd'),'context':_0x2583fe['context'],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':_0x15dd('0x4'),'appdata':_0x15dd('0x17'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':'Set','appdata':_0x15dd('0x18'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe['exten'],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':'Set','appdata':_0x15dd('0x19')+_0x2583fe['id'],'context':_0x2583fe['context'],'exten':_0x2583fe['exten'],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']}];if(_0x2583fe[_0x15dd('0x1a')](_0x15dd('0x1b'))&&_0x2583fe[_0x15dd('0x1b')]!==_0x15dd('0x1c')){_0x4f65ec[_0x15dd('0xc')]({'type':_0x15dd('0xe'),'app':_0x15dd('0x4'),'appdata':_0x15dd('0x1d'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']},{'type':_0x15dd('0xe'),'app':_0x15dd('0x4'),'appdata':_0x15dd('0x1e')+_0x2583fe[_0x15dd('0x1b')]||_0x15dd('0x1f'),'context':_0x2583fe[_0x15dd('0x6')],'exten':_0x2583fe[_0x15dd('0x7')],'priority':_0x3938ea++,'VoiceExtensionId':_0x2583fe['id']});}return _0x4f65ec;}function _0x479261(_0x2d9424,_0xf61328){var _0x5d1273=[{'name':'trunk','param':0x0},{'name':_0x15dd('0x20'),'param':0x1},{'name':_0x15dd('0x21'),'param':0x2},{'name':'url','param':0x3}];var _0x5ad09e={};var _0x2e02fa=_0xf61328[_0x15dd('0x22')](',');var _0x565041=[];for(var _0x2e92ca=0x0;_0x2e92ca<_0x5d1273[_0x15dd('0x23')];_0x2e92ca++){switch(_0x5d1273[_0x2e92ca][_0x15dd('0x24')]){case _0x15dd('0x25'):_0x5ad09e[_0x15dd('0x25')]=_0x2e02fa[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]][_0x15dd('0x22')]('/')[0x1];_0x5ad09e[_0x15dd('0x27')]=_0x2e02fa[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]]['split']('/')[0x2];_0x5ad09e[_0x15dd('0x28')]=_0x5ad09e['phone']?_0x5ad09e[_0x15dd('0x27')][_0x15dd('0x22')]('$')[0x0]:undefined;_0x5ad09e[_0x15dd('0x27')]=_0x2d9424['cutdigits']?(_0x5ad09e[_0x15dd('0x28')]||'')+_0x15dd('0x13')+_0x2d9424['cutdigits']+'}':(_0x5ad09e['prefix']||'')+_0x15dd('0x29');_0x565041[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]]=[_0x15dd('0x2a'),_0x5ad09e[_0x15dd('0x25')],_0x5ad09e[_0x15dd('0x27')]][_0x15dd('0x2b')]('/');break;case _0x15dd('0x21'):_0x5ad09e[_0x15dd('0x21')]=_0x2e02fa[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]];if(_0x2d9424['recordingFormat']!==_0x15dd('0x1c')){if(_0x5ad09e[_0x15dd('0x21')][_0x15dd('0x2c')]('U(xcally-mixmonitor-context)')<0x0){_0x5ad09e[_0x15dd('0x21')]+=_0x15dd('0x2d');}}else{_0x5ad09e[_0x15dd('0x21')]=_0x5ad09e[_0x15dd('0x21')][_0x15dd('0x2e')](_0x15dd('0x2d'),'');}_0x565041[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]]=_0x5ad09e[_0x15dd('0x21')];break;default:_0x565041[_0x5d1273[_0x2e92ca][_0x15dd('0x26')]]=_0x2e02fa[_0x5d1273[_0x2e92ca]['param']];}}return _0x565041[_0x15dd('0x2b')](',');}function _0x315223(_0x2a05d7,_0x50d182,_0x995fde){return new Promise(function(_0x476566,_0x57e1cb){var _0x24bed0=[];if(_[_0x15dd('0x2f')](_0x50d182))return _0x476566(_0x24bed0);_0x3e5b75[_0x15dd('0x30')]['findAll']({'attributes':['id',_0x15dd('0x31'),_0x15dd('0x32')],'raw':!![]})[_0x15dd('0x33')](function(_0xdfd42d){for(var _0x27e4d1=0x0,_0x179e64=0x0;_0x27e4d1<_0x50d182[_0x15dd('0x23')];_0x27e4d1++,_0x179e64=0x0){var _0x53f567=_0x50d182[_0x27e4d1];var _0xdae672=[];var _0x5f2f74=[];delete _0x53f567['id'];if(_0x53f567['interval']!=='*,*,*,*'){_0x53f567['intervals']=[_0x53f567['interval']];}else{_0x53f567['intervals']=_0x53f567[_0x15dd('0x32')]?_['map'](_[_0x15dd('0x34')](_0xdfd42d,{'IntervalId':_0x53f567['IntervalId']}),'interval'):[];}_0x53f567[_0x15dd('0x6')]=_0x2a05d7[_0x15dd('0x6')];_0x53f567[_0x15dd('0x7')]=_0x2a05d7[_0x15dd('0x7')];if(_0x53f567[_0x15dd('0x3')])_0x53f567[_0x15dd('0x3')]=_0x53f567['type'][_0x15dd('0x35')]();if(_0x2a05d7[_0x15dd('0x3')]===_0x15dd('0xe')){if(_0x53f567[_0x15dd('0x1a')](_0x15dd('0x36'))&&_0x53f567[_0x15dd('0x36')]&&_0x53f567['tag']!=='--'){_0xdae672[_0x15dd('0xc')]({'type':_0x53f567[_0x15dd('0x3')][_0x15dd('0x35')](),'app':'Set','appdata':_0x15dd('0x37')+_0x53f567['tag'],'context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});}_0xdae672['push']({'type':_0x53f567[_0x15dd('0x3')][_0x15dd('0x35')](),'app':'ExecIf','appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):'+(_0x53f567[_0x15dd('0x39')]?_0x15dd('0x3a')+_0x53f567[_0x15dd('0x39')]+')':_0x15dd('0x3b')),'context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});}else{if(_0x53f567['hasOwnProperty']('answer')){if(['queue',_0x15dd('0x3c')][_0x15dd('0x3d')](_0x53f567[_0x15dd('0x3e')][_0x15dd('0x35')]())&&_0x53f567[_0x15dd('0x3f')]!=='custom'){if(_0x53f567[_0x15dd('0x40')]){_0xdae672[_0x15dd('0xc')]({'type':_0x53f567['type'][_0x15dd('0x35')](),'app':_0x15dd('0x14'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});_0xdae672[_0x15dd('0xc')]({'type':_0x53f567['type'][_0x15dd('0x35')](),'app':_0x15dd('0x4'),'appdata':_0x15dd('0x41'),'context':_0x2a05d7['context'],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});}else{_0xdae672[_0x15dd('0xc')]({'type':_0x53f567[_0x15dd('0x3')][_0x15dd('0x35')](),'app':_0x15dd('0x14'),'appdata':'$[${XCALLY-MOTION-PROGRESS}=0]?Progress','context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7['exten'],'priority':_0x53f567[_0x15dd('0x38')]['length']+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});_0xdae672[_0x15dd('0xc')]({'type':_0x53f567[_0x15dd('0x3')][_0x15dd('0x35')](),'app':'Set','appdata':_0x15dd('0x42'),'context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});}}}}for(var _0x128312=0x0;_0x128312<_0x53f567['intervals'][_0x15dd('0x23')];_0x128312++){var _0x8e5a6e=_0x995fde+_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')];var _0x30cdfc=_0x128312===_0x53f567[_0x15dd('0x38')]['length']-0x1?_0x995fde+_0xdae672[_0x15dd('0x23')]+_0x5f2f74[_0x15dd('0x23')]+0x2:_0x995fde+_0x128312+0x1;_0xdae672[_0x15dd('0x43')](_0x128312,0x0,{'type':_0x2a05d7[_0x15dd('0x3')],'app':_0x15dd('0x44'),'appdata':_0x53f567[_0x15dd('0x38')][_0x128312]+'?'+_0x2a05d7[_0x15dd('0x6')]+',${EXTEN},'+_0x8e5a6e+':'+_0x2a05d7[_0x15dd('0x6')]+',${EXTEN},'+_0x30cdfc,'exten':_0x2a05d7[_0x15dd('0x7')],'context':_0x2a05d7['context'],'priority':_0x995fde+_0x128312,'VoiceExtensionId':_0x2a05d7['id']});}if(_0x53f567[_0x15dd('0x3f')]==='outboundDial'){_0x53f567[_0x15dd('0x45')]=_0x479261(_0x2a05d7,_0x53f567['appdata']);}if(_0x53f567[_0x15dd('0x3f')]==='agi'){_0xdae672['push']({'type':_0x53f567[_0x15dd('0x3')][_0x15dd('0x35')](),'app':_0x15dd('0x4'),'appdata':_0x15dd('0x46'),'context':_0x2a05d7[_0x15dd('0x6')],'exten':_0x2a05d7[_0x15dd('0x7')],'priority':_0x53f567[_0x15dd('0x38')][_0x15dd('0x23')]+_0x995fde+_0x179e64++,'VoiceExtensionId':_0x2a05d7['id']});}_0x53f567[_0x15dd('0x47')]=_0xdae672[_0x15dd('0x23')]?_[_0x15dd('0x48')](_0xdae672)[_0x15dd('0x47')]+0x1:_0x995fde;_0x24bed0=_[_0x15dd('0x49')](_0x24bed0,_0xdae672,[_0x53f567],_0x5f2f74);_0x995fde=_[_0x15dd('0x48')](_0x24bed0)['priority']+0x1;}return _0x476566(_0x24bed0);})[_0x15dd('0x4a')](function(_0x133acd){_0x57e1cb(_0x133acd);});});}return _0x4282d9['define'](_0x15dd('0x4b'),attributes,{'tableName':_0x15dd('0x4c'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x23f916){var _0x4f98ea=this[_0x15dd('0x4d')]({'plain':!![]});var _0x61dc66=_0x4f98ea[_0x15dd('0x3')]===_0x15dd('0xe')?_0x2c6610(_0x4f98ea):_0x3247f3(_0x4f98ea);return _0x315223(_0x4f98ea,_0x23f916,_[_0x15dd('0x48')](_0x61dc66)[_0x15dd('0x47')]+0x1)['then'](function(_0xc129fc){var _0xc24378=_[_0x15dd('0x49')](_0x61dc66,_0xc129fc);_0xc24378[_0x15dd('0xc')]({'type':_0x4f98ea[_0x15dd('0x3')],'app':_0x15dd('0x4e'),'exten':_0x4f98ea[_0x15dd('0x7')],'context':_0x4f98ea[_0x15dd('0x6')],'priority':_[_0x15dd('0x48')](_0xc24378)[_0x15dd('0x47')]+0x1,'VoiceExtensionId':_0x4f98ea['id']});return _0xc24378;});}}});};