Built motion from commit (unavailable).|2.4.19
[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 _0xbb90=['includes','noop','execif','gotoif','lodash','util','./utils','NO\x20ANSWER','ANSWERED','BUSY','FAILED','info','format','uniqueid','type','source','callerid','disposition','getUserByInternal','accountcode','then','UserId','request','CreateVoiceCallReport','newchannel','linkedid','channel','OutgoingSpoolFailed','calleridnum','exten','now','DOCUMENTATION','error','stack','newstate','isNil','channelstate','systemanswertime','destinationchannel','answertime','toNumber','hangup','endtime','duration','diffTime','starttime','billableseconds','attendedtransfer','localtwolinkedid','transfereechannel','secondtransfererchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','musiconholdstartAt','mohtime','varset','variable','value','xmd-phone','\x22\x20<','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','lastapplication','lastdata','xmd-contactid','ContactId','routeid','sipcallid','application','toLowerCase','set','startsWith','appdata','cdr','split','substring','lastIndexOf'];(function(_0x3dd8c6,_0x3ca820){var _0x1387ed=function(_0x5f0f60){while(--_0x5f0f60){_0x3dd8c6['push'](_0x3dd8c6['shift']());}};_0x1387ed(++_0x3ca820);}(_0xbb90,0x1f0));var _0x0bb9=function(_0x5afdf1,_0x2f8b33){_0x5afdf1=_0x5afdf1-0x0;var _0x5c1f8f=_0xbb90[_0x5afdf1];return _0x5c1f8f;};'use strict';var _=require(_0x0bb9('0x0'));var util=require(_0x0bb9('0x1'));var utils=require(_0x0bb9('0x2'));var dispositions=['NO\x20ANSWER','FAILED','FAILED',_0x0bb9('0x3'),_0x0bb9('0x3'),_0x0bb9('0x3'),_0x0bb9('0x4'),_0x0bb9('0x5'),_0x0bb9('0x6'),_0x0bb9('0x6'),'FAILED'];var channels={};function writeDB(_0x547a90){utils[_0x0bb9('0x7')](util[_0x0bb9('0x8')]('CALL|%s|%s|%s|%s|%s|%s|%s|%s',_0x547a90[_0x0bb9('0x9')],_0x547a90['channel'],_0x547a90[_0x0bb9('0xa')],_0x547a90['accountcode'],_0x547a90[_0x0bb9('0xb')],_0x547a90['destination'],_0x547a90[_0x0bb9('0xc')],_0x547a90[_0x0bb9('0xd')]));if(_0x547a90['accountcode']){utils[_0x0bb9('0xe')](_0x547a90[_0x0bb9('0xf')])[_0x0bb9('0x10')](function(_0x49105c){if(_0x49105c){_0x547a90[_0x0bb9('0x11')]=_0x49105c['id'];}utils[_0x0bb9('0x12')]('CreateVoiceCallReport',_0x547a90);});}else{utils[_0x0bb9('0x12')](_0x0bb9('0x13'),_0x547a90);}if(channels[_0x547a90[_0x0bb9('0x9')]]){delete channels[_0x547a90[_0x0bb9('0x9')]];}}exports[_0x0bb9('0x14')]=function(_0x45d511){try{if(_0x45d511[_0x0bb9('0x9')]==_0x45d511[_0x0bb9('0x15')]&&_0x45d511[_0x0bb9('0x16')]!=_0x0bb9('0x17')){channels[_0x45d511[_0x0bb9('0x9')]]={'uniqueid':_0x45d511['uniqueid'],'accountcode':_0x45d511['accountcode'],'source':_0x45d511[_0x0bb9('0x18')],'destination':_0x45d511[_0x0bb9('0x19')],'destinationcontext':_0x45d511['context'],'channel':_0x45d511[_0x0bb9('0x16')],'starttime':utils[_0x0bb9('0x1a')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x0bb9('0x3'),'amaflags':_0x0bb9('0x1b')};}}catch(_0x30bc71){utils[_0x0bb9('0x1c')](_0x30bc71[_0x0bb9('0x1d')]);}};exports[_0x0bb9('0x1e')]=function(_0x2c6dd8){try{if(!_[_0x0bb9('0x1f')](channels[_0x2c6dd8[_0x0bb9('0x9')]])&&_0x2c6dd8[_0x0bb9('0x20')]==0x6){if(_['isNil'](channels[_0x2c6dd8[_0x0bb9('0x9')]][_0x0bb9('0x21')])){channels[_0x2c6dd8[_0x0bb9('0x9')]][_0x0bb9('0x21')]=utils[_0x0bb9('0x1a')]();}}else if(!_['isNil'](channels[_0x2c6dd8[_0x0bb9('0x15')]])&&_0x2c6dd8['channelstate']==0x6&&_0x2c6dd8['context']!='transfer'){channels[_0x2c6dd8['linkedid']][_0x0bb9('0xf')]=_0x2c6dd8['accountcode'];channels[_0x2c6dd8[_0x0bb9('0x15')]][_0x0bb9('0x22')]=_0x2c6dd8[_0x0bb9('0x16')];if(_[_0x0bb9('0x1f')](channels[_0x2c6dd8[_0x0bb9('0x15')]]['answertime'])){channels[_0x2c6dd8[_0x0bb9('0x15')]][_0x0bb9('0x23')]=utils[_0x0bb9('0x1a')]();}channels[_0x2c6dd8[_0x0bb9('0x15')]][_0x0bb9('0xd')]=dispositions[_[_0x0bb9('0x24')](_0x2c6dd8['channelstate'])]||_0x0bb9('0x4');}}catch(_0x19158c){utils[_0x0bb9('0x1c')](_0x19158c['stack']);}};exports[_0x0bb9('0x25')]=function(_0x11ef57){try{if(!_[_0x0bb9('0x1f')](channels[_0x11ef57[_0x0bb9('0x9')]])){if(_['isNil'](channels[_0x11ef57[_0x0bb9('0x9')]]['callerid'])){channels[_0x11ef57['uniqueid']][_0x0bb9('0xc')]=_0x11ef57['calleridname']+'\x20<'+_0x11ef57[_0x0bb9('0x18')]+'>';}channels[_0x11ef57[_0x0bb9('0x9')]][_0x0bb9('0x26')]=utils[_0x0bb9('0x1a')]();channels[_0x11ef57[_0x0bb9('0x9')]][_0x0bb9('0x27')]=utils[_0x0bb9('0x28')](channels[_0x11ef57[_0x0bb9('0x9')]]['endtime'],channels[_0x11ef57['uniqueid']][_0x0bb9('0x29')]);channels[_0x11ef57[_0x0bb9('0x9')]][_0x0bb9('0x2a')]=channels[_0x11ef57[_0x0bb9('0x9')]][_0x0bb9('0x23')]?utils['diffTime'](channels[_0x11ef57[_0x0bb9('0x9')]][_0x0bb9('0x26')],channels[_0x11ef57[_0x0bb9('0x9')]]['answertime']):0x0;writeDB(channels[_0x11ef57[_0x0bb9('0x9')]]);}}catch(_0x250520){utils[_0x0bb9('0x1c')](_0x250520['stack']);}};exports[_0x0bb9('0x2b')]=function(_0x2c03a6){try{if(!_['isNil'](channels[_0x2c03a6[_0x0bb9('0x2c')]])){if(channels[_0x2c03a6[_0x0bb9('0x2c')]][_0x0bb9('0x16')]==_0x2c03a6[_0x0bb9('0x2d')]){channels[_0x2c03a6[_0x0bb9('0x2c')]][_0x0bb9('0x22')]=_0x2c03a6[_0x0bb9('0x2e')];channels[_0x2c03a6[_0x0bb9('0x2c')]][_0x0bb9('0x2f')]=_0x0bb9('0x30');}else if(channels[_0x2c03a6[_0x0bb9('0x2c')]][_0x0bb9('0x16')]=_0x2c03a6[_0x0bb9('0x31')]){channels[_0x2c03a6['localtwolinkedid']][_0x0bb9('0x22')]=_0x2c03a6[_0x0bb9('0x32')];channels[_0x2c03a6[_0x0bb9('0x2c')]][_0x0bb9('0x2f')]=_0x0bb9('0x30');}}}catch(_0x312c3c){utils[_0x0bb9('0x1c')](_0x312c3c[_0x0bb9('0x1d')]);}};exports[_0x0bb9('0x33')]=function(_0x510df6){try{if(!_[_0x0bb9('0x1f')](channels[_0x510df6['uniqueid']])){channels[_0x510df6[_0x0bb9('0x9')]][_0x0bb9('0x34')]=utils[_0x0bb9('0x1a')]();}}catch(_0x3dbb31){utils[_0x0bb9('0x1c')](_0x3dbb31[_0x0bb9('0x1d')]);}};exports['musiconholdstop']=function(_0x31b032){try{if(!_[_0x0bb9('0x1f')](channels[_0x31b032[_0x0bb9('0x9')]])){if(!_[_0x0bb9('0x1f')](channels[_0x31b032[_0x0bb9('0x9')]][_0x0bb9('0x34')])){channels[_0x31b032[_0x0bb9('0x9')]][_0x0bb9('0x35')]+=utils[_0x0bb9('0x28')](utils[_0x0bb9('0x1a')](),channels[_0x31b032[_0x0bb9('0x9')]]['musiconholdstartAt']);delete channels[_0x31b032[_0x0bb9('0x9')]][_0x0bb9('0x34')];}}}catch(_0x41ad43){utils[_0x0bb9('0x1c')](_0x41ad43[_0x0bb9('0x1d')]);}};exports[_0x0bb9('0x36')]=function(_0x28368d){try{if(!_[_0x0bb9('0x1f')](channels[_0x28368d['uniqueid']])){if(!_['isNil'](_0x28368d[_0x0bb9('0x37')]['xmd-originatecalleridnum'])){channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0xb')]=_0x28368d[_0x0bb9('0x38')];}if(!_['isNil'](_0x28368d['variable'][_0x0bb9('0x39')])){channels[_0x28368d['uniqueid']]['destination']=_0x28368d['value'];channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0xc')]='\x22'+_0x28368d[_0x0bb9('0x38')]+_0x0bb9('0x3a')+_0x28368d[_0x0bb9('0x38')]+'>';}if(!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')][_0x0bb9('0x3b')])||!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')][_0x0bb9('0x3c')])){channels[_0x28368d[_0x0bb9('0x9')]]['callerid']=_0x28368d[_0x0bb9('0x38')];}if(!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')][_0x0bb9('0x3d')])||!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')][_0x0bb9('0x3e')])){channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0x3f')]='Queue';channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0x40')]=_0x28368d['value'];channels[_0x28368d[_0x0bb9('0x9')]]['queue']=!![];}if(!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')][_0x0bb9('0x41')])){channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0x42')]=_0x28368d[_0x0bb9('0x38')];}if(!_['isNil'](_0x28368d[_0x0bb9('0x37')]['xmd-cdrtype'])){channels[_0x28368d[_0x0bb9('0x9')]]['type']=_0x28368d['value'];}if(!_['isNil'](_0x28368d[_0x0bb9('0x37')]['outboundrouteid'])){channels[_0x28368d['uniqueid']][_0x0bb9('0x43')]=_0x28368d['value'];}if(!_[_0x0bb9('0x1f')](_0x28368d[_0x0bb9('0x37')]['sipcallid'])){channels[_0x28368d[_0x0bb9('0x9')]][_0x0bb9('0x44')]=_0x28368d[_0x0bb9('0x38')];}}}catch(_0x3f73cf){utils[_0x0bb9('0x1c')](_0x3f73cf[_0x0bb9('0x1d')]);}};exports['newexten']=function(_0x4e46c0){try{if(!_[_0x0bb9('0x1f')](channels[_0x4e46c0[_0x0bb9('0x9')]])){if(_0x4e46c0[_0x0bb9('0x45')][_0x0bb9('0x46')]()==_0x0bb9('0x47')&&_[_0x0bb9('0x48')](_0x4e46c0[_0x0bb9('0x49')][_0x0bb9('0x46')](),_0x0bb9('0x4a'))){var _0x2a9529=_0x4e46c0[_0x0bb9('0x49')][_0x0bb9('0x4b')]('=');var _0x982aae=_0x2a9529[0x0][_0x0bb9('0x4c')](_0x2a9529[0x0][_0x0bb9('0x4d')]('(')+0x1,_0x2a9529[0x0][_0x0bb9('0x4d')](')'));var _0x65e2a4=_0x2a9529[0x1];channels[_0x4e46c0[_0x0bb9('0x9')]][_0x982aae]=_0x65e2a4;}if(!_[_0x0bb9('0x4e')]([_0x0bb9('0x25'),_0x0bb9('0x4f'),_0x0bb9('0x50'),_0x0bb9('0x47'),_0x0bb9('0x51')],_0x4e46c0[_0x0bb9('0x45')]['toLowerCase']())){channels[_0x4e46c0[_0x0bb9('0x9')]][_0x0bb9('0x3f')]=_0x4e46c0[_0x0bb9('0x45')];channels[_0x4e46c0['uniqueid']]['lastdata']=_0x4e46c0[_0x0bb9('0x49')];}}}catch(_0x3ffb01){utils[_0x0bb9('0x1c')](_0x3ffb01['stack']);}};