ba950f99a151d05d773385efa2ef9eb448f45e6c
[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 _0xa1e3=['toLowerCase','set','startsWith','cdr','split','lastIndexOf','queuecallerjoin','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','lodash','util','format','uniqueid','accountcode','getUserByInternal','then','membername','name','UserId','CreateVoiceRecording','request','debug','[%s][recordings][newchannel]','linkedid','info','[%s][recordings][newchannel]\x20context:%s\x20exten:%s','context','exten','isNil','[%s][recordings][newstate]\x20context:%s\x20channel:%s','transfer','channel','[%s][recordings][newstate]','varset','variable','mixmonitor_filename','[%s][recordings][varset]','value','replace','.WAV','monitors','push','error','hangup','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','cause-txt','connectedlinenum','type','connectedlinename','forEach','clone','[%s][recordings][hangup]','newexten','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','appdata','application'];(function(_0x42cae2,_0x284ef8){var _0x5f256f=function(_0x41abc8){while(--_0x41abc8){_0x42cae2['push'](_0x42cae2['shift']());}};_0x5f256f(++_0x284ef8);}(_0xa1e3,0x1d9));var _0x3a1e=function(_0x13a32e,_0x4b34ec){_0x13a32e=_0x13a32e-0x0;var _0x20c327=_0xa1e3[_0x13a32e];return _0x20c327;};'use strict';var _=require(_0x3a1e('0x0'));var util=require(_0x3a1e('0x1'));var utils=require('./utils');var recordings={};function writeDB(_0x4f72eb){utils['info'](util[_0x3a1e('0x2')]('[%s][recordings][writeDB]',_0x4f72eb[_0x3a1e('0x3')]));if(_0x4f72eb[_0x3a1e('0x4')]){utils[_0x3a1e('0x5')](_0x4f72eb[_0x3a1e('0x4')])[_0x3a1e('0x6')](function(_0x3a7fe3){if(_0x3a7fe3){_0x4f72eb[_0x3a1e('0x7')]=_0x3a7fe3[_0x3a1e('0x8')];_0x4f72eb[_0x3a1e('0x9')]=_0x3a7fe3['id'];}utils['request'](_0x3a1e('0xa'),_0x4f72eb);});}else{utils[_0x3a1e('0xb')]('CreateVoiceRecording',_0x4f72eb);}}exports['newchannel']=function(_0x5b611e){try{utils[_0x3a1e('0xc')](util[_0x3a1e('0x2')](_0x3a1e('0xd'),_0x5b611e['uniqueid']),_0x5b611e);if(_0x5b611e[_0x3a1e('0x3')]==_0x5b611e[_0x3a1e('0xe')]){utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')](_0x3a1e('0x10'),_0x5b611e['uniqueid'],_0x5b611e[_0x3a1e('0x11')],_0x5b611e[_0x3a1e('0x12')]));recordings[_0x5b611e['uniqueid']]={'uniqueid':_0x5b611e[_0x3a1e('0x3')],'accountcode':_0x5b611e['accountcode'],'exten':_0x5b611e[_0x3a1e('0x12')],'context':_0x5b611e['context'],'channel':_0x5b611e['channel'],'monitors':[]};}}catch(_0x131241){utils['error'](util[_0x3a1e('0x2')](_0x3a1e('0xd'),_0x5b611e[_0x3a1e('0x3')]),_0x131241);}};exports['newstate']=function(_0x1f812d){try{utils[_0x3a1e('0xc')](util[_0x3a1e('0x2')]('[%s][recordings][newstate]',_0x1f812d[_0x3a1e('0x3')]),_0x1f812d);if(!_[_0x3a1e('0x13')](recordings[_0x1f812d[_0x3a1e('0x3')]])&&_0x1f812d['channelstate']==0x6){utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')](_0x3a1e('0x14'),_0x1f812d['uniqueid'],_0x1f812d['context'],_0x1f812d['channel']));}else if(!_[_0x3a1e('0x13')](recordings[_0x1f812d[_0x3a1e('0xe')]])&&_0x1f812d['channelstate']==0x6&&_0x1f812d['context']!=_0x3a1e('0x15')){utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')]('[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x1f812d[_0x3a1e('0x3')],_0x1f812d[_0x3a1e('0xe')],_0x1f812d[_0x3a1e('0x11')],_0x1f812d[_0x3a1e('0x16')]));recordings[_0x1f812d[_0x3a1e('0xe')]][_0x3a1e('0x4')]=_0x1f812d[_0x3a1e('0x4')];}}catch(_0x5af454){utils['error'](util['format'](_0x3a1e('0x17'),_0x1f812d[_0x3a1e('0x3')]),_0x5af454);}};exports[_0x3a1e('0x18')]=function(_0x3d68eb){try{if(!_[_0x3a1e('0x13')](_0x3d68eb['variable'])&&!_[_0x3a1e('0x13')](_0x3d68eb[_0x3a1e('0x19')][_0x3a1e('0x1a')])){utils['debug'](util[_0x3a1e('0x2')](_0x3a1e('0x1b'),_0x3d68eb[_0x3a1e('0x3')]),_0x3d68eb);utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')]('[%s][recordings][varset]\x20variable:%s\x20value:%s',_0x3d68eb[_0x3a1e('0x3')],_0x3d68eb['variable'],_0x3d68eb[_0x3a1e('0x1c')]));if(_['endsWith'](_0x3d68eb['value'],'.wav49')){_0x3d68eb[_0x3a1e('0x1c')]=_0x3d68eb[_0x3a1e('0x1c')][_0x3a1e('0x1d')]('.wav49',_0x3a1e('0x1e'));}if(recordings[_0x3d68eb[_0x3a1e('0xe')]]){var _0x5e5a39=_['find'](recordings[_0x3d68eb[_0x3a1e('0xe')]][_0x3a1e('0x1f')],{'value':_0x3d68eb[_0x3a1e('0x1c')]});if(_['isNil'](_0x5e5a39)){recordings[_0x3d68eb[_0x3a1e('0xe')]]['monitors'][_0x3a1e('0x20')]({'value':_0x3d68eb[_0x3a1e('0x1c')]});}}}}catch(_0x476d57){utils[_0x3a1e('0x21')](util['format']('[%s][recordings][varset]',_0x3d68eb[_0x3a1e('0x3')]),_0x476d57);}};exports[_0x3a1e('0x22')]=function(_0x84a568){try{if(!_[_0x3a1e('0x13')](recordings[_0x84a568[_0x3a1e('0x3')]])){utils[_0x3a1e('0xc')](util[_0x3a1e('0x2')]('[%s][recordings][hangup]',_0x84a568['uniqueid']),_0x84a568);utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')](_0x3a1e('0x23'),_0x84a568['uniqueid'],_0x84a568[_0x3a1e('0x24')],_0x84a568[_0x3a1e('0x25')],_0x84a568[_0x3a1e('0x26')]));recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x24')]=_0x84a568[_0x3a1e('0x24')];recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x25')]=_0x84a568[_0x3a1e('0x25')];recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x27')]=_0x84a568[_0x3a1e('0x27')];recordings[_0x84a568[_0x3a1e('0x3')]]['connectedlinename']=_0x84a568['connectedlinename'];if(recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x28')]=='outbound'&&recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x4')]){recordings[_0x84a568[_0x3a1e('0x3')]]['connectedlinenum']=recordings[_0x84a568[_0x3a1e('0x3')]]['accountcode'];recordings[_0x84a568['uniqueid']][_0x3a1e('0x29')]='';}recordings[_0x84a568[_0x3a1e('0x3')]][_0x3a1e('0x1f')][_0x3a1e('0x2a')](function(_0x35672e){var _0x1f2081=_[_0x3a1e('0x2b')](recordings[_0x84a568[_0x3a1e('0x3')]]);_0x1f2081[_0x3a1e('0x1c')]=_0x35672e['value'];writeDB(_0x1f2081);});delete recordings[_0x84a568[_0x3a1e('0x3')]];}}catch(_0x3a238d){utils['error'](util[_0x3a1e('0x2')](_0x3a1e('0x2c'),_0x84a568[_0x3a1e('0x3')]),_0x3a238d);}};exports[_0x3a1e('0x2d')]=function(_0x406a8e){try{if(!_[_0x3a1e('0x13')](recordings[_0x406a8e[_0x3a1e('0x3')]])){utils['debug'](util['format']('[%s][recordings][newexten]',_0x406a8e[_0x3a1e('0x3')]),_0x406a8e);utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')](_0x3a1e('0x2e'),_0x406a8e[_0x3a1e('0x3')],_0x406a8e['application'],_0x406a8e[_0x3a1e('0x2f')]));if(_0x406a8e[_0x3a1e('0x30')][_0x3a1e('0x31')]()==_0x3a1e('0x32')&&_[_0x3a1e('0x33')](_0x406a8e[_0x3a1e('0x2f')]['toLowerCase'](),_0x3a1e('0x34'))){var _0x54a31b=_0x406a8e[_0x3a1e('0x2f')][_0x3a1e('0x35')]('=');var _0x46af0b=_0x54a31b[0x0]['substring'](_0x54a31b[0x0][_0x3a1e('0x36')]('(')+0x1,_0x54a31b[0x0][_0x3a1e('0x36')](')'));var _0x23a3d=_0x54a31b[0x1];recordings[_0x406a8e[_0x3a1e('0x3')]][_0x46af0b]=_0x23a3d;}}}catch(_0x2d0cb4){utils[_0x3a1e('0x21')](util[_0x3a1e('0x2')]('[%s][recordings][newexten]',_0x406a8e[_0x3a1e('0x3')]),_0x2d0cb4);}};exports[_0x3a1e('0x37')]=function(_0x4d255f){try{if(!_[_0x3a1e('0x13')](recordings[_0x4d255f[_0x3a1e('0x3')]])){utils[_0x3a1e('0xc')](util['format']('[%s][recordings][queuecallerjoin]',_0x4d255f[_0x3a1e('0x3')]),_0x4d255f);utils[_0x3a1e('0xf')](util[_0x3a1e('0x2')](_0x3a1e('0x38'),_0x4d255f['uniqueid'],_0x4d255f['queue']));recordings[_0x4d255f[_0x3a1e('0x3')]][_0x3a1e('0x39')]=_0x4d255f['queue'];}}catch(_0x4f51ea){utils[_0x3a1e('0x21')](util[_0x3a1e('0x2')]('[%s][recordings][queuecallerjoin]',_0x4d255f[_0x3a1e('0x3')]),_0x4f51ea);}};