2bc184a0eb8865d8d83f5873dc60a3755b78471d
[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 _0x89ed=['[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','exten','context','channel','now','DOCUMENTATION','error','newstate','[%s][calls][newstate]','channelstate','isNil','systemanswertime','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','answertime','disposition','toNumber','hangup','debug','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','duration','endtime','starttime','billableseconds','diffTime','[%s][calls][hangup]','attendedtransfer','localtwolinkedid','origtransfereruniqueid','transfereechannel','secondtransfererchannel','destinationchannel','userfield','_attended','transfertargetchannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfererchannel','musiconholdstart','[%s][calls][musiconholdstart]','musiconholdstartAt','musiconholdstop','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','[%s][calls][varset]','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','variable','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','destination','xmd-callerid-preview','xmd-callerid','xmcs-queue','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','lastapplication','lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','newexten','application','appdata','toLowerCase','set','startsWith','substring','lastIndexOf','includes','noop','execif','gotoif','util','./utils','./transfers.controller','NO\x20ANSWER','FAILED','ANSWERED','BUSY','blinds','uniqueid','transfereeuniqueid','info','format','membername','interface','calleridnum','connectedlinenum','lastevent','accountcode','then','UserId','request','CreateVoiceCallReport','newchannel'];(function(_0x234a9d,_0x2ab260){var _0x150982=function(_0xa4faf2){while(--_0xa4faf2){_0x234a9d['push'](_0x234a9d['shift']());}};_0x150982(++_0x2ab260);}(_0x89ed,0x136));var _0xd89e=function(_0x2ea92d,_0x2f5de7){_0x2ea92d=_0x2ea92d-0x0;var _0x3ccb05=_0x89ed[_0x2ea92d];return _0x3ccb05;};'use strict';var _=require('lodash');var util=require(_0xd89e('0x0'));var utils=require(_0xd89e('0x1'));var transfers=require(_0xd89e('0x2'));var dispositions=[_0xd89e('0x3'),_0xd89e('0x4'),_0xd89e('0x4'),_0xd89e('0x3'),_0xd89e('0x3'),_0xd89e('0x3'),_0xd89e('0x5'),_0xd89e('0x6'),_0xd89e('0x4'),_0xd89e('0x4'),_0xd89e('0x4')];var channels={};function writeDB(_0x39b484){var _0x5066c8;if(transfers[_0xd89e('0x7')][_0x39b484[_0xd89e('0x8')]]){_0x5066c8=_0x39b484[_0xd89e('0x8')];_0x39b484[_0xd89e('0x8')]=transfers[_0xd89e('0x7')][_0x39b484[_0xd89e('0x8')]][_0xd89e('0x9')];}utils[_0xd89e('0xa')](util[_0xd89e('0xb')]('[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s',_0x39b484[_0xd89e('0x8')],_0x39b484['channel'],_0x39b484['queue'],_0x39b484[_0xd89e('0xc')],_0x39b484[_0xd89e('0xd')],_0x39b484[_0xd89e('0xe')],_0x39b484[_0xd89e('0xf')],_0x39b484[_0xd89e('0x10')]));if(_0x39b484[_0xd89e('0x11')]){utils['getUserByInternal'](_0x39b484[_0xd89e('0x11')])[_0xd89e('0x12')](function(_0x26709d){if(_0x26709d){_0x39b484[_0xd89e('0x13')]=_0x26709d['id'];}utils['request']('CreateVoiceCallReport',_0x39b484);});}else{utils[_0xd89e('0x14')](_0xd89e('0x15'),_0x39b484);}if(channels[_0x39b484[_0xd89e('0x8')]]){delete channels[_0x39b484['uniqueid']];}else if(_0x5066c8&&channels[_0x5066c8]){delete transfers[_0xd89e('0x7')][_0x5066c8];delete channels[_0x5066c8];}}exports[_0xd89e('0x16')]=function(_0x56887e){try{utils['debug'](util[_0xd89e('0xb')](_0xd89e('0x17'),_0x56887e[_0xd89e('0x8')]),_0x56887e);if(_0x56887e[_0xd89e('0x8')]==_0x56887e[_0xd89e('0x18')]&&_0x56887e['channel']!=_0xd89e('0x19')){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x1a'),_0x56887e[_0xd89e('0x8')],_0x56887e['context'],_0x56887e[_0xd89e('0x1b')]));channels[_0x56887e['uniqueid']]={'uniqueid':_0x56887e[_0xd89e('0x8')],'accountcode':_0x56887e[_0xd89e('0x11')],'source':_0x56887e[_0xd89e('0xe')],'destination':_0x56887e['exten'],'destinationcontext':_0x56887e[_0xd89e('0x1c')],'channel':_0x56887e[_0xd89e('0x1d')],'starttime':utils[_0xd89e('0x1e')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xd89e('0x3'),'amaflags':_0xd89e('0x1f')};}}catch(_0x8464b5){utils[_0xd89e('0x20')](util[_0xd89e('0xb')](_0xd89e('0x17'),_0x56887e[_0xd89e('0x8')]),_0x8464b5);}};exports[_0xd89e('0x21')]=function(_0x1e4c1d){try{utils['debug'](util['format'](_0xd89e('0x22'),_0x1e4c1d[_0xd89e('0x8')]),_0x1e4c1d);if(!_['isNil'](channels[_0x1e4c1d[_0xd89e('0x8')]])&&_0x1e4c1d[_0xd89e('0x23')]==0x6){utils[_0xd89e('0xa')](util['format']('[%s][calls][newstate]\x20context:%s\x20channel:%s',_0x1e4c1d[_0xd89e('0x8')],_0x1e4c1d[_0xd89e('0x1c')],_0x1e4c1d[_0xd89e('0x1d')]));if(_[_0xd89e('0x24')](channels[_0x1e4c1d[_0xd89e('0x8')]][_0xd89e('0x25')])){channels[_0x1e4c1d['uniqueid']][_0xd89e('0x25')]=utils['now']();}}else if(!_[_0xd89e('0x24')](channels[_0x1e4c1d[_0xd89e('0x18')]])&&_0x1e4c1d['channelstate']==0x6&&_0x1e4c1d[_0xd89e('0x1c')]!=_0xd89e('0x26')){utils[_0xd89e('0xa')](util['format'](_0xd89e('0x27'),_0x1e4c1d['uniqueid'],_0x1e4c1d[_0xd89e('0x18')],_0x1e4c1d['context'],_0x1e4c1d[_0xd89e('0x1d')]));channels[_0x1e4c1d['linkedid']][_0xd89e('0x11')]=_0x1e4c1d['accountcode'];channels[_0x1e4c1d[_0xd89e('0x18')]]['destinationchannel']=_0x1e4c1d['channel'];if(_[_0xd89e('0x24')](channels[_0x1e4c1d[_0xd89e('0x18')]][_0xd89e('0x28')])){channels[_0x1e4c1d[_0xd89e('0x18')]][_0xd89e('0x28')]=utils['now']();}channels[_0x1e4c1d[_0xd89e('0x18')]][_0xd89e('0x29')]=dispositions[_[_0xd89e('0x2a')](_0x1e4c1d[_0xd89e('0x23')])]||'ANSWERED';}}catch(_0x577e09){utils[_0xd89e('0x20')](util[_0xd89e('0xb')](_0xd89e('0x22'),_0x1e4c1d['uniqueid']),_0x577e09);}};exports[_0xd89e('0x2b')]=function(_0x2d998d){try{if(!_[_0xd89e('0x24')](channels[_0x2d998d[_0xd89e('0x8')]])){utils[_0xd89e('0x2c')](util['format']('[%s][calls][hangup]',_0x2d998d[_0xd89e('0x8')]),_0x2d998d);if(_['isNil'](channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x2d')])){channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x2d')]=_0x2d998d[_0xd89e('0x2e')]+'\x20<'+_0x2d998d[_0xd89e('0xe')]+'>';}utils['info'](util[_0xd89e('0xb')](_0xd89e('0x2f'),_0x2d998d[_0xd89e('0x8')],channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x2d')],_0x2d998d[_0xd89e('0x30')]));channels[_0x2d998d['uniqueid']]['endtime']=utils['now']();channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x31')]=utils['diffTime'](channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x32')],channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x33')]);channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x34')]=channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x28')]?utils[_0xd89e('0x35')](channels[_0x2d998d[_0xd89e('0x8')]][_0xd89e('0x32')],channels[_0x2d998d[_0xd89e('0x8')]]['answertime']):0x0;writeDB(channels[_0x2d998d['uniqueid']]);}}catch(_0x573bbb){utils[_0xd89e('0x20')](util[_0xd89e('0xb')](_0xd89e('0x36'),_0x2d998d[_0xd89e('0x8')]),_0x573bbb);}};exports[_0xd89e('0x37')]=function(_0x33f708){try{if(!_[_0xd89e('0x24')](channels[_0x33f708[_0xd89e('0x38')]])){utils[_0xd89e('0x2c')](util[_0xd89e('0xb')]('[%s][calls][attendedtransfer]',_0x33f708[_0xd89e('0x39')]),_0x33f708);if(channels[_0x33f708['localtwolinkedid']][_0xd89e('0x1d')]==_0x33f708[_0xd89e('0x3a')]){utils[_0xd89e('0xa')](util[_0xd89e('0xb')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x33f708[_0xd89e('0x39')],_0x33f708[_0xd89e('0x38')],_0x33f708[_0xd89e('0x3b')]));channels[_0x33f708['localtwolinkedid']][_0xd89e('0x3c')]=_0x33f708[_0xd89e('0x3b')];channels[_0x33f708['localtwolinkedid']][_0xd89e('0x3d')]=_0xd89e('0x3e');}else if(channels[_0x33f708[_0xd89e('0x38')]][_0xd89e('0x1d')]=_0x33f708[_0xd89e('0x3f')]){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x40'),_0x33f708[_0xd89e('0x39')],_0x33f708['localtwolinkedid'],_0x33f708[_0xd89e('0x41')]));channels[_0x33f708[_0xd89e('0x38')]][_0xd89e('0x3c')]=_0x33f708[_0xd89e('0x41')];channels[_0x33f708[_0xd89e('0x38')]]['userfield']=_0xd89e('0x3e');}}}catch(_0x548aea){utils[_0xd89e('0x20')](util[_0xd89e('0xb')]('[%s][calls][attendedtransfer]',_0x33f708['origtransfereruniqueid']),_0x548aea);}};exports[_0xd89e('0x42')]=function(_0x250049){try{if(!_[_0xd89e('0x24')](channels[_0x250049[_0xd89e('0x8')]])){utils[_0xd89e('0x2c')](util['format'](_0xd89e('0x43'),_0x250049['uniqueid']),_0x250049);channels[_0x250049[_0xd89e('0x8')]][_0xd89e('0x44')]=utils[_0xd89e('0x1e')]();utils['info'](util[_0xd89e('0xb')]('[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s',_0x250049[_0xd89e('0x8')],channels[_0x250049[_0xd89e('0x8')]][_0xd89e('0x44')]));}}catch(_0x3eae3b){utils[_0xd89e('0x20')](util[_0xd89e('0xb')](_0xd89e('0x43'),_0x250049[_0xd89e('0x8')]),_0x3eae3b);}};exports[_0xd89e('0x45')]=function(_0x2cc196){try{if(!_[_0xd89e('0x24')](channels[_0x2cc196['uniqueid']])){utils[_0xd89e('0x2c')](util[_0xd89e('0xb')](_0xd89e('0x46'),_0x2cc196[_0xd89e('0x8')]),_0x2cc196);if(!_[_0xd89e('0x24')](channels[_0x2cc196[_0xd89e('0x8')]][_0xd89e('0x44')])){channels[_0x2cc196['uniqueid']][_0xd89e('0x47')]+=utils[_0xd89e('0x35')](utils['now'](),channels[_0x2cc196[_0xd89e('0x8')]]['musiconholdstartAt']);utils[_0xd89e('0xa')](util['format'](_0xd89e('0x48'),_0x2cc196[_0xd89e('0x8')],channels[_0x2cc196['uniqueid']]['mohtime']));delete channels[_0x2cc196['uniqueid']]['musiconholdstartAt'];}}}catch(_0x2e8694){utils[_0xd89e('0x20')](util['format'](_0xd89e('0x46'),_0x2cc196[_0xd89e('0x8')]),_0x2e8694);}};exports[_0xd89e('0x49')]=function(_0x5da6cf){try{if(!_['isNil'](channels[_0x5da6cf[_0xd89e('0x8')]])){utils[_0xd89e('0x2c')](util['format'](_0xd89e('0x4a'),_0x5da6cf[_0xd89e('0x8')]),_0x5da6cf);if(!_[_0xd89e('0x24')](_0x5da6cf['variable'][_0xd89e('0x4b')])){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x4c'),_0x5da6cf['uniqueid'],_0x5da6cf['value']));channels[_0x5da6cf[_0xd89e('0x8')]]['source']=_0x5da6cf[_0xd89e('0x4d')];}if(!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x4f')])){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x50'),_0x5da6cf['uniqueid'],_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x51')]=_0x5da6cf['value'];channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x2d')]='\x22'+_0x5da6cf[_0xd89e('0x4d')]+'\x22\x20<'+_0x5da6cf['value']+'>';}if(!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')]['xmd-callerid-preview'])||!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')]['xmd-callerid'])){utils['info'](util[_0xd89e('0xb')]('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x5da6cf[_0xd89e('0x8')],!_['isNil'](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x52')])?_0xd89e('0x52'):_0xd89e('0x53'),_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x2d')]=_0x5da6cf[_0xd89e('0x4d')];}if(!_[_0xd89e('0x24')](_0x5da6cf['variable']['xmd-queue'])||!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x54')])){utils[_0xd89e('0xa')](util['format'](_0xd89e('0x55'),_0x5da6cf[_0xd89e('0x8')],!_[_0xd89e('0x24')](_0x5da6cf['variable'][_0xd89e('0x56')])?'xmd-queue':_0xd89e('0x54'),_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x57')]='Queue';channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x58')]=_0x5da6cf['value'];channels[_0x5da6cf[_0xd89e('0x8')]]['queue']=!![];}if(!_[_0xd89e('0x24')](_0x5da6cf['variable'][_0xd89e('0x59')])){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x5a'),_0x5da6cf[_0xd89e('0x8')],_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x5b')]=_0x5da6cf['value'];}if(!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x5c')])){utils['info'](util['format'](_0xd89e('0x5d'),_0x5da6cf[_0xd89e('0x8')],_0x5da6cf['value']));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x5e')]=_0x5da6cf['value'];}if(!_['isNil'](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x5f')])){utils[_0xd89e('0xa')](util[_0xd89e('0xb')](_0xd89e('0x60'),_0x5da6cf[_0xd89e('0x8')],_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf[_0xd89e('0x8')]][_0xd89e('0x61')]=_0x5da6cf[_0xd89e('0x4d')];}if(!_[_0xd89e('0x24')](_0x5da6cf[_0xd89e('0x4e')][_0xd89e('0x62')])){utils['info'](util[_0xd89e('0xb')]('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x5da6cf[_0xd89e('0x8')],_0x5da6cf[_0xd89e('0x4d')]));channels[_0x5da6cf['uniqueid']]['sipcallid']=_0x5da6cf['value'];}}}catch(_0x321482){utils[_0xd89e('0x20')](util['format'](_0xd89e('0x4a'),_0x5da6cf[_0xd89e('0x8')]),_0x321482);}};exports[_0xd89e('0x63')]=function(_0x5671b3){try{if(!_[_0xd89e('0x24')](channels[_0x5671b3[_0xd89e('0x8')]])){utils[_0xd89e('0x2c')](util[_0xd89e('0xb')]('[%s][calls][newexten]',_0x5671b3[_0xd89e('0x8')]),_0x5671b3);utils[_0xd89e('0xa')](util[_0xd89e('0xb')]('[%s][calls][newexten]\x20application:%s\x20appdata:%s',_0x5671b3[_0xd89e('0x8')],_0x5671b3[_0xd89e('0x64')],_0x5671b3[_0xd89e('0x65')]));if(_0x5671b3[_0xd89e('0x64')][_0xd89e('0x66')]()==_0xd89e('0x67')&&_[_0xd89e('0x68')](_0x5671b3['appdata'][_0xd89e('0x66')](),'cdr')){var _0x1485cc=_0x5671b3[_0xd89e('0x65')]['split']('=');var _0x468fac=_0x1485cc[0x0][_0xd89e('0x69')](_0x1485cc[0x0]['lastIndexOf']('(')+0x1,_0x1485cc[0x0][_0xd89e('0x6a')](')'));var _0x2cd097=_0x1485cc[0x1];channels[_0x5671b3[_0xd89e('0x8')]][_0x468fac]=_0x2cd097;}if(!_[_0xd89e('0x6b')]([_0xd89e('0x2b'),_0xd89e('0x6c'),_0xd89e('0x6d'),_0xd89e('0x67'),_0xd89e('0x6e')],_0x5671b3[_0xd89e('0x64')][_0xd89e('0x66')]())){channels[_0x5671b3[_0xd89e('0x8')]][_0xd89e('0x57')]=_0x5671b3[_0xd89e('0x64')];channels[_0x5671b3[_0xd89e('0x8')]][_0xd89e('0x58')]=_0x5671b3[_0xd89e('0x65')];}}}catch(_0x2846c0){utils[_0xd89e('0x20')](util[_0xd89e('0xb')]('[%s][calls][newexten]',_0x5671b3[_0xd89e('0x8')]),_0x2846c0);}};