Built motion from commit fa4c4286.|2.6.29
[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 _0xc4b6=['[%s][calls][varset]\x20variable:sipcallid\x20value:%s','sipcallid','[%s][calls][varset]','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','startsWith','cdr','split','substring','lastIndexOf','noop','execif','set','lastdata','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','BUSY','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','queue','interface','calleridnum','accountcode','getUserByInternal','then','UserId','request','CreateVoiceCallReport','newchannel','debug','[%s][calls][newchannel]','linkedid','exten','now','DOCUMENTATION','error','newstate','[%s][calls][newstate]','isNil','[%s][calls][newstate]\x20context:%s\x20channel:%s','context','systemanswertime','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','destinationchannel','answertime','disposition','toNumber','hangup','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','starttime','billableseconds','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstop','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','[%s][calls][musiconholdstop]','variable','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','source','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','destination','value','\x22\x20<','xmd-callerid-preview','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','xmcs-queue','lastapplication','Queue','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s'];(function(_0x2fec66,_0x23880c){var _0x362641=function(_0x5a0e63){while(--_0x5a0e63){_0x2fec66['push'](_0x2fec66['shift']());}};_0x362641(++_0x23880c);}(_0xc4b6,0x80));var _0x6c4b=function(_0xed70bd,_0x315877){_0xed70bd=_0xed70bd-0x0;var _0x250dee=_0xc4b6[_0xed70bd];return _0x250dee;};'use strict';var _=require('lodash');var util=require(_0x6c4b('0x0'));var utils=require(_0x6c4b('0x1'));var dispositions=[_0x6c4b('0x2'),_0x6c4b('0x3'),_0x6c4b('0x3'),'NO\x20ANSWER','NO\x20ANSWER',_0x6c4b('0x2'),_0x6c4b('0x4'),_0x6c4b('0x5'),'FAILED',_0x6c4b('0x3'),_0x6c4b('0x3')];var channels={};function writeDB(_0x4f4693){utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x8'),_0x4f4693[_0x6c4b('0x9')],_0x4f4693[_0x6c4b('0xa')],_0x4f4693[_0x6c4b('0xb')],_0x4f4693['membername'],_0x4f4693[_0x6c4b('0xc')],_0x4f4693[_0x6c4b('0xd')],_0x4f4693['connectedlinenum'],_0x4f4693['lastevent']));if(_0x4f4693[_0x6c4b('0xe')]){utils[_0x6c4b('0xf')](_0x4f4693[_0x6c4b('0xe')])[_0x6c4b('0x10')](function(_0x3cbfc7){if(_0x3cbfc7){_0x4f4693[_0x6c4b('0x11')]=_0x3cbfc7['id'];}utils[_0x6c4b('0x12')](_0x6c4b('0x13'),_0x4f4693);});}else{utils[_0x6c4b('0x12')](_0x6c4b('0x13'),_0x4f4693);}if(channels[_0x4f4693[_0x6c4b('0x9')]]){delete channels[_0x4f4693[_0x6c4b('0x9')]];}}exports[_0x6c4b('0x14')]=function(_0x1ccd47){try{utils[_0x6c4b('0x15')](util[_0x6c4b('0x7')](_0x6c4b('0x16'),_0x1ccd47[_0x6c4b('0x9')]),_0x1ccd47);if(_0x1ccd47[_0x6c4b('0x9')]==_0x1ccd47[_0x6c4b('0x17')]&&_0x1ccd47['channel']!='OutgoingSpoolFailed'){utils[_0x6c4b('0x6')](util['format']('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x1ccd47['uniqueid'],_0x1ccd47['context'],_0x1ccd47['exten']));channels[_0x1ccd47[_0x6c4b('0x9')]]={'uniqueid':_0x1ccd47[_0x6c4b('0x9')],'accountcode':_0x1ccd47[_0x6c4b('0xe')],'source':_0x1ccd47[_0x6c4b('0xd')],'destination':_0x1ccd47[_0x6c4b('0x18')],'destinationcontext':_0x1ccd47['context'],'channel':_0x1ccd47[_0x6c4b('0xa')],'starttime':utils[_0x6c4b('0x19')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x6c4b('0x2'),'amaflags':_0x6c4b('0x1a')};}}catch(_0x25796e){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x16'),_0x1ccd47[_0x6c4b('0x9')]),_0x25796e);}};exports[_0x6c4b('0x1c')]=function(_0x1609bf){try{utils['debug'](util[_0x6c4b('0x7')](_0x6c4b('0x1d'),_0x1609bf[_0x6c4b('0x9')]),_0x1609bf);if(!_[_0x6c4b('0x1e')](channels[_0x1609bf[_0x6c4b('0x9')]])&&_0x1609bf['channelstate']==0x6){utils['info'](util['format'](_0x6c4b('0x1f'),_0x1609bf[_0x6c4b('0x9')],_0x1609bf[_0x6c4b('0x20')],_0x1609bf[_0x6c4b('0xa')]));if(_[_0x6c4b('0x1e')](channels[_0x1609bf[_0x6c4b('0x9')]]['systemanswertime'])){channels[_0x1609bf[_0x6c4b('0x9')]][_0x6c4b('0x21')]=utils[_0x6c4b('0x19')]();}}else if(!_[_0x6c4b('0x1e')](channels[_0x1609bf[_0x6c4b('0x17')]])&&_0x1609bf['channelstate']==0x6&&_0x1609bf[_0x6c4b('0x20')]!='transfer'){utils['info'](util[_0x6c4b('0x7')](_0x6c4b('0x22'),_0x1609bf[_0x6c4b('0x9')],_0x1609bf[_0x6c4b('0x17')],_0x1609bf[_0x6c4b('0x20')],_0x1609bf[_0x6c4b('0xa')]));channels[_0x1609bf[_0x6c4b('0x17')]]['accountcode']=_0x1609bf['accountcode'];channels[_0x1609bf[_0x6c4b('0x17')]][_0x6c4b('0x23')]=_0x1609bf[_0x6c4b('0xa')];if(_[_0x6c4b('0x1e')](channels[_0x1609bf[_0x6c4b('0x17')]][_0x6c4b('0x24')])){channels[_0x1609bf[_0x6c4b('0x17')]][_0x6c4b('0x24')]=utils[_0x6c4b('0x19')]();}channels[_0x1609bf[_0x6c4b('0x17')]][_0x6c4b('0x25')]=dispositions[_[_0x6c4b('0x26')](_0x1609bf['channelstate'])]||_0x6c4b('0x4');}}catch(_0xf5321d){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x1d'),_0x1609bf[_0x6c4b('0x9')]),_0xf5321d);}};exports[_0x6c4b('0x27')]=function(_0x50c7c3){try{if(!_[_0x6c4b('0x1e')](channels[_0x50c7c3[_0x6c4b('0x9')]])){utils[_0x6c4b('0x15')](util[_0x6c4b('0x7')](_0x6c4b('0x28'),_0x50c7c3[_0x6c4b('0x9')]),_0x50c7c3);if(_[_0x6c4b('0x1e')](channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x29')])){channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x29')]=_0x50c7c3[_0x6c4b('0x2a')]+'\x20<'+_0x50c7c3[_0x6c4b('0xd')]+'>';}utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x2b'),_0x50c7c3[_0x6c4b('0x9')],channels[_0x50c7c3['uniqueid']][_0x6c4b('0x29')],_0x50c7c3[_0x6c4b('0x2c')]));channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x2d')]=utils[_0x6c4b('0x19')]();channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x2e')]=utils[_0x6c4b('0x2f')](channels[_0x50c7c3['uniqueid']][_0x6c4b('0x2d')],channels[_0x50c7c3['uniqueid']][_0x6c4b('0x30')]);channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x31')]=channels[_0x50c7c3[_0x6c4b('0x9')]][_0x6c4b('0x24')]?utils[_0x6c4b('0x2f')](channels[_0x50c7c3['uniqueid']][_0x6c4b('0x2d')],channels[_0x50c7c3[_0x6c4b('0x9')]]['answertime']):0x0;writeDB(channels[_0x50c7c3[_0x6c4b('0x9')]]);}}catch(_0x34865c){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x28'),_0x50c7c3[_0x6c4b('0x9')]),_0x34865c);}};exports[_0x6c4b('0x32')]=function(_0x2a96e3){try{if(!_['isNil'](channels[_0x2a96e3[_0x6c4b('0x33')]])){utils['debug'](util[_0x6c4b('0x7')](_0x6c4b('0x34'),_0x2a96e3[_0x6c4b('0x35')]),_0x2a96e3);if(channels[_0x2a96e3[_0x6c4b('0x33')]][_0x6c4b('0xa')]==_0x2a96e3['transfereechannel']){utils['info'](util[_0x6c4b('0x7')](_0x6c4b('0x36'),_0x2a96e3[_0x6c4b('0x35')],_0x2a96e3['localtwolinkedid'],_0x2a96e3[_0x6c4b('0x37')]));channels[_0x2a96e3[_0x6c4b('0x33')]][_0x6c4b('0x23')]=_0x2a96e3[_0x6c4b('0x37')];channels[_0x2a96e3[_0x6c4b('0x33')]][_0x6c4b('0x38')]=_0x6c4b('0x39');}else if(channels[_0x2a96e3[_0x6c4b('0x33')]][_0x6c4b('0xa')]=_0x2a96e3[_0x6c4b('0x3a')]){utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x36'),_0x2a96e3[_0x6c4b('0x35')],_0x2a96e3[_0x6c4b('0x33')],_0x2a96e3[_0x6c4b('0x3b')]));channels[_0x2a96e3['localtwolinkedid']][_0x6c4b('0x23')]=_0x2a96e3['origtransfererchannel'];channels[_0x2a96e3[_0x6c4b('0x33')]][_0x6c4b('0x38')]='_attended';}}}catch(_0x17fcf3){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x34'),_0x2a96e3[_0x6c4b('0x35')]),_0x17fcf3);}};exports[_0x6c4b('0x3c')]=function(_0x3920d1){try{if(!_[_0x6c4b('0x1e')](channels[_0x3920d1['uniqueid']])){utils[_0x6c4b('0x15')](util[_0x6c4b('0x7')](_0x6c4b('0x3d'),_0x3920d1[_0x6c4b('0x9')]),_0x3920d1);channels[_0x3920d1[_0x6c4b('0x9')]][_0x6c4b('0x3e')]=utils[_0x6c4b('0x19')]();utils['info'](util['format'](_0x6c4b('0x3f'),_0x3920d1[_0x6c4b('0x9')],channels[_0x3920d1[_0x6c4b('0x9')]]['musiconholdstartAt']));}}catch(_0x2bf5a2){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x3d'),_0x3920d1[_0x6c4b('0x9')]),_0x2bf5a2);}};exports[_0x6c4b('0x40')]=function(_0x46c604){try{if(!_[_0x6c4b('0x1e')](channels[_0x46c604[_0x6c4b('0x9')]])){utils[_0x6c4b('0x15')](util[_0x6c4b('0x7')]('[%s][calls][musiconholdstop]',_0x46c604[_0x6c4b('0x9')]),_0x46c604);if(!_[_0x6c4b('0x1e')](channels[_0x46c604['uniqueid']][_0x6c4b('0x3e')])){channels[_0x46c604[_0x6c4b('0x9')]][_0x6c4b('0x41')]+=utils[_0x6c4b('0x2f')](utils['now'](),channels[_0x46c604[_0x6c4b('0x9')]]['musiconholdstartAt']);utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x42'),_0x46c604[_0x6c4b('0x9')],channels[_0x46c604[_0x6c4b('0x9')]][_0x6c4b('0x41')]));delete channels[_0x46c604[_0x6c4b('0x9')]][_0x6c4b('0x3e')];}}}catch(_0x4521be){utils['error'](util[_0x6c4b('0x7')](_0x6c4b('0x43'),_0x46c604['uniqueid']),_0x4521be);}};exports['varset']=function(_0x1094c8){try{if(!_[_0x6c4b('0x1e')](channels[_0x1094c8[_0x6c4b('0x9')]])){utils[_0x6c4b('0x15')](util['format']('[%s][calls][varset]',_0x1094c8[_0x6c4b('0x9')]),_0x1094c8);if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x45')])){utils['info'](util['format'](_0x6c4b('0x46'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8['value']));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x47')]=_0x1094c8['value'];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x48')])){utils[_0x6c4b('0x6')](util['format'](_0x6c4b('0x49'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8['value']));channels[_0x1094c8['uniqueid']][_0x6c4b('0x4a')]=_0x1094c8[_0x6c4b('0x4b')];channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x29')]='\x22'+_0x1094c8[_0x6c4b('0x4b')]+_0x6c4b('0x4c')+_0x1094c8['value']+'>';}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x4d')])||!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x4e')])){utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x4f'),_0x1094c8[_0x6c4b('0x9')],!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x4d')])?_0x6c4b('0x4d'):_0x6c4b('0x4e'),_0x1094c8['value']));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x29')]=_0x1094c8[_0x6c4b('0x4b')];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x50')])||!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x51')])){utils[_0x6c4b('0x6')](util['format'](_0x6c4b('0x4f'),_0x1094c8[_0x6c4b('0x9')],!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x50')])?'xmd-queue':_0x6c4b('0x51'),_0x1094c8['value']));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x52')]=_0x6c4b('0x53');channels[_0x1094c8[_0x6c4b('0x9')]]['lastdata']=_0x1094c8[_0x6c4b('0x4b')];channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0xb')]=!![];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x54')])){utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x55'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8[_0x6c4b('0x4b')]));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x56')]=_0x1094c8['value'];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x57')])){utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x58'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8[_0x6c4b('0x4b')]));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x59')]=_0x1094c8[_0x6c4b('0x4b')];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')][_0x6c4b('0x5a')])){utils['info'](util[_0x6c4b('0x7')](_0x6c4b('0x5b'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8[_0x6c4b('0x4b')]));channels[_0x1094c8[_0x6c4b('0x9')]]['routeid']=_0x1094c8[_0x6c4b('0x4b')];}if(!_[_0x6c4b('0x1e')](_0x1094c8[_0x6c4b('0x44')]['sipcallid'])){utils['info'](util[_0x6c4b('0x7')](_0x6c4b('0x5c'),_0x1094c8[_0x6c4b('0x9')],_0x1094c8[_0x6c4b('0x4b')]));channels[_0x1094c8[_0x6c4b('0x9')]][_0x6c4b('0x5d')]=_0x1094c8['value'];}}}catch(_0x28efd4){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')](_0x6c4b('0x5e'),_0x1094c8[_0x6c4b('0x9')]),_0x28efd4);}};exports[_0x6c4b('0x5f')]=function(_0x4ea3fa){try{if(!_[_0x6c4b('0x1e')](channels[_0x4ea3fa[_0x6c4b('0x9')]])){utils[_0x6c4b('0x15')](util[_0x6c4b('0x7')](_0x6c4b('0x60'),_0x4ea3fa[_0x6c4b('0x9')]),_0x4ea3fa);utils[_0x6c4b('0x6')](util[_0x6c4b('0x7')](_0x6c4b('0x61'),_0x4ea3fa[_0x6c4b('0x9')],_0x4ea3fa[_0x6c4b('0x62')],_0x4ea3fa[_0x6c4b('0x63')]));if(_0x4ea3fa[_0x6c4b('0x62')][_0x6c4b('0x64')]()=='set'&&_[_0x6c4b('0x65')](_0x4ea3fa[_0x6c4b('0x63')][_0x6c4b('0x64')](),_0x6c4b('0x66'))){var _0xcc7dcd=_0x4ea3fa[_0x6c4b('0x63')][_0x6c4b('0x67')]('=');var _0x47bf1e=_0xcc7dcd[0x0][_0x6c4b('0x68')](_0xcc7dcd[0x0]['lastIndexOf']('(')+0x1,_0xcc7dcd[0x0][_0x6c4b('0x69')](')'));var _0x12faa4=_0xcc7dcd[0x1];channels[_0x4ea3fa[_0x6c4b('0x9')]][_0x47bf1e]=_0x12faa4;}if(!_['includes']([_0x6c4b('0x27'),_0x6c4b('0x6a'),_0x6c4b('0x6b'),_0x6c4b('0x6c'),'gotoif'],_0x4ea3fa[_0x6c4b('0x62')][_0x6c4b('0x64')]())){channels[_0x4ea3fa[_0x6c4b('0x9')]][_0x6c4b('0x52')]=_0x4ea3fa[_0x6c4b('0x62')];channels[_0x4ea3fa[_0x6c4b('0x9')]][_0x6c4b('0x6d')]=_0x4ea3fa[_0x6c4b('0x63')];}}}catch(_0x315ddc){utils[_0x6c4b('0x1b')](util[_0x6c4b('0x7')]('[%s][calls][newexten]',_0x4ea3fa[_0x6c4b('0x9')]),_0x315ddc);}};