Built motion from commit b7e79837.|2.6.29
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index 5f1c9d4..dc81c94 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf72f=['info',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','length','internalemailaddress','outbound','destcalleridnum','calleridnum','/systemusers(','body','headers','odata-entityid','substring','lastIndexOf','toLowerCase','telephone1','contacts?$select=','&$filter=','\x20eq\x20\x27','replace','%2b','enduserId','contactid','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','string','picklist','type','nameField','customField','idField','indexOf','content','ticketType','assign','getString','Subjects','/contacts(','Fields','phonecall','callDirection','queue','phonecalls','Descriptions','ticketId','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','format','user:%s','emit','trigger:browser:url','modernAuthentication','stripTrailingSlash','serverUrl','%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]','recordingFormat','[OUTBOUND]','Recording\x20is\x20enabled!','recordingURL',']\x20The\x20User\x20ID\x20is:','moduleCreate','additionalSearchContact','unmanaged','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','name','Error\x20running\x20Dynamics365\x20integration','request-promise','util','md5','../../../../config/logger','redis','localhost','socket.io-emitter','remoteUri','data7','tenantId','data2','CloudProvider','POST','clientId','username','password','clientSecret','then','access_token','catch','error','toUpperCase','message','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','validateEmail','email','userEmail','isdisabled'];(function(_0x4b7895,_0x3c4f5d){var _0x264180=function(_0xe0e861){while(--_0xe0e861){_0x4b7895['push'](_0x4b7895['shift']());}};_0x264180(++_0x3c4f5d);}(_0xf72f,0x189));var _0xff72=function(_0x52f654,_0x5f40a6){_0x52f654=_0x52f654-0x0;var _0x52af7c=_0xf72f[_0x52f654];return _0x52af7c;};'use strict';var _=require('lodash');var rp=require(_0xff72('0x0'));var util=require(_0xff72('0x1'));var intUtil=require('./util');var md5=require(_0xff72('0x2'));var Redis=require('ioredis');var logger=require(_0xff72('0x3'))('dynamics365');var config=require('../../../../config/environment');config[_0xff72('0x4')]=_['defaults'](config['redis'],{'host':_0xff72('0x5'),'port':0x18eb});var io=require(_0xff72('0x6'))(new Redis(config[_0xff72('0x4')]));function getAuthToken(_0x41f3b2,_0x571329,_0x2c99cb){if(_0x41f3b2['modernAuthentication']){_0x41f3b2[_0xff72('0x7')]=_0x41f3b2['CloudProvider'][_0xff72('0x8')];_0x41f3b2[_0xff72('0x9')]=_0x41f3b2['CloudProvider'][_0xff72('0xa')];return Promise['resolve'](_0x41f3b2[_0xff72('0xb')]['data5']);}var _0x4882d8={'method':_0xff72('0xc'),'uri':_0x571329,'form':{'client_id':_0x41f3b2[_0xff72('0xd')],'resource':_0x41f3b2[_0xff72('0x7')],'username':_0x41f3b2[_0xff72('0xe')],'password':_0x41f3b2[_0xff72('0xf')],'grant_type':_0xff72('0xf'),'client_secret':_0x41f3b2[_0xff72('0x10')]},'json':!![]};return rp(_0x4882d8)[_0xff72('0x11')](function(_0x31de21){return _0x31de21[_0xff72('0x12')];})[_0xff72('0x13')](function(_0x2c7a3e){logger[_0xff72('0x14')]('['+[_0x2c99cb[_0xff72('0x15')]()]+']\x20Wrong\x20credentials!');return _0x2c7a3e[_0xff72('0x16')];});}function getUser(_0x5940b6,_0x542362,_0xf3269a,_0x282a94,_0x4019a2,_0x537881){return new Promise(function(_0x36df41,_0x50d805){return getAuthToken(_0x542362,_0x282a94,_0x537881)[_0xff72('0x11')](function(_0x36e011){var _0x3eb34f={'method':_0xff72('0x17'),'uri':_0x4019a2+_0xff72('0x18'),'headers':{'Authorization':_0xff72('0x19')+_0x36e011,'OData-Version':_0xff72('0x1a')},'json':!![]};return rp(_0x3eb34f);})['then'](function(_0x117693){var _0x29be94=_0x117693['value'];var _0x3d6a6c=![];var _0x41514b=null;if(!_['isNil'](_0xf3269a)){if(intUtil[_0xff72('0x1b')](_0xf3269a[_0xff72('0x1c')])){_0x5940b6[_0xff72('0x1d')]=_0xf3269a['email'];for(_0x41514b=0x0;_0x41514b<_0x29be94['length'];_0x41514b++){if(_0x29be94[_0x41514b]['internalemailaddress']===_0xf3269a[_0xff72('0x1c')]&&!_0x29be94[_0x41514b][_0xff72('0x1e')]){_0x3d6a6c=!![];logger[_0xff72('0x1f')]('['+[_0x537881[_0xff72('0x15')]()]+_0xff72('0x20')+_0x29be94[_0x41514b][_0xff72('0x21')]+'!');_0x5940b6[_0xff72('0x22')]=_0x29be94[_0x41514b]['systemuserid'];}}}}if(!_0x3d6a6c){logger[_0xff72('0x1f')]('['+[_0x537881['toUpperCase']()]+_0xff72('0x23'));_0x5940b6[_0xff72('0x1d')]=_0x542362['username'];for(_0x41514b=0x0;_0x41514b<_0x29be94[_0xff72('0x24')];_0x41514b++){if(_0x29be94[_0x41514b][_0xff72('0x25')]===_0x542362[_0xff72('0xe')]){_0x5940b6[_0xff72('0x22')]=_0x29be94[_0x41514b][_0xff72('0x21')];}}}_0x36df41(_0x5940b6);})[_0xff72('0x13')](function(_0x344fcb){_0x50d805(_0x344fcb[_0xff72('0x16')]);});});}function createEndUser(_0x5cec3d,_0x3843b3,_0x221649,_0xf5fa6a,_0x1e9482,_0x43ef9a,_0xb0c0b8){return new Promise(function(_0x2c4d78,_0x18169d){return getAuthToken(_0x3843b3,_0x221649,_0x43ef9a)[_0xff72('0x11')](function(_0x1f3bba){var _0x1895e4=_0x43ef9a['toLowerCase']()===_0xff72('0x26')?_0x1e9482[_0xff72('0x27')]:_0x1e9482[_0xff72('0x28')];var _0xb2b288={'method':_0xff72('0xc'),'uri':_0xf5fa6a+'contacts','body':{'fullname':_0x1895e4,'firstname':_0x1895e4,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0xff72('0x29')+_0x5cec3d[_0xff72('0x22')]+')'},'headers':{'Authorization':_0xff72('0x19')+_0x1f3bba,'OData-Version':_0xff72('0x1a')},'json':!![],'resolveWithFullResponse':!![]};_0xb2b288[_0xff72('0x2a')][_0xb0c0b8]=_0x1895e4;return rp(_0xb2b288);})[_0xff72('0x11')](function(_0x5349fe){var _0x2ba488=_0x5349fe[_0xff72('0x2b')][_0xff72('0x2c')];var _0x59f393=_0x2ba488[_0xff72('0x2d')](_0x2ba488['lastIndexOf']('(')+0x1,_0x2ba488[_0xff72('0x2e')](')'));_0x5cec3d['enduserId']=_0x59f393;_0x2c4d78(_0x5cec3d);})[_0xff72('0x13')](function(_0x4f5c62){_0x18169d(_0x4f5c62[_0xff72('0x16')]);});});}function getEndUser(_0x4c0e7c,_0x485b7c,_0x486874,_0x4320b0,_0x5d88f3,_0x42f99f,_0x6d43a6,_0xaca963){var _0x17bc89=_0x42f99f[_0xff72('0x2f')]()===_0xff72('0x26')?_0x5d88f3[_0xff72('0x27')]:_0x5d88f3['calleridnum'];return getAuthToken(_0x485b7c,_0x486874,_0x42f99f)[_0xff72('0x11')](function(_0x415484){_0xaca963=_0xaca963?_0xaca963:_0xff72('0x30');var _0x3a50ff={'method':_0xff72('0x17'),'uri':_0x4320b0+_0xff72('0x31')+_0xaca963+_0xff72('0x32')+_0xaca963+_0xff72('0x33')+_0x17bc89[_0xff72('0x34')]('+',_0xff72('0x35'))+'\x27','headers':{'Authorization':_0xff72('0x19')+_0x415484,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x3a50ff);})[_0xff72('0x11')](function(_0x4373aa){var _0x59b7b8=![];if(!_0x4373aa)return _0x59b7b8;var _0x323fbb=_0x4373aa['value'];for(var _0x641269=0x0;_0x641269<_0x323fbb['length'];_0x641269++){if(_0x323fbb[_0x641269][_0xaca963]===_0x17bc89){_0x59b7b8=!![];_0x4c0e7c[_0xff72('0x36')]=_0x323fbb[_0x641269][_0xff72('0x37')];}}return _0x59b7b8;})[_0xff72('0x11')](function(_0x189f21){if(_0x189f21)return _0x4c0e7c;if(_0x6d43a6===_0xff72('0x38')){logger[_0xff72('0x1f')]('['+[_0x42f99f[_0xff72('0x15')]()]+_0xff72('0x39'));return _0x4c0e7c;}return createEndUser(_0x4c0e7c,_0x485b7c,_0x486874,_0x4320b0,_0x5d88f3,_0x42f99f,_0xaca963)[_0xff72('0x11')](function(_0x4e90b5){logger[_0xff72('0x1f')]('['+[_0x42f99f['toUpperCase']()]+_0xff72('0x3a'),_0x4e90b5[_0xff72('0x36')]);return _0x4e90b5;});});}function getCustomFields(_0x39bb5a,_0x2babfc,_0x399693){var _0x49ff19={};if(_0x39bb5a[_0xff72('0x24')]>0x0){_[_0xff72('0x3b')](_0x39bb5a,function(_0x462fa7){if(_['includes']([_0xff72('0x3c'),_0xff72('0x3d')],_0x462fa7[_0xff72('0x3e')])&&_0x462fa7[_0xff72('0x3f')]&&!_0x462fa7[_0xff72('0x40')]){var _0x3daa7b=_0x462fa7[_0xff72('0x41')][_0xff72('0x2f')]();var _0x250240=_0x3daa7b[_0xff72('0x2d')](0x0,_0x3daa7b['indexOf']('_'));var _0x5ef9bc=_0x3daa7b[_0xff72('0x2d')](_0x3daa7b[_0xff72('0x42')]('_')+0x1);if(_0x250240===_0x399693){_0x49ff19[_0x5ef9bc]=_0x462fa7[_0xff72('0x43')];}}});}return _0x49ff19;}function getTicket(_0x542297,_0x1c9501,_0x256a4e,_0xd2a79e,_0x440cdd,_0x1b99ab,_0x9a18ac){return new Promise(function(_0x466a2d,_0x5197a6){var _0x3ac369;return getAuthToken(_0x1c9501,_0x256a4e,_0x9a18ac)['then'](function(_0x4b2247){if(_0x1b99ab[_0xff72('0x44')]==='incident'){_0x3ac369={'method':_0xff72('0xc'),'uri':_0xd2a79e+'incidents','body':Object[_0xff72('0x45')]({},{'title':intUtil[_0xff72('0x46')](_0x1b99ab[_0xff72('0x47')],_0x440cdd,'\x20'),'description':intUtil[_0xff72('0x46')](_0x1b99ab['Descriptions'],_0x440cdd,'\x0a'),'customerid_contact@odata.bind':_0x542297[_0xff72('0x36')]?_0xff72('0x48')+_0x542297[_0xff72('0x36')]+')':undefined,'ownerid@odata.bind':_0xff72('0x29')+_0x542297['userId']+')','caseorigincode':'1'},getCustomFields(_0x1b99ab[_0xff72('0x49')],_0x440cdd,_0x1b99ab[_0xff72('0x44')])),'headers':{'Authorization':_0xff72('0x19')+_0x4b2247,'OData-Version':_0xff72('0x1a')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x1b99ab[_0xff72('0x44')]===_0xff72('0x4a')){var _0x28164b=_0x542297[_0xff72('0x36')]?[{'partyid_systemuser@odata.bind':_0xff72('0x29')+_0x542297[_0xff72('0x22')]+')','participationtypemask':_0x542297[_0xff72('0x4b')]===_0xff72('0x4c')?0x2:0x1},{'partyid_contact@odata.bind':_0xff72('0x48')+_0x542297[_0xff72('0x36')]+')','participationtypemask':_0x542297['callDirection']===_0xff72('0x4c')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0xff72('0x29')+_0x542297[_0xff72('0x22')]+')','participationtypemask':_0x542297[_0xff72('0x4b')]==='queue'?0x2:0x1}];_0x3ac369={'method':_0xff72('0xc'),'uri':_0xd2a79e+_0xff72('0x4d'),'body':Object[_0xff72('0x45')]({},{'subject':intUtil[_0xff72('0x46')](_0x1b99ab[_0xff72('0x47')],_0x440cdd,'\x20'),'phonenumber':String(_0x440cdd['calleridnum']),'description':intUtil[_0xff72('0x46')](_0x1b99ab[_0xff72('0x4e')],_0x440cdd,'\x0a'),'regardingobjectid_contact@odata.bind':_0x542297[_0xff72('0x36')]?'/contacts('+_0x542297[_0xff72('0x36')]+')':undefined,'ownerid@odata.bind':_0xff72('0x29')+_0x542297[_0xff72('0x22')]+')','directioncode':_0x542297[_0xff72('0x4b')]===_0xff72('0x4c')?![]:!![],'phonecall_activity_parties':_0x28164b},getCustomFields(_0x1b99ab[_0xff72('0x49')],_0x440cdd,_0x1b99ab['ticketType'])),'headers':{'Authorization':_0xff72('0x19')+_0x4b2247,'OData-Version':_0xff72('0x1a')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x3ac369);})['then'](function(_0xe545f7){var _0x21e9bb=_0xe545f7[_0xff72('0x2b')][_0xff72('0x2c')];var _0x46c363=_0x21e9bb[_0xff72('0x2d')](_0x21e9bb[_0xff72('0x2e')]('(')+0x1,_0x21e9bb[_0xff72('0x2e')](')'));_0x542297[_0xff72('0x4f')]=_0x46c363;_0x466a2d(_0x542297);})[_0xff72('0x13')](function(_0x264e9d){_0x5197a6(_0x264e9d[_0xff72('0x16')]);});});}function emit(_0x4c2abd,_0x2bf6e1,_0x1b58df,_0x152fd1){var _0x14b2e0={'uri':util['format'](_0xff72('0x50'),_0x4c2abd,_0x1b58df,_0x152fd1)};io['to'](util[_0xff72('0x51')](_0xff72('0x52'),_0x2bf6e1))[_0xff72('0x53')](_0xff72('0x54'),_0x14b2e0);}exports['cs']=function(_0x119a29,_0x2bbba0,_0x119bf1,_0x533d9b,_0x4724bd,_0x1b6290,_0x51912f,_0x2a903c){var _0x3ee1e8={};_0x1b6290[_0xff72('0x7')]=_0x1b6290[_0xff72('0x55')]?intUtil[_0xff72('0x56')](_0x1b6290['CloudProvider'][_0xff72('0x8')]):intUtil[_0xff72('0x56')](_0x1b6290[_0xff72('0x7')]);_0x1b6290[_0xff72('0x57')]=intUtil[_0xff72('0x56')](_0x1b6290['serverUrl']);_0x3ee1e8[_0xff72('0x4b')]=_0x2a903c==='queue'||_0x2a903c==='unmanaged'?_0xff72('0x4c'):_0xff72('0x26');var _0x6611ee=_0x1b6290['modernAuthentication']?util[_0xff72('0x51')]('%s/api/data/v9.0/',_0x1b6290[_0xff72('0xb')][_0xff72('0x8')]):util[_0xff72('0x51')](_0xff72('0x58'),_0x1b6290['remoteUri']);var _0x2748ad=util[_0xff72('0x51')](_0xff72('0x59'),_0x1b6290[_0xff72('0x9')]);var _0x57244c=util['format'](_0xff72('0x5a'),_0x1b6290['serverUrl'],_0x2bbba0['uniqueid'],md5(_0x2bbba0[_0xff72('0x5b')]));if(_0x4724bd&&_0x4724bd[_0xff72('0x5c')]){logger['info'](_0xff72('0x5d'),'Recording\x20is\x20enabled!');_0x2bbba0['recordingURL']=_0x57244c;}else if(_0x51912f&&_0x51912f[_0xff72('0x5e')]&&_0x51912f[_0xff72('0x5e')]!=='none'){logger[_0xff72('0x1f')](_0xff72('0x5f'),_0xff72('0x60'));_0x2bbba0[_0xff72('0x61')]=_0x57244c;}else{_0x2bbba0[_0xff72('0x61')]='';}return getUser(_0x3ee1e8,_0x1b6290,_0x533d9b,_0x2748ad,_0x6611ee,_0x2a903c)[_0xff72('0x11')](function(_0x4fd2bc){logger['info']('['+_0x2a903c['toUpperCase']()+_0xff72('0x62'),_0x4fd2bc[_0xff72('0x22')]);logger['info']('['+_0x2a903c['toUpperCase']()+']\x20The\x20User\x20email\x20is:',_0x4fd2bc[_0xff72('0x1d')]);return getEndUser(_0x4fd2bc,_0x1b6290,_0x2748ad,_0x6611ee,_0x2bbba0,_0x2a903c,_0x119bf1[_0xff72('0x63')],_0x119bf1[_0xff72('0x64')]);})[_0xff72('0x11')](function(_0x4945f7){logger['info']('['+_0x2a903c[_0xff72('0x15')]()+']\x20The\x20Enduser\x20ID\x20is:',_0x4945f7[_0xff72('0x36')]);logger[_0xff72('0x1f')]('['+_0x2a903c[_0xff72('0x15')]()+']\x20The\x20Enduser\x20phone\x20is:',_0x2bbba0['calleridnum']);return getTicket(_0x4945f7,_0x1b6290,_0x2748ad,_0x6611ee,_0x2bbba0,_0x119bf1,_0x2a903c);})[_0xff72('0x11')](function(_0x606bff){logger[_0xff72('0x1f')](util[_0xff72('0x51')]('['+_0x2a903c[_0xff72('0x15')]()+']\x20The\x20%s\x20ID\x20is:\x20%s',_0x119bf1[_0xff72('0x44')],_0x606bff['ticketId']));logger[_0xff72('0x1f')](util[_0xff72('0x51')]('['+_0x2a903c[_0xff72('0x15')]()+']\x20Call\x20direction:\x20%s',_0x2a903c));if(_0x2a903c!==_0xff72('0x65')&&_0x119bf1[_0xff72('0x66')]){logger[_0xff72('0x1f')]('['+_0x2a903c['toUpperCase']()+']',_0xff72('0x67'));emit(_0x1b6290[_0xff72('0x7')],_0x533d9b[_0xff72('0x68')],_0x119bf1['ticketType'],_0x606bff[_0xff72('0x4f')]);}})[_0xff72('0x13')](function(_0x5f59b3){logger[_0xff72('0x14')]('['+_0x2a903c[_0xff72('0x15')]()+']\x20Error\x20running\x20Dynamics365\x20integration',_0x5f59b3['message']);console[_0xff72('0x14')](_0xff72('0x69'),_0x5f59b3);});};
\ No newline at end of file
+var _0x46e2=['calleridnum','contacts','Bearer\x20','4.0','body','headers','odata-entityid','substring','lastIndexOf','enduserId','toLowerCase','destcalleridnum','telephone1','contacts?$select=','\x20eq\x20\x27','replace','%2b','nothing',']\x20Enduser\x20created!','forEach','includes','picklist','nameField','idField','indexOf','ticketType','incident','incidents','assign','getString','Subjects','Descriptions','/contacts(','/systemusers(','Fields','phonecall','callDirection','queue','phonecalls','ticketId','format','user:%s','emit','stripTrailingSlash','serverUrl','unmanaged','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','tenantId','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','monitor_format','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:',']\x20The\x20User\x20email\x20is:','moduleCreate','additionalSearchContact',']\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','request-promise','util','md5','dynamics365','../../../../config/environment','redis','localhost','socket.io-emitter','modernAuthentication','remoteUri','data7','CloudProvider','data2','resolve','POST','username','password','clientSecret','then','access_token','catch','error','toUpperCase',']\x20Wrong\x20credentials!','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','value','isNil','email','userEmail','length','isdisabled','systemuserid','userId','info',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','internalemailaddress','message','outbound'];(function(_0x266600,_0x2afa01){var _0x564a48=function(_0x115cfe){while(--_0x115cfe){_0x266600['push'](_0x266600['shift']());}};_0x564a48(++_0x2afa01);}(_0x46e2,0x117));var _0x246e=function(_0x3e1bac,_0x445840){_0x3e1bac=_0x3e1bac-0x0;var _0x3c3d9d=_0x46e2[_0x3e1bac];return _0x3c3d9d;};'use strict';var _=require('lodash');var rp=require(_0x246e('0x0'));var util=require(_0x246e('0x1'));var intUtil=require('./util');var md5=require(_0x246e('0x2'));var Redis=require('ioredis');var logger=require('../../../../config/logger')(_0x246e('0x3'));var config=require(_0x246e('0x4'));config[_0x246e('0x5')]=_['defaults'](config[_0x246e('0x5')],{'host':_0x246e('0x6'),'port':0x18eb});var io=require(_0x246e('0x7'))(new Redis(config['redis']));function getAuthToken(_0x4dd942,_0x32ef5a,_0x3161e2){if(_0x4dd942[_0x246e('0x8')]){_0x4dd942[_0x246e('0x9')]=_0x4dd942['CloudProvider'][_0x246e('0xa')];_0x4dd942['tenantId']=_0x4dd942[_0x246e('0xb')][_0x246e('0xc')];return Promise[_0x246e('0xd')](_0x4dd942['CloudProvider']['data5']);}var _0x460bad={'method':_0x246e('0xe'),'uri':_0x32ef5a,'form':{'client_id':_0x4dd942['clientId'],'resource':_0x4dd942[_0x246e('0x9')],'username':_0x4dd942[_0x246e('0xf')],'password':_0x4dd942[_0x246e('0x10')],'grant_type':_0x246e('0x10'),'client_secret':_0x4dd942[_0x246e('0x11')]},'json':!![]};return rp(_0x460bad)[_0x246e('0x12')](function(_0x3eec0e){return _0x3eec0e[_0x246e('0x13')];})[_0x246e('0x14')](function(_0x109ea8){logger[_0x246e('0x15')]('['+[_0x3161e2[_0x246e('0x16')]()]+_0x246e('0x17'));return _0x109ea8['message'];});}function getUser(_0x133a80,_0x41b599,_0x54fb45,_0x426f3b,_0x278fdd,_0x49bdc5){return new Promise(function(_0x4b7ba9,_0xe8d7fd){return getAuthToken(_0x41b599,_0x426f3b,_0x49bdc5)[_0x246e('0x12')](function(_0x35d236){var _0x4e8853={'method':_0x246e('0x18'),'uri':_0x278fdd+_0x246e('0x19'),'headers':{'Authorization':'Bearer\x20'+_0x35d236,'OData-Version':'4.0'},'json':!![]};return rp(_0x4e8853);})['then'](function(_0x27ca04){var _0x15b1a1=_0x27ca04[_0x246e('0x1a')];var _0x5c54f3=![];var _0x4763a3=null;if(!_[_0x246e('0x1b')](_0x54fb45)){if(intUtil['validateEmail'](_0x54fb45[_0x246e('0x1c')])){_0x133a80[_0x246e('0x1d')]=_0x54fb45[_0x246e('0x1c')];for(_0x4763a3=0x0;_0x4763a3<_0x15b1a1[_0x246e('0x1e')];_0x4763a3++){if(_0x15b1a1[_0x4763a3]['internalemailaddress']===_0x54fb45['email']&&!_0x15b1a1[_0x4763a3][_0x246e('0x1f')]){_0x5c54f3=!![];logger['info']('['+[_0x49bdc5['toUpperCase']()]+']\x20Agent\x20found\x20'+_0x15b1a1[_0x4763a3][_0x246e('0x20')]+'!');_0x133a80[_0x246e('0x21')]=_0x15b1a1[_0x4763a3][_0x246e('0x20')];}}}}if(!_0x5c54f3){logger[_0x246e('0x22')]('['+[_0x49bdc5[_0x246e('0x16')]()]+_0x246e('0x23'));_0x133a80[_0x246e('0x1d')]=_0x41b599['username'];for(_0x4763a3=0x0;_0x4763a3<_0x15b1a1[_0x246e('0x1e')];_0x4763a3++){if(_0x15b1a1[_0x4763a3][_0x246e('0x24')]===_0x41b599[_0x246e('0xf')]){_0x133a80[_0x246e('0x21')]=_0x15b1a1[_0x4763a3][_0x246e('0x20')];}}}_0x4b7ba9(_0x133a80);})['catch'](function(_0x570f30){_0xe8d7fd(_0x570f30[_0x246e('0x25')]);});});}function createEndUser(_0x399c4c,_0x4faf15,_0x41ab3a,_0x1feaf8,_0x1f09f8,_0x2e231b,_0x52e52c){return new Promise(function(_0x370278,_0x20c386){return getAuthToken(_0x4faf15,_0x41ab3a,_0x2e231b)[_0x246e('0x12')](function(_0x1c6977){var _0x347066=_0x2e231b['toLowerCase']()===_0x246e('0x26')?_0x1f09f8['destcalleridnum']:_0x1f09f8[_0x246e('0x27')];var _0x45718f={'method':_0x246e('0xe'),'uri':_0x1feaf8+_0x246e('0x28'),'body':{'fullname':_0x347066,'firstname':_0x347066,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x399c4c[_0x246e('0x21')]+')'},'headers':{'Authorization':_0x246e('0x29')+_0x1c6977,'OData-Version':_0x246e('0x2a')},'json':!![],'resolveWithFullResponse':!![]};_0x45718f[_0x246e('0x2b')][_0x52e52c]=_0x347066;return rp(_0x45718f);})['then'](function(_0x2fe405){var _0x564cfb=_0x2fe405[_0x246e('0x2c')][_0x246e('0x2d')];var _0x27d162=_0x564cfb[_0x246e('0x2e')](_0x564cfb[_0x246e('0x2f')]('(')+0x1,_0x564cfb[_0x246e('0x2f')](')'));_0x399c4c[_0x246e('0x30')]=_0x27d162;_0x370278(_0x399c4c);})[_0x246e('0x14')](function(_0x4c5222){_0x20c386(_0x4c5222[_0x246e('0x25')]);});});}function getEndUser(_0x4e7cb9,_0x306f3f,_0x7a5cc0,_0x396441,_0x3e487f,_0x168dde,_0x24da29,_0x58a5b3){var _0x349d1c=_0x168dde[_0x246e('0x31')]()===_0x246e('0x26')?_0x3e487f[_0x246e('0x32')]:_0x3e487f['calleridnum'];return getAuthToken(_0x306f3f,_0x7a5cc0,_0x168dde)[_0x246e('0x12')](function(_0x28c8ff){_0x58a5b3=_0x58a5b3?_0x58a5b3:_0x246e('0x33');var _0xb5e19f={'method':_0x246e('0x18'),'uri':_0x396441+_0x246e('0x34')+_0x58a5b3+'&$filter='+_0x58a5b3+_0x246e('0x35')+_0x349d1c[_0x246e('0x36')]('+',_0x246e('0x37'))+'\x27','headers':{'Authorization':_0x246e('0x29')+_0x28c8ff,'If-None-Match':null,'OData-Version':_0x246e('0x2a')},'json':!![]};return rp(_0xb5e19f);})[_0x246e('0x12')](function(_0x48c0d5){var _0x504b3f=![];if(!_0x48c0d5)return _0x504b3f;var _0x3d35cb=_0x48c0d5[_0x246e('0x1a')];for(var _0x53398d=0x0;_0x53398d<_0x3d35cb[_0x246e('0x1e')];_0x53398d++){if(_0x3d35cb[_0x53398d][_0x58a5b3]===_0x349d1c){_0x504b3f=!![];_0x4e7cb9[_0x246e('0x30')]=_0x3d35cb[_0x53398d]['contactid'];}}return _0x504b3f;})[_0x246e('0x12')](function(_0x411fd2){if(_0x411fd2)return _0x4e7cb9;if(_0x24da29===_0x246e('0x38')){logger[_0x246e('0x22')]('['+[_0x168dde['toUpperCase']()]+']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing');return _0x4e7cb9;}return createEndUser(_0x4e7cb9,_0x306f3f,_0x7a5cc0,_0x396441,_0x3e487f,_0x168dde,_0x58a5b3)[_0x246e('0x12')](function(_0x35f145){logger[_0x246e('0x22')]('['+[_0x168dde[_0x246e('0x16')]()]+_0x246e('0x39'),_0x35f145['enduserId']);return _0x35f145;});});}function getCustomFields(_0x578b1a,_0x51018a,_0x27d9f1){var _0x1a3a98={};if(_0x578b1a['length']>0x0){_[_0x246e('0x3a')](_0x578b1a,function(_0x1f2a17){if(_[_0x246e('0x3b')](['string',_0x246e('0x3c')],_0x1f2a17['type'])&&_0x1f2a17[_0x246e('0x3d')]&&!_0x1f2a17['customField']){var _0x3f07e6=_0x1f2a17[_0x246e('0x3e')][_0x246e('0x31')]();var _0x41f8a9=_0x3f07e6[_0x246e('0x2e')](0x0,_0x3f07e6[_0x246e('0x3f')]('_'));var _0x1cad6b=_0x3f07e6['substring'](_0x3f07e6[_0x246e('0x3f')]('_')+0x1);if(_0x41f8a9===_0x27d9f1){_0x1a3a98[_0x1cad6b]=_0x1f2a17['content'];}}});}return _0x1a3a98;}function getTicket(_0x1cb67e,_0x203bdf,_0x5a1905,_0x151d40,_0x5c1f2e,_0x354938,_0x3f9e71){return new Promise(function(_0x5dc201,_0x2908d5){var _0x2847d3;return getAuthToken(_0x203bdf,_0x5a1905,_0x3f9e71)[_0x246e('0x12')](function(_0x4dec64){if(_0x354938[_0x246e('0x40')]===_0x246e('0x41')){_0x2847d3={'method':_0x246e('0xe'),'uri':_0x151d40+_0x246e('0x42'),'body':Object[_0x246e('0x43')]({},{'title':intUtil[_0x246e('0x44')](_0x354938[_0x246e('0x45')],_0x5c1f2e,'\x20'),'description':intUtil[_0x246e('0x44')](_0x354938[_0x246e('0x46')],_0x5c1f2e,'\x0a'),'customerid_contact@odata.bind':_0x1cb67e[_0x246e('0x30')]?_0x246e('0x47')+_0x1cb67e[_0x246e('0x30')]+')':undefined,'ownerid@odata.bind':_0x246e('0x48')+_0x1cb67e[_0x246e('0x21')]+')','caseorigincode':'1'},getCustomFields(_0x354938[_0x246e('0x49')],_0x5c1f2e,_0x354938[_0x246e('0x40')])),'headers':{'Authorization':_0x246e('0x29')+_0x4dec64,'OData-Version':_0x246e('0x2a')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x354938[_0x246e('0x40')]===_0x246e('0x4a')){var _0x2924bb=_0x1cb67e['enduserId']?[{'partyid_systemuser@odata.bind':_0x246e('0x48')+_0x1cb67e[_0x246e('0x21')]+')','participationtypemask':_0x1cb67e['callDirection']==='queue'?0x2:0x1},{'partyid_contact@odata.bind':_0x246e('0x47')+_0x1cb67e[_0x246e('0x30')]+')','participationtypemask':_0x1cb67e[_0x246e('0x4b')]===_0x246e('0x4c')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0x246e('0x48')+_0x1cb67e[_0x246e('0x21')]+')','participationtypemask':_0x1cb67e[_0x246e('0x4b')]===_0x246e('0x4c')?0x2:0x1}];_0x2847d3={'method':_0x246e('0xe'),'uri':_0x151d40+_0x246e('0x4d'),'body':Object[_0x246e('0x43')]({},{'subject':intUtil[_0x246e('0x44')](_0x354938[_0x246e('0x45')],_0x5c1f2e,'\x20'),'phonenumber':String(_0x5c1f2e[_0x246e('0x27')]),'description':intUtil[_0x246e('0x44')](_0x354938[_0x246e('0x46')],_0x5c1f2e,'\x0a'),'regardingobjectid_contact@odata.bind':_0x1cb67e[_0x246e('0x30')]?_0x246e('0x47')+_0x1cb67e[_0x246e('0x30')]+')':undefined,'ownerid@odata.bind':_0x246e('0x48')+_0x1cb67e['userId']+')','directioncode':_0x1cb67e[_0x246e('0x4b')]===_0x246e('0x4c')?![]:!![],'phonecall_activity_parties':_0x2924bb},getCustomFields(_0x354938['Fields'],_0x5c1f2e,_0x354938[_0x246e('0x40')])),'headers':{'Authorization':_0x246e('0x29')+_0x4dec64,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x2847d3);})[_0x246e('0x12')](function(_0x4df0b3){var _0x2f4637=_0x4df0b3[_0x246e('0x2c')][_0x246e('0x2d')];var _0x1aaab4=_0x2f4637['substring'](_0x2f4637[_0x246e('0x2f')]('(')+0x1,_0x2f4637[_0x246e('0x2f')](')'));_0x1cb67e[_0x246e('0x4e')]=_0x1aaab4;_0x5dc201(_0x1cb67e);})['catch'](function(_0x510126){_0x2908d5(_0x510126[_0x246e('0x25')]);});});}function emit(_0x21b045,_0x3d5e7d,_0x5238a6,_0x1565d8){var _0x25f3b8={'uri':util[_0x246e('0x4f')]('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x21b045,_0x5238a6,_0x1565d8)};io['to'](util['format'](_0x246e('0x50'),_0x3d5e7d))[_0x246e('0x51')]('trigger:browser:url',_0x25f3b8);}exports['cs']=function(_0x85c102,_0x31fce6,_0x42b6b9,_0x3651e9,_0x5801d6,_0x3865f8,_0x3d3f61,_0x23abad){var _0x4b66c4={};_0x3865f8[_0x246e('0x9')]=_0x3865f8[_0x246e('0x8')]?intUtil[_0x246e('0x52')](_0x3865f8[_0x246e('0xb')]['data7']):intUtil[_0x246e('0x52')](_0x3865f8[_0x246e('0x9')]);_0x3865f8[_0x246e('0x53')]=intUtil['stripTrailingSlash'](_0x3865f8[_0x246e('0x53')]);_0x4b66c4[_0x246e('0x4b')]=_0x23abad===_0x246e('0x4c')||_0x23abad===_0x246e('0x54')?_0x246e('0x4c'):_0x246e('0x26');var _0x2aeb49=_0x3865f8[_0x246e('0x8')]?util['format'](_0x246e('0x55'),_0x3865f8['CloudProvider']['data7']):util[_0x246e('0x4f')](_0x246e('0x55'),_0x3865f8['remoteUri']);var _0x133f43=util[_0x246e('0x4f')](_0x246e('0x56'),_0x3865f8[_0x246e('0x57')]);var _0x4c77d9=util[_0x246e('0x4f')](_0x246e('0x58'),_0x3865f8[_0x246e('0x53')],_0x31fce6['uniqueid'],md5(_0x31fce6['uniqueid']));if(_0x5801d6&&_0x5801d6[_0x246e('0x59')]){logger[_0x246e('0x22')]('[QUEUE]',_0x246e('0x5a'));_0x31fce6[_0x246e('0x5b')]=_0x4c77d9;}else if(_0x3d3f61&&_0x3d3f61['recordingFormat']&&_0x3d3f61[_0x246e('0x5c')]!==_0x246e('0x5d')){logger['info'](_0x246e('0x5e'),_0x246e('0x5a'));_0x31fce6[_0x246e('0x5b')]=_0x4c77d9;}else{_0x31fce6[_0x246e('0x5b')]='';}return getUser(_0x4b66c4,_0x3865f8,_0x3651e9,_0x133f43,_0x2aeb49,_0x23abad)['then'](function(_0x48f22c){logger[_0x246e('0x22')]('['+_0x23abad['toUpperCase']()+_0x246e('0x5f'),_0x48f22c[_0x246e('0x21')]);logger[_0x246e('0x22')]('['+_0x23abad['toUpperCase']()+_0x246e('0x60'),_0x48f22c[_0x246e('0x1d')]);return getEndUser(_0x48f22c,_0x3865f8,_0x133f43,_0x2aeb49,_0x31fce6,_0x23abad,_0x42b6b9[_0x246e('0x61')],_0x42b6b9[_0x246e('0x62')]);})['then'](function(_0x2c33ee){logger[_0x246e('0x22')]('['+_0x23abad[_0x246e('0x16')]()+']\x20The\x20Enduser\x20ID\x20is:',_0x2c33ee[_0x246e('0x30')]);logger[_0x246e('0x22')]('['+_0x23abad[_0x246e('0x16')]()+_0x246e('0x63'),_0x31fce6[_0x246e('0x27')]);return getTicket(_0x2c33ee,_0x3865f8,_0x133f43,_0x2aeb49,_0x31fce6,_0x42b6b9,_0x23abad);})['then'](function(_0x3841e5){logger[_0x246e('0x22')](util[_0x246e('0x4f')]('['+_0x23abad[_0x246e('0x16')]()+_0x246e('0x64'),_0x42b6b9[_0x246e('0x40')],_0x3841e5['ticketId']));logger[_0x246e('0x22')](util['format']('['+_0x23abad[_0x246e('0x16')]()+_0x246e('0x65'),_0x23abad));if(_0x23abad!=='unmanaged'&&_0x42b6b9[_0x246e('0x66')]){logger[_0x246e('0x22')]('['+_0x23abad['toUpperCase']()+']',_0x246e('0x67'));emit(_0x3865f8[_0x246e('0x9')],_0x3651e9['name'],_0x42b6b9[_0x246e('0x40')],_0x3841e5[_0x246e('0x4e')]);}})[_0x246e('0x14')](function(_0x5904fc){logger[_0x246e('0x15')]('['+_0x23abad['toUpperCase']()+_0x246e('0x68'),_0x5904fc[_0x246e('0x25')]);console[_0x246e('0x15')](_0x246e('0x69'),_0x5904fc);});};
\ No newline at end of file