718a55e514357bb1f01f15d8692e1506ccea8abe
[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 _0xc8cc=['_attended','musiconholdstart','mohtime','varset','variable','xmd-originatecalleridnum','value','xmd-phone','destination','\x22\x20<','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','ContactId','xmd-cdrtype','outboundrouteid','routeid','application','toLowerCase','set','startsWith','appdata','split','substring','lastIndexOf','includes','noop','gotoif','lastapplication','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','BUSY','info','format','uniqueid','type','source','disposition','getUserByInternal','accountcode','UserId','CreateVoiceCallReport','request','newchannel','channel','OutgoingSpoolFailed','exten','context','now','DOCUMENTATION','stack','newstate','isNil','channelstate','systemanswertime','transfer','linkedid','destinationchannel','answertime','toNumber','error','hangup','callerid','calleridname','calleridnum','endtime','duration','diffTime','starttime','billableseconds','attendedtransfer','localtwolinkedid','transfereechannel','secondtransfererchannel','transfertargetchannel','origtransfererchannel','userfield'];(function(_0x168ed2,_0x19950f){var _0x14abe6=function(_0x5266d2){while(--_0x5266d2){_0x168ed2['push'](_0x168ed2['shift']());}};_0x14abe6(++_0x19950f);}(_0xc8cc,0x114));var _0xcc8c=function(_0x29c504,_0x5ce9aa){_0x29c504=_0x29c504-0x0;var _0x138d10=_0xc8cc[_0x29c504];return _0x138d10;};'use strict';var _=require(_0xcc8c('0x0'));var util=require(_0xcc8c('0x1'));var utils=require(_0xcc8c('0x2'));var dispositions=[_0xcc8c('0x3'),_0xcc8c('0x4'),_0xcc8c('0x4'),_0xcc8c('0x3'),'NO\x20ANSWER',_0xcc8c('0x3'),_0xcc8c('0x5'),_0xcc8c('0x6'),_0xcc8c('0x4'),_0xcc8c('0x4'),_0xcc8c('0x4')];var channels={};function writeDB(_0xc4df81){utils[_0xcc8c('0x7')](util[_0xcc8c('0x8')]('CALL|%s|%s|%s|%s|%s|%s|%s|%s',_0xc4df81[_0xcc8c('0x9')],_0xc4df81['channel'],_0xc4df81[_0xcc8c('0xa')],_0xc4df81['accountcode'],_0xc4df81[_0xcc8c('0xb')],_0xc4df81['destination'],_0xc4df81['callerid'],_0xc4df81[_0xcc8c('0xc')]));if(_0xc4df81['accountcode']){utils[_0xcc8c('0xd')](_0xc4df81[_0xcc8c('0xe')])['then'](function(_0x24b576){if(_0x24b576){_0xc4df81[_0xcc8c('0xf')]=_0x24b576['id'];}utils['request'](_0xcc8c('0x10'),_0xc4df81);});}else{utils[_0xcc8c('0x11')]('CreateVoiceCallReport',_0xc4df81);}if(channels[_0xc4df81[_0xcc8c('0x9')]]){delete channels[_0xc4df81['uniqueid']];}}exports[_0xcc8c('0x12')]=function(_0x22c207){try{if(_0x22c207[_0xcc8c('0x9')]==_0x22c207['linkedid']&&_0x22c207[_0xcc8c('0x13')]!=_0xcc8c('0x14')){channels[_0x22c207[_0xcc8c('0x9')]]={'uniqueid':_0x22c207[_0xcc8c('0x9')],'accountcode':_0x22c207[_0xcc8c('0xe')],'source':_0x22c207['calleridnum'],'destination':_0x22c207[_0xcc8c('0x15')],'destinationcontext':_0x22c207[_0xcc8c('0x16')],'channel':_0x22c207['channel'],'starttime':utils[_0xcc8c('0x17')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xcc8c('0x3'),'amaflags':_0xcc8c('0x18')};}}catch(_0x25e797){utils['error'](_0x25e797[_0xcc8c('0x19')]);}};exports[_0xcc8c('0x1a')]=function(_0x1e9566){try{if(!_[_0xcc8c('0x1b')](channels[_0x1e9566[_0xcc8c('0x9')]])&&_0x1e9566[_0xcc8c('0x1c')]==0x6){if(_['isNil'](channels[_0x1e9566['uniqueid']][_0xcc8c('0x1d')])){channels[_0x1e9566['uniqueid']][_0xcc8c('0x1d')]=utils[_0xcc8c('0x17')]();}}else if(!_[_0xcc8c('0x1b')](channels[_0x1e9566['linkedid']])&&_0x1e9566[_0xcc8c('0x1c')]==0x6&&_0x1e9566[_0xcc8c('0x16')]!=_0xcc8c('0x1e')){channels[_0x1e9566[_0xcc8c('0x1f')]][_0xcc8c('0xe')]=_0x1e9566[_0xcc8c('0xe')];channels[_0x1e9566[_0xcc8c('0x1f')]][_0xcc8c('0x20')]=_0x1e9566[_0xcc8c('0x13')];if(_[_0xcc8c('0x1b')](channels[_0x1e9566[_0xcc8c('0x1f')]][_0xcc8c('0x21')])){channels[_0x1e9566[_0xcc8c('0x1f')]][_0xcc8c('0x21')]=utils['now']();}channels[_0x1e9566['linkedid']][_0xcc8c('0xc')]=dispositions[_[_0xcc8c('0x22')](_0x1e9566['channelstate'])]||_0xcc8c('0x5');}}catch(_0x49aba5){utils[_0xcc8c('0x23')](_0x49aba5[_0xcc8c('0x19')]);}};exports[_0xcc8c('0x24')]=function(_0x4f7ec6){try{if(!_[_0xcc8c('0x1b')](channels[_0x4f7ec6[_0xcc8c('0x9')]])){if(_[_0xcc8c('0x1b')](channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x25')])){channels[_0x4f7ec6['uniqueid']][_0xcc8c('0x25')]=_0x4f7ec6[_0xcc8c('0x26')]+'\x20<'+_0x4f7ec6[_0xcc8c('0x27')]+'>';}channels[_0x4f7ec6['uniqueid']][_0xcc8c('0x28')]=utils[_0xcc8c('0x17')]();channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x29')]=utils[_0xcc8c('0x2a')](channels[_0x4f7ec6['uniqueid']]['endtime'],channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x2b')]);channels[_0x4f7ec6['uniqueid']][_0xcc8c('0x2c')]=channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x21')]?utils[_0xcc8c('0x2a')](channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x28')],channels[_0x4f7ec6[_0xcc8c('0x9')]][_0xcc8c('0x21')]):0x0;writeDB(channels[_0x4f7ec6[_0xcc8c('0x9')]]);}}catch(_0x48f852){utils[_0xcc8c('0x23')](_0x48f852['stack']);}};exports[_0xcc8c('0x2d')]=function(_0x5369f3){try{if(!_['isNil'](channels[_0x5369f3[_0xcc8c('0x2e')]])){if(channels[_0x5369f3[_0xcc8c('0x2e')]][_0xcc8c('0x13')]==_0x5369f3[_0xcc8c('0x2f')]){channels[_0x5369f3[_0xcc8c('0x2e')]][_0xcc8c('0x20')]=_0x5369f3[_0xcc8c('0x30')];channels[_0x5369f3[_0xcc8c('0x2e')]]['userfield']='_attended';}else if(channels[_0x5369f3[_0xcc8c('0x2e')]][_0xcc8c('0x13')]=_0x5369f3[_0xcc8c('0x31')]){channels[_0x5369f3[_0xcc8c('0x2e')]][_0xcc8c('0x20')]=_0x5369f3[_0xcc8c('0x32')];channels[_0x5369f3[_0xcc8c('0x2e')]][_0xcc8c('0x33')]=_0xcc8c('0x34');}}}catch(_0x438c22){utils['error'](_0x438c22[_0xcc8c('0x19')]);}};exports[_0xcc8c('0x35')]=function(_0x584599){try{if(!_[_0xcc8c('0x1b')](channels[_0x584599[_0xcc8c('0x9')]])){channels[_0x584599[_0xcc8c('0x9')]]['musiconholdstartAt']=utils[_0xcc8c('0x17')]();}}catch(_0x4525b0){utils[_0xcc8c('0x23')](_0x4525b0[_0xcc8c('0x19')]);}};exports['musiconholdstop']=function(_0x3bd90d){try{if(!_['isNil'](channels[_0x3bd90d[_0xcc8c('0x9')]])){if(!_[_0xcc8c('0x1b')](channels[_0x3bd90d['uniqueid']]['musiconholdstartAt'])){channels[_0x3bd90d[_0xcc8c('0x9')]][_0xcc8c('0x36')]+=utils[_0xcc8c('0x2a')](utils[_0xcc8c('0x17')](),channels[_0x3bd90d['uniqueid']]['musiconholdstartAt']);delete channels[_0x3bd90d['uniqueid']]['musiconholdstartAt'];}}}catch(_0x3cadb3){utils[_0xcc8c('0x23')](_0x3cadb3['stack']);}};exports[_0xcc8c('0x37')]=function(_0x22d2b8){try{if(!_['isNil'](channels[_0x22d2b8['uniqueid']])){if(!_[_0xcc8c('0x1b')](_0x22d2b8[_0xcc8c('0x38')][_0xcc8c('0x39')])){channels[_0x22d2b8[_0xcc8c('0x9')]][_0xcc8c('0xb')]=_0x22d2b8[_0xcc8c('0x3a')];}if(!_['isNil'](_0x22d2b8[_0xcc8c('0x38')][_0xcc8c('0x3b')])){channels[_0x22d2b8['uniqueid']][_0xcc8c('0x3c')]=_0x22d2b8[_0xcc8c('0x3a')];channels[_0x22d2b8[_0xcc8c('0x9')]][_0xcc8c('0x25')]='\x22'+_0x22d2b8[_0xcc8c('0x3a')]+_0xcc8c('0x3d')+_0x22d2b8[_0xcc8c('0x3a')]+'>';}if(!_[_0xcc8c('0x1b')](_0x22d2b8['variable'][_0xcc8c('0x3e')])||!_['isNil'](_0x22d2b8[_0xcc8c('0x38')][_0xcc8c('0x3f')])){channels[_0x22d2b8['uniqueid']]['callerid']=_0x22d2b8[_0xcc8c('0x3a')];}if(!_['isNil'](_0x22d2b8['variable'][_0xcc8c('0x40')])||!_[_0xcc8c('0x1b')](_0x22d2b8['variable'][_0xcc8c('0x41')])){channels[_0x22d2b8[_0xcc8c('0x9')]]['lastapplication']='Queue';channels[_0x22d2b8[_0xcc8c('0x9')]]['lastdata']=_0x22d2b8[_0xcc8c('0x3a')];channels[_0x22d2b8['uniqueid']]['queue']=!![];}if(!_[_0xcc8c('0x1b')](_0x22d2b8[_0xcc8c('0x38')]['xmd-contactid'])){channels[_0x22d2b8[_0xcc8c('0x9')]][_0xcc8c('0x42')]=_0x22d2b8[_0xcc8c('0x3a')];}if(!_[_0xcc8c('0x1b')](_0x22d2b8['variable'][_0xcc8c('0x43')])){channels[_0x22d2b8[_0xcc8c('0x9')]]['type']=_0x22d2b8[_0xcc8c('0x3a')];}if(!_[_0xcc8c('0x1b')](_0x22d2b8[_0xcc8c('0x38')][_0xcc8c('0x44')])){channels[_0x22d2b8[_0xcc8c('0x9')]][_0xcc8c('0x45')]=_0x22d2b8['value'];}if(!_[_0xcc8c('0x1b')](_0x22d2b8[_0xcc8c('0x38')]['sipcallid'])){channels[_0x22d2b8['uniqueid']]['sipcallid']=_0x22d2b8[_0xcc8c('0x3a')];}}}catch(_0x10f72c){utils[_0xcc8c('0x23')](_0x10f72c[_0xcc8c('0x19')]);}};exports['newexten']=function(_0x20c558){try{if(!_[_0xcc8c('0x1b')](channels[_0x20c558[_0xcc8c('0x9')]])){if(_0x20c558[_0xcc8c('0x46')][_0xcc8c('0x47')]()==_0xcc8c('0x48')&&_[_0xcc8c('0x49')](_0x20c558[_0xcc8c('0x4a')][_0xcc8c('0x47')](),'cdr')){var _0x593b4a=_0x20c558['appdata'][_0xcc8c('0x4b')]('=');var _0x4669ea=_0x593b4a[0x0][_0xcc8c('0x4c')](_0x593b4a[0x0]['lastIndexOf']('(')+0x1,_0x593b4a[0x0][_0xcc8c('0x4d')](')'));var _0x1abc3c=_0x593b4a[0x1];channels[_0x20c558[_0xcc8c('0x9')]][_0x4669ea]=_0x1abc3c;}if(!_[_0xcc8c('0x4e')]([_0xcc8c('0x24'),_0xcc8c('0x4f'),'execif','set',_0xcc8c('0x50')],_0x20c558['application'][_0xcc8c('0x47')]())){channels[_0x20c558['uniqueid']][_0xcc8c('0x51')]=_0x20c558[_0xcc8c('0x46')];channels[_0x20c558[_0xcc8c('0x9')]]['lastdata']=_0x20c558['appdata'];}}}catch(_0x3def77){utils[_0xcc8c('0x23')](_0x3def77[_0xcc8c('0x19')]);}};