Built motion from commit 980b26c3.|2.6.29
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index 86bccd0..6338257 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x04e6=['GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','isNil','validateEmail','email','length','internalemailaddress','isdisabled','info','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userEmail','toLowerCase','destcalleridnum','calleridnum','contacts','headers','lastIndexOf','enduserId','outbound','telephone1','contacts?$select=','\x20eq\x20\x27','replace','contactid','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','string','picklist','nameField','customField','indexOf','substring','content','ticketType','incident','assign','getString','Subjects','Descriptions','/contacts(','/systemusers(','Fields','queue','callDirection','phonecalls','odata-entityid','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','emit','trigger:browser:url','stripTrailingSlash','data7','serverUrl','unmanaged','%s/api/data/v9.0/','uniqueid','recordingURL','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!',']\x20The\x20User\x20ID\x20is:',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s','ticketId',']\x20Call\x20direction:\x20%s','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','error','Error\x20running\x20Dynamics365\x20integration','request-promise','util','./util','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','redis','defaults','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','tenantId','data2','resolve','data5','POST','clientId','username','clientSecret','access_token','catch','toUpperCase',']\x20Wrong\x20credentials!','message','then'];(function(_0x838b37,_0x43f2f0){var _0x161478=function(_0x2db472){while(--_0x2db472){_0x838b37['push'](_0x838b37['shift']());}};_0x161478(++_0x43f2f0);}(_0x04e6,0x195));var _0x604e=function(_0x5f1391,_0x19c132){_0x5f1391=_0x5f1391-0x0;var _0x50ebe3=_0x04e6[_0x5f1391];return _0x50ebe3;};'use strict';var _=require('lodash');var rp=require(_0x604e('0x0'));var util=require(_0x604e('0x1'));var intUtil=require(_0x604e('0x2'));var md5=require('md5');var Redis=require(_0x604e('0x3'));var logger=require(_0x604e('0x4'))(_0x604e('0x5'));var config=require(_0x604e('0x6'));config[_0x604e('0x7')]=_[_0x604e('0x8')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x604e('0x9'))(new Redis(config[_0x604e('0x7')]));function getAuthToken(_0x13adb2,_0x4d537a,_0x35e8e2){if(_0x13adb2[_0x604e('0xa')]){_0x13adb2[_0x604e('0xb')]=_0x13adb2[_0x604e('0xc')]['data7'];_0x13adb2[_0x604e('0xd')]=_0x13adb2['CloudProvider'][_0x604e('0xe')];return Promise[_0x604e('0xf')](_0x13adb2[_0x604e('0xc')][_0x604e('0x10')]);}var _0x455ccd={'method':_0x604e('0x11'),'uri':_0x4d537a,'form':{'client_id':_0x13adb2[_0x604e('0x12')],'resource':_0x13adb2[_0x604e('0xb')],'username':_0x13adb2[_0x604e('0x13')],'password':_0x13adb2['password'],'grant_type':'password','client_secret':_0x13adb2[_0x604e('0x14')]},'json':!![]};return rp(_0x455ccd)['then'](function(_0x29b2fa){return _0x29b2fa[_0x604e('0x15')];})[_0x604e('0x16')](function(_0x5de5dd){logger['error']('['+[_0x35e8e2[_0x604e('0x17')]()]+_0x604e('0x18'));return _0x5de5dd[_0x604e('0x19')];});}function getUser(_0x28061,_0x1745b5,_0x424ba8,_0x4759bd,_0x381345,_0x2ad029){return new Promise(function(_0x45885b,_0x59f743){return getAuthToken(_0x1745b5,_0x4759bd,_0x2ad029)[_0x604e('0x1a')](function(_0x4db76d){var _0x589c48={'method':_0x604e('0x1b'),'uri':_0x381345+_0x604e('0x1c'),'headers':{'Authorization':_0x604e('0x1d')+_0x4db76d,'OData-Version':_0x604e('0x1e')},'json':!![]};return rp(_0x589c48);})['then'](function(_0x2815ed){var _0x3fb9d7=_0x2815ed[_0x604e('0x1f')];var _0x569404=![];var _0x19e16e=null;if(!_[_0x604e('0x20')](_0x424ba8)){if(intUtil[_0x604e('0x21')](_0x424ba8[_0x604e('0x22')])){_0x28061['userEmail']=_0x424ba8['email'];for(_0x19e16e=0x0;_0x19e16e<_0x3fb9d7[_0x604e('0x23')];_0x19e16e++){if(_0x3fb9d7[_0x19e16e][_0x604e('0x24')]===_0x424ba8['email']&&!_0x3fb9d7[_0x19e16e][_0x604e('0x25')]){_0x569404=!![];logger[_0x604e('0x26')]('['+[_0x2ad029[_0x604e('0x17')]()]+']\x20Agent\x20found\x20'+_0x3fb9d7[_0x19e16e][_0x604e('0x27')]+'!');_0x28061[_0x604e('0x28')]=_0x3fb9d7[_0x19e16e][_0x604e('0x27')];}}}}if(!_0x569404){logger[_0x604e('0x26')]('['+[_0x2ad029[_0x604e('0x17')]()]+_0x604e('0x29'));_0x28061[_0x604e('0x2a')]=_0x1745b5[_0x604e('0x13')];for(_0x19e16e=0x0;_0x19e16e<_0x3fb9d7[_0x604e('0x23')];_0x19e16e++){if(_0x3fb9d7[_0x19e16e]['internalemailaddress']===_0x1745b5[_0x604e('0x13')]){_0x28061['userId']=_0x3fb9d7[_0x19e16e][_0x604e('0x27')];}}}_0x45885b(_0x28061);})[_0x604e('0x16')](function(_0x55e6cd){_0x59f743(_0x55e6cd[_0x604e('0x19')]);});});}function createEndUser(_0x4302f7,_0x50e5e1,_0x3b36fe,_0x3fcc5c,_0x29f643,_0x152c0c,_0x494d8a){return new Promise(function(_0xd03b51,_0x26471e){return getAuthToken(_0x50e5e1,_0x3b36fe,_0x152c0c)[_0x604e('0x1a')](function(_0x518972){var _0x2d79ed=_0x152c0c[_0x604e('0x2b')]()==='outbound'?_0x29f643[_0x604e('0x2c')]:_0x29f643[_0x604e('0x2d')];var _0x249acd={'method':_0x604e('0x11'),'uri':_0x3fcc5c+_0x604e('0x2e'),'body':{'fullname':_0x2d79ed,'firstname':_0x2d79ed,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x4302f7[_0x604e('0x28')]+')'},'headers':{'Authorization':_0x604e('0x1d')+_0x518972,'OData-Version':_0x604e('0x1e')},'json':!![],'resolveWithFullResponse':!![]};_0x249acd['body'][_0x494d8a]=_0x2d79ed;return rp(_0x249acd);})[_0x604e('0x1a')](function(_0x661aca){var _0x33afb8=_0x661aca[_0x604e('0x2f')]['odata-entityid'];var _0x1a165f=_0x33afb8['substring'](_0x33afb8[_0x604e('0x30')]('(')+0x1,_0x33afb8[_0x604e('0x30')](')'));_0x4302f7[_0x604e('0x31')]=_0x1a165f;_0xd03b51(_0x4302f7);})[_0x604e('0x16')](function(_0x19fb52){_0x26471e(_0x19fb52['message']);});});}function getEndUser(_0x3229b1,_0x3d1c71,_0x3ec5a2,_0x465216,_0x52750f,_0x1e3127,_0x875fb,_0xbed913){var _0x358163=_0x1e3127[_0x604e('0x2b')]()===_0x604e('0x32')?_0x52750f[_0x604e('0x2c')]:_0x52750f[_0x604e('0x2d')];return getAuthToken(_0x3d1c71,_0x3ec5a2,_0x1e3127)[_0x604e('0x1a')](function(_0x4401cc){_0xbed913=_0xbed913?_0xbed913:_0x604e('0x33');var _0x11c1ff={'method':'GET','uri':_0x465216+_0x604e('0x34')+_0xbed913+'&$filter='+_0xbed913+_0x604e('0x35')+_0x358163[_0x604e('0x36')]('+','%2b')+'\x27','headers':{'Authorization':_0x604e('0x1d')+_0x4401cc,'If-None-Match':null,'OData-Version':_0x604e('0x1e')},'json':!![]};return rp(_0x11c1ff);})[_0x604e('0x1a')](function(_0x5bb3c3){var _0x1b7fd5=![];if(!_0x5bb3c3)return _0x1b7fd5;var _0x3f1283=_0x5bb3c3[_0x604e('0x1f')];for(var _0x241aaa=0x0;_0x241aaa<_0x3f1283[_0x604e('0x23')];_0x241aaa++){if(_0x3f1283[_0x241aaa][_0xbed913]===_0x358163){_0x1b7fd5=!![];_0x3229b1[_0x604e('0x31')]=_0x3f1283[_0x241aaa][_0x604e('0x37')];}}return _0x1b7fd5;})['then'](function(_0xbff5b9){if(_0xbff5b9)return _0x3229b1;if(_0x875fb===_0x604e('0x38')){logger['info']('['+[_0x1e3127['toUpperCase']()]+_0x604e('0x39'));return _0x3229b1;}return createEndUser(_0x3229b1,_0x3d1c71,_0x3ec5a2,_0x465216,_0x52750f,_0x1e3127,_0xbed913)[_0x604e('0x1a')](function(_0x1701de){logger['info']('['+[_0x1e3127[_0x604e('0x17')]()]+_0x604e('0x3a'),_0x1701de['enduserId']);return _0x1701de;});});}function getCustomFields(_0x2dc414,_0x46d1ab,_0x1709e3){var _0x3785e9={};if(_0x2dc414[_0x604e('0x23')]>0x0){_[_0x604e('0x3b')](_0x2dc414,function(_0x1d2311){if(_['includes']([_0x604e('0x3c'),_0x604e('0x3d')],_0x1d2311['type'])&&_0x1d2311[_0x604e('0x3e')]&&!_0x1d2311[_0x604e('0x3f')]){var _0x3b1b71=_0x1d2311['idField']['toLowerCase']();var _0x12e915=_0x3b1b71['substring'](0x0,_0x3b1b71[_0x604e('0x40')]('_'));var _0x3faa86=_0x3b1b71[_0x604e('0x41')](_0x3b1b71[_0x604e('0x40')]('_')+0x1);if(_0x12e915===_0x1709e3){_0x3785e9[_0x3faa86]=_0x1d2311[_0x604e('0x42')];}}});}return _0x3785e9;}function getTicket(_0x2d138f,_0x4c5109,_0x2a78f,_0x16784e,_0x310b2b,_0x56defa,_0x1e2413){return new Promise(function(_0x4f60cd,_0x4ff1b3){var _0x27dd56;return getAuthToken(_0x4c5109,_0x2a78f,_0x1e2413)[_0x604e('0x1a')](function(_0xa0fb2b){if(_0x56defa[_0x604e('0x43')]===_0x604e('0x44')){_0x27dd56={'method':_0x604e('0x11'),'uri':_0x16784e+'incidents','body':Object[_0x604e('0x45')]({},{'title':intUtil[_0x604e('0x46')](_0x56defa[_0x604e('0x47')],_0x310b2b,'\x20'),'description':intUtil['getString'](_0x56defa[_0x604e('0x48')],_0x310b2b,'\x0a'),'customerid_contact@odata.bind':_0x2d138f[_0x604e('0x31')]?_0x604e('0x49')+_0x2d138f[_0x604e('0x31')]+')':undefined,'ownerid@odata.bind':_0x604e('0x4a')+_0x2d138f[_0x604e('0x28')]+')','caseorigincode':'1'},getCustomFields(_0x56defa[_0x604e('0x4b')],_0x310b2b,_0x56defa[_0x604e('0x43')])),'headers':{'Authorization':_0x604e('0x1d')+_0xa0fb2b,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}if(_0x56defa[_0x604e('0x43')]==='phonecall'){var _0x26a79b=_0x2d138f[_0x604e('0x31')]?[{'partyid_systemuser@odata.bind':_0x604e('0x4a')+_0x2d138f['userId']+')','participationtypemask':_0x2d138f['callDirection']===_0x604e('0x4c')?0x2:0x1},{'partyid_contact@odata.bind':_0x604e('0x49')+_0x2d138f[_0x604e('0x31')]+')','participationtypemask':_0x2d138f[_0x604e('0x4d')]===_0x604e('0x4c')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0x604e('0x4a')+_0x2d138f[_0x604e('0x28')]+')','participationtypemask':_0x2d138f[_0x604e('0x4d')]===_0x604e('0x4c')?0x2:0x1}];_0x27dd56={'method':_0x604e('0x11'),'uri':_0x16784e+_0x604e('0x4e'),'body':Object[_0x604e('0x45')]({},{'subject':intUtil[_0x604e('0x46')](_0x56defa[_0x604e('0x47')],_0x310b2b,'\x20'),'phonenumber':String(_0x310b2b['calleridnum']),'description':intUtil[_0x604e('0x46')](_0x56defa['Descriptions'],_0x310b2b,'\x0a'),'regardingobjectid_contact@odata.bind':_0x2d138f[_0x604e('0x31')]?'/contacts('+_0x2d138f['enduserId']+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x2d138f[_0x604e('0x28')]+')','directioncode':_0x2d138f[_0x604e('0x4d')]===_0x604e('0x4c')?![]:!![],'phonecall_activity_parties':_0x26a79b},getCustomFields(_0x56defa['Fields'],_0x310b2b,_0x56defa[_0x604e('0x43')])),'headers':{'Authorization':_0x604e('0x1d')+_0xa0fb2b,'OData-Version':_0x604e('0x1e')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x27dd56);})[_0x604e('0x1a')](function(_0x28b9e0){var _0x6c4567=_0x28b9e0['headers'][_0x604e('0x4f')];var _0x31fe8d=_0x6c4567['substring'](_0x6c4567[_0x604e('0x30')]('(')+0x1,_0x6c4567['lastIndexOf'](')'));_0x2d138f['ticketId']=_0x31fe8d;_0x4f60cd(_0x2d138f);})[_0x604e('0x16')](function(_0x36624d){_0x4ff1b3(_0x36624d[_0x604e('0x19')]);});});}function emit(_0xe96845,_0x27aa0e,_0x49b0f4,_0x539b02){var _0xff677e={'uri':util[_0x604e('0x50')](_0x604e('0x51'),_0xe96845,_0x49b0f4,_0x539b02)};io['to'](util['format'](_0x604e('0x52'),_0x27aa0e))[_0x604e('0x53')](_0x604e('0x54'),_0xff677e);}exports['cs']=function(_0x7e39a7,_0xcb72f,_0x4d6956,_0x1162ad,_0x1c1ef3,_0x2b14d0,_0x25e142,_0x13d759){var _0x4caeef={};_0x2b14d0[_0x604e('0xb')]=_0x2b14d0[_0x604e('0xa')]?intUtil[_0x604e('0x55')](_0x2b14d0[_0x604e('0xc')][_0x604e('0x56')]):intUtil[_0x604e('0x55')](_0x2b14d0['remoteUri']);_0x2b14d0[_0x604e('0x57')]=intUtil[_0x604e('0x55')](_0x2b14d0['serverUrl']);_0x4caeef[_0x604e('0x4d')]=_0x13d759===_0x604e('0x4c')||_0x13d759===_0x604e('0x58')?_0x604e('0x4c'):_0x604e('0x32');var _0x4037d8=_0x2b14d0['modernAuthentication']?util[_0x604e('0x50')](_0x604e('0x59'),_0x2b14d0[_0x604e('0xc')][_0x604e('0x56')]):util[_0x604e('0x50')](_0x604e('0x59'),_0x2b14d0[_0x604e('0xb')]);var _0x305827=util[_0x604e('0x50')]('https://login.microsoftonline.com/%s/oauth2/token',_0x2b14d0[_0x604e('0xd')]);var _0x174414=util[_0x604e('0x50')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2b14d0[_0x604e('0x57')],_0xcb72f[_0x604e('0x5a')],md5(_0xcb72f[_0x604e('0x5a')]));if(_0x1c1ef3&&_0x1c1ef3['monitor_format']){logger[_0x604e('0x26')]('[QUEUE]','Recording\x20is\x20enabled!');_0xcb72f[_0x604e('0x5b')]=_0x174414;}else if(_0x25e142&&_0x25e142[_0x604e('0x5c')]&&_0x25e142[_0x604e('0x5c')]!==_0x604e('0x5d')){logger[_0x604e('0x26')](_0x604e('0x5e'),_0x604e('0x5f'));_0xcb72f[_0x604e('0x5b')]=_0x174414;}else{_0xcb72f[_0x604e('0x5b')]='';}return getUser(_0x4caeef,_0x2b14d0,_0x1162ad,_0x305827,_0x4037d8,_0x13d759)[_0x604e('0x1a')](function(_0x1815a7){logger[_0x604e('0x26')]('['+_0x13d759[_0x604e('0x17')]()+_0x604e('0x60'),_0x1815a7[_0x604e('0x28')]);logger[_0x604e('0x26')]('['+_0x13d759[_0x604e('0x17')]()+_0x604e('0x61'),_0x1815a7[_0x604e('0x2a')]);return getEndUser(_0x1815a7,_0x2b14d0,_0x305827,_0x4037d8,_0xcb72f,_0x13d759,_0x4d6956[_0x604e('0x62')],_0x4d6956[_0x604e('0x63')]);})[_0x604e('0x1a')](function(_0x4dd266){logger[_0x604e('0x26')]('['+_0x13d759['toUpperCase']()+']\x20The\x20Enduser\x20ID\x20is:',_0x4dd266[_0x604e('0x31')]);logger[_0x604e('0x26')]('['+_0x13d759[_0x604e('0x17')]()+_0x604e('0x64'),_0xcb72f[_0x604e('0x2d')]);return getTicket(_0x4dd266,_0x2b14d0,_0x305827,_0x4037d8,_0xcb72f,_0x4d6956,_0x13d759);})[_0x604e('0x1a')](function(_0x7a42a3){logger['info'](util[_0x604e('0x50')]('['+_0x13d759[_0x604e('0x17')]()+_0x604e('0x65'),_0x4d6956[_0x604e('0x43')],_0x7a42a3[_0x604e('0x66')]));logger[_0x604e('0x26')](util[_0x604e('0x50')]('['+_0x13d759[_0x604e('0x17')]()+_0x604e('0x67'),_0x13d759));if(_0x13d759!==_0x604e('0x58')&&_0x4d6956[_0x604e('0x68')]){logger[_0x604e('0x26')]('['+_0x13d759[_0x604e('0x17')]()+']',_0x604e('0x69'));emit(_0x2b14d0[_0x604e('0xb')],_0x1162ad['name'],_0x4d6956[_0x604e('0x43')],_0x7a42a3['ticketId']);}})[_0x604e('0x16')](function(_0x4f79ed){logger[_0x604e('0x6a')]('['+_0x13d759[_0x604e('0x17')]()+']\x20Error\x20running\x20Dynamics365\x20integration',_0x4f79ed[_0x604e('0x19')]);console['error'](_0x604e('0x6b'),_0x4f79ed);});};
\ No newline at end of file
+var _0xa6fb=['substring','&$filter=','\x20eq\x20\x27','replace','%2b','enduserId','contactid',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing','string','picklist','nameField','customField','ticketType','incidents','getString','Subjects','/contacts(','/systemusers(','Fields','phonecall','callDirection','queue','phonecalls','Descriptions','lastIndexOf','ticketId','format','user:%s','emit','stripTrailingSlash','data7','unmanaged','%s/api/data/v9.0/','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','recordingURL',']\x20The\x20User\x20ID\x20is:','moduleCreate','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','lodash','request-promise','util','./util','ioredis','../../../../config/logger','dynamics365','redis','defaults','localhost','socket.io-emitter','modernAuthentication','remoteUri','tenantId','CloudProvider','data2','data5','POST','clientId','username','password','access_token','catch','error','toUpperCase',']\x20Wrong\x20credentials!','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','isNil','validateEmail','email','userEmail','length','internalemailaddress','isdisabled','info',']\x20Agent\x20found\x20','systemuserid',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','message','toLowerCase','destcalleridnum','calleridnum','userId','body','then','headers','odata-entityid'];(function(_0x1a08cf,_0x186382){var _0x4174b7=function(_0x263861){while(--_0x263861){_0x1a08cf['push'](_0x1a08cf['shift']());}};_0x4174b7(++_0x186382);}(_0xa6fb,0x95));var _0xba6f=function(_0x21687e,_0x1b5243){_0x21687e=_0x21687e-0x0;var _0x3fa162=_0xa6fb[_0x21687e];return _0x3fa162;};'use strict';var _=require(_0xba6f('0x0'));var rp=require(_0xba6f('0x1'));var util=require(_0xba6f('0x2'));var intUtil=require(_0xba6f('0x3'));var md5=require('md5');var Redis=require(_0xba6f('0x4'));var logger=require(_0xba6f('0x5'))(_0xba6f('0x6'));var config=require('../../../../config/environment');config[_0xba6f('0x7')]=_[_0xba6f('0x8')](config['redis'],{'host':_0xba6f('0x9'),'port':0x18eb});var io=require(_0xba6f('0xa'))(new Redis(config[_0xba6f('0x7')]));function getAuthToken(_0x59a289,_0x52ab54,_0x3cc45c){if(_0x59a289[_0xba6f('0xb')]){_0x59a289[_0xba6f('0xc')]=_0x59a289['CloudProvider']['data7'];_0x59a289[_0xba6f('0xd')]=_0x59a289[_0xba6f('0xe')][_0xba6f('0xf')];return Promise['resolve'](_0x59a289[_0xba6f('0xe')][_0xba6f('0x10')]);}var _0x34183a={'method':_0xba6f('0x11'),'uri':_0x52ab54,'form':{'client_id':_0x59a289[_0xba6f('0x12')],'resource':_0x59a289[_0xba6f('0xc')],'username':_0x59a289[_0xba6f('0x13')],'password':_0x59a289[_0xba6f('0x14')],'grant_type':_0xba6f('0x14'),'client_secret':_0x59a289['clientSecret']},'json':!![]};return rp(_0x34183a)['then'](function(_0x27d660){return _0x27d660[_0xba6f('0x15')];})[_0xba6f('0x16')](function(_0x444fc6){logger[_0xba6f('0x17')]('['+[_0x3cc45c[_0xba6f('0x18')]()]+_0xba6f('0x19'));return _0x444fc6['message'];});}function getUser(_0x33c890,_0x425b2e,_0x4cd4a0,_0x1d26e3,_0x116293,_0x293c50){return new Promise(function(_0x5abcf3,_0x390820){return getAuthToken(_0x425b2e,_0x1d26e3,_0x293c50)['then'](function(_0xbf29c){var _0x14a081={'method':_0xba6f('0x1a'),'uri':_0x116293+_0xba6f('0x1b'),'headers':{'Authorization':_0xba6f('0x1c')+_0xbf29c,'OData-Version':_0xba6f('0x1d')},'json':!![]};return rp(_0x14a081);})['then'](function(_0x7496b6){var _0x4a02be=_0x7496b6[_0xba6f('0x1e')];var _0x26d8d2=![];var _0x5c4efd=null;if(!_[_0xba6f('0x1f')](_0x4cd4a0)){if(intUtil[_0xba6f('0x20')](_0x4cd4a0[_0xba6f('0x21')])){_0x33c890[_0xba6f('0x22')]=_0x4cd4a0[_0xba6f('0x21')];for(_0x5c4efd=0x0;_0x5c4efd<_0x4a02be[_0xba6f('0x23')];_0x5c4efd++){if(_0x4a02be[_0x5c4efd][_0xba6f('0x24')]===_0x4cd4a0['email']&&!_0x4a02be[_0x5c4efd][_0xba6f('0x25')]){_0x26d8d2=!![];logger[_0xba6f('0x26')]('['+[_0x293c50[_0xba6f('0x18')]()]+_0xba6f('0x27')+_0x4a02be[_0x5c4efd][_0xba6f('0x28')]+'!');_0x33c890['userId']=_0x4a02be[_0x5c4efd]['systemuserid'];}}}}if(!_0x26d8d2){logger[_0xba6f('0x26')]('['+[_0x293c50[_0xba6f('0x18')]()]+_0xba6f('0x29'));_0x33c890[_0xba6f('0x22')]=_0x425b2e['username'];for(_0x5c4efd=0x0;_0x5c4efd<_0x4a02be[_0xba6f('0x23')];_0x5c4efd++){if(_0x4a02be[_0x5c4efd]['internalemailaddress']===_0x425b2e[_0xba6f('0x13')]){_0x33c890['userId']=_0x4a02be[_0x5c4efd][_0xba6f('0x28')];}}}_0x5abcf3(_0x33c890);})['catch'](function(_0x58b11d){_0x390820(_0x58b11d[_0xba6f('0x2a')]);});});}function createEndUser(_0x58a472,_0x2a35db,_0x180100,_0x8f5f7e,_0x25d16b,_0x569f3b,_0xe6da9f){return new Promise(function(_0x110c40,_0x1246b4){return getAuthToken(_0x2a35db,_0x180100,_0x569f3b)['then'](function(_0x2396cd){var _0x55eb2a=_0x569f3b[_0xba6f('0x2b')]()==='outbound'?_0x25d16b[_0xba6f('0x2c')]:_0x25d16b[_0xba6f('0x2d')];var _0x20d858={'method':'POST','uri':_0x8f5f7e+'contacts','body':{'fullname':_0x55eb2a,'firstname':_0x55eb2a,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x58a472[_0xba6f('0x2e')]+')'},'headers':{'Authorization':'Bearer\x20'+_0x2396cd,'OData-Version':_0xba6f('0x1d')},'json':!![],'resolveWithFullResponse':!![]};_0x20d858[_0xba6f('0x2f')][_0xe6da9f]=_0x55eb2a;return rp(_0x20d858);})[_0xba6f('0x30')](function(_0x14e321){var _0x23cf33=_0x14e321[_0xba6f('0x31')][_0xba6f('0x32')];var _0xdbe8c8=_0x23cf33[_0xba6f('0x33')](_0x23cf33['lastIndexOf']('(')+0x1,_0x23cf33['lastIndexOf'](')'));_0x58a472['enduserId']=_0xdbe8c8;_0x110c40(_0x58a472);})[_0xba6f('0x16')](function(_0x12a250){_0x1246b4(_0x12a250['message']);});});}function getEndUser(_0x4dd378,_0x42696e,_0x52436b,_0x56b6ac,_0x48ab58,_0xee821e,_0x58b73f,_0x2ff962){var _0x2ed88f=_0xee821e[_0xba6f('0x2b')]()==='outbound'?_0x48ab58[_0xba6f('0x2c')]:_0x48ab58[_0xba6f('0x2d')];return getAuthToken(_0x42696e,_0x52436b,_0xee821e)[_0xba6f('0x30')](function(_0x1a46ea){_0x2ff962=_0x2ff962?_0x2ff962:'telephone1';var _0x2418a4={'method':'GET','uri':_0x56b6ac+'contacts?$select='+_0x2ff962+_0xba6f('0x34')+_0x2ff962+_0xba6f('0x35')+_0x2ed88f[_0xba6f('0x36')]('+',_0xba6f('0x37'))+'\x27','headers':{'Authorization':_0xba6f('0x1c')+_0x1a46ea,'If-None-Match':null,'OData-Version':_0xba6f('0x1d')},'json':!![]};return rp(_0x2418a4);})[_0xba6f('0x30')](function(_0x5e35c5){var _0x2e0e97=![];if(!_0x5e35c5)return _0x2e0e97;var _0x6b3850=_0x5e35c5[_0xba6f('0x1e')];for(var _0x371803=0x0;_0x371803<_0x6b3850[_0xba6f('0x23')];_0x371803++){if(_0x6b3850[_0x371803][_0x2ff962]===_0x2ed88f){_0x2e0e97=!![];_0x4dd378[_0xba6f('0x38')]=_0x6b3850[_0x371803][_0xba6f('0x39')];}}return _0x2e0e97;})[_0xba6f('0x30')](function(_0x3001f3){if(_0x3001f3)return _0x4dd378;if(_0x58b73f==='nothing'){logger[_0xba6f('0x26')]('['+[_0xee821e[_0xba6f('0x18')]()]+_0xba6f('0x3a'));return _0x4dd378;}return createEndUser(_0x4dd378,_0x42696e,_0x52436b,_0x56b6ac,_0x48ab58,_0xee821e,_0x2ff962)[_0xba6f('0x30')](function(_0x3adf15){logger[_0xba6f('0x26')]('['+[_0xee821e[_0xba6f('0x18')]()]+']\x20Enduser\x20created!',_0x3adf15[_0xba6f('0x38')]);return _0x3adf15;});});}function getCustomFields(_0x4fe94f,_0x1ead2b,_0x4590c7){var _0x3219d7={};if(_0x4fe94f[_0xba6f('0x23')]>0x0){_['forEach'](_0x4fe94f,function(_0x2b14f0){if(_['includes']([_0xba6f('0x3b'),_0xba6f('0x3c')],_0x2b14f0['type'])&&_0x2b14f0[_0xba6f('0x3d')]&&!_0x2b14f0[_0xba6f('0x3e')]){var _0xd1b4bd=_0x2b14f0['idField'][_0xba6f('0x2b')]();var _0x50ee03=_0xd1b4bd[_0xba6f('0x33')](0x0,_0xd1b4bd['indexOf']('_'));var _0x3c4ecf=_0xd1b4bd[_0xba6f('0x33')](_0xd1b4bd['indexOf']('_')+0x1);if(_0x50ee03===_0x4590c7){_0x3219d7[_0x3c4ecf]=_0x2b14f0['content'];}}});}return _0x3219d7;}function getTicket(_0x49922b,_0x4db175,_0x893c5f,_0x46347d,_0x36344a,_0x125994,_0x47061e){return new Promise(function(_0x4a916c,_0x572ce9){var _0x4dda18;return getAuthToken(_0x4db175,_0x893c5f,_0x47061e)[_0xba6f('0x30')](function(_0x1005c7){if(_0x125994[_0xba6f('0x3f')]==='incident'){_0x4dda18={'method':'POST','uri':_0x46347d+_0xba6f('0x40'),'body':Object['assign']({},{'title':intUtil[_0xba6f('0x41')](_0x125994[_0xba6f('0x42')],_0x36344a,'\x20'),'description':intUtil[_0xba6f('0x41')](_0x125994['Descriptions'],_0x36344a,'\x0a'),'customerid_contact@odata.bind':_0x49922b[_0xba6f('0x38')]?_0xba6f('0x43')+_0x49922b[_0xba6f('0x38')]+')':undefined,'ownerid@odata.bind':_0xba6f('0x44')+_0x49922b[_0xba6f('0x2e')]+')','caseorigincode':'1'},getCustomFields(_0x125994[_0xba6f('0x45')],_0x36344a,_0x125994[_0xba6f('0x3f')])),'headers':{'Authorization':_0xba6f('0x1c')+_0x1005c7,'OData-Version':_0xba6f('0x1d')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x125994[_0xba6f('0x3f')]===_0xba6f('0x46')){var _0x4b134f=_0x49922b['enduserId']?[{'partyid_systemuser@odata.bind':'/systemusers('+_0x49922b[_0xba6f('0x2e')]+')','participationtypemask':_0x49922b[_0xba6f('0x47')]===_0xba6f('0x48')?0x2:0x1},{'partyid_contact@odata.bind':_0xba6f('0x43')+_0x49922b[_0xba6f('0x38')]+')','participationtypemask':_0x49922b[_0xba6f('0x47')]==='queue'?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0x49922b[_0xba6f('0x2e')]+')','participationtypemask':_0x49922b['callDirection']===_0xba6f('0x48')?0x2:0x1}];_0x4dda18={'method':_0xba6f('0x11'),'uri':_0x46347d+_0xba6f('0x49'),'body':Object['assign']({},{'subject':intUtil[_0xba6f('0x41')](_0x125994[_0xba6f('0x42')],_0x36344a,'\x20'),'phonenumber':String(_0x36344a[_0xba6f('0x2d')]),'description':intUtil[_0xba6f('0x41')](_0x125994[_0xba6f('0x4a')],_0x36344a,'\x0a'),'regardingobjectid_contact@odata.bind':_0x49922b[_0xba6f('0x38')]?_0xba6f('0x43')+_0x49922b[_0xba6f('0x38')]+')':undefined,'ownerid@odata.bind':_0xba6f('0x44')+_0x49922b[_0xba6f('0x2e')]+')','directioncode':_0x49922b['callDirection']==='queue'?![]:!![],'phonecall_activity_parties':_0x4b134f},getCustomFields(_0x125994[_0xba6f('0x45')],_0x36344a,_0x125994[_0xba6f('0x3f')])),'headers':{'Authorization':_0xba6f('0x1c')+_0x1005c7,'OData-Version':_0xba6f('0x1d')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x4dda18);})[_0xba6f('0x30')](function(_0x2a023d){var _0x41cb8c=_0x2a023d[_0xba6f('0x31')]['odata-entityid'];var _0x5048f8=_0x41cb8c[_0xba6f('0x33')](_0x41cb8c['lastIndexOf']('(')+0x1,_0x41cb8c[_0xba6f('0x4b')](')'));_0x49922b[_0xba6f('0x4c')]=_0x5048f8;_0x4a916c(_0x49922b);})[_0xba6f('0x16')](function(_0x273ed2){_0x572ce9(_0x273ed2[_0xba6f('0x2a')]);});});}function emit(_0x55dd63,_0x2c69e6,_0x7b638,_0x2279dc){var _0x4a83fe={'uri':util[_0xba6f('0x4d')]('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x55dd63,_0x7b638,_0x2279dc)};io['to'](util[_0xba6f('0x4d')](_0xba6f('0x4e'),_0x2c69e6))[_0xba6f('0x4f')]('trigger:browser:url',_0x4a83fe);}exports['cs']=function(_0x3fa0e7,_0x4aae93,_0x40b798,_0x356145,_0x11a321,_0x4a4fb4,_0x1a787c,_0x34f6a4){var _0x5cb2ef={};_0x4a4fb4[_0xba6f('0xc')]=_0x4a4fb4[_0xba6f('0xb')]?intUtil[_0xba6f('0x50')](_0x4a4fb4[_0xba6f('0xe')][_0xba6f('0x51')]):intUtil[_0xba6f('0x50')](_0x4a4fb4['remoteUri']);_0x4a4fb4['serverUrl']=intUtil[_0xba6f('0x50')](_0x4a4fb4['serverUrl']);_0x5cb2ef[_0xba6f('0x47')]=_0x34f6a4==='queue'||_0x34f6a4===_0xba6f('0x52')?_0xba6f('0x48'):'outbound';var _0x3c92a1=_0x4a4fb4['modernAuthentication']?util['format']('%s/api/data/v9.0/',_0x4a4fb4[_0xba6f('0xe')][_0xba6f('0x51')]):util[_0xba6f('0x4d')](_0xba6f('0x53'),_0x4a4fb4[_0xba6f('0xc')]);var _0x56f62f=util[_0xba6f('0x4d')]('https://login.microsoftonline.com/%s/oauth2/token',_0x4a4fb4[_0xba6f('0xd')]);var _0x57593e=util[_0xba6f('0x4d')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x4a4fb4['serverUrl'],_0x4aae93[_0xba6f('0x54')],md5(_0x4aae93['uniqueid']));if(_0x11a321&&_0x11a321['monitor_format']){logger[_0xba6f('0x26')](_0xba6f('0x55'),_0xba6f('0x56'));_0x4aae93['recordingURL']=_0x57593e;}else if(_0x1a787c&&_0x1a787c[_0xba6f('0x57')]&&_0x1a787c['recordingFormat']!=='none'){logger[_0xba6f('0x26')]('[OUTBOUND]',_0xba6f('0x56'));_0x4aae93[_0xba6f('0x58')]=_0x57593e;}else{_0x4aae93[_0xba6f('0x58')]='';}return getUser(_0x5cb2ef,_0x4a4fb4,_0x356145,_0x56f62f,_0x3c92a1,_0x34f6a4)[_0xba6f('0x30')](function(_0x13a0e0){logger[_0xba6f('0x26')]('['+_0x34f6a4[_0xba6f('0x18')]()+_0xba6f('0x59'),_0x13a0e0['userId']);logger[_0xba6f('0x26')]('['+_0x34f6a4[_0xba6f('0x18')]()+']\x20The\x20User\x20email\x20is:',_0x13a0e0[_0xba6f('0x22')]);return getEndUser(_0x13a0e0,_0x4a4fb4,_0x56f62f,_0x3c92a1,_0x4aae93,_0x34f6a4,_0x40b798[_0xba6f('0x5a')],_0x40b798[_0xba6f('0x5b')]);})[_0xba6f('0x30')](function(_0x5b3678){logger['info']('['+_0x34f6a4[_0xba6f('0x18')]()+_0xba6f('0x5c'),_0x5b3678[_0xba6f('0x38')]);logger[_0xba6f('0x26')]('['+_0x34f6a4[_0xba6f('0x18')]()+_0xba6f('0x5d'),_0x4aae93[_0xba6f('0x2d')]);return getTicket(_0x5b3678,_0x4a4fb4,_0x56f62f,_0x3c92a1,_0x4aae93,_0x40b798,_0x34f6a4);})[_0xba6f('0x30')](function(_0x1b30b6){logger[_0xba6f('0x26')](util['format']('['+_0x34f6a4[_0xba6f('0x18')]()+_0xba6f('0x5e'),_0x40b798[_0xba6f('0x3f')],_0x1b30b6[_0xba6f('0x4c')]));logger[_0xba6f('0x26')](util[_0xba6f('0x4d')]('['+_0x34f6a4['toUpperCase']()+_0xba6f('0x5f'),_0x34f6a4));if(_0x34f6a4!==_0xba6f('0x52')&&_0x40b798[_0xba6f('0x60')]){logger['info']('['+_0x34f6a4[_0xba6f('0x18')]()+']',_0xba6f('0x61'));emit(_0x4a4fb4[_0xba6f('0xc')],_0x356145['name'],_0x40b798[_0xba6f('0x3f')],_0x1b30b6[_0xba6f('0x4c')]);}})[_0xba6f('0x16')](function(_0x4c60cf){logger[_0xba6f('0x17')]('['+_0x34f6a4[_0xba6f('0x18')]()+_0xba6f('0x62'),_0x4c60cf[_0xba6f('0x2a')]);console[_0xba6f('0x17')](_0xba6f('0x63'),_0x4c60cf);});};
\ No newline at end of file