Built motion from commit 53172ac8.|2.6.30
[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 _0xf71b=['lastIndexOf','includes','hangup','noop','execif','gotoif','lodash','util','FAILED','NO\x20ANSWER','BUSY','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','membername','interface','calleridnum','connectedlinenum','accountcode','getUserByInternal','request','CreateVoiceCallReport','newchannel','[%s][calls][newchannel]','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','exten','context','now','DOCUMENTATION','error','debug','[%s][calls][newstate]','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','linkedid','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','destinationchannel','answertime','disposition','ANSWERED','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','billableseconds','attendedtransfer','localtwolinkedid','origtransfereruniqueid','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','_attended','transfertargetchannel','origtransfererchannel','userfield','[%s][calls][attendedtransfer]','[%s][calls][musiconholdstart]','musiconholdstartAt','musiconholdstop','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','[%s][calls][musiconholdstop]','[%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','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','xmcs-queue','lastapplication','Queue','queue','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','startsWith','cdr','split'];(function(_0x498c78,_0x2eab48){var _0xb7697f=function(_0x1f6da7){while(--_0x1f6da7){_0x498c78['push'](_0x498c78['shift']());}};_0xb7697f(++_0x2eab48);}(_0xf71b,0xd2));var _0xbf71=function(_0x45fb23,_0x4696d2){_0x45fb23=_0x45fb23-0x0;var _0x5ed695=_0xf71b[_0x45fb23];return _0x5ed695;};'use strict';var _=require(_0xbf71('0x0'));var util=require(_0xbf71('0x1'));var utils=require('./utils');var dispositions=['NO\x20ANSWER',_0xbf71('0x2'),_0xbf71('0x2'),_0xbf71('0x3'),_0xbf71('0x3'),_0xbf71('0x3'),'ANSWERED',_0xbf71('0x4'),'FAILED','FAILED',_0xbf71('0x2')];var channels={};function writeDB(_0x381719){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x7'),_0x381719[_0xbf71('0x8')],_0x381719[_0xbf71('0x9')],_0x381719['queue'],_0x381719[_0xbf71('0xa')],_0x381719[_0xbf71('0xb')],_0x381719[_0xbf71('0xc')],_0x381719[_0xbf71('0xd')],_0x381719['lastevent']));if(_0x381719[_0xbf71('0xe')]){utils[_0xbf71('0xf')](_0x381719[_0xbf71('0xe')])['then'](function(_0xddc481){if(_0xddc481){_0x381719['UserId']=_0xddc481['id'];}utils[_0xbf71('0x10')](_0xbf71('0x11'),_0x381719);});}else{utils[_0xbf71('0x10')](_0xbf71('0x11'),_0x381719);}if(channels[_0x381719[_0xbf71('0x8')]]){delete channels[_0x381719[_0xbf71('0x8')]];}}exports[_0xbf71('0x12')]=function(_0x11e922){try{utils['debug'](util[_0xbf71('0x6')](_0xbf71('0x13'),_0x11e922['uniqueid']),_0x11e922);if(_0x11e922[_0xbf71('0x8')]==_0x11e922['linkedid']&&_0x11e922['channel']!=_0xbf71('0x14')){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x15'),_0x11e922[_0xbf71('0x8')],_0x11e922['context'],_0x11e922[_0xbf71('0x16')]));channels[_0x11e922[_0xbf71('0x8')]]={'uniqueid':_0x11e922['uniqueid'],'accountcode':_0x11e922[_0xbf71('0xe')],'source':_0x11e922[_0xbf71('0xc')],'destination':_0x11e922[_0xbf71('0x16')],'destinationcontext':_0x11e922[_0xbf71('0x17')],'channel':_0x11e922['channel'],'starttime':utils[_0xbf71('0x18')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0xbf71('0x19')};}}catch(_0x4c68de){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')](_0xbf71('0x13'),_0x11e922[_0xbf71('0x8')]),_0x4c68de);}};exports['newstate']=function(_0x127e31){try{utils[_0xbf71('0x1b')](util['format'](_0xbf71('0x1c'),_0x127e31[_0xbf71('0x8')]),_0x127e31);if(!_[_0xbf71('0x1d')](channels[_0x127e31['uniqueid']])&&_0x127e31[_0xbf71('0x1e')]==0x6){utils['info'](util[_0xbf71('0x6')](_0xbf71('0x1f'),_0x127e31[_0xbf71('0x8')],_0x127e31['context'],_0x127e31[_0xbf71('0x9')]));if(_['isNil'](channels[_0x127e31[_0xbf71('0x8')]][_0xbf71('0x20')])){channels[_0x127e31[_0xbf71('0x8')]][_0xbf71('0x20')]=utils['now']();}}else if(!_[_0xbf71('0x1d')](channels[_0x127e31[_0xbf71('0x21')]])&&_0x127e31[_0xbf71('0x1e')]==0x6&&_0x127e31[_0xbf71('0x17')]!=_0xbf71('0x22')){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x23'),_0x127e31['uniqueid'],_0x127e31[_0xbf71('0x21')],_0x127e31[_0xbf71('0x17')],_0x127e31['channel']));channels[_0x127e31['linkedid']]['accountcode']=_0x127e31[_0xbf71('0xe')];channels[_0x127e31[_0xbf71('0x21')]][_0xbf71('0x24')]=_0x127e31['channel'];if(_[_0xbf71('0x1d')](channels[_0x127e31[_0xbf71('0x21')]]['answertime'])){channels[_0x127e31[_0xbf71('0x21')]][_0xbf71('0x25')]=utils['now']();}channels[_0x127e31[_0xbf71('0x21')]][_0xbf71('0x26')]=dispositions[_['toNumber'](_0x127e31[_0xbf71('0x1e')])]||_0xbf71('0x27');}}catch(_0x4c51a9){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')](_0xbf71('0x1c'),_0x127e31['uniqueid']),_0x4c51a9);}};exports['hangup']=function(_0x4da034){try{if(!_[_0xbf71('0x1d')](channels[_0x4da034[_0xbf71('0x8')]])){utils['debug'](util['format'](_0xbf71('0x28'),_0x4da034['uniqueid']),_0x4da034);if(_[_0xbf71('0x1d')](channels[_0x4da034[_0xbf71('0x8')]][_0xbf71('0x29')])){channels[_0x4da034[_0xbf71('0x8')]][_0xbf71('0x29')]=_0x4da034[_0xbf71('0x2a')]+'\x20<'+_0x4da034[_0xbf71('0xc')]+'>';}utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x2b'),_0x4da034[_0xbf71('0x8')],channels[_0x4da034[_0xbf71('0x8')]]['callerid'],_0x4da034[_0xbf71('0x2c')]));channels[_0x4da034['uniqueid']][_0xbf71('0x2d')]=utils[_0xbf71('0x18')]();channels[_0x4da034[_0xbf71('0x8')]][_0xbf71('0x2e')]=utils[_0xbf71('0x2f')](channels[_0x4da034[_0xbf71('0x8')]]['endtime'],channels[_0x4da034[_0xbf71('0x8')]]['starttime']);channels[_0x4da034['uniqueid']][_0xbf71('0x30')]=channels[_0x4da034[_0xbf71('0x8')]][_0xbf71('0x25')]?utils['diffTime'](channels[_0x4da034[_0xbf71('0x8')]]['endtime'],channels[_0x4da034['uniqueid']][_0xbf71('0x25')]):0x0;writeDB(channels[_0x4da034[_0xbf71('0x8')]]);}}catch(_0x3a6f3d){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')](_0xbf71('0x28'),_0x4da034[_0xbf71('0x8')]),_0x3a6f3d);}};exports[_0xbf71('0x31')]=function(_0x31d433){try{if(!_[_0xbf71('0x1d')](channels[_0x31d433[_0xbf71('0x32')]])){utils[_0xbf71('0x1b')](util[_0xbf71('0x6')]('[%s][calls][attendedtransfer]',_0x31d433[_0xbf71('0x33')]),_0x31d433);if(channels[_0x31d433[_0xbf71('0x32')]][_0xbf71('0x9')]==_0x31d433['transfereechannel']){utils['info'](util[_0xbf71('0x6')](_0xbf71('0x34'),_0x31d433['origtransfereruniqueid'],_0x31d433[_0xbf71('0x32')],_0x31d433[_0xbf71('0x35')]));channels[_0x31d433[_0xbf71('0x32')]][_0xbf71('0x24')]=_0x31d433['secondtransfererchannel'];channels[_0x31d433[_0xbf71('0x32')]]['userfield']=_0xbf71('0x36');}else if(channels[_0x31d433[_0xbf71('0x32')]]['channel']=_0x31d433[_0xbf71('0x37')]){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x34'),_0x31d433[_0xbf71('0x33')],_0x31d433[_0xbf71('0x32')],_0x31d433[_0xbf71('0x38')]));channels[_0x31d433[_0xbf71('0x32')]][_0xbf71('0x24')]=_0x31d433[_0xbf71('0x38')];channels[_0x31d433['localtwolinkedid']][_0xbf71('0x39')]=_0xbf71('0x36');}}}catch(_0x58e637){utils[_0xbf71('0x1a')](util['format'](_0xbf71('0x3a'),_0x31d433[_0xbf71('0x33')]),_0x58e637);}};exports['musiconholdstart']=function(_0x41b6bc){try{if(!_[_0xbf71('0x1d')](channels[_0x41b6bc[_0xbf71('0x8')]])){utils[_0xbf71('0x1b')](util[_0xbf71('0x6')](_0xbf71('0x3b'),_0x41b6bc['uniqueid']),_0x41b6bc);channels[_0x41b6bc[_0xbf71('0x8')]][_0xbf71('0x3c')]=utils['now']();utils[_0xbf71('0x5')](util[_0xbf71('0x6')]('[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s',_0x41b6bc[_0xbf71('0x8')],channels[_0x41b6bc['uniqueid']][_0xbf71('0x3c')]));}}catch(_0x55d0c9){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')]('[%s][calls][musiconholdstart]',_0x41b6bc['uniqueid']),_0x55d0c9);}};exports[_0xbf71('0x3d')]=function(_0x31f7d8){try{if(!_['isNil'](channels[_0x31f7d8[_0xbf71('0x8')]])){utils[_0xbf71('0x1b')](util['format']('[%s][calls][musiconholdstop]',_0x31f7d8[_0xbf71('0x8')]),_0x31f7d8);if(!_[_0xbf71('0x1d')](channels[_0x31f7d8[_0xbf71('0x8')]][_0xbf71('0x3c')])){channels[_0x31f7d8[_0xbf71('0x8')]][_0xbf71('0x3e')]+=utils[_0xbf71('0x2f')](utils[_0xbf71('0x18')](),channels[_0x31f7d8[_0xbf71('0x8')]]['musiconholdstartAt']);utils['info'](util['format'](_0xbf71('0x3f'),_0x31f7d8[_0xbf71('0x8')],channels[_0x31f7d8[_0xbf71('0x8')]][_0xbf71('0x3e')]));delete channels[_0x31f7d8['uniqueid']][_0xbf71('0x3c')];}}}catch(_0x52d402){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')](_0xbf71('0x40'),_0x31f7d8[_0xbf71('0x8')]),_0x52d402);}};exports['varset']=function(_0x403188){try{if(!_[_0xbf71('0x1d')](channels[_0x403188[_0xbf71('0x8')]])){utils[_0xbf71('0x1b')](util['format'](_0xbf71('0x41'),_0x403188[_0xbf71('0x8')]),_0x403188);if(!_[_0xbf71('0x1d')](_0x403188['variable'][_0xbf71('0x42')])){utils[_0xbf71('0x5')](util['format'](_0xbf71('0x43'),_0x403188[_0xbf71('0x8')],_0x403188[_0xbf71('0x44')]));channels[_0x403188[_0xbf71('0x8')]]['source']=_0x403188[_0xbf71('0x44')];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x46')])){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x47'),_0x403188[_0xbf71('0x8')],_0x403188[_0xbf71('0x44')]));channels[_0x403188['uniqueid']][_0xbf71('0x48')]=_0x403188[_0xbf71('0x44')];channels[_0x403188[_0xbf71('0x8')]][_0xbf71('0x29')]='\x22'+_0x403188[_0xbf71('0x44')]+'\x22\x20<'+_0x403188[_0xbf71('0x44')]+'>';}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x49')])||!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')]['xmd-callerid'])){utils['info'](util['format'](_0xbf71('0x4a'),_0x403188['uniqueid'],!_['isNil'](_0x403188[_0xbf71('0x45')][_0xbf71('0x49')])?_0xbf71('0x49'):'xmd-callerid',_0x403188[_0xbf71('0x44')]));channels[_0x403188[_0xbf71('0x8')]][_0xbf71('0x29')]=_0x403188[_0xbf71('0x44')];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x4b')])||!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x4c')])){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x4a'),_0x403188[_0xbf71('0x8')],!_[_0xbf71('0x1d')](_0x403188['variable'][_0xbf71('0x4b')])?_0xbf71('0x4b'):_0xbf71('0x4c'),_0x403188['value']));channels[_0x403188['uniqueid']][_0xbf71('0x4d')]=_0xbf71('0x4e');channels[_0x403188['uniqueid']]['lastdata']=_0x403188['value'];channels[_0x403188[_0xbf71('0x8')]][_0xbf71('0x4f')]=!![];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x50')])){utils['info'](util[_0xbf71('0x6')](_0xbf71('0x51'),_0x403188[_0xbf71('0x8')],_0x403188['value']));channels[_0x403188['uniqueid']]['ContactId']=_0x403188[_0xbf71('0x44')];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')]['xmd-cdrtype'])){utils[_0xbf71('0x5')](util[_0xbf71('0x6')](_0xbf71('0x52'),_0x403188[_0xbf71('0x8')],_0x403188[_0xbf71('0x44')]));channels[_0x403188[_0xbf71('0x8')]][_0xbf71('0x53')]=_0x403188[_0xbf71('0x44')];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')]['outboundrouteid'])){utils['info'](util[_0xbf71('0x6')](_0xbf71('0x54'),_0x403188['uniqueid'],_0x403188[_0xbf71('0x44')]));channels[_0x403188['uniqueid']][_0xbf71('0x55')]=_0x403188[_0xbf71('0x44')];}if(!_[_0xbf71('0x1d')](_0x403188[_0xbf71('0x45')][_0xbf71('0x56')])){utils[_0xbf71('0x5')](util['format']('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x403188[_0xbf71('0x8')],_0x403188[_0xbf71('0x44')]));channels[_0x403188['uniqueid']]['sipcallid']=_0x403188[_0xbf71('0x44')];}}}catch(_0x292ea8){utils[_0xbf71('0x1a')](util[_0xbf71('0x6')](_0xbf71('0x41'),_0x403188[_0xbf71('0x8')]),_0x292ea8);}};exports[_0xbf71('0x57')]=function(_0x39047c){try{if(!_[_0xbf71('0x1d')](channels[_0x39047c['uniqueid']])){utils[_0xbf71('0x1b')](util['format'](_0xbf71('0x58'),_0x39047c['uniqueid']),_0x39047c);utils[_0xbf71('0x5')](util['format'](_0xbf71('0x59'),_0x39047c[_0xbf71('0x8')],_0x39047c[_0xbf71('0x5a')],_0x39047c[_0xbf71('0x5b')]));if(_0x39047c[_0xbf71('0x5a')][_0xbf71('0x5c')]()=='set'&&_[_0xbf71('0x5d')](_0x39047c[_0xbf71('0x5b')]['toLowerCase'](),_0xbf71('0x5e'))){var _0x4f06e6=_0x39047c[_0xbf71('0x5b')][_0xbf71('0x5f')]('=');var _0x39fbd4=_0x4f06e6[0x0]['substring'](_0x4f06e6[0x0]['lastIndexOf']('(')+0x1,_0x4f06e6[0x0][_0xbf71('0x60')](')'));var _0x1e8c63=_0x4f06e6[0x1];channels[_0x39047c[_0xbf71('0x8')]][_0x39fbd4]=_0x1e8c63;}if(!_[_0xbf71('0x61')]([_0xbf71('0x62'),_0xbf71('0x63'),_0xbf71('0x64'),'set',_0xbf71('0x65')],_0x39047c[_0xbf71('0x5a')][_0xbf71('0x5c')]())){channels[_0x39047c[_0xbf71('0x8')]][_0xbf71('0x4d')]=_0x39047c['application'];channels[_0x39047c['uniqueid']]['lastdata']=_0x39047c[_0xbf71('0x5b')];}}}catch(_0x4beb8c){utils['error'](util[_0xbf71('0x6')](_0xbf71('0x58'),_0x39047c[_0xbf71('0x8')]),_0x4beb8c);}};