Built motion from commit (unavailable).|2.5.4
[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 _0x58df=['execif','gotoif','lastdata','lodash','util','./utils','FAILED','NO\x20ANSWER','ANSWERED','info','format','CALL|%s|%s|%s|%s|%s|%s|%s|%s','channel','type','source','disposition','getUserByInternal','accountcode','then','UserId','request','newchannel','uniqueid','OutgoingSpoolFailed','now','stack','newstate','isNil','systemanswertime','linkedid','channelstate','context','transfer','destinationchannel','answertime','toNumber','error','calleridnum','endtime','duration','diffTime','starttime','localtwolinkedid','transfereechannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','musiconholdstartAt','musiconholdstop','mohtime','varset','value','variable','xmd-phone','destination','\x22\x20<','xmd-callerid-preview','xmd-callerid','callerid','xmd-queue','lastapplication','queue','xmd-contactid','ContactId','xmd-cdrtype','outboundrouteid','routeid','sipcallid','newexten','application','toLowerCase','set','startsWith','appdata','cdr','split','substring','lastIndexOf','noop'];(function(_0x21923b,_0x44380f){var _0x3ff466=function(_0x4cd098){while(--_0x4cd098){_0x21923b['push'](_0x21923b['shift']());}};_0x3ff466(++_0x44380f);}(_0x58df,0x147));var _0xf58d=function(_0x5d26b7,_0x3ff698){_0x5d26b7=_0x5d26b7-0x0;var _0x572be7=_0x58df[_0x5d26b7];return _0x572be7;};'use strict';var _=require(_0xf58d('0x0'));var util=require(_0xf58d('0x1'));var utils=require(_0xf58d('0x2'));var dispositions=['NO\x20ANSWER',_0xf58d('0x3'),'FAILED','NO\x20ANSWER',_0xf58d('0x4'),_0xf58d('0x4'),_0xf58d('0x5'),'BUSY',_0xf58d('0x3'),_0xf58d('0x3'),'FAILED'];var channels={};function writeDB(_0x5ab393){utils[_0xf58d('0x6')](util[_0xf58d('0x7')](_0xf58d('0x8'),_0x5ab393['uniqueid'],_0x5ab393[_0xf58d('0x9')],_0x5ab393[_0xf58d('0xa')],_0x5ab393['accountcode'],_0x5ab393[_0xf58d('0xb')],_0x5ab393['destination'],_0x5ab393['callerid'],_0x5ab393[_0xf58d('0xc')]));if(_0x5ab393['accountcode']){utils[_0xf58d('0xd')](_0x5ab393[_0xf58d('0xe')])[_0xf58d('0xf')](function(_0x4e45d7){if(_0x4e45d7){_0x5ab393[_0xf58d('0x10')]=_0x4e45d7['id'];}utils[_0xf58d('0x11')]('CreateVoiceCallReport',_0x5ab393);});}else{utils['request']('CreateVoiceCallReport',_0x5ab393);}if(channels[_0x5ab393['uniqueid']]){delete channels[_0x5ab393['uniqueid']];}}exports[_0xf58d('0x12')]=function(_0x443aaf){try{if(_0x443aaf[_0xf58d('0x13')]==_0x443aaf['linkedid']&&_0x443aaf[_0xf58d('0x9')]!=_0xf58d('0x14')){channels[_0x443aaf['uniqueid']]={'uniqueid':_0x443aaf[_0xf58d('0x13')],'accountcode':_0x443aaf[_0xf58d('0xe')],'source':_0x443aaf['calleridnum'],'destination':_0x443aaf['exten'],'destinationcontext':_0x443aaf['context'],'channel':_0x443aaf[_0xf58d('0x9')],'starttime':utils[_0xf58d('0x15')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xf58d('0x4'),'amaflags':'DOCUMENTATION'};}}catch(_0x576930){utils['error'](_0x576930[_0xf58d('0x16')]);}};exports[_0xf58d('0x17')]=function(_0x3cf12f){try{if(!_[_0xf58d('0x18')](channels[_0x3cf12f['uniqueid']])&&_0x3cf12f['channelstate']==0x6){if(_['isNil'](channels[_0x3cf12f[_0xf58d('0x13')]][_0xf58d('0x19')])){channels[_0x3cf12f[_0xf58d('0x13')]][_0xf58d('0x19')]=utils[_0xf58d('0x15')]();}}else if(!_[_0xf58d('0x18')](channels[_0x3cf12f[_0xf58d('0x1a')]])&&_0x3cf12f[_0xf58d('0x1b')]==0x6&&_0x3cf12f[_0xf58d('0x1c')]!=_0xf58d('0x1d')){channels[_0x3cf12f[_0xf58d('0x1a')]][_0xf58d('0xe')]=_0x3cf12f[_0xf58d('0xe')];channels[_0x3cf12f[_0xf58d('0x1a')]][_0xf58d('0x1e')]=_0x3cf12f[_0xf58d('0x9')];if(_[_0xf58d('0x18')](channels[_0x3cf12f[_0xf58d('0x1a')]]['answertime'])){channels[_0x3cf12f[_0xf58d('0x1a')]][_0xf58d('0x1f')]=utils['now']();}channels[_0x3cf12f[_0xf58d('0x1a')]][_0xf58d('0xc')]=dispositions[_[_0xf58d('0x20')](_0x3cf12f[_0xf58d('0x1b')])]||_0xf58d('0x5');}}catch(_0x4e06df){utils[_0xf58d('0x21')](_0x4e06df[_0xf58d('0x16')]);}};exports['hangup']=function(_0x521133){try{if(!_[_0xf58d('0x18')](channels[_0x521133[_0xf58d('0x13')]])){if(_[_0xf58d('0x18')](channels[_0x521133['uniqueid']]['callerid'])){channels[_0x521133[_0xf58d('0x13')]]['callerid']=_0x521133['calleridname']+'\x20<'+_0x521133[_0xf58d('0x22')]+'>';}channels[_0x521133['uniqueid']][_0xf58d('0x23')]=utils[_0xf58d('0x15')]();channels[_0x521133['uniqueid']][_0xf58d('0x24')]=utils[_0xf58d('0x25')](channels[_0x521133['uniqueid']]['endtime'],channels[_0x521133[_0xf58d('0x13')]][_0xf58d('0x26')]);channels[_0x521133['uniqueid']]['billableseconds']=channels[_0x521133[_0xf58d('0x13')]]['answertime']?utils[_0xf58d('0x25')](channels[_0x521133[_0xf58d('0x13')]][_0xf58d('0x23')],channels[_0x521133[_0xf58d('0x13')]][_0xf58d('0x1f')]):0x0;writeDB(channels[_0x521133[_0xf58d('0x13')]]);}}catch(_0x5aa09b){utils['error'](_0x5aa09b[_0xf58d('0x16')]);}};exports['attendedtransfer']=function(_0x103967){try{if(!_[_0xf58d('0x18')](channels[_0x103967[_0xf58d('0x27')]])){if(channels[_0x103967[_0xf58d('0x27')]][_0xf58d('0x9')]==_0x103967[_0xf58d('0x28')]){channels[_0x103967[_0xf58d('0x27')]][_0xf58d('0x1e')]=_0x103967['secondtransfererchannel'];channels[_0x103967[_0xf58d('0x27')]][_0xf58d('0x29')]=_0xf58d('0x2a');}else if(channels[_0x103967['localtwolinkedid']][_0xf58d('0x9')]=_0x103967[_0xf58d('0x2b')]){channels[_0x103967[_0xf58d('0x27')]][_0xf58d('0x1e')]=_0x103967[_0xf58d('0x2c')];channels[_0x103967[_0xf58d('0x27')]][_0xf58d('0x29')]='_attended';}}}catch(_0x451b3c){utils['error'](_0x451b3c[_0xf58d('0x16')]);}};exports[_0xf58d('0x2d')]=function(_0x346df4){try{if(!_[_0xf58d('0x18')](channels[_0x346df4[_0xf58d('0x13')]])){channels[_0x346df4['uniqueid']][_0xf58d('0x2e')]=utils[_0xf58d('0x15')]();}}catch(_0x336713){utils['error'](_0x336713[_0xf58d('0x16')]);}};exports[_0xf58d('0x2f')]=function(_0x887722){try{if(!_[_0xf58d('0x18')](channels[_0x887722[_0xf58d('0x13')]])){if(!_['isNil'](channels[_0x887722[_0xf58d('0x13')]][_0xf58d('0x2e')])){channels[_0x887722[_0xf58d('0x13')]][_0xf58d('0x30')]+=utils[_0xf58d('0x25')](utils[_0xf58d('0x15')](),channels[_0x887722[_0xf58d('0x13')]][_0xf58d('0x2e')]);delete channels[_0x887722[_0xf58d('0x13')]][_0xf58d('0x2e')];}}}catch(_0x591b09){utils[_0xf58d('0x21')](_0x591b09[_0xf58d('0x16')]);}};exports[_0xf58d('0x31')]=function(_0x1b393c){try{if(!_[_0xf58d('0x18')](channels[_0x1b393c[_0xf58d('0x13')]])){if(!_[_0xf58d('0x18')](_0x1b393c['variable']['xmd-originatecalleridnum'])){channels[_0x1b393c['uniqueid']]['source']=_0x1b393c[_0xf58d('0x32')];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x34')])){channels[_0x1b393c[_0xf58d('0x13')]][_0xf58d('0x35')]=_0x1b393c[_0xf58d('0x32')];channels[_0x1b393c[_0xf58d('0x13')]]['callerid']='\x22'+_0x1b393c['value']+_0xf58d('0x36')+_0x1b393c[_0xf58d('0x32')]+'>';}if(!_['isNil'](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x37')])||!_[_0xf58d('0x18')](_0x1b393c['variable'][_0xf58d('0x38')])){channels[_0x1b393c[_0xf58d('0x13')]][_0xf58d('0x39')]=_0x1b393c['value'];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x3a')])||!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')]['xmcs-queue'])){channels[_0x1b393c[_0xf58d('0x13')]][_0xf58d('0x3b')]='Queue';channels[_0x1b393c['uniqueid']]['lastdata']=_0x1b393c['value'];channels[_0x1b393c['uniqueid']][_0xf58d('0x3c')]=!![];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x3d')])){channels[_0x1b393c[_0xf58d('0x13')]][_0xf58d('0x3e')]=_0x1b393c[_0xf58d('0x32')];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x3f')])){channels[_0x1b393c['uniqueid']][_0xf58d('0xa')]=_0x1b393c['value'];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')][_0xf58d('0x40')])){channels[_0x1b393c['uniqueid']][_0xf58d('0x41')]=_0x1b393c[_0xf58d('0x32')];}if(!_[_0xf58d('0x18')](_0x1b393c[_0xf58d('0x33')]['sipcallid'])){channels[_0x1b393c['uniqueid']][_0xf58d('0x42')]=_0x1b393c[_0xf58d('0x32')];}}}catch(_0x315bbd){utils['error'](_0x315bbd[_0xf58d('0x16')]);}};exports[_0xf58d('0x43')]=function(_0x5a4c87){try{if(!_[_0xf58d('0x18')](channels[_0x5a4c87[_0xf58d('0x13')]])){if(_0x5a4c87[_0xf58d('0x44')][_0xf58d('0x45')]()==_0xf58d('0x46')&&_[_0xf58d('0x47')](_0x5a4c87[_0xf58d('0x48')][_0xf58d('0x45')](),_0xf58d('0x49'))){var _0x4829bf=_0x5a4c87[_0xf58d('0x48')][_0xf58d('0x4a')]('=');var _0xecaa31=_0x4829bf[0x0][_0xf58d('0x4b')](_0x4829bf[0x0][_0xf58d('0x4c')]('(')+0x1,_0x4829bf[0x0][_0xf58d('0x4c')](')'));var _0xe29284=_0x4829bf[0x1];channels[_0x5a4c87[_0xf58d('0x13')]][_0xecaa31]=_0xe29284;}if(!_['includes'](['hangup',_0xf58d('0x4d'),_0xf58d('0x4e'),_0xf58d('0x46'),_0xf58d('0x4f')],_0x5a4c87['application']['toLowerCase']())){channels[_0x5a4c87[_0xf58d('0x13')]][_0xf58d('0x3b')]=_0x5a4c87[_0xf58d('0x44')];channels[_0x5a4c87['uniqueid']][_0xf58d('0x50')]=_0x5a4c87[_0xf58d('0x48')];}}}catch(_0x5b8ef7){utils[_0xf58d('0x21')](_0x5b8ef7[_0xf58d('0x16')]);}};