Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index 9e5172c..fa972b9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf773=['recordingFormat','[OUTBOUND]','recordingURL',']\x20The\x20User\x20email\x20is:','userEmail','moduleCreate',']\x20The\x20Enduser\x20ID\x20is:','ticketId',']\x20Call\x20direction:\x20%s','name',']\x20Error\x20running\x20Dynamics365\x20integration','lodash','bluebird','util','./util','md5','ioredis','dynamics365','../../../../config/environment','redis','defaults','localhost','clientId','username','password','clientSecret','then','access_token','catch',']\x20Wrong\x20credentials!','message','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','isNil','email','length','internalemailaddress','isdisabled','info','toUpperCase',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','toLowerCase','destcalleridnum','calleridnum','POST','contacts','/systemusers(','headers','odata-entityid','substring','outbound','replace','%2b','enduserId','contactid','nothing',']\x20Enduser\x20created!','forEach','includes','string','type','idField','indexOf','ticketType','incident','incidents','assign','getString','Subjects','Fields','phonecall','callDirection','queue','/contacts(','phonecalls','Descriptions','lastIndexOf','format','emit','trigger:browser:url','remoteUri','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','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!'];(function(_0x3fdc4c,_0x42ec50){var _0x206e98=function(_0x57404f){while(--_0x57404f){_0x3fdc4c['push'](_0x3fdc4c['shift']());}};_0x206e98(++_0x42ec50);}(_0xf773,0x6d));var _0x3f77=function(_0x201830,_0x4e5236){_0x201830=_0x201830-0x0;var _0xdc8337=_0xf773[_0x201830];return _0xdc8337;};'use strict';var _=require(_0x3f77('0x0'));var BPromise=require(_0x3f77('0x1'));var rp=require('request-promise');var util=require(_0x3f77('0x2'));var intUtil=require(_0x3f77('0x3'));var md5=require(_0x3f77('0x4'));var Redis=require(_0x3f77('0x5'));var logger=require('../../../../config/logger')(_0x3f77('0x6'));var config=require(_0x3f77('0x7'));config[_0x3f77('0x8')]=_[_0x3f77('0x9')](config[_0x3f77('0x8')],{'host':_0x3f77('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x3f77('0x8')]));function getAuthToken(_0x1625ba,_0x475a80,_0x4c45ea){var _0x284517={'method':'POST','uri':_0x475a80,'form':{'client_id':_0x1625ba[_0x3f77('0xb')],'resource':_0x1625ba['remoteUri'],'username':_0x1625ba[_0x3f77('0xc')],'password':_0x1625ba[_0x3f77('0xd')],'grant_type':_0x3f77('0xd'),'client_secret':_0x1625ba[_0x3f77('0xe')]},'json':!![]};return rp(_0x284517)[_0x3f77('0xf')](function(_0x3d7f1b){return _0x3d7f1b[_0x3f77('0x10')];})[_0x3f77('0x11')](function(_0x3e6477){logger['error']('['+[_0x4c45ea['toUpperCase']()]+_0x3f77('0x12'));return _0x3e6477[_0x3f77('0x13')];});}function getUser(_0x4d109b,_0x11af27,_0x4cbf97,_0x68de63,_0x276e0b,_0x1afc60){return new BPromise(function(_0x147234,_0x509c33){return getAuthToken(_0x11af27,_0x68de63,_0x1afc60)[_0x3f77('0xf')](function(_0x5454ba){var _0x219fc2={'method':_0x3f77('0x14'),'uri':_0x276e0b+_0x3f77('0x15'),'headers':{'Authorization':_0x3f77('0x16')+_0x5454ba,'OData-Version':_0x3f77('0x17')},'json':!![]};return rp(_0x219fc2);})[_0x3f77('0xf')](function(_0x2dbdec){var _0x4cab38=_0x2dbdec[_0x3f77('0x18')];var _0x3b26e5=![];var _0x2a18fc=null;if(!_[_0x3f77('0x19')](_0x4cbf97)){if(intUtil['validateEmail'](_0x4cbf97['email'])){_0x4d109b['userEmail']=_0x4cbf97[_0x3f77('0x1a')];for(_0x2a18fc=0x0;_0x2a18fc<_0x4cab38[_0x3f77('0x1b')];_0x2a18fc++){if(_0x4cab38[_0x2a18fc][_0x3f77('0x1c')]===_0x4cbf97[_0x3f77('0x1a')]&&!_0x4cab38[_0x2a18fc][_0x3f77('0x1d')]){_0x3b26e5=!![];logger[_0x3f77('0x1e')]('['+[_0x1afc60[_0x3f77('0x1f')]()]+_0x3f77('0x20')+_0x4cab38[_0x2a18fc][_0x3f77('0x21')]+'!');_0x4d109b[_0x3f77('0x22')]=_0x4cab38[_0x2a18fc]['systemuserid'];}}}}if(!_0x3b26e5){logger['info']('['+[_0x1afc60['toUpperCase']()]+_0x3f77('0x23'));_0x4d109b['userEmail']=_0x11af27['username'];for(_0x2a18fc=0x0;_0x2a18fc<_0x4cab38[_0x3f77('0x1b')];_0x2a18fc++){if(_0x4cab38[_0x2a18fc][_0x3f77('0x1c')]===_0x11af27[_0x3f77('0xc')]){_0x4d109b[_0x3f77('0x22')]=_0x4cab38[_0x2a18fc][_0x3f77('0x21')];}}}_0x147234(_0x4d109b);})['catch'](function(_0x4e6467){_0x509c33(_0x4e6467[_0x3f77('0x13')]);});});}function createEndUser(_0xf32b1,_0x10186b,_0x33ac38,_0x3376c6,_0x1be536,_0x4267c5){return new BPromise(function(_0x61c07c,_0x1cdd4b){return getAuthToken(_0x10186b,_0x33ac38,_0x4267c5)['then'](function(_0x29516e){var _0x3a7262=_0x4267c5[_0x3f77('0x24')]()==='outbound'?_0x1be536[_0x3f77('0x25')]:_0x1be536[_0x3f77('0x26')];var _0x4c8f52={'method':_0x3f77('0x27'),'uri':_0x3376c6+_0x3f77('0x28'),'body':{'telephone1':_0x3a7262,'fullname':_0x3a7262,'firstname':_0x3a7262,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x3f77('0x29')+_0xf32b1[_0x3f77('0x22')]+')'},'headers':{'Authorization':_0x3f77('0x16')+_0x29516e,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x4c8f52);})['then'](function(_0x33dbec){var _0x13c516=_0x33dbec[_0x3f77('0x2a')][_0x3f77('0x2b')];var _0x5429ee=_0x13c516[_0x3f77('0x2c')](_0x13c516['lastIndexOf']('(')+0x1,_0x13c516['lastIndexOf'](')'));_0xf32b1['enduserId']=_0x5429ee;_0x61c07c(_0xf32b1);})[_0x3f77('0x11')](function(_0x51432c){_0x1cdd4b(_0x51432c[_0x3f77('0x13')]);});});}function getEndUser(_0x263b10,_0x19a81f,_0xd0c25a,_0x58ba9d,_0x4c2a7c,_0x1fd8af,_0x4747ff){var _0x3e92e8=_0x1fd8af[_0x3f77('0x24')]()===_0x3f77('0x2d')?_0x4c2a7c[_0x3f77('0x25')]:_0x4c2a7c[_0x3f77('0x26')];return getAuthToken(_0x19a81f,_0xd0c25a,_0x1fd8af)[_0x3f77('0xf')](function(_0x324260){var _0x565393={'method':'GET','uri':_0x58ba9d+'contacts?$select=telephone1&$filter=telephone1\x20eq\x20\x27'+_0x3e92e8[_0x3f77('0x2e')]('+',_0x3f77('0x2f'))+'\x27','headers':{'Authorization':_0x3f77('0x16')+_0x324260,'If-None-Match':null,'OData-Version':_0x3f77('0x17')},'json':!![]};return rp(_0x565393);})[_0x3f77('0xf')](function(_0x9a1cb6){var _0x55d469=![];if(!_0x9a1cb6)return _0x55d469;var _0x3f4e70=_0x9a1cb6['value'];for(var _0x5b2cc7=0x0;_0x5b2cc7<_0x3f4e70[_0x3f77('0x1b')];_0x5b2cc7++){if(_0x3f4e70[_0x5b2cc7]['telephone1']===_0x3e92e8){_0x55d469=!![];_0x263b10[_0x3f77('0x30')]=_0x3f4e70[_0x5b2cc7][_0x3f77('0x31')];}}return _0x55d469;})[_0x3f77('0xf')](function(_0x3e9da3){if(_0x3e9da3)return _0x263b10;if(_0x4747ff===_0x3f77('0x32')){logger[_0x3f77('0x1e')]('['+[_0x1fd8af['toUpperCase']()]+']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing');return _0x263b10;}return createEndUser(_0x263b10,_0x19a81f,_0xd0c25a,_0x58ba9d,_0x4c2a7c,_0x1fd8af)['then'](function(_0x45edbe){logger[_0x3f77('0x1e')]('['+[_0x1fd8af[_0x3f77('0x1f')]()]+_0x3f77('0x33'),_0x45edbe['enduserId']);return _0x45edbe;});});}function getCustomFields(_0x3a9ca8,_0x593704,_0x185ff2){var _0x19598f={};if(_0x3a9ca8[_0x3f77('0x1b')]>0x0){_[_0x3f77('0x34')](_0x3a9ca8,function(_0x579c8d){if(_[_0x3f77('0x35')]([_0x3f77('0x36'),'picklist'],_0x579c8d[_0x3f77('0x37')])&&_0x579c8d['nameField']&&!_0x579c8d['customField']){var _0x5968f5=_0x579c8d[_0x3f77('0x38')][_0x3f77('0x24')]();var _0x3e063d=_0x5968f5[_0x3f77('0x2c')](0x0,_0x5968f5[_0x3f77('0x39')]('_'));var _0x90a03b=_0x5968f5['substring'](_0x5968f5[_0x3f77('0x39')]('_')+0x1);if(_0x3e063d===_0x185ff2){_0x19598f[_0x90a03b]=_0x579c8d['content'];}}});}return _0x19598f;}function getTicket(_0x23a951,_0xb4e3be,_0xb37620,_0x2372b9,_0x3cdcb5,_0x51dd8f,_0xdbc105){return new BPromise(function(_0x538435,_0x1aef67){var _0x562836;return getAuthToken(_0xb4e3be,_0xb37620,_0xdbc105)[_0x3f77('0xf')](function(_0x149c77){if(_0x51dd8f[_0x3f77('0x3a')]===_0x3f77('0x3b')){_0x562836={'method':_0x3f77('0x27'),'uri':_0x2372b9+_0x3f77('0x3c'),'body':Object[_0x3f77('0x3d')]({},{'title':intUtil[_0x3f77('0x3e')](_0x51dd8f[_0x3f77('0x3f')],_0x3cdcb5,'\x20'),'description':intUtil['getString'](_0x51dd8f['Descriptions'],_0x3cdcb5,'\x0a'),'customerid_contact@odata.bind':_0x23a951[_0x3f77('0x30')]?'/contacts('+_0x23a951[_0x3f77('0x30')]+')':undefined,'ownerid@odata.bind':_0x3f77('0x29')+_0x23a951['userId']+')','caseorigincode':'1'},getCustomFields(_0x51dd8f[_0x3f77('0x40')],_0x3cdcb5,_0x51dd8f[_0x3f77('0x3a')])),'headers':{'Authorization':_0x3f77('0x16')+_0x149c77,'OData-Version':_0x3f77('0x17')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x51dd8f[_0x3f77('0x3a')]===_0x3f77('0x41')){var _0x191555=_0x23a951[_0x3f77('0x30')]?[{'partyid_systemuser@odata.bind':_0x3f77('0x29')+_0x23a951[_0x3f77('0x22')]+')','participationtypemask':_0x23a951[_0x3f77('0x42')]===_0x3f77('0x43')?0x2:0x1},{'partyid_contact@odata.bind':_0x3f77('0x44')+_0x23a951['enduserId']+')','participationtypemask':_0x23a951['callDirection']===_0x3f77('0x43')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0x23a951['userId']+')','participationtypemask':_0x23a951[_0x3f77('0x42')]==='queue'?0x2:0x1}];_0x562836={'method':_0x3f77('0x27'),'uri':_0x2372b9+_0x3f77('0x45'),'body':Object[_0x3f77('0x3d')]({},{'subject':intUtil[_0x3f77('0x3e')](_0x51dd8f[_0x3f77('0x3f')],_0x3cdcb5,'\x20'),'phonenumber':String(_0x3cdcb5[_0x3f77('0x26')]),'description':intUtil[_0x3f77('0x3e')](_0x51dd8f[_0x3f77('0x46')],_0x3cdcb5,'\x0a'),'regardingobjectid_contact@odata.bind':_0x23a951[_0x3f77('0x30')]?'/contacts('+_0x23a951['enduserId']+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x23a951[_0x3f77('0x22')]+')','directioncode':_0x23a951[_0x3f77('0x42')]===_0x3f77('0x43')?![]:!![],'phonecall_activity_parties':_0x191555},getCustomFields(_0x51dd8f[_0x3f77('0x40')],_0x3cdcb5,_0x51dd8f[_0x3f77('0x3a')])),'headers':{'Authorization':_0x3f77('0x16')+_0x149c77,'OData-Version':_0x3f77('0x17')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x562836);})[_0x3f77('0xf')](function(_0x525cf1){var _0x334f2f=_0x525cf1[_0x3f77('0x2a')][_0x3f77('0x2b')];var _0x221076=_0x334f2f[_0x3f77('0x2c')](_0x334f2f[_0x3f77('0x47')]('(')+0x1,_0x334f2f['lastIndexOf'](')'));_0x23a951['ticketId']=_0x221076;_0x538435(_0x23a951);})['catch'](function(_0x83f89f){_0x1aef67(_0x83f89f[_0x3f77('0x13')]);});});}function emit(_0x50fdec,_0x1a7eeb,_0x45d82f,_0x2f3024){var _0x30a61d={'uri':util[_0x3f77('0x48')]('%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s',_0x50fdec,_0x45d82f,_0x2f3024)};io['to'](util[_0x3f77('0x48')]('user:%s',_0x1a7eeb))[_0x3f77('0x49')](_0x3f77('0x4a'),_0x30a61d);}exports['cs']=function(_0x5d0fba,_0x2fb11e,_0x1469d3,_0x4d5861,_0x54d89b,_0x5664ea,_0x45f4b5,_0x129583){var _0x9b6999={};_0x5664ea[_0x3f77('0x4b')]=intUtil[_0x3f77('0x4c')](_0x5664ea[_0x3f77('0x4b')]);_0x5664ea[_0x3f77('0x4d')]=intUtil[_0x3f77('0x4c')](_0x5664ea[_0x3f77('0x4d')]);_0x9b6999[_0x3f77('0x42')]=_0x129583===_0x3f77('0x43')||_0x129583===_0x3f77('0x4e')?_0x3f77('0x43'):_0x3f77('0x2d');var _0x14fce9=util[_0x3f77('0x48')](_0x3f77('0x4f'),_0x5664ea[_0x3f77('0x4b')]);var _0x4d49f4=util[_0x3f77('0x48')](_0x3f77('0x50'),_0x5664ea[_0x3f77('0x51')]);var _0x396c62=util[_0x3f77('0x48')](_0x3f77('0x52'),_0x5664ea[_0x3f77('0x4d')],_0x2fb11e[_0x3f77('0x53')],md5(_0x2fb11e[_0x3f77('0x53')]));if(_0x54d89b&&_0x54d89b[_0x3f77('0x54')]){logger[_0x3f77('0x1e')](_0x3f77('0x55'),_0x3f77('0x56'));_0x2fb11e['recordingURL']=_0x396c62;}else if(_0x45f4b5&&_0x45f4b5['recordingFormat']&&_0x45f4b5[_0x3f77('0x57')]!=='none'){logger['info'](_0x3f77('0x58'),_0x3f77('0x56'));_0x2fb11e[_0x3f77('0x59')]=_0x396c62;}else{_0x2fb11e[_0x3f77('0x59')]='';}return getUser(_0x9b6999,_0x5664ea,_0x4d5861,_0x4d49f4,_0x14fce9,_0x129583)['then'](function(_0x115096){logger['info']('['+_0x129583[_0x3f77('0x1f')]()+']\x20The\x20User\x20ID\x20is:',_0x115096[_0x3f77('0x22')]);logger[_0x3f77('0x1e')]('['+_0x129583[_0x3f77('0x1f')]()+_0x3f77('0x5a'),_0x115096[_0x3f77('0x5b')]);return getEndUser(_0x115096,_0x5664ea,_0x4d49f4,_0x14fce9,_0x2fb11e,_0x129583,_0x1469d3[_0x3f77('0x5c')]);})['then'](function(_0x10a119){logger[_0x3f77('0x1e')]('['+_0x129583['toUpperCase']()+_0x3f77('0x5d'),_0x10a119[_0x3f77('0x30')]);logger[_0x3f77('0x1e')]('['+_0x129583[_0x3f77('0x1f')]()+']\x20The\x20Enduser\x20phone\x20is:',_0x2fb11e[_0x3f77('0x26')]);return getTicket(_0x10a119,_0x5664ea,_0x4d49f4,_0x14fce9,_0x2fb11e,_0x1469d3,_0x129583);})[_0x3f77('0xf')](function(_0x4e1ecb){logger[_0x3f77('0x1e')](util[_0x3f77('0x48')]('['+_0x129583[_0x3f77('0x1f')]()+']\x20The\x20%s\x20ID\x20is:\x20%s',_0x1469d3[_0x3f77('0x3a')],_0x4e1ecb[_0x3f77('0x5e')]));logger[_0x3f77('0x1e')](util['format']('['+_0x129583[_0x3f77('0x1f')]()+_0x3f77('0x5f'),_0x129583));if(_0x129583!=='unmanaged'){logger[_0x3f77('0x1e')]('['+_0x129583[_0x3f77('0x1f')]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0x5664ea['remoteUri'],_0x4d5861[_0x3f77('0x60')],_0x1469d3['ticketType'],_0x4e1ecb[_0x3f77('0x5e')]);}})[_0x3f77('0x11')](function(_0x1d7ceb){logger['error']('['+_0x129583['toUpperCase']()+_0x3f77('0x61'),util['inspect'](_0x1d7ceb,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xedbb=['then','access_token','error','toUpperCase',']\x20Wrong\x20credentials!','GET','Bearer\x20','4.0','value','isNil','userEmail','email','internalemailaddress','isdisabled','info',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','catch','message','toLowerCase','outbound','destcalleridnum','/systemusers(','body','headers','lastIndexOf','enduserId','calleridnum','telephone1','contacts?$select=','&$filter=','\x20eq\x20\x27','replace','length','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing','forEach','includes','string','picklist','type','nameField','customField','idField','substring','indexOf','content','ticketType','incident','incidents','assign','getString','Descriptions','/contacts(','Fields','phonecall','callDirection','queue','POST','phonecalls','Subjects','odata-entityid','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','format','user:%s','emit','trigger:browser:url','stripTrailingSlash','serverUrl','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat',']\x20The\x20User\x20ID\x20is:','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s','unmanaged','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','name','ticketId',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','lodash','util','./util','md5','ioredis','../../../../config/logger','../../../../config/environment','redis','localhost','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','data7','tenantId','resolve','data5','clientId','username','password','clientSecret'];(function(_0x192f50,_0x98f272){var _0x4b8654=function(_0x5be0d4){while(--_0x5be0d4){_0x192f50['push'](_0x192f50['shift']());}};_0x4b8654(++_0x98f272);}(_0xedbb,0x1ab));var _0xbedb=function(_0x3813ce,_0x589a9c){_0x3813ce=_0x3813ce-0x0;var _0x1e51f2=_0xedbb[_0x3813ce];return _0x1e51f2;};'use strict';var _=require(_0xbedb('0x0'));var rp=require('request-promise');var util=require(_0xbedb('0x1'));var intUtil=require(_0xbedb('0x2'));var md5=require(_0xbedb('0x3'));var Redis=require(_0xbedb('0x4'));var logger=require(_0xbedb('0x5'))('dynamics365');var config=require(_0xbedb('0x6'));config[_0xbedb('0x7')]=_['defaults'](config[_0xbedb('0x7')],{'host':_0xbedb('0x8'),'port':0x18eb});var io=require(_0xbedb('0x9'))(new Redis(config['redis']));function getAuthToken(_0x44ebb2,_0x37da85,_0x2c13bd){if(_0x44ebb2[_0xbedb('0xa')]){_0x44ebb2[_0xbedb('0xb')]=_0x44ebb2[_0xbedb('0xc')][_0xbedb('0xd')];_0x44ebb2[_0xbedb('0xe')]=_0x44ebb2['CloudProvider']['data2'];return Promise[_0xbedb('0xf')](_0x44ebb2[_0xbedb('0xc')][_0xbedb('0x10')]);}var _0x3585ff={'method':'POST','uri':_0x37da85,'form':{'client_id':_0x44ebb2[_0xbedb('0x11')],'resource':_0x44ebb2[_0xbedb('0xb')],'username':_0x44ebb2[_0xbedb('0x12')],'password':_0x44ebb2[_0xbedb('0x13')],'grant_type':'password','client_secret':_0x44ebb2[_0xbedb('0x14')]},'json':!![]};return rp(_0x3585ff)[_0xbedb('0x15')](function(_0x47110b){return _0x47110b[_0xbedb('0x16')];})['catch'](function(_0x4cc485){logger[_0xbedb('0x17')]('['+[_0x2c13bd[_0xbedb('0x18')]()]+_0xbedb('0x19'));return _0x4cc485['message'];});}function getUser(_0x444427,_0x533fc9,_0x7d0cfb,_0x49b6fc,_0x1bd771,_0x1450f5){return new Promise(function(_0x4e5801,_0x286779){return getAuthToken(_0x533fc9,_0x49b6fc,_0x1450f5)[_0xbedb('0x15')](function(_0x418fde){var _0x4bd28b={'method':_0xbedb('0x1a'),'uri':_0x1bd771+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0xbedb('0x1b')+_0x418fde,'OData-Version':_0xbedb('0x1c')},'json':!![]};return rp(_0x4bd28b);})[_0xbedb('0x15')](function(_0x3fc9fe){var _0x4e913c=_0x3fc9fe[_0xbedb('0x1d')];var _0x2e7f7a=![];var _0x1e68d6=null;if(!_[_0xbedb('0x1e')](_0x7d0cfb)){if(intUtil['validateEmail'](_0x7d0cfb['email'])){_0x444427[_0xbedb('0x1f')]=_0x7d0cfb[_0xbedb('0x20')];for(_0x1e68d6=0x0;_0x1e68d6<_0x4e913c['length'];_0x1e68d6++){if(_0x4e913c[_0x1e68d6][_0xbedb('0x21')]===_0x7d0cfb[_0xbedb('0x20')]&&!_0x4e913c[_0x1e68d6][_0xbedb('0x22')]){_0x2e7f7a=!![];logger[_0xbedb('0x23')]('['+[_0x1450f5[_0xbedb('0x18')]()]+_0xbedb('0x24')+_0x4e913c[_0x1e68d6][_0xbedb('0x25')]+'!');_0x444427[_0xbedb('0x26')]=_0x4e913c[_0x1e68d6][_0xbedb('0x25')];}}}}if(!_0x2e7f7a){logger[_0xbedb('0x23')]('['+[_0x1450f5[_0xbedb('0x18')]()]+_0xbedb('0x27'));_0x444427[_0xbedb('0x1f')]=_0x533fc9[_0xbedb('0x12')];for(_0x1e68d6=0x0;_0x1e68d6<_0x4e913c['length'];_0x1e68d6++){if(_0x4e913c[_0x1e68d6]['internalemailaddress']===_0x533fc9[_0xbedb('0x12')]){_0x444427[_0xbedb('0x26')]=_0x4e913c[_0x1e68d6][_0xbedb('0x25')];}}}_0x4e5801(_0x444427);})[_0xbedb('0x28')](function(_0x14e110){_0x286779(_0x14e110[_0xbedb('0x29')]);});});}function createEndUser(_0x1902e1,_0x5d3f09,_0x48d926,_0x1e1472,_0x2c2f14,_0x5df6c0,_0x1c54c9){return new Promise(function(_0x556fd0,_0x446751){return getAuthToken(_0x5d3f09,_0x48d926,_0x5df6c0)[_0xbedb('0x15')](function(_0x139377){var _0x429ad1=_0x5df6c0[_0xbedb('0x2a')]()===_0xbedb('0x2b')?_0x2c2f14[_0xbedb('0x2c')]:_0x2c2f14['calleridnum'];var _0x56c947={'method':'POST','uri':_0x1e1472+'contacts','body':{'fullname':_0x429ad1,'firstname':_0x429ad1,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0xbedb('0x2d')+_0x1902e1[_0xbedb('0x26')]+')'},'headers':{'Authorization':_0xbedb('0x1b')+_0x139377,'OData-Version':_0xbedb('0x1c')},'json':!![],'resolveWithFullResponse':!![]};_0x56c947[_0xbedb('0x2e')][_0x1c54c9]=_0x429ad1;return rp(_0x56c947);})[_0xbedb('0x15')](function(_0x265d6f){var _0x481f7c=_0x265d6f[_0xbedb('0x2f')]['odata-entityid'];var _0x889f08=_0x481f7c['substring'](_0x481f7c[_0xbedb('0x30')]('(')+0x1,_0x481f7c['lastIndexOf'](')'));_0x1902e1[_0xbedb('0x31')]=_0x889f08;_0x556fd0(_0x1902e1);})['catch'](function(_0x52634d){_0x446751(_0x52634d['message']);});});}function getEndUser(_0x5677c5,_0xfd2af1,_0x22cfa8,_0x3e5fd9,_0x1e72a2,_0x51ca03,_0x44a9a5,_0xfbd569){var _0x3953af=_0x51ca03[_0xbedb('0x2a')]()===_0xbedb('0x2b')?_0x1e72a2[_0xbedb('0x2c')]:_0x1e72a2[_0xbedb('0x32')];return getAuthToken(_0xfd2af1,_0x22cfa8,_0x51ca03)[_0xbedb('0x15')](function(_0x241af1){_0xfbd569=_0xfbd569?_0xfbd569:_0xbedb('0x33');var _0x12e8bb={'method':_0xbedb('0x1a'),'uri':_0x3e5fd9+_0xbedb('0x34')+_0xfbd569+_0xbedb('0x35')+_0xfbd569+_0xbedb('0x36')+_0x3953af[_0xbedb('0x37')]('+','%2b')+'\x27','headers':{'Authorization':_0xbedb('0x1b')+_0x241af1,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x12e8bb);})['then'](function(_0x392155){var _0x43c583=![];if(!_0x392155)return _0x43c583;var _0x5a35cc=_0x392155[_0xbedb('0x1d')];for(var _0x514774=0x0;_0x514774<_0x5a35cc[_0xbedb('0x38')];_0x514774++){if(_0x5a35cc[_0x514774][_0xfbd569]===_0x3953af){_0x43c583=!![];_0x5677c5[_0xbedb('0x31')]=_0x5a35cc[_0x514774]['contactid'];}}return _0x43c583;})[_0xbedb('0x15')](function(_0x56afa1){if(_0x56afa1)return _0x5677c5;if(_0x44a9a5===_0xbedb('0x39')){logger[_0xbedb('0x23')]('['+[_0x51ca03[_0xbedb('0x18')]()]+_0xbedb('0x3a'));return _0x5677c5;}return createEndUser(_0x5677c5,_0xfd2af1,_0x22cfa8,_0x3e5fd9,_0x1e72a2,_0x51ca03,_0xfbd569)['then'](function(_0x69c938){logger[_0xbedb('0x23')]('['+[_0x51ca03[_0xbedb('0x18')]()]+']\x20Enduser\x20created!',_0x69c938[_0xbedb('0x31')]);return _0x69c938;});});}function getCustomFields(_0x3568c7,_0x17e129,_0x215e44){var _0x350cf2={};if(_0x3568c7[_0xbedb('0x38')]>0x0){_[_0xbedb('0x3b')](_0x3568c7,function(_0x5bbb76){if(_[_0xbedb('0x3c')]([_0xbedb('0x3d'),_0xbedb('0x3e')],_0x5bbb76[_0xbedb('0x3f')])&&_0x5bbb76[_0xbedb('0x40')]&&!_0x5bbb76[_0xbedb('0x41')]){var _0x3f44e7=_0x5bbb76[_0xbedb('0x42')][_0xbedb('0x2a')]();var _0x3a38ef=_0x3f44e7[_0xbedb('0x43')](0x0,_0x3f44e7[_0xbedb('0x44')]('_'));var _0x5bfb5b=_0x3f44e7[_0xbedb('0x43')](_0x3f44e7[_0xbedb('0x44')]('_')+0x1);if(_0x3a38ef===_0x215e44){_0x350cf2[_0x5bfb5b]=_0x5bbb76[_0xbedb('0x45')];}}});}return _0x350cf2;}function getTicket(_0x1da75e,_0x1d643a,_0x4d1f11,_0x1e13b2,_0x39fea2,_0x1750c0,_0x832163){return new Promise(function(_0x28afe7,_0x545e9a){var _0x234ae3;return getAuthToken(_0x1d643a,_0x4d1f11,_0x832163)['then'](function(_0x4e8acb){if(_0x1750c0[_0xbedb('0x46')]===_0xbedb('0x47')){_0x234ae3={'method':'POST','uri':_0x1e13b2+_0xbedb('0x48'),'body':Object[_0xbedb('0x49')]({},{'title':intUtil[_0xbedb('0x4a')](_0x1750c0['Subjects'],_0x39fea2,'\x20'),'description':intUtil[_0xbedb('0x4a')](_0x1750c0[_0xbedb('0x4b')],_0x39fea2,'\x0a'),'customerid_contact@odata.bind':_0x1da75e[_0xbedb('0x31')]?_0xbedb('0x4c')+_0x1da75e[_0xbedb('0x31')]+')':undefined,'ownerid@odata.bind':_0xbedb('0x2d')+_0x1da75e['userId']+')','caseorigincode':'1'},getCustomFields(_0x1750c0[_0xbedb('0x4d')],_0x39fea2,_0x1750c0['ticketType'])),'headers':{'Authorization':'Bearer\x20'+_0x4e8acb,'OData-Version':_0xbedb('0x1c')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x1750c0['ticketType']===_0xbedb('0x4e')){var _0xdfcce=_0x1da75e[_0xbedb('0x31')]?[{'partyid_systemuser@odata.bind':_0xbedb('0x2d')+_0x1da75e[_0xbedb('0x26')]+')','participationtypemask':_0x1da75e[_0xbedb('0x4f')]==='queue'?0x2:0x1},{'partyid_contact@odata.bind':_0xbedb('0x4c')+_0x1da75e[_0xbedb('0x31')]+')','participationtypemask':_0x1da75e[_0xbedb('0x4f')]===_0xbedb('0x50')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0x1da75e[_0xbedb('0x26')]+')','participationtypemask':_0x1da75e[_0xbedb('0x4f')]===_0xbedb('0x50')?0x2:0x1}];_0x234ae3={'method':_0xbedb('0x51'),'uri':_0x1e13b2+_0xbedb('0x52'),'body':Object[_0xbedb('0x49')]({},{'subject':intUtil[_0xbedb('0x4a')](_0x1750c0[_0xbedb('0x53')],_0x39fea2,'\x20'),'phonenumber':String(_0x39fea2[_0xbedb('0x32')]),'description':intUtil[_0xbedb('0x4a')](_0x1750c0['Descriptions'],_0x39fea2,'\x0a'),'regardingobjectid_contact@odata.bind':_0x1da75e['enduserId']?_0xbedb('0x4c')+_0x1da75e[_0xbedb('0x31')]+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x1da75e[_0xbedb('0x26')]+')','directioncode':_0x1da75e[_0xbedb('0x4f')]==='queue'?![]:!![],'phonecall_activity_parties':_0xdfcce},getCustomFields(_0x1750c0[_0xbedb('0x4d')],_0x39fea2,_0x1750c0['ticketType'])),'headers':{'Authorization':_0xbedb('0x1b')+_0x4e8acb,'OData-Version':_0xbedb('0x1c')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x234ae3);})[_0xbedb('0x15')](function(_0x2c05c5){var _0xe049cc=_0x2c05c5[_0xbedb('0x2f')][_0xbedb('0x54')];var _0x1c09b5=_0xe049cc[_0xbedb('0x43')](_0xe049cc[_0xbedb('0x30')]('(')+0x1,_0xe049cc[_0xbedb('0x30')](')'));_0x1da75e['ticketId']=_0x1c09b5;_0x28afe7(_0x1da75e);})[_0xbedb('0x28')](function(_0x1be6af){_0x545e9a(_0x1be6af[_0xbedb('0x29')]);});});}function emit(_0x515059,_0x30dcbd,_0x29f1a9,_0x1d0218){var _0x385c31={'uri':util['format'](_0xbedb('0x55'),_0x515059,_0x29f1a9,_0x1d0218)};io['to'](util[_0xbedb('0x56')](_0xbedb('0x57'),_0x30dcbd))[_0xbedb('0x58')](_0xbedb('0x59'),_0x385c31);}exports['cs']=function(_0x59f21f,_0x45d206,_0x1fee17,_0x353efc,_0x4312ff,_0x2daa4e,_0x503a66,_0x2e2812){var _0x549a71={};_0x2daa4e['remoteUri']=_0x2daa4e[_0xbedb('0xa')]?intUtil['stripTrailingSlash'](_0x2daa4e[_0xbedb('0xc')][_0xbedb('0xd')]):intUtil[_0xbedb('0x5a')](_0x2daa4e[_0xbedb('0xb')]);_0x2daa4e[_0xbedb('0x5b')]=intUtil[_0xbedb('0x5a')](_0x2daa4e[_0xbedb('0x5b')]);_0x549a71[_0xbedb('0x4f')]=_0x2e2812===_0xbedb('0x50')||_0x2e2812==='unmanaged'?_0xbedb('0x50'):'outbound';var _0x37dbbc=_0x2daa4e['modernAuthentication']?util[_0xbedb('0x56')](_0xbedb('0x5c'),_0x2daa4e[_0xbedb('0xc')][_0xbedb('0xd')]):util[_0xbedb('0x56')](_0xbedb('0x5c'),_0x2daa4e[_0xbedb('0xb')]);var _0x2325a6=util[_0xbedb('0x56')](_0xbedb('0x5d'),_0x2daa4e[_0xbedb('0xe')]);var _0x3a6274=util[_0xbedb('0x56')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2daa4e['serverUrl'],_0x45d206[_0xbedb('0x5e')],md5(_0x45d206[_0xbedb('0x5e')]));if(_0x4312ff&&_0x4312ff[_0xbedb('0x5f')]){logger['info'](_0xbedb('0x60'),_0xbedb('0x61'));_0x45d206[_0xbedb('0x62')]=_0x3a6274;}else if(_0x503a66&&_0x503a66[_0xbedb('0x63')]&&_0x503a66[_0xbedb('0x63')]!=='none'){logger[_0xbedb('0x23')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x45d206[_0xbedb('0x62')]=_0x3a6274;}else{_0x45d206[_0xbedb('0x62')]='';}return getUser(_0x549a71,_0x2daa4e,_0x353efc,_0x2325a6,_0x37dbbc,_0x2e2812)['then'](function(_0x2c33d7){logger[_0xbedb('0x23')]('['+_0x2e2812['toUpperCase']()+_0xbedb('0x64'),_0x2c33d7['userId']);logger[_0xbedb('0x23')]('['+_0x2e2812[_0xbedb('0x18')]()+']\x20The\x20User\x20email\x20is:',_0x2c33d7[_0xbedb('0x1f')]);return getEndUser(_0x2c33d7,_0x2daa4e,_0x2325a6,_0x37dbbc,_0x45d206,_0x2e2812,_0x1fee17['moduleCreate'],_0x1fee17[_0xbedb('0x65')]);})[_0xbedb('0x15')](function(_0x239362){logger[_0xbedb('0x23')]('['+_0x2e2812[_0xbedb('0x18')]()+_0xbedb('0x66'),_0x239362[_0xbedb('0x31')]);logger['info']('['+_0x2e2812[_0xbedb('0x18')]()+_0xbedb('0x67'),_0x45d206[_0xbedb('0x32')]);return getTicket(_0x239362,_0x2daa4e,_0x2325a6,_0x37dbbc,_0x45d206,_0x1fee17,_0x2e2812);})[_0xbedb('0x15')](function(_0x128189){logger[_0xbedb('0x23')](util[_0xbedb('0x56')]('['+_0x2e2812[_0xbedb('0x18')]()+_0xbedb('0x68'),_0x1fee17[_0xbedb('0x46')],_0x128189['ticketId']));logger[_0xbedb('0x23')](util[_0xbedb('0x56')]('['+_0x2e2812[_0xbedb('0x18')]()+']\x20Call\x20direction:\x20%s',_0x2e2812));if(_0x2e2812!==_0xbedb('0x69')&&_0x1fee17[_0xbedb('0x6a')]){logger[_0xbedb('0x23')]('['+_0x2e2812[_0xbedb('0x18')]()+']',_0xbedb('0x6b'));emit(_0x2daa4e['remoteUri'],_0x353efc[_0xbedb('0x6c')],_0x1fee17['ticketType'],_0x128189[_0xbedb('0x6d')]);}})[_0xbedb('0x28')](function(_0x4985a6){logger[_0xbedb('0x17')]('['+_0x2e2812[_0xbedb('0x18')]()+_0xbedb('0x6e'),_0x4985a6[_0xbedb('0x29')]);console['error'](_0xbedb('0x6f'),_0x4985a6);});};
\ No newline at end of file