Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / services / xdr / recordings.controller.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 _0x9ce0=['[%s][recordings][blindtransfer]','lodash','util','./transfers.controller','format','uniqueid','blinds','transfereeuniqueid','accountcode','getUserByInternal','then','membername','name','request','CreateVoiceRecording','newchannel','debug','linkedid','info','exten','context','error','[%s][recordings][newchannel]','newstate','[%s][recordings][newstate]','[%s][recordings][newstate]\x20context:%s\x20channel:%s','channel','isNil','channelstate','transfer','[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','varset','variable','mixmonitor_filename','[%s][recordings][varset]','[%s][recordings][varset]\x20variable:%s\x20value:%s','value','endsWith','.wav49','replace','.WAV','monitors','push','hangup','[%s][recordings][hangup]','calleridnum','calleridname','connectedlinenum','connectedlinename','type','outbound','forEach','clone','newexten','[%s][recordings][newexten]','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','appdata','application','set','startsWith','toLowerCase','cdr','substring','lastIndexOf','queuecallerjoin','[%s][recordings][queuecallerjoin]','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','blindtransfer','transferercalleridnum','transferercalleridname','transfereecalleridnum','transfereecalleridname','transfereruniqueid','recording'];(function(_0x3883df,_0x306f22){var _0x4706ab=function(_0x56ec3d){while(--_0x56ec3d){_0x3883df['push'](_0x3883df['shift']());}};_0x4706ab(++_0x306f22);}(_0x9ce0,0x97));var _0x09ce=function(_0x3bf83f,_0x181cac){_0x3bf83f=_0x3bf83f-0x0;var _0x22c4a9=_0x9ce0[_0x3bf83f];return _0x22c4a9;};'use strict';var _=require(_0x09ce('0x0'));var util=require(_0x09ce('0x1'));var utils=require('./utils');var transfers=require(_0x09ce('0x2'));var recordings={};function writeDB(_0x48ae90){var _0x4d716c;utils['info'](util[_0x09ce('0x3')]('[%s][recordings][writeDB]',_0x48ae90[_0x09ce('0x4')]));if(transfers[_0x09ce('0x5')][_0x48ae90['uniqueid']]){_0x4d716c=_0x48ae90[_0x09ce('0x4')];_0x48ae90[_0x09ce('0x4')]=transfers['blinds'][_0x48ae90[_0x09ce('0x4')]][_0x09ce('0x6')];}if(_0x48ae90[_0x09ce('0x7')]){utils[_0x09ce('0x8')](_0x48ae90[_0x09ce('0x7')])[_0x09ce('0x9')](function(_0x40c1a3){if(_0x40c1a3){_0x48ae90[_0x09ce('0xa')]=_0x40c1a3[_0x09ce('0xb')];_0x48ae90['UserId']=_0x40c1a3['id'];}utils['request']('CreateVoiceRecording',_0x48ae90);});}else{utils[_0x09ce('0xc')](_0x09ce('0xd'),_0x48ae90);}if(_0x4d716c)delete transfers[_0x09ce('0x5')][_0x4d716c];}exports[_0x09ce('0xe')]=function(_0x51c4e5){try{utils[_0x09ce('0xf')](util[_0x09ce('0x3')]('[%s][recordings][newchannel]',_0x51c4e5[_0x09ce('0x4')]),_0x51c4e5);if(_0x51c4e5[_0x09ce('0x4')]==_0x51c4e5[_0x09ce('0x10')]){utils[_0x09ce('0x11')](util[_0x09ce('0x3')]('[%s][recordings][newchannel]\x20context:%s\x20exten:%s',_0x51c4e5[_0x09ce('0x4')],_0x51c4e5['context'],_0x51c4e5['exten']));recordings[_0x51c4e5[_0x09ce('0x4')]]={'uniqueid':_0x51c4e5[_0x09ce('0x4')],'accountcode':_0x51c4e5[_0x09ce('0x7')],'exten':_0x51c4e5[_0x09ce('0x12')],'context':_0x51c4e5[_0x09ce('0x13')],'channel':_0x51c4e5['channel'],'monitors':[]};}}catch(_0x29acb0){utils[_0x09ce('0x14')](util[_0x09ce('0x3')](_0x09ce('0x15'),_0x51c4e5[_0x09ce('0x4')]),_0x29acb0);}};exports[_0x09ce('0x16')]=function(_0x4db750){try{utils['debug'](util[_0x09ce('0x3')](_0x09ce('0x17'),_0x4db750[_0x09ce('0x4')]),_0x4db750);if(!_['isNil'](recordings[_0x4db750[_0x09ce('0x4')]])&&_0x4db750['channelstate']==0x6){utils['info'](util[_0x09ce('0x3')](_0x09ce('0x18'),_0x4db750[_0x09ce('0x4')],_0x4db750['context'],_0x4db750[_0x09ce('0x19')]));}else if(!_[_0x09ce('0x1a')](recordings[_0x4db750[_0x09ce('0x10')]])&&_0x4db750[_0x09ce('0x1b')]==0x6&&_0x4db750[_0x09ce('0x13')]!=_0x09ce('0x1c')){utils[_0x09ce('0x11')](util['format'](_0x09ce('0x1d'),_0x4db750[_0x09ce('0x4')],_0x4db750[_0x09ce('0x10')],_0x4db750[_0x09ce('0x13')],_0x4db750['channel']));recordings[_0x4db750['linkedid']][_0x09ce('0x7')]=_0x4db750[_0x09ce('0x7')];}}catch(_0x2461b1){utils[_0x09ce('0x14')](util['format'](_0x09ce('0x17'),_0x4db750[_0x09ce('0x4')]),_0x2461b1);}};exports[_0x09ce('0x1e')]=function(_0x11c671){try{if(!_['isNil'](_0x11c671[_0x09ce('0x1f')])&&!_[_0x09ce('0x1a')](_0x11c671[_0x09ce('0x1f')][_0x09ce('0x20')])){utils[_0x09ce('0xf')](util[_0x09ce('0x3')](_0x09ce('0x21'),_0x11c671['uniqueid']),_0x11c671);utils[_0x09ce('0x11')](util[_0x09ce('0x3')](_0x09ce('0x22'),_0x11c671[_0x09ce('0x4')],_0x11c671['variable'],_0x11c671[_0x09ce('0x23')]));if(_[_0x09ce('0x24')](_0x11c671['value'],_0x09ce('0x25'))){_0x11c671[_0x09ce('0x23')]=_0x11c671['value'][_0x09ce('0x26')]('.wav49',_0x09ce('0x27'));}if(recordings[_0x11c671[_0x09ce('0x10')]]){var _0x37cc39=_['find'](recordings[_0x11c671[_0x09ce('0x10')]][_0x09ce('0x28')],{'value':_0x11c671[_0x09ce('0x23')]});if(_['isNil'](_0x37cc39)){recordings[_0x11c671['linkedid']][_0x09ce('0x28')][_0x09ce('0x29')]({'value':_0x11c671[_0x09ce('0x23')]});}}}}catch(_0x3c6dbb){utils[_0x09ce('0x14')](util[_0x09ce('0x3')](_0x09ce('0x21'),_0x11c671[_0x09ce('0x4')]),_0x3c6dbb);}};exports[_0x09ce('0x2a')]=function(_0x177b3e){try{if(!_[_0x09ce('0x1a')](recordings[_0x177b3e['uniqueid']])){utils[_0x09ce('0xf')](util[_0x09ce('0x3')](_0x09ce('0x2b'),_0x177b3e['uniqueid']),_0x177b3e);utils[_0x09ce('0x11')](util[_0x09ce('0x3')]('[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s',_0x177b3e[_0x09ce('0x4')],_0x177b3e[_0x09ce('0x2c')],_0x177b3e['calleridname'],_0x177b3e['cause-txt']));recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x2c')]=_0x177b3e['calleridnum'];recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x2d')]=_0x177b3e['calleridname'];recordings[_0x177b3e[_0x09ce('0x4')]]['connectedlinenum']=_0x177b3e[_0x09ce('0x2e')];recordings[_0x177b3e[_0x09ce('0x4')]]['connectedlinename']=_0x177b3e[_0x09ce('0x2f')];if(recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x30')]==_0x09ce('0x31')&&recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x7')]){recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x2e')]=recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x7')];recordings[_0x177b3e['uniqueid']][_0x09ce('0x2f')]='';}recordings[_0x177b3e[_0x09ce('0x4')]][_0x09ce('0x28')][_0x09ce('0x32')](function(_0x2da6a5){var _0x4c3ea7=_[_0x09ce('0x33')](recordings[_0x177b3e[_0x09ce('0x4')]]);_0x4c3ea7['value']=_0x2da6a5[_0x09ce('0x23')];writeDB(_0x4c3ea7);});delete recordings[_0x177b3e[_0x09ce('0x4')]];}}catch(_0x47cb76){utils[_0x09ce('0x14')](util[_0x09ce('0x3')](_0x09ce('0x2b'),_0x177b3e[_0x09ce('0x4')]),_0x47cb76);}};exports[_0x09ce('0x34')]=function(_0x5bb4b4){try{if(!_[_0x09ce('0x1a')](recordings[_0x5bb4b4['uniqueid']])){utils[_0x09ce('0xf')](util[_0x09ce('0x3')](_0x09ce('0x35'),_0x5bb4b4[_0x09ce('0x4')]),_0x5bb4b4);utils[_0x09ce('0x11')](util['format'](_0x09ce('0x36'),_0x5bb4b4['uniqueid'],_0x5bb4b4['application'],_0x5bb4b4[_0x09ce('0x37')]));if(_0x5bb4b4[_0x09ce('0x38')]['toLowerCase']()==_0x09ce('0x39')&&_[_0x09ce('0x3a')](_0x5bb4b4[_0x09ce('0x37')][_0x09ce('0x3b')](),_0x09ce('0x3c'))){var _0x1e03a8=_0x5bb4b4['appdata']['split']('=');var _0x2735ed=_0x1e03a8[0x0][_0x09ce('0x3d')](_0x1e03a8[0x0][_0x09ce('0x3e')]('(')+0x1,_0x1e03a8[0x0][_0x09ce('0x3e')](')'));var _0x3c8d6b=_0x1e03a8[0x1];recordings[_0x5bb4b4[_0x09ce('0x4')]][_0x2735ed]=_0x3c8d6b;}}}catch(_0x4770f2){utils['error'](util[_0x09ce('0x3')](_0x09ce('0x35'),_0x5bb4b4['uniqueid']),_0x4770f2);}};exports[_0x09ce('0x3f')]=function(_0x5a1c77){try{if(!_['isNil'](recordings[_0x5a1c77[_0x09ce('0x4')]])){utils['debug'](util[_0x09ce('0x3')](_0x09ce('0x40'),_0x5a1c77[_0x09ce('0x4')]),_0x5a1c77);utils[_0x09ce('0x11')](util[_0x09ce('0x3')](_0x09ce('0x41'),_0x5a1c77['uniqueid'],_0x5a1c77[_0x09ce('0x42')]));recordings[_0x5a1c77[_0x09ce('0x4')]][_0x09ce('0x42')]=_0x5a1c77[_0x09ce('0x42')];}}catch(_0x1201a2){utils[_0x09ce('0x14')](util[_0x09ce('0x3')](_0x09ce('0x40'),_0x5a1c77['uniqueid']),_0x1201a2);}};exports[_0x09ce('0x43')]=function(_0x218070){try{utils[_0x09ce('0xf')](util[_0x09ce('0x3')]('[%s][recordings][blindtransfer]',_0x218070[_0x09ce('0x4')]),_0x218070);utils[_0x09ce('0x11')](util[_0x09ce('0x3')]('[%s][recordings][blindtransfer]\x20transferercalleridnum:%s\x20transferercalleridname:%s\x20transfereecalleridnum:%s\x20transfereecalleridname:%s',_0x218070[_0x09ce('0x4')],_0x218070[_0x09ce('0x44')],_0x218070[_0x09ce('0x45')],_0x218070[_0x09ce('0x46')],_0x218070[_0x09ce('0x47')]));if(recordings[_0x218070['transfereruniqueid']]&&transfers[_0x09ce('0x5')][_0x218070[_0x09ce('0x48')]]){transfers[_0x09ce('0x5')][_0x218070[_0x09ce('0x48')]][_0x09ce('0x49')]=!![];}}catch(_0x399bbd){utils[_0x09ce('0x14')](util[_0x09ce('0x3')](_0x09ce('0x4a'),_0x218070[_0x09ce('0x4')]),_0x399bbd);}};