Built motion from commit a9fb64cc6defd8fb3a5cc199221f878e91c0e969. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / sugarcrm.js
index 966a72d..ec34fb0 100644 (file)
@@ -1 +1 @@
-const a1142_0x4fc7=['merge','[QUEUE]','forEach','debug','Subjects','password','stringify','find','serverUrl','[OUTBOUND]','name_value_list','request-promise-native','unmanaged','recordingURL','version','direction','user:%s','Ticket\x20created!','%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s','Recording\x20is\x20enabled!','assigned_user_id','entry_list','Account\x20%d\x20is\x20not\x20valid','<unknown>','username','Caller\x20-\x20%s','sessionID','charAt','PLAIN','value','resolve','outbound','lodash','error','info','login','The\x20Enduser\x20ID\x20is:','set_relationship','users','../../../../rediscache','Inbound','../../../../config/logger','get_entry_list','contacts.phone_home\x20=\x20\x22%s\x22','Fields','The\x20User\x20ID\x20is:','Contacts','remoteUri','then','first_name','The\x20Ticket\x20ID\x20is:','toUpperCase','parent_id','POST','%s/#bwc/index.php?module=Calls&action=EditView&record=%s','phone_home','getString','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','format','JSON','user_id','Descriptions','Calls','monitor_format','Agent\x20not\x20available,\x20using\x20the\x20admin\x20account!','set_entry','catch','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','contacts','Enduser\x20found!','lastevent','isNil','uniqueid','calleridname','trigger:browser:url','replace','duration_minutes','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','variableName','idField','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','queue','Agent\x20found!','created_by','Searching\x20enduser\x20with\x20phone','stripTrailingSlash','parent_type','sugarcrm','name','none','uri','length','recordingFormat','toISOString','duration_hours'];(function(_0x50e6b7,_0x4fc739){const _0x40aaf9=function(_0x3b0a00){while(--_0x3b0a00){_0x50e6b7['push'](_0x50e6b7['shift']());}};_0x40aaf9(++_0x4fc739);}(a1142_0x4fc7,0x19e));const a1142_0x40aa=function(_0x50e6b7,_0x4fc739){_0x50e6b7=_0x50e6b7-0x0;let _0x40aaf9=a1142_0x4fc7[_0x50e6b7];return _0x40aaf9;};const _0x4ca224=a1142_0x40aa;'use strict';const _=require(_0x4ca224('0x5d')),rp=require(_0x4ca224('0x48')),md5=require('md5'),util=require('util'),intUtil=require('./util'),logger=require(_0x4ca224('0x7'))(_0x4ca224('0x35')),{getSocket}=require(_0x4ca224('0x5')),io=getSocket(),def={'method':_0x4ca224('0x13'),'json':!![]};function emit(_0x3b0a00,_0x94451c,_0x22060d){io['to'](_0x3b0a00)['emit'](_0x94451c,_0x22060d);}function getTicket(_0x4b098f,_0x4acbe5,_0x22cff2,_0x92cf5d,_0x26cdd,_0x4f1683,_0x57ca97,_0x2a9396){const _0x2ed96b=_0x4ca224;logger['info']('Creating\x20new\x20ticket...');const _0x40402f=new Date(),_0x386b53=[{'name':'name','value':intUtil[_0x2ed96b('0x16')](_0x92cf5d[_0x2ed96b('0x41')],_0x26cdd,'\x20')},{'name':_0x2ed96b('0x51'),'value':_0x4acbe5['id']},{'name':_0x2ed96b('0x31'),'value':_0x4acbe5['id']},{'name':'description','value':intUtil['getString'](_0x92cf5d[_0x2ed96b('0x1b')],_0x26cdd,'\x0a')},{'name':'date_start','value':_0x40402f[_0x2ed96b('0x3b')]()['slice'](0x0,0x13)[_0x2ed96b('0x29')]('T','\x20')},{'name':_0x2ed96b('0x3c'),'value':'0'},{'name':_0x2ed96b('0x2a'),'value':'15'},{'name':_0x2ed96b('0x12'),'value':_0x22cff2['id']},{'name':_0x2ed96b('0x34'),'value':_0x2ed96b('0xc')},{'name':'parent_name','value':_0x22cff2['name']},{'name':_0x2ed96b('0x4c'),'value':_0x2a9396}];return _0x4f1683[_0x2ed96b('0x39')]&&_[_0x2ed96b('0x3f')](_0x4f1683,function(_0x2a10ab){const _0xc046dd=_0x2ed96b;_0x26cdd[_0x2a10ab['variableName']]&&_0x386b53['push']({'name':_0x2a10ab[_0xc046dd('0x2d')],'value':_0x26cdd[_0x2a10ab[_0xc046dd('0x2c')]]});}),request({'form':{'method':_0x2ed96b('0x1f'),'input_type':_0x2ed96b('0x19'),'response_type':'JSON','rest_data':JSON[_0x2ed96b('0x43')]({'session':_0x57ca97['id'],'module_name':_0x2ed96b('0x1c'),'name_value_list':_0x386b53})}});}function getServerInfo(_0x5ba6a2){const _0x484f4f=_0x4ca224;return request({'form':{'method':'get_server_info','input_type':_0x484f4f('0x19'),'response_type':_0x484f4f('0x19'),'rest_data':JSON[_0x484f4f('0x43')]({'session':_0x5ba6a2['id']})}});}function getUser(_0x3de685,_0x475ba8,_0x302451){const _0x3f5066=_0x4ca224;return!_['isNil'](_0x475ba8)?(logger[_0x3f5066('0x0')]('Getting\x20agent\x20with\x20name',_0x475ba8),request({'form':{'method':_0x3f5066('0x8'),'input_type':'JSON','response_type':_0x3f5066('0x19'),'rest_data':JSON[_0x3f5066('0x43')]({'session':_0x302451['id'],'module_name':'Employees','query':util[_0x3f5066('0x18')]('INSTR\x20(\x20users.user_name,\x20\x22%s\x22)\x20>\x200',_0x475ba8),'order_by':'','offset':'0','select_fields':['id','name','user_name'],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0x3f5066('0xe')](function(_0x4073ea){const _0x19438d=_0x3f5066;if(_0x4073ea[_0x19438d('0x52')][_0x19438d('0x39')]){const _0x468678=_['find'](_0x4073ea[_0x19438d('0x52')],function(_0x2bd1ec){const _0x4b66f7=_0x19438d;return _0x2bd1ec[_0x4b66f7('0x47')]['user_name']['value']===_0x475ba8;});if(_0x468678)return logger[_0x19438d('0x0')](_0x19438d('0x30')),Promise[_0x19438d('0x5b')]({'id':_0x468678['name_value_list']['id']['value'],'name':_0x468678[_0x19438d('0x47')][_0x19438d('0x36')][_0x19438d('0x5a')]});}return logger[_0x19438d('0x0')](_0x19438d('0x2b')),Promise[_0x19438d('0x5b')]({'id':_0x302451[_0x19438d('0x47')]['user_id'][_0x19438d('0x5a')],'name':_0x302451[_0x19438d('0x47')]['user_name'][_0x19438d('0x5a')]});})):(logger[_0x3f5066('0x0')](_0x3f5066('0x1e')),Promise[_0x3f5066('0x5b')]({'id':_0x302451[_0x3f5066('0x47')][_0x3f5066('0x1a')]['value'],'name':_0x302451['name_value_list']['user_name'][_0x3f5066('0x5a')]}));}function getEndUser(_0x1f13e9,_0x117640,_0x49e6ee,_0x27f512){const _0x5380dd=_0x4ca224;return logger[_0x5380dd('0x0')](_0x5380dd('0x32'),_0x49e6ee),request({'form':{'method':_0x5380dd('0x8'),'input_type':_0x5380dd('0x19'),'response_type':_0x5380dd('0x19'),'rest_data':JSON[_0x5380dd('0x43')]({'session':_0x27f512['id'],'module_name':_0x5380dd('0xc'),'query':util[_0x5380dd('0x18')](_0x5380dd('0x9'),_0x49e6ee),'order_by':'','offset':'0','select_fields':['id','name',_0x5380dd('0x15')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0x5380dd('0xe')](function(_0x76c06b){const _0x44ec5c=_0x5380dd;if(_0x76c06b[_0x44ec5c('0x52')][_0x44ec5c('0x39')]){const _0x549b99=_[_0x44ec5c('0x44')](_0x76c06b[_0x44ec5c('0x52')],function(_0x17606c){const _0x4c9f24=_0x44ec5c;return _0x17606c['name_value_list'][_0x4c9f24('0x15')]['value']===_0x49e6ee;});if(_0x549b99)return logger[_0x44ec5c('0x0')](_0x44ec5c('0x23')),Promise[_0x44ec5c('0x5b')]({'id':_0x549b99[_0x44ec5c('0x47')]['id']['value'],'name':_0x549b99[_0x44ec5c('0x47')][_0x44ec5c('0x36')][_0x44ec5c('0x5a')],'phone':_0x549b99['name_value_list'][_0x44ec5c('0x15')][_0x44ec5c('0x5a')]});}else return logger[_0x44ec5c('0x0')](_0x44ec5c('0x21')),request({'form':{'method':_0x44ec5c('0x1f'),'input_type':'JSON','response_type':'JSON','rest_data':JSON[_0x44ec5c('0x43')]({'session':_0x27f512['id'],'module_name':_0x44ec5c('0xc'),'name_value_list':[{'name':_0x44ec5c('0xf'),'value':_0x117640!==_0x44ec5c('0x54')?_0x117640:util[_0x44ec5c('0x18')](_0x44ec5c('0x56'),_0x49e6ee)},{'name':_0x44ec5c('0x15'),'value':_0x49e6ee}]})}})[_0x44ec5c('0xe')](function(_0x2edd13){const _0x4e4cb4=_0x44ec5c;return logger[_0x4e4cb4('0x0')]('Enduser\x20created.'),Promise[_0x4e4cb4('0x5b')]({'id':_0x2edd13['id'],'name':_0x2edd13[_0x4e4cb4('0x52')][_0x4e4cb4('0xf')][_0x4e4cb4('0x5a')],'phone':_0x2edd13[_0x4e4cb4('0x52')][_0x4e4cb4('0x15')][_0x4e4cb4('0x5a')]});});});}function request(_0x334dca){const _0x58fb2e=_0x4ca224;return logger[_0x58fb2e('0x40')]('[HTTP]',JSON['stringify'](_0x334dca)),rp(_[_0x58fb2e('0x3d')](def,_0x334dca));}function getConnection(_0x2db3d1){const _0x3bf42b=_0x4ca224;return request({'method':_0x3bf42b('0x13'),'form':{'method':_0x3bf42b('0x1'),'input_type':_0x3bf42b('0x19'),'response_type':_0x3bf42b('0x19'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x2db3d1[_0x3bf42b('0x55')],'password':_0x2db3d1[_0x3bf42b('0x42')],'encryption':_0x3bf42b('0x59')},'application':'xCALLY\x20Motion\x20integration'})}})[_0x3bf42b('0xe')](function(_0x16374f){const _0x567d76=_0x3bf42b,_0x41b71d=_0x16374f;if(_0x41b71d['id'])return def[_0x567d76('0x57')]=_0x41b71d['id'],Promise[_0x567d76('0x5b')](_0x41b71d);else throw new Error(util[_0x567d76('0x18')](_0x567d76('0x53'),_0x2db3d1['id']));});}function setRelationship(_0x31f6f6,_0xc4faa5,_0x3869ad,_0x95bbc9){const _0x3c8d58=_0x4ca224;return request({'form':{'method':_0x3c8d58('0x3'),'input_type':_0x3c8d58('0x19'),'response_type':_0x3c8d58('0x19'),'rest_data':JSON[_0x3c8d58('0x43')]({'session':_0x31f6f6['id'],'module_name':_0x3c8d58('0x1c'),'module_id':_0x3869ad['id'],'link_field_name':_0x95bbc9,'related_ids':[_0xc4faa5['id']]})}});}exports[_0x4ca224('0x2f')]=function(_0x5beb9f,_0x3f5e78,_0x5e68d1,_0x33e645,_0x453463,_0x2cea26){const _0x4b5bdc=_0x4ca224;let _0x552e0a,_0x458c66,_0x4c1908,_0x59c198;return _0x2cea26[_0x4b5bdc('0xd')]=intUtil[_0x4b5bdc('0x33')](_0x2cea26['remoteUri']),_0x2cea26['serverUrl']=intUtil[_0x4b5bdc('0x33')](_0x2cea26['serverUrl']),def[_0x4b5bdc('0x38')]=util['format']('%s/service/v4_1/rest.php',_0x2cea26[_0x4b5bdc('0xd')]),_0x453463&&_0x453463['monitor_format']?(logger[_0x4b5bdc('0x0')](_0x4b5bdc('0x3e'),_0x4b5bdc('0x50')),_0x3f5e78[_0x4b5bdc('0x4a')]=util[_0x4b5bdc('0x18')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2cea26['serverUrl'],_0x3f5e78[_0x4b5bdc('0x26')],md5(_0x3f5e78[_0x4b5bdc('0x26')]))):_0x3f5e78['recordingURL']='',getConnection(_0x2cea26)['then'](function(_0x2681e5){const _0x3de04e=_0x4b5bdc;return _0x59c198=_0x2681e5,getUser(_0x2cea26,_0x33e645[_0x3de04e('0x36')],_0x59c198);})[_0x4b5bdc('0xe')](function(_0x5a868f){const _0xf4e08e=_0x4b5bdc;return _0x552e0a=_0x5a868f,logger['info'](_0xf4e08e('0xb'),_0x552e0a['id']),getEndUser(_0x2cea26,_0x3f5e78[_0xf4e08e('0x27')],_0x3f5e78['calleridnum'],_0x59c198);})[_0x4b5bdc('0xe')](function(_0x3fe285){const _0x55e7c6=_0x4b5bdc;return _0x458c66=_0x3fe285,logger[_0x55e7c6('0x0')](_0x55e7c6('0x2'),_0x458c66['id']),getTicket(_0x2cea26,_0x552e0a,_0x458c66,_0x5e68d1,_0x3f5e78,_0x5e68d1[_0x55e7c6('0xa')],_0x59c198,_0x55e7c6('0x6'));})[_0x4b5bdc('0xe')](function(_0x8dded1){const _0xb72a3f=_0x4b5bdc;return _0x4c1908=_0x8dded1,logger[_0xb72a3f('0x0')](_0xb72a3f('0x4e')),logger[_0xb72a3f('0x0')](_0xb72a3f('0x10'),_0x4c1908['id']),setRelationship(_0x59c198,_0x552e0a,_0x4c1908,_0xb72a3f('0x4'));})[_0x4b5bdc('0xe')](function(){return setRelationship(_0x59c198,_0x458c66,_0x4c1908,'contacts');})['then'](function(){return getServerInfo(_0x59c198);})[_0x4b5bdc('0xe')](function(_0x7063d5){const _0x3cf97e=_0x4b5bdc,_0x53806f=parseInt(_0x7063d5[_0x3cf97e('0x4b')][_0x3cf97e('0x58')](0x0));let _0x53b255=util[_0x3cf97e('0x18')](_0x3cf97e('0x4f'),_0x2cea26[_0x3cf97e('0xd')],_0x4c1908['id']);_0x53806f>0x6&&(_0x53b255=util[_0x3cf97e('0x18')](_0x3cf97e('0x14'),_0x2cea26[_0x3cf97e('0xd')],_0x4c1908['id'])),logger[_0x3cf97e('0x0')](_0x3cf97e('0x3e'),_0x3cf97e('0x17')),emit(util['format'](_0x3cf97e('0x4d'),_0x33e645[_0x3cf97e('0x36')]),_0x3cf97e('0x28'),{'uri':_0x53b255});})[_0x4b5bdc('0x20')](function(_0x4d1836){const _0x3cf75c=_0x4b5bdc;logger[_0x3cf75c('0x5e')](_0x3cf75c('0x3e'),JSON['stringify'](_0x4d1836));});},exports[_0x4ca224('0x5c')]=function(_0x3c5285,_0x3f907b,_0x6b700e,_0x1b9924,_0x12fc62,_0x3ecd2f,_0x509b49){const _0x132ed2=_0x4ca224;let _0xec1328,_0x14a643,_0x3be430,_0xe01639;return _0x3ecd2f[_0x132ed2('0xd')]=intUtil[_0x132ed2('0x33')](_0x3ecd2f[_0x132ed2('0xd')]),_0x3ecd2f[_0x132ed2('0x45')]=intUtil[_0x132ed2('0x33')](_0x3ecd2f[_0x132ed2('0x45')]),def[_0x132ed2('0x38')]=util[_0x132ed2('0x18')]('%s/service/v4_1/rest.php',_0x3ecd2f['remoteUri']),_0x509b49&&_0x509b49[_0x132ed2('0x3a')]&&_0x509b49[_0x132ed2('0x3a')]!==_0x132ed2('0x37')&&(logger[_0x132ed2('0x0')](_0x132ed2('0x46'),_0x132ed2('0x50')),_0x3f907b[_0x132ed2('0x4a')]=util[_0x132ed2('0x18')](_0x132ed2('0x2e'),_0x3ecd2f['serverUrl'],_0x3f907b['uniqueid'],md5(_0x3f907b[_0x132ed2('0x26')]))),getConnection(_0x3ecd2f)[_0x132ed2('0xe')](function(_0x126724){const _0x1a3b7d=_0x132ed2;return _0xe01639=_0x126724,getUser(_0x3ecd2f,_0x1b9924[_0x1a3b7d('0x36')],_0xe01639);})['then'](function(_0x266454){const _0x22224e=_0x132ed2;return _0xec1328=_0x266454,logger['info'](_0x22224e('0xb'),_0xec1328['id']),getEndUser(_0x3ecd2f,_0x3f907b['destcalleridname'],_0x3f907b['destcalleridnum'],_0xe01639);})[_0x132ed2('0xe')](function(_0x3c26b2){const _0xdaf881=_0x132ed2;return _0x14a643=_0x3c26b2,logger['info'](_0xdaf881('0x2'),_0x14a643['id']),getTicket(_0x3ecd2f,_0xec1328,_0x14a643,_0x6b700e,_0x3f907b,_0x6b700e[_0xdaf881('0xa')],_0xe01639,'Outbound');})[_0x132ed2('0xe')](function(_0x11c2e2){const _0x2e097c=_0x132ed2;return _0x3be430=_0x11c2e2,logger[_0x2e097c('0x0')](_0x2e097c('0x4e')),logger['info'](_0x2e097c('0x10'),_0x3be430['id']),setRelationship(_0xe01639,_0xec1328,_0x3be430,_0x2e097c('0x4'));})[_0x132ed2('0xe')](function(){const _0x3c5986=_0x132ed2;return setRelationship(_0xe01639,_0x14a643,_0x3be430,_0x3c5986('0x22'));})[_0x132ed2('0xe')](function(){return getServerInfo(_0xe01639);})['then'](function(_0x1f962f){const _0x4bffc9=_0x132ed2,_0x2faa64=parseInt(_0x1f962f['version'][_0x4bffc9('0x58')](0x0));let _0x541121=util['format'](_0x4bffc9('0x4f'),_0x3ecd2f['remoteUri'],_0x3be430['id']);_0x2faa64>0x6&&(_0x541121=util[_0x4bffc9('0x18')](_0x4bffc9('0x14'),_0x3ecd2f[_0x4bffc9('0xd')],_0x3be430['id'])),logger[_0x4bffc9('0x0')](_0x4bffc9('0x46'),_0x4bffc9('0x17')),emit(util['format'](_0x4bffc9('0x4d'),_0x1b9924[_0x4bffc9('0x36')]),_0x4bffc9('0x28'),{'uri':_0x541121});})['catch'](function(_0x20cf47){const _0x1eb521=_0x132ed2;logger[_0x1eb521('0x5e')](_0x1eb521('0x46'),JSON[_0x1eb521('0x43')](_0x20cf47));});},exports[_0x4ca224('0x49')]=function(_0x21ec3a,_0x544952,_0x21ceb5,_0x34b766,_0x797492,_0x5be448){const _0x54b83c=_0x4ca224;let _0x571aec,_0x2739aa,_0x3c3791,_0x1774fa;return _0x5be448[_0x54b83c('0xd')]=intUtil[_0x54b83c('0x33')](_0x5be448['remoteUri']),_0x5be448[_0x54b83c('0x45')]=intUtil[_0x54b83c('0x33')](_0x5be448[_0x54b83c('0x45')]),def['uri']=util[_0x54b83c('0x18')]('%s/service/v4_1/rest.php',_0x5be448[_0x54b83c('0xd')]),_0x797492&&_0x797492[_0x54b83c('0x1d')]?(logger[_0x54b83c('0x0')]('['+_0x544952['lastevent']['toUpperCase']()+']','Recording\x20is\x20enabled!'),_0x544952[_0x54b83c('0x4a')]=util[_0x54b83c('0x18')](_0x54b83c('0x2e'),_0x5be448[_0x54b83c('0x45')],_0x544952[_0x54b83c('0x26')],md5(_0x544952[_0x54b83c('0x26')]))):_0x544952[_0x54b83c('0x4a')]='',getConnection(_0x5be448)[_0x54b83c('0xe')](function(_0x290886){const _0x400abd=_0x54b83c;return _0x1774fa=_0x290886,!_[_0x400abd('0x25')](_0x34b766)?getUser(_0x5be448,_0x34b766['name'],_0x1774fa):getUser(_0x5be448,null,_0x1774fa);})[_0x54b83c('0xe')](function(_0x391e5e){const _0x1d6a6b=_0x54b83c;return _0x571aec=_0x391e5e,logger[_0x1d6a6b('0x0')](_0x1d6a6b('0xb'),_0x571aec['id']),getEndUser(_0x5be448,_0x544952[_0x1d6a6b('0x27')],_0x544952['calleridnum'],_0x1774fa);})['then'](function(_0x367e03){const _0x17d3d4=_0x54b83c;return _0x2739aa=_0x367e03,logger[_0x17d3d4('0x0')]('The\x20Enduser\x20ID\x20is:',_0x2739aa['id']),getTicket(_0x5be448,_0x571aec,_0x2739aa,_0x21ceb5,_0x544952,_0x21ceb5['Fields'],_0x1774fa,_0x17d3d4('0x6'));})[_0x54b83c('0xe')](function(_0x1350b6){const _0x3ac2a5=_0x54b83c;return _0x3c3791=_0x1350b6,logger[_0x3ac2a5('0x0')](_0x3ac2a5('0x4e')),logger[_0x3ac2a5('0x0')](_0x3ac2a5('0x10'),_0x3c3791['id']),setRelationship(_0x1774fa,_0x571aec,_0x3c3791,_0x3ac2a5('0x4'));})[_0x54b83c('0xe')](function(){const _0xc2eff=_0x54b83c;return setRelationship(_0x1774fa,_0x2739aa,_0x3c3791,_0xc2eff('0x22'));})[_0x54b83c('0xe')](function(){return getServerInfo(_0x1774fa);})[_0x54b83c('0x20')](function(_0x46894b){const _0x3aea0e=_0x54b83c;logger[_0x3aea0e('0x5e')]('['+_0x544952[_0x3aea0e('0x24')][_0x3aea0e('0x11')]()+']',JSON[_0x3aea0e('0x43')](_0x46894b));});};
\ No newline at end of file
+const a1142_0xbe5a=['idField','catch','lodash','Agent\x20not\x20available,\x20using\x20the\x20admin\x20account!','slice','password','Getting\x20agent\x20with\x20name','phone_home','The\x20User\x20ID\x20is:','user:%s','stripTrailingSlash','JSON','Fields','Searching\x20enduser\x20with\x20phone','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','getString','<unknown>','info','Account\x20%d\x20is\x20not\x20valid','forEach','Descriptions','debug','recordingFormat','Enduser\x20found!','none','username','resolve','Calls','replace','calleridnum','Inbound','format','date_start','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','first_name','%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s','The\x20Ticket\x20ID\x20is:','user_name','remoteUri','calleridname','push','then','users','destcalleridname','stringify','length','../../../../rediscache','Caller\x20-\x20%s','toISOString','destcalleridnum','assigned_user_id','[HTTP]','INSTR\x20(\x20users.user_name,\x20\x22%s\x22)\x20>\x200','merge','Ticket\x20created!','charAt','login','The\x20Enduser\x20ID\x20is:','%s/service/v4_1/rest.php','variableName','user_id','monitor_format','[QUEUE]','unmanaged','error','description','set_relationship','recordingURL','find','Agent\x20found!','Employees','serverUrl','uri','direction','parent_name','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Outbound','set_entry','uniqueid','request-promise-native','toUpperCase','POST','queue','lastevent','get_entry_list','isNil','value','Contacts','Recording\x20is\x20enabled!','contacts.phone_home\x20=\x20\x22%s\x22','./util','get_server_info','Enduser\x20created.','name_value_list','sugarcrm','trigger:browser:url','Creating\x20new\x20ticket...','../../../../config/logger','contacts','parent_type','Subjects','name','%s/#bwc/index.php?module=Calls&action=EditView&record=%s','PLAIN','entry_list'];(function(_0x18b44b,_0xbe5a47){const _0x4cbe12=function(_0x534b54){while(--_0x534b54){_0x18b44b['push'](_0x18b44b['shift']());}};_0x4cbe12(++_0xbe5a47);}(a1142_0xbe5a,0x165));const a1142_0x4cbe=function(_0x18b44b,_0xbe5a47){_0x18b44b=_0x18b44b-0x0;let _0x4cbe12=a1142_0xbe5a[_0x18b44b];return _0x4cbe12;};const _0x98c90c=a1142_0x4cbe;'use strict';const _=require(_0x98c90c('0x45')),rp=require(_0x98c90c('0x29')),md5=require('md5'),util=require('util'),intUtil=require(_0x98c90c('0x34')),logger=require(_0x98c90c('0x3b'))(_0x98c90c('0x38')),{getSocket}=require(_0x98c90c('0x7')),io=getSocket(),def={'method':'POST','json':!![]};function emit(_0x534b54,_0x222618,_0x207eda){io['to'](_0x534b54)['emit'](_0x222618,_0x207eda);}function getTicket(_0x254a07,_0xab660f,_0xc26bd5,_0x2456e6,_0x2af861,_0x3188dd,_0x5b9df9,_0x3e602a){const _0x221771=_0x98c90c;logger[_0x221771('0x54')](_0x221771('0x3a'));const _0x51cd0f=new Date(),_0x32971c=[{'name':_0x221771('0x3f'),'value':intUtil['getString'](_0x2456e6[_0x221771('0x3e')],_0x2af861,'\x20')},{'name':_0x221771('0xb'),'value':_0xab660f['id']},{'name':'created_by','value':_0xab660f['id']},{'name':_0x221771('0x1a'),'value':intUtil[_0x221771('0x52')](_0x2456e6[_0x221771('0x57')],_0x2af861,'\x0a')},{'name':_0x221771('0x63'),'value':_0x51cd0f[_0x221771('0x9')]()[_0x221771('0x47')](0x0,0x13)[_0x221771('0x5f')]('T','\x20')},{'name':'duration_hours','value':'0'},{'name':'duration_minutes','value':'15'},{'name':'parent_id','value':_0xc26bd5['id']},{'name':_0x221771('0x3d'),'value':_0x221771('0x31')},{'name':_0x221771('0x23'),'value':_0xc26bd5[_0x221771('0x3f')]},{'name':_0x221771('0x22'),'value':_0x3e602a}];return _0x3188dd[_0x221771('0x6')]&&_[_0x221771('0x56')](_0x3188dd,function(_0x3efa6b){const _0x2a4a08=_0x221771;_0x2af861[_0x3efa6b[_0x2a4a08('0x14')]]&&_0x32971c[_0x2a4a08('0x1')]({'name':_0x3efa6b[_0x2a4a08('0x43')],'value':_0x2af861[_0x3efa6b[_0x2a4a08('0x14')]]});}),request({'form':{'method':_0x221771('0x27'),'input_type':_0x221771('0x4e'),'response_type':_0x221771('0x4e'),'rest_data':JSON[_0x221771('0x5')]({'session':_0x5b9df9['id'],'module_name':_0x221771('0x5e'),'name_value_list':_0x32971c})}});}function getServerInfo(_0x106074){const _0xc3fca=_0x98c90c;return request({'form':{'method':_0xc3fca('0x35'),'input_type':'JSON','response_type':'JSON','rest_data':JSON[_0xc3fca('0x5')]({'session':_0x106074['id']})}});}function getUser(_0x1faf8c,_0xba6813,_0x1a1570){const _0x28449f=_0x98c90c;return!_[_0x28449f('0x2f')](_0xba6813)?(logger[_0x28449f('0x54')](_0x28449f('0x49'),_0xba6813),request({'form':{'method':_0x28449f('0x2e'),'input_type':'JSON','response_type':_0x28449f('0x4e'),'rest_data':JSON[_0x28449f('0x5')]({'session':_0x1a1570['id'],'module_name':_0x28449f('0x1f'),'query':util[_0x28449f('0x62')](_0x28449f('0xd'),_0xba6813),'order_by':'','offset':'0','select_fields':['id','name',_0x28449f('0x68')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})[_0x28449f('0x2')](function(_0x2f9e56){const _0x35d539=_0x28449f;if(_0x2f9e56[_0x35d539('0x42')][_0x35d539('0x6')]){const _0x25aaf0=_['find'](_0x2f9e56['entry_list'],function(_0x44cdd0){const _0x1962ed=_0x35d539;return _0x44cdd0[_0x1962ed('0x37')]['user_name'][_0x1962ed('0x30')]===_0xba6813;});if(_0x25aaf0)return logger[_0x35d539('0x54')](_0x35d539('0x1e')),Promise[_0x35d539('0x5d')]({'id':_0x25aaf0[_0x35d539('0x37')]['id'][_0x35d539('0x30')],'name':_0x25aaf0['name_value_list'][_0x35d539('0x3f')]['value']});}return logger[_0x35d539('0x54')](_0x35d539('0x51')),Promise['resolve']({'id':_0x1a1570[_0x35d539('0x37')][_0x35d539('0x15')][_0x35d539('0x30')],'name':_0x1a1570['name_value_list'][_0x35d539('0x68')][_0x35d539('0x30')]});})):(logger[_0x28449f('0x54')](_0x28449f('0x46')),Promise['resolve']({'id':_0x1a1570[_0x28449f('0x37')]['user_id'][_0x28449f('0x30')],'name':_0x1a1570['name_value_list'][_0x28449f('0x68')][_0x28449f('0x30')]}));}function getEndUser(_0x53ab85,_0x1fa112,_0x4b4890,_0x2bfae9){const _0x4e2c9a=_0x98c90c;return logger[_0x4e2c9a('0x54')](_0x4e2c9a('0x50'),_0x4b4890),request({'form':{'method':'get_entry_list','input_type':_0x4e2c9a('0x4e'),'response_type':_0x4e2c9a('0x4e'),'rest_data':JSON[_0x4e2c9a('0x5')]({'session':_0x2bfae9['id'],'module_name':_0x4e2c9a('0x31'),'query':util[_0x4e2c9a('0x62')](_0x4e2c9a('0x33'),_0x4b4890),'order_by':'','offset':'0','select_fields':['id',_0x4e2c9a('0x3f'),_0x4e2c9a('0x4a')],'link_name_to_fields_array':[],'max_results':-0x1,'deleted':'0'})}})['then'](function(_0x1678df){const _0xc70f11=_0x4e2c9a;if(_0x1678df[_0xc70f11('0x42')][_0xc70f11('0x6')]){const _0x45c7c1=_[_0xc70f11('0x1d')](_0x1678df[_0xc70f11('0x42')],function(_0xcc5a39){const _0x110caf=_0xc70f11;return _0xcc5a39[_0x110caf('0x37')][_0x110caf('0x4a')]['value']===_0x4b4890;});if(_0x45c7c1)return logger['info'](_0xc70f11('0x5a')),Promise[_0xc70f11('0x5d')]({'id':_0x45c7c1[_0xc70f11('0x37')]['id']['value'],'name':_0x45c7c1[_0xc70f11('0x37')][_0xc70f11('0x3f')][_0xc70f11('0x30')],'phone':_0x45c7c1[_0xc70f11('0x37')]['phone_home']['value']});}else return logger['info']('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!'),request({'form':{'method':'set_entry','input_type':_0xc70f11('0x4e'),'response_type':_0xc70f11('0x4e'),'rest_data':JSON[_0xc70f11('0x5')]({'session':_0x2bfae9['id'],'module_name':_0xc70f11('0x31'),'name_value_list':[{'name':_0xc70f11('0x65'),'value':_0x1fa112!==_0xc70f11('0x53')?_0x1fa112:util[_0xc70f11('0x62')](_0xc70f11('0x8'),_0x4b4890)},{'name':_0xc70f11('0x4a'),'value':_0x4b4890}]})}})['then'](function(_0x46c966){const _0x4da35a=_0xc70f11;return logger[_0x4da35a('0x54')](_0x4da35a('0x36')),Promise[_0x4da35a('0x5d')]({'id':_0x46c966['id'],'name':_0x46c966['entry_list'][_0x4da35a('0x65')]['value'],'phone':_0x46c966[_0x4da35a('0x42')][_0x4da35a('0x4a')][_0x4da35a('0x30')]});});});}function request(_0x7a2833){const _0x1b506a=_0x98c90c;return logger[_0x1b506a('0x58')](_0x1b506a('0xc'),JSON[_0x1b506a('0x5')](_0x7a2833)),rp(_[_0x1b506a('0xe')](def,_0x7a2833));}function getConnection(_0x14e8a3){const _0x25b962=_0x98c90c;return request({'method':_0x25b962('0x2b'),'form':{'method':_0x25b962('0x11'),'input_type':_0x25b962('0x4e'),'response_type':_0x25b962('0x4e'),'rest_data':JSON[_0x25b962('0x5')]({'user_auth':{'user_name':_0x14e8a3[_0x25b962('0x5c')],'password':_0x14e8a3[_0x25b962('0x48')],'encryption':_0x25b962('0x41')},'application':'xCALLY\x20Motion\x20integration'})}})[_0x25b962('0x2')](function(_0x120a0b){const _0x13504e=_0x25b962,_0x5e4c2a=_0x120a0b;if(_0x5e4c2a['id'])return def['sessionID']=_0x5e4c2a['id'],Promise[_0x13504e('0x5d')](_0x5e4c2a);else throw new Error(util['format'](_0x13504e('0x55'),_0x14e8a3['id']));});}function setRelationship(_0x20553c,_0x41a69a,_0x389701,_0x49b62d){const _0x4c7c6b=_0x98c90c;return request({'form':{'method':_0x4c7c6b('0x1b'),'input_type':_0x4c7c6b('0x4e'),'response_type':_0x4c7c6b('0x4e'),'rest_data':JSON['stringify']({'session':_0x20553c['id'],'module_name':_0x4c7c6b('0x5e'),'module_id':_0x389701['id'],'link_field_name':_0x49b62d,'related_ids':[_0x41a69a['id']]})}});}exports[_0x98c90c('0x2c')]=function(_0x23340f,_0x58451b,_0x297065,_0x57d93d,_0x24ba64,_0x2b622f){const _0x5d4862=_0x98c90c;let _0x33beab,_0x5161b6,_0x4e0c0c,_0xe28100;return _0x2b622f[_0x5d4862('0x69')]=intUtil['stripTrailingSlash'](_0x2b622f[_0x5d4862('0x69')]),_0x2b622f[_0x5d4862('0x20')]=intUtil['stripTrailingSlash'](_0x2b622f[_0x5d4862('0x20')]),def['uri']=util[_0x5d4862('0x62')](_0x5d4862('0x13'),_0x2b622f['remoteUri']),_0x24ba64&&_0x24ba64[_0x5d4862('0x16')]?(logger[_0x5d4862('0x54')](_0x5d4862('0x17'),_0x5d4862('0x32')),_0x58451b[_0x5d4862('0x1c')]=util[_0x5d4862('0x62')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2b622f[_0x5d4862('0x20')],_0x58451b['uniqueid'],md5(_0x58451b[_0x5d4862('0x28')]))):_0x58451b['recordingURL']='',getConnection(_0x2b622f)[_0x5d4862('0x2')](function(_0x3e0e0a){const _0x1964c4=_0x5d4862;return _0xe28100=_0x3e0e0a,getUser(_0x2b622f,_0x57d93d[_0x1964c4('0x3f')],_0xe28100);})[_0x5d4862('0x2')](function(_0x3ce0f0){const _0x374d9b=_0x5d4862;return _0x33beab=_0x3ce0f0,logger[_0x374d9b('0x54')]('The\x20User\x20ID\x20is:',_0x33beab['id']),getEndUser(_0x2b622f,_0x58451b['calleridname'],_0x58451b[_0x374d9b('0x60')],_0xe28100);})[_0x5d4862('0x2')](function(_0xa14429){const _0x1c0f30=_0x5d4862;return _0x5161b6=_0xa14429,logger[_0x1c0f30('0x54')](_0x1c0f30('0x12'),_0x5161b6['id']),getTicket(_0x2b622f,_0x33beab,_0x5161b6,_0x297065,_0x58451b,_0x297065[_0x1c0f30('0x4f')],_0xe28100,_0x1c0f30('0x61'));})['then'](function(_0x487475){const _0x470c77=_0x5d4862;return _0x4e0c0c=_0x487475,logger['info'](_0x470c77('0xf')),logger[_0x470c77('0x54')](_0x470c77('0x67'),_0x4e0c0c['id']),setRelationship(_0xe28100,_0x33beab,_0x4e0c0c,_0x470c77('0x3'));})[_0x5d4862('0x2')](function(){const _0x529766=_0x5d4862;return setRelationship(_0xe28100,_0x5161b6,_0x4e0c0c,_0x529766('0x3c'));})[_0x5d4862('0x2')](function(){return getServerInfo(_0xe28100);})[_0x5d4862('0x2')](function(_0x15e2f6){const _0x3e97e9=_0x5d4862,_0x559b95=parseInt(_0x15e2f6['version'][_0x3e97e9('0x10')](0x0));let _0x476919=util[_0x3e97e9('0x62')]('%s/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCalls%26action%3DEditView%26record%3D%s',_0x2b622f[_0x3e97e9('0x69')],_0x4e0c0c['id']);_0x559b95>0x6&&(_0x476919=util[_0x3e97e9('0x62')](_0x3e97e9('0x40'),_0x2b622f[_0x3e97e9('0x69')],_0x4e0c0c['id'])),logger[_0x3e97e9('0x54')]('[QUEUE]',_0x3e97e9('0x64')),emit(util[_0x3e97e9('0x62')](_0x3e97e9('0x4c'),_0x57d93d['name']),'trigger:browser:url',{'uri':_0x476919});})[_0x5d4862('0x44')](function(_0x52d551){const _0x26fd85=_0x5d4862;logger[_0x26fd85('0x19')](_0x26fd85('0x17'),JSON[_0x26fd85('0x5')](_0x52d551));});},exports['outbound']=function(_0x1c42b1,_0x287d37,_0x679c45,_0x365c3f,_0x382e35,_0x282800,_0x5971ae){const _0x14dcca=_0x98c90c;let _0x379bf5,_0xb3b50c,_0x5e7a86,_0x2e8bde;return _0x282800['remoteUri']=intUtil[_0x14dcca('0x4d')](_0x282800[_0x14dcca('0x69')]),_0x282800[_0x14dcca('0x20')]=intUtil[_0x14dcca('0x4d')](_0x282800[_0x14dcca('0x20')]),def[_0x14dcca('0x21')]=util[_0x14dcca('0x62')](_0x14dcca('0x13'),_0x282800[_0x14dcca('0x69')]),_0x5971ae&&_0x5971ae['recordingFormat']&&_0x5971ae[_0x14dcca('0x59')]!==_0x14dcca('0x5b')&&(logger[_0x14dcca('0x54')](_0x14dcca('0x24'),_0x14dcca('0x32')),_0x287d37[_0x14dcca('0x1c')]=util[_0x14dcca('0x62')](_0x14dcca('0x25'),_0x282800[_0x14dcca('0x20')],_0x287d37[_0x14dcca('0x28')],md5(_0x287d37[_0x14dcca('0x28')]))),getConnection(_0x282800)[_0x14dcca('0x2')](function(_0x46dbe0){return _0x2e8bde=_0x46dbe0,getUser(_0x282800,_0x365c3f['name'],_0x2e8bde);})[_0x14dcca('0x2')](function(_0x1f7c5b){const _0x264554=_0x14dcca;return _0x379bf5=_0x1f7c5b,logger['info']('The\x20User\x20ID\x20is:',_0x379bf5['id']),getEndUser(_0x282800,_0x287d37[_0x264554('0x4')],_0x287d37[_0x264554('0xa')],_0x2e8bde);})[_0x14dcca('0x2')](function(_0x58c904){const _0x4b7860=_0x14dcca;return _0xb3b50c=_0x58c904,logger[_0x4b7860('0x54')](_0x4b7860('0x12'),_0xb3b50c['id']),getTicket(_0x282800,_0x379bf5,_0xb3b50c,_0x679c45,_0x287d37,_0x679c45[_0x4b7860('0x4f')],_0x2e8bde,_0x4b7860('0x26'));})[_0x14dcca('0x2')](function(_0x428b72){const _0x48285e=_0x14dcca;return _0x5e7a86=_0x428b72,logger['info'](_0x48285e('0xf')),logger[_0x48285e('0x54')](_0x48285e('0x67'),_0x5e7a86['id']),setRelationship(_0x2e8bde,_0x379bf5,_0x5e7a86,_0x48285e('0x3'));})[_0x14dcca('0x2')](function(){return setRelationship(_0x2e8bde,_0xb3b50c,_0x5e7a86,'contacts');})[_0x14dcca('0x2')](function(){return getServerInfo(_0x2e8bde);})[_0x14dcca('0x2')](function(_0x5197c0){const _0x390b92=_0x14dcca,_0x409237=parseInt(_0x5197c0['version']['charAt'](0x0));let _0x69bb26=util[_0x390b92('0x62')](_0x390b92('0x66'),_0x282800['remoteUri'],_0x5e7a86['id']);_0x409237>0x6&&(_0x69bb26=util[_0x390b92('0x62')](_0x390b92('0x40'),_0x282800[_0x390b92('0x69')],_0x5e7a86['id'])),logger[_0x390b92('0x54')](_0x390b92('0x24'),_0x390b92('0x64')),emit(util['format'](_0x390b92('0x4c'),_0x365c3f['name']),_0x390b92('0x39'),{'uri':_0x69bb26});})[_0x14dcca('0x44')](function(_0x3e98eb){const _0x32418a=_0x14dcca;logger[_0x32418a('0x19')]('[OUTBOUND]',JSON[_0x32418a('0x5')](_0x3e98eb));});},exports[_0x98c90c('0x18')]=function(_0x3d717b,_0x59deb6,_0x4c11ae,_0x1ab600,_0x267fea,_0x305a4c){const _0x5af9f4=_0x98c90c;let _0x1461a0,_0xad90a1,_0xb95643,_0x581485;return _0x305a4c[_0x5af9f4('0x69')]=intUtil[_0x5af9f4('0x4d')](_0x305a4c['remoteUri']),_0x305a4c[_0x5af9f4('0x20')]=intUtil[_0x5af9f4('0x4d')](_0x305a4c[_0x5af9f4('0x20')]),def[_0x5af9f4('0x21')]=util[_0x5af9f4('0x62')]('%s/service/v4_1/rest.php',_0x305a4c[_0x5af9f4('0x69')]),_0x267fea&&_0x267fea[_0x5af9f4('0x16')]?(logger[_0x5af9f4('0x54')]('['+_0x59deb6['lastevent'][_0x5af9f4('0x2a')]()+']','Recording\x20is\x20enabled!'),_0x59deb6[_0x5af9f4('0x1c')]=util['format'](_0x5af9f4('0x25'),_0x305a4c[_0x5af9f4('0x20')],_0x59deb6[_0x5af9f4('0x28')],md5(_0x59deb6[_0x5af9f4('0x28')]))):_0x59deb6[_0x5af9f4('0x1c')]='',getConnection(_0x305a4c)[_0x5af9f4('0x2')](function(_0x1c1d96){const _0x2ccdcf=_0x5af9f4;return _0x581485=_0x1c1d96,!_[_0x2ccdcf('0x2f')](_0x1ab600)?getUser(_0x305a4c,_0x1ab600[_0x2ccdcf('0x3f')],_0x581485):getUser(_0x305a4c,null,_0x581485);})['then'](function(_0x4d3f78){const _0x2f18b3=_0x5af9f4;return _0x1461a0=_0x4d3f78,logger['info'](_0x2f18b3('0x4b'),_0x1461a0['id']),getEndUser(_0x305a4c,_0x59deb6[_0x2f18b3('0x0')],_0x59deb6[_0x2f18b3('0x60')],_0x581485);})[_0x5af9f4('0x2')](function(_0x35cc4a){const _0x4bd969=_0x5af9f4;return _0xad90a1=_0x35cc4a,logger[_0x4bd969('0x54')](_0x4bd969('0x12'),_0xad90a1['id']),getTicket(_0x305a4c,_0x1461a0,_0xad90a1,_0x4c11ae,_0x59deb6,_0x4c11ae['Fields'],_0x581485,_0x4bd969('0x61'));})['then'](function(_0x294961){const _0x3d0ba7=_0x5af9f4;return _0xb95643=_0x294961,logger[_0x3d0ba7('0x54')](_0x3d0ba7('0xf')),logger[_0x3d0ba7('0x54')](_0x3d0ba7('0x67'),_0xb95643['id']),setRelationship(_0x581485,_0x1461a0,_0xb95643,_0x3d0ba7('0x3'));})[_0x5af9f4('0x2')](function(){const _0x66fef1=_0x5af9f4;return setRelationship(_0x581485,_0xad90a1,_0xb95643,_0x66fef1('0x3c'));})[_0x5af9f4('0x2')](function(){return getServerInfo(_0x581485);})['catch'](function(_0x4567d5){const _0x1d9604=_0x5af9f4;logger[_0x1d9604('0x19')]('['+_0x59deb6[_0x1d9604('0x2d')][_0x1d9604('0x2a')]()+']',JSON[_0x1d9604('0x5')](_0x4567d5));});};
\ No newline at end of file