Built motion from commit fd055180.|2.6.30
[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 _0xcc2d=['startsWith','toLowerCase','cdr','split','lastIndexOf','[%s][recordings][newexten]','[%s][recordings][queuecallerjoin]','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','lodash','util','./utils','format','[%s][recordings][writeDB]','accountcode','membername','UserId','request','CreateVoiceRecording','newchannel','[%s][recordings][newchannel]','uniqueid','linkedid','[%s][recordings][newchannel]\x20context:%s\x20exten:%s','context','exten','channel','error','isNil','channelstate','info','[%s][recordings][newstate]\x20context:%s\x20channel:%s','[%s][recordings][newstate]','varset','variable','mixmonitor_filename','[%s][recordings][varset]','value','endsWith','.wav49','.WAV','monitors','push','debug','[%s][recordings][hangup]','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','connectedlinenum','connectedlinename','outbound','forEach','clone','newexten','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','application','appdata','set'];(function(_0x2c6336,_0x1fb3a4){var _0x5b07ec=function(_0x1cbbd9){while(--_0x1cbbd9){_0x2c6336['push'](_0x2c6336['shift']());}};_0x5b07ec(++_0x1fb3a4);}(_0xcc2d,0x7d));var _0xdcc2=function(_0x33a91a,_0x4a2db5){_0x33a91a=_0x33a91a-0x0;var _0x284314=_0xcc2d[_0x33a91a];return _0x284314;};'use strict';var _=require(_0xdcc2('0x0'));var util=require(_0xdcc2('0x1'));var utils=require(_0xdcc2('0x2'));var recordings={};function writeDB(_0x3ad1f2){utils['info'](util[_0xdcc2('0x3')](_0xdcc2('0x4'),_0x3ad1f2['uniqueid']));if(_0x3ad1f2[_0xdcc2('0x5')]){utils['getUserByInternal'](_0x3ad1f2[_0xdcc2('0x5')])['then'](function(_0x179caf){if(_0x179caf){_0x3ad1f2[_0xdcc2('0x6')]=_0x179caf['name'];_0x3ad1f2[_0xdcc2('0x7')]=_0x179caf['id'];}utils[_0xdcc2('0x8')](_0xdcc2('0x9'),_0x3ad1f2);});}else{utils[_0xdcc2('0x8')](_0xdcc2('0x9'),_0x3ad1f2);}}exports[_0xdcc2('0xa')]=function(_0x5c0b96){try{utils['debug'](util[_0xdcc2('0x3')](_0xdcc2('0xb'),_0x5c0b96[_0xdcc2('0xc')]),_0x5c0b96);if(_0x5c0b96[_0xdcc2('0xc')]==_0x5c0b96[_0xdcc2('0xd')]){utils['info'](util[_0xdcc2('0x3')](_0xdcc2('0xe'),_0x5c0b96[_0xdcc2('0xc')],_0x5c0b96[_0xdcc2('0xf')],_0x5c0b96[_0xdcc2('0x10')]));recordings[_0x5c0b96[_0xdcc2('0xc')]]={'uniqueid':_0x5c0b96[_0xdcc2('0xc')],'accountcode':_0x5c0b96['accountcode'],'exten':_0x5c0b96[_0xdcc2('0x10')],'context':_0x5c0b96[_0xdcc2('0xf')],'channel':_0x5c0b96[_0xdcc2('0x11')],'monitors':[]};}}catch(_0x1cf3af){utils[_0xdcc2('0x12')](util[_0xdcc2('0x3')](_0xdcc2('0xb'),_0x5c0b96[_0xdcc2('0xc')]),_0x1cf3af);}};exports['newstate']=function(_0x37fedb){try{utils['debug'](util[_0xdcc2('0x3')]('[%s][recordings][newstate]',_0x37fedb['uniqueid']),_0x37fedb);if(!_[_0xdcc2('0x13')](recordings[_0x37fedb[_0xdcc2('0xc')]])&&_0x37fedb[_0xdcc2('0x14')]==0x6){utils[_0xdcc2('0x15')](util[_0xdcc2('0x3')](_0xdcc2('0x16'),_0x37fedb['uniqueid'],_0x37fedb['context'],_0x37fedb[_0xdcc2('0x11')]));}else if(!_['isNil'](recordings[_0x37fedb[_0xdcc2('0xd')]])&&_0x37fedb[_0xdcc2('0x14')]==0x6&&_0x37fedb[_0xdcc2('0xf')]!='transfer'){utils['info'](util['format']('[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x37fedb[_0xdcc2('0xc')],_0x37fedb[_0xdcc2('0xd')],_0x37fedb['context'],_0x37fedb[_0xdcc2('0x11')]));recordings[_0x37fedb[_0xdcc2('0xd')]][_0xdcc2('0x5')]=_0x37fedb['accountcode'];}}catch(_0x44ac10){utils[_0xdcc2('0x12')](util[_0xdcc2('0x3')](_0xdcc2('0x17'),_0x37fedb[_0xdcc2('0xc')]),_0x44ac10);}};exports[_0xdcc2('0x18')]=function(_0x188a71){try{if(!_[_0xdcc2('0x13')](_0x188a71['variable'])&&!_['isNil'](_0x188a71[_0xdcc2('0x19')][_0xdcc2('0x1a')])){utils['debug'](util[_0xdcc2('0x3')](_0xdcc2('0x1b'),_0x188a71[_0xdcc2('0xc')]),_0x188a71);utils[_0xdcc2('0x15')](util[_0xdcc2('0x3')]('[%s][recordings][varset]\x20variable:%s\x20value:%s',_0x188a71['uniqueid'],_0x188a71[_0xdcc2('0x19')],_0x188a71[_0xdcc2('0x1c')]));if(_[_0xdcc2('0x1d')](_0x188a71[_0xdcc2('0x1c')],_0xdcc2('0x1e'))){_0x188a71[_0xdcc2('0x1c')]=_0x188a71['value']['replace'](_0xdcc2('0x1e'),_0xdcc2('0x1f'));}if(recordings[_0x188a71[_0xdcc2('0xd')]]){var _0x5c7a1d=_['find'](recordings[_0x188a71['linkedid']][_0xdcc2('0x20')],{'value':_0x188a71[_0xdcc2('0x1c')]});if(_[_0xdcc2('0x13')](_0x5c7a1d)){recordings[_0x188a71['linkedid']][_0xdcc2('0x20')][_0xdcc2('0x21')]({'value':_0x188a71[_0xdcc2('0x1c')]});}}}}catch(_0x23aace){utils['error'](util[_0xdcc2('0x3')](_0xdcc2('0x1b'),_0x188a71[_0xdcc2('0xc')]),_0x23aace);}};exports['hangup']=function(_0x4070c3){try{if(!_[_0xdcc2('0x13')](recordings[_0x4070c3['uniqueid']])){utils[_0xdcc2('0x22')](util[_0xdcc2('0x3')](_0xdcc2('0x23'),_0x4070c3[_0xdcc2('0xc')]),_0x4070c3);utils[_0xdcc2('0x15')](util['format'](_0xdcc2('0x24'),_0x4070c3[_0xdcc2('0xc')],_0x4070c3[_0xdcc2('0x25')],_0x4070c3[_0xdcc2('0x26')],_0x4070c3['cause-txt']));recordings[_0x4070c3[_0xdcc2('0xc')]]['calleridnum']=_0x4070c3['calleridnum'];recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x26')]=_0x4070c3['calleridname'];recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x27')]=_0x4070c3[_0xdcc2('0x27')];recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x28')]=_0x4070c3[_0xdcc2('0x28')];if(recordings[_0x4070c3[_0xdcc2('0xc')]]['type']==_0xdcc2('0x29')&&recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x5')]){recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x27')]=recordings[_0x4070c3[_0xdcc2('0xc')]]['accountcode'];recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x28')]='';}recordings[_0x4070c3[_0xdcc2('0xc')]][_0xdcc2('0x20')][_0xdcc2('0x2a')](function(_0x6b3cc5){var _0x11e54c=_[_0xdcc2('0x2b')](recordings[_0x4070c3[_0xdcc2('0xc')]]);_0x11e54c[_0xdcc2('0x1c')]=_0x6b3cc5[_0xdcc2('0x1c')];writeDB(_0x11e54c);});delete recordings[_0x4070c3[_0xdcc2('0xc')]];}}catch(_0x1ddea0){utils[_0xdcc2('0x12')](util[_0xdcc2('0x3')](_0xdcc2('0x23'),_0x4070c3[_0xdcc2('0xc')]),_0x1ddea0);}};exports[_0xdcc2('0x2c')]=function(_0x14a62a){try{if(!_['isNil'](recordings[_0x14a62a[_0xdcc2('0xc')]])){utils['debug'](util[_0xdcc2('0x3')]('[%s][recordings][newexten]',_0x14a62a[_0xdcc2('0xc')]),_0x14a62a);utils['info'](util['format'](_0xdcc2('0x2d'),_0x14a62a[_0xdcc2('0xc')],_0x14a62a[_0xdcc2('0x2e')],_0x14a62a[_0xdcc2('0x2f')]));if(_0x14a62a[_0xdcc2('0x2e')]['toLowerCase']()==_0xdcc2('0x30')&&_[_0xdcc2('0x31')](_0x14a62a[_0xdcc2('0x2f')][_0xdcc2('0x32')](),_0xdcc2('0x33'))){var _0x54de02=_0x14a62a[_0xdcc2('0x2f')][_0xdcc2('0x34')]('=');var _0x4cacb2=_0x54de02[0x0]['substring'](_0x54de02[0x0]['lastIndexOf']('(')+0x1,_0x54de02[0x0][_0xdcc2('0x35')](')'));var _0x1dcd08=_0x54de02[0x1];recordings[_0x14a62a[_0xdcc2('0xc')]][_0x4cacb2]=_0x1dcd08;}}}catch(_0x4f19af){utils[_0xdcc2('0x12')](util[_0xdcc2('0x3')](_0xdcc2('0x36'),_0x14a62a[_0xdcc2('0xc')]),_0x4f19af);}};exports['queuecallerjoin']=function(_0x12af14){try{if(!_[_0xdcc2('0x13')](recordings[_0x12af14['uniqueid']])){utils[_0xdcc2('0x22')](util[_0xdcc2('0x3')](_0xdcc2('0x37'),_0x12af14['uniqueid']),_0x12af14);utils[_0xdcc2('0x15')](util['format'](_0xdcc2('0x38'),_0x12af14[_0xdcc2('0xc')],_0x12af14[_0xdcc2('0x39')]));recordings[_0x12af14[_0xdcc2('0xc')]][_0xdcc2('0x39')]=_0x12af14[_0xdcc2('0x39')];}}catch(_0x30f464){utils['error'](util['format'](_0xdcc2('0x37'),_0x12af14[_0xdcc2('0xc')]),_0x30f464);}};