Built motion from commit bfc7a72f7045b27461c9a5d1f71c1a658cfd0b8b. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / dynamics365.js
index 1d0b999..f5f8464 100644 (file)
@@ -1 +1 @@
-const a1137_0x28d0=['email','phonecalls','string','userEmail','customField','indexOf','nameField','Descriptions','phonecall','lodash',']\x20Enduser\x20created!','headers','request-promise-native','lastIndexOf','ticketType','value','systemuserid',']\x20The\x20User\x20email\x20is:','4.0','monitor_format',']\x20Wrong\x20credentials!','toLowerCase','serverUrl',']\x20Enduser\x20Created!','recordingFormat','isNil','util',']\x20Call\x20direction:\x20%s','catch','format','destcalleridnum','getString','incidents','/contacts(','GET','Fields','md5','password','error','recordingURL','Recording\x20is\x20enabled!','ticketId','userId','forEach','odata-entityid','then','info',']\x20Error\x20running\x20Dynamics365\x20integration','emit','contactid',']\x20The\x20User\x20ID\x20is:','./util','clientId','Displaying\x20call\x20in\x20a\x20new\x20tab...','name','uniqueid','substring',']\x20The\x20%s\x20ID\x20is:\x20%s','outbound','Subjects','toUpperCase','content',']\x20The\x20Enduser\x20ID\x20is:','callDirection','queue','telephone1','/systemusers(','remoteUri','calleridnum','Bearer\x20','length','[QUEUE]','contacts?$select=telephone1','message','unmanaged','isdisabled','assign','validateEmail','enduserId','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','type','tenantId','stripTrailingSlash','inspect','trigger:browser:url','internalemailaddress','POST'];(function(_0xe2a5df,_0x28d099){const _0x1c1782=function(_0x2f1aa8){while(--_0x2f1aa8){_0xe2a5df['push'](_0xe2a5df['shift']());}};_0x1c1782(++_0x28d099);}(a1137_0x28d0,0x131));const a1137_0x1c17=function(_0xe2a5df,_0x28d099){_0xe2a5df=_0xe2a5df-0x0;let _0x1c1782=a1137_0x28d0[_0xe2a5df];return _0x1c1782;};const _0x2a1224=a1137_0x1c17;'use strict';const _=require(_0x2a1224('0x34')),rp=require(_0x2a1224('0x37')),util=require(_0x2a1224('0x45')),intUtil=require(_0x2a1224('0x7')),md5=require(_0x2a1224('0x4f')),logger=require('../../../../config/logger')('dynamics365'),{getSocket}=require('../../../../rediscache'),io=getSocket();function getAuthToken(_0x2f1aa8,_0x1e7bfc,_0x15dbcc){const _0x14e998=_0x2a1224,_0x25e910={'method':_0x14e998('0x2a'),'uri':_0x1e7bfc,'form':{'client_id':_0x2f1aa8[_0x14e998('0x8')],'resource':_0x2f1aa8[_0x14e998('0x17')],'username':_0x2f1aa8['username'],'password':_0x2f1aa8[_0x14e998('0x50')],'grant_type':_0x14e998('0x50'),'client_secret':_0x2f1aa8['clientSecret']},'json':!![]};return rp(_0x25e910)[_0x14e998('0x1')](function(_0x469c80){return _0x469c80['access_token'];})[_0x14e998('0x47')](function(_0x1391ef){const _0x5ed065=_0x14e998;return logger[_0x5ed065('0x51')]('['+[_0x15dbcc[_0x5ed065('0x10')]()]+_0x5ed065('0x3f')),_0x1391ef[_0x5ed065('0x1d')];});}function getUser(_0x233e4d,_0x1271a1,_0x5c682e,_0x1efb3f,_0xf5ae3a,_0xae919e){return new Promise(function(_0x14de46,_0x3c3c32){const _0x39e3a5=a1137_0x1c17;return getAuthToken(_0x1271a1,_0x1efb3f,_0xae919e)[_0x39e3a5('0x1')](function(_0x3ed10b){const _0x21c540=_0x39e3a5,_0x277459={'method':_0x21c540('0x4d'),'uri':_0xf5ae3a+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0x21c540('0x19')+_0x3ed10b,'OData-Version':_0x21c540('0x3d')},'json':!![]};return rp(_0x277459);})[_0x39e3a5('0x1')](function(_0x1d4c71){const _0x2548c7=_0x39e3a5,_0x7e919e=_0x1d4c71[_0x2548c7('0x3a')];let _0x108ef5=![],_0x499901=null;if(!_[_0x2548c7('0x44')](_0x5c682e)){if(intUtil[_0x2548c7('0x21')](_0x5c682e[_0x2548c7('0x2b')])){_0x233e4d['userEmail']=_0x5c682e[_0x2548c7('0x2b')];for(_0x499901=0x0;_0x499901<_0x7e919e[_0x2548c7('0x1a')];_0x499901++){_0x7e919e[_0x499901][_0x2548c7('0x29')]===_0x5c682e[_0x2548c7('0x2b')]&&!_0x7e919e[_0x499901][_0x2548c7('0x1f')]&&(_0x108ef5=!![],logger[_0x2548c7('0x2')]('['+[_0xae919e[_0x2548c7('0x10')]()]+']\x20Agent\x20found\x20'+_0x7e919e[_0x499901]['systemuserid']+'!'),_0x233e4d[_0x2548c7('0x55')]=_0x7e919e[_0x499901][_0x2548c7('0x3b')]);}}}if(!_0x108ef5){logger[_0x2548c7('0x2')]('['+[_0xae919e[_0x2548c7('0x10')]()]+']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!'),_0x233e4d[_0x2548c7('0x2e')]=_0x1271a1['username'];for(_0x499901=0x0;_0x499901<_0x7e919e[_0x2548c7('0x1a')];_0x499901++){_0x7e919e[_0x499901]['internalemailaddress']===_0x1271a1['username']&&(_0x233e4d[_0x2548c7('0x55')]=_0x7e919e[_0x499901]['systemuserid']);}}_0x14de46(_0x233e4d);})[_0x39e3a5('0x47')](function(_0x3ee877){_0x3c3c32(_0x3ee877['message']);});});}function createEndUser(_0x2ada53,_0x513f4f,_0xa212b3,_0x62fbe7,_0x5a7db1,_0x4e35ad){return new Promise(function(_0x506b83,_0x4e1aff){const _0xd01552=a1137_0x1c17;return getAuthToken(_0x513f4f,_0xa212b3,_0x4e35ad)[_0xd01552('0x1')](function(_0x2513d4){const _0x2563ea=_0xd01552,_0x22b695=_0x4e35ad[_0x2563ea('0x40')]()==='outbound'?_0x5a7db1[_0x2563ea('0x49')]:_0x5a7db1[_0x2563ea('0x18')],_0x1003ce={'method':_0x2563ea('0x2a'),'uri':_0x62fbe7+'contacts','body':{'telephone1':_0x22b695,'fullname':_0x22b695,'firstname':_0x22b695,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x2ada53[_0x2563ea('0x55')]+')'},'headers':{'Authorization':_0x2563ea('0x19')+_0x2513d4,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x1003ce);})[_0xd01552('0x1')](function(_0x2adaa0){const _0xe445c8=_0xd01552,_0x16be95=_0x2adaa0['headers'][_0xe445c8('0x0')],_0x5bb853=_0x16be95[_0xe445c8('0xc')](_0x16be95[_0xe445c8('0x38')]('(')+0x1,_0x16be95[_0xe445c8('0x38')](')'));_0x2ada53[_0xe445c8('0x22')]=_0x5bb853,_0x506b83(_0x2ada53);})['catch'](function(_0x57f6a3){const _0x235e5d=_0xd01552;_0x4e1aff(_0x57f6a3[_0x235e5d('0x1d')]);});});}function getEndUser(_0xedd4cd,_0x4f096c,_0x2c646f,_0x272ba9,_0x25ec17,_0x3f7341){return new Promise(function(_0x2402b3){const _0x1f1d11=a1137_0x1c17;return getAuthToken(_0x4f096c,_0x2c646f,_0x3f7341)[_0x1f1d11('0x1')](function(_0x3a5f57){const _0x42eaf6=_0x1f1d11,_0x15cff6={'method':_0x42eaf6('0x4d'),'uri':_0x272ba9+_0x42eaf6('0x1c'),'headers':{'Authorization':_0x42eaf6('0x19')+_0x3a5f57,'If-None-Match':null,'OData-Version':_0x42eaf6('0x3d')},'json':!![]};return rp(_0x15cff6);})['then'](function(_0x46679c){const _0x221cc9=_0x1f1d11;let _0x44df5d=null;if(_0x46679c){const _0x2f4727=_0x46679c['value'];let _0x51ad68=![];for(_0x44df5d=0x0;_0x44df5d<_0x2f4727[_0x221cc9('0x1a')];_0x44df5d++){const _0x18a807=_0x3f7341['toLowerCase']()===_0x221cc9('0xe')?_0x25ec17[_0x221cc9('0x49')]:_0x25ec17['calleridnum'];_0x2f4727[_0x44df5d][_0x221cc9('0x15')]===_0x18a807&&(_0x51ad68=!![],_0xedd4cd['enduserId']=_0x2f4727[_0x44df5d][_0x221cc9('0x5')]);}if(_0x51ad68)_0x2402b3(_0xedd4cd);else return createEndUser(_0xedd4cd,_0x4f096c,_0x2c646f,_0x272ba9,_0x25ec17,_0x3f7341)[_0x221cc9('0x1')](function(_0x7ee97e){const _0xfd1101=_0x221cc9;logger['info']('['+[_0x3f7341[_0xfd1101('0x10')]()]+_0xfd1101('0x35'),_0x7ee97e[_0xfd1101('0x22')]),_0x2402b3(_0x7ee97e);});}else return createEndUser(_0xedd4cd,_0x4f096c,_0x2c646f,_0x272ba9,_0x25ec17,_0x3f7341)[_0x221cc9('0x1')](function(_0x519f0a){const _0x14ce71=_0x221cc9;logger['info']('['+[_0x3f7341[_0x14ce71('0x10')]()]+_0x14ce71('0x42'),_0x519f0a[_0x14ce71('0x22')]),_0x2402b3(_0x519f0a);});});});}function getCustomFields(_0x21eecd,_0x3bff3b,_0x1d9d4e){const _0x443b76=_0x2a1224,_0xcdd3cb={};return _0x21eecd[_0x443b76('0x1a')]>0x0&&_[_0x443b76('0x56')](_0x21eecd,function(_0xd1d87a){const _0x3cf80d=_0x443b76;if(_0xd1d87a[_0x3cf80d('0x24')]===_0x3cf80d('0x2d')&&_0xd1d87a[_0x3cf80d('0x31')]&&!_0xd1d87a[_0x3cf80d('0x2f')]){const _0x4c9845=_0xd1d87a['idField'][_0x3cf80d('0x40')](),_0x37a3b0=_0x4c9845[_0x3cf80d('0xc')](0x0,_0x4c9845[_0x3cf80d('0x30')]('_')),_0x58a54e=_0x4c9845[_0x3cf80d('0xc')](_0x4c9845[_0x3cf80d('0x30')]('_')+0x1);_0x37a3b0===_0x1d9d4e&&(_0xcdd3cb[_0x58a54e]=_0xd1d87a[_0x3cf80d('0x11')]);}}),_0xcdd3cb;}function getTicket(_0x1c7aea,_0x43e2b8,_0x30577f,_0x53eab4,_0x108baa,_0x315eba,_0x3786a7){return new Promise(function(_0x1b89a0,_0x50f9f1){const _0x3d5222=a1137_0x1c17;let _0x3b03a0;return getAuthToken(_0x43e2b8,_0x30577f,_0x3786a7)[_0x3d5222('0x1')](function(_0x1ceae2){const _0x56f93e=_0x3d5222;return _0x315eba[_0x56f93e('0x39')]==='incident'&&(_0x3b03a0={'method':_0x56f93e('0x2a'),'uri':_0x53eab4+_0x56f93e('0x4b'),'body':Object['assign']({},{'title':intUtil[_0x56f93e('0x4a')](_0x315eba['Subjects'],_0x108baa,'\x20'),'description':intUtil[_0x56f93e('0x4a')](_0x315eba['Descriptions'],_0x108baa,'\x0a'),'customerid_contact@odata.bind':_0x56f93e('0x4c')+_0x1c7aea['enduserId']+')','ownerid@odata.bind':_0x56f93e('0x16')+_0x1c7aea[_0x56f93e('0x55')]+')','caseorigincode':'1'},getCustomFields(_0x315eba[_0x56f93e('0x4e')],_0x108baa,_0x315eba[_0x56f93e('0x39')])),'headers':{'Authorization':'Bearer\x20'+_0x1ceae2,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]}),_0x315eba[_0x56f93e('0x39')]===_0x56f93e('0x33')&&(_0x3b03a0={'method':_0x56f93e('0x2a'),'uri':_0x53eab4+_0x56f93e('0x2c'),'body':Object[_0x56f93e('0x20')]({},{'subject':intUtil['getString'](_0x315eba[_0x56f93e('0xf')],_0x108baa,'\x20'),'phonenumber':String(_0x108baa[_0x56f93e('0x18')]),'description':intUtil[_0x56f93e('0x4a')](_0x315eba[_0x56f93e('0x32')],_0x108baa,'\x0a'),'regardingobjectid_contact@odata.bind':_0x56f93e('0x4c')+_0x1c7aea[_0x56f93e('0x22')]+')','ownerid@odata.bind':_0x56f93e('0x16')+_0x1c7aea[_0x56f93e('0x55')]+')','directioncode':_0x1c7aea[_0x56f93e('0x13')]===_0x56f93e('0x14')?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':'/systemusers('+_0x1c7aea[_0x56f93e('0x55')]+')','participationtypemask':_0x1c7aea[_0x56f93e('0x13')]===_0x56f93e('0x14')?0x2:0x1},{'partyid_contact@odata.bind':_0x56f93e('0x4c')+_0x1c7aea['enduserId']+')','participationtypemask':_0x1c7aea['callDirection']==='queue'?0x1:0x2}]},getCustomFields(_0x315eba[_0x56f93e('0x4e')],_0x108baa,_0x315eba['ticketType'])),'headers':{'Authorization':_0x56f93e('0x19')+_0x1ceae2,'OData-Version':_0x56f93e('0x3d')},'json':!![],'resolveWithFullResponse':!![]}),rp(_0x3b03a0);})[_0x3d5222('0x1')](function(_0x3cd0ee){const _0x3a4681=_0x3d5222,_0x339324=_0x3cd0ee[_0x3a4681('0x36')][_0x3a4681('0x0')],_0x34d24e=_0x339324[_0x3a4681('0xc')](_0x339324[_0x3a4681('0x38')]('(')+0x1,_0x339324['lastIndexOf'](')'));_0x1c7aea[_0x3a4681('0x54')]=_0x34d24e,_0x1b89a0(_0x1c7aea);})[_0x3d5222('0x47')](function(_0x2c148d){const _0x5826f7=_0x3d5222;_0x50f9f1(_0x2c148d[_0x5826f7('0x1d')]);});});}function emit(_0x3906c0,_0x550360,_0x1c9486,_0x795317){const _0x5a3bb5=_0x2a1224,_0xa9e9b0={'uri':util[_0x5a3bb5('0x48')](_0x5a3bb5('0x23'),_0x3906c0,_0x1c9486,_0x795317)};io['to'](util[_0x5a3bb5('0x48')]('user:%s',_0x550360))[_0x5a3bb5('0x4')](_0x5a3bb5('0x28'),_0xa9e9b0);}exports['cs']=function(_0x5d628e,_0x49daa1,_0x239235,_0x553d15,_0x599c98,_0x19636e,_0x196de6,_0x25e8d1){const _0x24e6c6=_0x2a1224,_0xc9275d={};_0x19636e['remoteUri']=intUtil['stripTrailingSlash'](_0x19636e[_0x24e6c6('0x17')]),_0x19636e[_0x24e6c6('0x41')]=intUtil[_0x24e6c6('0x26')](_0x19636e[_0x24e6c6('0x41')]),_0xc9275d['callDirection']=_0x25e8d1===_0x24e6c6('0x14')||_0x25e8d1===_0x24e6c6('0x1e')?_0x24e6c6('0x14'):'outbound';const _0x4ae5c4=util[_0x24e6c6('0x48')]('%s/api/data/v9.0/',_0x19636e[_0x24e6c6('0x17')]),_0x3de4e3=util[_0x24e6c6('0x48')]('https://login.microsoftonline.com/%s/oauth2/token',_0x19636e[_0x24e6c6('0x25')]),_0x4b315f=util[_0x24e6c6('0x48')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x19636e[_0x24e6c6('0x41')],_0x49daa1[_0x24e6c6('0xb')],md5(_0x49daa1[_0x24e6c6('0xb')]));if(_0x599c98&&_0x599c98[_0x24e6c6('0x3e')])logger[_0x24e6c6('0x2')](_0x24e6c6('0x1b'),_0x24e6c6('0x53')),_0x49daa1[_0x24e6c6('0x52')]=_0x4b315f;else _0x196de6&&_0x196de6[_0x24e6c6('0x43')]&&_0x196de6[_0x24e6c6('0x43')]!=='none'?(logger[_0x24e6c6('0x2')]('[OUTBOUND]','Recording\x20is\x20enabled!'),_0x49daa1[_0x24e6c6('0x52')]=_0x4b315f):_0x49daa1[_0x24e6c6('0x52')]='';return getUser(_0xc9275d,_0x19636e,_0x553d15,_0x3de4e3,_0x4ae5c4,_0x25e8d1)['then'](function(_0x5eeab4){const _0x52abdd=_0x24e6c6;return logger[_0x52abdd('0x2')]('['+_0x25e8d1[_0x52abdd('0x10')]()+_0x52abdd('0x6'),_0x5eeab4[_0x52abdd('0x55')]),logger[_0x52abdd('0x2')]('['+_0x25e8d1[_0x52abdd('0x10')]()+_0x52abdd('0x3c'),_0x5eeab4[_0x52abdd('0x2e')]),getEndUser(_0x5eeab4,_0x19636e,_0x3de4e3,_0x4ae5c4,_0x49daa1,_0x25e8d1);})[_0x24e6c6('0x1')](function(_0x5f44a3){const _0x4fc7c7=_0x24e6c6;return logger[_0x4fc7c7('0x2')]('['+_0x25e8d1[_0x4fc7c7('0x10')]()+_0x4fc7c7('0x12'),_0x5f44a3['enduserId']),logger[_0x4fc7c7('0x2')]('['+_0x25e8d1['toUpperCase']()+']\x20The\x20Enduser\x20phone\x20is:',_0x49daa1[_0x4fc7c7('0x18')]),getTicket(_0x5f44a3,_0x19636e,_0x3de4e3,_0x4ae5c4,_0x49daa1,_0x239235,_0x25e8d1);})[_0x24e6c6('0x1')](function(_0x241cf2){const _0x178019=_0x24e6c6;logger[_0x178019('0x2')](util['format']('['+_0x25e8d1['toUpperCase']()+_0x178019('0xd'),_0x239235[_0x178019('0x39')],_0x241cf2['ticketId'])),logger['info'](util[_0x178019('0x48')]('['+_0x25e8d1[_0x178019('0x10')]()+_0x178019('0x46'),_0x25e8d1)),_0x25e8d1!==_0x178019('0x1e')&&(logger[_0x178019('0x2')]('['+_0x25e8d1[_0x178019('0x10')]()+']',_0x178019('0x9')),emit(_0x19636e[_0x178019('0x17')],_0x553d15[_0x178019('0xa')],_0x239235[_0x178019('0x39')],_0x241cf2[_0x178019('0x54')]));})[_0x24e6c6('0x47')](function(_0x413e08){const _0x5f3de9=_0x24e6c6;logger[_0x5f3de9('0x51')]('['+_0x25e8d1['toUpperCase']()+_0x5f3de9('0x3'),util[_0x5f3de9('0x27')](_0x413e08,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+const a1137_0x4481=['recordingURL','serverUrl','ticketType','outbound','/contacts(',']\x20Agent\x20found\x20',']\x20The\x20Enduser\x20phone\x20is:','queue',']\x20The\x20User\x20email\x20is:','type','%s/api/data/v9.0/','contacts?$select=telephone1','customField','format','systemusers?$select=internalemailaddress,isdisabled,systemuserid','phonecalls','enduserId','nameField','catch','user:%s','lastIndexOf','Displaying\x20call\x20in\x20a\x20new\x20tab...','unmanaged','recordingFormat','contacts','substring','Descriptions','length','Bearer\x20','destcalleridnum','request-promise-native',']\x20The\x20User\x20ID\x20is:','[OUTBOUND]',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','incident',']\x20The\x20%s\x20ID\x20is:\x20%s','phonecall','toUpperCase','then','validateEmail','password','POST','./util','ticketId','getString','isdisabled','headers','clientId','/systemusers(','access_token','calleridnum','inspect','email','monitor_format','none',']\x20Wrong\x20credentials!','string','remoteUri','message','internalemailaddress','userEmail','odata-entityid','callDirection','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','value','GET','tenantId','indexOf','[QUEUE]','../../../../config/logger','Subjects','assign',']\x20Error\x20running\x20Dynamics365\x20integration','emit',']\x20The\x20Enduser\x20ID\x20is:','info','systemuserid','4.0','md5','util','stripTrailingSlash','error','username','userId','isNil','toLowerCase'];(function(_0x5071c3,_0x448116){const _0x3fcc65=function(_0x17d6e1){while(--_0x17d6e1){_0x5071c3['push'](_0x5071c3['shift']());}};_0x3fcc65(++_0x448116);}(a1137_0x4481,0x145));const a1137_0x3fcc=function(_0x5071c3,_0x448116){_0x5071c3=_0x5071c3-0x0;let _0x3fcc65=a1137_0x4481[_0x5071c3];return _0x3fcc65;};const _0x4d917d=a1137_0x3fcc;'use strict';const _=require('lodash'),rp=require(_0x4d917d('0x31')),util=require(_0x4d917d('0xc')),intUtil=require(_0x4d917d('0x3d')),md5=require(_0x4d917d('0xb')),logger=require(_0x4d917d('0x2'))('dynamics365'),{getSocket}=require('../../../../rediscache'),io=getSocket();function getAuthToken(_0x17d6e1,_0x36efeb,_0x45ecd7){const _0x56891e=_0x4d917d,_0x3fc73c={'method':_0x56891e('0x3c'),'uri':_0x36efeb,'form':{'client_id':_0x17d6e1[_0x56891e('0x42')],'resource':_0x17d6e1[_0x56891e('0x4c')],'username':_0x17d6e1[_0x56891e('0xf')],'password':_0x17d6e1[_0x56891e('0x3b')],'grant_type':_0x56891e('0x3b'),'client_secret':_0x17d6e1['clientSecret']},'json':!![]};return rp(_0x3fc73c)['then'](function(_0x45e4ee){const _0x288ca0=_0x56891e;return _0x45e4ee[_0x288ca0('0x44')];})['catch'](function(_0x10bcb5){const _0x30b239=_0x56891e;return logger[_0x30b239('0xe')]('['+[_0x45ecd7[_0x30b239('0x38')]()]+_0x30b239('0x4a')),_0x10bcb5[_0x30b239('0x4d')];});}function getUser(_0x162336,_0x25ca52,_0xdf593f,_0x2f2554,_0x6a886c,_0x5a9665){return new Promise(function(_0x4b5942,_0x595b61){const _0x5f5500=a1137_0x3fcc;return getAuthToken(_0x25ca52,_0x2f2554,_0x5a9665)['then'](function(_0x99c792){const _0x27c352=a1137_0x3fcc,_0x19a4ff={'method':_0x27c352('0x54'),'uri':_0x6a886c+_0x27c352('0x21'),'headers':{'Authorization':'Bearer\x20'+_0x99c792,'OData-Version':'4.0'},'json':!![]};return rp(_0x19a4ff);})[_0x5f5500('0x39')](function(_0x4800e0){const _0x3399e3=_0x5f5500,_0x2cde71=_0x4800e0[_0x3399e3('0x53')];let _0xe196a9=![],_0x217ec4=null;if(!_[_0x3399e3('0x11')](_0xdf593f)){if(intUtil[_0x3399e3('0x3a')](_0xdf593f['email'])){_0x162336[_0x3399e3('0x4f')]=_0xdf593f[_0x3399e3('0x47')];for(_0x217ec4=0x0;_0x217ec4<_0x2cde71[_0x3399e3('0x2e')];_0x217ec4++){_0x2cde71[_0x217ec4]['internalemailaddress']===_0xdf593f['email']&&!_0x2cde71[_0x217ec4][_0x3399e3('0x40')]&&(_0xe196a9=!![],logger[_0x3399e3('0x8')]('['+[_0x5a9665[_0x3399e3('0x38')]()]+_0x3399e3('0x18')+_0x2cde71[_0x217ec4][_0x3399e3('0x9')]+'!'),_0x162336[_0x3399e3('0x10')]=_0x2cde71[_0x217ec4]['systemuserid']);}}}if(!_0xe196a9){logger[_0x3399e3('0x8')]('['+[_0x5a9665['toUpperCase']()]+_0x3399e3('0x34')),_0x162336[_0x3399e3('0x4f')]=_0x25ca52[_0x3399e3('0xf')];for(_0x217ec4=0x0;_0x217ec4<_0x2cde71[_0x3399e3('0x2e')];_0x217ec4++){_0x2cde71[_0x217ec4][_0x3399e3('0x4e')]===_0x25ca52[_0x3399e3('0xf')]&&(_0x162336[_0x3399e3('0x10')]=_0x2cde71[_0x217ec4][_0x3399e3('0x9')]);}}_0x4b5942(_0x162336);})[_0x5f5500('0x25')](function(_0x104a82){const _0x2d0047=_0x5f5500;_0x595b61(_0x104a82[_0x2d0047('0x4d')]);});});}function createEndUser(_0x45406d,_0x18f197,_0xa1f98e,_0x46fba9,_0x56fca9,_0x146a47){return new Promise(function(_0x49ef50,_0x888662){const _0x3c9669=a1137_0x3fcc;return getAuthToken(_0x18f197,_0xa1f98e,_0x146a47)[_0x3c9669('0x39')](function(_0x5bbda1){const _0x2d96d5=_0x3c9669,_0x1f4707=_0x146a47[_0x2d96d5('0x12')]()===_0x2d96d5('0x16')?_0x56fca9[_0x2d96d5('0x30')]:_0x56fca9['calleridnum'],_0xabed41={'method':'POST','uri':_0x46fba9+_0x2d96d5('0x2b'),'body':{'telephone1':_0x1f4707,'fullname':_0x1f4707,'firstname':_0x1f4707,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x2d96d5('0x43')+_0x45406d[_0x2d96d5('0x10')]+')'},'headers':{'Authorization':_0x2d96d5('0x2f')+_0x5bbda1,'OData-Version':_0x2d96d5('0xa')},'json':!![],'resolveWithFullResponse':!![]};return rp(_0xabed41);})[_0x3c9669('0x39')](function(_0x53af9b){const _0x103f77=_0x3c9669,_0x56e455=_0x53af9b[_0x103f77('0x41')][_0x103f77('0x50')],_0x5cfddc=_0x56e455[_0x103f77('0x2c')](_0x56e455[_0x103f77('0x27')]('(')+0x1,_0x56e455['lastIndexOf'](')'));_0x45406d[_0x103f77('0x23')]=_0x5cfddc,_0x49ef50(_0x45406d);})['catch'](function(_0x2c5ad3){const _0x238f84=_0x3c9669;_0x888662(_0x2c5ad3[_0x238f84('0x4d')]);});});}function getEndUser(_0xf488f,_0x1ce76e,_0x22783a,_0x548053,_0x15b2ec,_0x309d92){return new Promise(function(_0x516b8a){const _0x319725=a1137_0x3fcc;return getAuthToken(_0x1ce76e,_0x22783a,_0x309d92)[_0x319725('0x39')](function(_0x4f1c1f){const _0x3ca94c=_0x319725,_0x3cb0b3={'method':'GET','uri':_0x548053+_0x3ca94c('0x1e'),'headers':{'Authorization':_0x3ca94c('0x2f')+_0x4f1c1f,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x3cb0b3);})['then'](function(_0x594d49){const _0x54d87c=_0x319725;let _0x322232=null;if(_0x594d49){const _0x2a455c=_0x594d49[_0x54d87c('0x53')];let _0x25a990=![];for(_0x322232=0x0;_0x322232<_0x2a455c[_0x54d87c('0x2e')];_0x322232++){const _0x1f883f=_0x309d92[_0x54d87c('0x12')]()===_0x54d87c('0x16')?_0x15b2ec[_0x54d87c('0x30')]:_0x15b2ec[_0x54d87c('0x45')];_0x2a455c[_0x322232]['telephone1']===_0x1f883f&&(_0x25a990=!![],_0xf488f[_0x54d87c('0x23')]=_0x2a455c[_0x322232]['contactid']);}if(_0x25a990)_0x516b8a(_0xf488f);else return createEndUser(_0xf488f,_0x1ce76e,_0x22783a,_0x548053,_0x15b2ec,_0x309d92)[_0x54d87c('0x39')](function(_0x916527){const _0x2ba3c4=_0x54d87c;logger[_0x2ba3c4('0x8')]('['+[_0x309d92['toUpperCase']()]+']\x20Enduser\x20created!',_0x916527[_0x2ba3c4('0x23')]),_0x516b8a(_0x916527);});}else return createEndUser(_0xf488f,_0x1ce76e,_0x22783a,_0x548053,_0x15b2ec,_0x309d92)[_0x54d87c('0x39')](function(_0x305895){const _0x7123dc=_0x54d87c;logger[_0x7123dc('0x8')]('['+[_0x309d92[_0x7123dc('0x38')]()]+']\x20Enduser\x20Created!',_0x305895[_0x7123dc('0x23')]),_0x516b8a(_0x305895);});});});}function getCustomFields(_0x97da7d,_0x89950a,_0x448e2a){const _0x2fab10=_0x4d917d,_0x2a17bc={};return _0x97da7d[_0x2fab10('0x2e')]>0x0&&_['forEach'](_0x97da7d,function(_0x397afd){const _0x2512e6=_0x2fab10;if(_0x397afd[_0x2512e6('0x1c')]===_0x2512e6('0x4b')&&_0x397afd[_0x2512e6('0x24')]&&!_0x397afd[_0x2512e6('0x1f')]){const _0x1a5cea=_0x397afd['idField'][_0x2512e6('0x12')](),_0x52dc58=_0x1a5cea[_0x2512e6('0x2c')](0x0,_0x1a5cea[_0x2512e6('0x0')]('_')),_0x173a29=_0x1a5cea[_0x2512e6('0x2c')](_0x1a5cea[_0x2512e6('0x0')]('_')+0x1);_0x52dc58===_0x448e2a&&(_0x2a17bc[_0x173a29]=_0x397afd['content']);}}),_0x2a17bc;}function getTicket(_0x3be755,_0x360bdb,_0x184384,_0x3a3de7,_0x1711f3,_0x1b3fcc,_0x48b38c){return new Promise(function(_0x20a191,_0x330b1b){const _0x25188f=a1137_0x3fcc;let _0x397543;return getAuthToken(_0x360bdb,_0x184384,_0x48b38c)['then'](function(_0x246bfc){const _0x772f9e=a1137_0x3fcc;return _0x1b3fcc['ticketType']===_0x772f9e('0x35')&&(_0x397543={'method':_0x772f9e('0x3c'),'uri':_0x3a3de7+'incidents','body':Object['assign']({},{'title':intUtil[_0x772f9e('0x3f')](_0x1b3fcc[_0x772f9e('0x3')],_0x1711f3,'\x20'),'description':intUtil['getString'](_0x1b3fcc[_0x772f9e('0x2d')],_0x1711f3,'\x0a'),'customerid_contact@odata.bind':_0x772f9e('0x17')+_0x3be755[_0x772f9e('0x23')]+')','ownerid@odata.bind':_0x772f9e('0x43')+_0x3be755['userId']+')','caseorigincode':'1'},getCustomFields(_0x1b3fcc['Fields'],_0x1711f3,_0x1b3fcc[_0x772f9e('0x15')])),'headers':{'Authorization':_0x772f9e('0x2f')+_0x246bfc,'OData-Version':_0x772f9e('0xa')},'json':!![],'resolveWithFullResponse':!![]}),_0x1b3fcc[_0x772f9e('0x15')]===_0x772f9e('0x37')&&(_0x397543={'method':_0x772f9e('0x3c'),'uri':_0x3a3de7+_0x772f9e('0x22'),'body':Object[_0x772f9e('0x4')]({},{'subject':intUtil[_0x772f9e('0x3f')](_0x1b3fcc[_0x772f9e('0x3')],_0x1711f3,'\x20'),'phonenumber':String(_0x1711f3[_0x772f9e('0x45')]),'description':intUtil[_0x772f9e('0x3f')](_0x1b3fcc[_0x772f9e('0x2d')],_0x1711f3,'\x0a'),'regardingobjectid_contact@odata.bind':'/contacts('+_0x3be755['enduserId']+')','ownerid@odata.bind':'/systemusers('+_0x3be755[_0x772f9e('0x10')]+')','directioncode':_0x3be755[_0x772f9e('0x51')]==='queue'?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':_0x772f9e('0x43')+_0x3be755[_0x772f9e('0x10')]+')','participationtypemask':_0x3be755[_0x772f9e('0x51')]===_0x772f9e('0x1a')?0x2:0x1},{'partyid_contact@odata.bind':_0x772f9e('0x17')+_0x3be755[_0x772f9e('0x23')]+')','participationtypemask':_0x3be755[_0x772f9e('0x51')]==='queue'?0x1:0x2}]},getCustomFields(_0x1b3fcc['Fields'],_0x1711f3,_0x1b3fcc['ticketType'])),'headers':{'Authorization':_0x772f9e('0x2f')+_0x246bfc,'OData-Version':_0x772f9e('0xa')},'json':!![],'resolveWithFullResponse':!![]}),rp(_0x397543);})[_0x25188f('0x39')](function(_0x3cb404){const _0x2c1b84=_0x25188f,_0xe56393=_0x3cb404['headers'][_0x2c1b84('0x50')],_0x587806=_0xe56393[_0x2c1b84('0x2c')](_0xe56393[_0x2c1b84('0x27')]('(')+0x1,_0xe56393[_0x2c1b84('0x27')](')'));_0x3be755[_0x2c1b84('0x3e')]=_0x587806,_0x20a191(_0x3be755);})[_0x25188f('0x25')](function(_0x20e409){const _0x2500ae=_0x25188f;_0x330b1b(_0x20e409[_0x2500ae('0x4d')]);});});}function emit(_0x542aab,_0x10e99a,_0x54e975,_0x1fa7a9){const _0x55776b=_0x4d917d,_0x50c387={'uri':util[_0x55776b('0x20')](_0x55776b('0x52'),_0x542aab,_0x54e975,_0x1fa7a9)};io['to'](util['format'](_0x55776b('0x26'),_0x10e99a))[_0x55776b('0x6')]('trigger:browser:url',_0x50c387);}exports['cs']=function(_0x23fe6d,_0x2ba25f,_0x3aae32,_0x33a024,_0x1ddbc2,_0x390005,_0x3b1141,_0x1d7cba){const _0x35100e=_0x4d917d,_0x54c757={};_0x390005[_0x35100e('0x4c')]=intUtil[_0x35100e('0xd')](_0x390005[_0x35100e('0x4c')]),_0x390005[_0x35100e('0x14')]=intUtil[_0x35100e('0xd')](_0x390005[_0x35100e('0x14')]),_0x54c757[_0x35100e('0x51')]=_0x1d7cba===_0x35100e('0x1a')||_0x1d7cba===_0x35100e('0x29')?_0x35100e('0x1a'):'outbound';const _0x155294=util[_0x35100e('0x20')](_0x35100e('0x1d'),_0x390005[_0x35100e('0x4c')]),_0x1b951d=util[_0x35100e('0x20')]('https://login.microsoftonline.com/%s/oauth2/token',_0x390005[_0x35100e('0x55')]),_0x59dc1a=util[_0x35100e('0x20')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x390005[_0x35100e('0x14')],_0x2ba25f['uniqueid'],md5(_0x2ba25f['uniqueid']));if(_0x1ddbc2&&_0x1ddbc2[_0x35100e('0x48')])logger[_0x35100e('0x8')](_0x35100e('0x1'),'Recording\x20is\x20enabled!'),_0x2ba25f['recordingURL']=_0x59dc1a;else _0x3b1141&&_0x3b1141['recordingFormat']&&_0x3b1141[_0x35100e('0x2a')]!==_0x35100e('0x49')?(logger['info'](_0x35100e('0x33'),'Recording\x20is\x20enabled!'),_0x2ba25f[_0x35100e('0x13')]=_0x59dc1a):_0x2ba25f[_0x35100e('0x13')]='';return getUser(_0x54c757,_0x390005,_0x33a024,_0x1b951d,_0x155294,_0x1d7cba)['then'](function(_0x2288f4){const _0x55faf5=_0x35100e;return logger[_0x55faf5('0x8')]('['+_0x1d7cba['toUpperCase']()+_0x55faf5('0x32'),_0x2288f4['userId']),logger['info']('['+_0x1d7cba['toUpperCase']()+_0x55faf5('0x1b'),_0x2288f4[_0x55faf5('0x4f')]),getEndUser(_0x2288f4,_0x390005,_0x1b951d,_0x155294,_0x2ba25f,_0x1d7cba);})[_0x35100e('0x39')](function(_0x3427c8){const _0xbd71af=_0x35100e;return logger[_0xbd71af('0x8')]('['+_0x1d7cba[_0xbd71af('0x38')]()+_0xbd71af('0x7'),_0x3427c8[_0xbd71af('0x23')]),logger[_0xbd71af('0x8')]('['+_0x1d7cba[_0xbd71af('0x38')]()+_0xbd71af('0x19'),_0x2ba25f[_0xbd71af('0x45')]),getTicket(_0x3427c8,_0x390005,_0x1b951d,_0x155294,_0x2ba25f,_0x3aae32,_0x1d7cba);})[_0x35100e('0x39')](function(_0x42239d){const _0x1f09ec=_0x35100e;logger[_0x1f09ec('0x8')](util['format']('['+_0x1d7cba['toUpperCase']()+_0x1f09ec('0x36'),_0x3aae32[_0x1f09ec('0x15')],_0x42239d[_0x1f09ec('0x3e')])),logger[_0x1f09ec('0x8')](util[_0x1f09ec('0x20')]('['+_0x1d7cba[_0x1f09ec('0x38')]()+']\x20Call\x20direction:\x20%s',_0x1d7cba)),_0x1d7cba!==_0x1f09ec('0x29')&&(logger[_0x1f09ec('0x8')]('['+_0x1d7cba['toUpperCase']()+']',_0x1f09ec('0x28')),emit(_0x390005[_0x1f09ec('0x4c')],_0x33a024['name'],_0x3aae32['ticketType'],_0x42239d[_0x1f09ec('0x3e')]));})[_0x35100e('0x25')](function(_0x1c2717){const _0x4a8b2f=_0x35100e;logger[_0x4a8b2f('0xe')]('['+_0x1d7cba['toUpperCase']()+_0x4a8b2f('0x5'),util[_0x4a8b2f('0x46')](_0x1c2717,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file