Built motion from commit (unavailable).|2.3.4
[motion2.git] / server / services / xdr / calls.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 _0xe756=['destaccountcode','assign','isBefore','starttime','isAfter','endtime','Local/_attended@transfer','destinationchannel','duration','billableseconds','lastdata','lodash','util','./utils','answertime','info','format','CALL|%s|%s|%s|%s|%s|%s|%s|%s','type','accountcode','source','callerid','disposition','getUserByInternal','then','UserId','request','CreateVoiceCallReport','channel','newchannel','isNil','uniqueid','linkedid','musiconholdstartAt','now','musiconholdstop','mohtime','diffTime','varset','variable','xmd-phone','value','xmd-callerid-preview','xmd-queue','lastapplication','Queue','queue','xmd-contactid','ContactId','routeid','newexten','application','set','startsWith','toLowerCase','cdr','appdata','split','substring','lastIndexOf','agentcomplete'];(function(_0x45fd89,_0x57f39a){var _0xa0dc0=function(_0x2e4955){while(--_0x2e4955){_0x45fd89['push'](_0x45fd89['shift']());}};_0xa0dc0(++_0x57f39a);}(_0xe756,0x1b6));var _0x6e75=function(_0x45cf8e,_0x43d33c){_0x45cf8e=_0x45cf8e-0x0;var _0x1416ef=_0xe756[_0x45cf8e];return _0x1416ef;};'use strict';var _=require(_0x6e75('0x0'));var util=require(_0x6e75('0x1'));var utils=require(_0x6e75('0x2'));var channels={};var timeouts={};function writeDB(_0x3c1320){return function(){_0x3c1320[_0x6e75('0x3')]=_0x3c1320['answertime']||null;utils[_0x6e75('0x4')](util[_0x6e75('0x5')](_0x6e75('0x6'),_0x3c1320['uniqueid'],_0x3c1320['channel'],_0x3c1320[_0x6e75('0x7')],_0x3c1320[_0x6e75('0x8')],_0x3c1320[_0x6e75('0x9')],_0x3c1320['destination'],_0x3c1320[_0x6e75('0xa')],_0x3c1320[_0x6e75('0xb')]));if(_0x3c1320[_0x6e75('0x8')]){utils[_0x6e75('0xc')](_0x3c1320['accountcode'])[_0x6e75('0xd')](function(_0x39d119){if(_0x39d119){_0x3c1320[_0x6e75('0xe')]=_0x39d119['id'];}utils[_0x6e75('0xf')](_0x6e75('0x10'),_0x3c1320);});}else{utils[_0x6e75('0xf')](_0x6e75('0x10'),_0x3c1320);}if(channels[_0x3c1320[_0x6e75('0x11')]]){delete channels[_0x3c1320[_0x6e75('0x11')]];}if(timeouts[_0x3c1320[_0x6e75('0x11')]]){delete timeouts[_0x3c1320[_0x6e75('0x11')]];}};}exports[_0x6e75('0x12')]=function(_0x121a24){if(_[_0x6e75('0x13')](channels[_0x121a24[_0x6e75('0x11')]])&&_0x121a24[_0x6e75('0x14')]==_0x121a24[_0x6e75('0x15')]){channels[_0x121a24['channel']]={'mohtime':0x0};if(_0x121a24[_0x6e75('0x8')]){channels[_0x121a24['channel']][_0x6e75('0x8')]=_0x121a24[_0x6e75('0x8')];}}};exports['musiconholdstart']=function(_0x49c00b){if(!_[_0x6e75('0x13')](channels[_0x49c00b[_0x6e75('0x11')]])){channels[_0x49c00b[_0x6e75('0x11')]][_0x6e75('0x16')]=utils[_0x6e75('0x17')]();}};exports[_0x6e75('0x18')]=function(_0x3e58b8){if(!_[_0x6e75('0x13')](channels[_0x3e58b8[_0x6e75('0x11')]])){if(!_[_0x6e75('0x13')](channels[_0x3e58b8[_0x6e75('0x11')]]['musiconholdstartAt'])){channels[_0x3e58b8['channel']][_0x6e75('0x19')]+=utils[_0x6e75('0x1a')](utils[_0x6e75('0x17')](),channels[_0x3e58b8[_0x6e75('0x11')]]['musiconholdstartAt']);delete channels[_0x3e58b8[_0x6e75('0x11')]][_0x6e75('0x16')];}}};exports[_0x6e75('0x1b')]=function(_0x40a2ef){if(!_['isNil'](channels[_0x40a2ef['channel']])){if(!_[_0x6e75('0x13')](_0x40a2ef['variable']['xmd-originatecalleridnum'])){channels[_0x40a2ef[_0x6e75('0x11')]][_0x6e75('0x9')]=_0x40a2ef['value'];}if(!_['isNil'](_0x40a2ef[_0x6e75('0x1c')][_0x6e75('0x1d')])){channels[_0x40a2ef[_0x6e75('0x11')]]['destination']=_0x40a2ef[_0x6e75('0x1e')];}if(!_['isNil'](_0x40a2ef[_0x6e75('0x1c')][_0x6e75('0x1f')])||!_[_0x6e75('0x13')](_0x40a2ef['variable']['xmd-callerid'])){channels[_0x40a2ef['channel']]['callerid']=_0x40a2ef['value'];}if(!_[_0x6e75('0x13')](_0x40a2ef[_0x6e75('0x1c')][_0x6e75('0x20')])){channels[_0x40a2ef[_0x6e75('0x11')]][_0x6e75('0x21')]=_0x6e75('0x22');channels[_0x40a2ef[_0x6e75('0x11')]]['lastdata']=_0x40a2ef[_0x6e75('0x1e')];channels[_0x40a2ef[_0x6e75('0x11')]][_0x6e75('0x23')]=!![];}if(!_[_0x6e75('0x13')](_0x40a2ef[_0x6e75('0x1c')][_0x6e75('0x24')])){channels[_0x40a2ef[_0x6e75('0x11')]][_0x6e75('0x25')]=_0x40a2ef[_0x6e75('0x1e')];}if(!_[_0x6e75('0x13')](_0x40a2ef[_0x6e75('0x1c')]['outboundrouteid'])){channels[_0x40a2ef[_0x6e75('0x11')]][_0x6e75('0x26')]=_0x40a2ef[_0x6e75('0x1e')];}}};exports[_0x6e75('0x27')]=function(_0x31a353){if(!_[_0x6e75('0x13')](channels[_0x31a353[_0x6e75('0x11')]])){if(_0x31a353[_0x6e75('0x28')]['toLowerCase']()==_0x6e75('0x29')&&_[_0x6e75('0x2a')](_0x31a353['appdata'][_0x6e75('0x2b')](),_0x6e75('0x2c'))){var _0x1a310b=_0x31a353[_0x6e75('0x2d')][_0x6e75('0x2e')]('=');var _0x46a510=_0x1a310b[0x0][_0x6e75('0x2f')](_0x1a310b[0x0]['lastIndexOf']('(')+0x1,_0x1a310b[0x0][_0x6e75('0x30')](')'));var _0x133038=_0x1a310b[0x1];channels[_0x31a353['channel']][_0x46a510]=_0x133038;}}};exports[_0x6e75('0x31')]=function(_0x265257){if(!_[_0x6e75('0x13')](channels[_0x265257[_0x6e75('0x11')]])){channels[_0x265257[_0x6e75('0x11')]][_0x6e75('0x8')]=_0x265257[_0x6e75('0x32')];}};function handleCDR(_0x5deb04){if(_[_0x6e75('0x13')](timeouts[_0x5deb04[_0x6e75('0x11')]])){channels[_0x5deb04[_0x6e75('0x11')]]=_[_0x6e75('0x33')](_0x5deb04,channels[_0x5deb04['channel']]);}else{clearTimeout(timeouts[_0x5deb04[_0x6e75('0x11')]]);channels[_0x5deb04[_0x6e75('0x11')]]=_[_0x6e75('0x33')](channels[_0x5deb04[_0x6e75('0x11')]],{'starttime':utils[_0x6e75('0x34')](_0x5deb04[_0x6e75('0x35')],channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x35')])?_0x5deb04['starttime']:channels[_0x5deb04[_0x6e75('0x11')]]['starttime'],'answertime':utils[_0x6e75('0x34')](_0x5deb04[_0x6e75('0x3')],channels[_0x5deb04[_0x6e75('0x11')]]['answertime'])?_0x5deb04[_0x6e75('0x3')]:channels[_0x5deb04[_0x6e75('0x11')]]['answertime']});if(utils[_0x6e75('0x36')](_0x5deb04[_0x6e75('0x37')],channels[_0x5deb04['channel']]['endtime'])){channels[_0x5deb04[_0x6e75('0x11')]]=_[_0x6e75('0x33')](channels[_0x5deb04[_0x6e75('0x11')]],{'endtime':_0x5deb04['endtime'],'destinationchannel':_['startsWith'](_0x5deb04['destinationchannel'],_0x6e75('0x38'))?channels[_0x5deb04['channel']][_0x6e75('0x39')]:_0x5deb04[_0x6e75('0x39')]});}channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x3a')]=utils[_0x6e75('0x1a')](channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x37')],channels[_0x5deb04[_0x6e75('0x11')]]['starttime']);channels[_0x5deb04['channel']][_0x6e75('0x3b')]=utils[_0x6e75('0x1a')](channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x37')],channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x3')]);if(_0x5deb04['lastapplication'][_0x6e75('0x2b')]()!='hangup'){channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x3c')]=_0x5deb04[_0x6e75('0x3c')];channels[_0x5deb04[_0x6e75('0x11')]][_0x6e75('0x21')]=_0x5deb04['lastapplication'];}}timeouts[_0x5deb04[_0x6e75('0x11')]]=setTimeout(writeDB(channels[_0x5deb04['channel']]),0x3e8);}exports[_0x6e75('0x2c')]=function(_0x58e79c){if(!_[_0x6e75('0x13')](channels[_0x58e79c[_0x6e75('0x11')]])){handleCDR(_0x58e79c);}else if(!_['isNil'](channels[_0x58e79c[_0x6e75('0x39')]])){_0x58e79c[_0x6e75('0x11')]=_0x58e79c['destinationchannel'];handleCDR(_0x58e79c);}};