Built motion from commit (unavailable).|2.5.3
[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 _0x26eb=['gotoif','lastapplication','lodash','util','./utils','NO\x20ANSWER','FAILED','BUSY','info','format','CALL|%s|%s|%s|%s|%s|%s|%s|%s','uniqueid','channel','type','accountcode','source','destination','callerid','disposition','getUserByInternal','UserId','request','CreateVoiceCallReport','OutgoingSpoolFailed','calleridnum','exten','context','now','DOCUMENTATION','error','stack','newstate','isNil','channelstate','systemanswertime','linkedid','transfer','answertime','ANSWERED','hangup','calleridname','duration','diffTime','endtime','starttime','billableseconds','secondtransfererchannel','userfield','_attended','localtwolinkedid','destinationchannel','musiconholdstart','musiconholdstartAt','mohtime','varset','variable','xmd-originatecalleridnum','value','xmd-phone','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','Queue','lastdata','queue','xmd-cdrtype','outboundrouteid','routeid','sipcallid','application','toLowerCase','startsWith','appdata','split','substring','includes','noop','execif','set'];(function(_0x11f4cc,_0x40d102){var _0x53cabb=function(_0x3a7be4){while(--_0x3a7be4){_0x11f4cc['push'](_0x11f4cc['shift']());}};_0x53cabb(++_0x40d102);}(_0x26eb,0xf2));var _0xb26e=function(_0x127c7b,_0x48bacb){_0x127c7b=_0x127c7b-0x0;var _0x5f1e61=_0x26eb[_0x127c7b];return _0x5f1e61;};'use strict';var _=require(_0xb26e('0x0'));var util=require(_0xb26e('0x1'));var utils=require(_0xb26e('0x2'));var dispositions=[_0xb26e('0x3'),_0xb26e('0x4'),_0xb26e('0x4'),_0xb26e('0x3'),_0xb26e('0x3'),_0xb26e('0x3'),'ANSWERED',_0xb26e('0x5'),_0xb26e('0x4'),_0xb26e('0x4'),_0xb26e('0x4')];var channels={};function writeDB(_0x199d18){utils[_0xb26e('0x6')](util[_0xb26e('0x7')](_0xb26e('0x8'),_0x199d18[_0xb26e('0x9')],_0x199d18[_0xb26e('0xa')],_0x199d18[_0xb26e('0xb')],_0x199d18[_0xb26e('0xc')],_0x199d18[_0xb26e('0xd')],_0x199d18[_0xb26e('0xe')],_0x199d18[_0xb26e('0xf')],_0x199d18[_0xb26e('0x10')]));if(_0x199d18[_0xb26e('0xc')]){utils[_0xb26e('0x11')](_0x199d18[_0xb26e('0xc')])['then'](function(_0x2ee569){if(_0x2ee569){_0x199d18[_0xb26e('0x12')]=_0x2ee569['id'];}utils[_0xb26e('0x13')](_0xb26e('0x14'),_0x199d18);});}else{utils[_0xb26e('0x13')](_0xb26e('0x14'),_0x199d18);}if(channels[_0x199d18[_0xb26e('0x9')]]){delete channels[_0x199d18[_0xb26e('0x9')]];}}exports['newchannel']=function(_0xc4f46c){try{if(_0xc4f46c[_0xb26e('0x9')]==_0xc4f46c['linkedid']&&_0xc4f46c[_0xb26e('0xa')]!=_0xb26e('0x15')){channels[_0xc4f46c[_0xb26e('0x9')]]={'uniqueid':_0xc4f46c[_0xb26e('0x9')],'accountcode':_0xc4f46c[_0xb26e('0xc')],'source':_0xc4f46c[_0xb26e('0x16')],'destination':_0xc4f46c[_0xb26e('0x17')],'destinationcontext':_0xc4f46c[_0xb26e('0x18')],'channel':_0xc4f46c[_0xb26e('0xa')],'starttime':utils[_0xb26e('0x19')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xb26e('0x3'),'amaflags':_0xb26e('0x1a')};}}catch(_0x1cd52a){utils[_0xb26e('0x1b')](_0x1cd52a[_0xb26e('0x1c')]);}};exports[_0xb26e('0x1d')]=function(_0x4337ea){try{if(!_[_0xb26e('0x1e')](channels[_0x4337ea['uniqueid']])&&_0x4337ea[_0xb26e('0x1f')]==0x6){if(_[_0xb26e('0x1e')](channels[_0x4337ea[_0xb26e('0x9')]][_0xb26e('0x20')])){channels[_0x4337ea[_0xb26e('0x9')]][_0xb26e('0x20')]=utils[_0xb26e('0x19')]();}}else if(!_[_0xb26e('0x1e')](channels[_0x4337ea[_0xb26e('0x21')]])&&_0x4337ea[_0xb26e('0x1f')]==0x6&&_0x4337ea[_0xb26e('0x18')]!=_0xb26e('0x22')){channels[_0x4337ea['linkedid']][_0xb26e('0xc')]=_0x4337ea[_0xb26e('0xc')];channels[_0x4337ea[_0xb26e('0x21')]]['destinationchannel']=_0x4337ea[_0xb26e('0xa')];if(_[_0xb26e('0x1e')](channels[_0x4337ea['linkedid']][_0xb26e('0x23')])){channels[_0x4337ea[_0xb26e('0x21')]][_0xb26e('0x23')]=utils[_0xb26e('0x19')]();}channels[_0x4337ea[_0xb26e('0x21')]]['disposition']=dispositions[_['toNumber'](_0x4337ea[_0xb26e('0x1f')])]||_0xb26e('0x24');}}catch(_0x6407c9){utils[_0xb26e('0x1b')](_0x6407c9[_0xb26e('0x1c')]);}};exports[_0xb26e('0x25')]=function(_0x371d91){try{if(!_[_0xb26e('0x1e')](channels[_0x371d91[_0xb26e('0x9')]])){if(_['isNil'](channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0xf')])){channels[_0x371d91['uniqueid']][_0xb26e('0xf')]=_0x371d91[_0xb26e('0x26')]+'\x20<'+_0x371d91[_0xb26e('0x16')]+'>';}channels[_0x371d91[_0xb26e('0x9')]]['endtime']=utils[_0xb26e('0x19')]();channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x27')]=utils[_0xb26e('0x28')](channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x29')],channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x2a')]);channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x2b')]=channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x23')]?utils[_0xb26e('0x28')](channels[_0x371d91[_0xb26e('0x9')]][_0xb26e('0x29')],channels[_0x371d91['uniqueid']][_0xb26e('0x23')]):0x0;writeDB(channels[_0x371d91[_0xb26e('0x9')]]);}}catch(_0x863067){utils[_0xb26e('0x1b')](_0x863067[_0xb26e('0x1c')]);}};exports['attendedtransfer']=function(_0x1649f5){try{if(!_['isNil'](channels[_0x1649f5['localtwolinkedid']])){if(channels[_0x1649f5['localtwolinkedid']][_0xb26e('0xa')]==_0x1649f5['transfereechannel']){channels[_0x1649f5['localtwolinkedid']]['destinationchannel']=_0x1649f5[_0xb26e('0x2c')];channels[_0x1649f5['localtwolinkedid']][_0xb26e('0x2d')]=_0xb26e('0x2e');}else if(channels[_0x1649f5[_0xb26e('0x2f')]]['channel']=_0x1649f5['transfertargetchannel']){channels[_0x1649f5['localtwolinkedid']][_0xb26e('0x30')]=_0x1649f5['origtransfererchannel'];channels[_0x1649f5[_0xb26e('0x2f')]][_0xb26e('0x2d')]=_0xb26e('0x2e');}}}catch(_0x224ac1){utils[_0xb26e('0x1b')](_0x224ac1['stack']);}};exports[_0xb26e('0x31')]=function(_0xed5980){try{if(!_[_0xb26e('0x1e')](channels[_0xed5980[_0xb26e('0x9')]])){channels[_0xed5980[_0xb26e('0x9')]][_0xb26e('0x32')]=utils[_0xb26e('0x19')]();}}catch(_0x1dc9a3){utils['error'](_0x1dc9a3[_0xb26e('0x1c')]);}};exports['musiconholdstop']=function(_0x451366){try{if(!_[_0xb26e('0x1e')](channels[_0x451366['uniqueid']])){if(!_[_0xb26e('0x1e')](channels[_0x451366['uniqueid']][_0xb26e('0x32')])){channels[_0x451366['uniqueid']][_0xb26e('0x33')]+=utils['diffTime'](utils[_0xb26e('0x19')](),channels[_0x451366[_0xb26e('0x9')]][_0xb26e('0x32')]);delete channels[_0x451366['uniqueid']][_0xb26e('0x32')];}}}catch(_0x3cedbe){utils[_0xb26e('0x1b')](_0x3cedbe[_0xb26e('0x1c')]);}};exports[_0xb26e('0x34')]=function(_0x4f43ff){try{if(!_['isNil'](channels[_0x4f43ff[_0xb26e('0x9')]])){if(!_[_0xb26e('0x1e')](_0x4f43ff[_0xb26e('0x35')][_0xb26e('0x36')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0xd')]=_0x4f43ff[_0xb26e('0x37')];}if(!_[_0xb26e('0x1e')](_0x4f43ff[_0xb26e('0x35')][_0xb26e('0x38')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0xe')]=_0x4f43ff['value'];channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0xf')]='\x22'+_0x4f43ff[_0xb26e('0x37')]+'\x22\x20<'+_0x4f43ff['value']+'>';}if(!_[_0xb26e('0x1e')](_0x4f43ff['variable'][_0xb26e('0x39')])||!_['isNil'](_0x4f43ff['variable'][_0xb26e('0x3a')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0xf')]=_0x4f43ff[_0xb26e('0x37')];}if(!_[_0xb26e('0x1e')](_0x4f43ff['variable'][_0xb26e('0x3b')])||!_[_0xb26e('0x1e')](_0x4f43ff['variable'][_0xb26e('0x3c')])){channels[_0x4f43ff['uniqueid']]['lastapplication']=_0xb26e('0x3d');channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0x3e')]=_0x4f43ff['value'];channels[_0x4f43ff['uniqueid']][_0xb26e('0x3f')]=!![];}if(!_[_0xb26e('0x1e')](_0x4f43ff[_0xb26e('0x35')]['xmd-contactid'])){channels[_0x4f43ff[_0xb26e('0x9')]]['ContactId']=_0x4f43ff[_0xb26e('0x37')];}if(!_[_0xb26e('0x1e')](_0x4f43ff[_0xb26e('0x35')][_0xb26e('0x40')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0xb')]=_0x4f43ff['value'];}if(!_['isNil'](_0x4f43ff['variable'][_0xb26e('0x41')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0x42')]=_0x4f43ff[_0xb26e('0x37')];}if(!_[_0xb26e('0x1e')](_0x4f43ff[_0xb26e('0x35')][_0xb26e('0x43')])){channels[_0x4f43ff[_0xb26e('0x9')]][_0xb26e('0x43')]=_0x4f43ff[_0xb26e('0x37')];}}}catch(_0x351676){utils[_0xb26e('0x1b')](_0x351676[_0xb26e('0x1c')]);}};exports['newexten']=function(_0x5f42fa){try{if(!_[_0xb26e('0x1e')](channels[_0x5f42fa[_0xb26e('0x9')]])){if(_0x5f42fa[_0xb26e('0x44')][_0xb26e('0x45')]()=='set'&&_[_0xb26e('0x46')](_0x5f42fa[_0xb26e('0x47')][_0xb26e('0x45')](),'cdr')){var _0x19be6d=_0x5f42fa[_0xb26e('0x47')][_0xb26e('0x48')]('=');var _0x541d68=_0x19be6d[0x0][_0xb26e('0x49')](_0x19be6d[0x0]['lastIndexOf']('(')+0x1,_0x19be6d[0x0]['lastIndexOf'](')'));var _0x2e6778=_0x19be6d[0x1];channels[_0x5f42fa[_0xb26e('0x9')]][_0x541d68]=_0x2e6778;}if(!_[_0xb26e('0x4a')](['hangup',_0xb26e('0x4b'),_0xb26e('0x4c'),_0xb26e('0x4d'),_0xb26e('0x4e')],_0x5f42fa[_0xb26e('0x44')]['toLowerCase']())){channels[_0x5f42fa[_0xb26e('0x9')]][_0xb26e('0x4f')]=_0x5f42fa[_0xb26e('0x44')];channels[_0x5f42fa[_0xb26e('0x9')]][_0xb26e('0x3e')]=_0x5f42fa[_0xb26e('0x47')];}}}catch(_0x5a6ee4){utils[_0xb26e('0x1b')](_0x5a6ee4['stack']);}};