fdd81137be53b2a3e8dbb65ad914ddf163b22dd6
[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 _0x0589=['varset','variable','mixmonitor_filename','[%s][recordings][varset]','[%s][recordings][varset]\x20variable:%s\x20value:%s','endsWith','value','.wav49','.WAV','find','monitors','push','hangup','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','cause-txt','connectedlinenum','connectedlinename','forEach','clone','[%s][recordings][hangup]','newexten','[%s][recordings][newexten]','application','appdata','toLowerCase','startsWith','cdr','split','substring','lastIndexOf','queuecallerjoin','[%s][recordings][queuecallerjoin]','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','lodash','util','./utils','info','uniqueid','accountcode','getUserByInternal','then','membername','name','UserId','request','CreateVoiceRecording','newchannel','format','[%s][recordings][newchannel]','[%s][recordings][newchannel]\x20context:%s\x20exten:%s','context','exten','channel','newstate','debug','[%s][recordings][newstate]','isNil','channelstate','[%s][recordings][newstate]\x20context:%s\x20channel:%s','[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','linkedid','error'];(function(_0x15aa8b,_0x1e02b2){var _0x24dd4b=function(_0x14e6ad){while(--_0x14e6ad){_0x15aa8b['push'](_0x15aa8b['shift']());}};_0x24dd4b(++_0x1e02b2);}(_0x0589,0x169));var _0x9058=function(_0xaf8992,_0x33c72d){_0xaf8992=_0xaf8992-0x0;var _0x370df5=_0x0589[_0xaf8992];return _0x370df5;};'use strict';var _=require(_0x9058('0x0'));var util=require(_0x9058('0x1'));var utils=require(_0x9058('0x2'));var recordings={};function writeDB(_0x5b5c8f){utils[_0x9058('0x3')](util['format']('[%s][recordings][writeDB]',_0x5b5c8f[_0x9058('0x4')]));if(_0x5b5c8f[_0x9058('0x5')]){utils[_0x9058('0x6')](_0x5b5c8f[_0x9058('0x5')])[_0x9058('0x7')](function(_0x3411c6){if(_0x3411c6){_0x5b5c8f[_0x9058('0x8')]=_0x3411c6[_0x9058('0x9')];_0x5b5c8f[_0x9058('0xa')]=_0x3411c6['id'];}utils[_0x9058('0xb')]('CreateVoiceRecording',_0x5b5c8f);});}else{utils['request'](_0x9058('0xc'),_0x5b5c8f);}}exports[_0x9058('0xd')]=function(_0x1f5523){try{utils['debug'](util[_0x9058('0xe')](_0x9058('0xf'),_0x1f5523['uniqueid']),_0x1f5523);if(_0x1f5523['uniqueid']==_0x1f5523['linkedid']){utils[_0x9058('0x3')](util[_0x9058('0xe')](_0x9058('0x10'),_0x1f5523['uniqueid'],_0x1f5523[_0x9058('0x11')],_0x1f5523['exten']));recordings[_0x1f5523[_0x9058('0x4')]]={'uniqueid':_0x1f5523[_0x9058('0x4')],'accountcode':_0x1f5523[_0x9058('0x5')],'exten':_0x1f5523[_0x9058('0x12')],'context':_0x1f5523[_0x9058('0x11')],'channel':_0x1f5523[_0x9058('0x13')],'monitors':[]};}}catch(_0x2c7ae5){utils['error'](util[_0x9058('0xe')](_0x9058('0xf'),_0x1f5523[_0x9058('0x4')]),_0x2c7ae5);}};exports[_0x9058('0x14')]=function(_0x1884b1){try{utils[_0x9058('0x15')](util['format'](_0x9058('0x16'),_0x1884b1[_0x9058('0x4')]),_0x1884b1);if(!_[_0x9058('0x17')](recordings[_0x1884b1[_0x9058('0x4')]])&&_0x1884b1[_0x9058('0x18')]==0x6){utils[_0x9058('0x3')](util[_0x9058('0xe')](_0x9058('0x19'),_0x1884b1[_0x9058('0x4')],_0x1884b1['context'],_0x1884b1[_0x9058('0x13')]));}else if(!_[_0x9058('0x17')](recordings[_0x1884b1['linkedid']])&&_0x1884b1[_0x9058('0x18')]==0x6&&_0x1884b1[_0x9058('0x11')]!='transfer'){utils[_0x9058('0x3')](util['format'](_0x9058('0x1a'),_0x1884b1[_0x9058('0x4')],_0x1884b1[_0x9058('0x1b')],_0x1884b1['context'],_0x1884b1[_0x9058('0x13')]));recordings[_0x1884b1[_0x9058('0x1b')]][_0x9058('0x5')]=_0x1884b1[_0x9058('0x5')];}}catch(_0x198cd9){utils[_0x9058('0x1c')](util[_0x9058('0xe')]('[%s][recordings][newstate]',_0x1884b1[_0x9058('0x4')]),_0x198cd9);}};exports[_0x9058('0x1d')]=function(_0x564980){try{if(!_[_0x9058('0x17')](_0x564980[_0x9058('0x1e')])&&!_['isNil'](_0x564980[_0x9058('0x1e')][_0x9058('0x1f')])){utils[_0x9058('0x15')](util[_0x9058('0xe')](_0x9058('0x20'),_0x564980[_0x9058('0x4')]),_0x564980);utils['info'](util['format'](_0x9058('0x21'),_0x564980[_0x9058('0x4')],_0x564980[_0x9058('0x1e')],_0x564980['value']));if(_[_0x9058('0x22')](_0x564980[_0x9058('0x23')],_0x9058('0x24'))){_0x564980[_0x9058('0x23')]=_0x564980[_0x9058('0x23')]['replace'](_0x9058('0x24'),_0x9058('0x25'));}if(recordings[_0x564980[_0x9058('0x1b')]]){var _0x29b0b7=_[_0x9058('0x26')](recordings[_0x564980['linkedid']][_0x9058('0x27')],{'value':_0x564980[_0x9058('0x23')]});if(_[_0x9058('0x17')](_0x29b0b7)){recordings[_0x564980[_0x9058('0x1b')]]['monitors'][_0x9058('0x28')]({'value':_0x564980[_0x9058('0x23')]});}}}}catch(_0x49a26a){utils['error'](util['format'](_0x9058('0x20'),_0x564980[_0x9058('0x4')]),_0x49a26a);}};exports[_0x9058('0x29')]=function(_0x51495f){try{if(!_[_0x9058('0x17')](recordings[_0x51495f[_0x9058('0x4')]])){utils[_0x9058('0x15')](util[_0x9058('0xe')]('[%s][recordings][hangup]',_0x51495f['uniqueid']),_0x51495f);utils['info'](util[_0x9058('0xe')](_0x9058('0x2a'),_0x51495f['uniqueid'],_0x51495f[_0x9058('0x2b')],_0x51495f[_0x9058('0x2c')],_0x51495f[_0x9058('0x2d')]));recordings[_0x51495f[_0x9058('0x4')]]['calleridnum']=_0x51495f[_0x9058('0x2b')];recordings[_0x51495f[_0x9058('0x4')]][_0x9058('0x2c')]=_0x51495f[_0x9058('0x2c')];recordings[_0x51495f['uniqueid']][_0x9058('0x2e')]=_0x51495f[_0x9058('0x2e')];recordings[_0x51495f[_0x9058('0x4')]][_0x9058('0x2f')]=_0x51495f[_0x9058('0x2f')];if(recordings[_0x51495f['uniqueid']]['type']=='outbound'&&recordings[_0x51495f[_0x9058('0x4')]][_0x9058('0x5')]){recordings[_0x51495f[_0x9058('0x4')]][_0x9058('0x2e')]=recordings[_0x51495f['uniqueid']][_0x9058('0x5')];recordings[_0x51495f[_0x9058('0x4')]][_0x9058('0x2f')]='';}recordings[_0x51495f['uniqueid']][_0x9058('0x27')][_0x9058('0x30')](function(_0x1cd516){var _0x1cf26d=_[_0x9058('0x31')](recordings[_0x51495f['uniqueid']]);_0x1cf26d[_0x9058('0x23')]=_0x1cd516['value'];writeDB(_0x1cf26d);});delete recordings[_0x51495f[_0x9058('0x4')]];}}catch(_0x385cf2){utils[_0x9058('0x1c')](util[_0x9058('0xe')](_0x9058('0x32'),_0x51495f[_0x9058('0x4')]),_0x385cf2);}};exports[_0x9058('0x33')]=function(_0xc0a209){try{if(!_[_0x9058('0x17')](recordings[_0xc0a209[_0x9058('0x4')]])){utils[_0x9058('0x15')](util[_0x9058('0xe')](_0x9058('0x34'),_0xc0a209[_0x9058('0x4')]),_0xc0a209);utils[_0x9058('0x3')](util[_0x9058('0xe')]('[%s][recordings][newexten]\x20application:%s\x20appdata:%s',_0xc0a209['uniqueid'],_0xc0a209[_0x9058('0x35')],_0xc0a209[_0x9058('0x36')]));if(_0xc0a209[_0x9058('0x35')][_0x9058('0x37')]()=='set'&&_[_0x9058('0x38')](_0xc0a209[_0x9058('0x36')]['toLowerCase'](),_0x9058('0x39'))){var _0x21d806=_0xc0a209[_0x9058('0x36')][_0x9058('0x3a')]('=');var _0x3ec712=_0x21d806[0x0][_0x9058('0x3b')](_0x21d806[0x0]['lastIndexOf']('(')+0x1,_0x21d806[0x0][_0x9058('0x3c')](')'));var _0x21edeb=_0x21d806[0x1];recordings[_0xc0a209[_0x9058('0x4')]][_0x3ec712]=_0x21edeb;}}}catch(_0x323e45){utils[_0x9058('0x1c')](util['format'](_0x9058('0x34'),_0xc0a209['uniqueid']),_0x323e45);}};exports[_0x9058('0x3d')]=function(_0x12554d){try{if(!_[_0x9058('0x17')](recordings[_0x12554d['uniqueid']])){utils['debug'](util[_0x9058('0xe')](_0x9058('0x3e'),_0x12554d[_0x9058('0x4')]),_0x12554d);utils[_0x9058('0x3')](util[_0x9058('0xe')](_0x9058('0x3f'),_0x12554d[_0x9058('0x4')],_0x12554d[_0x9058('0x40')]));recordings[_0x12554d[_0x9058('0x4')]][_0x9058('0x40')]=_0x12554d[_0x9058('0x40')];}}catch(_0x3bd4af){utils[_0x9058('0x1c')](util[_0x9058('0xe')](_0x9058('0x3e'),_0x12554d[_0x9058('0x4')]),_0x3bd4af);}};