ac9f3796bbb57a910fe87a15f382574219784adb
[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 _0x0446=['NO\x20ANSWER','FAILED','ANSWERED','BUSY','info','CALL|%s|%s|%s|%s|%s|%s|%s|%s','uniqueid','channel','type','source','accountcode','getUserByInternal','then','UserId','request','CreateVoiceCallReport','newchannel','linkedid','OutgoingSpoolFailed','calleridnum','exten','DOCUMENTATION','error','stack','newstate','isNil','channelstate','systemanswertime','context','transfer','destinationchannel','answertime','disposition','toNumber','hangup','callerid','endtime','now','diffTime','starttime','billableseconds','attendedtransfer','transfereechannel','secondtransfererchannel','localtwolinkedid','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','musiconholdstartAt','musiconholdstop','varset','value','xmd-phone','destination','\x22\x20<','variable','xmd-callerid-preview','xmcs-queue','lastapplication','Queue','queue','xmd-contactid','ContactId','xmd-cdrtype','sipcallid','newexten','toLowerCase','startsWith','appdata','split','lastIndexOf','includes','execif','set','gotoif','application','lastdata','lodash','util','./utils'];(function(_0x15be24,_0x17cd29){var _0xa4e5d6=function(_0x5f5bf8){while(--_0x5f5bf8){_0x15be24['push'](_0x15be24['shift']());}};_0xa4e5d6(++_0x17cd29);}(_0x0446,0xf3));var _0x6044=function(_0x3f933c,_0x3c35ea){_0x3f933c=_0x3f933c-0x0;var _0x55cfd0=_0x0446[_0x3f933c];return _0x55cfd0;};'use strict';var _=require(_0x6044('0x0'));var util=require(_0x6044('0x1'));var utils=require(_0x6044('0x2'));var dispositions=[_0x6044('0x3'),_0x6044('0x4'),'FAILED','NO\x20ANSWER',_0x6044('0x3'),_0x6044('0x3'),_0x6044('0x5'),_0x6044('0x6'),_0x6044('0x4'),'FAILED',_0x6044('0x4')];var channels={};function writeDB(_0x20b77f){utils[_0x6044('0x7')](util['format'](_0x6044('0x8'),_0x20b77f[_0x6044('0x9')],_0x20b77f[_0x6044('0xa')],_0x20b77f[_0x6044('0xb')],_0x20b77f['accountcode'],_0x20b77f[_0x6044('0xc')],_0x20b77f['destination'],_0x20b77f['callerid'],_0x20b77f['disposition']));if(_0x20b77f[_0x6044('0xd')]){utils[_0x6044('0xe')](_0x20b77f[_0x6044('0xd')])[_0x6044('0xf')](function(_0x159122){if(_0x159122){_0x20b77f[_0x6044('0x10')]=_0x159122['id'];}utils[_0x6044('0x11')](_0x6044('0x12'),_0x20b77f);});}else{utils[_0x6044('0x11')]('CreateVoiceCallReport',_0x20b77f);}if(channels[_0x20b77f[_0x6044('0x9')]]){delete channels[_0x20b77f[_0x6044('0x9')]];}}exports[_0x6044('0x13')]=function(_0x2da257){try{if(_0x2da257[_0x6044('0x9')]==_0x2da257[_0x6044('0x14')]&&_0x2da257[_0x6044('0xa')]!=_0x6044('0x15')){channels[_0x2da257[_0x6044('0x9')]]={'uniqueid':_0x2da257[_0x6044('0x9')],'accountcode':_0x2da257[_0x6044('0xd')],'source':_0x2da257[_0x6044('0x16')],'destination':_0x2da257[_0x6044('0x17')],'destinationcontext':_0x2da257['context'],'channel':_0x2da257['channel'],'starttime':utils['now'](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x6044('0x3'),'amaflags':_0x6044('0x18')};}}catch(_0xed13e5){utils[_0x6044('0x19')](_0xed13e5[_0x6044('0x1a')]);}};exports[_0x6044('0x1b')]=function(_0x1e3d7a){try{if(!_[_0x6044('0x1c')](channels[_0x1e3d7a['uniqueid']])&&_0x1e3d7a[_0x6044('0x1d')]==0x6){if(_[_0x6044('0x1c')](channels[_0x1e3d7a['uniqueid']][_0x6044('0x1e')])){channels[_0x1e3d7a['uniqueid']][_0x6044('0x1e')]=utils['now']();}}else if(!_['isNil'](channels[_0x1e3d7a[_0x6044('0x14')]])&&_0x1e3d7a[_0x6044('0x1d')]==0x6&&_0x1e3d7a[_0x6044('0x1f')]!=_0x6044('0x20')){channels[_0x1e3d7a[_0x6044('0x14')]][_0x6044('0xd')]=_0x1e3d7a[_0x6044('0xd')];channels[_0x1e3d7a[_0x6044('0x14')]][_0x6044('0x21')]=_0x1e3d7a['channel'];if(_[_0x6044('0x1c')](channels[_0x1e3d7a[_0x6044('0x14')]][_0x6044('0x22')])){channels[_0x1e3d7a[_0x6044('0x14')]]['answertime']=utils['now']();}channels[_0x1e3d7a[_0x6044('0x14')]][_0x6044('0x23')]=dispositions[_[_0x6044('0x24')](_0x1e3d7a['channelstate'])]||_0x6044('0x5');}}catch(_0x288e29){utils['error'](_0x288e29[_0x6044('0x1a')]);}};exports[_0x6044('0x25')]=function(_0x2344fc){try{if(!_['isNil'](channels[_0x2344fc['uniqueid']])){if(_[_0x6044('0x1c')](channels[_0x2344fc[_0x6044('0x9')]][_0x6044('0x26')])){channels[_0x2344fc['uniqueid']]['callerid']=_0x2344fc['calleridname']+'\x20<'+_0x2344fc[_0x6044('0x16')]+'>';}channels[_0x2344fc['uniqueid']][_0x6044('0x27')]=utils[_0x6044('0x28')]();channels[_0x2344fc[_0x6044('0x9')]]['duration']=utils[_0x6044('0x29')](channels[_0x2344fc[_0x6044('0x9')]][_0x6044('0x27')],channels[_0x2344fc[_0x6044('0x9')]][_0x6044('0x2a')]);channels[_0x2344fc[_0x6044('0x9')]][_0x6044('0x2b')]=channels[_0x2344fc[_0x6044('0x9')]]['answertime']?utils[_0x6044('0x29')](channels[_0x2344fc[_0x6044('0x9')]]['endtime'],channels[_0x2344fc[_0x6044('0x9')]][_0x6044('0x22')]):0x0;writeDB(channels[_0x2344fc[_0x6044('0x9')]]);}}catch(_0x599cd5){utils['error'](_0x599cd5[_0x6044('0x1a')]);}};exports[_0x6044('0x2c')]=function(_0x2f6d16){try{if(!_[_0x6044('0x1c')](channels[_0x2f6d16['localtwolinkedid']])){if(channels[_0x2f6d16['localtwolinkedid']][_0x6044('0xa')]==_0x2f6d16[_0x6044('0x2d')]){channels[_0x2f6d16['localtwolinkedid']][_0x6044('0x21')]=_0x2f6d16[_0x6044('0x2e')];channels[_0x2f6d16[_0x6044('0x2f')]][_0x6044('0x30')]=_0x6044('0x31');}else if(channels[_0x2f6d16[_0x6044('0x2f')]]['channel']=_0x2f6d16[_0x6044('0x32')]){channels[_0x2f6d16['localtwolinkedid']][_0x6044('0x21')]=_0x2f6d16[_0x6044('0x33')];channels[_0x2f6d16['localtwolinkedid']][_0x6044('0x30')]=_0x6044('0x31');}}}catch(_0x15957d){utils['error'](_0x15957d[_0x6044('0x1a')]);}};exports[_0x6044('0x34')]=function(_0x1fa871){try{if(!_[_0x6044('0x1c')](channels[_0x1fa871[_0x6044('0x9')]])){channels[_0x1fa871[_0x6044('0x9')]][_0x6044('0x35')]=utils['now']();}}catch(_0x467e3a){utils[_0x6044('0x19')](_0x467e3a[_0x6044('0x1a')]);}};exports[_0x6044('0x36')]=function(_0x5080ba){try{if(!_[_0x6044('0x1c')](channels[_0x5080ba[_0x6044('0x9')]])){if(!_[_0x6044('0x1c')](channels[_0x5080ba['uniqueid']]['musiconholdstartAt'])){channels[_0x5080ba[_0x6044('0x9')]]['mohtime']+=utils[_0x6044('0x29')](utils[_0x6044('0x28')](),channels[_0x5080ba[_0x6044('0x9')]]['musiconholdstartAt']);delete channels[_0x5080ba['uniqueid']][_0x6044('0x35')];}}}catch(_0x4bdb65){utils[_0x6044('0x19')](_0x4bdb65[_0x6044('0x1a')]);}};exports[_0x6044('0x37')]=function(_0xe021d1){try{if(!_[_0x6044('0x1c')](channels[_0xe021d1[_0x6044('0x9')]])){if(!_[_0x6044('0x1c')](_0xe021d1['variable']['xmd-originatecalleridnum'])){channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0xc')]=_0xe021d1[_0x6044('0x38')];}if(!_['isNil'](_0xe021d1['variable'][_0x6044('0x39')])){channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0x3a')]=_0xe021d1[_0x6044('0x38')];channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0x26')]='\x22'+_0xe021d1['value']+_0x6044('0x3b')+_0xe021d1['value']+'>';}if(!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')][_0x6044('0x3d')])||!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')]['xmd-callerid'])){channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0x26')]=_0xe021d1[_0x6044('0x38')];}if(!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')]['xmd-queue'])||!_['isNil'](_0xe021d1['variable'][_0x6044('0x3e')])){channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0x3f')]=_0x6044('0x40');channels[_0xe021d1[_0x6044('0x9')]]['lastdata']=_0xe021d1['value'];channels[_0xe021d1[_0x6044('0x9')]][_0x6044('0x41')]=!![];}if(!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')][_0x6044('0x42')])){channels[_0xe021d1['uniqueid']][_0x6044('0x43')]=_0xe021d1[_0x6044('0x38')];}if(!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')][_0x6044('0x44')])){channels[_0xe021d1['uniqueid']][_0x6044('0xb')]=_0xe021d1['value'];}if(!_[_0x6044('0x1c')](_0xe021d1[_0x6044('0x3c')]['outboundrouteid'])){channels[_0xe021d1[_0x6044('0x9')]]['routeid']=_0xe021d1[_0x6044('0x38')];}if(!_['isNil'](_0xe021d1[_0x6044('0x3c')][_0x6044('0x45')])){channels[_0xe021d1['uniqueid']][_0x6044('0x45')]=_0xe021d1['value'];}}}catch(_0x3ce992){utils[_0x6044('0x19')](_0x3ce992['stack']);}};exports[_0x6044('0x46')]=function(_0x15c1cf){try{if(!_[_0x6044('0x1c')](channels[_0x15c1cf[_0x6044('0x9')]])){if(_0x15c1cf['application'][_0x6044('0x47')]()=='set'&&_[_0x6044('0x48')](_0x15c1cf[_0x6044('0x49')]['toLowerCase'](),'cdr')){var _0x306e99=_0x15c1cf['appdata'][_0x6044('0x4a')]('=');var _0x3ee757=_0x306e99[0x0]['substring'](_0x306e99[0x0][_0x6044('0x4b')]('(')+0x1,_0x306e99[0x0][_0x6044('0x4b')](')'));var _0x4d7c8f=_0x306e99[0x1];channels[_0x15c1cf['uniqueid']][_0x3ee757]=_0x4d7c8f;}if(!_[_0x6044('0x4c')]([_0x6044('0x25'),'noop',_0x6044('0x4d'),_0x6044('0x4e'),_0x6044('0x4f')],_0x15c1cf[_0x6044('0x50')]['toLowerCase']())){channels[_0x15c1cf[_0x6044('0x9')]][_0x6044('0x3f')]=_0x15c1cf['application'];channels[_0x15c1cf[_0x6044('0x9')]][_0x6044('0x51')]=_0x15c1cf[_0x6044('0x49')];}}}catch(_0x1f00d3){utils[_0x6044('0x19')](_0x1f00d3[_0x6044('0x1a')]);}};