Built motion from commit 5ae82ce5.|2.6.7
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index a94c773..1e1e0ce 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcc27=['isdisabled','info',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','message','toLowerCase','outbound','destcalleridnum','calleridnum','POST','/systemusers(','body','headers','lastIndexOf','enduserId','telephone1','contacts?$select=','&$filter=','replace','%2b','contactid','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing','length','forEach','includes','picklist','type','nameField','customField','idField','substring','indexOf','content','ticketType','incident','incidents','getString','Subjects','/contacts(','Fields','phonecall','queue','callDirection','phonecalls','assign','Descriptions','odata-entityid','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','trigger:browser:url','stripTrailingSlash','data7','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','recordingURL','recordingFormat','none','Recording\x20is\x20enabled!',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','request-promise','util','./util','md5','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','remoteUri','CloudProvider','tenantId','resolve','username','password','clientSecret','then','access_token','catch','error','toUpperCase',']\x20Wrong\x20credentials!','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','isNil','userEmail','email','internalemailaddress'];(function(_0x65404,_0x34da3c){var _0x48b94d=function(_0x3d2d68){while(--_0x3d2d68){_0x65404['push'](_0x65404['shift']());}};_0x48b94d(++_0x34da3c);}(_0xcc27,0x19e));var _0x7cc2=function(_0x28996c,_0x4ecba6){_0x28996c=_0x28996c-0x0;var _0x2690eb=_0xcc27[_0x28996c];return _0x2690eb;};'use strict';var _=require('lodash');var rp=require(_0x7cc2('0x0'));var util=require(_0x7cc2('0x1'));var intUtil=require(_0x7cc2('0x2'));var md5=require(_0x7cc2('0x3'));var Redis=require(_0x7cc2('0x4'));var logger=require(_0x7cc2('0x5'))(_0x7cc2('0x6'));var config=require(_0x7cc2('0x7'));config[_0x7cc2('0x8')]=_[_0x7cc2('0x9')](config[_0x7cc2('0x8')],{'host':_0x7cc2('0xa'),'port':0x18eb});var io=require(_0x7cc2('0xb'))(new Redis(config[_0x7cc2('0x8')]));function getAuthToken(_0x5c40cf,_0x205bf5,_0x5aa741){if(_0x5c40cf['modernAuthentication']){_0x5c40cf[_0x7cc2('0xc')]=_0x5c40cf[_0x7cc2('0xd')]['data7'];_0x5c40cf[_0x7cc2('0xe')]=_0x5c40cf[_0x7cc2('0xd')]['data2'];return Promise[_0x7cc2('0xf')](_0x5c40cf[_0x7cc2('0xd')]['data5']);}var _0x2effe4={'method':'POST','uri':_0x205bf5,'form':{'client_id':_0x5c40cf['clientId'],'resource':_0x5c40cf[_0x7cc2('0xc')],'username':_0x5c40cf[_0x7cc2('0x10')],'password':_0x5c40cf['password'],'grant_type':_0x7cc2('0x11'),'client_secret':_0x5c40cf[_0x7cc2('0x12')]},'json':!![]};return rp(_0x2effe4)[_0x7cc2('0x13')](function(_0x2be1c1){return _0x2be1c1[_0x7cc2('0x14')];})[_0x7cc2('0x15')](function(_0x37cc83){logger[_0x7cc2('0x16')]('['+[_0x5aa741[_0x7cc2('0x17')]()]+_0x7cc2('0x18'));return _0x37cc83['message'];});}function getUser(_0x228d33,_0x98874c,_0x1cd2fb,_0x44e81f,_0x1ccb50,_0x1b85e5){return new Promise(function(_0x487f30,_0x357378){return getAuthToken(_0x98874c,_0x44e81f,_0x1b85e5)[_0x7cc2('0x13')](function(_0x331f5a){var _0x2d1052={'method':_0x7cc2('0x19'),'uri':_0x1ccb50+_0x7cc2('0x1a'),'headers':{'Authorization':_0x7cc2('0x1b')+_0x331f5a,'OData-Version':_0x7cc2('0x1c')},'json':!![]};return rp(_0x2d1052);})[_0x7cc2('0x13')](function(_0x53883b){var _0x43cea5=_0x53883b[_0x7cc2('0x1d')];var _0x336ad9=![];var _0xac3b7f=null;if(!_[_0x7cc2('0x1e')](_0x1cd2fb)){if(intUtil['validateEmail'](_0x1cd2fb['email'])){_0x228d33[_0x7cc2('0x1f')]=_0x1cd2fb[_0x7cc2('0x20')];for(_0xac3b7f=0x0;_0xac3b7f<_0x43cea5['length'];_0xac3b7f++){if(_0x43cea5[_0xac3b7f][_0x7cc2('0x21')]===_0x1cd2fb[_0x7cc2('0x20')]&&!_0x43cea5[_0xac3b7f][_0x7cc2('0x22')]){_0x336ad9=!![];logger[_0x7cc2('0x23')]('['+[_0x1b85e5[_0x7cc2('0x17')]()]+_0x7cc2('0x24')+_0x43cea5[_0xac3b7f][_0x7cc2('0x25')]+'!');_0x228d33[_0x7cc2('0x26')]=_0x43cea5[_0xac3b7f]['systemuserid'];}}}}if(!_0x336ad9){logger[_0x7cc2('0x23')]('['+[_0x1b85e5[_0x7cc2('0x17')]()]+_0x7cc2('0x27'));_0x228d33[_0x7cc2('0x1f')]=_0x98874c['username'];for(_0xac3b7f=0x0;_0xac3b7f<_0x43cea5['length'];_0xac3b7f++){if(_0x43cea5[_0xac3b7f][_0x7cc2('0x21')]===_0x98874c['username']){_0x228d33['userId']=_0x43cea5[_0xac3b7f]['systemuserid'];}}}_0x487f30(_0x228d33);})[_0x7cc2('0x15')](function(_0x3ae51a){_0x357378(_0x3ae51a[_0x7cc2('0x28')]);});});}function createEndUser(_0xed3daa,_0x4cbd64,_0x5222f9,_0x53507d,_0x2b6e25,_0x21271b,_0x574747){return new Promise(function(_0x32548f,_0x1436c6){return getAuthToken(_0x4cbd64,_0x5222f9,_0x21271b)[_0x7cc2('0x13')](function(_0x170a19){var _0xe614b6=_0x21271b[_0x7cc2('0x29')]()===_0x7cc2('0x2a')?_0x2b6e25[_0x7cc2('0x2b')]:_0x2b6e25[_0x7cc2('0x2c')];var _0x328f00={'method':_0x7cc2('0x2d'),'uri':_0x53507d+'contacts','body':{'fullname':_0xe614b6,'firstname':_0xe614b6,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x7cc2('0x2e')+_0xed3daa['userId']+')'},'headers':{'Authorization':_0x7cc2('0x1b')+_0x170a19,'OData-Version':_0x7cc2('0x1c')},'json':!![],'resolveWithFullResponse':!![]};_0x328f00[_0x7cc2('0x2f')][_0x574747]=_0xe614b6;return rp(_0x328f00);})['then'](function(_0x4eab64){var _0x53f882=_0x4eab64[_0x7cc2('0x30')]['odata-entityid'];var _0x53ced5=_0x53f882['substring'](_0x53f882[_0x7cc2('0x31')]('(')+0x1,_0x53f882[_0x7cc2('0x31')](')'));_0xed3daa[_0x7cc2('0x32')]=_0x53ced5;_0x32548f(_0xed3daa);})[_0x7cc2('0x15')](function(_0x483f48){_0x1436c6(_0x483f48[_0x7cc2('0x28')]);});});}function getEndUser(_0x20de40,_0x18b3cd,_0x50a059,_0x1d4137,_0xb85cef,_0x259f5c,_0x9c0faf,_0xb74009){var _0x164503=_0x259f5c[_0x7cc2('0x29')]()===_0x7cc2('0x2a')?_0xb85cef[_0x7cc2('0x2b')]:_0xb85cef[_0x7cc2('0x2c')];return getAuthToken(_0x18b3cd,_0x50a059,_0x259f5c)[_0x7cc2('0x13')](function(_0x5ef556){_0xb74009=_0xb74009?_0xb74009:_0x7cc2('0x33');var _0x124243={'method':'GET','uri':_0x1d4137+_0x7cc2('0x34')+_0xb74009+_0x7cc2('0x35')+_0xb74009+'\x20eq\x20\x27'+_0x164503[_0x7cc2('0x36')]('+',_0x7cc2('0x37'))+'\x27','headers':{'Authorization':_0x7cc2('0x1b')+_0x5ef556,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x124243);})['then'](function(_0x3ad94d){var _0xbf3192=![];if(!_0x3ad94d)return _0xbf3192;var _0x1f8236=_0x3ad94d[_0x7cc2('0x1d')];for(var _0x4f4193=0x0;_0x4f4193<_0x1f8236['length'];_0x4f4193++){if(_0x1f8236[_0x4f4193][_0xb74009]===_0x164503){_0xbf3192=!![];_0x20de40['enduserId']=_0x1f8236[_0x4f4193][_0x7cc2('0x38')];}}return _0xbf3192;})[_0x7cc2('0x13')](function(_0x447705){if(_0x447705)return _0x20de40;if(_0x9c0faf===_0x7cc2('0x39')){logger['info']('['+[_0x259f5c[_0x7cc2('0x17')]()]+_0x7cc2('0x3a'));return _0x20de40;}return createEndUser(_0x20de40,_0x18b3cd,_0x50a059,_0x1d4137,_0xb85cef,_0x259f5c,_0xb74009)[_0x7cc2('0x13')](function(_0x291945){logger[_0x7cc2('0x23')]('['+[_0x259f5c[_0x7cc2('0x17')]()]+']\x20Enduser\x20created!',_0x291945[_0x7cc2('0x32')]);return _0x291945;});});}function getCustomFields(_0x265387,_0x54a822,_0x43ebf5){var _0x9e3993={};if(_0x265387[_0x7cc2('0x3b')]>0x0){_[_0x7cc2('0x3c')](_0x265387,function(_0xbadbcd){if(_[_0x7cc2('0x3d')](['string',_0x7cc2('0x3e')],_0xbadbcd[_0x7cc2('0x3f')])&&_0xbadbcd[_0x7cc2('0x40')]&&!_0xbadbcd[_0x7cc2('0x41')]){var _0x2d5872=_0xbadbcd[_0x7cc2('0x42')][_0x7cc2('0x29')]();var _0x2bd66f=_0x2d5872[_0x7cc2('0x43')](0x0,_0x2d5872['indexOf']('_'));var _0x6fe220=_0x2d5872[_0x7cc2('0x43')](_0x2d5872[_0x7cc2('0x44')]('_')+0x1);if(_0x2bd66f===_0x43ebf5){_0x9e3993[_0x6fe220]=_0xbadbcd[_0x7cc2('0x45')];}}});}return _0x9e3993;}function getTicket(_0x3481a2,_0x44c294,_0xed2c2a,_0x32f0b7,_0x26bf68,_0x43000e,_0x224018){return new Promise(function(_0x404b92,_0x550a47){var _0x201ebd;return getAuthToken(_0x44c294,_0xed2c2a,_0x224018)[_0x7cc2('0x13')](function(_0x92d222){if(_0x43000e[_0x7cc2('0x46')]===_0x7cc2('0x47')){_0x201ebd={'method':_0x7cc2('0x2d'),'uri':_0x32f0b7+_0x7cc2('0x48'),'body':Object['assign']({},{'title':intUtil[_0x7cc2('0x49')](_0x43000e[_0x7cc2('0x4a')],_0x26bf68,'\x20'),'description':intUtil[_0x7cc2('0x49')](_0x43000e['Descriptions'],_0x26bf68,'\x0a'),'customerid_contact@odata.bind':_0x3481a2['enduserId']?_0x7cc2('0x4b')+_0x3481a2[_0x7cc2('0x32')]+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x3481a2[_0x7cc2('0x26')]+')','caseorigincode':'1'},getCustomFields(_0x43000e[_0x7cc2('0x4c')],_0x26bf68,_0x43000e[_0x7cc2('0x46')])),'headers':{'Authorization':_0x7cc2('0x1b')+_0x92d222,'OData-Version':_0x7cc2('0x1c')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x43000e['ticketType']===_0x7cc2('0x4d')){var _0x26c9c8=_0x3481a2[_0x7cc2('0x32')]?[{'partyid_systemuser@odata.bind':_0x7cc2('0x2e')+_0x3481a2['userId']+')','participationtypemask':_0x3481a2['callDirection']===_0x7cc2('0x4e')?0x2:0x1},{'partyid_contact@odata.bind':_0x7cc2('0x4b')+_0x3481a2[_0x7cc2('0x32')]+')','participationtypemask':_0x3481a2[_0x7cc2('0x4f')]===_0x7cc2('0x4e')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0x3481a2[_0x7cc2('0x26')]+')','participationtypemask':_0x3481a2['callDirection']===_0x7cc2('0x4e')?0x2:0x1}];_0x201ebd={'method':'POST','uri':_0x32f0b7+_0x7cc2('0x50'),'body':Object[_0x7cc2('0x51')]({},{'subject':intUtil[_0x7cc2('0x49')](_0x43000e[_0x7cc2('0x4a')],_0x26bf68,'\x20'),'phonenumber':String(_0x26bf68['calleridnum']),'description':intUtil['getString'](_0x43000e[_0x7cc2('0x52')],_0x26bf68,'\x0a'),'regardingobjectid_contact@odata.bind':_0x3481a2[_0x7cc2('0x32')]?_0x7cc2('0x4b')+_0x3481a2[_0x7cc2('0x32')]+')':undefined,'ownerid@odata.bind':_0x7cc2('0x2e')+_0x3481a2[_0x7cc2('0x26')]+')','directioncode':_0x3481a2[_0x7cc2('0x4f')]===_0x7cc2('0x4e')?![]:!![],'phonecall_activity_parties':_0x26c9c8},getCustomFields(_0x43000e[_0x7cc2('0x4c')],_0x26bf68,_0x43000e[_0x7cc2('0x46')])),'headers':{'Authorization':_0x7cc2('0x1b')+_0x92d222,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x201ebd);})['then'](function(_0x5d69d7){var _0x107434=_0x5d69d7[_0x7cc2('0x30')][_0x7cc2('0x53')];var _0x3f6856=_0x107434[_0x7cc2('0x43')](_0x107434['lastIndexOf']('(')+0x1,_0x107434[_0x7cc2('0x31')](')'));_0x3481a2[_0x7cc2('0x54')]=_0x3f6856;_0x404b92(_0x3481a2);})['catch'](function(_0x26258e){_0x550a47(_0x26258e[_0x7cc2('0x28')]);});});}function emit(_0x3f7c68,_0x73dcea,_0xd19fb8,_0x340b13){var _0x5d24d4={'uri':util[_0x7cc2('0x55')](_0x7cc2('0x56'),_0x3f7c68,_0xd19fb8,_0x340b13)};io['to'](util[_0x7cc2('0x55')](_0x7cc2('0x57'),_0x73dcea))['emit'](_0x7cc2('0x58'),_0x5d24d4);}exports['cs']=function(_0x429d5d,_0x1222ba,_0xb852a7,_0x1b85d0,_0x203602,_0x2b332f,_0x36ed04,_0x3ca3b7){var _0x2464c8={};_0x2b332f[_0x7cc2('0xc')]=_0x2b332f['modernAuthentication']?intUtil[_0x7cc2('0x59')](_0x2b332f[_0x7cc2('0xd')][_0x7cc2('0x5a')]):intUtil[_0x7cc2('0x59')](_0x2b332f['remoteUri']);_0x2b332f['serverUrl']=intUtil[_0x7cc2('0x59')](_0x2b332f[_0x7cc2('0x5b')]);_0x2464c8[_0x7cc2('0x4f')]=_0x3ca3b7==='queue'||_0x3ca3b7===_0x7cc2('0x5c')?_0x7cc2('0x4e'):_0x7cc2('0x2a');var _0x3e414b=_0x2b332f['modernAuthentication']?util['format'](_0x7cc2('0x5d'),_0x2b332f[_0x7cc2('0xd')][_0x7cc2('0x5a')]):util['format']('%s/api/data/v9.0/',_0x2b332f[_0x7cc2('0xc')]);var _0x42c58f=util['format'](_0x7cc2('0x5e'),_0x2b332f[_0x7cc2('0xe')]);var _0x5c4bd9=util[_0x7cc2('0x55')](_0x7cc2('0x5f'),_0x2b332f['serverUrl'],_0x1222ba[_0x7cc2('0x60')],md5(_0x1222ba[_0x7cc2('0x60')]));if(_0x203602&&_0x203602['monitor_format']){logger[_0x7cc2('0x23')]('[QUEUE]','Recording\x20is\x20enabled!');_0x1222ba[_0x7cc2('0x61')]=_0x5c4bd9;}else if(_0x36ed04&&_0x36ed04[_0x7cc2('0x62')]&&_0x36ed04[_0x7cc2('0x62')]!==_0x7cc2('0x63')){logger[_0x7cc2('0x23')]('[OUTBOUND]',_0x7cc2('0x64'));_0x1222ba[_0x7cc2('0x61')]=_0x5c4bd9;}else{_0x1222ba['recordingURL']='';}return getUser(_0x2464c8,_0x2b332f,_0x1b85d0,_0x42c58f,_0x3e414b,_0x3ca3b7)[_0x7cc2('0x13')](function(_0xc1020c){logger[_0x7cc2('0x23')]('['+_0x3ca3b7[_0x7cc2('0x17')]()+']\x20The\x20User\x20ID\x20is:',_0xc1020c[_0x7cc2('0x26')]);logger[_0x7cc2('0x23')]('['+_0x3ca3b7['toUpperCase']()+_0x7cc2('0x65'),_0xc1020c[_0x7cc2('0x1f')]);return getEndUser(_0xc1020c,_0x2b332f,_0x42c58f,_0x3e414b,_0x1222ba,_0x3ca3b7,_0xb852a7[_0x7cc2('0x66')],_0xb852a7[_0x7cc2('0x67')]);})[_0x7cc2('0x13')](function(_0x67f040){logger[_0x7cc2('0x23')]('['+_0x3ca3b7[_0x7cc2('0x17')]()+_0x7cc2('0x68'),_0x67f040[_0x7cc2('0x32')]);logger['info']('['+_0x3ca3b7[_0x7cc2('0x17')]()+']\x20The\x20Enduser\x20phone\x20is:',_0x1222ba[_0x7cc2('0x2c')]);return getTicket(_0x67f040,_0x2b332f,_0x42c58f,_0x3e414b,_0x1222ba,_0xb852a7,_0x3ca3b7);})[_0x7cc2('0x13')](function(_0x28a9c0){logger[_0x7cc2('0x23')](util['format']('['+_0x3ca3b7[_0x7cc2('0x17')]()+_0x7cc2('0x69'),_0xb852a7[_0x7cc2('0x46')],_0x28a9c0['ticketId']));logger['info'](util[_0x7cc2('0x55')]('['+_0x3ca3b7['toUpperCase']()+_0x7cc2('0x6a'),_0x3ca3b7));if(_0x3ca3b7!==_0x7cc2('0x5c')&&_0xb852a7[_0x7cc2('0x6b')]){logger[_0x7cc2('0x23')]('['+_0x3ca3b7['toUpperCase']()+']',_0x7cc2('0x6c'));emit(_0x2b332f[_0x7cc2('0xc')],_0x1b85d0[_0x7cc2('0x6d')],_0xb852a7[_0x7cc2('0x46')],_0x28a9c0[_0x7cc2('0x54')]);}})['catch'](function(_0x105e2e){logger['error']('['+_0x3ca3b7[_0x7cc2('0x17')]()+_0x7cc2('0x6e'),_0x105e2e['message']);console['error'](_0x7cc2('0x6f'),_0x105e2e);});};
\ No newline at end of file
+var _0xc6dd=['https://login.microsoftonline.com/%s/oauth2/token','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:','ticketId',']\x20Call\x20direction:\x20%s','openNewTab','name','catch',']\x20Error\x20running\x20Dynamics365\x20integration','lodash','request-promise','./util','ioredis','dynamics365','../../../../config/environment','redis','defaults','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','data7','tenantId','data2','data5','POST','username','password','then','error','toUpperCase',']\x20Wrong\x20credentials!','GET','Bearer\x20','isNil','validateEmail','email','userEmail','length','internalemailaddress',']\x20Agent\x20found\x20','userId','systemuserid',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','destcalleridnum','calleridnum','contacts','/systemusers(','4.0','headers','lastIndexOf','message','toLowerCase','contacts?$select=','&$filter=','replace','%2b','value','enduserId','info',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','string','customField','indexOf','substring','ticketType','incident','incidents','assign','getString','Descriptions','/contacts(','phonecall','queue','callDirection','Subjects','Fields','format','user:%s','emit','stripTrailingSlash','serverUrl','unmanaged','outbound','%s/api/data/v9.0/'];(function(_0x330fdc,_0x3fdba4){var _0x2edb38=function(_0x4f79e8){while(--_0x4f79e8){_0x330fdc['push'](_0x330fdc['shift']());}};_0x2edb38(++_0x3fdba4);}(_0xc6dd,0x18d));var _0xdc6d=function(_0xfd3034,_0x4ad7a9){_0xfd3034=_0xfd3034-0x0;var _0x8e0e16=_0xc6dd[_0xfd3034];return _0x8e0e16;};'use strict';var _=require(_0xdc6d('0x0'));var rp=require(_0xdc6d('0x1'));var util=require('util');var intUtil=require(_0xdc6d('0x2'));var md5=require('md5');var Redis=require(_0xdc6d('0x3'));var logger=require('../../../../config/logger')(_0xdc6d('0x4'));var config=require(_0xdc6d('0x5'));config[_0xdc6d('0x6')]=_[_0xdc6d('0x7')](config[_0xdc6d('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0xdc6d('0x8'))(new Redis(config[_0xdc6d('0x6')]));function getAuthToken(_0x2332e8,_0x4b8977,_0xd6723b){if(_0x2332e8[_0xdc6d('0x9')]){_0x2332e8[_0xdc6d('0xa')]=_0x2332e8[_0xdc6d('0xb')][_0xdc6d('0xc')];_0x2332e8[_0xdc6d('0xd')]=_0x2332e8[_0xdc6d('0xb')][_0xdc6d('0xe')];return Promise['resolve'](_0x2332e8[_0xdc6d('0xb')][_0xdc6d('0xf')]);}var _0x41115c={'method':_0xdc6d('0x10'),'uri':_0x4b8977,'form':{'client_id':_0x2332e8['clientId'],'resource':_0x2332e8[_0xdc6d('0xa')],'username':_0x2332e8[_0xdc6d('0x11')],'password':_0x2332e8[_0xdc6d('0x12')],'grant_type':_0xdc6d('0x12'),'client_secret':_0x2332e8['clientSecret']},'json':!![]};return rp(_0x41115c)[_0xdc6d('0x13')](function(_0x465fdd){return _0x465fdd['access_token'];})['catch'](function(_0x2537f5){logger[_0xdc6d('0x14')]('['+[_0xd6723b[_0xdc6d('0x15')]()]+_0xdc6d('0x16'));return _0x2537f5['message'];});}function getUser(_0x4d2b17,_0x3942cf,_0x237452,_0x4c6e5d,_0x4ed308,_0x2ba446){return new Promise(function(_0x2c9879,_0x5c77d3){return getAuthToken(_0x3942cf,_0x4c6e5d,_0x2ba446)[_0xdc6d('0x13')](function(_0x10ea65){var _0x5e1e08={'method':_0xdc6d('0x17'),'uri':_0x4ed308+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0xdc6d('0x18')+_0x10ea65,'OData-Version':'4.0'},'json':!![]};return rp(_0x5e1e08);})[_0xdc6d('0x13')](function(_0x3353c6){var _0x2ba602=_0x3353c6['value'];var _0x51f8c6=![];var _0x326691=null;if(!_[_0xdc6d('0x19')](_0x237452)){if(intUtil[_0xdc6d('0x1a')](_0x237452[_0xdc6d('0x1b')])){_0x4d2b17[_0xdc6d('0x1c')]=_0x237452[_0xdc6d('0x1b')];for(_0x326691=0x0;_0x326691<_0x2ba602[_0xdc6d('0x1d')];_0x326691++){if(_0x2ba602[_0x326691][_0xdc6d('0x1e')]===_0x237452[_0xdc6d('0x1b')]&&!_0x2ba602[_0x326691]['isdisabled']){_0x51f8c6=!![];logger['info']('['+[_0x2ba446[_0xdc6d('0x15')]()]+_0xdc6d('0x1f')+_0x2ba602[_0x326691]['systemuserid']+'!');_0x4d2b17[_0xdc6d('0x20')]=_0x2ba602[_0x326691][_0xdc6d('0x21')];}}}}if(!_0x51f8c6){logger['info']('['+[_0x2ba446['toUpperCase']()]+_0xdc6d('0x22'));_0x4d2b17[_0xdc6d('0x1c')]=_0x3942cf[_0xdc6d('0x11')];for(_0x326691=0x0;_0x326691<_0x2ba602[_0xdc6d('0x1d')];_0x326691++){if(_0x2ba602[_0x326691][_0xdc6d('0x1e')]===_0x3942cf[_0xdc6d('0x11')]){_0x4d2b17[_0xdc6d('0x20')]=_0x2ba602[_0x326691][_0xdc6d('0x21')];}}}_0x2c9879(_0x4d2b17);})['catch'](function(_0x3e0ce7){_0x5c77d3(_0x3e0ce7['message']);});});}function createEndUser(_0x35c5c9,_0x4a8596,_0x4d2e14,_0x3ec2cf,_0x5643b7,_0x2713b2,_0x4ddfe8){return new Promise(function(_0x46af59,_0x430ab8){return getAuthToken(_0x4a8596,_0x4d2e14,_0x2713b2)[_0xdc6d('0x13')](function(_0x13b5ac){var _0x3454eb=_0x2713b2['toLowerCase']()==='outbound'?_0x5643b7[_0xdc6d('0x23')]:_0x5643b7[_0xdc6d('0x24')];var _0x24017e={'method':_0xdc6d('0x10'),'uri':_0x3ec2cf+_0xdc6d('0x25'),'body':{'fullname':_0x3454eb,'firstname':_0x3454eb,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0xdc6d('0x26')+_0x35c5c9['userId']+')'},'headers':{'Authorization':_0xdc6d('0x18')+_0x13b5ac,'OData-Version':_0xdc6d('0x27')},'json':!![],'resolveWithFullResponse':!![]};_0x24017e['body'][_0x4ddfe8]=_0x3454eb;return rp(_0x24017e);})[_0xdc6d('0x13')](function(_0x185f70){var _0x1f5bcc=_0x185f70[_0xdc6d('0x28')]['odata-entityid'];var _0x206ec1=_0x1f5bcc['substring'](_0x1f5bcc[_0xdc6d('0x29')]('(')+0x1,_0x1f5bcc[_0xdc6d('0x29')](')'));_0x35c5c9['enduserId']=_0x206ec1;_0x46af59(_0x35c5c9);})['catch'](function(_0x1a6c8e){_0x430ab8(_0x1a6c8e[_0xdc6d('0x2a')]);});});}function getEndUser(_0x2357b3,_0x4153a5,_0x1e52fa,_0x21804e,_0x3ef1a4,_0x1bc518,_0x1650c2,_0x104937){var _0x4791e6=_0x1bc518[_0xdc6d('0x2b')]()==='outbound'?_0x3ef1a4['destcalleridnum']:_0x3ef1a4[_0xdc6d('0x24')];return getAuthToken(_0x4153a5,_0x1e52fa,_0x1bc518)['then'](function(_0xa23353){_0x104937=_0x104937?_0x104937:'telephone1';var _0x1f3b91={'method':_0xdc6d('0x17'),'uri':_0x21804e+_0xdc6d('0x2c')+_0x104937+_0xdc6d('0x2d')+_0x104937+'\x20eq\x20\x27'+_0x4791e6[_0xdc6d('0x2e')]('+',_0xdc6d('0x2f'))+'\x27','headers':{'Authorization':'Bearer\x20'+_0xa23353,'If-None-Match':null,'OData-Version':_0xdc6d('0x27')},'json':!![]};return rp(_0x1f3b91);})[_0xdc6d('0x13')](function(_0x311e5b){var _0x12fd64=![];if(!_0x311e5b)return _0x12fd64;var _0x388703=_0x311e5b[_0xdc6d('0x30')];for(var _0x43f176=0x0;_0x43f176<_0x388703[_0xdc6d('0x1d')];_0x43f176++){if(_0x388703[_0x43f176][_0x104937]===_0x4791e6){_0x12fd64=!![];_0x2357b3[_0xdc6d('0x31')]=_0x388703[_0x43f176]['contactid'];}}return _0x12fd64;})['then'](function(_0x1cf86f){if(_0x1cf86f)return _0x2357b3;if(_0x1650c2==='nothing'){logger[_0xdc6d('0x32')]('['+[_0x1bc518[_0xdc6d('0x15')]()]+_0xdc6d('0x33'));return _0x2357b3;}return createEndUser(_0x2357b3,_0x4153a5,_0x1e52fa,_0x21804e,_0x3ef1a4,_0x1bc518,_0x104937)['then'](function(_0x321a8b){logger['info']('['+[_0x1bc518['toUpperCase']()]+_0xdc6d('0x34'),_0x321a8b[_0xdc6d('0x31')]);return _0x321a8b;});});}function getCustomFields(_0x55ec79,_0x2aca83,_0x5604c3){var _0x38e5d3={};if(_0x55ec79['length']>0x0){_[_0xdc6d('0x35')](_0x55ec79,function(_0x580e4a){if(_['includes']([_0xdc6d('0x36'),'picklist'],_0x580e4a['type'])&&_0x580e4a['nameField']&&!_0x580e4a[_0xdc6d('0x37')]){var _0x1fa6b7=_0x580e4a['idField'][_0xdc6d('0x2b')]();var _0x1fe09a=_0x1fa6b7['substring'](0x0,_0x1fa6b7[_0xdc6d('0x38')]('_'));var _0x188fc7=_0x1fa6b7[_0xdc6d('0x39')](_0x1fa6b7[_0xdc6d('0x38')]('_')+0x1);if(_0x1fe09a===_0x5604c3){_0x38e5d3[_0x188fc7]=_0x580e4a['content'];}}});}return _0x38e5d3;}function getTicket(_0x124c22,_0x372a40,_0x14397c,_0x258cb8,_0x98781b,_0x5e5611,_0x34aa75){return new Promise(function(_0x575487,_0x3a6cc9){var _0x533e4e;return getAuthToken(_0x372a40,_0x14397c,_0x34aa75)[_0xdc6d('0x13')](function(_0x2fba57){if(_0x5e5611[_0xdc6d('0x3a')]===_0xdc6d('0x3b')){_0x533e4e={'method':_0xdc6d('0x10'),'uri':_0x258cb8+_0xdc6d('0x3c'),'body':Object[_0xdc6d('0x3d')]({},{'title':intUtil[_0xdc6d('0x3e')](_0x5e5611['Subjects'],_0x98781b,'\x20'),'description':intUtil[_0xdc6d('0x3e')](_0x5e5611[_0xdc6d('0x3f')],_0x98781b,'\x0a'),'customerid_contact@odata.bind':_0x124c22['enduserId']?_0xdc6d('0x40')+_0x124c22[_0xdc6d('0x31')]+')':undefined,'ownerid@odata.bind':_0xdc6d('0x26')+_0x124c22[_0xdc6d('0x20')]+')','caseorigincode':'1'},getCustomFields(_0x5e5611['Fields'],_0x98781b,_0x5e5611['ticketType'])),'headers':{'Authorization':_0xdc6d('0x18')+_0x2fba57,'OData-Version':_0xdc6d('0x27')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x5e5611[_0xdc6d('0x3a')]===_0xdc6d('0x41')){var _0x4dbae2=_0x124c22[_0xdc6d('0x31')]?[{'partyid_systemuser@odata.bind':'/systemusers('+_0x124c22[_0xdc6d('0x20')]+')','participationtypemask':_0x124c22['callDirection']===_0xdc6d('0x42')?0x2:0x1},{'partyid_contact@odata.bind':_0xdc6d('0x40')+_0x124c22[_0xdc6d('0x31')]+')','participationtypemask':_0x124c22[_0xdc6d('0x43')]===_0xdc6d('0x42')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0xdc6d('0x26')+_0x124c22[_0xdc6d('0x20')]+')','participationtypemask':_0x124c22[_0xdc6d('0x43')]===_0xdc6d('0x42')?0x2:0x1}];_0x533e4e={'method':_0xdc6d('0x10'),'uri':_0x258cb8+'phonecalls','body':Object[_0xdc6d('0x3d')]({},{'subject':intUtil[_0xdc6d('0x3e')](_0x5e5611[_0xdc6d('0x44')],_0x98781b,'\x20'),'phonenumber':String(_0x98781b[_0xdc6d('0x24')]),'description':intUtil['getString'](_0x5e5611[_0xdc6d('0x3f')],_0x98781b,'\x0a'),'regardingobjectid_contact@odata.bind':_0x124c22[_0xdc6d('0x31')]?_0xdc6d('0x40')+_0x124c22[_0xdc6d('0x31')]+')':undefined,'ownerid@odata.bind':_0xdc6d('0x26')+_0x124c22[_0xdc6d('0x20')]+')','directioncode':_0x124c22[_0xdc6d('0x43')]==='queue'?![]:!![],'phonecall_activity_parties':_0x4dbae2},getCustomFields(_0x5e5611[_0xdc6d('0x45')],_0x98781b,_0x5e5611[_0xdc6d('0x3a')])),'headers':{'Authorization':_0xdc6d('0x18')+_0x2fba57,'OData-Version':_0xdc6d('0x27')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x533e4e);})[_0xdc6d('0x13')](function(_0x106421){var _0x19e630=_0x106421[_0xdc6d('0x28')]['odata-entityid'];var _0x3e6831=_0x19e630[_0xdc6d('0x39')](_0x19e630[_0xdc6d('0x29')]('(')+0x1,_0x19e630['lastIndexOf'](')'));_0x124c22['ticketId']=_0x3e6831;_0x575487(_0x124c22);})['catch'](function(_0x9bc797){_0x3a6cc9(_0x9bc797['message']);});});}function emit(_0x3d58c0,_0x44699a,_0x1442b4,_0x4bd7c3){var _0x3b1f45={'uri':util[_0xdc6d('0x46')]('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x3d58c0,_0x1442b4,_0x4bd7c3)};io['to'](util[_0xdc6d('0x46')](_0xdc6d('0x47'),_0x44699a))[_0xdc6d('0x48')]('trigger:browser:url',_0x3b1f45);}exports['cs']=function(_0x240edc,_0x371022,_0x4146dd,_0x132b26,_0x505956,_0x376092,_0x476e58,_0x468d38){var _0x10a64b={};_0x376092[_0xdc6d('0xa')]=_0x376092[_0xdc6d('0x9')]?intUtil[_0xdc6d('0x49')](_0x376092[_0xdc6d('0xb')][_0xdc6d('0xc')]):intUtil[_0xdc6d('0x49')](_0x376092[_0xdc6d('0xa')]);_0x376092[_0xdc6d('0x4a')]=intUtil[_0xdc6d('0x49')](_0x376092[_0xdc6d('0x4a')]);_0x10a64b[_0xdc6d('0x43')]=_0x468d38==='queue'||_0x468d38===_0xdc6d('0x4b')?_0xdc6d('0x42'):_0xdc6d('0x4c');var _0x3739ca=_0x376092['modernAuthentication']?util[_0xdc6d('0x46')](_0xdc6d('0x4d'),_0x376092['CloudProvider'][_0xdc6d('0xc')]):util[_0xdc6d('0x46')](_0xdc6d('0x4d'),_0x376092[_0xdc6d('0xa')]);var _0x3e470d=util[_0xdc6d('0x46')](_0xdc6d('0x4e'),_0x376092[_0xdc6d('0xd')]);var _0x34c98d=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x376092[_0xdc6d('0x4a')],_0x371022[_0xdc6d('0x4f')],md5(_0x371022[_0xdc6d('0x4f')]));if(_0x505956&&_0x505956['monitor_format']){logger[_0xdc6d('0x32')](_0xdc6d('0x50'),_0xdc6d('0x51'));_0x371022[_0xdc6d('0x52')]=_0x34c98d;}else if(_0x476e58&&_0x476e58[_0xdc6d('0x53')]&&_0x476e58[_0xdc6d('0x53')]!=='none'){logger[_0xdc6d('0x32')](_0xdc6d('0x54'),_0xdc6d('0x51'));_0x371022[_0xdc6d('0x52')]=_0x34c98d;}else{_0x371022[_0xdc6d('0x52')]='';}return getUser(_0x10a64b,_0x376092,_0x132b26,_0x3e470d,_0x3739ca,_0x468d38)[_0xdc6d('0x13')](function(_0xccf166){logger[_0xdc6d('0x32')]('['+_0x468d38[_0xdc6d('0x15')]()+_0xdc6d('0x55'),_0xccf166[_0xdc6d('0x20')]);logger['info']('['+_0x468d38[_0xdc6d('0x15')]()+']\x20The\x20User\x20email\x20is:',_0xccf166['userEmail']);return getEndUser(_0xccf166,_0x376092,_0x3e470d,_0x3739ca,_0x371022,_0x468d38,_0x4146dd['moduleCreate'],_0x4146dd[_0xdc6d('0x56')]);})[_0xdc6d('0x13')](function(_0x1b7e76){logger[_0xdc6d('0x32')]('['+_0x468d38[_0xdc6d('0x15')]()+_0xdc6d('0x57'),_0x1b7e76['enduserId']);logger[_0xdc6d('0x32')]('['+_0x468d38['toUpperCase']()+_0xdc6d('0x58'),_0x371022[_0xdc6d('0x24')]);return getTicket(_0x1b7e76,_0x376092,_0x3e470d,_0x3739ca,_0x371022,_0x4146dd,_0x468d38);})['then'](function(_0x176ade){logger[_0xdc6d('0x32')](util[_0xdc6d('0x46')]('['+_0x468d38[_0xdc6d('0x15')]()+']\x20The\x20%s\x20ID\x20is:\x20%s',_0x4146dd[_0xdc6d('0x3a')],_0x176ade[_0xdc6d('0x59')]));logger['info'](util[_0xdc6d('0x46')]('['+_0x468d38['toUpperCase']()+_0xdc6d('0x5a'),_0x468d38));if(_0x468d38!=='unmanaged'&&_0x4146dd[_0xdc6d('0x5b')]){logger[_0xdc6d('0x32')]('['+_0x468d38[_0xdc6d('0x15')]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0x376092[_0xdc6d('0xa')],_0x132b26[_0xdc6d('0x5c')],_0x4146dd['ticketType'],_0x176ade[_0xdc6d('0x59')]);}})[_0xdc6d('0x5d')](function(_0x53dacb){logger[_0xdc6d('0x14')]('['+_0x468d38[_0xdc6d('0x15')]()+_0xdc6d('0x5e'),_0x53dacb[_0xdc6d('0x2a')]);console[_0xdc6d('0x14')]('Error\x20running\x20Dynamics365\x20integration',_0x53dacb);});};
\ No newline at end of file