Built motion from commit 7a4eb044.|2.5.36
[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 _0x272c=['then','UserId','CreateVoiceCallReport','request','newchannel','debug','[%s][calls][newchannel]','linkedid','context','exten','now','DOCUMENTATION','error','newstate','[%s][calls][newstate]','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','answertime','disposition','toNumber','hangup','[%s][calls][hangup]','callerid','calleridname','calleridnum','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','duration','diffTime','endtime','starttime','attendedtransfer','[%s][calls][attendedtransfer]','origtransfereruniqueid','localtwolinkedid','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','destinationchannel','musiconholdstart','[%s][calls][musiconholdstart]','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstartAt','musiconholdstop','[%s][calls][musiconholdstop]','mohtime','variable','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','source','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','destination','\x22\x20<','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-callerid-preview','xmd-queue','xmcs-queue','lastapplication','Queue','lastdata','xmd-contactid','ContactId','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','[%s][calls][varset]','newexten','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','toLowerCase','set','startsWith','appdata','cdr','lastIndexOf','includes','noop','execif','gotoif','lodash','./utils','NO\x20ANSWER','FAILED','BUSY','blinds','uniqueid','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','channel','queue','interface','connectedlinenum','getUserByInternal','accountcode'];(function(_0x5af5a7,_0x2020df){var _0x30634f=function(_0x4e8123){while(--_0x4e8123){_0x5af5a7['push'](_0x5af5a7['shift']());}};_0x30634f(++_0x2020df);}(_0x272c,0x137));var _0xc272=function(_0x4519dc,_0x506b7c){_0x4519dc=_0x4519dc-0x0;var _0x3a8c1d=_0x272c[_0x4519dc];return _0x3a8c1d;};'use strict';var _=require(_0xc272('0x0'));var util=require('util');var utils=require(_0xc272('0x1'));var transfers=require('./transfers.controller');var dispositions=[_0xc272('0x2'),_0xc272('0x3'),_0xc272('0x3'),_0xc272('0x2'),_0xc272('0x2'),'NO\x20ANSWER','ANSWERED',_0xc272('0x4'),_0xc272('0x3'),_0xc272('0x3'),'FAILED'];var channels={};function writeDB(_0x42c059){var _0x35bc66;if(transfers[_0xc272('0x5')][_0x42c059[_0xc272('0x6')]]){_0x35bc66=_0x42c059[_0xc272('0x6')];_0x42c059[_0xc272('0x6')]=transfers[_0xc272('0x5')][_0x42c059[_0xc272('0x6')]]['transfereeuniqueid'];}utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x9'),_0x42c059[_0xc272('0x6')],_0x42c059[_0xc272('0xa')],_0x42c059[_0xc272('0xb')],_0x42c059['membername'],_0x42c059[_0xc272('0xc')],_0x42c059['calleridnum'],_0x42c059[_0xc272('0xd')],_0x42c059['lastevent']));if(_0x42c059['accountcode']){utils[_0xc272('0xe')](_0x42c059[_0xc272('0xf')])[_0xc272('0x10')](function(_0x47864d){if(_0x47864d){_0x42c059[_0xc272('0x11')]=_0x47864d['id'];}utils['request'](_0xc272('0x12'),_0x42c059);});}else{utils[_0xc272('0x13')]('CreateVoiceCallReport',_0x42c059);}if(channels[_0x42c059['uniqueid']]){delete channels[_0x42c059[_0xc272('0x6')]];}else if(_0x35bc66&&channels[_0x35bc66]){delete transfers[_0xc272('0x5')][_0x35bc66];delete channels[_0x35bc66];}}exports[_0xc272('0x14')]=function(_0x4ee8a0){try{utils[_0xc272('0x15')](util['format'](_0xc272('0x16'),_0x4ee8a0[_0xc272('0x6')]),_0x4ee8a0);if(_0x4ee8a0[_0xc272('0x6')]==_0x4ee8a0[_0xc272('0x17')]&&_0x4ee8a0[_0xc272('0xa')]!='OutgoingSpoolFailed'){utils[_0xc272('0x7')](util['format']('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x4ee8a0[_0xc272('0x6')],_0x4ee8a0[_0xc272('0x18')],_0x4ee8a0[_0xc272('0x19')]));channels[_0x4ee8a0[_0xc272('0x6')]]={'uniqueid':_0x4ee8a0['uniqueid'],'accountcode':_0x4ee8a0[_0xc272('0xf')],'source':_0x4ee8a0['calleridnum'],'destination':_0x4ee8a0[_0xc272('0x19')],'destinationcontext':_0x4ee8a0['context'],'channel':_0x4ee8a0['channel'],'starttime':utils[_0xc272('0x1a')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0xc272('0x1b')};}}catch(_0x157e6a){utils[_0xc272('0x1c')](util[_0xc272('0x8')](_0xc272('0x16'),_0x4ee8a0[_0xc272('0x6')]),_0x157e6a);}};exports[_0xc272('0x1d')]=function(_0x3f0f4c){try{utils['debug'](util[_0xc272('0x8')](_0xc272('0x1e'),_0x3f0f4c[_0xc272('0x6')]),_0x3f0f4c);if(!_[_0xc272('0x1f')](channels[_0x3f0f4c[_0xc272('0x6')]])&&_0x3f0f4c[_0xc272('0x20')]==0x6){utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x21'),_0x3f0f4c[_0xc272('0x6')],_0x3f0f4c[_0xc272('0x18')],_0x3f0f4c[_0xc272('0xa')]));if(_[_0xc272('0x1f')](channels[_0x3f0f4c[_0xc272('0x6')]]['systemanswertime'])){channels[_0x3f0f4c['uniqueid']][_0xc272('0x22')]=utils[_0xc272('0x1a')]();}}else if(!_[_0xc272('0x1f')](channels[_0x3f0f4c['linkedid']])&&_0x3f0f4c[_0xc272('0x20')]==0x6&&_0x3f0f4c[_0xc272('0x18')]!=_0xc272('0x23')){utils[_0xc272('0x7')](util['format'](_0xc272('0x24'),_0x3f0f4c[_0xc272('0x6')],_0x3f0f4c[_0xc272('0x17')],_0x3f0f4c[_0xc272('0x18')],_0x3f0f4c[_0xc272('0xa')]));channels[_0x3f0f4c['linkedid']][_0xc272('0xf')]=_0x3f0f4c[_0xc272('0xf')];channels[_0x3f0f4c[_0xc272('0x17')]]['destinationchannel']=_0x3f0f4c[_0xc272('0xa')];if(_[_0xc272('0x1f')](channels[_0x3f0f4c[_0xc272('0x17')]]['answertime'])){channels[_0x3f0f4c[_0xc272('0x17')]][_0xc272('0x25')]=utils[_0xc272('0x1a')]();}channels[_0x3f0f4c[_0xc272('0x17')]][_0xc272('0x26')]=dispositions[_[_0xc272('0x27')](_0x3f0f4c[_0xc272('0x20')])]||'ANSWERED';}}catch(_0xe08bf6){utils[_0xc272('0x1c')](util[_0xc272('0x8')](_0xc272('0x1e'),_0x3f0f4c[_0xc272('0x6')]),_0xe08bf6);}};exports[_0xc272('0x28')]=function(_0x491b1a){try{if(!_[_0xc272('0x1f')](channels[_0x491b1a[_0xc272('0x6')]])){utils[_0xc272('0x15')](util[_0xc272('0x8')](_0xc272('0x29'),_0x491b1a[_0xc272('0x6')]),_0x491b1a);if(_[_0xc272('0x1f')](channels[_0x491b1a[_0xc272('0x6')]][_0xc272('0x2a')])){channels[_0x491b1a[_0xc272('0x6')]][_0xc272('0x2a')]=_0x491b1a[_0xc272('0x2b')]+'\x20<'+_0x491b1a[_0xc272('0x2c')]+'>';}utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x2d'),_0x491b1a[_0xc272('0x6')],channels[_0x491b1a[_0xc272('0x6')]]['callerid'],_0x491b1a[_0xc272('0x2e')]));channels[_0x491b1a['uniqueid']]['endtime']=utils['now']();channels[_0x491b1a[_0xc272('0x6')]][_0xc272('0x2f')]=utils[_0xc272('0x30')](channels[_0x491b1a[_0xc272('0x6')]][_0xc272('0x31')],channels[_0x491b1a['uniqueid']][_0xc272('0x32')]);channels[_0x491b1a[_0xc272('0x6')]]['billableseconds']=channels[_0x491b1a['uniqueid']][_0xc272('0x25')]?utils[_0xc272('0x30')](channels[_0x491b1a[_0xc272('0x6')]]['endtime'],channels[_0x491b1a[_0xc272('0x6')]][_0xc272('0x25')]):0x0;writeDB(channels[_0x491b1a['uniqueid']]);}}catch(_0x2c8013){utils['error'](util['format'](_0xc272('0x29'),_0x491b1a[_0xc272('0x6')]),_0x2c8013);}};exports[_0xc272('0x33')]=function(_0x50769b){try{if(!_[_0xc272('0x1f')](channels[_0x50769b['localtwolinkedid']])){utils[_0xc272('0x15')](util[_0xc272('0x8')](_0xc272('0x34'),_0x50769b[_0xc272('0x35')]),_0x50769b);if(channels[_0x50769b[_0xc272('0x36')]]['channel']==_0x50769b[_0xc272('0x37')]){utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x38'),_0x50769b[_0xc272('0x35')],_0x50769b['localtwolinkedid'],_0x50769b['secondtransfererchannel']));channels[_0x50769b[_0xc272('0x36')]]['destinationchannel']=_0x50769b[_0xc272('0x39')];channels[_0x50769b[_0xc272('0x36')]][_0xc272('0x3a')]=_0xc272('0x3b');}else if(channels[_0x50769b['localtwolinkedid']][_0xc272('0xa')]=_0x50769b[_0xc272('0x3c')]){utils[_0xc272('0x7')](util[_0xc272('0x8')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x50769b['origtransfereruniqueid'],_0x50769b[_0xc272('0x36')],_0x50769b[_0xc272('0x3d')]));channels[_0x50769b['localtwolinkedid']][_0xc272('0x3e')]=_0x50769b[_0xc272('0x3d')];channels[_0x50769b[_0xc272('0x36')]]['userfield']=_0xc272('0x3b');}}}catch(_0x3a73e9){utils[_0xc272('0x1c')](util[_0xc272('0x8')](_0xc272('0x34'),_0x50769b[_0xc272('0x35')]),_0x3a73e9);}};exports[_0xc272('0x3f')]=function(_0x2d235c){try{if(!_['isNil'](channels[_0x2d235c['uniqueid']])){utils[_0xc272('0x15')](util[_0xc272('0x8')](_0xc272('0x40'),_0x2d235c[_0xc272('0x6')]),_0x2d235c);channels[_0x2d235c[_0xc272('0x6')]]['musiconholdstartAt']=utils['now']();utils['info'](util[_0xc272('0x8')](_0xc272('0x41'),_0x2d235c['uniqueid'],channels[_0x2d235c[_0xc272('0x6')]][_0xc272('0x42')]));}}catch(_0x161a1b){utils['error'](util['format'](_0xc272('0x40'),_0x2d235c[_0xc272('0x6')]),_0x161a1b);}};exports[_0xc272('0x43')]=function(_0x17c3ea){try{if(!_['isNil'](channels[_0x17c3ea['uniqueid']])){utils[_0xc272('0x15')](util[_0xc272('0x8')](_0xc272('0x44'),_0x17c3ea['uniqueid']),_0x17c3ea);if(!_['isNil'](channels[_0x17c3ea[_0xc272('0x6')]][_0xc272('0x42')])){channels[_0x17c3ea[_0xc272('0x6')]][_0xc272('0x45')]+=utils[_0xc272('0x30')](utils[_0xc272('0x1a')](),channels[_0x17c3ea['uniqueid']][_0xc272('0x42')]);utils[_0xc272('0x7')](util[_0xc272('0x8')]('[%s][calls][musiconholdstop]\x20mohtime:%s',_0x17c3ea[_0xc272('0x6')],channels[_0x17c3ea[_0xc272('0x6')]][_0xc272('0x45')]));delete channels[_0x17c3ea[_0xc272('0x6')]][_0xc272('0x42')];}}}catch(_0x154a2f){utils[_0xc272('0x1c')](util[_0xc272('0x8')](_0xc272('0x44'),_0x17c3ea[_0xc272('0x6')]),_0x154a2f);}};exports['varset']=function(_0xd98e82){try{if(!_[_0xc272('0x1f')](channels[_0xd98e82['uniqueid']])){utils[_0xc272('0x15')](util[_0xc272('0x8')]('[%s][calls][varset]',_0xd98e82[_0xc272('0x6')]),_0xd98e82);if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x47')])){utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x48'),_0xd98e82[_0xc272('0x6')],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x4a')]=_0xd98e82[_0xc272('0x49')];}if(!_['isNil'](_0xd98e82['variable']['xmd-phone'])){utils[_0xc272('0x7')](util['format'](_0xc272('0x4b'),_0xd98e82[_0xc272('0x6')],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x4c')]=_0xd98e82['value'];channels[_0xd98e82['uniqueid']][_0xc272('0x2a')]='\x22'+_0xd98e82[_0xc272('0x49')]+_0xc272('0x4d')+_0xd98e82[_0xc272('0x49')]+'>';}if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')]['xmd-callerid-preview'])||!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x4e')])){utils[_0xc272('0x7')](util['format'](_0xc272('0x4f'),_0xd98e82['uniqueid'],!_['isNil'](_0xd98e82[_0xc272('0x46')][_0xc272('0x50')])?'xmd-callerid-preview':_0xc272('0x4e'),_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x2a')]=_0xd98e82[_0xc272('0x49')];}if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x51')])||!_['isNil'](_0xd98e82[_0xc272('0x46')][_0xc272('0x52')])){utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x4f'),_0xd98e82['uniqueid'],!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x51')])?'xmd-queue':_0xc272('0x52'),_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x53')]=_0xc272('0x54');channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x55')]=_0xd98e82['value'];channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0xb')]=!![];}if(!_[_0xc272('0x1f')](_0xd98e82['variable'][_0xc272('0x56')])){utils[_0xc272('0x7')](util[_0xc272('0x8')]('[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s',_0xd98e82[_0xc272('0x6')],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x57')]=_0xd98e82['value'];}if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')]['xmd-cdrtype'])){utils[_0xc272('0x7')](util['format'](_0xc272('0x58'),_0xd98e82[_0xc272('0x6')],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]][_0xc272('0x59')]=_0xd98e82[_0xc272('0x49')];}if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x5a')])){utils[_0xc272('0x7')](util['format'](_0xc272('0x5b'),_0xd98e82[_0xc272('0x6')],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82['uniqueid']][_0xc272('0x5c')]=_0xd98e82[_0xc272('0x49')];}if(!_[_0xc272('0x1f')](_0xd98e82[_0xc272('0x46')][_0xc272('0x5d')])){utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x5e'),_0xd98e82['uniqueid'],_0xd98e82[_0xc272('0x49')]));channels[_0xd98e82[_0xc272('0x6')]]['sipcallid']=_0xd98e82[_0xc272('0x49')];}}}catch(_0x298a0b){utils['error'](util[_0xc272('0x8')](_0xc272('0x5f'),_0xd98e82['uniqueid']),_0x298a0b);}};exports[_0xc272('0x60')]=function(_0xe3e7c2){try{if(!_[_0xc272('0x1f')](channels[_0xe3e7c2[_0xc272('0x6')]])){utils[_0xc272('0x15')](util[_0xc272('0x8')]('[%s][calls][newexten]',_0xe3e7c2[_0xc272('0x6')]),_0xe3e7c2);utils[_0xc272('0x7')](util[_0xc272('0x8')](_0xc272('0x61'),_0xe3e7c2[_0xc272('0x6')],_0xe3e7c2[_0xc272('0x62')],_0xe3e7c2['appdata']));if(_0xe3e7c2[_0xc272('0x62')][_0xc272('0x63')]()==_0xc272('0x64')&&_[_0xc272('0x65')](_0xe3e7c2[_0xc272('0x66')][_0xc272('0x63')](),_0xc272('0x67'))){var _0x1d9c96=_0xe3e7c2[_0xc272('0x66')]['split']('=');var _0x1792e6=_0x1d9c96[0x0]['substring'](_0x1d9c96[0x0][_0xc272('0x68')]('(')+0x1,_0x1d9c96[0x0][_0xc272('0x68')](')'));var _0x309e9f=_0x1d9c96[0x1];channels[_0xe3e7c2[_0xc272('0x6')]][_0x1792e6]=_0x309e9f;}if(!_[_0xc272('0x69')](['hangup',_0xc272('0x6a'),_0xc272('0x6b'),_0xc272('0x64'),_0xc272('0x6c')],_0xe3e7c2[_0xc272('0x62')][_0xc272('0x63')]())){channels[_0xe3e7c2['uniqueid']]['lastapplication']=_0xe3e7c2[_0xc272('0x62')];channels[_0xe3e7c2[_0xc272('0x6')]]['lastdata']=_0xe3e7c2[_0xc272('0x66')];}}}catch(_0x4bdddc){utils[_0xc272('0x1c')](util[_0xc272('0x8')]('[%s][calls][newexten]',_0xe3e7c2[_0xc272('0x6')]),_0x4bdddc);}};