Built motion from commit b0a9a629.|2.6.33
[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 _0x5814=['intervals','map','filter','tag','CDR(tag)=','$[${LEN(${PREFIX-CALLERIDALL})}\x20>\x200]?Set(CALLERID(all)=${PREFIX-CALLERIDALL}):','callerID','Set(CALLERID(all)=','NoOp(No\x20number\x20available)','answer','playback','includes','app','appType','toLowerCase','ExecIf','$[${XCALLY-MOTION-ANSWER}=0]?Answer','XCALLY-MOTION-ANSWER=1','$[${XCALLY-MOTION-PROGRESS}=0]?Progress','XCALLY-MOTION-PROGRESS=1','splice',',${EXTEN},','appdata','agi','XMCS-UNIQUEID=${CHANNEL(LINKEDID)}','priority','last','concat','define','VoiceExtension','get','Hangup','lodash','./voiceExtension.attributes','exports','type','CDR(type)=','context','exten','inbound','push','Set','CDR(routeid)=','XCALLY-MOTION-ANSWER=0','XCALLY-MOTION-PROGRESS=0','MONITOR_OPTIONS=ab','outbound','CDR(type)=outbound','cutdigits','$[${LEN(${CDR(prefix)})}\x20>\x200]?Goto(','):Goto(','CDR(prefix)=noprefix','outboundrouteid=','hasOwnProperty','recordingFormat','none','_XCALLY_MIXMONITOR_FORMAT=','wav','trunk','options','url','split','length','param','prefix','phone','${EXTEN:','${EXTEN}','SIP','join','indexOf','U(xcally-mixmonitor-context)','replace','isEmpty','Interval','interval','IntervalId','then'];(function(_0x2a8606,_0xcbed1e){var _0x307a2e=function(_0x26554a){while(--_0x26554a){_0x2a8606['push'](_0x2a8606['shift']());}};_0x307a2e(++_0xcbed1e);}(_0x5814,0x6e));var _0x4581=function(_0x10020f,_0x4af5f0){_0x10020f=_0x10020f-0x0;var _0x2b58a4=_0x5814[_0x10020f];return _0x2b58a4;};'use strict';var _=require(_0x4581('0x0'));var attributes=require(_0x4581('0x1'));module[_0x4581('0x2')]=function(_0xa24c1f){var _0x9cb452=_0xa24c1f['models'];function _0x52cea2(_0x2a1d5b){var _0x23e61a=0x2;var _0x3e873a=[{'type':_0x2a1d5b[_0x4581('0x3')],'app':'Set','appdata':_0x4581('0x4')+_0x2a1d5b[_0x4581('0x3')],'context':_0x2a1d5b[_0x4581('0x5')],'exten':_0x2a1d5b[_0x4581('0x6')],'priority':_0x23e61a++,'VoiceExtensionId':_0x2a1d5b['id']}];if(_0x2a1d5b['type']===_0x4581('0x7')){_0x3e873a[_0x4581('0x8')]({'type':_0x4581('0x7'),'app':_0x4581('0x9'),'appdata':_0x4581('0xa')+_0x2a1d5b['id'],'context':_0x2a1d5b[_0x4581('0x5')],'exten':_0x2a1d5b[_0x4581('0x6')],'priority':_0x23e61a++,'VoiceExtensionId':_0x2a1d5b['id']});}_0x3e873a[_0x4581('0x8')]({'type':_0x2a1d5b[_0x4581('0x3')],'app':'Set','appdata':_0x4581('0xb'),'context':_0x2a1d5b[_0x4581('0x5')],'exten':_0x2a1d5b['exten'],'priority':_0x23e61a++,'VoiceExtensionId':_0x2a1d5b['id']},{'type':_0x2a1d5b['type'],'app':_0x4581('0x9'),'appdata':_0x4581('0xc'),'context':_0x2a1d5b[_0x4581('0x5')],'exten':_0x2a1d5b[_0x4581('0x6')],'priority':_0x23e61a++,'VoiceExtensionId':_0x2a1d5b['id']},{'type':_0x2a1d5b[_0x4581('0x3')],'app':_0x4581('0x9'),'appdata':_0x4581('0xd'),'context':_0x2a1d5b[_0x4581('0x5')],'exten':_0x2a1d5b[_0x4581('0x6')],'priority':_0x23e61a++,'VoiceExtensionId':_0x2a1d5b['id']});return _0x3e873a;}function _0x5d1453(_0x54262b){var _0xc4d7a9=0x2;var _0x5c7c04=[{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0xf'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':'outbound','app':'Set','appdata':'CDR(destination)='+(_0x54262b[_0x4581('0x10')]?'${EXTEN:'+_0x54262b[_0x4581('0x10')]+'}':'${EXTEN}'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b['exten'],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0xa')+_0x54262b['id'],'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':'outbound','app':'ExecIf','appdata':_0x4581('0x11')+(_0xc4d7a9+0x2)+_0x4581('0x12')+(_0xc4d7a9+0x1)+')','context':_0x54262b['context'],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':'outbound','app':_0x4581('0x9'),'appdata':_0x54262b['cutdigits']?'CDR(prefix)=${EXTEN:0:'+_0x54262b[_0x4581('0x10')]+'}':_0x4581('0x13'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0xb'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0xc'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0xd'),'context':_0x54262b['context'],'exten':_0x54262b['exten'],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0x14')+_0x54262b['id'],'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']}];if(_0x54262b[_0x4581('0x15')](_0x4581('0x16'))&&_0x54262b[_0x4581('0x16')]!==_0x4581('0x17')){_0x5c7c04[_0x4581('0x8')]({'type':_0x4581('0xe'),'app':'Set','appdata':'_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b[_0x4581('0x6')],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']},{'type':_0x4581('0xe'),'app':_0x4581('0x9'),'appdata':_0x4581('0x18')+_0x54262b[_0x4581('0x16')]||_0x4581('0x19'),'context':_0x54262b[_0x4581('0x5')],'exten':_0x54262b['exten'],'priority':_0xc4d7a9++,'VoiceExtensionId':_0x54262b['id']});}return _0x5c7c04;}function _0x141441(_0x28d436,_0x519555){var _0x2445d0=[{'name':_0x4581('0x1a'),'param':0x0},{'name':'timeout','param':0x1},{'name':_0x4581('0x1b'),'param':0x2},{'name':_0x4581('0x1c'),'param':0x3}];var _0x33ebe6={};var _0xc2720f=_0x519555[_0x4581('0x1d')](',');var _0x2d544d=[];for(var _0x16ea29=0x0;_0x16ea29<_0x2445d0[_0x4581('0x1e')];_0x16ea29++){switch(_0x2445d0[_0x16ea29]['name']){case _0x4581('0x1a'):_0x33ebe6[_0x4581('0x1a')]=_0xc2720f[_0x2445d0[_0x16ea29][_0x4581('0x1f')]][_0x4581('0x1d')]('/')[0x1];_0x33ebe6['phone']=_0xc2720f[_0x2445d0[_0x16ea29][_0x4581('0x1f')]][_0x4581('0x1d')]('/')[0x2];_0x33ebe6[_0x4581('0x20')]=_0x33ebe6[_0x4581('0x21')]?_0x33ebe6[_0x4581('0x21')]['split']('$')[0x0]:undefined;_0x33ebe6[_0x4581('0x21')]=_0x28d436[_0x4581('0x10')]?(_0x33ebe6[_0x4581('0x20')]||'')+_0x4581('0x22')+_0x28d436[_0x4581('0x10')]+'}':(_0x33ebe6['prefix']||'')+_0x4581('0x23');_0x2d544d[_0x2445d0[_0x16ea29][_0x4581('0x1f')]]=[_0x4581('0x24'),_0x33ebe6[_0x4581('0x1a')],_0x33ebe6[_0x4581('0x21')]][_0x4581('0x25')]('/');break;case _0x4581('0x1b'):_0x33ebe6[_0x4581('0x1b')]=_0xc2720f[_0x2445d0[_0x16ea29][_0x4581('0x1f')]];if(_0x28d436[_0x4581('0x16')]!==_0x4581('0x17')){if(_0x33ebe6['options'][_0x4581('0x26')](_0x4581('0x27'))<0x0){_0x33ebe6[_0x4581('0x1b')]+=_0x4581('0x27');}}else{_0x33ebe6[_0x4581('0x1b')]=_0x33ebe6[_0x4581('0x1b')][_0x4581('0x28')](_0x4581('0x27'),'');}_0x2d544d[_0x2445d0[_0x16ea29][_0x4581('0x1f')]]=_0x33ebe6[_0x4581('0x1b')];break;default:_0x2d544d[_0x2445d0[_0x16ea29][_0x4581('0x1f')]]=_0xc2720f[_0x2445d0[_0x16ea29][_0x4581('0x1f')]];}}return _0x2d544d[_0x4581('0x25')](',');}function _0x5ea1ad(_0x565d69,_0x197d08,_0x515d6f){return new Promise(function(_0x45c496,_0x60f31d){var _0x343bfd=[];if(_[_0x4581('0x29')](_0x197d08))return _0x45c496(_0x343bfd);_0x9cb452[_0x4581('0x2a')]['findAll']({'attributes':['id',_0x4581('0x2b'),_0x4581('0x2c')],'raw':!![]})[_0x4581('0x2d')](function(_0x46edf9){for(var _0x5de704=0x0,_0x17f25a=0x0;_0x5de704<_0x197d08[_0x4581('0x1e')];_0x5de704++,_0x17f25a=0x0){var _0x2f25f2=_0x197d08[_0x5de704];var _0x3c071c=[];var _0x3109ea=[];delete _0x2f25f2['id'];if(_0x2f25f2[_0x4581('0x2b')]!=='*,*,*,*'){_0x2f25f2[_0x4581('0x2e')]=[_0x2f25f2[_0x4581('0x2b')]];}else{_0x2f25f2[_0x4581('0x2e')]=_0x2f25f2['IntervalId']?_[_0x4581('0x2f')](_[_0x4581('0x30')](_0x46edf9,{'IntervalId':_0x2f25f2[_0x4581('0x2c')]}),_0x4581('0x2b')):[];}_0x2f25f2[_0x4581('0x5')]=_0x565d69[_0x4581('0x5')];_0x2f25f2[_0x4581('0x6')]=_0x565d69[_0x4581('0x6')];if(_0x2f25f2[_0x4581('0x3')])_0x2f25f2[_0x4581('0x3')]=_0x2f25f2[_0x4581('0x3')]['toLowerCase']();if(_0x565d69[_0x4581('0x3')]===_0x4581('0xe')){if(_0x2f25f2[_0x4581('0x15')]('tag')&&_0x2f25f2[_0x4581('0x31')]&&_0x2f25f2[_0x4581('0x31')]!=='--'){_0x3c071c[_0x4581('0x8')]({'type':_0x2f25f2[_0x4581('0x3')]['toLowerCase'](),'app':_0x4581('0x9'),'appdata':_0x4581('0x32')+_0x2f25f2[_0x4581('0x31')],'context':_0x565d69[_0x4581('0x5')],'exten':_0x565d69[_0x4581('0x6')],'priority':_0x2f25f2['intervals'][_0x4581('0x1e')]+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});}_0x3c071c['push']({'type':_0x2f25f2[_0x4581('0x3')]['toLowerCase'](),'app':'ExecIf','appdata':_0x4581('0x33')+(_0x2f25f2[_0x4581('0x34')]?_0x4581('0x35')+_0x2f25f2[_0x4581('0x34')]+')':_0x4581('0x36')),'context':_0x565d69[_0x4581('0x5')],'exten':_0x565d69[_0x4581('0x6')],'priority':_0x2f25f2[_0x4581('0x2e')]['length']+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});}else{if(_0x2f25f2[_0x4581('0x15')](_0x4581('0x37'))){if(['queue',_0x4581('0x38')][_0x4581('0x39')](_0x2f25f2[_0x4581('0x3a')]['toLowerCase']())&&_0x2f25f2[_0x4581('0x3b')]!=='custom'){if(_0x2f25f2[_0x4581('0x37')]){_0x3c071c[_0x4581('0x8')]({'type':_0x2f25f2[_0x4581('0x3')][_0x4581('0x3c')](),'app':_0x4581('0x3d'),'appdata':_0x4581('0x3e'),'context':_0x565d69[_0x4581('0x5')],'exten':_0x565d69['exten'],'priority':_0x2f25f2[_0x4581('0x2e')]['length']+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});_0x3c071c[_0x4581('0x8')]({'type':_0x2f25f2[_0x4581('0x3')]['toLowerCase'](),'app':_0x4581('0x9'),'appdata':_0x4581('0x3f'),'context':_0x565d69[_0x4581('0x5')],'exten':_0x565d69[_0x4581('0x6')],'priority':_0x2f25f2['intervals'][_0x4581('0x1e')]+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});}else{_0x3c071c[_0x4581('0x8')]({'type':_0x2f25f2[_0x4581('0x3')][_0x4581('0x3c')](),'app':_0x4581('0x3d'),'appdata':_0x4581('0x40'),'context':_0x565d69['context'],'exten':_0x565d69[_0x4581('0x6')],'priority':_0x2f25f2[_0x4581('0x2e')][_0x4581('0x1e')]+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});_0x3c071c[_0x4581('0x8')]({'type':_0x2f25f2[_0x4581('0x3')][_0x4581('0x3c')](),'app':_0x4581('0x9'),'appdata':_0x4581('0x41'),'context':_0x565d69['context'],'exten':_0x565d69[_0x4581('0x6')],'priority':_0x2f25f2[_0x4581('0x2e')]['length']+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});}}}}for(var _0x205cd0=0x0;_0x205cd0<_0x2f25f2[_0x4581('0x2e')][_0x4581('0x1e')];_0x205cd0++){var _0x11c617=_0x515d6f+_0x2f25f2[_0x4581('0x2e')][_0x4581('0x1e')];var _0x435200=_0x205cd0===_0x2f25f2[_0x4581('0x2e')][_0x4581('0x1e')]-0x1?_0x515d6f+_0x3c071c['length']+_0x3109ea[_0x4581('0x1e')]+0x2:_0x515d6f+_0x205cd0+0x1;_0x3c071c[_0x4581('0x42')](_0x205cd0,0x0,{'type':_0x565d69[_0x4581('0x3')],'app':'GotoIfTime','appdata':_0x2f25f2['intervals'][_0x205cd0]+'?'+_0x565d69[_0x4581('0x5')]+',${EXTEN},'+_0x11c617+':'+_0x565d69[_0x4581('0x5')]+_0x4581('0x43')+_0x435200,'exten':_0x565d69[_0x4581('0x6')],'context':_0x565d69[_0x4581('0x5')],'priority':_0x515d6f+_0x205cd0,'VoiceExtensionId':_0x565d69['id']});}if(_0x2f25f2[_0x4581('0x3b')]==='outboundDial'){_0x2f25f2['appdata']=_0x141441(_0x565d69,_0x2f25f2[_0x4581('0x44')]);}if(_0x2f25f2['appType']===_0x4581('0x45')){_0x3c071c['push']({'type':_0x2f25f2['type'][_0x4581('0x3c')](),'app':'Set','appdata':_0x4581('0x46'),'context':_0x565d69[_0x4581('0x5')],'exten':_0x565d69['exten'],'priority':_0x2f25f2[_0x4581('0x2e')]['length']+_0x515d6f+_0x17f25a++,'VoiceExtensionId':_0x565d69['id']});}_0x2f25f2[_0x4581('0x47')]=_0x3c071c[_0x4581('0x1e')]?_[_0x4581('0x48')](_0x3c071c)[_0x4581('0x47')]+0x1:_0x515d6f;_0x343bfd=_[_0x4581('0x49')](_0x343bfd,_0x3c071c,[_0x2f25f2],_0x3109ea);_0x515d6f=_[_0x4581('0x48')](_0x343bfd)['priority']+0x1;}return _0x45c496(_0x343bfd);})['catch'](function(_0x50c74a){_0x60f31d(_0x50c74a);});});}return _0xa24c1f[_0x4581('0x4a')](_0x4581('0x4b'),attributes,{'tableName':'voice_extensions','paranoid':![],'indexes':[],'timestamps':!![],'instanceMethods':{'createRouting':function(_0x1f0717){var _0xd3bd8f=this[_0x4581('0x4c')]({'plain':!![]});var _0x4191d1=_0xd3bd8f[_0x4581('0x3')]===_0x4581('0xe')?_0x5d1453(_0xd3bd8f):_0x52cea2(_0xd3bd8f);return _0x5ea1ad(_0xd3bd8f,_0x1f0717,_[_0x4581('0x48')](_0x4191d1)[_0x4581('0x47')]+0x1)[_0x4581('0x2d')](function(_0x5f1db8){var _0x56d256=_[_0x4581('0x49')](_0x4191d1,_0x5f1db8);_0x56d256['push']({'type':_0xd3bd8f[_0x4581('0x3')],'app':_0x4581('0x4d'),'exten':_0xd3bd8f[_0x4581('0x6')],'context':_0xd3bd8f['context'],'priority':_[_0x4581('0x48')](_0x56d256)['priority']+0x1,'VoiceExtensionId':_0xd3bd8f['id']});return _0x56d256;});}}});};