Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index 8976166..39d356e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3537=[']\x20The\x20Enduser\x20phone\x20is:',']\x20Call\x20direction:\x20%s','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20Dynamics365\x20integration','error','Error\x20running\x20Dynamics365\x20integration','lodash','request-promise','util','ioredis','dynamics365','../../../../config/environment','redis','localhost','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','data2','data5','POST','clientId','username','password','clientSecret','then','access_token','toUpperCase','message','value','isNil','validateEmail','email','userEmail','length','isdisabled','info',']\x20Agent\x20found\x20','userId','systemuserid',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','catch','toLowerCase','outbound','destcalleridnum','calleridnum','contacts','4.0','headers','odata-entityid','substring','lastIndexOf','enduserId','telephone1','GET','contacts?$select=','\x20eq\x20\x27','replace','%2b','Bearer\x20','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','includes','string','picklist','type','customField','idField','indexOf','content','incidents','assign','getString','Subjects','Descriptions','/contacts(','/systemusers(','ticketType','callDirection','queue','phonecalls','Fields','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','emit','trigger:browser:url','data7','serverUrl','stripTrailingSlash','unmanaged','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','tenantId','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact'];(function(_0x22b8a3,_0x2a79a7){var _0x199a0c=function(_0x544c66){while(--_0x544c66){_0x22b8a3['push'](_0x22b8a3['shift']());}};_0x199a0c(++_0x2a79a7);}(_0x3537,0x75));var _0x7353=function(_0x2e4e19,_0x493b50){_0x2e4e19=_0x2e4e19-0x0;var _0x9ba20b=_0x3537[_0x2e4e19];return _0x9ba20b;};'use strict';var _=require(_0x7353('0x0'));var rp=require(_0x7353('0x1'));var util=require(_0x7353('0x2'));var intUtil=require('./util');var md5=require('md5');var Redis=require(_0x7353('0x3'));var logger=require('../../../../config/logger')(_0x7353('0x4'));var config=require(_0x7353('0x5'));config[_0x7353('0x6')]=_['defaults'](config[_0x7353('0x6')],{'host':_0x7353('0x7'),'port':0x18eb});var io=require(_0x7353('0x8'))(new Redis(config[_0x7353('0x6')]));function getAuthToken(_0x167859,_0x466dd9,_0xc8eefc){if(_0x167859[_0x7353('0x9')]){_0x167859[_0x7353('0xa')]=_0x167859[_0x7353('0xb')]['data7'];_0x167859['tenantId']=_0x167859[_0x7353('0xb')][_0x7353('0xc')];return Promise['resolve'](_0x167859['CloudProvider'][_0x7353('0xd')]);}var _0x4257dc={'method':_0x7353('0xe'),'uri':_0x466dd9,'form':{'client_id':_0x167859[_0x7353('0xf')],'resource':_0x167859['remoteUri'],'username':_0x167859[_0x7353('0x10')],'password':_0x167859[_0x7353('0x11')],'grant_type':'password','client_secret':_0x167859[_0x7353('0x12')]},'json':!![]};return rp(_0x4257dc)[_0x7353('0x13')](function(_0x55299a){return _0x55299a[_0x7353('0x14')];})['catch'](function(_0x23acbb){logger['error']('['+[_0xc8eefc[_0x7353('0x15')]()]+']\x20Wrong\x20credentials!');return _0x23acbb[_0x7353('0x16')];});}function getUser(_0x444dff,_0x403816,_0x1ec18a,_0x20e24f,_0x3ce059,_0xf97de4){return new Promise(function(_0x3d3ae0,_0x4d7e69){return getAuthToken(_0x403816,_0x20e24f,_0xf97de4)['then'](function(_0x23e242){var _0x20348d={'method':'GET','uri':_0x3ce059+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':'Bearer\x20'+_0x23e242,'OData-Version':'4.0'},'json':!![]};return rp(_0x20348d);})[_0x7353('0x13')](function(_0x25a3b9){var _0x4ef526=_0x25a3b9[_0x7353('0x17')];var _0x535c56=![];var _0x54338f=null;if(!_[_0x7353('0x18')](_0x1ec18a)){if(intUtil[_0x7353('0x19')](_0x1ec18a[_0x7353('0x1a')])){_0x444dff[_0x7353('0x1b')]=_0x1ec18a[_0x7353('0x1a')];for(_0x54338f=0x0;_0x54338f<_0x4ef526[_0x7353('0x1c')];_0x54338f++){if(_0x4ef526[_0x54338f]['internalemailaddress']===_0x1ec18a['email']&&!_0x4ef526[_0x54338f][_0x7353('0x1d')]){_0x535c56=!![];logger[_0x7353('0x1e')]('['+[_0xf97de4[_0x7353('0x15')]()]+_0x7353('0x1f')+_0x4ef526[_0x54338f]['systemuserid']+'!');_0x444dff[_0x7353('0x20')]=_0x4ef526[_0x54338f][_0x7353('0x21')];}}}}if(!_0x535c56){logger[_0x7353('0x1e')]('['+[_0xf97de4[_0x7353('0x15')]()]+_0x7353('0x22'));_0x444dff[_0x7353('0x1b')]=_0x403816[_0x7353('0x10')];for(_0x54338f=0x0;_0x54338f<_0x4ef526[_0x7353('0x1c')];_0x54338f++){if(_0x4ef526[_0x54338f]['internalemailaddress']===_0x403816[_0x7353('0x10')]){_0x444dff[_0x7353('0x20')]=_0x4ef526[_0x54338f][_0x7353('0x21')];}}}_0x3d3ae0(_0x444dff);})[_0x7353('0x23')](function(_0x4dcd7d){_0x4d7e69(_0x4dcd7d[_0x7353('0x16')]);});});}function createEndUser(_0x3c9d18,_0x2c356f,_0x5e883a,_0x35d928,_0x57fe39,_0x590958,_0x13e45c){return new Promise(function(_0x47d938,_0xb0fe86){return getAuthToken(_0x2c356f,_0x5e883a,_0x590958)['then'](function(_0x17c23f){var _0x5518a7=_0x590958[_0x7353('0x24')]()===_0x7353('0x25')?_0x57fe39[_0x7353('0x26')]:_0x57fe39[_0x7353('0x27')];var _0x30f9c5={'method':_0x7353('0xe'),'uri':_0x35d928+_0x7353('0x28'),'body':{'fullname':_0x5518a7,'firstname':_0x5518a7,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x3c9d18[_0x7353('0x20')]+')'},'headers':{'Authorization':'Bearer\x20'+_0x17c23f,'OData-Version':_0x7353('0x29')},'json':!![],'resolveWithFullResponse':!![]};_0x30f9c5['body'][_0x13e45c]=_0x5518a7;return rp(_0x30f9c5);})[_0x7353('0x13')](function(_0x5ad551){var _0x3d2066=_0x5ad551[_0x7353('0x2a')][_0x7353('0x2b')];var _0x13c59d=_0x3d2066[_0x7353('0x2c')](_0x3d2066['lastIndexOf']('(')+0x1,_0x3d2066[_0x7353('0x2d')](')'));_0x3c9d18[_0x7353('0x2e')]=_0x13c59d;_0x47d938(_0x3c9d18);})[_0x7353('0x23')](function(_0x3d12ce){_0xb0fe86(_0x3d12ce[_0x7353('0x16')]);});});}function getEndUser(_0x58915d,_0xb85a8,_0x4aa839,_0x5099cf,_0x53e66e,_0x1f77cd,_0x3da78e,_0x158622){var _0x4a68b0=_0x1f77cd[_0x7353('0x24')]()==='outbound'?_0x53e66e[_0x7353('0x26')]:_0x53e66e[_0x7353('0x27')];return getAuthToken(_0xb85a8,_0x4aa839,_0x1f77cd)[_0x7353('0x13')](function(_0x117bf0){_0x158622=_0x158622?_0x158622:_0x7353('0x2f');var _0x5cbf3f={'method':_0x7353('0x30'),'uri':_0x5099cf+_0x7353('0x31')+_0x158622+'&$filter='+_0x158622+_0x7353('0x32')+_0x4a68b0[_0x7353('0x33')]('+',_0x7353('0x34'))+'\x27','headers':{'Authorization':_0x7353('0x35')+_0x117bf0,'If-None-Match':null,'OData-Version':_0x7353('0x29')},'json':!![]};return rp(_0x5cbf3f);})['then'](function(_0x38633d){var _0x2a20cd=![];if(!_0x38633d)return _0x2a20cd;var _0x5a7e76=_0x38633d[_0x7353('0x17')];for(var _0x10de44=0x0;_0x10de44<_0x5a7e76[_0x7353('0x1c')];_0x10de44++){if(_0x5a7e76[_0x10de44][_0x158622]===_0x4a68b0){_0x2a20cd=!![];_0x58915d[_0x7353('0x2e')]=_0x5a7e76[_0x10de44]['contactid'];}}return _0x2a20cd;})[_0x7353('0x13')](function(_0x43cd54){if(_0x43cd54)return _0x58915d;if(_0x3da78e===_0x7353('0x36')){logger['info']('['+[_0x1f77cd[_0x7353('0x15')]()]+_0x7353('0x37'));return _0x58915d;}return createEndUser(_0x58915d,_0xb85a8,_0x4aa839,_0x5099cf,_0x53e66e,_0x1f77cd,_0x158622)[_0x7353('0x13')](function(_0x1924cc){logger[_0x7353('0x1e')]('['+[_0x1f77cd[_0x7353('0x15')]()]+_0x7353('0x38'),_0x1924cc[_0x7353('0x2e')]);return _0x1924cc;});});}function getCustomFields(_0xfe16c3,_0x5512fe,_0x5e7c31){var _0x255c25={};if(_0xfe16c3[_0x7353('0x1c')]>0x0){_[_0x7353('0x39')](_0xfe16c3,function(_0x56b815){if(_[_0x7353('0x3a')]([_0x7353('0x3b'),_0x7353('0x3c')],_0x56b815[_0x7353('0x3d')])&&_0x56b815['nameField']&&!_0x56b815[_0x7353('0x3e')]){var _0x102f00=_0x56b815[_0x7353('0x3f')][_0x7353('0x24')]();var _0x103d5c=_0x102f00[_0x7353('0x2c')](0x0,_0x102f00[_0x7353('0x40')]('_'));var _0x20e9c6=_0x102f00[_0x7353('0x2c')](_0x102f00[_0x7353('0x40')]('_')+0x1);if(_0x103d5c===_0x5e7c31){_0x255c25[_0x20e9c6]=_0x56b815[_0x7353('0x41')];}}});}return _0x255c25;}function getTicket(_0x388b35,_0x201525,_0x44550e,_0x5da3af,_0x188323,_0x28349f,_0xc7aa4){return new Promise(function(_0x2bfb61,_0xae02eb){var _0x3fdc1a;return getAuthToken(_0x201525,_0x44550e,_0xc7aa4)[_0x7353('0x13')](function(_0x3c353e){if(_0x28349f['ticketType']==='incident'){_0x3fdc1a={'method':_0x7353('0xe'),'uri':_0x5da3af+_0x7353('0x42'),'body':Object[_0x7353('0x43')]({},{'title':intUtil[_0x7353('0x44')](_0x28349f[_0x7353('0x45')],_0x188323,'\x20'),'description':intUtil[_0x7353('0x44')](_0x28349f[_0x7353('0x46')],_0x188323,'\x0a'),'customerid_contact@odata.bind':_0x388b35[_0x7353('0x2e')]?_0x7353('0x47')+_0x388b35[_0x7353('0x2e')]+')':undefined,'ownerid@odata.bind':_0x7353('0x48')+_0x388b35[_0x7353('0x20')]+')','caseorigincode':'1'},getCustomFields(_0x28349f['Fields'],_0x188323,_0x28349f[_0x7353('0x49')])),'headers':{'Authorization':_0x7353('0x35')+_0x3c353e,'OData-Version':_0x7353('0x29')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x28349f[_0x7353('0x49')]==='phonecall'){var _0x3f3c99=_0x388b35['enduserId']?[{'partyid_systemuser@odata.bind':'/systemusers('+_0x388b35[_0x7353('0x20')]+')','participationtypemask':_0x388b35[_0x7353('0x4a')]===_0x7353('0x4b')?0x2:0x1},{'partyid_contact@odata.bind':_0x7353('0x47')+_0x388b35[_0x7353('0x2e')]+')','participationtypemask':_0x388b35[_0x7353('0x4a')]===_0x7353('0x4b')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0x7353('0x48')+_0x388b35['userId']+')','participationtypemask':_0x388b35[_0x7353('0x4a')]===_0x7353('0x4b')?0x2:0x1}];_0x3fdc1a={'method':'POST','uri':_0x5da3af+_0x7353('0x4c'),'body':Object[_0x7353('0x43')]({},{'subject':intUtil[_0x7353('0x44')](_0x28349f['Subjects'],_0x188323,'\x20'),'phonenumber':String(_0x188323[_0x7353('0x27')]),'description':intUtil['getString'](_0x28349f[_0x7353('0x46')],_0x188323,'\x0a'),'regardingobjectid_contact@odata.bind':_0x388b35[_0x7353('0x2e')]?_0x7353('0x47')+_0x388b35[_0x7353('0x2e')]+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x388b35[_0x7353('0x20')]+')','directioncode':_0x388b35['callDirection']===_0x7353('0x4b')?![]:!![],'phonecall_activity_parties':_0x3f3c99},getCustomFields(_0x28349f[_0x7353('0x4d')],_0x188323,_0x28349f[_0x7353('0x49')])),'headers':{'Authorization':'Bearer\x20'+_0x3c353e,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x3fdc1a);})[_0x7353('0x13')](function(_0x32f599){var _0x29c8ca=_0x32f599[_0x7353('0x2a')][_0x7353('0x2b')];var _0x2f6947=_0x29c8ca[_0x7353('0x2c')](_0x29c8ca[_0x7353('0x2d')]('(')+0x1,_0x29c8ca['lastIndexOf'](')'));_0x388b35[_0x7353('0x4e')]=_0x2f6947;_0x2bfb61(_0x388b35);})['catch'](function(_0x170af7){_0xae02eb(_0x170af7[_0x7353('0x16')]);});});}function emit(_0x1edbb1,_0x2b685e,_0x4b2974,_0x2562b9){var _0x5cb40c={'uri':util[_0x7353('0x4f')](_0x7353('0x50'),_0x1edbb1,_0x4b2974,_0x2562b9)};io['to'](util[_0x7353('0x4f')](_0x7353('0x51'),_0x2b685e))[_0x7353('0x52')](_0x7353('0x53'),_0x5cb40c);}exports['cs']=function(_0x284855,_0x1d859d,_0x5ca5fd,_0x3f0a92,_0x3d9b1b,_0x460cfb,_0x171028,_0x278000){var _0x3b2ad0={};_0x460cfb[_0x7353('0xa')]=_0x460cfb[_0x7353('0x9')]?intUtil['stripTrailingSlash'](_0x460cfb['CloudProvider'][_0x7353('0x54')]):intUtil['stripTrailingSlash'](_0x460cfb[_0x7353('0xa')]);_0x460cfb[_0x7353('0x55')]=intUtil[_0x7353('0x56')](_0x460cfb[_0x7353('0x55')]);_0x3b2ad0[_0x7353('0x4a')]=_0x278000===_0x7353('0x4b')||_0x278000===_0x7353('0x57')?_0x7353('0x4b'):'outbound';var _0x5ebc54=_0x460cfb[_0x7353('0x9')]?util[_0x7353('0x4f')]('%s/api/data/v9.0/',_0x460cfb[_0x7353('0xb')]['data7']):util[_0x7353('0x4f')](_0x7353('0x58'),_0x460cfb[_0x7353('0xa')]);var _0x5c6e15=util[_0x7353('0x4f')](_0x7353('0x59'),_0x460cfb[_0x7353('0x5a')]);var _0x39c441=util[_0x7353('0x4f')](_0x7353('0x5b'),_0x460cfb['serverUrl'],_0x1d859d[_0x7353('0x5c')],md5(_0x1d859d[_0x7353('0x5c')]));if(_0x3d9b1b&&_0x3d9b1b['monitor_format']){logger['info'](_0x7353('0x5d'),_0x7353('0x5e'));_0x1d859d[_0x7353('0x5f')]=_0x39c441;}else if(_0x171028&&_0x171028[_0x7353('0x60')]&&_0x171028[_0x7353('0x60')]!==_0x7353('0x61')){logger[_0x7353('0x1e')](_0x7353('0x62'),'Recording\x20is\x20enabled!');_0x1d859d[_0x7353('0x5f')]=_0x39c441;}else{_0x1d859d[_0x7353('0x5f')]='';}return getUser(_0x3b2ad0,_0x460cfb,_0x3f0a92,_0x5c6e15,_0x5ebc54,_0x278000)[_0x7353('0x13')](function(_0x1cd02a){logger['info']('['+_0x278000[_0x7353('0x15')]()+_0x7353('0x63'),_0x1cd02a[_0x7353('0x20')]);logger['info']('['+_0x278000[_0x7353('0x15')]()+_0x7353('0x64'),_0x1cd02a['userEmail']);return getEndUser(_0x1cd02a,_0x460cfb,_0x5c6e15,_0x5ebc54,_0x1d859d,_0x278000,_0x5ca5fd[_0x7353('0x65')],_0x5ca5fd[_0x7353('0x66')]);})[_0x7353('0x13')](function(_0x18dc3f){logger[_0x7353('0x1e')]('['+_0x278000[_0x7353('0x15')]()+']\x20The\x20Enduser\x20ID\x20is:',_0x18dc3f[_0x7353('0x2e')]);logger[_0x7353('0x1e')]('['+_0x278000[_0x7353('0x15')]()+_0x7353('0x67'),_0x1d859d[_0x7353('0x27')]);return getTicket(_0x18dc3f,_0x460cfb,_0x5c6e15,_0x5ebc54,_0x1d859d,_0x5ca5fd,_0x278000);})['then'](function(_0x3748c7){logger['info'](util[_0x7353('0x4f')]('['+_0x278000[_0x7353('0x15')]()+']\x20The\x20%s\x20ID\x20is:\x20%s',_0x5ca5fd['ticketType'],_0x3748c7[_0x7353('0x4e')]));logger['info'](util[_0x7353('0x4f')]('['+_0x278000[_0x7353('0x15')]()+_0x7353('0x68'),_0x278000));if(_0x278000!==_0x7353('0x57')&&_0x5ca5fd[_0x7353('0x69')]){logger['info']('['+_0x278000[_0x7353('0x15')]()+']',_0x7353('0x6a'));emit(_0x460cfb[_0x7353('0xa')],_0x3f0a92['name'],_0x5ca5fd[_0x7353('0x49')],_0x3748c7[_0x7353('0x4e')]);}})[_0x7353('0x23')](function(_0x54fa45){logger['error']('['+_0x278000['toUpperCase']()+_0x7353('0x6b'),_0x54fa45[_0x7353('0x16')]);console[_0x7353('0x6c')](_0x7353('0x6d'),_0x54fa45);});};
\ No newline at end of file
+var _0xdcd1=['username','outbound','destcalleridnum','/systemusers(','body','odata-entityid','lastIndexOf','toLowerCase','calleridnum','telephone1','&$filter=','\x20eq\x20\x27','replace','%2b','value','enduserId','contactid','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','includes','type','nameField','idField','substring','indexOf','content','ticketType','incidents','getString','Subjects','Descriptions','/contacts(','Fields','phonecall','queue','callDirection','phonecalls','assign','headers','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','trigger:browser:url','serverUrl','stripTrailingSlash','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','none','recordingURL',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','unmanaged','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','name','lodash','request-promise','util','./util','md5','ioredis','../../../../config/logger','dynamics365','redis','localhost','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','data7','tenantId','data2','resolve','data5','POST','clientId','password','clientSecret','catch','error','toUpperCase','message','then','Bearer\x20','4.0','isNil','validateEmail','email','userEmail','length','internalemailaddress','isdisabled','info',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!'];(function(_0x405ec7,_0x250c61){var _0xcee8c6=function(_0x274725){while(--_0x274725){_0x405ec7['push'](_0x405ec7['shift']());}};_0xcee8c6(++_0x250c61);}(_0xdcd1,0x11d));var _0x1dcd=function(_0x364077,_0x23c4bb){_0x364077=_0x364077-0x0;var _0x5eed17=_0xdcd1[_0x364077];return _0x5eed17;};'use strict';var _=require(_0x1dcd('0x0'));var rp=require(_0x1dcd('0x1'));var util=require(_0x1dcd('0x2'));var intUtil=require(_0x1dcd('0x3'));var md5=require(_0x1dcd('0x4'));var Redis=require(_0x1dcd('0x5'));var logger=require(_0x1dcd('0x6'))(_0x1dcd('0x7'));var config=require('../../../../config/environment');config[_0x1dcd('0x8')]=_['defaults'](config['redis'],{'host':_0x1dcd('0x9'),'port':0x18eb});var io=require(_0x1dcd('0xa'))(new Redis(config[_0x1dcd('0x8')]));function getAuthToken(_0x20ebb9,_0x41e089,_0x268d12){if(_0x20ebb9[_0x1dcd('0xb')]){_0x20ebb9[_0x1dcd('0xc')]=_0x20ebb9[_0x1dcd('0xd')][_0x1dcd('0xe')];_0x20ebb9[_0x1dcd('0xf')]=_0x20ebb9['CloudProvider'][_0x1dcd('0x10')];return Promise[_0x1dcd('0x11')](_0x20ebb9['CloudProvider'][_0x1dcd('0x12')]);}var _0x527209={'method':_0x1dcd('0x13'),'uri':_0x41e089,'form':{'client_id':_0x20ebb9[_0x1dcd('0x14')],'resource':_0x20ebb9[_0x1dcd('0xc')],'username':_0x20ebb9['username'],'password':_0x20ebb9[_0x1dcd('0x15')],'grant_type':'password','client_secret':_0x20ebb9[_0x1dcd('0x16')]},'json':!![]};return rp(_0x527209)['then'](function(_0x171795){return _0x171795['access_token'];})[_0x1dcd('0x17')](function(_0x1c54ca){logger[_0x1dcd('0x18')]('['+[_0x268d12[_0x1dcd('0x19')]()]+']\x20Wrong\x20credentials!');return _0x1c54ca[_0x1dcd('0x1a')];});}function getUser(_0x29abda,_0x327e1f,_0x441b2c,_0x3c04ee,_0x904cc1,_0x325602){return new Promise(function(_0x286fb1,_0x5e4fd3){return getAuthToken(_0x327e1f,_0x3c04ee,_0x325602)[_0x1dcd('0x1b')](function(_0x19649c){var _0x1820b4={'method':'GET','uri':_0x904cc1+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0x1dcd('0x1c')+_0x19649c,'OData-Version':_0x1dcd('0x1d')},'json':!![]};return rp(_0x1820b4);})[_0x1dcd('0x1b')](function(_0x54675d){var _0x31c31b=_0x54675d['value'];var _0x3d7a39=![];var _0xc88122=null;if(!_[_0x1dcd('0x1e')](_0x441b2c)){if(intUtil[_0x1dcd('0x1f')](_0x441b2c[_0x1dcd('0x20')])){_0x29abda[_0x1dcd('0x21')]=_0x441b2c['email'];for(_0xc88122=0x0;_0xc88122<_0x31c31b[_0x1dcd('0x22')];_0xc88122++){if(_0x31c31b[_0xc88122][_0x1dcd('0x23')]===_0x441b2c[_0x1dcd('0x20')]&&!_0x31c31b[_0xc88122][_0x1dcd('0x24')]){_0x3d7a39=!![];logger[_0x1dcd('0x25')]('['+[_0x325602[_0x1dcd('0x19')]()]+_0x1dcd('0x26')+_0x31c31b[_0xc88122][_0x1dcd('0x27')]+'!');_0x29abda[_0x1dcd('0x28')]=_0x31c31b[_0xc88122][_0x1dcd('0x27')];}}}}if(!_0x3d7a39){logger[_0x1dcd('0x25')]('['+[_0x325602[_0x1dcd('0x19')]()]+_0x1dcd('0x29'));_0x29abda['userEmail']=_0x327e1f[_0x1dcd('0x2a')];for(_0xc88122=0x0;_0xc88122<_0x31c31b[_0x1dcd('0x22')];_0xc88122++){if(_0x31c31b[_0xc88122][_0x1dcd('0x23')]===_0x327e1f[_0x1dcd('0x2a')]){_0x29abda['userId']=_0x31c31b[_0xc88122][_0x1dcd('0x27')];}}}_0x286fb1(_0x29abda);})['catch'](function(_0xf0287c){_0x5e4fd3(_0xf0287c[_0x1dcd('0x1a')]);});});}function createEndUser(_0x910f87,_0x4ab547,_0x1340f0,_0x4e9dcc,_0x48cbe1,_0x48038b,_0x232a14){return new Promise(function(_0x29b745,_0x5981a2){return getAuthToken(_0x4ab547,_0x1340f0,_0x48038b)['then'](function(_0x57b367){var _0xc9476c=_0x48038b['toLowerCase']()===_0x1dcd('0x2b')?_0x48cbe1[_0x1dcd('0x2c')]:_0x48cbe1['calleridnum'];var _0x35d4ea={'method':'POST','uri':_0x4e9dcc+'contacts','body':{'fullname':_0xc9476c,'firstname':_0xc9476c,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x1dcd('0x2d')+_0x910f87[_0x1dcd('0x28')]+')'},'headers':{'Authorization':'Bearer\x20'+_0x57b367,'OData-Version':_0x1dcd('0x1d')},'json':!![],'resolveWithFullResponse':!![]};_0x35d4ea[_0x1dcd('0x2e')][_0x232a14]=_0xc9476c;return rp(_0x35d4ea);})[_0x1dcd('0x1b')](function(_0x14a10d){var _0x5aeaba=_0x14a10d['headers'][_0x1dcd('0x2f')];var _0xbc4e94=_0x5aeaba['substring'](_0x5aeaba[_0x1dcd('0x30')]('(')+0x1,_0x5aeaba[_0x1dcd('0x30')](')'));_0x910f87['enduserId']=_0xbc4e94;_0x29b745(_0x910f87);})[_0x1dcd('0x17')](function(_0x4d7f1e){_0x5981a2(_0x4d7f1e[_0x1dcd('0x1a')]);});});}function getEndUser(_0x162ece,_0x236f02,_0xf4cc4c,_0x2bde11,_0x3cece0,_0x395487,_0x480275,_0x5112fc){var _0x49e8eb=_0x395487[_0x1dcd('0x31')]()===_0x1dcd('0x2b')?_0x3cece0[_0x1dcd('0x2c')]:_0x3cece0[_0x1dcd('0x32')];return getAuthToken(_0x236f02,_0xf4cc4c,_0x395487)[_0x1dcd('0x1b')](function(_0x10f3f6){_0x5112fc=_0x5112fc?_0x5112fc:_0x1dcd('0x33');var _0x399ced={'method':'GET','uri':_0x2bde11+'contacts?$select='+_0x5112fc+_0x1dcd('0x34')+_0x5112fc+_0x1dcd('0x35')+_0x49e8eb[_0x1dcd('0x36')]('+',_0x1dcd('0x37'))+'\x27','headers':{'Authorization':_0x1dcd('0x1c')+_0x10f3f6,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x399ced);})['then'](function(_0x30b422){var _0x56d5f7=![];if(!_0x30b422)return _0x56d5f7;var _0x14fd02=_0x30b422[_0x1dcd('0x38')];for(var _0x45df20=0x0;_0x45df20<_0x14fd02[_0x1dcd('0x22')];_0x45df20++){if(_0x14fd02[_0x45df20][_0x5112fc]===_0x49e8eb){_0x56d5f7=!![];_0x162ece[_0x1dcd('0x39')]=_0x14fd02[_0x45df20][_0x1dcd('0x3a')];}}return _0x56d5f7;})['then'](function(_0x145b16){if(_0x145b16)return _0x162ece;if(_0x480275===_0x1dcd('0x3b')){logger[_0x1dcd('0x25')]('['+[_0x395487[_0x1dcd('0x19')]()]+_0x1dcd('0x3c'));return _0x162ece;}return createEndUser(_0x162ece,_0x236f02,_0xf4cc4c,_0x2bde11,_0x3cece0,_0x395487,_0x5112fc)[_0x1dcd('0x1b')](function(_0x142646){logger[_0x1dcd('0x25')]('['+[_0x395487[_0x1dcd('0x19')]()]+_0x1dcd('0x3d'),_0x142646[_0x1dcd('0x39')]);return _0x142646;});});}function getCustomFields(_0x1eee15,_0x388d2f,_0x61940d){var _0x5cfb48={};if(_0x1eee15[_0x1dcd('0x22')]>0x0){_[_0x1dcd('0x3e')](_0x1eee15,function(_0x1fd619){if(_[_0x1dcd('0x3f')](['string','picklist'],_0x1fd619[_0x1dcd('0x40')])&&_0x1fd619[_0x1dcd('0x41')]&&!_0x1fd619['customField']){var _0x53f163=_0x1fd619[_0x1dcd('0x42')][_0x1dcd('0x31')]();var _0x1e08ba=_0x53f163[_0x1dcd('0x43')](0x0,_0x53f163[_0x1dcd('0x44')]('_'));var _0x55c728=_0x53f163[_0x1dcd('0x43')](_0x53f163[_0x1dcd('0x44')]('_')+0x1);if(_0x1e08ba===_0x61940d){_0x5cfb48[_0x55c728]=_0x1fd619[_0x1dcd('0x45')];}}});}return _0x5cfb48;}function getTicket(_0x18c55a,_0x160329,_0x1f50c1,_0x3cd0f8,_0x4b8387,_0x48f4fd,_0x147998){return new Promise(function(_0xb94821,_0x2cc199){var _0x2aa3b6;return getAuthToken(_0x160329,_0x1f50c1,_0x147998)['then'](function(_0x5d43ae){if(_0x48f4fd[_0x1dcd('0x46')]==='incident'){_0x2aa3b6={'method':_0x1dcd('0x13'),'uri':_0x3cd0f8+_0x1dcd('0x47'),'body':Object['assign']({},{'title':intUtil[_0x1dcd('0x48')](_0x48f4fd[_0x1dcd('0x49')],_0x4b8387,'\x20'),'description':intUtil[_0x1dcd('0x48')](_0x48f4fd[_0x1dcd('0x4a')],_0x4b8387,'\x0a'),'customerid_contact@odata.bind':_0x18c55a[_0x1dcd('0x39')]?_0x1dcd('0x4b')+_0x18c55a['enduserId']+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x18c55a[_0x1dcd('0x28')]+')','caseorigincode':'1'},getCustomFields(_0x48f4fd[_0x1dcd('0x4c')],_0x4b8387,_0x48f4fd[_0x1dcd('0x46')])),'headers':{'Authorization':_0x1dcd('0x1c')+_0x5d43ae,'OData-Version':_0x1dcd('0x1d')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x48f4fd[_0x1dcd('0x46')]===_0x1dcd('0x4d')){var _0x373a8a=_0x18c55a['enduserId']?[{'partyid_systemuser@odata.bind':_0x1dcd('0x2d')+_0x18c55a['userId']+')','participationtypemask':_0x18c55a['callDirection']===_0x1dcd('0x4e')?0x2:0x1},{'partyid_contact@odata.bind':'/contacts('+_0x18c55a[_0x1dcd('0x39')]+')','participationtypemask':_0x18c55a[_0x1dcd('0x4f')]==='queue'?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0x1dcd('0x2d')+_0x18c55a[_0x1dcd('0x28')]+')','participationtypemask':_0x18c55a[_0x1dcd('0x4f')]===_0x1dcd('0x4e')?0x2:0x1}];_0x2aa3b6={'method':_0x1dcd('0x13'),'uri':_0x3cd0f8+_0x1dcd('0x50'),'body':Object[_0x1dcd('0x51')]({},{'subject':intUtil[_0x1dcd('0x48')](_0x48f4fd[_0x1dcd('0x49')],_0x4b8387,'\x20'),'phonenumber':String(_0x4b8387[_0x1dcd('0x32')]),'description':intUtil[_0x1dcd('0x48')](_0x48f4fd[_0x1dcd('0x4a')],_0x4b8387,'\x0a'),'regardingobjectid_contact@odata.bind':_0x18c55a[_0x1dcd('0x39')]?_0x1dcd('0x4b')+_0x18c55a[_0x1dcd('0x39')]+')':undefined,'ownerid@odata.bind':_0x1dcd('0x2d')+_0x18c55a[_0x1dcd('0x28')]+')','directioncode':_0x18c55a['callDirection']==='queue'?![]:!![],'phonecall_activity_parties':_0x373a8a},getCustomFields(_0x48f4fd[_0x1dcd('0x4c')],_0x4b8387,_0x48f4fd[_0x1dcd('0x46')])),'headers':{'Authorization':_0x1dcd('0x1c')+_0x5d43ae,'OData-Version':_0x1dcd('0x1d')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x2aa3b6);})['then'](function(_0x4d1a68){var _0x1c8337=_0x4d1a68[_0x1dcd('0x52')][_0x1dcd('0x2f')];var _0x197efd=_0x1c8337[_0x1dcd('0x43')](_0x1c8337[_0x1dcd('0x30')]('(')+0x1,_0x1c8337['lastIndexOf'](')'));_0x18c55a[_0x1dcd('0x53')]=_0x197efd;_0xb94821(_0x18c55a);})[_0x1dcd('0x17')](function(_0x553f8a){_0x2cc199(_0x553f8a[_0x1dcd('0x1a')]);});});}function emit(_0x376554,_0x30a70c,_0x3f0c8a,_0x174cf5){var _0x56f3a9={'uri':util[_0x1dcd('0x54')](_0x1dcd('0x55'),_0x376554,_0x3f0c8a,_0x174cf5)};io['to'](util[_0x1dcd('0x54')](_0x1dcd('0x56'),_0x30a70c))['emit'](_0x1dcd('0x57'),_0x56f3a9);}exports['cs']=function(_0x289483,_0x31a700,_0x4bcd43,_0x5ef15f,_0x11a119,_0x1da327,_0x8fde97,_0x33da28){var _0x39e4ea={};_0x1da327[_0x1dcd('0xc')]=_0x1da327['modernAuthentication']?intUtil['stripTrailingSlash'](_0x1da327['CloudProvider'][_0x1dcd('0xe')]):intUtil['stripTrailingSlash'](_0x1da327['remoteUri']);_0x1da327[_0x1dcd('0x58')]=intUtil[_0x1dcd('0x59')](_0x1da327[_0x1dcd('0x58')]);_0x39e4ea['callDirection']=_0x33da28==='queue'||_0x33da28==='unmanaged'?_0x1dcd('0x4e'):_0x1dcd('0x2b');var _0x3349dd=_0x1da327['modernAuthentication']?util[_0x1dcd('0x54')](_0x1dcd('0x5a'),_0x1da327[_0x1dcd('0xd')]['data7']):util['format'](_0x1dcd('0x5a'),_0x1da327[_0x1dcd('0xc')]);var _0x540982=util['format'](_0x1dcd('0x5b'),_0x1da327['tenantId']);var _0x473774=util[_0x1dcd('0x54')](_0x1dcd('0x5c'),_0x1da327['serverUrl'],_0x31a700['uniqueid'],md5(_0x31a700[_0x1dcd('0x5d')]));if(_0x11a119&&_0x11a119[_0x1dcd('0x5e')]){logger['info'](_0x1dcd('0x5f'),_0x1dcd('0x60'));_0x31a700['recordingURL']=_0x473774;}else if(_0x8fde97&&_0x8fde97[_0x1dcd('0x61')]&&_0x8fde97['recordingFormat']!==_0x1dcd('0x62')){logger[_0x1dcd('0x25')]('[OUTBOUND]',_0x1dcd('0x60'));_0x31a700[_0x1dcd('0x63')]=_0x473774;}else{_0x31a700[_0x1dcd('0x63')]='';}return getUser(_0x39e4ea,_0x1da327,_0x5ef15f,_0x540982,_0x3349dd,_0x33da28)[_0x1dcd('0x1b')](function(_0x1cf29f){logger[_0x1dcd('0x25')]('['+_0x33da28['toUpperCase']()+']\x20The\x20User\x20ID\x20is:',_0x1cf29f[_0x1dcd('0x28')]);logger['info']('['+_0x33da28[_0x1dcd('0x19')]()+_0x1dcd('0x64'),_0x1cf29f['userEmail']);return getEndUser(_0x1cf29f,_0x1da327,_0x540982,_0x3349dd,_0x31a700,_0x33da28,_0x4bcd43[_0x1dcd('0x65')],_0x4bcd43[_0x1dcd('0x66')]);})[_0x1dcd('0x1b')](function(_0xb55403){logger['info']('['+_0x33da28[_0x1dcd('0x19')]()+']\x20The\x20Enduser\x20ID\x20is:',_0xb55403[_0x1dcd('0x39')]);logger['info']('['+_0x33da28['toUpperCase']()+']\x20The\x20Enduser\x20phone\x20is:',_0x31a700[_0x1dcd('0x32')]);return getTicket(_0xb55403,_0x1da327,_0x540982,_0x3349dd,_0x31a700,_0x4bcd43,_0x33da28);})[_0x1dcd('0x1b')](function(_0x3ddf91){logger[_0x1dcd('0x25')](util['format']('['+_0x33da28[_0x1dcd('0x19')]()+_0x1dcd('0x67'),_0x4bcd43[_0x1dcd('0x46')],_0x3ddf91[_0x1dcd('0x53')]));logger[_0x1dcd('0x25')](util['format']('['+_0x33da28[_0x1dcd('0x19')]()+_0x1dcd('0x68'),_0x33da28));if(_0x33da28!==_0x1dcd('0x69')&&_0x4bcd43[_0x1dcd('0x6a')]){logger[_0x1dcd('0x25')]('['+_0x33da28['toUpperCase']()+']',_0x1dcd('0x6b'));emit(_0x1da327[_0x1dcd('0xc')],_0x5ef15f[_0x1dcd('0x6c')],_0x4bcd43['ticketType'],_0x3ddf91['ticketId']);}})['catch'](function(_0x2d8889){logger['error']('['+_0x33da28[_0x1dcd('0x19')]()+']\x20Error\x20running\x20Dynamics365\x20integration',_0x2d8889[_0x1dcd('0x1a')]);console[_0x1dcd('0x18')]('Error\x20running\x20Dynamics365\x20integration',_0x2d8889);});};
\ No newline at end of file