Built motion from commit 6db1674d.|2.6.23
[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 _0x6fd8=['[%s][recordings][queuecallerjoin]\x20queue:%s','queue','util','./utils','info','format','[%s][recordings][writeDB]','uniqueid','accountcode','getUserByInternal','membername','name','UserId','request','CreateVoiceRecording','newchannel','debug','exten','context','channel','newstate','isNil','channelstate','linkedid','transfer','error','[%s][recordings][newstate]','varset','variable','[%s][recordings][varset]\x20variable:%s\x20value:%s','value','endsWith','.wav49','replace','find','monitors','push','[%s][recordings][varset]','hangup','[%s][recordings][hangup]','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','cause-txt','connectedlinenum','connectedlinename','type','outbound','forEach','clone','newexten','[%s][recordings][newexten]','application','appdata','set','startsWith','toLowerCase','split','substring','lastIndexOf','queuecallerjoin','[%s][recordings][queuecallerjoin]'];(function(_0x5b561d,_0x422b7c){var _0x431060=function(_0x401409){while(--_0x401409){_0x5b561d['push'](_0x5b561d['shift']());}};_0x431060(++_0x422b7c);}(_0x6fd8,0xbc));var _0x86fd=function(_0x4a0f12,_0x3aab8c){_0x4a0f12=_0x4a0f12-0x0;var _0x1d96c7=_0x6fd8[_0x4a0f12];return _0x1d96c7;};'use strict';var _=require('lodash');var util=require(_0x86fd('0x0'));var utils=require(_0x86fd('0x1'));var recordings={};function writeDB(_0x596daf){utils[_0x86fd('0x2')](util[_0x86fd('0x3')](_0x86fd('0x4'),_0x596daf[_0x86fd('0x5')]));if(_0x596daf[_0x86fd('0x6')]){utils[_0x86fd('0x7')](_0x596daf[_0x86fd('0x6')])['then'](function(_0x45d1f3){if(_0x45d1f3){_0x596daf[_0x86fd('0x8')]=_0x45d1f3[_0x86fd('0x9')];_0x596daf[_0x86fd('0xa')]=_0x45d1f3['id'];}utils[_0x86fd('0xb')](_0x86fd('0xc'),_0x596daf);});}else{utils[_0x86fd('0xb')](_0x86fd('0xc'),_0x596daf);}}exports[_0x86fd('0xd')]=function(_0x651891){try{utils[_0x86fd('0xe')](util['format']('[%s][recordings][newchannel]',_0x651891[_0x86fd('0x5')]),_0x651891);if(_0x651891[_0x86fd('0x5')]==_0x651891['linkedid']){utils[_0x86fd('0x2')](util[_0x86fd('0x3')]('[%s][recordings][newchannel]\x20context:%s\x20exten:%s',_0x651891['uniqueid'],_0x651891['context'],_0x651891[_0x86fd('0xf')]));recordings[_0x651891['uniqueid']]={'uniqueid':_0x651891[_0x86fd('0x5')],'accountcode':_0x651891['accountcode'],'exten':_0x651891[_0x86fd('0xf')],'context':_0x651891[_0x86fd('0x10')],'channel':_0x651891[_0x86fd('0x11')],'monitors':[]};}}catch(_0x58391d){utils['error'](util[_0x86fd('0x3')]('[%s][recordings][newchannel]',_0x651891[_0x86fd('0x5')]),_0x58391d);}};exports[_0x86fd('0x12')]=function(_0x2020fe){try{utils[_0x86fd('0xe')](util['format']('[%s][recordings][newstate]',_0x2020fe['uniqueid']),_0x2020fe);if(!_[_0x86fd('0x13')](recordings[_0x2020fe[_0x86fd('0x5')]])&&_0x2020fe[_0x86fd('0x14')]==0x6){utils[_0x86fd('0x2')](util[_0x86fd('0x3')]('[%s][recordings][newstate]\x20context:%s\x20channel:%s',_0x2020fe[_0x86fd('0x5')],_0x2020fe[_0x86fd('0x10')],_0x2020fe['channel']));}else if(!_['isNil'](recordings[_0x2020fe[_0x86fd('0x15')]])&&_0x2020fe['channelstate']==0x6&&_0x2020fe[_0x86fd('0x10')]!=_0x86fd('0x16')){utils[_0x86fd('0x2')](util[_0x86fd('0x3')]('[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x2020fe[_0x86fd('0x5')],_0x2020fe[_0x86fd('0x15')],_0x2020fe[_0x86fd('0x10')],_0x2020fe[_0x86fd('0x11')]));recordings[_0x2020fe[_0x86fd('0x15')]][_0x86fd('0x6')]=_0x2020fe['accountcode'];}}catch(_0x5d1f83){utils[_0x86fd('0x17')](util[_0x86fd('0x3')](_0x86fd('0x18'),_0x2020fe['uniqueid']),_0x5d1f83);}};exports[_0x86fd('0x19')]=function(_0x4549dd){try{if(!_['isNil'](_0x4549dd[_0x86fd('0x1a')])&&!_[_0x86fd('0x13')](_0x4549dd[_0x86fd('0x1a')]['mixmonitor_filename'])){utils[_0x86fd('0xe')](util[_0x86fd('0x3')]('[%s][recordings][varset]',_0x4549dd[_0x86fd('0x5')]),_0x4549dd);utils['info'](util['format'](_0x86fd('0x1b'),_0x4549dd[_0x86fd('0x5')],_0x4549dd[_0x86fd('0x1a')],_0x4549dd[_0x86fd('0x1c')]));if(_[_0x86fd('0x1d')](_0x4549dd[_0x86fd('0x1c')],_0x86fd('0x1e'))){_0x4549dd[_0x86fd('0x1c')]=_0x4549dd['value'][_0x86fd('0x1f')](_0x86fd('0x1e'),'.WAV');}if(recordings[_0x4549dd[_0x86fd('0x15')]]){var _0x1c0d2a=_[_0x86fd('0x20')](recordings[_0x4549dd['linkedid']][_0x86fd('0x21')],{'value':_0x4549dd[_0x86fd('0x1c')]});if(_[_0x86fd('0x13')](_0x1c0d2a)){recordings[_0x4549dd[_0x86fd('0x15')]]['monitors'][_0x86fd('0x22')]({'value':_0x4549dd['value']});}}}}catch(_0x5e7253){utils[_0x86fd('0x17')](util[_0x86fd('0x3')](_0x86fd('0x23'),_0x4549dd[_0x86fd('0x5')]),_0x5e7253);}};exports[_0x86fd('0x24')]=function(_0xf578ce){try{if(!_['isNil'](recordings[_0xf578ce[_0x86fd('0x5')]])){utils[_0x86fd('0xe')](util[_0x86fd('0x3')](_0x86fd('0x25'),_0xf578ce[_0x86fd('0x5')]),_0xf578ce);utils[_0x86fd('0x2')](util['format'](_0x86fd('0x26'),_0xf578ce[_0x86fd('0x5')],_0xf578ce[_0x86fd('0x27')],_0xf578ce[_0x86fd('0x28')],_0xf578ce[_0x86fd('0x29')]));recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x27')]=_0xf578ce[_0x86fd('0x27')];recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x28')]=_0xf578ce[_0x86fd('0x28')];recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x2a')]=_0xf578ce['connectedlinenum'];recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x2b')]=_0xf578ce[_0x86fd('0x2b')];if(recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x2c')]==_0x86fd('0x2d')&&recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x6')]){recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x2a')]=recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x6')];recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x2b')]='';}recordings[_0xf578ce[_0x86fd('0x5')]][_0x86fd('0x21')][_0x86fd('0x2e')](function(_0x1624af){var _0x1714aa=_[_0x86fd('0x2f')](recordings[_0xf578ce['uniqueid']]);_0x1714aa[_0x86fd('0x1c')]=_0x1624af[_0x86fd('0x1c')];writeDB(_0x1714aa);});delete recordings[_0xf578ce[_0x86fd('0x5')]];}}catch(_0x24ec30){utils[_0x86fd('0x17')](util[_0x86fd('0x3')](_0x86fd('0x25'),_0xf578ce['uniqueid']),_0x24ec30);}};exports[_0x86fd('0x30')]=function(_0x3bac27){try{if(!_['isNil'](recordings[_0x3bac27['uniqueid']])){utils[_0x86fd('0xe')](util[_0x86fd('0x3')](_0x86fd('0x31'),_0x3bac27['uniqueid']),_0x3bac27);utils[_0x86fd('0x2')](util[_0x86fd('0x3')]('[%s][recordings][newexten]\x20application:%s\x20appdata:%s',_0x3bac27[_0x86fd('0x5')],_0x3bac27[_0x86fd('0x32')],_0x3bac27[_0x86fd('0x33')]));if(_0x3bac27[_0x86fd('0x32')]['toLowerCase']()==_0x86fd('0x34')&&_[_0x86fd('0x35')](_0x3bac27['appdata'][_0x86fd('0x36')](),'cdr')){var _0x5dc19b=_0x3bac27[_0x86fd('0x33')][_0x86fd('0x37')]('=');var _0x550a15=_0x5dc19b[0x0][_0x86fd('0x38')](_0x5dc19b[0x0][_0x86fd('0x39')]('(')+0x1,_0x5dc19b[0x0][_0x86fd('0x39')](')'));var _0x218019=_0x5dc19b[0x1];recordings[_0x3bac27[_0x86fd('0x5')]][_0x550a15]=_0x218019;}}}catch(_0x5f0708){utils[_0x86fd('0x17')](util[_0x86fd('0x3')](_0x86fd('0x31'),_0x3bac27['uniqueid']),_0x5f0708);}};exports[_0x86fd('0x3a')]=function(_0x1674b2){try{if(!_[_0x86fd('0x13')](recordings[_0x1674b2[_0x86fd('0x5')]])){utils[_0x86fd('0xe')](util[_0x86fd('0x3')](_0x86fd('0x3b'),_0x1674b2[_0x86fd('0x5')]),_0x1674b2);utils[_0x86fd('0x2')](util[_0x86fd('0x3')](_0x86fd('0x3c'),_0x1674b2[_0x86fd('0x5')],_0x1674b2['queue']));recordings[_0x1674b2['uniqueid']]['queue']=_0x1674b2[_0x86fd('0x3d')];}}catch(_0x415f5e){utils[_0x86fd('0x17')](util['format'](_0x86fd('0x3b'),_0x1674b2[_0x86fd('0x5')]),_0x415f5e);}};