8f6108f9f840f208ab155afd339617d54058ca66
[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 _0x0910=['CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','trunk','options','url','split','length','name','param','phone','prefix','${EXTEN:','${EXTEN}','SIP','join','indexOf','U(xcally-mixmonitor-context)','isEmpty','Interval','findAll','IntervalId','interval','*,*,*,*','intervals','map','filter','toLowerCase','tag','CDR(tag)=','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','includes','app','custom','answer','$[${XCALLY-MOTION-PROGRESS}=0]?Progress',',${EXTEN},','appdata','priority','last','concat','catch','define','VoiceExtension','get','then','./voiceExtension.attributes','exports','models','type','Set','CDR(type)=','context','exten','alias','CDR(routeAlias)=','No\x20alias\x20set','inbound','push','CDR(routeid)=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','outbound','CDR(type)=outbound','NoOp','CDR(destination)=','cutdigits','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto('];(function(_0x532c73,_0x3769ec){var _0x3e43eb=function(_0x94ccf8){while(--_0x94ccf8){_0x532c73['push'](_0x532c73['shift']());}};_0x3e43eb(++_0x3769ec);}(_0x0910,0xd7));var _0x0091=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x0910[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var attributes=require(_0x0091('0x0'));module[_0x0091('0x1')]=function(_0xf3be31){var _0x54d23d=_0xf3be31[_0x0091('0x2')];function _0x3dffac(_0x2ab1fb){var _0x58d951=0x2;var _0x5ca31e=[{'type':_0x2ab1fb[_0x0091('0x3')],'app':_0x0091('0x4'),'appdata':_0x0091('0x5')+_0x2ab1fb[_0x0091('0x3')],'context':_0x2ab1fb[_0x0091('0x6')],'exten':_0x2ab1fb[_0x0091('0x7')],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']},{'type':_0x2ab1fb[_0x0091('0x3')],'app':_0x2ab1fb[_0x0091('0x8')]?_0x0091('0x4'):'NoOp','appdata':_0x2ab1fb[_0x0091('0x8')]?_0x0091('0x9')+_0x2ab1fb[_0x0091('0x8')]:_0x0091('0xa'),'context':_0x2ab1fb[_0x0091('0x6')],'exten':_0x2ab1fb[_0x0091('0x7')],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']}];if(_0x2ab1fb[_0x0091('0x3')]===_0x0091('0xb')){_0x5ca31e[_0x0091('0xc')]({'type':_0x0091('0xb'),'app':_0x0091('0x4'),'appdata':_0x0091('0xd')+_0x2ab1fb['id'],'context':_0x2ab1fb[_0x0091('0x6')],'exten':_0x2ab1fb[_0x0091('0x7')],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']});}_0x5ca31e[_0x0091('0xc')]({'type':_0x2ab1fb['type'],'app':_0x0091('0x4'),'appdata':_0x0091('0xe'),'context':_0x2ab1fb['context'],'exten':_0x2ab1fb[_0x0091('0x7')],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']},{'type':_0x2ab1fb[_0x0091('0x3')],'app':_0x0091('0x4'),'appdata':_0x0091('0xf'),'context':_0x2ab1fb['context'],'exten':_0x2ab1fb['exten'],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']},{'type':_0x2ab1fb['type'],'app':_0x0091('0x4'),'appdata':_0x0091('0x10'),'context':_0x2ab1fb[_0x0091('0x6')],'exten':_0x2ab1fb['exten'],'priority':_0x58d951++,'VoiceExtensionId':_0x2ab1fb['id']});return _0x5ca31e;}function _0x4ee49f(_0x53e962){var _0x5290ef=0x2;var _0x3e958e=[{'type':_0x0091('0x11'),'app':_0x0091('0x4'),'appdata':_0x0091('0x12'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':_0x53e962[_0x0091('0x8')]?'Set':_0x0091('0x13'),'appdata':_0x53e962[_0x0091('0x8')]?_0x0091('0x9')+_0x53e962[_0x0091('0x8')]:_0x0091('0xa'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':'outbound','app':'Set','appdata':_0x0091('0x14')+(_0x53e962[_0x0091('0x15')]?'${EXTEN:'+_0x53e962[_0x0091('0x15')]+'}':'${EXTEN}'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':_0x0091('0x4'),'appdata':_0x0091('0xd')+_0x53e962['id'],'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':_0x0091('0x16'),'appdata':_0x0091('0x17')+(_0x5290ef+0x2)+_0x0091('0x18')+(_0x5290ef+0x1)+')','context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':_0x0091('0x4'),'appdata':_0x53e962[_0x0091('0x15')]?_0x0091('0x19')+_0x53e962[_0x0091('0x15')]+'}':_0x0091('0x1a'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':'Set','appdata':'XCALLY-MOTION-ANSWER=0','context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':'outbound','app':_0x0091('0x4'),'appdata':_0x0091('0xf'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962['exten'],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':'Set','appdata':_0x0091('0x10'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':'outbound','app':_0x0091('0x4'),'appdata':_0x0091('0x1b')+_0x53e962['id'],'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962['exten'],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']}];if(_0x53e962[_0x0091('0x1c')](_0x0091('0x1d'))&&_0x53e962[_0x0091('0x1d')]!==_0x0091('0x1e')){_0x3e958e[_0x0091('0xc')]({'type':'outbound','app':_0x0091('0x4'),'appdata':_0x0091('0x1f'),'context':_0x53e962['context'],'exten':_0x53e962[_0x0091('0x7')],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']},{'type':_0x0091('0x11'),'app':'Set','appdata':_0x0091('0x20')+_0x53e962['recordingFormat']||_0x0091('0x21'),'context':_0x53e962[_0x0091('0x6')],'exten':_0x53e962['exten'],'priority':_0x5290ef++,'VoiceExtensionId':_0x53e962['id']});}return _0x3e958e;}function _0x1de43c(_0x44f394,_0x3c1a6b){var _0x44fca0=[{'name':_0x0091('0x22'),'param':0x0},{'name':'timeout','param':0x1},{'name':_0x0091('0x23'),'param':0x2},{'name':_0x0091('0x24'),'param':0x3}];var _0x5d93fe={};var _0x1d6c74=_0x3c1a6b[_0x0091('0x25')](',');var _0x589ad0=[];for(var _0x129dd5=0x0;_0x129dd5<_0x44fca0[_0x0091('0x26')];_0x129dd5++){switch(_0x44fca0[_0x129dd5][_0x0091('0x27')]){case'trunk':_0x5d93fe[_0x0091('0x22')]=_0x1d6c74[_0x44fca0[_0x129dd5][_0x0091('0x28')]][_0x0091('0x25')]('/')[0x1];_0x5d93fe[_0x0091('0x29')]=_0x1d6c74[_0x44fca0[_0x129dd5][_0x0091('0x28')]][_0x0091('0x25')]('/')[0x2];_0x5d93fe[_0x0091('0x2a')]=_0x5d93fe[_0x0091('0x29')]?_0x5d93fe[_0x0091('0x29')][_0x0091('0x25')]('$')[0x0]:undefined;_0x5d93fe[_0x0091('0x29')]=_0x44f394[_0x0091('0x15')]?(_0x5d93fe[_0x0091('0x2a')]||'')+_0x0091('0x2b')+_0x44f394[_0x0091('0x15')]+'}':(_0x5d93fe['prefix']||'')+_0x0091('0x2c');_0x589ad0[_0x44fca0[_0x129dd5]['param']]=[_0x0091('0x2d'),_0x5d93fe[_0x0091('0x22')],_0x5d93fe['phone']][_0x0091('0x2e')]('/');break;case'options':_0x5d93fe['options']=_0x1d6c74[_0x44fca0[_0x129dd5][_0x0091('0x28')]];if(_0x44f394['recordingFormat']!==_0x0091('0x1e')){if(_0x5d93fe[_0x0091('0x23')][_0x0091('0x2f')](_0x0091('0x30'))<0x0){_0x5d93fe[_0x0091('0x23')]+='U(xcally-mixmonitor-context)';}}else{_0x5d93fe['options']=_0x5d93fe['options']['replace'](_0x0091('0x30'),'');}_0x589ad0[_0x44fca0[_0x129dd5]['param']]=_0x5d93fe[_0x0091('0x23')];break;default:_0x589ad0[_0x44fca0[_0x129dd5][_0x0091('0x28')]]=_0x1d6c74[_0x44fca0[_0x129dd5][_0x0091('0x28')]];}}return _0x589ad0[_0x0091('0x2e')](',');}function _0x2c8eaa(_0x4755fd,_0x540898,_0x249247){return new Promise(function(_0x49e3a9,_0x1e71d7){var _0x396e86=[];if(_[_0x0091('0x31')](_0x540898))return _0x49e3a9(_0x396e86);_0x54d23d[_0x0091('0x32')][_0x0091('0x33')]({'attributes':['id','interval',_0x0091('0x34')],'raw':!![]})['then'](function(_0x4f07c9){for(var _0x4c5c51=0x0,_0x43f19d=0x0;_0x4c5c51<_0x540898['length'];_0x4c5c51++,_0x43f19d=0x0){var _0x22f08b=_0x540898[_0x4c5c51];var _0x14cef5=[];var _0x3633fb=[];delete _0x22f08b['id'];if(_0x22f08b[_0x0091('0x35')]!==_0x0091('0x36')){_0x22f08b[_0x0091('0x37')]=[_0x22f08b[_0x0091('0x35')]];}else{_0x22f08b[_0x0091('0x37')]=_0x22f08b[_0x0091('0x34')]?_[_0x0091('0x38')](_[_0x0091('0x39')](_0x4f07c9,{'IntervalId':_0x22f08b[_0x0091('0x34')]}),_0x0091('0x35')):[];}_0x22f08b[_0x0091('0x6')]=_0x4755fd[_0x0091('0x6')];_0x22f08b[_0x0091('0x7')]=_0x4755fd[_0x0091('0x7')];if(_0x22f08b[_0x0091('0x3')])_0x22f08b['type']=_0x22f08b['type'][_0x0091('0x3a')]();if(_0x4755fd[_0x0091('0x3')]===_0x0091('0x11')){if(_0x22f08b['hasOwnProperty'](_0x0091('0x3b'))&&_0x22f08b[_0x0091('0x3b')]&&_0x22f08b[_0x0091('0x3b')]!=='--'){_0x14cef5[_0x0091('0xc')]({'type':_0x22f08b[_0x0091('0x3')][_0x0091('0x3a')](),'app':_0x0091('0x4'),'appdata':_0x0091('0x3c')+_0x22f08b[_0x0091('0x3b')],'context':_0x4755fd[_0x0091('0x6')],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});}_0x14cef5[_0x0091('0xc')]({'type':_0x22f08b[_0x0091('0x3')][_0x0091('0x3a')](),'app':_0x0091('0x16'),'appdata':_0x0091('0x3d')+(_0x22f08b[_0x0091('0x3e')]?_0x0091('0x3f')+_0x22f08b[_0x0091('0x3e')]+')':_0x0091('0x40')),'context':_0x4755fd['context'],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')]['length']+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});}else{if(_0x22f08b['hasOwnProperty']('answer')){if(['queue','playback'][_0x0091('0x41')](_0x22f08b[_0x0091('0x42')]['toLowerCase']())&&_0x22f08b['appType']!==_0x0091('0x43')){if(_0x22f08b[_0x0091('0x44')]){_0x14cef5['push']({'type':_0x22f08b[_0x0091('0x3')]['toLowerCase'](),'app':_0x0091('0x16'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0x4755fd[_0x0091('0x6')],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});_0x14cef5[_0x0091('0xc')]({'type':_0x22f08b[_0x0091('0x3')][_0x0091('0x3a')](),'app':_0x0091('0x4'),'appdata':'XCALLY-MOTION-ANSWER=1','context':_0x4755fd['context'],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});}else{_0x14cef5['push']({'type':_0x22f08b[_0x0091('0x3')][_0x0091('0x3a')](),'app':_0x0091('0x16'),'appdata':_0x0091('0x45'),'context':_0x4755fd[_0x0091('0x6')],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});_0x14cef5['push']({'type':_0x22f08b['type'][_0x0091('0x3a')](),'app':'Set','appdata':'XCALLY-MOTION-PROGRESS=1','context':_0x4755fd[_0x0091('0x6')],'exten':_0x4755fd['exten'],'priority':_0x22f08b[_0x0091('0x37')]['length']+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});}}}}for(var _0x15f43e=0x0;_0x15f43e<_0x22f08b['intervals'][_0x0091('0x26')];_0x15f43e++){var _0xbd4d24=_0x249247+_0x22f08b[_0x0091('0x37')][_0x0091('0x26')];var _0x56ed1a=_0x15f43e===_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]-0x1?_0x249247+_0x14cef5[_0x0091('0x26')]+_0x3633fb[_0x0091('0x26')]+0x2:_0x249247+_0x15f43e+0x1;_0x14cef5['splice'](_0x15f43e,0x0,{'type':_0x4755fd[_0x0091('0x3')],'app':'GotoIfTime','appdata':_0x22f08b[_0x0091('0x37')][_0x15f43e]+'?'+_0x4755fd[_0x0091('0x6')]+_0x0091('0x46')+_0xbd4d24+':'+_0x4755fd[_0x0091('0x6')]+_0x0091('0x46')+_0x56ed1a,'exten':_0x4755fd[_0x0091('0x7')],'context':_0x4755fd['context'],'priority':_0x249247+_0x15f43e,'VoiceExtensionId':_0x4755fd['id']});}if(_0x22f08b['appType']==='outboundDial'){_0x22f08b[_0x0091('0x47')]=_0x1de43c(_0x4755fd,_0x22f08b['appdata']);}if(_0x22f08b['appType']==='agi'){_0x14cef5[_0x0091('0xc')]({'type':_0x22f08b[_0x0091('0x3')][_0x0091('0x3a')](),'app':'Set','appdata':'XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','context':_0x4755fd[_0x0091('0x6')],'exten':_0x4755fd[_0x0091('0x7')],'priority':_0x22f08b[_0x0091('0x37')][_0x0091('0x26')]+_0x249247+_0x43f19d++,'VoiceExtensionId':_0x4755fd['id']});}_0x22f08b[_0x0091('0x48')]=_0x14cef5['length']?_[_0x0091('0x49')](_0x14cef5)[_0x0091('0x48')]+0x1:_0x249247;_0x396e86=_[_0x0091('0x4a')](_0x396e86,_0x14cef5,[_0x22f08b],_0x3633fb);_0x249247=_[_0x0091('0x49')](_0x396e86)[_0x0091('0x48')]+0x1;}return _0x49e3a9(_0x396e86);})[_0x0091('0x4b')](function(_0x1af0ce){_0x1e71d7(_0x1af0ce);});});}return _0xf3be31[_0x0091('0x4c')](_0x0091('0x4d'),attributes,{'tableName':'voice_extensions','paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x44537f){var _0x411713=this[_0x0091('0x4e')]({'plain':!![]});var _0x1a0bc9=_0x411713['type']==='outbound'?_0x4ee49f(_0x411713):_0x3dffac(_0x411713);return _0x2c8eaa(_0x411713,_0x44537f,_[_0x0091('0x49')](_0x1a0bc9)['priority']+0x1)[_0x0091('0x4f')](function(_0x3ba05d){var _0x5c9327=_['concat'](_0x1a0bc9,_0x3ba05d);_0x5c9327[_0x0091('0xc')]({'type':_0x411713['type'],'app':'Hangup','exten':_0x411713[_0x0091('0x7')],'context':_0x411713[_0x0091('0x6')],'priority':_[_0x0091('0x49')](_0x5c9327)[_0x0091('0x48')]+0x1,'VoiceExtensionId':_0x411713['id']});return _0x5c9327;});}}});};