Built motion from commit fa4c4286.|2.6.29
[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 _0x14c4=['lodash','./voiceExtension.attributes','exports','models','type','Set','context','exten','CDR(routeid)=','push','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','CDR(type)=outbound','outbound','cutdigits','${EXTEN:','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','recordingFormat','none','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','trunk','options','url','name','param','split','phone','prefix','${EXTEN}','SIP','join','indexOf','U(xcally-mixmonitor-context)','isEmpty','Interval','findAll','then','length','interval','*,*,*,*','IntervalId','map','filter','toLowerCase','hasOwnProperty','tag','CDR(tag)=','intervals','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','Set(CALLERID(all)=','callerID','NoOp(No\x20number\x20available)','playback','app','answer','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice','GotoIfTime',',${EXTEN},','outboundDial','appdata','appType','agi','priority','concat','last','catch','define','VoiceExtension','voice_extensions','get','Hangup'];(function(_0x2c729e,_0x4fa670){var _0x28645e=function(_0x5321a9){while(--_0x5321a9){_0x2c729e['push'](_0x2c729e['shift']());}};_0x28645e(++_0x4fa670);}(_0x14c4,0xa2));var _0x414c=function(_0x53c26d,_0x4ad64e){_0x53c26d=_0x53c26d-0x0;var _0x5727d6=_0x14c4[_0x53c26d];return _0x5727d6;};'use strict';var _=require(_0x414c('0x0'));var attributes=require(_0x414c('0x1'));module[_0x414c('0x2')]=function(_0x1bf646){var _0x5260ab=_0x1bf646[_0x414c('0x3')];function _0x4a6ffb(_0x485701){var _0x376a7b=0x2;var _0x2a507a=[{'type':_0x485701[_0x414c('0x4')],'app':_0x414c('0x5'),'appdata':'CDR(type)='+_0x485701[_0x414c('0x4')],'context':_0x485701[_0x414c('0x6')],'exten':_0x485701[_0x414c('0x7')],'priority':_0x376a7b++,'VoiceExtensionId':_0x485701['id']}];if(_0x485701[_0x414c('0x4')]==='inbound'){_0x2a507a['push']({'type':'inbound','app':_0x414c('0x5'),'appdata':_0x414c('0x8')+_0x485701['id'],'context':_0x485701['context'],'exten':_0x485701[_0x414c('0x7')],'priority':_0x376a7b++,'VoiceExtensionId':_0x485701['id']});}_0x2a507a[_0x414c('0x9')]({'type':_0x485701[_0x414c('0x4')],'app':'Set','appdata':_0x414c('0xa'),'context':_0x485701[_0x414c('0x6')],'exten':_0x485701['exten'],'priority':_0x376a7b++,'VoiceExtensionId':_0x485701['id']},{'type':_0x485701[_0x414c('0x4')],'app':_0x414c('0x5'),'appdata':_0x414c('0xb'),'context':_0x485701[_0x414c('0x6')],'exten':_0x485701['exten'],'priority':_0x376a7b++,'VoiceExtensionId':_0x485701['id']},{'type':_0x485701[_0x414c('0x4')],'app':_0x414c('0x5'),'appdata':_0x414c('0xc'),'context':_0x485701[_0x414c('0x6')],'exten':_0x485701['exten'],'priority':_0x376a7b++,'VoiceExtensionId':_0x485701['id']});return _0x2a507a;}function _0x7f96f7(_0x5d638e){var _0xdb259d=0x2;var _0x32f707=[{'type':'outbound','app':_0x414c('0x5'),'appdata':_0x414c('0xd'),'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e['exten'],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':'Set','appdata':'CDR(destination)='+(_0x5d638e[_0x414c('0xf')]?_0x414c('0x10')+_0x5d638e[_0x414c('0xf')]+'}':'${EXTEN}'),'context':_0x5d638e['context'],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':_0x414c('0x5'),'appdata':_0x414c('0x8')+_0x5d638e['id'],'context':_0x5d638e['context'],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':'outbound','app':_0x414c('0x11'),'appdata':_0x414c('0x12')+(_0xdb259d+0x2)+_0x414c('0x13')+(_0xdb259d+0x1)+')','context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':'Set','appdata':_0x5d638e[_0x414c('0xf')]?_0x414c('0x14')+_0x5d638e[_0x414c('0xf')]+'}':_0x414c('0x15'),'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':_0x414c('0x5'),'appdata':_0x414c('0xa'),'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e['exten'],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':_0x414c('0x5'),'appdata':_0x414c('0xb'),'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':'outbound','app':_0x414c('0x5'),'appdata':'MONITOR_OPTIONS=ab','context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':_0x414c('0x5'),'appdata':'outboundrouteid='+_0x5d638e['id'],'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e[_0x414c('0x7')],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']}];if(_0x5d638e['hasOwnProperty']('recordingFormat')&&_0x5d638e[_0x414c('0x16')]!==_0x414c('0x17')){_0x32f707[_0x414c('0x9')]({'type':_0x414c('0xe'),'app':'Set','appdata':_0x414c('0x18'),'context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e['exten'],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']},{'type':_0x414c('0xe'),'app':_0x414c('0x5'),'appdata':_0x414c('0x19')+_0x5d638e[_0x414c('0x16')]||'wav','context':_0x5d638e[_0x414c('0x6')],'exten':_0x5d638e['exten'],'priority':_0xdb259d++,'VoiceExtensionId':_0x5d638e['id']});}return _0x32f707;}function _0x3e0cbc(_0x4e89d2,_0xb62958){var _0x25411c=[{'name':_0x414c('0x1a'),'param':0x0},{'name':'timeout','param':0x1},{'name':_0x414c('0x1b'),'param':0x2},{'name':_0x414c('0x1c'),'param':0x3}];var _0x31e2bf={};var _0x4f8558=_0xb62958['split'](',');var _0x57aa07=[];for(var _0xe9845b=0x0;_0xe9845b<_0x25411c['length'];_0xe9845b++){switch(_0x25411c[_0xe9845b][_0x414c('0x1d')]){case _0x414c('0x1a'):_0x31e2bf[_0x414c('0x1a')]=_0x4f8558[_0x25411c[_0xe9845b][_0x414c('0x1e')]][_0x414c('0x1f')]('/')[0x1];_0x31e2bf[_0x414c('0x20')]=_0x4f8558[_0x25411c[_0xe9845b][_0x414c('0x1e')]][_0x414c('0x1f')]('/')[0x2];_0x31e2bf[_0x414c('0x21')]=_0x31e2bf[_0x414c('0x20')]?_0x31e2bf[_0x414c('0x20')][_0x414c('0x1f')]('$')[0x0]:undefined;_0x31e2bf[_0x414c('0x20')]=_0x4e89d2['cutdigits']?(_0x31e2bf[_0x414c('0x21')]||'')+_0x414c('0x10')+_0x4e89d2[_0x414c('0xf')]+'}':(_0x31e2bf[_0x414c('0x21')]||'')+_0x414c('0x22');_0x57aa07[_0x25411c[_0xe9845b][_0x414c('0x1e')]]=[_0x414c('0x23'),_0x31e2bf[_0x414c('0x1a')],_0x31e2bf[_0x414c('0x20')]][_0x414c('0x24')]('/');break;case _0x414c('0x1b'):_0x31e2bf[_0x414c('0x1b')]=_0x4f8558[_0x25411c[_0xe9845b]['param']];if(_0x4e89d2[_0x414c('0x16')]!=='none'){if(_0x31e2bf['options'][_0x414c('0x25')](_0x414c('0x26'))<0x0){_0x31e2bf[_0x414c('0x1b')]+='U(xcally-mixmonitor-context)';}}else{_0x31e2bf['options']=_0x31e2bf['options']['replace']('U(xcally-mixmonitor-context)','');}_0x57aa07[_0x25411c[_0xe9845b][_0x414c('0x1e')]]=_0x31e2bf[_0x414c('0x1b')];break;default:_0x57aa07[_0x25411c[_0xe9845b]['param']]=_0x4f8558[_0x25411c[_0xe9845b]['param']];}}return _0x57aa07[_0x414c('0x24')](',');}function _0x3b3f5f(_0x5d174c,_0x290641,_0xda4a05){return new Promise(function(_0x4e81b6,_0x259ab8){var _0x233c74=[];if(_[_0x414c('0x27')](_0x290641))return _0x4e81b6(_0x233c74);_0x5260ab[_0x414c('0x28')][_0x414c('0x29')]({'attributes':['id','interval','IntervalId'],'raw':!![]})[_0x414c('0x2a')](function(_0x352238){for(var _0x30a688=0x0,_0x370ff5=0x0;_0x30a688<_0x290641[_0x414c('0x2b')];_0x30a688++,_0x370ff5=0x0){var _0x27aea6=_0x290641[_0x30a688];var _0x57f069=[];var _0x69dd8e=[];delete _0x27aea6['id'];if(_0x27aea6[_0x414c('0x2c')]!==_0x414c('0x2d')){_0x27aea6['intervals']=[_0x27aea6[_0x414c('0x2c')]];}else{_0x27aea6['intervals']=_0x27aea6[_0x414c('0x2e')]?_[_0x414c('0x2f')](_[_0x414c('0x30')](_0x352238,{'IntervalId':_0x27aea6[_0x414c('0x2e')]}),_0x414c('0x2c')):[];}_0x27aea6['context']=_0x5d174c[_0x414c('0x6')];_0x27aea6[_0x414c('0x7')]=_0x5d174c[_0x414c('0x7')];if(_0x27aea6[_0x414c('0x4')])_0x27aea6[_0x414c('0x4')]=_0x27aea6[_0x414c('0x4')][_0x414c('0x31')]();if(_0x5d174c['type']==='outbound'){if(_0x27aea6[_0x414c('0x32')](_0x414c('0x33'))&&_0x27aea6['tag']&&_0x27aea6[_0x414c('0x33')]!=='--'){_0x57f069[_0x414c('0x9')]({'type':_0x27aea6[_0x414c('0x4')][_0x414c('0x31')](),'app':_0x414c('0x5'),'appdata':_0x414c('0x34')+_0x27aea6['tag'],'context':_0x5d174c[_0x414c('0x6')],'exten':_0x5d174c['exten'],'priority':_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});}_0x57f069[_0x414c('0x9')]({'type':_0x27aea6['type']['toLowerCase'](),'app':'ExecIf','appdata':_0x414c('0x36')+(_0x27aea6['callerID']?_0x414c('0x37')+_0x27aea6[_0x414c('0x38')]+')':_0x414c('0x39')),'context':_0x5d174c['context'],'exten':_0x5d174c[_0x414c('0x7')],'priority':_0x27aea6[_0x414c('0x35')]['length']+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});}else{if(_0x27aea6['hasOwnProperty']('answer')){if(['queue',_0x414c('0x3a')]['includes'](_0x27aea6[_0x414c('0x3b')][_0x414c('0x31')]())&&_0x27aea6['appType']!=='custom'){if(_0x27aea6[_0x414c('0x3c')]){_0x57f069[_0x414c('0x9')]({'type':_0x27aea6[_0x414c('0x4')][_0x414c('0x31')](),'app':_0x414c('0x11'),'appdata':_0x414c('0x3d'),'context':_0x5d174c['context'],'exten':_0x5d174c[_0x414c('0x7')],'priority':_0x27aea6['intervals'][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});_0x57f069[_0x414c('0x9')]({'type':_0x27aea6[_0x414c('0x4')]['toLowerCase'](),'app':_0x414c('0x5'),'appdata':_0x414c('0x3e'),'context':_0x5d174c[_0x414c('0x6')],'exten':_0x5d174c['exten'],'priority':_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});}else{_0x57f069[_0x414c('0x9')]({'type':_0x27aea6[_0x414c('0x4')][_0x414c('0x31')](),'app':_0x414c('0x11'),'appdata':_0x414c('0x3f'),'context':_0x5d174c[_0x414c('0x6')],'exten':_0x5d174c['exten'],'priority':_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});_0x57f069[_0x414c('0x9')]({'type':_0x27aea6[_0x414c('0x4')][_0x414c('0x31')](),'app':'Set','appdata':_0x414c('0x40'),'context':_0x5d174c['context'],'exten':_0x5d174c[_0x414c('0x7')],'priority':_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});}}}}for(var _0x1208df=0x0;_0x1208df<_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')];_0x1208df++){var _0x84638e=_0xda4a05+_0x27aea6['intervals'][_0x414c('0x2b')];var _0xb8b5f5=_0x1208df===_0x27aea6[_0x414c('0x35')]['length']-0x1?_0xda4a05+_0x57f069['length']+_0x69dd8e[_0x414c('0x2b')]+0x2:_0xda4a05+_0x1208df+0x1;_0x57f069[_0x414c('0x41')](_0x1208df,0x0,{'type':_0x5d174c[_0x414c('0x4')],'app':_0x414c('0x42'),'appdata':_0x27aea6[_0x414c('0x35')][_0x1208df]+'?'+_0x5d174c['context']+_0x414c('0x43')+_0x84638e+':'+_0x5d174c['context']+_0x414c('0x43')+_0xb8b5f5,'exten':_0x5d174c[_0x414c('0x7')],'context':_0x5d174c[_0x414c('0x6')],'priority':_0xda4a05+_0x1208df,'VoiceExtensionId':_0x5d174c['id']});}if(_0x27aea6['appType']===_0x414c('0x44')){_0x27aea6[_0x414c('0x45')]=_0x3e0cbc(_0x5d174c,_0x27aea6['appdata']);}if(_0x27aea6[_0x414c('0x46')]===_0x414c('0x47')){_0x57f069[_0x414c('0x9')]({'type':_0x27aea6['type'][_0x414c('0x31')](),'app':'Set','appdata':'XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','context':_0x5d174c[_0x414c('0x6')],'exten':_0x5d174c[_0x414c('0x7')],'priority':_0x27aea6[_0x414c('0x35')][_0x414c('0x2b')]+_0xda4a05+_0x370ff5++,'VoiceExtensionId':_0x5d174c['id']});}_0x27aea6[_0x414c('0x48')]=_0x57f069['length']?_['last'](_0x57f069)[_0x414c('0x48')]+0x1:_0xda4a05;_0x233c74=_[_0x414c('0x49')](_0x233c74,_0x57f069,[_0x27aea6],_0x69dd8e);_0xda4a05=_[_0x414c('0x4a')](_0x233c74)['priority']+0x1;}return _0x4e81b6(_0x233c74);})[_0x414c('0x4b')](function(_0x3f643d){_0x259ab8(_0x3f643d);});});}return _0x1bf646[_0x414c('0x4c')](_0x414c('0x4d'),attributes,{'tableName':_0x414c('0x4e'),'paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x30a9ae){var _0x518a2d=this[_0x414c('0x4f')]({'plain':!![]});var _0x3cc6ed=_0x518a2d[_0x414c('0x4')]===_0x414c('0xe')?_0x7f96f7(_0x518a2d):_0x4a6ffb(_0x518a2d);return _0x3b3f5f(_0x518a2d,_0x30a9ae,_[_0x414c('0x4a')](_0x3cc6ed)[_0x414c('0x48')]+0x1)[_0x414c('0x2a')](function(_0x52928f){var _0x5a0f15=_['concat'](_0x3cc6ed,_0x52928f);_0x5a0f15[_0x414c('0x9')]({'type':_0x518a2d['type'],'app':_0x414c('0x50'),'exten':_0x518a2d['exten'],'context':_0x518a2d[_0x414c('0x6')],'priority':_[_0x414c('0x4a')](_0x5a0f15)[_0x414c('0x48')]+0x1,'VoiceExtensionId':_0x518a2d['id']});return _0x5a0f15;});}}});};