Built motion from commit (unavailable).|2.5.6
[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 _0xec25=['gotoif','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','info','CALL|%s|%s|%s|%s|%s|%s|%s|%s','uniqueid','channel','type','accountcode','callerid','disposition','then','UserId','request','CreateVoiceCallReport','newchannel','OutgoingSpoolFailed','calleridnum','context','now','DOCUMENTATION','stack','newstate','isNil','channelstate','systemanswertime','linkedid','transfer','destinationchannel','answertime','toNumber','hangup','calleridname','duration','diffTime','starttime','billableseconds','endtime','error','attendedtransfer','localtwolinkedid','transfereechannel','secondtransfererchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','musiconholdstartAt','musiconholdstop','mohtime','varset','variable','xmd-originatecalleridnum','source','value','xmd-phone','destination','xmd-callerid-preview','xmd-callerid','xmcs-queue','lastapplication','Queue','queue','xmd-contactid','xmd-cdrtype','outboundrouteid','routeid','sipcallid','application','toLowerCase','set','startsWith','appdata','cdr','split','includes','noop'];(function(_0x5cf52b,_0x2e5d72){var _0x4af206=function(_0xa1ab1e){while(--_0xa1ab1e){_0x5cf52b['push'](_0x5cf52b['shift']());}};_0x4af206(++_0x2e5d72);}(_0xec25,0x1ed));var _0x5ec2=function(_0x3850fd,_0x3245ed){_0x3850fd=_0x3850fd-0x0;var _0x5c5306=_0xec25[_0x3850fd];return _0x5c5306;};'use strict';var _=require(_0x5ec2('0x0'));var util=require(_0x5ec2('0x1'));var utils=require(_0x5ec2('0x2'));var dispositions=[_0x5ec2('0x3'),_0x5ec2('0x4'),_0x5ec2('0x4'),_0x5ec2('0x3'),_0x5ec2('0x3'),'NO\x20ANSWER',_0x5ec2('0x5'),'BUSY',_0x5ec2('0x4'),_0x5ec2('0x4'),_0x5ec2('0x4')];var channels={};function writeDB(_0x46ef2c){utils[_0x5ec2('0x6')](util['format'](_0x5ec2('0x7'),_0x46ef2c[_0x5ec2('0x8')],_0x46ef2c[_0x5ec2('0x9')],_0x46ef2c[_0x5ec2('0xa')],_0x46ef2c[_0x5ec2('0xb')],_0x46ef2c['source'],_0x46ef2c['destination'],_0x46ef2c[_0x5ec2('0xc')],_0x46ef2c[_0x5ec2('0xd')]));if(_0x46ef2c[_0x5ec2('0xb')]){utils['getUserByInternal'](_0x46ef2c[_0x5ec2('0xb')])[_0x5ec2('0xe')](function(_0x5854a7){if(_0x5854a7){_0x46ef2c[_0x5ec2('0xf')]=_0x5854a7['id'];}utils[_0x5ec2('0x10')](_0x5ec2('0x11'),_0x46ef2c);});}else{utils[_0x5ec2('0x10')](_0x5ec2('0x11'),_0x46ef2c);}if(channels[_0x46ef2c['uniqueid']]){delete channels[_0x46ef2c[_0x5ec2('0x8')]];}}exports[_0x5ec2('0x12')]=function(_0x121fa7){try{if(_0x121fa7[_0x5ec2('0x8')]==_0x121fa7['linkedid']&&_0x121fa7['channel']!=_0x5ec2('0x13')){channels[_0x121fa7[_0x5ec2('0x8')]]={'uniqueid':_0x121fa7[_0x5ec2('0x8')],'accountcode':_0x121fa7[_0x5ec2('0xb')],'source':_0x121fa7[_0x5ec2('0x14')],'destination':_0x121fa7['exten'],'destinationcontext':_0x121fa7[_0x5ec2('0x15')],'channel':_0x121fa7[_0x5ec2('0x9')],'starttime':utils[_0x5ec2('0x16')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x5ec2('0x3'),'amaflags':_0x5ec2('0x17')};}}catch(_0x239a02){utils['error'](_0x239a02[_0x5ec2('0x18')]);}};exports[_0x5ec2('0x19')]=function(_0x25ea84){try{if(!_[_0x5ec2('0x1a')](channels[_0x25ea84[_0x5ec2('0x8')]])&&_0x25ea84[_0x5ec2('0x1b')]==0x6){if(_[_0x5ec2('0x1a')](channels[_0x25ea84['uniqueid']][_0x5ec2('0x1c')])){channels[_0x25ea84[_0x5ec2('0x8')]][_0x5ec2('0x1c')]=utils['now']();}}else if(!_[_0x5ec2('0x1a')](channels[_0x25ea84[_0x5ec2('0x1d')]])&&_0x25ea84[_0x5ec2('0x1b')]==0x6&&_0x25ea84[_0x5ec2('0x15')]!=_0x5ec2('0x1e')){channels[_0x25ea84['linkedid']][_0x5ec2('0xb')]=_0x25ea84[_0x5ec2('0xb')];channels[_0x25ea84[_0x5ec2('0x1d')]][_0x5ec2('0x1f')]=_0x25ea84['channel'];if(_[_0x5ec2('0x1a')](channels[_0x25ea84['linkedid']]['answertime'])){channels[_0x25ea84[_0x5ec2('0x1d')]][_0x5ec2('0x20')]=utils[_0x5ec2('0x16')]();}channels[_0x25ea84[_0x5ec2('0x1d')]][_0x5ec2('0xd')]=dispositions[_[_0x5ec2('0x21')](_0x25ea84[_0x5ec2('0x1b')])]||_0x5ec2('0x5');}}catch(_0x121ca0){utils['error'](_0x121ca0[_0x5ec2('0x18')]);}};exports[_0x5ec2('0x22')]=function(_0x342336){try{if(!_[_0x5ec2('0x1a')](channels[_0x342336[_0x5ec2('0x8')]])){if(_[_0x5ec2('0x1a')](channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0xc')])){channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0xc')]=_0x342336[_0x5ec2('0x23')]+'\x20<'+_0x342336[_0x5ec2('0x14')]+'>';}channels[_0x342336[_0x5ec2('0x8')]]['endtime']=utils['now']();channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0x24')]=utils[_0x5ec2('0x25')](channels[_0x342336[_0x5ec2('0x8')]]['endtime'],channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0x26')]);channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0x27')]=channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0x20')]?utils[_0x5ec2('0x25')](channels[_0x342336[_0x5ec2('0x8')]][_0x5ec2('0x28')],channels[_0x342336['uniqueid']][_0x5ec2('0x20')]):0x0;writeDB(channels[_0x342336[_0x5ec2('0x8')]]);}}catch(_0x29bc38){utils[_0x5ec2('0x29')](_0x29bc38['stack']);}};exports[_0x5ec2('0x2a')]=function(_0x4ead5c){try{if(!_['isNil'](channels[_0x4ead5c[_0x5ec2('0x2b')]])){if(channels[_0x4ead5c[_0x5ec2('0x2b')]]['channel']==_0x4ead5c[_0x5ec2('0x2c')]){channels[_0x4ead5c[_0x5ec2('0x2b')]][_0x5ec2('0x1f')]=_0x4ead5c[_0x5ec2('0x2d')];channels[_0x4ead5c[_0x5ec2('0x2b')]][_0x5ec2('0x2e')]=_0x5ec2('0x2f');}else if(channels[_0x4ead5c[_0x5ec2('0x2b')]][_0x5ec2('0x9')]=_0x4ead5c[_0x5ec2('0x30')]){channels[_0x4ead5c['localtwolinkedid']][_0x5ec2('0x1f')]=_0x4ead5c[_0x5ec2('0x31')];channels[_0x4ead5c[_0x5ec2('0x2b')]][_0x5ec2('0x2e')]='_attended';}}}catch(_0x11222a){utils['error'](_0x11222a[_0x5ec2('0x18')]);}};exports[_0x5ec2('0x32')]=function(_0x4aee5e){try{if(!_[_0x5ec2('0x1a')](channels[_0x4aee5e[_0x5ec2('0x8')]])){channels[_0x4aee5e[_0x5ec2('0x8')]][_0x5ec2('0x33')]=utils['now']();}}catch(_0x20dc0a){utils[_0x5ec2('0x29')](_0x20dc0a['stack']);}};exports[_0x5ec2('0x34')]=function(_0x3c7112){try{if(!_[_0x5ec2('0x1a')](channels[_0x3c7112[_0x5ec2('0x8')]])){if(!_[_0x5ec2('0x1a')](channels[_0x3c7112[_0x5ec2('0x8')]][_0x5ec2('0x33')])){channels[_0x3c7112[_0x5ec2('0x8')]][_0x5ec2('0x35')]+=utils['diffTime'](utils[_0x5ec2('0x16')](),channels[_0x3c7112[_0x5ec2('0x8')]][_0x5ec2('0x33')]);delete channels[_0x3c7112['uniqueid']][_0x5ec2('0x33')];}}}catch(_0x49bc71){utils[_0x5ec2('0x29')](_0x49bc71[_0x5ec2('0x18')]);}};exports[_0x5ec2('0x36')]=function(_0x201c8f){try{if(!_[_0x5ec2('0x1a')](channels[_0x201c8f[_0x5ec2('0x8')]])){if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x38')])){channels[_0x201c8f['uniqueid']][_0x5ec2('0x39')]=_0x201c8f[_0x5ec2('0x3a')];}if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x3b')])){channels[_0x201c8f[_0x5ec2('0x8')]][_0x5ec2('0x3c')]=_0x201c8f[_0x5ec2('0x3a')];channels[_0x201c8f[_0x5ec2('0x8')]][_0x5ec2('0xc')]='\x22'+_0x201c8f[_0x5ec2('0x3a')]+'\x22\x20<'+_0x201c8f[_0x5ec2('0x3a')]+'>';}if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x3d')])||!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x3e')])){channels[_0x201c8f['uniqueid']][_0x5ec2('0xc')]=_0x201c8f[_0x5ec2('0x3a')];}if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')]['xmd-queue'])||!_[_0x5ec2('0x1a')](_0x201c8f['variable'][_0x5ec2('0x3f')])){channels[_0x201c8f[_0x5ec2('0x8')]][_0x5ec2('0x40')]=_0x5ec2('0x41');channels[_0x201c8f[_0x5ec2('0x8')]]['lastdata']=_0x201c8f['value'];channels[_0x201c8f[_0x5ec2('0x8')]][_0x5ec2('0x42')]=!![];}if(!_['isNil'](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x43')])){channels[_0x201c8f[_0x5ec2('0x8')]]['ContactId']=_0x201c8f[_0x5ec2('0x3a')];}if(!_['isNil'](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x44')])){channels[_0x201c8f['uniqueid']][_0x5ec2('0xa')]=_0x201c8f[_0x5ec2('0x3a')];}if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x45')])){channels[_0x201c8f[_0x5ec2('0x8')]][_0x5ec2('0x46')]=_0x201c8f['value'];}if(!_[_0x5ec2('0x1a')](_0x201c8f[_0x5ec2('0x37')][_0x5ec2('0x47')])){channels[_0x201c8f['uniqueid']][_0x5ec2('0x47')]=_0x201c8f['value'];}}}catch(_0xd7b475){utils['error'](_0xd7b475[_0x5ec2('0x18')]);}};exports['newexten']=function(_0x49714b){try{if(!_[_0x5ec2('0x1a')](channels[_0x49714b[_0x5ec2('0x8')]])){if(_0x49714b[_0x5ec2('0x48')][_0x5ec2('0x49')]()==_0x5ec2('0x4a')&&_[_0x5ec2('0x4b')](_0x49714b[_0x5ec2('0x4c')][_0x5ec2('0x49')](),_0x5ec2('0x4d'))){var _0x39894b=_0x49714b[_0x5ec2('0x4c')][_0x5ec2('0x4e')]('=');var _0x142b2e=_0x39894b[0x0]['substring'](_0x39894b[0x0]['lastIndexOf']('(')+0x1,_0x39894b[0x0]['lastIndexOf'](')'));var _0x5eb572=_0x39894b[0x1];channels[_0x49714b['uniqueid']][_0x142b2e]=_0x5eb572;}if(!_[_0x5ec2('0x4f')]([_0x5ec2('0x22'),_0x5ec2('0x50'),'execif',_0x5ec2('0x4a'),_0x5ec2('0x51')],_0x49714b[_0x5ec2('0x48')]['toLowerCase']())){channels[_0x49714b[_0x5ec2('0x8')]][_0x5ec2('0x40')]=_0x49714b['application'];channels[_0x49714b['uniqueid']]['lastdata']=_0x49714b[_0x5ec2('0x4c')];}}}catch(_0x13aee3){utils[_0x5ec2('0x29')](_0x13aee3[_0x5ec2('0x18')]);}};