Built motion from commit 980b26c3.|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 _0xb2b6=['catch','define','VoiceExtension','get','then','Hangup','models','type','Set','CDR(type)=','context','push','CDR(routeid)=','exten','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','outbound','CDR(type)=outbound','CDR(destination)=','cutdigits','${EXTEN:','${EXTEN}','ExecIf','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','CDR(prefix)=${EXTEN:0:','CDR(prefix)=noprefix','MONITOR_OPTIONS=ab','outboundrouteid=','hasOwnProperty','recordingFormat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','_XCALLY_MIXMONITOR_FORMAT=','wav','trunk','timeout','options','url','split','length','param','phone','prefix','none','indexOf','U(xcally-mixmonitor-context)','join','Interval','findAll','interval','IntervalId','*,*,*,*','intervals','filter','toLowerCase','tag','CDR(tag)=','Set(CALLERID(all)=','callerID','NoOp(No\x20number\x20available)','playback','includes','app','custom','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','appdata','appType','agi','priority','last','concat'];(function(_0x2ace6b,_0x1fa5cb){var _0x45992a=function(_0xcec921){while(--_0xcec921){_0x2ace6b['push'](_0x2ace6b['shift']());}};_0x45992a(++_0x1fa5cb);}(_0xb2b6,0x173));var _0x6b2b=function(_0x4559e2,_0x30086b){_0x4559e2=_0x4559e2-0x0;var _0x463d14=_0xb2b6[_0x4559e2];return _0x463d14;};'use strict';var _=require('lodash');var attributes=require('./voiceExtension.attributes');module['exports']=function(_0x1aa0cc){var _0x481843=_0x1aa0cc[_0x6b2b('0x0')];function _0x38af21(_0x153dba){var _0x41ab34=0x2;var _0x54bdd2=[{'type':_0x153dba[_0x6b2b('0x1')],'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x3')+_0x153dba[_0x6b2b('0x1')],'context':_0x153dba[_0x6b2b('0x4')],'exten':_0x153dba['exten'],'priority':_0x41ab34++,'VoiceExtensionId':_0x153dba['id']}];if(_0x153dba[_0x6b2b('0x1')]==='inbound'){_0x54bdd2[_0x6b2b('0x5')]({'type':'inbound','app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x6')+_0x153dba['id'],'context':_0x153dba[_0x6b2b('0x4')],'exten':_0x153dba[_0x6b2b('0x7')],'priority':_0x41ab34++,'VoiceExtensionId':_0x153dba['id']});}_0x54bdd2[_0x6b2b('0x5')]({'type':_0x153dba['type'],'app':'Set','appdata':_0x6b2b('0x8'),'context':_0x153dba['context'],'exten':_0x153dba['exten'],'priority':_0x41ab34++,'VoiceExtensionId':_0x153dba['id']},{'type':_0x153dba[_0x6b2b('0x1')],'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x9'),'context':_0x153dba[_0x6b2b('0x4')],'exten':_0x153dba[_0x6b2b('0x7')],'priority':_0x41ab34++,'VoiceExtensionId':_0x153dba['id']},{'type':_0x153dba[_0x6b2b('0x1')],'app':_0x6b2b('0x2'),'appdata':'MONITOR_OPTIONS=ab','context':_0x153dba[_0x6b2b('0x4')],'exten':_0x153dba[_0x6b2b('0x7')],'priority':_0x41ab34++,'VoiceExtensionId':_0x153dba['id']});return _0x54bdd2;}function _0x2cb8f6(_0x35e5fe){var _0x2a8941=0x2;var _0x4282bd=[{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0xb'),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0xc')+(_0x35e5fe[_0x6b2b('0xd')]?_0x6b2b('0xe')+_0x35e5fe[_0x6b2b('0xd')]+'}':_0x6b2b('0xf')),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':'CDR(routeid)='+_0x35e5fe['id'],'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x10'),'appdata':_0x6b2b('0x11')+(_0x2a8941+0x2)+'):Goto('+(_0x2a8941+0x1)+')','context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':_0x35e5fe['cutdigits']?_0x6b2b('0x12')+_0x35e5fe['cutdigits']+'}':_0x6b2b('0x13'),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':'Set','appdata':'XCALLY-MOTION-ANSWER=0','context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':'outbound','app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x9'),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe['exten'],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x14'),'context':_0x35e5fe['context'],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':'outbound','app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x15')+_0x35e5fe['id'],'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']}];if(_0x35e5fe[_0x6b2b('0x16')](_0x6b2b('0x17'))&&_0x35e5fe[_0x6b2b('0x17')]!=='none'){_0x4282bd[_0x6b2b('0x5')]({'type':'outbound','app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x18'),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe['exten'],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']},{'type':_0x6b2b('0xa'),'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x19')+_0x35e5fe[_0x6b2b('0x17')]||_0x6b2b('0x1a'),'context':_0x35e5fe[_0x6b2b('0x4')],'exten':_0x35e5fe[_0x6b2b('0x7')],'priority':_0x2a8941++,'VoiceExtensionId':_0x35e5fe['id']});}return _0x4282bd;}function _0x3e2496(_0x10eeaa,_0x595233){var _0x118242=[{'name':_0x6b2b('0x1b'),'param':0x0},{'name':_0x6b2b('0x1c'),'param':0x1},{'name':_0x6b2b('0x1d'),'param':0x2},{'name':_0x6b2b('0x1e'),'param':0x3}];var _0x3825a6={};var _0x1ef108=_0x595233[_0x6b2b('0x1f')](',');var _0x453cc5=[];for(var _0x58e032=0x0;_0x58e032<_0x118242[_0x6b2b('0x20')];_0x58e032++){switch(_0x118242[_0x58e032]['name']){case _0x6b2b('0x1b'):_0x3825a6[_0x6b2b('0x1b')]=_0x1ef108[_0x118242[_0x58e032][_0x6b2b('0x21')]][_0x6b2b('0x1f')]('/')[0x1];_0x3825a6[_0x6b2b('0x22')]=_0x1ef108[_0x118242[_0x58e032][_0x6b2b('0x21')]][_0x6b2b('0x1f')]('/')[0x2];_0x3825a6[_0x6b2b('0x23')]=_0x3825a6['phone']?_0x3825a6[_0x6b2b('0x22')]['split']('$')[0x0]:undefined;_0x3825a6[_0x6b2b('0x22')]=_0x10eeaa['cutdigits']?(_0x3825a6[_0x6b2b('0x23')]||'')+_0x6b2b('0xe')+_0x10eeaa[_0x6b2b('0xd')]+'}':(_0x3825a6[_0x6b2b('0x23')]||'')+_0x6b2b('0xf');_0x453cc5[_0x118242[_0x58e032][_0x6b2b('0x21')]]=['SIP',_0x3825a6[_0x6b2b('0x1b')],_0x3825a6[_0x6b2b('0x22')]]['join']('/');break;case _0x6b2b('0x1d'):_0x3825a6['options']=_0x1ef108[_0x118242[_0x58e032][_0x6b2b('0x21')]];if(_0x10eeaa[_0x6b2b('0x17')]!==_0x6b2b('0x24')){if(_0x3825a6[_0x6b2b('0x1d')][_0x6b2b('0x25')](_0x6b2b('0x26'))<0x0){_0x3825a6[_0x6b2b('0x1d')]+='U(xcally-mixmonitor-context)';}}else{_0x3825a6[_0x6b2b('0x1d')]=_0x3825a6[_0x6b2b('0x1d')]['replace'](_0x6b2b('0x26'),'');}_0x453cc5[_0x118242[_0x58e032]['param']]=_0x3825a6[_0x6b2b('0x1d')];break;default:_0x453cc5[_0x118242[_0x58e032][_0x6b2b('0x21')]]=_0x1ef108[_0x118242[_0x58e032]['param']];}}return _0x453cc5[_0x6b2b('0x27')](',');}function _0xaffe6(_0xb5c36,_0x149313,_0x284425){return new Promise(function(_0x5249c7,_0x5aedd7){var _0x5a4149=[];if(_['isEmpty'](_0x149313))return _0x5249c7(_0x5a4149);_0x481843[_0x6b2b('0x28')][_0x6b2b('0x29')]({'attributes':['id',_0x6b2b('0x2a'),_0x6b2b('0x2b')],'raw':!![]})['then'](function(_0x28a4b3){for(var _0x65a0df=0x0,_0xb12259=0x0;_0x65a0df<_0x149313[_0x6b2b('0x20')];_0x65a0df++,_0xb12259=0x0){var _0x4a93f6=_0x149313[_0x65a0df];var _0x3eb194=[];var _0x3cc297=[];delete _0x4a93f6['id'];if(_0x4a93f6[_0x6b2b('0x2a')]!==_0x6b2b('0x2c')){_0x4a93f6['intervals']=[_0x4a93f6[_0x6b2b('0x2a')]];}else{_0x4a93f6[_0x6b2b('0x2d')]=_0x4a93f6[_0x6b2b('0x2b')]?_['map'](_[_0x6b2b('0x2e')](_0x28a4b3,{'IntervalId':_0x4a93f6[_0x6b2b('0x2b')]}),_0x6b2b('0x2a')):[];}_0x4a93f6[_0x6b2b('0x4')]=_0xb5c36[_0x6b2b('0x4')];_0x4a93f6['exten']=_0xb5c36[_0x6b2b('0x7')];if(_0x4a93f6[_0x6b2b('0x1')])_0x4a93f6[_0x6b2b('0x1')]=_0x4a93f6['type'][_0x6b2b('0x2f')]();if(_0xb5c36['type']==='outbound'){if(_0x4a93f6[_0x6b2b('0x16')](_0x6b2b('0x30'))&&_0x4a93f6[_0x6b2b('0x30')]&&_0x4a93f6[_0x6b2b('0x30')]!=='--'){_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')][_0x6b2b('0x2f')](),'app':'Set','appdata':_0x6b2b('0x31')+_0x4a93f6[_0x6b2b('0x30')],'context':_0xb5c36['context'],'exten':_0xb5c36['exten'],'priority':_0x4a93f6[_0x6b2b('0x2d')]['length']+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});}_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')]['toLowerCase'](),'app':_0x6b2b('0x10'),'appdata':'$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):'+(_0x4a93f6['callerID']?_0x6b2b('0x32')+_0x4a93f6[_0x6b2b('0x33')]+')':_0x6b2b('0x34')),'context':_0xb5c36[_0x6b2b('0x4')],'exten':_0xb5c36[_0x6b2b('0x7')],'priority':_0x4a93f6['intervals']['length']+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});}else{if(_0x4a93f6[_0x6b2b('0x16')]('answer')){if(['queue',_0x6b2b('0x35')][_0x6b2b('0x36')](_0x4a93f6[_0x6b2b('0x37')][_0x6b2b('0x2f')]())&&_0x4a93f6['appType']!==_0x6b2b('0x38')){if(_0x4a93f6['answer']){_0x3eb194['push']({'type':_0x4a93f6[_0x6b2b('0x1')][_0x6b2b('0x2f')](),'app':_0x6b2b('0x10'),'appdata':'$[${XCALLY-MOTION-ANSWER}=0]?Answer','context':_0xb5c36['context'],'exten':_0xb5c36[_0x6b2b('0x7')],'priority':_0x4a93f6[_0x6b2b('0x2d')][_0x6b2b('0x20')]+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')]['toLowerCase'](),'app':'Set','appdata':'XCALLY-MOTION-ANSWER=1','context':_0xb5c36[_0x6b2b('0x4')],'exten':_0xb5c36[_0x6b2b('0x7')],'priority':_0x4a93f6[_0x6b2b('0x2d')][_0x6b2b('0x20')]+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});}else{_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')][_0x6b2b('0x2f')](),'app':_0x6b2b('0x10'),'appdata':_0x6b2b('0x39'),'context':_0xb5c36[_0x6b2b('0x4')],'exten':_0xb5c36[_0x6b2b('0x7')],'priority':_0x4a93f6['intervals']['length']+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')][_0x6b2b('0x2f')](),'app':_0x6b2b('0x2'),'appdata':_0x6b2b('0x3a'),'context':_0xb5c36[_0x6b2b('0x4')],'exten':_0xb5c36[_0x6b2b('0x7')],'priority':_0x4a93f6[_0x6b2b('0x2d')][_0x6b2b('0x20')]+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});}}}}for(var _0x379393=0x0;_0x379393<_0x4a93f6[_0x6b2b('0x2d')]['length'];_0x379393++){var _0x227aa4=_0x284425+_0x4a93f6[_0x6b2b('0x2d')][_0x6b2b('0x20')];var _0x2feeaa=_0x379393===_0x4a93f6['intervals'][_0x6b2b('0x20')]-0x1?_0x284425+_0x3eb194[_0x6b2b('0x20')]+_0x3cc297['length']+0x2:_0x284425+_0x379393+0x1;_0x3eb194[_0x6b2b('0x3b')](_0x379393,0x0,{'type':_0xb5c36[_0x6b2b('0x1')],'app':'GotoIfTime','appdata':_0x4a93f6['intervals'][_0x379393]+'?'+_0xb5c36[_0x6b2b('0x4')]+_0x6b2b('0x3c')+_0x227aa4+':'+_0xb5c36[_0x6b2b('0x4')]+_0x6b2b('0x3c')+_0x2feeaa,'exten':_0xb5c36[_0x6b2b('0x7')],'context':_0xb5c36[_0x6b2b('0x4')],'priority':_0x284425+_0x379393,'VoiceExtensionId':_0xb5c36['id']});}if(_0x4a93f6['appType']==='outboundDial'){_0x4a93f6[_0x6b2b('0x3d')]=_0x3e2496(_0xb5c36,_0x4a93f6[_0x6b2b('0x3d')]);}if(_0x4a93f6[_0x6b2b('0x3e')]===_0x6b2b('0x3f')){_0x3eb194[_0x6b2b('0x5')]({'type':_0x4a93f6[_0x6b2b('0x1')]['toLowerCase'](),'app':_0x6b2b('0x2'),'appdata':'XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','context':_0xb5c36[_0x6b2b('0x4')],'exten':_0xb5c36['exten'],'priority':_0x4a93f6['intervals']['length']+_0x284425+_0xb12259++,'VoiceExtensionId':_0xb5c36['id']});}_0x4a93f6[_0x6b2b('0x40')]=_0x3eb194[_0x6b2b('0x20')]?_[_0x6b2b('0x41')](_0x3eb194)[_0x6b2b('0x40')]+0x1:_0x284425;_0x5a4149=_[_0x6b2b('0x42')](_0x5a4149,_0x3eb194,[_0x4a93f6],_0x3cc297);_0x284425=_[_0x6b2b('0x41')](_0x5a4149)[_0x6b2b('0x40')]+0x1;}return _0x5249c7(_0x5a4149);})[_0x6b2b('0x43')](function(_0x440b0e){_0x5aedd7(_0x440b0e);});});}return _0x1aa0cc[_0x6b2b('0x44')](_0x6b2b('0x45'),attributes,{'tableName':'voice_extensions','paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x34f9d5){var _0x3fbd3d=this[_0x6b2b('0x46')]({'plain':!![]});var _0x5c755e=_0x3fbd3d[_0x6b2b('0x1')]===_0x6b2b('0xa')?_0x2cb8f6(_0x3fbd3d):_0x38af21(_0x3fbd3d);return _0xaffe6(_0x3fbd3d,_0x34f9d5,_[_0x6b2b('0x41')](_0x5c755e)[_0x6b2b('0x40')]+0x1)[_0x6b2b('0x47')](function(_0x3b8023){var _0x38a811=_[_0x6b2b('0x42')](_0x5c755e,_0x3b8023);_0x38a811[_0x6b2b('0x5')]({'type':_0x3fbd3d[_0x6b2b('0x1')],'app':_0x6b2b('0x48'),'exten':_0x3fbd3d[_0x6b2b('0x7')],'context':_0x3fbd3d[_0x6b2b('0x4')],'priority':_[_0x6b2b('0x41')](_0x38a811)[_0x6b2b('0x40')]+0x1,'VoiceExtensionId':_0x3fbd3d['id']});return _0x38a811;});}}});};