Built motion from commit 4d4d9a88.|2.6.26
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index da656f7..85f531f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xba9f=['type','nameField','idField','indexOf','ticketType','assign','getString','/contacts(','Fields','phonecall','callDirection','queue','Descriptions','headers','substring','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','trigger:browser:url','modernAuthentication','stripTrailingSlash','serverUrl','unmanaged','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none',']\x20The\x20User\x20ID\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s','openNewTab','error',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','lodash','request-promise','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','redis','socket.io-emitter','remoteUri','data7','tenantId','data5','POST','clientId','password','access_token','catch','toUpperCase',']\x20Wrong\x20credentials!','message','GET','Bearer\x20','4.0','then','value','isNil','validateEmail','email','userEmail','length','internalemailaddress','isdisabled','info','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','username','toLowerCase','outbound','calleridnum','/systemusers(','body','odata-entityid','lastIndexOf','destcalleridnum','telephone1','contacts?$select=','\x20eq\x20\x27','replace','%2b','enduserId','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','string','picklist'];(function(_0x11b6a8,_0x38b981){var _0x5537a9=function(_0x1f1699){while(--_0x1f1699){_0x11b6a8['push'](_0x11b6a8['shift']());}};_0x5537a9(++_0x38b981);}(_0xba9f,0x1bb));var _0xfba9=function(_0x49068f,_0x252a71){_0x49068f=_0x49068f-0x0;var _0x5a3090=_0xba9f[_0x49068f];return _0x5a3090;};'use strict';var _=require(_0xfba9('0x0'));var rp=require(_0xfba9('0x1'));var util=require('util');var intUtil=require('./util');var md5=require('md5');var Redis=require(_0xfba9('0x2'));var logger=require(_0xfba9('0x3'))(_0xfba9('0x4'));var config=require(_0xfba9('0x5'));config[_0xfba9('0x6')]=_['defaults'](config[_0xfba9('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0xfba9('0x7'))(new Redis(config[_0xfba9('0x6')]));function getAuthToken(_0x4f3da3,_0x10ffa1,_0x59ec28){if(_0x4f3da3['modernAuthentication']){_0x4f3da3[_0xfba9('0x8')]=_0x4f3da3['CloudProvider'][_0xfba9('0x9')];_0x4f3da3[_0xfba9('0xa')]=_0x4f3da3['CloudProvider']['data2'];return Promise['resolve'](_0x4f3da3['CloudProvider'][_0xfba9('0xb')]);}var _0x26ba3d={'method':_0xfba9('0xc'),'uri':_0x10ffa1,'form':{'client_id':_0x4f3da3[_0xfba9('0xd')],'resource':_0x4f3da3['remoteUri'],'username':_0x4f3da3['username'],'password':_0x4f3da3['password'],'grant_type':_0xfba9('0xe'),'client_secret':_0x4f3da3['clientSecret']},'json':!![]};return rp(_0x26ba3d)['then'](function(_0x304f41){return _0x304f41[_0xfba9('0xf')];})[_0xfba9('0x10')](function(_0xa8bbb4){logger['error']('['+[_0x59ec28[_0xfba9('0x11')]()]+_0xfba9('0x12'));return _0xa8bbb4[_0xfba9('0x13')];});}function getUser(_0x173a2d,_0x2c50d0,_0x4f3231,_0x2e0847,_0x558306,_0x2359ab){return new Promise(function(_0x4dd508,_0x4d11b0){return getAuthToken(_0x2c50d0,_0x2e0847,_0x2359ab)['then'](function(_0x18464c){var _0x54e51c={'method':_0xfba9('0x14'),'uri':_0x558306+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0xfba9('0x15')+_0x18464c,'OData-Version':_0xfba9('0x16')},'json':!![]};return rp(_0x54e51c);})[_0xfba9('0x17')](function(_0x117b7f){var _0x1f0e98=_0x117b7f[_0xfba9('0x18')];var _0x16013b=![];var _0x4d75cb=null;if(!_[_0xfba9('0x19')](_0x4f3231)){if(intUtil[_0xfba9('0x1a')](_0x4f3231[_0xfba9('0x1b')])){_0x173a2d[_0xfba9('0x1c')]=_0x4f3231[_0xfba9('0x1b')];for(_0x4d75cb=0x0;_0x4d75cb<_0x1f0e98[_0xfba9('0x1d')];_0x4d75cb++){if(_0x1f0e98[_0x4d75cb][_0xfba9('0x1e')]===_0x4f3231[_0xfba9('0x1b')]&&!_0x1f0e98[_0x4d75cb][_0xfba9('0x1f')]){_0x16013b=!![];logger[_0xfba9('0x20')]('['+[_0x2359ab['toUpperCase']()]+']\x20Agent\x20found\x20'+_0x1f0e98[_0x4d75cb][_0xfba9('0x21')]+'!');_0x173a2d[_0xfba9('0x22')]=_0x1f0e98[_0x4d75cb][_0xfba9('0x21')];}}}}if(!_0x16013b){logger[_0xfba9('0x20')]('['+[_0x2359ab['toUpperCase']()]+_0xfba9('0x23'));_0x173a2d['userEmail']=_0x2c50d0[_0xfba9('0x24')];for(_0x4d75cb=0x0;_0x4d75cb<_0x1f0e98[_0xfba9('0x1d')];_0x4d75cb++){if(_0x1f0e98[_0x4d75cb][_0xfba9('0x1e')]===_0x2c50d0[_0xfba9('0x24')]){_0x173a2d[_0xfba9('0x22')]=_0x1f0e98[_0x4d75cb][_0xfba9('0x21')];}}}_0x4dd508(_0x173a2d);})[_0xfba9('0x10')](function(_0x19234d){_0x4d11b0(_0x19234d[_0xfba9('0x13')]);});});}function createEndUser(_0x42b446,_0x34c2a6,_0x479f7c,_0x54b405,_0x24da74,_0x48bd35,_0x2dca3a){return new Promise(function(_0x238ddb,_0x16b76a){return getAuthToken(_0x34c2a6,_0x479f7c,_0x48bd35)[_0xfba9('0x17')](function(_0x34c43e){var _0xa3746c=_0x48bd35[_0xfba9('0x25')]()===_0xfba9('0x26')?_0x24da74['destcalleridnum']:_0x24da74[_0xfba9('0x27')];var _0xca4505={'method':_0xfba9('0xc'),'uri':_0x54b405+'contacts','body':{'fullname':_0xa3746c,'firstname':_0xa3746c,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0xfba9('0x28')+_0x42b446[_0xfba9('0x22')]+')'},'headers':{'Authorization':_0xfba9('0x15')+_0x34c43e,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};_0xca4505[_0xfba9('0x29')][_0x2dca3a]=_0xa3746c;return rp(_0xca4505);})[_0xfba9('0x17')](function(_0xa165e0){var _0x36c13a=_0xa165e0['headers'][_0xfba9('0x2a')];var _0x10a7b1=_0x36c13a['substring'](_0x36c13a[_0xfba9('0x2b')]('(')+0x1,_0x36c13a[_0xfba9('0x2b')](')'));_0x42b446['enduserId']=_0x10a7b1;_0x238ddb(_0x42b446);})[_0xfba9('0x10')](function(_0x51778f){_0x16b76a(_0x51778f['message']);});});}function getEndUser(_0x18622c,_0x1edb73,_0x48437c,_0x3417c8,_0xceb13e,_0x3499b3,_0x1fe647,_0x1d9526){var _0x520d45=_0x3499b3[_0xfba9('0x25')]()===_0xfba9('0x26')?_0xceb13e[_0xfba9('0x2c')]:_0xceb13e[_0xfba9('0x27')];return getAuthToken(_0x1edb73,_0x48437c,_0x3499b3)['then'](function(_0x481182){_0x1d9526=_0x1d9526?_0x1d9526:_0xfba9('0x2d');var _0x27cae8={'method':_0xfba9('0x14'),'uri':_0x3417c8+_0xfba9('0x2e')+_0x1d9526+'&$filter='+_0x1d9526+_0xfba9('0x2f')+_0x520d45[_0xfba9('0x30')]('+',_0xfba9('0x31'))+'\x27','headers':{'Authorization':_0xfba9('0x15')+_0x481182,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x27cae8);})[_0xfba9('0x17')](function(_0x969482){var _0x1fffb1=![];if(!_0x969482)return _0x1fffb1;var _0x3f6bf4=_0x969482[_0xfba9('0x18')];for(var _0xa56f9e=0x0;_0xa56f9e<_0x3f6bf4['length'];_0xa56f9e++){if(_0x3f6bf4[_0xa56f9e][_0x1d9526]===_0x520d45){_0x1fffb1=!![];_0x18622c[_0xfba9('0x32')]=_0x3f6bf4[_0xa56f9e]['contactid'];}}return _0x1fffb1;})[_0xfba9('0x17')](function(_0x24b9f6){if(_0x24b9f6)return _0x18622c;if(_0x1fe647===_0xfba9('0x33')){logger[_0xfba9('0x20')]('['+[_0x3499b3['toUpperCase']()]+_0xfba9('0x34'));return _0x18622c;}return createEndUser(_0x18622c,_0x1edb73,_0x48437c,_0x3417c8,_0xceb13e,_0x3499b3,_0x1d9526)[_0xfba9('0x17')](function(_0x1e3364){logger[_0xfba9('0x20')]('['+[_0x3499b3['toUpperCase']()]+_0xfba9('0x35'),_0x1e3364[_0xfba9('0x32')]);return _0x1e3364;});});}function getCustomFields(_0x222048,_0x3b613f,_0x142884){var _0x3d1f56={};if(_0x222048[_0xfba9('0x1d')]>0x0){_[_0xfba9('0x36')](_0x222048,function(_0x38aece){if(_['includes']([_0xfba9('0x37'),_0xfba9('0x38')],_0x38aece[_0xfba9('0x39')])&&_0x38aece[_0xfba9('0x3a')]&&!_0x38aece['customField']){var _0x3531a6=_0x38aece[_0xfba9('0x3b')]['toLowerCase']();var _0x14833e=_0x3531a6['substring'](0x0,_0x3531a6[_0xfba9('0x3c')]('_'));var _0x298a19=_0x3531a6['substring'](_0x3531a6[_0xfba9('0x3c')]('_')+0x1);if(_0x14833e===_0x142884){_0x3d1f56[_0x298a19]=_0x38aece['content'];}}});}return _0x3d1f56;}function getTicket(_0x2c427f,_0xa3cb0d,_0x9b7847,_0x111e25,_0x510024,_0x5f48cd,_0x24c0b9){return new Promise(function(_0x56a57f,_0x1c6751){var _0xc6b66d;return getAuthToken(_0xa3cb0d,_0x9b7847,_0x24c0b9)['then'](function(_0x1810be){if(_0x5f48cd[_0xfba9('0x3d')]==='incident'){_0xc6b66d={'method':_0xfba9('0xc'),'uri':_0x111e25+'incidents','body':Object[_0xfba9('0x3e')]({},{'title':intUtil[_0xfba9('0x3f')](_0x5f48cd['Subjects'],_0x510024,'\x20'),'description':intUtil['getString'](_0x5f48cd['Descriptions'],_0x510024,'\x0a'),'customerid_contact@odata.bind':_0x2c427f[_0xfba9('0x32')]?_0xfba9('0x40')+_0x2c427f[_0xfba9('0x32')]+')':undefined,'ownerid@odata.bind':_0xfba9('0x28')+_0x2c427f[_0xfba9('0x22')]+')','caseorigincode':'1'},getCustomFields(_0x5f48cd[_0xfba9('0x41')],_0x510024,_0x5f48cd[_0xfba9('0x3d')])),'headers':{'Authorization':_0xfba9('0x15')+_0x1810be,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}if(_0x5f48cd[_0xfba9('0x3d')]===_0xfba9('0x42')){var _0x4e87d4=_0x2c427f['enduserId']?[{'partyid_systemuser@odata.bind':'/systemusers('+_0x2c427f[_0xfba9('0x22')]+')','participationtypemask':_0x2c427f[_0xfba9('0x43')]===_0xfba9('0x44')?0x2:0x1},{'partyid_contact@odata.bind':_0xfba9('0x40')+_0x2c427f['enduserId']+')','participationtypemask':_0x2c427f[_0xfba9('0x43')]==='queue'?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0xfba9('0x28')+_0x2c427f[_0xfba9('0x22')]+')','participationtypemask':_0x2c427f[_0xfba9('0x43')]===_0xfba9('0x44')?0x2:0x1}];_0xc6b66d={'method':_0xfba9('0xc'),'uri':_0x111e25+'phonecalls','body':Object['assign']({},{'subject':intUtil[_0xfba9('0x3f')](_0x5f48cd['Subjects'],_0x510024,'\x20'),'phonenumber':String(_0x510024[_0xfba9('0x27')]),'description':intUtil[_0xfba9('0x3f')](_0x5f48cd[_0xfba9('0x45')],_0x510024,'\x0a'),'regardingobjectid_contact@odata.bind':_0x2c427f[_0xfba9('0x32')]?_0xfba9('0x40')+_0x2c427f[_0xfba9('0x32')]+')':undefined,'ownerid@odata.bind':_0xfba9('0x28')+_0x2c427f['userId']+')','directioncode':_0x2c427f['callDirection']===_0xfba9('0x44')?![]:!![],'phonecall_activity_parties':_0x4e87d4},getCustomFields(_0x5f48cd[_0xfba9('0x41')],_0x510024,_0x5f48cd[_0xfba9('0x3d')])),'headers':{'Authorization':_0xfba9('0x15')+_0x1810be,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0xc6b66d);})[_0xfba9('0x17')](function(_0xbb9039){var _0x270ee7=_0xbb9039[_0xfba9('0x46')][_0xfba9('0x2a')];var _0x39267a=_0x270ee7[_0xfba9('0x47')](_0x270ee7[_0xfba9('0x2b')]('(')+0x1,_0x270ee7['lastIndexOf'](')'));_0x2c427f[_0xfba9('0x48')]=_0x39267a;_0x56a57f(_0x2c427f);})[_0xfba9('0x10')](function(_0x29792d){_0x1c6751(_0x29792d[_0xfba9('0x13')]);});});}function emit(_0x5d3e72,_0x40c8c3,_0x40a78e,_0xd6b29d){var _0x2fa671={'uri':util[_0xfba9('0x49')](_0xfba9('0x4a'),_0x5d3e72,_0x40a78e,_0xd6b29d)};io['to'](util[_0xfba9('0x49')](_0xfba9('0x4b'),_0x40c8c3))['emit'](_0xfba9('0x4c'),_0x2fa671);}exports['cs']=function(_0x36d7d2,_0x439104,_0x1f672c,_0x5b32a4,_0x2af7fb,_0xf2bec6,_0x281a97,_0x2733c8){var _0x346e9a={};_0xf2bec6[_0xfba9('0x8')]=_0xf2bec6[_0xfba9('0x4d')]?intUtil[_0xfba9('0x4e')](_0xf2bec6['CloudProvider'][_0xfba9('0x9')]):intUtil[_0xfba9('0x4e')](_0xf2bec6['remoteUri']);_0xf2bec6['serverUrl']=intUtil[_0xfba9('0x4e')](_0xf2bec6[_0xfba9('0x4f')]);_0x346e9a['callDirection']=_0x2733c8===_0xfba9('0x44')||_0x2733c8===_0xfba9('0x50')?_0xfba9('0x44'):_0xfba9('0x26');var _0x301a77=_0xf2bec6[_0xfba9('0x4d')]?util[_0xfba9('0x49')](_0xfba9('0x51'),_0xf2bec6['CloudProvider']['data7']):util[_0xfba9('0x49')]('%s/api/data/v9.0/',_0xf2bec6[_0xfba9('0x8')]);var _0x5f1e27=util[_0xfba9('0x49')](_0xfba9('0x52'),_0xf2bec6[_0xfba9('0xa')]);var _0x48c9a2=util[_0xfba9('0x49')](_0xfba9('0x53'),_0xf2bec6[_0xfba9('0x4f')],_0x439104['uniqueid'],md5(_0x439104[_0xfba9('0x54')]));if(_0x2af7fb&&_0x2af7fb['monitor_format']){logger[_0xfba9('0x20')](_0xfba9('0x55'),_0xfba9('0x56'));_0x439104[_0xfba9('0x57')]=_0x48c9a2;}else if(_0x281a97&&_0x281a97[_0xfba9('0x58')]&&_0x281a97[_0xfba9('0x58')]!==_0xfba9('0x59')){logger[_0xfba9('0x20')]('[OUTBOUND]',_0xfba9('0x56'));_0x439104[_0xfba9('0x57')]=_0x48c9a2;}else{_0x439104[_0xfba9('0x57')]='';}return getUser(_0x346e9a,_0xf2bec6,_0x5b32a4,_0x5f1e27,_0x301a77,_0x2733c8)[_0xfba9('0x17')](function(_0x314e36){logger[_0xfba9('0x20')]('['+_0x2733c8[_0xfba9('0x11')]()+_0xfba9('0x5a'),_0x314e36['userId']);logger[_0xfba9('0x20')]('['+_0x2733c8[_0xfba9('0x11')]()+']\x20The\x20User\x20email\x20is:',_0x314e36['userEmail']);return getEndUser(_0x314e36,_0xf2bec6,_0x5f1e27,_0x301a77,_0x439104,_0x2733c8,_0x1f672c[_0xfba9('0x5b')],_0x1f672c[_0xfba9('0x5c')]);})[_0xfba9('0x17')](function(_0x43faed){logger['info']('['+_0x2733c8[_0xfba9('0x11')]()+_0xfba9('0x5d'),_0x43faed[_0xfba9('0x32')]);logger[_0xfba9('0x20')]('['+_0x2733c8[_0xfba9('0x11')]()+_0xfba9('0x5e'),_0x439104[_0xfba9('0x27')]);return getTicket(_0x43faed,_0xf2bec6,_0x5f1e27,_0x301a77,_0x439104,_0x1f672c,_0x2733c8);})[_0xfba9('0x17')](function(_0x27ae25){logger[_0xfba9('0x20')](util[_0xfba9('0x49')]('['+_0x2733c8['toUpperCase']()+_0xfba9('0x5f'),_0x1f672c[_0xfba9('0x3d')],_0x27ae25[_0xfba9('0x48')]));logger[_0xfba9('0x20')](util[_0xfba9('0x49')]('['+_0x2733c8[_0xfba9('0x11')]()+']\x20Call\x20direction:\x20%s',_0x2733c8));if(_0x2733c8!==_0xfba9('0x50')&&_0x1f672c[_0xfba9('0x60')]){logger[_0xfba9('0x20')]('['+_0x2733c8[_0xfba9('0x11')]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0xf2bec6[_0xfba9('0x8')],_0x5b32a4['name'],_0x1f672c['ticketType'],_0x27ae25[_0xfba9('0x48')]);}})[_0xfba9('0x10')](function(_0x591211){logger[_0xfba9('0x61')]('['+_0x2733c8['toUpperCase']()+_0xfba9('0x62'),_0x591211[_0xfba9('0x13')]);console[_0xfba9('0x61')](_0xfba9('0x63'),_0x591211);});};
\ No newline at end of file
+var _0x9719=[']\x20Enduser\x20created!','forEach','includes','picklist','type','nameField','idField','substring','ticketType','incident','incidents','getString','/contacts(','/systemusers(','phonecall','callDirection','queue','phonecalls','assign','Fields','headers','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','emit','stripTrailingSlash','data7','serverUrl','unmanaged','%s/api/data/v9.0/','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','recordingURL','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','openNewTab','error','Error\x20running\x20Dynamics365\x20integration','request-promise','util','md5','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','redis','defaults','localhost','modernAuthentication','remoteUri','CloudProvider','tenantId','data2','resolve','data5','POST','username','password','clientSecret','then','access_token',']\x20Wrong\x20credentials!','message','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','validateEmail','email','userEmail','length','isdisabled','info','toUpperCase',']\x20Agent\x20found\x20','systemuserid','internalemailaddress','catch','destcalleridnum','calleridnum','contacts','userId','body','lastIndexOf','enduserId','toLowerCase','outbound','telephone1','contacts?$select=','&$filter=','\x20eq\x20\x27','replace','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing'];(function(_0x629479,_0x16f852){var _0x238e1f=function(_0x5575a3){while(--_0x5575a3){_0x629479['push'](_0x629479['shift']());}};_0x238e1f(++_0x16f852);}(_0x9719,0x108));var _0x9971=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0x9719[_0x4a9fb1];return _0x348672;};'use strict';var _=require('lodash');var rp=require(_0x9971('0x0'));var util=require(_0x9971('0x1'));var intUtil=require('./util');var md5=require(_0x9971('0x2'));var Redis=require(_0x9971('0x3'));var logger=require(_0x9971('0x4'))(_0x9971('0x5'));var config=require(_0x9971('0x6'));config[_0x9971('0x7')]=_[_0x9971('0x8')](config[_0x9971('0x7')],{'host':_0x9971('0x9'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x9971('0x7')]));function getAuthToken(_0x56dc2e,_0x2da07b,_0x40264a){if(_0x56dc2e[_0x9971('0xa')]){_0x56dc2e[_0x9971('0xb')]=_0x56dc2e[_0x9971('0xc')]['data7'];_0x56dc2e[_0x9971('0xd')]=_0x56dc2e['CloudProvider'][_0x9971('0xe')];return Promise[_0x9971('0xf')](_0x56dc2e[_0x9971('0xc')][_0x9971('0x10')]);}var _0x178910={'method':_0x9971('0x11'),'uri':_0x2da07b,'form':{'client_id':_0x56dc2e['clientId'],'resource':_0x56dc2e['remoteUri'],'username':_0x56dc2e[_0x9971('0x12')],'password':_0x56dc2e[_0x9971('0x13')],'grant_type':_0x9971('0x13'),'client_secret':_0x56dc2e[_0x9971('0x14')]},'json':!![]};return rp(_0x178910)[_0x9971('0x15')](function(_0xef2d32){return _0xef2d32[_0x9971('0x16')];})['catch'](function(_0x40c578){logger['error']('['+[_0x40264a['toUpperCase']()]+_0x9971('0x17'));return _0x40c578[_0x9971('0x18')];});}function getUser(_0x20733e,_0x555541,_0x375d49,_0x10d357,_0x3505f9,_0x499265){return new Promise(function(_0xefcbda,_0x13ca37){return getAuthToken(_0x555541,_0x10d357,_0x499265)[_0x9971('0x15')](function(_0x368100){var _0x436386={'method':_0x9971('0x19'),'uri':_0x3505f9+_0x9971('0x1a'),'headers':{'Authorization':_0x9971('0x1b')+_0x368100,'OData-Version':_0x9971('0x1c')},'json':!![]};return rp(_0x436386);})[_0x9971('0x15')](function(_0x54ff91){var _0x403955=_0x54ff91[_0x9971('0x1d')];var _0x1435b2=![];var _0x4862d4=null;if(!_['isNil'](_0x375d49)){if(intUtil[_0x9971('0x1e')](_0x375d49[_0x9971('0x1f')])){_0x20733e[_0x9971('0x20')]=_0x375d49[_0x9971('0x1f')];for(_0x4862d4=0x0;_0x4862d4<_0x403955[_0x9971('0x21')];_0x4862d4++){if(_0x403955[_0x4862d4]['internalemailaddress']===_0x375d49[_0x9971('0x1f')]&&!_0x403955[_0x4862d4][_0x9971('0x22')]){_0x1435b2=!![];logger[_0x9971('0x23')]('['+[_0x499265[_0x9971('0x24')]()]+_0x9971('0x25')+_0x403955[_0x4862d4]['systemuserid']+'!');_0x20733e['userId']=_0x403955[_0x4862d4][_0x9971('0x26')];}}}}if(!_0x1435b2){logger['info']('['+[_0x499265[_0x9971('0x24')]()]+']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');_0x20733e[_0x9971('0x20')]=_0x555541['username'];for(_0x4862d4=0x0;_0x4862d4<_0x403955['length'];_0x4862d4++){if(_0x403955[_0x4862d4][_0x9971('0x27')]===_0x555541[_0x9971('0x12')]){_0x20733e['userId']=_0x403955[_0x4862d4]['systemuserid'];}}}_0xefcbda(_0x20733e);})[_0x9971('0x28')](function(_0x36f799){_0x13ca37(_0x36f799[_0x9971('0x18')]);});});}function createEndUser(_0x5a78f8,_0x56f686,_0x122538,_0x511700,_0x3b0696,_0x3c3c1e,_0x52d6ee){return new Promise(function(_0xe3daad,_0x1a5b59){return getAuthToken(_0x56f686,_0x122538,_0x3c3c1e)[_0x9971('0x15')](function(_0x27a32e){var _0x4c524d=_0x3c3c1e['toLowerCase']()==='outbound'?_0x3b0696[_0x9971('0x29')]:_0x3b0696[_0x9971('0x2a')];var _0x1158dc={'method':_0x9971('0x11'),'uri':_0x511700+_0x9971('0x2b'),'body':{'fullname':_0x4c524d,'firstname':_0x4c524d,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x5a78f8[_0x9971('0x2c')]+')'},'headers':{'Authorization':_0x9971('0x1b')+_0x27a32e,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};_0x1158dc[_0x9971('0x2d')][_0x52d6ee]=_0x4c524d;return rp(_0x1158dc);})['then'](function(_0x3c6ad2){var _0x1b4cd7=_0x3c6ad2['headers']['odata-entityid'];var _0x36f5c0=_0x1b4cd7['substring'](_0x1b4cd7['lastIndexOf']('(')+0x1,_0x1b4cd7[_0x9971('0x2e')](')'));_0x5a78f8[_0x9971('0x2f')]=_0x36f5c0;_0xe3daad(_0x5a78f8);})['catch'](function(_0x4c8f0b){_0x1a5b59(_0x4c8f0b[_0x9971('0x18')]);});});}function getEndUser(_0x20eb76,_0x519eaa,_0x92d4c6,_0x32bed1,_0x18e389,_0x1b7bdf,_0x1c47ca,_0x335569){var _0x4f162f=_0x1b7bdf[_0x9971('0x30')]()===_0x9971('0x31')?_0x18e389[_0x9971('0x29')]:_0x18e389[_0x9971('0x2a')];return getAuthToken(_0x519eaa,_0x92d4c6,_0x1b7bdf)[_0x9971('0x15')](function(_0x4c3d81){_0x335569=_0x335569?_0x335569:_0x9971('0x32');var _0x4eb71a={'method':_0x9971('0x19'),'uri':_0x32bed1+_0x9971('0x33')+_0x335569+_0x9971('0x34')+_0x335569+_0x9971('0x35')+_0x4f162f[_0x9971('0x36')]('+','%2b')+'\x27','headers':{'Authorization':_0x9971('0x1b')+_0x4c3d81,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x4eb71a);})[_0x9971('0x15')](function(_0x32d599){var _0x1db81c=![];if(!_0x32d599)return _0x1db81c;var _0x54aa3a=_0x32d599['value'];for(var _0x4bdf80=0x0;_0x4bdf80<_0x54aa3a[_0x9971('0x21')];_0x4bdf80++){if(_0x54aa3a[_0x4bdf80][_0x335569]===_0x4f162f){_0x1db81c=!![];_0x20eb76[_0x9971('0x2f')]=_0x54aa3a[_0x4bdf80]['contactid'];}}return _0x1db81c;})['then'](function(_0x376655){if(_0x376655)return _0x20eb76;if(_0x1c47ca===_0x9971('0x37')){logger[_0x9971('0x23')]('['+[_0x1b7bdf[_0x9971('0x24')]()]+_0x9971('0x38'));return _0x20eb76;}return createEndUser(_0x20eb76,_0x519eaa,_0x92d4c6,_0x32bed1,_0x18e389,_0x1b7bdf,_0x335569)['then'](function(_0x584665){logger[_0x9971('0x23')]('['+[_0x1b7bdf['toUpperCase']()]+_0x9971('0x39'),_0x584665[_0x9971('0x2f')]);return _0x584665;});});}function getCustomFields(_0x2747f2,_0x55a66c,_0x83ebf9){var _0x28a341={};if(_0x2747f2[_0x9971('0x21')]>0x0){_[_0x9971('0x3a')](_0x2747f2,function(_0x2dd2af){if(_[_0x9971('0x3b')](['string',_0x9971('0x3c')],_0x2dd2af[_0x9971('0x3d')])&&_0x2dd2af[_0x9971('0x3e')]&&!_0x2dd2af['customField']){var _0x1a0205=_0x2dd2af[_0x9971('0x3f')][_0x9971('0x30')]();var _0x826388=_0x1a0205[_0x9971('0x40')](0x0,_0x1a0205['indexOf']('_'));var _0x30eeb8=_0x1a0205[_0x9971('0x40')](_0x1a0205['indexOf']('_')+0x1);if(_0x826388===_0x83ebf9){_0x28a341[_0x30eeb8]=_0x2dd2af['content'];}}});}return _0x28a341;}function getTicket(_0x1633ce,_0x3360e2,_0xa80ba5,_0x149934,_0x4a42fd,_0x5a528b,_0x3cf1de){return new Promise(function(_0x145ac0,_0x32b248){var _0x4460fe;return getAuthToken(_0x3360e2,_0xa80ba5,_0x3cf1de)[_0x9971('0x15')](function(_0xf3aa4b){if(_0x5a528b[_0x9971('0x41')]===_0x9971('0x42')){_0x4460fe={'method':_0x9971('0x11'),'uri':_0x149934+_0x9971('0x43'),'body':Object['assign']({},{'title':intUtil['getString'](_0x5a528b['Subjects'],_0x4a42fd,'\x20'),'description':intUtil[_0x9971('0x44')](_0x5a528b['Descriptions'],_0x4a42fd,'\x0a'),'customerid_contact@odata.bind':_0x1633ce[_0x9971('0x2f')]?_0x9971('0x45')+_0x1633ce[_0x9971('0x2f')]+')':undefined,'ownerid@odata.bind':_0x9971('0x46')+_0x1633ce[_0x9971('0x2c')]+')','caseorigincode':'1'},getCustomFields(_0x5a528b['Fields'],_0x4a42fd,_0x5a528b['ticketType'])),'headers':{'Authorization':_0x9971('0x1b')+_0xf3aa4b,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}if(_0x5a528b['ticketType']===_0x9971('0x47')){var _0x8647dc=_0x1633ce['enduserId']?[{'partyid_systemuser@odata.bind':_0x9971('0x46')+_0x1633ce[_0x9971('0x2c')]+')','participationtypemask':_0x1633ce[_0x9971('0x48')]===_0x9971('0x49')?0x2:0x1},{'partyid_contact@odata.bind':_0x9971('0x45')+_0x1633ce[_0x9971('0x2f')]+')','participationtypemask':_0x1633ce['callDirection']===_0x9971('0x49')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0x1633ce[_0x9971('0x2c')]+')','participationtypemask':_0x1633ce[_0x9971('0x48')]==='queue'?0x2:0x1}];_0x4460fe={'method':'POST','uri':_0x149934+_0x9971('0x4a'),'body':Object[_0x9971('0x4b')]({},{'subject':intUtil[_0x9971('0x44')](_0x5a528b['Subjects'],_0x4a42fd,'\x20'),'phonenumber':String(_0x4a42fd[_0x9971('0x2a')]),'description':intUtil['getString'](_0x5a528b['Descriptions'],_0x4a42fd,'\x0a'),'regardingobjectid_contact@odata.bind':_0x1633ce['enduserId']?_0x9971('0x45')+_0x1633ce[_0x9971('0x2f')]+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x1633ce[_0x9971('0x2c')]+')','directioncode':_0x1633ce[_0x9971('0x48')]===_0x9971('0x49')?![]:!![],'phonecall_activity_parties':_0x8647dc},getCustomFields(_0x5a528b[_0x9971('0x4c')],_0x4a42fd,_0x5a528b['ticketType'])),'headers':{'Authorization':_0x9971('0x1b')+_0xf3aa4b,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x4460fe);})[_0x9971('0x15')](function(_0x20519b){var _0x2b7701=_0x20519b[_0x9971('0x4d')]['odata-entityid'];var _0x44d1d7=_0x2b7701['substring'](_0x2b7701[_0x9971('0x2e')]('(')+0x1,_0x2b7701['lastIndexOf'](')'));_0x1633ce[_0x9971('0x4e')]=_0x44d1d7;_0x145ac0(_0x1633ce);})[_0x9971('0x28')](function(_0x453855){_0x32b248(_0x453855[_0x9971('0x18')]);});});}function emit(_0x36968f,_0xeb0d6a,_0x1c30c4,_0x3fafb4){var _0x3aee88={'uri':util[_0x9971('0x4f')](_0x9971('0x50'),_0x36968f,_0x1c30c4,_0x3fafb4)};io['to'](util[_0x9971('0x4f')](_0x9971('0x51'),_0xeb0d6a))[_0x9971('0x52')]('trigger:browser:url',_0x3aee88);}exports['cs']=function(_0x28afc3,_0x38b92d,_0x5adf25,_0x1462ba,_0x4ba8a0,_0xeab64c,_0x50bc2d,_0x2a4188){var _0x2de410={};_0xeab64c[_0x9971('0xb')]=_0xeab64c['modernAuthentication']?intUtil[_0x9971('0x53')](_0xeab64c[_0x9971('0xc')][_0x9971('0x54')]):intUtil[_0x9971('0x53')](_0xeab64c[_0x9971('0xb')]);_0xeab64c[_0x9971('0x55')]=intUtil[_0x9971('0x53')](_0xeab64c[_0x9971('0x55')]);_0x2de410[_0x9971('0x48')]=_0x2a4188===_0x9971('0x49')||_0x2a4188===_0x9971('0x56')?'queue':_0x9971('0x31');var _0x40ba1e=_0xeab64c[_0x9971('0xa')]?util['format'](_0x9971('0x57'),_0xeab64c[_0x9971('0xc')][_0x9971('0x54')]):util[_0x9971('0x4f')]('%s/api/data/v9.0/',_0xeab64c['remoteUri']);var _0x5db72b=util['format']('https://login.microsoftonline.com/%s/oauth2/token',_0xeab64c[_0x9971('0xd')]);var _0x219ea2=util[_0x9971('0x4f')](_0x9971('0x58'),_0xeab64c[_0x9971('0x55')],_0x38b92d[_0x9971('0x59')],md5(_0x38b92d['uniqueid']));if(_0x4ba8a0&&_0x4ba8a0[_0x9971('0x5a')]){logger['info'](_0x9971('0x5b'),'Recording\x20is\x20enabled!');_0x38b92d[_0x9971('0x5c')]=_0x219ea2;}else if(_0x50bc2d&&_0x50bc2d[_0x9971('0x5d')]&&_0x50bc2d[_0x9971('0x5d')]!==_0x9971('0x5e')){logger[_0x9971('0x23')](_0x9971('0x5f'),_0x9971('0x60'));_0x38b92d[_0x9971('0x5c')]=_0x219ea2;}else{_0x38b92d[_0x9971('0x5c')]='';}return getUser(_0x2de410,_0xeab64c,_0x1462ba,_0x5db72b,_0x40ba1e,_0x2a4188)['then'](function(_0x4e018c){logger[_0x9971('0x23')]('['+_0x2a4188['toUpperCase']()+']\x20The\x20User\x20ID\x20is:',_0x4e018c['userId']);logger['info']('['+_0x2a4188['toUpperCase']()+_0x9971('0x61'),_0x4e018c['userEmail']);return getEndUser(_0x4e018c,_0xeab64c,_0x5db72b,_0x40ba1e,_0x38b92d,_0x2a4188,_0x5adf25[_0x9971('0x62')],_0x5adf25[_0x9971('0x63')]);})[_0x9971('0x15')](function(_0x200b5d){logger[_0x9971('0x23')]('['+_0x2a4188[_0x9971('0x24')]()+_0x9971('0x64'),_0x200b5d[_0x9971('0x2f')]);logger[_0x9971('0x23')]('['+_0x2a4188[_0x9971('0x24')]()+_0x9971('0x65'),_0x38b92d[_0x9971('0x2a')]);return getTicket(_0x200b5d,_0xeab64c,_0x5db72b,_0x40ba1e,_0x38b92d,_0x5adf25,_0x2a4188);})[_0x9971('0x15')](function(_0xee52af){logger['info'](util['format']('['+_0x2a4188[_0x9971('0x24')]()+_0x9971('0x66'),_0x5adf25['ticketType'],_0xee52af[_0x9971('0x4e')]));logger[_0x9971('0x23')](util[_0x9971('0x4f')]('['+_0x2a4188[_0x9971('0x24')]()+_0x9971('0x67'),_0x2a4188));if(_0x2a4188!=='unmanaged'&&_0x5adf25[_0x9971('0x68')]){logger[_0x9971('0x23')]('['+_0x2a4188[_0x9971('0x24')]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0xeab64c[_0x9971('0xb')],_0x1462ba['name'],_0x5adf25[_0x9971('0x41')],_0xee52af[_0x9971('0x4e')]);}})[_0x9971('0x28')](function(_0x1a098e){logger[_0x9971('0x69')]('['+_0x2a4188[_0x9971('0x24')]()+']\x20Error\x20running\x20Dynamics365\x20integration',_0x1a098e[_0x9971('0x18')]);console['error'](_0x9971('0x6a'),_0x1a098e);});};
\ No newline at end of file