Built motion from commit f738f9592c388b9f9eb3948f400a5c9d717a3561. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / dynamics365.js
index 6a7e0f3..c3096c7 100644 (file)
@@ -1 +1 @@
-const a1301_0xf45a=['../../../../config/logger','length','toUpperCase','systemusers?$select=internalemailaddress,isdisabled,systemuserid','clientId','contacts?$select=telephone1','remoteUri','request-promise-native','calleridnum','callDirection','user:%s','userId','inspect',']\x20The\x20User\x20ID\x20is:','getString','odata-entityid','POST','lastIndexOf','catch','value','access_token','emit','message','customField',']\x20Enduser\x20Created!','idField','then','recordingURL','Descriptions','internalemailaddress','content','phonecalls','stripTrailingSlash','password',']\x20Error\x20running\x20Dynamics365\x20integration','destcalleridnum','assign','ticketId','queue','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Fields','format','isNil',']\x20Wrong\x20credentials!','isdisabled','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','toLowerCase','telephone1','recordingFormat','/contacts(','clientSecret','contactid','error','nameField','Bearer\x20','headers','info',']\x20The\x20User\x20email\x20is:','tenantId','https://login.microsoftonline.com/%s/oauth2/token','userEmail','serverUrl','outbound','ticketType','none','incidents','indexOf',']\x20The\x20Enduser\x20phone\x20is:','type','4.0','util','email','username',']\x20Call\x20direction:\x20%s',']\x20The\x20%s\x20ID\x20is:\x20%s','unmanaged','../../../../rediscache','systemuserid',']\x20Enduser\x20created!','trigger:browser:url','./util','/systemusers(',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','Subjects',']\x20Agent\x20found\x20','forEach','%s/api/data/v9.0/','substring','enduserId'];(function(_0x5871eb,_0x132763){const _0xf45af7=function(_0x532e63){while(--_0x532e63){_0x5871eb['push'](_0x5871eb['shift']());}};_0xf45af7(++_0x132763);}(a1301_0xf45a,0x1e0));const a1301_0x532e=function(_0x5871eb,_0x132763){_0x5871eb=_0x5871eb-0xbf;let _0xf45af7=a1301_0xf45a[_0x5871eb];return _0xf45af7;};const a1301_0x42c596=a1301_0x532e;'use strict';const _=require('lodash'),rp=require(a1301_0x42c596(0x108)),util=require(a1301_0x42c596(0xee)),intUtil=require(a1301_0x42c596(0xf8)),md5=require('md5'),logger=require(a1301_0x42c596(0x101))('dynamics365'),{getSocket}=require(a1301_0x42c596(0xf4)),io=getSocket();function getAuthToken(_0x41bddb,_0x76f985,_0xf5560){const _0x513a60=a1301_0x42c596,_0xe0a9f4={'method':'POST','uri':_0x76f985,'form':{'client_id':_0x41bddb[_0x513a60(0x105)],'resource':_0x41bddb[_0x513a60(0x107)],'username':_0x41bddb[_0x513a60(0xf0)],'password':_0x41bddb[_0x513a60(0xc7)],'grant_type':_0x513a60(0xc7),'client_secret':_0x41bddb[_0x513a60(0xda)]},'json':!![]};return rp(_0xe0a9f4)['then'](function(_0x43eefb){const _0x47c775=_0x513a60;return _0x43eefb[_0x47c775(0x115)];})[_0x513a60(0x113)](function(_0xf078b5){const _0x1c9f35=_0x513a60;return logger[_0x1c9f35(0xdc)]('['+[_0xf5560[_0x1c9f35(0x103)]()]+_0x1c9f35(0xd1)),_0xf078b5[_0x1c9f35(0x117)];});}function getUser(_0x3655b1,_0x161461,_0x7a8ad7,_0x3da012,_0x2763d8,_0x214e71){return new Promise(function(_0x259b2a,_0x3c4a4e){const _0x14352e=a1301_0x532e;return getAuthToken(_0x161461,_0x3da012,_0x214e71)[_0x14352e(0xc0)](function(_0x52301f){const _0x200f87=_0x14352e,_0x4ff436={'method':'GET','uri':_0x2763d8+_0x200f87(0x104),'headers':{'Authorization':_0x200f87(0xde)+_0x52301f,'OData-Version':'4.0'},'json':!![]};return rp(_0x4ff436);})[_0x14352e(0xc0)](function(_0x1bbd4a){const _0x4f91d0=_0x14352e,_0x21ef82=_0x1bbd4a[_0x4f91d0(0x114)];let _0x35a074=![],_0x2c50de=null;if(!_[_0x4f91d0(0xd0)](_0x7a8ad7)){if(intUtil['validateEmail'](_0x7a8ad7[_0x4f91d0(0xef)])){_0x3655b1[_0x4f91d0(0xe4)]=_0x7a8ad7[_0x4f91d0(0xef)];for(_0x2c50de=0x0;_0x2c50de<_0x21ef82[_0x4f91d0(0x102)];_0x2c50de++){_0x21ef82[_0x2c50de][_0x4f91d0(0xc3)]===_0x7a8ad7[_0x4f91d0(0xef)]&&!_0x21ef82[_0x2c50de][_0x4f91d0(0xd2)]&&(_0x35a074=!![],logger['info']('['+[_0x214e71[_0x4f91d0(0x103)]()]+_0x4f91d0(0xfc)+_0x21ef82[_0x2c50de]['systemuserid']+'!'),_0x3655b1[_0x4f91d0(0x10c)]=_0x21ef82[_0x2c50de][_0x4f91d0(0xf5)]);}}}if(!_0x35a074){logger[_0x4f91d0(0xe0)]('['+[_0x214e71[_0x4f91d0(0x103)]()]+_0x4f91d0(0xfa)),_0x3655b1[_0x4f91d0(0xe4)]=_0x161461[_0x4f91d0(0xf0)];for(_0x2c50de=0x0;_0x2c50de<_0x21ef82[_0x4f91d0(0x102)];_0x2c50de++){_0x21ef82[_0x2c50de][_0x4f91d0(0xc3)]===_0x161461[_0x4f91d0(0xf0)]&&(_0x3655b1[_0x4f91d0(0x10c)]=_0x21ef82[_0x2c50de][_0x4f91d0(0xf5)]);}}_0x259b2a(_0x3655b1);})[_0x14352e(0x113)](function(_0x3c75c9){const _0x4f5124=_0x14352e;_0x3c4a4e(_0x3c75c9[_0x4f5124(0x117)]);});});}function createEndUser(_0x388745,_0x3fc3f4,_0xdfed4f,_0x5e377d,_0x3b81c5,_0x2a7974){return new Promise(function(_0x5e8a35,_0x2cebdd){const _0x6b0b4e=a1301_0x532e;return getAuthToken(_0x3fc3f4,_0xdfed4f,_0x2a7974)[_0x6b0b4e(0xc0)](function(_0x980ff7){const _0x2c3a95=_0x6b0b4e,_0x5857c1=_0x2a7974[_0x2c3a95(0xd6)]()===_0x2c3a95(0xe6)?_0x3b81c5[_0x2c3a95(0xc9)]:_0x3b81c5[_0x2c3a95(0x109)],_0x3c7c38={'method':_0x2c3a95(0x111),'uri':_0x5e377d+'contacts','body':{'telephone1':_0x5857c1,'fullname':_0x5857c1,'firstname':_0x5857c1,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x2c3a95(0xf9)+_0x388745[_0x2c3a95(0x10c)]+')'},'headers':{'Authorization':_0x2c3a95(0xde)+_0x980ff7,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x3c7c38);})['then'](function(_0x2af078){const _0x40e1c3=_0x6b0b4e,_0x24fe70=_0x2af078[_0x40e1c3(0xdf)][_0x40e1c3(0x110)],_0x3b8da9=_0x24fe70[_0x40e1c3(0xff)](_0x24fe70['lastIndexOf']('(')+0x1,_0x24fe70[_0x40e1c3(0x112)](')'));_0x388745[_0x40e1c3(0x100)]=_0x3b8da9,_0x5e8a35(_0x388745);})[_0x6b0b4e(0x113)](function(_0x3cf09d){const _0x54e75d=_0x6b0b4e;_0x2cebdd(_0x3cf09d[_0x54e75d(0x117)]);});});}function getEndUser(_0x1d93cf,_0x53830a,_0x3fb501,_0x560e3d,_0x5d98f0,_0x4d2c4b){return new Promise(function(_0x1f42a3){const _0x11495a=a1301_0x532e;return getAuthToken(_0x53830a,_0x3fb501,_0x4d2c4b)['then'](function(_0x37bbaf){const _0x409dd0=a1301_0x532e,_0x2b8e20={'method':'GET','uri':_0x560e3d+_0x409dd0(0x106),'headers':{'Authorization':_0x409dd0(0xde)+_0x37bbaf,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x2b8e20);})[_0x11495a(0xc0)](function(_0x514d8f){const _0x1b2cc1=_0x11495a;let _0x38a88a=null;if(_0x514d8f){const _0xd1b0d=_0x514d8f['value'];let _0x1d6208=![];for(_0x38a88a=0x0;_0x38a88a<_0xd1b0d['length'];_0x38a88a++){const _0x1db31f=_0x4d2c4b[_0x1b2cc1(0xd6)]()===_0x1b2cc1(0xe6)?_0x5d98f0[_0x1b2cc1(0xc9)]:_0x5d98f0[_0x1b2cc1(0x109)];_0xd1b0d[_0x38a88a][_0x1b2cc1(0xd7)]===_0x1db31f&&(_0x1d6208=!![],_0x1d93cf['enduserId']=_0xd1b0d[_0x38a88a][_0x1b2cc1(0xdb)]);}if(_0x1d6208)_0x1f42a3(_0x1d93cf);else return createEndUser(_0x1d93cf,_0x53830a,_0x3fb501,_0x560e3d,_0x5d98f0,_0x4d2c4b)['then'](function(_0x31a6b5){const _0x232158=_0x1b2cc1;logger[_0x232158(0xe0)]('['+[_0x4d2c4b['toUpperCase']()]+_0x232158(0xf6),_0x31a6b5[_0x232158(0x100)]),_0x1f42a3(_0x31a6b5);});}else return createEndUser(_0x1d93cf,_0x53830a,_0x3fb501,_0x560e3d,_0x5d98f0,_0x4d2c4b)[_0x1b2cc1(0xc0)](function(_0x134da2){const _0x440a6e=_0x1b2cc1;logger[_0x440a6e(0xe0)]('['+[_0x4d2c4b[_0x440a6e(0x103)]()]+_0x440a6e(0x119),_0x134da2[_0x440a6e(0x100)]),_0x1f42a3(_0x134da2);});});});}function getCustomFields(_0x5f1fe9,_0x54671e,_0xc81baf){const _0x303454=a1301_0x42c596,_0x32b3a8={};return _0x5f1fe9['length']>0x0&&_[_0x303454(0xfd)](_0x5f1fe9,function(_0x4abae8){const _0x72d6=_0x303454;if(_0x4abae8[_0x72d6(0xec)]==='string'&&_0x4abae8[_0x72d6(0xdd)]&&!_0x4abae8[_0x72d6(0x118)]){const _0x3b47b9=_0x4abae8[_0x72d6(0xbf)][_0x72d6(0xd6)](),_0x238367=_0x3b47b9[_0x72d6(0xff)](0x0,_0x3b47b9[_0x72d6(0xea)]('_')),_0x40b3f5=_0x3b47b9[_0x72d6(0xff)](_0x3b47b9[_0x72d6(0xea)]('_')+0x1);_0x238367===_0xc81baf&&(_0x32b3a8[_0x40b3f5]=_0x4abae8[_0x72d6(0xc4)]);}}),_0x32b3a8;}function getTicket(_0x5149fe,_0x2eddd9,_0x3840f9,_0x5d7cea,_0x371a6c,_0x49b66c,_0x4ee6ca){return new Promise(function(_0x34baf3,_0x52bb2b){const _0x2a54f5=a1301_0x532e;let _0x23e1ec;return getAuthToken(_0x2eddd9,_0x3840f9,_0x4ee6ca)[_0x2a54f5(0xc0)](function(_0x4e5365){const _0x1a0d95=_0x2a54f5;return _0x49b66c[_0x1a0d95(0xe7)]==='incident'&&(_0x23e1ec={'method':_0x1a0d95(0x111),'uri':_0x5d7cea+_0x1a0d95(0xe9),'body':Object[_0x1a0d95(0xca)]({},{'title':intUtil[_0x1a0d95(0x10f)](_0x49b66c[_0x1a0d95(0xfb)],_0x371a6c,'\x20'),'description':intUtil['getString'](_0x49b66c['Descriptions'],_0x371a6c,'\x0a'),'customerid_contact@odata.bind':_0x1a0d95(0xd9)+_0x5149fe[_0x1a0d95(0x100)]+')','ownerid@odata.bind':'/systemusers('+_0x5149fe['userId']+')','caseorigincode':'1'},getCustomFields(_0x49b66c[_0x1a0d95(0xce)],_0x371a6c,_0x49b66c[_0x1a0d95(0xe7)])),'headers':{'Authorization':'Bearer\x20'+_0x4e5365,'OData-Version':_0x1a0d95(0xed)},'json':!![],'resolveWithFullResponse':!![]}),_0x49b66c['ticketType']==='phonecall'&&(_0x23e1ec={'method':'POST','uri':_0x5d7cea+_0x1a0d95(0xc5),'body':Object['assign']({},{'subject':intUtil[_0x1a0d95(0x10f)](_0x49b66c[_0x1a0d95(0xfb)],_0x371a6c,'\x20'),'phonenumber':String(_0x371a6c[_0x1a0d95(0x109)]),'description':intUtil[_0x1a0d95(0x10f)](_0x49b66c[_0x1a0d95(0xc2)],_0x371a6c,'\x0a'),'regardingobjectid_contact@odata.bind':_0x1a0d95(0xd9)+_0x5149fe['enduserId']+')','ownerid@odata.bind':_0x1a0d95(0xf9)+_0x5149fe[_0x1a0d95(0x10c)]+')','directioncode':_0x5149fe[_0x1a0d95(0x10a)]===_0x1a0d95(0xcc)?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':_0x1a0d95(0xf9)+_0x5149fe['userId']+')','participationtypemask':_0x5149fe[_0x1a0d95(0x10a)]===_0x1a0d95(0xcc)?0x2:0x1},{'partyid_contact@odata.bind':_0x1a0d95(0xd9)+_0x5149fe[_0x1a0d95(0x100)]+')','participationtypemask':_0x5149fe[_0x1a0d95(0x10a)]==='queue'?0x1:0x2}]},getCustomFields(_0x49b66c[_0x1a0d95(0xce)],_0x371a6c,_0x49b66c[_0x1a0d95(0xe7)])),'headers':{'Authorization':'Bearer\x20'+_0x4e5365,'OData-Version':_0x1a0d95(0xed)},'json':!![],'resolveWithFullResponse':!![]}),rp(_0x23e1ec);})['then'](function(_0x294c8a){const _0x51f510=_0x2a54f5,_0x595548=_0x294c8a[_0x51f510(0xdf)][_0x51f510(0x110)],_0x2db47b=_0x595548[_0x51f510(0xff)](_0x595548[_0x51f510(0x112)]('(')+0x1,_0x595548[_0x51f510(0x112)](')'));_0x5149fe[_0x51f510(0xcb)]=_0x2db47b,_0x34baf3(_0x5149fe);})[_0x2a54f5(0x113)](function(_0x25a839){const _0x125f91=_0x2a54f5;_0x52bb2b(_0x25a839[_0x125f91(0x117)]);});});}function emit(_0x485eec,_0x160070,_0x2f592c,_0x3eaa23){const _0x376a86=a1301_0x42c596,_0x4c0a98={'uri':util['format']('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x485eec,_0x2f592c,_0x3eaa23)};io['to'](util['format'](_0x376a86(0x10b),_0x160070))[_0x376a86(0x116)](_0x376a86(0xf7),_0x4c0a98);}exports['cs']=function(_0xf51a40,_0x4d3549,_0x3db83b,_0x30eb3c,_0x1452f1,_0x5b2f4d,_0x50bbfc,_0x5e6c79){const _0x3c4af2=a1301_0x42c596,_0x2f0be9={};_0x5b2f4d[_0x3c4af2(0x107)]=intUtil[_0x3c4af2(0xc6)](_0x5b2f4d['remoteUri']),_0x5b2f4d[_0x3c4af2(0xe5)]=intUtil['stripTrailingSlash'](_0x5b2f4d[_0x3c4af2(0xe5)]),_0x2f0be9[_0x3c4af2(0x10a)]=_0x5e6c79===_0x3c4af2(0xcc)||_0x5e6c79===_0x3c4af2(0xf3)?'queue':_0x3c4af2(0xe6);const _0x289988=util[_0x3c4af2(0xcf)](_0x3c4af2(0xfe),_0x5b2f4d[_0x3c4af2(0x107)]),_0xd8d6fd=util['format'](_0x3c4af2(0xe3),_0x5b2f4d[_0x3c4af2(0xe2)]),_0x35713a=util[_0x3c4af2(0xcf)](_0x3c4af2(0xcd),_0x5b2f4d[_0x3c4af2(0xe5)],_0x4d3549[_0x3c4af2(0xd3)],md5(_0x4d3549[_0x3c4af2(0xd3)]));if(_0x1452f1&&_0x1452f1['monitor_format'])logger[_0x3c4af2(0xe0)](_0x3c4af2(0xd4),_0x3c4af2(0xd5)),_0x4d3549[_0x3c4af2(0xc1)]=_0x35713a;else _0x50bbfc&&_0x50bbfc[_0x3c4af2(0xd8)]&&_0x50bbfc['recordingFormat']!==_0x3c4af2(0xe8)?(logger['info']('[OUTBOUND]',_0x3c4af2(0xd5)),_0x4d3549[_0x3c4af2(0xc1)]=_0x35713a):_0x4d3549['recordingURL']='';return getUser(_0x2f0be9,_0x5b2f4d,_0x30eb3c,_0xd8d6fd,_0x289988,_0x5e6c79)[_0x3c4af2(0xc0)](function(_0x5935e3){const _0x57c65b=_0x3c4af2;return logger['info']('['+_0x5e6c79[_0x57c65b(0x103)]()+_0x57c65b(0x10e),_0x5935e3[_0x57c65b(0x10c)]),logger['info']('['+_0x5e6c79[_0x57c65b(0x103)]()+_0x57c65b(0xe1),_0x5935e3[_0x57c65b(0xe4)]),getEndUser(_0x5935e3,_0x5b2f4d,_0xd8d6fd,_0x289988,_0x4d3549,_0x5e6c79);})[_0x3c4af2(0xc0)](function(_0x76bb86){const _0x4328b2=_0x3c4af2;return logger[_0x4328b2(0xe0)]('['+_0x5e6c79[_0x4328b2(0x103)]()+']\x20The\x20Enduser\x20ID\x20is:',_0x76bb86[_0x4328b2(0x100)]),logger[_0x4328b2(0xe0)]('['+_0x5e6c79[_0x4328b2(0x103)]()+_0x4328b2(0xeb),_0x4d3549[_0x4328b2(0x109)]),getTicket(_0x76bb86,_0x5b2f4d,_0xd8d6fd,_0x289988,_0x4d3549,_0x3db83b,_0x5e6c79);})['then'](function(_0x12c1ee){const _0xe4551c=_0x3c4af2;logger['info'](util[_0xe4551c(0xcf)]('['+_0x5e6c79[_0xe4551c(0x103)]()+_0xe4551c(0xf2),_0x3db83b[_0xe4551c(0xe7)],_0x12c1ee[_0xe4551c(0xcb)])),logger['info'](util['format']('['+_0x5e6c79[_0xe4551c(0x103)]()+_0xe4551c(0xf1),_0x5e6c79)),_0x5e6c79!=='unmanaged'&&(logger[_0xe4551c(0xe0)]('['+_0x5e6c79[_0xe4551c(0x103)]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...'),emit(_0x5b2f4d[_0xe4551c(0x107)],_0x30eb3c['name'],_0x3db83b[_0xe4551c(0xe7)],_0x12c1ee[_0xe4551c(0xcb)]));})[_0x3c4af2(0x113)](function(_0x26c4ac){const _0x1aedaa=_0x3c4af2;logger['error']('['+_0x5e6c79[_0x1aedaa(0x103)]()+_0x1aedaa(0xc8),util[_0x1aedaa(0x10d)](_0x26c4ac,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+const a1305_0x443c=['substring','Descriptions','odata-entityid','then','idField','emit','GET','string','userEmail','length','incidents','phonecall','isNil','assign','recordingURL','remoteUri','ticketType','Recording\x20is\x20enabled!','inspect','getString','request-promise-native','../../../../rediscache','indexOf','userId','stripTrailingSlash','tenantId','toUpperCase','calleridnum',']\x20Call\x20direction:\x20%s','ticketId','Fields','util','queue','systemuserid','value','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','username','incident','catch','4.0',']\x20Enduser\x20created!','outbound','Subjects',']\x20The\x20Enduser\x20phone\x20is:','error','headers','contactid','message','type','recordingFormat','trigger:browser:url','monitor_format','format','toLowerCase','clientSecret','[OUTBOUND]','lastIndexOf','forEach','dynamics365','serverUrl','/contacts(','callDirection','isdisabled','internalemailaddress','password','clientId','info','POST',']\x20Enduser\x20Created!','./util','destcalleridnum','unmanaged',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','/systemusers(','../../../../config/logger',']\x20The\x20User\x20ID\x20is:','email','enduserId','Bearer\x20',']\x20The\x20Enduser\x20ID\x20is:','access_token','md5','lodash','content','customField'];(function(_0x8296c1,_0x1a272e){const _0x443ccf=function(_0xfdbe96){while(--_0xfdbe96){_0x8296c1['push'](_0x8296c1['shift']());}};_0x443ccf(++_0x1a272e);}(a1305_0x443c,0x185));const a1305_0xfdbe=function(_0x8296c1,_0x1a272e){_0x8296c1=_0x8296c1-0x154;let _0x443ccf=a1305_0x443c[_0x8296c1];return _0x443ccf;};const a1305_0x3788ac=a1305_0xfdbe;'use strict';const _=require(a1305_0x3788ac(0x175)),rp=require(a1305_0x3788ac(0x18c)),util=require(a1305_0x3788ac(0x197)),intUtil=require(a1305_0x3788ac(0x168)),md5=require(a1305_0x3788ac(0x174)),logger=require(a1305_0x3788ac(0x16d))(a1305_0x3788ac(0x15d)),{getSocket}=require(a1305_0x3788ac(0x18d)),io=getSocket();function getAuthToken(_0x261c37,_0x47129a,_0x3a4a35){const _0x5ae220=a1305_0x3788ac,_0x59d4ab={'method':_0x5ae220(0x166),'uri':_0x47129a,'form':{'client_id':_0x261c37[_0x5ae220(0x164)],'resource':_0x261c37[_0x5ae220(0x187)],'username':_0x261c37[_0x5ae220(0x19c)],'password':_0x261c37[_0x5ae220(0x163)],'grant_type':_0x5ae220(0x163),'client_secret':_0x261c37[_0x5ae220(0x159)]},'json':!![]};return rp(_0x59d4ab)[_0x5ae220(0x17b)](function(_0x56a566){const _0x455f1a=_0x5ae220;return _0x56a566[_0x455f1a(0x173)];})[_0x5ae220(0x19e)](function(_0x6af90){const _0x509a3f=_0x5ae220;return logger[_0x509a3f(0x1a4)]('['+[_0x3a4a35[_0x509a3f(0x192)]()]+']\x20Wrong\x20credentials!'),_0x6af90[_0x509a3f(0x1a7)];});}function getUser(_0x352bd0,_0x875aff,_0xda5ce7,_0x5a4254,_0x570f05,_0x36a018){return new Promise(function(_0x5351d0,_0x15c7fb){const _0x37b509=a1305_0xfdbe;return getAuthToken(_0x875aff,_0x5a4254,_0x36a018)[_0x37b509(0x17b)](function(_0x251ad9){const _0x48fb05=_0x37b509,_0x2fd429={'method':_0x48fb05(0x17e),'uri':_0x570f05+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0x48fb05(0x171)+_0x251ad9,'OData-Version':_0x48fb05(0x19f)},'json':!![]};return rp(_0x2fd429);})['then'](function(_0x4f6316){const _0xfdb723=_0x37b509,_0x2e5651=_0x4f6316[_0xfdb723(0x19a)];let _0x28ae35=![],_0x5254c9=null;if(!_[_0xfdb723(0x184)](_0xda5ce7)){if(intUtil['validateEmail'](_0xda5ce7[_0xfdb723(0x16f)])){_0x352bd0['userEmail']=_0xda5ce7[_0xfdb723(0x16f)];for(_0x5254c9=0x0;_0x5254c9<_0x2e5651[_0xfdb723(0x181)];_0x5254c9++){_0x2e5651[_0x5254c9][_0xfdb723(0x162)]===_0xda5ce7[_0xfdb723(0x16f)]&&!_0x2e5651[_0x5254c9][_0xfdb723(0x161)]&&(_0x28ae35=!![],logger['info']('['+[_0x36a018[_0xfdb723(0x192)]()]+']\x20Agent\x20found\x20'+_0x2e5651[_0x5254c9][_0xfdb723(0x199)]+'!'),_0x352bd0[_0xfdb723(0x18f)]=_0x2e5651[_0x5254c9][_0xfdb723(0x199)]);}}}if(!_0x28ae35){logger[_0xfdb723(0x165)]('['+[_0x36a018['toUpperCase']()]+_0xfdb723(0x16b)),_0x352bd0[_0xfdb723(0x180)]=_0x875aff[_0xfdb723(0x19c)];for(_0x5254c9=0x0;_0x5254c9<_0x2e5651[_0xfdb723(0x181)];_0x5254c9++){_0x2e5651[_0x5254c9]['internalemailaddress']===_0x875aff['username']&&(_0x352bd0[_0xfdb723(0x18f)]=_0x2e5651[_0x5254c9][_0xfdb723(0x199)]);}}_0x5351d0(_0x352bd0);})[_0x37b509(0x19e)](function(_0x58c0bd){const _0x28bae4=_0x37b509;_0x15c7fb(_0x58c0bd[_0x28bae4(0x1a7)]);});});}function createEndUser(_0x2d7991,_0x594d87,_0x364ab8,_0x370288,_0x451e57,_0x2828ac){return new Promise(function(_0x309bd2,_0xe9773e){const _0x40166d=a1305_0xfdbe;return getAuthToken(_0x594d87,_0x364ab8,_0x2828ac)[_0x40166d(0x17b)](function(_0x3725d2){const _0x56ce25=_0x40166d,_0x4a4b26=_0x2828ac[_0x56ce25(0x158)]()==='outbound'?_0x451e57[_0x56ce25(0x169)]:_0x451e57[_0x56ce25(0x193)],_0x110fe8={'method':_0x56ce25(0x166),'uri':_0x370288+'contacts','body':{'telephone1':_0x4a4b26,'fullname':_0x4a4b26,'firstname':_0x4a4b26,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x56ce25(0x16c)+_0x2d7991[_0x56ce25(0x18f)]+')'},'headers':{'Authorization':_0x56ce25(0x171)+_0x3725d2,'OData-Version':_0x56ce25(0x19f)},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x110fe8);})['then'](function(_0x262ab9){const _0xbfaf7d=_0x40166d,_0x5942b1=_0x262ab9[_0xbfaf7d(0x1a5)]['odata-entityid'],_0x198b34=_0x5942b1[_0xbfaf7d(0x178)](_0x5942b1[_0xbfaf7d(0x15b)]('(')+0x1,_0x5942b1[_0xbfaf7d(0x15b)](')'));_0x2d7991[_0xbfaf7d(0x170)]=_0x198b34,_0x309bd2(_0x2d7991);})[_0x40166d(0x19e)](function(_0x438a39){const _0x3f0b76=_0x40166d;_0xe9773e(_0x438a39[_0x3f0b76(0x1a7)]);});});}function getEndUser(_0x501afd,_0x8702d3,_0xf1b88c,_0x557a38,_0x2d71a7,_0x4ed544){return new Promise(function(_0x3a63fe){const _0xdc2534=a1305_0xfdbe;return getAuthToken(_0x8702d3,_0xf1b88c,_0x4ed544)[_0xdc2534(0x17b)](function(_0x156784){const _0x5d6332=_0xdc2534,_0x4a84f5={'method':'GET','uri':_0x557a38+'contacts?$select=telephone1','headers':{'Authorization':_0x5d6332(0x171)+_0x156784,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x4a84f5);})[_0xdc2534(0x17b)](function(_0x407e9b){const _0xbef3bf=_0xdc2534;let _0x594157=null;if(_0x407e9b){const _0x439f75=_0x407e9b[_0xbef3bf(0x19a)];let _0x1f3f2e=![];for(_0x594157=0x0;_0x594157<_0x439f75[_0xbef3bf(0x181)];_0x594157++){const _0x32af82=_0x4ed544['toLowerCase']()===_0xbef3bf(0x1a1)?_0x2d71a7[_0xbef3bf(0x169)]:_0x2d71a7[_0xbef3bf(0x193)];_0x439f75[_0x594157]['telephone1']===_0x32af82&&(_0x1f3f2e=!![],_0x501afd[_0xbef3bf(0x170)]=_0x439f75[_0x594157][_0xbef3bf(0x1a6)]);}if(_0x1f3f2e)_0x3a63fe(_0x501afd);else return createEndUser(_0x501afd,_0x8702d3,_0xf1b88c,_0x557a38,_0x2d71a7,_0x4ed544)[_0xbef3bf(0x17b)](function(_0x3a07fa){const _0x189bdd=_0xbef3bf;logger[_0x189bdd(0x165)]('['+[_0x4ed544[_0x189bdd(0x192)]()]+_0x189bdd(0x1a0),_0x3a07fa['enduserId']),_0x3a63fe(_0x3a07fa);});}else return createEndUser(_0x501afd,_0x8702d3,_0xf1b88c,_0x557a38,_0x2d71a7,_0x4ed544)[_0xbef3bf(0x17b)](function(_0x3b5d7b){const _0x1678d5=_0xbef3bf;logger['info']('['+[_0x4ed544[_0x1678d5(0x192)]()]+_0x1678d5(0x167),_0x3b5d7b[_0x1678d5(0x170)]),_0x3a63fe(_0x3b5d7b);});});});}function getCustomFields(_0x2b5c16,_0x2e8748,_0x325fc8){const _0xafe447=a1305_0x3788ac,_0x4533f6={};return _0x2b5c16[_0xafe447(0x181)]>0x0&&_[_0xafe447(0x15c)](_0x2b5c16,function(_0x198a1a){const _0x311553=_0xafe447;if(_0x198a1a[_0x311553(0x1a8)]===_0x311553(0x17f)&&_0x198a1a['nameField']&&!_0x198a1a[_0x311553(0x177)]){const _0x646d84=_0x198a1a[_0x311553(0x17c)][_0x311553(0x158)](),_0x1c2eb9=_0x646d84[_0x311553(0x178)](0x0,_0x646d84[_0x311553(0x18e)]('_')),_0x163706=_0x646d84[_0x311553(0x178)](_0x646d84[_0x311553(0x18e)]('_')+0x1);_0x1c2eb9===_0x325fc8&&(_0x4533f6[_0x163706]=_0x198a1a[_0x311553(0x176)]);}}),_0x4533f6;}function getTicket(_0x3dee24,_0x4b53f0,_0x5bf06c,_0x1a34de,_0x15edd9,_0x2f448f,_0x263af6){return new Promise(function(_0x234404,_0x2daf79){const _0x29f956=a1305_0xfdbe;let _0x426e59;return getAuthToken(_0x4b53f0,_0x5bf06c,_0x263af6)[_0x29f956(0x17b)](function(_0x5c9c6f){const _0x4ea294=_0x29f956;return _0x2f448f[_0x4ea294(0x188)]===_0x4ea294(0x19d)&&(_0x426e59={'method':'POST','uri':_0x1a34de+_0x4ea294(0x182),'body':Object[_0x4ea294(0x185)]({},{'title':intUtil[_0x4ea294(0x18b)](_0x2f448f[_0x4ea294(0x1a2)],_0x15edd9,'\x20'),'description':intUtil[_0x4ea294(0x18b)](_0x2f448f[_0x4ea294(0x179)],_0x15edd9,'\x0a'),'customerid_contact@odata.bind':_0x4ea294(0x15f)+_0x3dee24['enduserId']+')','ownerid@odata.bind':_0x4ea294(0x16c)+_0x3dee24['userId']+')','caseorigincode':'1'},getCustomFields(_0x2f448f[_0x4ea294(0x196)],_0x15edd9,_0x2f448f[_0x4ea294(0x188)])),'headers':{'Authorization':'Bearer\x20'+_0x5c9c6f,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]}),_0x2f448f['ticketType']===_0x4ea294(0x183)&&(_0x426e59={'method':_0x4ea294(0x166),'uri':_0x1a34de+'phonecalls','body':Object[_0x4ea294(0x185)]({},{'subject':intUtil[_0x4ea294(0x18b)](_0x2f448f[_0x4ea294(0x1a2)],_0x15edd9,'\x20'),'phonenumber':String(_0x15edd9[_0x4ea294(0x193)]),'description':intUtil['getString'](_0x2f448f[_0x4ea294(0x179)],_0x15edd9,'\x0a'),'regardingobjectid_contact@odata.bind':_0x4ea294(0x15f)+_0x3dee24[_0x4ea294(0x170)]+')','ownerid@odata.bind':_0x4ea294(0x16c)+_0x3dee24[_0x4ea294(0x18f)]+')','directioncode':_0x3dee24['callDirection']==='queue'?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':'/systemusers('+_0x3dee24[_0x4ea294(0x18f)]+')','participationtypemask':_0x3dee24['callDirection']===_0x4ea294(0x198)?0x2:0x1},{'partyid_contact@odata.bind':'/contacts('+_0x3dee24[_0x4ea294(0x170)]+')','participationtypemask':_0x3dee24['callDirection']==='queue'?0x1:0x2}]},getCustomFields(_0x2f448f[_0x4ea294(0x196)],_0x15edd9,_0x2f448f['ticketType'])),'headers':{'Authorization':_0x4ea294(0x171)+_0x5c9c6f,'OData-Version':_0x4ea294(0x19f)},'json':!![],'resolveWithFullResponse':!![]}),rp(_0x426e59);})[_0x29f956(0x17b)](function(_0xcb9bc8){const _0x2465bd=_0x29f956,_0x3f06bc=_0xcb9bc8[_0x2465bd(0x1a5)][_0x2465bd(0x17a)],_0x57d6aa=_0x3f06bc[_0x2465bd(0x178)](_0x3f06bc['lastIndexOf']('(')+0x1,_0x3f06bc['lastIndexOf'](')'));_0x3dee24[_0x2465bd(0x195)]=_0x57d6aa,_0x234404(_0x3dee24);})['catch'](function(_0x45d668){_0x2daf79(_0x45d668['message']);});});}function emit(_0x239408,_0x43321a,_0x452490,_0xe3fb21){const _0x46b288=a1305_0x3788ac,_0x4f7c8a={'uri':util[_0x46b288(0x157)]('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x239408,_0x452490,_0xe3fb21)};io['to'](util[_0x46b288(0x157)]('user:%s',_0x43321a))[_0x46b288(0x17d)](_0x46b288(0x155),_0x4f7c8a);}exports['cs']=function(_0x3e19ec,_0x2947c3,_0xec5fbe,_0x21038e,_0x4159e8,_0x48ebd0,_0x1fac4b,_0x89fa1){const _0x2b2c01=a1305_0x3788ac,_0x4ee83c={};_0x48ebd0[_0x2b2c01(0x187)]=intUtil[_0x2b2c01(0x190)](_0x48ebd0[_0x2b2c01(0x187)]),_0x48ebd0[_0x2b2c01(0x15e)]=intUtil['stripTrailingSlash'](_0x48ebd0[_0x2b2c01(0x15e)]),_0x4ee83c[_0x2b2c01(0x160)]=_0x89fa1===_0x2b2c01(0x198)||_0x89fa1===_0x2b2c01(0x16a)?_0x2b2c01(0x198):_0x2b2c01(0x1a1);const _0x46a3dd=util[_0x2b2c01(0x157)]('%s/api/data/v9.0/',_0x48ebd0['remoteUri']),_0x21f035=util['format']('https://login.microsoftonline.com/%s/oauth2/token',_0x48ebd0[_0x2b2c01(0x191)]),_0x33b579=util[_0x2b2c01(0x157)](_0x2b2c01(0x19b),_0x48ebd0[_0x2b2c01(0x15e)],_0x2947c3['uniqueid'],md5(_0x2947c3['uniqueid']));if(_0x4159e8&&_0x4159e8[_0x2b2c01(0x156)])logger[_0x2b2c01(0x165)]('[QUEUE]',_0x2b2c01(0x189)),_0x2947c3[_0x2b2c01(0x186)]=_0x33b579;else _0x1fac4b&&_0x1fac4b[_0x2b2c01(0x154)]&&_0x1fac4b[_0x2b2c01(0x154)]!=='none'?(logger[_0x2b2c01(0x165)](_0x2b2c01(0x15a),_0x2b2c01(0x189)),_0x2947c3[_0x2b2c01(0x186)]=_0x33b579):_0x2947c3['recordingURL']='';return getUser(_0x4ee83c,_0x48ebd0,_0x21038e,_0x21f035,_0x46a3dd,_0x89fa1)['then'](function(_0x5f58b2){const _0x1d1fa6=_0x2b2c01;return logger['info']('['+_0x89fa1[_0x1d1fa6(0x192)]()+_0x1d1fa6(0x16e),_0x5f58b2['userId']),logger[_0x1d1fa6(0x165)]('['+_0x89fa1[_0x1d1fa6(0x192)]()+']\x20The\x20User\x20email\x20is:',_0x5f58b2[_0x1d1fa6(0x180)]),getEndUser(_0x5f58b2,_0x48ebd0,_0x21f035,_0x46a3dd,_0x2947c3,_0x89fa1);})[_0x2b2c01(0x17b)](function(_0x172f16){const _0x4f9e4e=_0x2b2c01;return logger[_0x4f9e4e(0x165)]('['+_0x89fa1['toUpperCase']()+_0x4f9e4e(0x172),_0x172f16[_0x4f9e4e(0x170)]),logger[_0x4f9e4e(0x165)]('['+_0x89fa1[_0x4f9e4e(0x192)]()+_0x4f9e4e(0x1a3),_0x2947c3[_0x4f9e4e(0x193)]),getTicket(_0x172f16,_0x48ebd0,_0x21f035,_0x46a3dd,_0x2947c3,_0xec5fbe,_0x89fa1);})[_0x2b2c01(0x17b)](function(_0x5ef0bb){const _0x1c19c9=_0x2b2c01;logger[_0x1c19c9(0x165)](util[_0x1c19c9(0x157)]('['+_0x89fa1['toUpperCase']()+']\x20The\x20%s\x20ID\x20is:\x20%s',_0xec5fbe[_0x1c19c9(0x188)],_0x5ef0bb['ticketId'])),logger[_0x1c19c9(0x165)](util[_0x1c19c9(0x157)]('['+_0x89fa1[_0x1c19c9(0x192)]()+_0x1c19c9(0x194),_0x89fa1)),_0x89fa1!==_0x1c19c9(0x16a)&&(logger[_0x1c19c9(0x165)]('['+_0x89fa1[_0x1c19c9(0x192)]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...'),emit(_0x48ebd0[_0x1c19c9(0x187)],_0x21038e['name'],_0xec5fbe[_0x1c19c9(0x188)],_0x5ef0bb[_0x1c19c9(0x195)]));})['catch'](function(_0x140045){const _0x97d927=_0x2b2c01;logger[_0x97d927(0x1a4)]('['+_0x89fa1['toUpperCase']()+']\x20Error\x20running\x20Dynamics365\x20integration',util[_0x97d927(0x18a)](_0x140045,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file