4596cf1f6be0f7d120280de74dbb36836bda0cea
[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 _0x6f85=['lastIndexOf','includes','execif','application','lastdata','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','BUSY','info','format','CALL|%s|%s|%s|%s|%s|%s|%s|%s','uniqueid','channel','type','accountcode','source','destination','callerid','disposition','getUserByInternal','then','UserId','request','CreateVoiceCallReport','linkedid','OutgoingSpoolFailed','calleridnum','exten','context','now','error','newstate','isNil','channelstate','systemanswertime','destinationchannel','answertime','toNumber','stack','hangup','calleridname','endtime','duration','diffTime','starttime','attendedtransfer','localtwolinkedid','transfereechannel','secondtransfererchannel','transfertargetchannel','_attended','musiconholdstart','musiconholdstartAt','musiconholdstop','mohtime','value','variable','xmd-phone','\x22\x20<','xmd-callerid-preview','xmcs-queue','lastapplication','Queue','xmd-contactid','xmd-cdrtype','routeid','newexten','set','startsWith','appdata','toLowerCase','split'];(function(_0x2b10c6,_0x185590){var _0x3789d2=function(_0x272987){while(--_0x272987){_0x2b10c6['push'](_0x2b10c6['shift']());}};_0x3789d2(++_0x185590);}(_0x6f85,0xe9));var _0x56f8=function(_0x30d87a,_0xf3a07f){_0x30d87a=_0x30d87a-0x0;var _0x48f64b=_0x6f85[_0x30d87a];return _0x48f64b;};'use strict';var _=require(_0x56f8('0x0'));var util=require(_0x56f8('0x1'));var utils=require(_0x56f8('0x2'));var dispositions=[_0x56f8('0x3'),'FAILED',_0x56f8('0x4'),'NO\x20ANSWER',_0x56f8('0x3'),_0x56f8('0x3'),_0x56f8('0x5'),_0x56f8('0x6'),'FAILED',_0x56f8('0x4'),_0x56f8('0x4')];var channels={};function writeDB(_0x49bbab){utils[_0x56f8('0x7')](util[_0x56f8('0x8')](_0x56f8('0x9'),_0x49bbab[_0x56f8('0xa')],_0x49bbab[_0x56f8('0xb')],_0x49bbab[_0x56f8('0xc')],_0x49bbab[_0x56f8('0xd')],_0x49bbab[_0x56f8('0xe')],_0x49bbab[_0x56f8('0xf')],_0x49bbab[_0x56f8('0x10')],_0x49bbab[_0x56f8('0x11')]));if(_0x49bbab[_0x56f8('0xd')]){utils[_0x56f8('0x12')](_0x49bbab['accountcode'])[_0x56f8('0x13')](function(_0x56f524){if(_0x56f524){_0x49bbab[_0x56f8('0x14')]=_0x56f524['id'];}utils[_0x56f8('0x15')](_0x56f8('0x16'),_0x49bbab);});}else{utils[_0x56f8('0x15')](_0x56f8('0x16'),_0x49bbab);}if(channels[_0x49bbab[_0x56f8('0xa')]]){delete channels[_0x49bbab[_0x56f8('0xa')]];}}exports['newchannel']=function(_0xd38a60){try{if(_0xd38a60[_0x56f8('0xa')]==_0xd38a60[_0x56f8('0x17')]&&_0xd38a60[_0x56f8('0xb')]!=_0x56f8('0x18')){channels[_0xd38a60[_0x56f8('0xa')]]={'uniqueid':_0xd38a60[_0x56f8('0xa')],'accountcode':_0xd38a60[_0x56f8('0xd')],'source':_0xd38a60[_0x56f8('0x19')],'destination':_0xd38a60[_0x56f8('0x1a')],'destinationcontext':_0xd38a60[_0x56f8('0x1b')],'channel':_0xd38a60[_0x56f8('0xb')],'starttime':utils[_0x56f8('0x1c')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':'DOCUMENTATION'};}}catch(_0xa9dc2){utils[_0x56f8('0x1d')](_0xa9dc2['stack']);}};exports[_0x56f8('0x1e')]=function(_0x39690f){try{if(!_[_0x56f8('0x1f')](channels[_0x39690f[_0x56f8('0xa')]])&&_0x39690f[_0x56f8('0x20')]==0x6){if(_[_0x56f8('0x1f')](channels[_0x39690f['uniqueid']][_0x56f8('0x21')])){channels[_0x39690f['uniqueid']]['systemanswertime']=utils['now']();}}else if(!_[_0x56f8('0x1f')](channels[_0x39690f[_0x56f8('0x17')]])&&_0x39690f[_0x56f8('0x20')]==0x6&&_0x39690f[_0x56f8('0x1b')]!='transfer'){channels[_0x39690f[_0x56f8('0x17')]][_0x56f8('0xd')]=_0x39690f[_0x56f8('0xd')];channels[_0x39690f[_0x56f8('0x17')]][_0x56f8('0x22')]=_0x39690f[_0x56f8('0xb')];if(_[_0x56f8('0x1f')](channels[_0x39690f['linkedid']][_0x56f8('0x23')])){channels[_0x39690f[_0x56f8('0x17')]][_0x56f8('0x23')]=utils[_0x56f8('0x1c')]();}channels[_0x39690f[_0x56f8('0x17')]][_0x56f8('0x11')]=dispositions[_[_0x56f8('0x24')](_0x39690f['channelstate'])]||_0x56f8('0x5');}}catch(_0x4b73c0){utils[_0x56f8('0x1d')](_0x4b73c0[_0x56f8('0x25')]);}};exports[_0x56f8('0x26')]=function(_0x1c51b3){try{if(!_[_0x56f8('0x1f')](channels[_0x1c51b3['uniqueid']])){if(_['isNil'](channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x10')])){channels[_0x1c51b3['uniqueid']]['callerid']=_0x1c51b3[_0x56f8('0x27')]+'\x20<'+_0x1c51b3[_0x56f8('0x19')]+'>';}channels[_0x1c51b3['uniqueid']][_0x56f8('0x28')]=utils[_0x56f8('0x1c')]();channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x29')]=utils[_0x56f8('0x2a')](channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x28')],channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x2b')]);channels[_0x1c51b3[_0x56f8('0xa')]]['billableseconds']=channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x23')]?utils[_0x56f8('0x2a')](channels[_0x1c51b3['uniqueid']][_0x56f8('0x28')],channels[_0x1c51b3[_0x56f8('0xa')]][_0x56f8('0x23')]):0x0;writeDB(channels[_0x1c51b3['uniqueid']]);}}catch(_0x2d5b3c){utils['error'](_0x2d5b3c['stack']);}};exports[_0x56f8('0x2c')]=function(_0x40a973){try{if(!_['isNil'](channels[_0x40a973[_0x56f8('0x2d')]])){if(channels[_0x40a973[_0x56f8('0x2d')]]['channel']==_0x40a973[_0x56f8('0x2e')]){channels[_0x40a973['localtwolinkedid']]['destinationchannel']=_0x40a973[_0x56f8('0x2f')];channels[_0x40a973['localtwolinkedid']]['userfield']='_attended';}else if(channels[_0x40a973['localtwolinkedid']][_0x56f8('0xb')]=_0x40a973[_0x56f8('0x30')]){channels[_0x40a973['localtwolinkedid']][_0x56f8('0x22')]=_0x40a973['origtransfererchannel'];channels[_0x40a973['localtwolinkedid']]['userfield']=_0x56f8('0x31');}}}catch(_0x24390f){utils['error'](_0x24390f['stack']);}};exports[_0x56f8('0x32')]=function(_0x566f2c){try{if(!_[_0x56f8('0x1f')](channels[_0x566f2c[_0x56f8('0xa')]])){channels[_0x566f2c[_0x56f8('0xa')]][_0x56f8('0x33')]=utils[_0x56f8('0x1c')]();}}catch(_0x521db2){utils[_0x56f8('0x1d')](_0x521db2[_0x56f8('0x25')]);}};exports[_0x56f8('0x34')]=function(_0x3504b5){try{if(!_[_0x56f8('0x1f')](channels[_0x3504b5[_0x56f8('0xa')]])){if(!_[_0x56f8('0x1f')](channels[_0x3504b5['uniqueid']][_0x56f8('0x33')])){channels[_0x3504b5['uniqueid']][_0x56f8('0x35')]+=utils['diffTime'](utils[_0x56f8('0x1c')](),channels[_0x3504b5[_0x56f8('0xa')]][_0x56f8('0x33')]);delete channels[_0x3504b5[_0x56f8('0xa')]][_0x56f8('0x33')];}}}catch(_0x12f521){utils['error'](_0x12f521[_0x56f8('0x25')]);}};exports['varset']=function(_0x50b438){try{if(!_[_0x56f8('0x1f')](channels[_0x50b438['uniqueid']])){if(!_['isNil'](_0x50b438['variable']['xmd-originatecalleridnum'])){channels[_0x50b438[_0x56f8('0xa')]][_0x56f8('0xe')]=_0x50b438[_0x56f8('0x36')];}if(!_['isNil'](_0x50b438[_0x56f8('0x37')][_0x56f8('0x38')])){channels[_0x50b438[_0x56f8('0xa')]][_0x56f8('0xf')]=_0x50b438[_0x56f8('0x36')];channels[_0x50b438[_0x56f8('0xa')]]['callerid']='\x22'+_0x50b438[_0x56f8('0x36')]+_0x56f8('0x39')+_0x50b438[_0x56f8('0x36')]+'>';}if(!_[_0x56f8('0x1f')](_0x50b438[_0x56f8('0x37')][_0x56f8('0x3a')])||!_[_0x56f8('0x1f')](_0x50b438['variable']['xmd-callerid'])){channels[_0x50b438[_0x56f8('0xa')]][_0x56f8('0x10')]=_0x50b438[_0x56f8('0x36')];}if(!_['isNil'](_0x50b438[_0x56f8('0x37')]['xmd-queue'])||!_[_0x56f8('0x1f')](_0x50b438[_0x56f8('0x37')][_0x56f8('0x3b')])){channels[_0x50b438['uniqueid']][_0x56f8('0x3c')]=_0x56f8('0x3d');channels[_0x50b438[_0x56f8('0xa')]]['lastdata']=_0x50b438[_0x56f8('0x36')];channels[_0x50b438['uniqueid']]['queue']=!![];}if(!_[_0x56f8('0x1f')](_0x50b438[_0x56f8('0x37')][_0x56f8('0x3e')])){channels[_0x50b438[_0x56f8('0xa')]]['ContactId']=_0x50b438[_0x56f8('0x36')];}if(!_[_0x56f8('0x1f')](_0x50b438[_0x56f8('0x37')][_0x56f8('0x3f')])){channels[_0x50b438['uniqueid']]['type']=_0x50b438[_0x56f8('0x36')];}if(!_[_0x56f8('0x1f')](_0x50b438['variable']['outboundrouteid'])){channels[_0x50b438[_0x56f8('0xa')]][_0x56f8('0x40')]=_0x50b438[_0x56f8('0x36')];}if(!_[_0x56f8('0x1f')](_0x50b438[_0x56f8('0x37')]['sipcallid'])){channels[_0x50b438[_0x56f8('0xa')]]['sipcallid']=_0x50b438[_0x56f8('0x36')];}}}catch(_0x5c8d94){utils[_0x56f8('0x1d')](_0x5c8d94[_0x56f8('0x25')]);}};exports[_0x56f8('0x41')]=function(_0x297b7f){try{if(!_[_0x56f8('0x1f')](channels[_0x297b7f['uniqueid']])){if(_0x297b7f['application']['toLowerCase']()==_0x56f8('0x42')&&_[_0x56f8('0x43')](_0x297b7f[_0x56f8('0x44')][_0x56f8('0x45')](),'cdr')){var _0x36df96=_0x297b7f[_0x56f8('0x44')][_0x56f8('0x46')]('=');var _0x59983b=_0x36df96[0x0]['substring'](_0x36df96[0x0]['lastIndexOf']('(')+0x1,_0x36df96[0x0][_0x56f8('0x47')](')'));var _0x319648=_0x36df96[0x1];channels[_0x297b7f[_0x56f8('0xa')]][_0x59983b]=_0x319648;}if(!_[_0x56f8('0x48')]([_0x56f8('0x26'),'noop',_0x56f8('0x49'),'set','gotoif'],_0x297b7f[_0x56f8('0x4a')]['toLowerCase']())){channels[_0x297b7f['uniqueid']][_0x56f8('0x3c')]=_0x297b7f[_0x56f8('0x4a')];channels[_0x297b7f[_0x56f8('0xa')]][_0x56f8('0x4b')]=_0x297b7f[_0x56f8('0x44')];}}}catch(_0x2bb480){utils[_0x56f8('0x1d')](_0x2bb480['stack']);}};