Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index 32175fb..5e7585d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1bf7=['outbound','destcalleridnum','calleridnum','contacts','headers','odata-entityid','lastIndexOf','contacts?$select=telephone1','telephone1','enduserId',']\x20Enduser\x20Created!','forEach','type','string','nameField','idField','substring','indexOf','content','ticketType','incident','incidents','getString','Subjects','Descriptions','/contacts(','/systemusers(','Fields','phonecalls','assign','queue','callDirection','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','emit','remoteUri','serverUrl','stripTrailingSlash','tenantId','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:',']\x20The\x20User\x20email\x20is:','userEmail',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','unmanaged','Displaying\x20call\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Dynamics365\x20integration','inspect','./util','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','POST','username','clientSecret','then','access_token','catch','error','toUpperCase',']\x20Wrong\x20credentials!','message','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','isNil','validateEmail','email','length','isdisabled',']\x20Agent\x20found\x20','systemuserid','info',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','internalemailaddress','userId'];(function(_0x29dbbd,_0x410267){var _0x1ea22f=function(_0x34fa26){while(--_0x34fa26){_0x29dbbd['push'](_0x29dbbd['shift']());}};_0x1ea22f(++_0x410267);}(_0x1bf7,0x1b4));var _0x71bf=function(_0x3d0e12,_0x41e165){_0x3d0e12=_0x3d0e12-0x0;var _0x22da51=_0x1bf7[_0x3d0e12];return _0x22da51;};'use strict';var _=require('lodash');var BPromise=require('bluebird');var rp=require('request-promise');var util=require('util');var intUtil=require(_0x71bf('0x0'));var md5=require('md5');var Redis=require(_0x71bf('0x1'));var logger=require(_0x71bf('0x2'))(_0x71bf('0x3'));var config=require(_0x71bf('0x4'));config[_0x71bf('0x5')]=_[_0x71bf('0x6')](config[_0x71bf('0x5')],{'host':_0x71bf('0x7'),'port':0x18eb});var io=require(_0x71bf('0x8'))(new Redis(config[_0x71bf('0x5')]));function getAuthToken(_0x5524e6,_0x58579b,_0x158f03){var _0x1bbbb3={'method':_0x71bf('0x9'),'uri':_0x58579b,'form':{'client_id':_0x5524e6['clientId'],'resource':_0x5524e6['remoteUri'],'username':_0x5524e6[_0x71bf('0xa')],'password':_0x5524e6['password'],'grant_type':'password','client_secret':_0x5524e6[_0x71bf('0xb')]},'json':!![]};return rp(_0x1bbbb3)[_0x71bf('0xc')](function(_0xa60440){return _0xa60440[_0x71bf('0xd')];})[_0x71bf('0xe')](function(_0x2e724b){logger[_0x71bf('0xf')]('['+[_0x158f03[_0x71bf('0x10')]()]+_0x71bf('0x11'));return _0x2e724b[_0x71bf('0x12')];});}function getUser(_0x4fb124,_0xdf8a03,_0x462c27,_0x22874c,_0x100f06,_0x5cf6e0){return new BPromise(function(_0x32cc47,_0x46179d){return getAuthToken(_0xdf8a03,_0x22874c,_0x5cf6e0)[_0x71bf('0xc')](function(_0x14f48a){var _0x4a7eb0={'method':_0x71bf('0x13'),'uri':_0x100f06+_0x71bf('0x14'),'headers':{'Authorization':_0x71bf('0x15')+_0x14f48a,'OData-Version':_0x71bf('0x16')},'json':!![]};return rp(_0x4a7eb0);})[_0x71bf('0xc')](function(_0x37e07e){var _0x21301c=_0x37e07e['value'];var _0xa4dfee=![];var _0x15841a=null;if(!_[_0x71bf('0x17')](_0x462c27)){if(intUtil[_0x71bf('0x18')](_0x462c27[_0x71bf('0x19')])){_0x4fb124['userEmail']=_0x462c27['email'];for(_0x15841a=0x0;_0x15841a<_0x21301c[_0x71bf('0x1a')];_0x15841a++){if(_0x21301c[_0x15841a]['internalemailaddress']===_0x462c27[_0x71bf('0x19')]&&!_0x21301c[_0x15841a][_0x71bf('0x1b')]){_0xa4dfee=!![];logger['info']('['+[_0x5cf6e0['toUpperCase']()]+_0x71bf('0x1c')+_0x21301c[_0x15841a]['systemuserid']+'!');_0x4fb124['userId']=_0x21301c[_0x15841a][_0x71bf('0x1d')];}}}}if(!_0xa4dfee){logger[_0x71bf('0x1e')]('['+[_0x5cf6e0[_0x71bf('0x10')]()]+_0x71bf('0x1f'));_0x4fb124['userEmail']=_0xdf8a03[_0x71bf('0xa')];for(_0x15841a=0x0;_0x15841a<_0x21301c[_0x71bf('0x1a')];_0x15841a++){if(_0x21301c[_0x15841a][_0x71bf('0x20')]===_0xdf8a03[_0x71bf('0xa')]){_0x4fb124[_0x71bf('0x21')]=_0x21301c[_0x15841a]['systemuserid'];}}}_0x32cc47(_0x4fb124);})['catch'](function(_0x5919a1){_0x46179d(_0x5919a1[_0x71bf('0x12')]);});});}function createEndUser(_0x38abb2,_0x5b3d29,_0xbf1ba4,_0x99f272,_0x501b67,_0x30d4b5){return new BPromise(function(_0x58cae5,_0x599d39){return getAuthToken(_0x5b3d29,_0xbf1ba4,_0x30d4b5)[_0x71bf('0xc')](function(_0x2a4823){var _0x18f41d=_0x30d4b5['toLowerCase']()===_0x71bf('0x22')?_0x501b67[_0x71bf('0x23')]:_0x501b67[_0x71bf('0x24')];var _0x45213a={'method':_0x71bf('0x9'),'uri':_0x99f272+_0x71bf('0x25'),'body':{'telephone1':_0x18f41d,'fullname':_0x18f41d,'firstname':_0x18f41d,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x38abb2['userId']+')'},'headers':{'Authorization':_0x71bf('0x15')+_0x2a4823,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x45213a);})[_0x71bf('0xc')](function(_0x12c0c8){var _0x4546e2=_0x12c0c8[_0x71bf('0x26')][_0x71bf('0x27')];var _0x37c8ea=_0x4546e2['substring'](_0x4546e2[_0x71bf('0x28')]('(')+0x1,_0x4546e2[_0x71bf('0x28')](')'));_0x38abb2['enduserId']=_0x37c8ea;_0x58cae5(_0x38abb2);})[_0x71bf('0xe')](function(_0x4779de){_0x599d39(_0x4779de[_0x71bf('0x12')]);});});}function getEndUser(_0x4f18d8,_0x315ae1,_0x3a5a4d,_0x41fee7,_0x10f06f,_0x286fc8){return new BPromise(function(_0x134f36,_0x20fcb4){return getAuthToken(_0x315ae1,_0x3a5a4d,_0x286fc8)[_0x71bf('0xc')](function(_0x13ffa2){var _0x380331={'method':_0x71bf('0x13'),'uri':_0x41fee7+_0x71bf('0x29'),'headers':{'Authorization':'Bearer\x20'+_0x13ffa2,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x380331);})[_0x71bf('0xc')](function(_0x585615){var _0x5d32df=null;if(_0x585615){var _0x42c7a5=_0x585615['value'];var _0x4f6133=![];for(_0x5d32df=0x0;_0x5d32df<_0x42c7a5[_0x71bf('0x1a')];_0x5d32df++){var _0x36555c=_0x286fc8['toLowerCase']()===_0x71bf('0x22')?_0x10f06f['destcalleridnum']:_0x10f06f['calleridnum'];if(_0x42c7a5[_0x5d32df][_0x71bf('0x2a')]===_0x36555c){_0x4f6133=!![];_0x4f18d8[_0x71bf('0x2b')]=_0x42c7a5[_0x5d32df]['contactid'];}}if(_0x4f6133){_0x134f36(_0x4f18d8);}else{return createEndUser(_0x4f18d8,_0x315ae1,_0x3a5a4d,_0x41fee7,_0x10f06f,_0x286fc8)[_0x71bf('0xc')](function(_0x4e5788){logger[_0x71bf('0x1e')]('['+[_0x286fc8['toUpperCase']()]+']\x20Enduser\x20created!',_0x4e5788[_0x71bf('0x2b')]);_0x134f36(_0x4e5788);});}}else{return createEndUser(_0x4f18d8,_0x315ae1,_0x3a5a4d,_0x41fee7,_0x10f06f,_0x286fc8)[_0x71bf('0xc')](function(_0x54d3bf){logger[_0x71bf('0x1e')]('['+[_0x286fc8[_0x71bf('0x10')]()]+_0x71bf('0x2c'),_0x54d3bf[_0x71bf('0x2b')]);_0x134f36(_0x54d3bf);});}});});}function getCustomFields(_0x4f00d3,_0x339540,_0x2dfaae){var _0x4dbf78={};if(_0x4f00d3[_0x71bf('0x1a')]>0x0){_[_0x71bf('0x2d')](_0x4f00d3,function(_0x5dab67){if(_0x5dab67[_0x71bf('0x2e')]===_0x71bf('0x2f')&&_0x5dab67[_0x71bf('0x30')]&&!_0x5dab67['customField']){var _0xf58c43=_0x5dab67[_0x71bf('0x31')]['toLowerCase']();var _0x2b0eea=_0xf58c43[_0x71bf('0x32')](0x0,_0xf58c43[_0x71bf('0x33')]('_'));var _0x80df3a=_0xf58c43[_0x71bf('0x32')](_0xf58c43['indexOf']('_')+0x1);if(_0x2b0eea===_0x2dfaae){_0x4dbf78[_0x80df3a]=_0x5dab67[_0x71bf('0x34')];}}});}return _0x4dbf78;}function getTicket(_0x3ca51b,_0x3d8731,_0x2c4776,_0x1235c2,_0x26579c,_0x46f5a3,_0x47c8d9){return new BPromise(function(_0x1af5c5,_0x27dbfe){var _0x1355e9;return getAuthToken(_0x3d8731,_0x2c4776,_0x47c8d9)['then'](function(_0x458020){if(_0x46f5a3[_0x71bf('0x35')]===_0x71bf('0x36')){_0x1355e9={'method':_0x71bf('0x9'),'uri':_0x1235c2+_0x71bf('0x37'),'body':Object['assign']({},{'title':intUtil[_0x71bf('0x38')](_0x46f5a3[_0x71bf('0x39')],_0x26579c,'\x20'),'description':intUtil[_0x71bf('0x38')](_0x46f5a3[_0x71bf('0x3a')],_0x26579c,'\x0a'),'customerid_contact@odata.bind':_0x71bf('0x3b')+_0x3ca51b[_0x71bf('0x2b')]+')','ownerid@odata.bind':_0x71bf('0x3c')+_0x3ca51b['userId']+')','caseorigincode':'1'},getCustomFields(_0x46f5a3[_0x71bf('0x3d')],_0x26579c,_0x46f5a3[_0x71bf('0x35')])),'headers':{'Authorization':_0x71bf('0x15')+_0x458020,'OData-Version':_0x71bf('0x16')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x46f5a3[_0x71bf('0x35')]==='phonecall'){_0x1355e9={'method':_0x71bf('0x9'),'uri':_0x1235c2+_0x71bf('0x3e'),'body':Object[_0x71bf('0x3f')]({},{'subject':intUtil[_0x71bf('0x38')](_0x46f5a3['Subjects'],_0x26579c,'\x20'),'phonenumber':String(_0x26579c['calleridnum']),'description':intUtil[_0x71bf('0x38')](_0x46f5a3[_0x71bf('0x3a')],_0x26579c,'\x0a'),'regardingobjectid_contact@odata.bind':_0x71bf('0x3b')+_0x3ca51b[_0x71bf('0x2b')]+')','ownerid@odata.bind':_0x71bf('0x3c')+_0x3ca51b[_0x71bf('0x21')]+')','directioncode':_0x3ca51b['callDirection']===_0x71bf('0x40')?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':_0x71bf('0x3c')+_0x3ca51b[_0x71bf('0x21')]+')','participationtypemask':_0x3ca51b[_0x71bf('0x41')]===_0x71bf('0x40')?0x2:0x1},{'partyid_contact@odata.bind':_0x71bf('0x3b')+_0x3ca51b[_0x71bf('0x2b')]+')','participationtypemask':_0x3ca51b[_0x71bf('0x41')]===_0x71bf('0x40')?0x1:0x2}]},getCustomFields(_0x46f5a3[_0x71bf('0x3d')],_0x26579c,_0x46f5a3[_0x71bf('0x35')])),'headers':{'Authorization':'Bearer\x20'+_0x458020,'OData-Version':_0x71bf('0x16')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x1355e9);})[_0x71bf('0xc')](function(_0x470dc0){var _0x2ba32a=_0x470dc0[_0x71bf('0x26')][_0x71bf('0x27')];var _0x1aca9e=_0x2ba32a[_0x71bf('0x32')](_0x2ba32a['lastIndexOf']('(')+0x1,_0x2ba32a[_0x71bf('0x28')](')'));_0x3ca51b[_0x71bf('0x42')]=_0x1aca9e;_0x1af5c5(_0x3ca51b);})[_0x71bf('0xe')](function(_0x35da98){_0x27dbfe(_0x35da98[_0x71bf('0x12')]);});});}function emit(_0x564d49,_0x5c3617,_0xdac919,_0xb39077){var _0x569cd7={'uri':util[_0x71bf('0x43')](_0x71bf('0x44'),_0x564d49,_0xdac919,_0xb39077)};io['to'](util[_0x71bf('0x43')]('user:%s',_0x5c3617))[_0x71bf('0x45')]('trigger:browser:url',_0x569cd7);}exports['cs']=function(_0x20fc86,_0x49b648,_0x3a9c1e,_0x37acf0,_0x393eb3,_0x2f4d66,_0x5f397b,_0x4efb5f){var _0x2eed4f={};_0x2f4d66[_0x71bf('0x46')]=intUtil['stripTrailingSlash'](_0x2f4d66[_0x71bf('0x46')]);_0x2f4d66[_0x71bf('0x47')]=intUtil[_0x71bf('0x48')](_0x2f4d66['serverUrl']);_0x2eed4f[_0x71bf('0x41')]=_0x4efb5f===_0x71bf('0x40')||_0x4efb5f==='unmanaged'?_0x71bf('0x40'):_0x71bf('0x22');var _0x51c856=util[_0x71bf('0x43')]('%s/api/data/v9.0/',_0x2f4d66[_0x71bf('0x46')]);var _0x520c6f=util[_0x71bf('0x43')]('https://login.microsoftonline.com/%s/oauth2/token',_0x2f4d66[_0x71bf('0x49')]);var _0x542f50=util[_0x71bf('0x43')](_0x71bf('0x4a'),_0x2f4d66[_0x71bf('0x47')],_0x49b648['uniqueid'],md5(_0x49b648[_0x71bf('0x4b')]));if(_0x393eb3&&_0x393eb3[_0x71bf('0x4c')]){logger['info'](_0x71bf('0x4d'),_0x71bf('0x4e'));_0x49b648[_0x71bf('0x4f')]=_0x542f50;}else if(_0x5f397b&&_0x5f397b['recordingFormat']&&_0x5f397b[_0x71bf('0x50')]!=='none'){logger[_0x71bf('0x1e')](_0x71bf('0x51'),'Recording\x20is\x20enabled!');_0x49b648[_0x71bf('0x4f')]=_0x542f50;}else{_0x49b648[_0x71bf('0x4f')]='';}return getUser(_0x2eed4f,_0x2f4d66,_0x37acf0,_0x520c6f,_0x51c856,_0x4efb5f)[_0x71bf('0xc')](function(_0x3eff68){logger['info']('['+_0x4efb5f[_0x71bf('0x10')]()+_0x71bf('0x52'),_0x3eff68[_0x71bf('0x21')]);logger[_0x71bf('0x1e')]('['+_0x4efb5f[_0x71bf('0x10')]()+_0x71bf('0x53'),_0x3eff68[_0x71bf('0x54')]);return getEndUser(_0x3eff68,_0x2f4d66,_0x520c6f,_0x51c856,_0x49b648,_0x4efb5f);})[_0x71bf('0xc')](function(_0x26e860){logger['info']('['+_0x4efb5f['toUpperCase']()+_0x71bf('0x55'),_0x26e860[_0x71bf('0x2b')]);logger[_0x71bf('0x1e')]('['+_0x4efb5f[_0x71bf('0x10')]()+_0x71bf('0x56'),_0x49b648[_0x71bf('0x24')]);return getTicket(_0x26e860,_0x2f4d66,_0x520c6f,_0x51c856,_0x49b648,_0x3a9c1e,_0x4efb5f);})[_0x71bf('0xc')](function(_0x1e24e7){logger[_0x71bf('0x1e')](util[_0x71bf('0x43')]('['+_0x4efb5f[_0x71bf('0x10')]()+_0x71bf('0x57'),_0x3a9c1e[_0x71bf('0x35')],_0x1e24e7[_0x71bf('0x42')]));logger[_0x71bf('0x1e')](util['format']('['+_0x4efb5f['toUpperCase']()+_0x71bf('0x58'),_0x4efb5f));if(_0x4efb5f!==_0x71bf('0x59')){logger[_0x71bf('0x1e')]('['+_0x4efb5f['toUpperCase']()+']',_0x71bf('0x5a'));emit(_0x2f4d66[_0x71bf('0x46')],_0x37acf0[_0x71bf('0x5b')],_0x3a9c1e['ticketType'],_0x1e24e7['ticketId']);}})['catch'](function(_0x380cd1){logger[_0x71bf('0xf')]('['+_0x4efb5f[_0x71bf('0x10')]()+_0x71bf('0x5c'),util[_0x71bf('0x5d')](_0x380cd1,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xc5c5=['tenantId','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:',']\x20The\x20User\x20email\x20is:',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s','Displaying\x20call\x20in\x20a\x20new\x20tab...','name','ticketId',']\x20Error\x20running\x20Dynamics365\x20integration','inspect','lodash','bluebird','util','ioredis','../../../../config/logger','dynamics365','../../../../config/environment','defaults','redis','clientId','remoteUri','username','password','clientSecret','access_token','error','toUpperCase',']\x20Wrong\x20credentials!','then','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','isNil','validateEmail','userEmail','email','length','internalemailaddress','isdisabled','info',']\x20Agent\x20found\x20','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','catch','message','destcalleridnum','calleridnum','POST','contacts','/systemusers(','4.0','headers','odata-entityid','substring','contacts?$select=telephone1','value','toLowerCase','outbound','enduserId',']\x20Enduser\x20created!','forEach','type','string','nameField','customField','idField','indexOf','content','ticketType','incident','incidents','assign','Subjects','getString','Descriptions','/contacts(','Fields','phonecall','phonecalls','callDirection','queue','lastIndexOf','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','emit','trigger:browser:url','serverUrl','stripTrailingSlash','unmanaged','https://login.microsoftonline.com/%s/oauth2/token'];(function(_0x4c137c,_0x41c5b4){var _0x5e1d03=function(_0x240bbf){while(--_0x240bbf){_0x4c137c['push'](_0x4c137c['shift']());}};_0x5e1d03(++_0x41c5b4);}(_0xc5c5,0xdd));var _0x5c5c=function(_0x423564,_0x13fdef){_0x423564=_0x423564-0x0;var _0x35036c=_0xc5c5[_0x423564];return _0x35036c;};'use strict';var _=require(_0x5c5c('0x0'));var BPromise=require(_0x5c5c('0x1'));var rp=require('request-promise');var util=require(_0x5c5c('0x2'));var intUtil=require('./util');var md5=require('md5');var Redis=require(_0x5c5c('0x3'));var logger=require(_0x5c5c('0x4'))(_0x5c5c('0x5'));var config=require(_0x5c5c('0x6'));config['redis']=_[_0x5c5c('0x7')](config[_0x5c5c('0x8')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x5c5c('0x8')]));function getAuthToken(_0x44d83a,_0x5baf53,_0x55cd45){var _0x2167d9={'method':'POST','uri':_0x5baf53,'form':{'client_id':_0x44d83a[_0x5c5c('0x9')],'resource':_0x44d83a[_0x5c5c('0xa')],'username':_0x44d83a[_0x5c5c('0xb')],'password':_0x44d83a['password'],'grant_type':_0x5c5c('0xc'),'client_secret':_0x44d83a[_0x5c5c('0xd')]},'json':!![]};return rp(_0x2167d9)['then'](function(_0x1d8325){return _0x1d8325[_0x5c5c('0xe')];})['catch'](function(_0x3f9554){logger[_0x5c5c('0xf')]('['+[_0x55cd45[_0x5c5c('0x10')]()]+_0x5c5c('0x11'));return _0x3f9554['message'];});}function getUser(_0x49f6c4,_0x5cdac3,_0x3dd425,_0x5134ed,_0x37f14b,_0x2bf031){return new BPromise(function(_0x37224a,_0x350e65){return getAuthToken(_0x5cdac3,_0x5134ed,_0x2bf031)[_0x5c5c('0x12')](function(_0x3a62e9){var _0x43d215={'method':_0x5c5c('0x13'),'uri':_0x37f14b+_0x5c5c('0x14'),'headers':{'Authorization':_0x5c5c('0x15')+_0x3a62e9,'OData-Version':'4.0'},'json':!![]};return rp(_0x43d215);})[_0x5c5c('0x12')](function(_0xef9297){var _0x21c528=_0xef9297['value'];var _0x5a86f6=![];var _0x35d9b5=null;if(!_[_0x5c5c('0x16')](_0x3dd425)){if(intUtil[_0x5c5c('0x17')](_0x3dd425['email'])){_0x49f6c4[_0x5c5c('0x18')]=_0x3dd425[_0x5c5c('0x19')];for(_0x35d9b5=0x0;_0x35d9b5<_0x21c528[_0x5c5c('0x1a')];_0x35d9b5++){if(_0x21c528[_0x35d9b5][_0x5c5c('0x1b')]===_0x3dd425[_0x5c5c('0x19')]&&!_0x21c528[_0x35d9b5][_0x5c5c('0x1c')]){_0x5a86f6=!![];logger[_0x5c5c('0x1d')]('['+[_0x2bf031['toUpperCase']()]+_0x5c5c('0x1e')+_0x21c528[_0x35d9b5][_0x5c5c('0x1f')]+'!');_0x49f6c4[_0x5c5c('0x20')]=_0x21c528[_0x35d9b5][_0x5c5c('0x1f')];}}}}if(!_0x5a86f6){logger[_0x5c5c('0x1d')]('['+[_0x2bf031[_0x5c5c('0x10')]()]+_0x5c5c('0x21'));_0x49f6c4[_0x5c5c('0x18')]=_0x5cdac3[_0x5c5c('0xb')];for(_0x35d9b5=0x0;_0x35d9b5<_0x21c528[_0x5c5c('0x1a')];_0x35d9b5++){if(_0x21c528[_0x35d9b5]['internalemailaddress']===_0x5cdac3[_0x5c5c('0xb')]){_0x49f6c4[_0x5c5c('0x20')]=_0x21c528[_0x35d9b5]['systemuserid'];}}}_0x37224a(_0x49f6c4);})[_0x5c5c('0x22')](function(_0x1f5c97){_0x350e65(_0x1f5c97[_0x5c5c('0x23')]);});});}function createEndUser(_0x3819b7,_0x186be0,_0x2fa729,_0x5077a3,_0x5efb77,_0x232758){return new BPromise(function(_0x325481,_0x464645){return getAuthToken(_0x186be0,_0x2fa729,_0x232758)[_0x5c5c('0x12')](function(_0x438785){var _0x56e59b=_0x232758['toLowerCase']()==='outbound'?_0x5efb77[_0x5c5c('0x24')]:_0x5efb77[_0x5c5c('0x25')];var _0x564f53={'method':_0x5c5c('0x26'),'uri':_0x5077a3+_0x5c5c('0x27'),'body':{'telephone1':_0x56e59b,'fullname':_0x56e59b,'firstname':_0x56e59b,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x5c5c('0x28')+_0x3819b7[_0x5c5c('0x20')]+')'},'headers':{'Authorization':_0x5c5c('0x15')+_0x438785,'OData-Version':_0x5c5c('0x29')},'json':!![],'resolveWithFullResponse':!![]};return rp(_0x564f53);})['then'](function(_0x2e4418){var _0x5c7663=_0x2e4418[_0x5c5c('0x2a')][_0x5c5c('0x2b')];var _0xa46ab0=_0x5c7663[_0x5c5c('0x2c')](_0x5c7663['lastIndexOf']('(')+0x1,_0x5c7663['lastIndexOf'](')'));_0x3819b7['enduserId']=_0xa46ab0;_0x325481(_0x3819b7);})['catch'](function(_0x3b5dba){_0x464645(_0x3b5dba[_0x5c5c('0x23')]);});});}function getEndUser(_0x54559b,_0x19e702,_0x3b2d71,_0x55b6c0,_0x2d86da,_0x26023c){return new BPromise(function(_0xd020c8,_0x587e66){return getAuthToken(_0x19e702,_0x3b2d71,_0x26023c)['then'](function(_0x17ff0b){var _0x1d432b={'method':_0x5c5c('0x13'),'uri':_0x55b6c0+_0x5c5c('0x2d'),'headers':{'Authorization':_0x5c5c('0x15')+_0x17ff0b,'If-None-Match':null,'OData-Version':_0x5c5c('0x29')},'json':!![]};return rp(_0x1d432b);})[_0x5c5c('0x12')](function(_0x1b9de3){var _0x47c027=null;if(_0x1b9de3){var _0x3735d9=_0x1b9de3[_0x5c5c('0x2e')];var _0x50616f=![];for(_0x47c027=0x0;_0x47c027<_0x3735d9[_0x5c5c('0x1a')];_0x47c027++){var _0x2f8751=_0x26023c[_0x5c5c('0x2f')]()===_0x5c5c('0x30')?_0x2d86da[_0x5c5c('0x24')]:_0x2d86da[_0x5c5c('0x25')];if(_0x3735d9[_0x47c027]['telephone1']===_0x2f8751){_0x50616f=!![];_0x54559b[_0x5c5c('0x31')]=_0x3735d9[_0x47c027]['contactid'];}}if(_0x50616f){_0xd020c8(_0x54559b);}else{return createEndUser(_0x54559b,_0x19e702,_0x3b2d71,_0x55b6c0,_0x2d86da,_0x26023c)['then'](function(_0x37507b){logger['info']('['+[_0x26023c[_0x5c5c('0x10')]()]+_0x5c5c('0x32'),_0x37507b[_0x5c5c('0x31')]);_0xd020c8(_0x37507b);});}}else{return createEndUser(_0x54559b,_0x19e702,_0x3b2d71,_0x55b6c0,_0x2d86da,_0x26023c)[_0x5c5c('0x12')](function(_0x3b5bbb){logger[_0x5c5c('0x1d')]('['+[_0x26023c[_0x5c5c('0x10')]()]+']\x20Enduser\x20Created!',_0x3b5bbb['enduserId']);_0xd020c8(_0x3b5bbb);});}});});}function getCustomFields(_0x1d451b,_0x1c492d,_0x42dde6){var _0x408a4a={};if(_0x1d451b[_0x5c5c('0x1a')]>0x0){_[_0x5c5c('0x33')](_0x1d451b,function(_0x312697){if(_0x312697[_0x5c5c('0x34')]===_0x5c5c('0x35')&&_0x312697[_0x5c5c('0x36')]&&!_0x312697[_0x5c5c('0x37')]){var _0x460dbf=_0x312697[_0x5c5c('0x38')][_0x5c5c('0x2f')]();var _0x57e2c4=_0x460dbf[_0x5c5c('0x2c')](0x0,_0x460dbf[_0x5c5c('0x39')]('_'));var _0x4bcf54=_0x460dbf[_0x5c5c('0x2c')](_0x460dbf['indexOf']('_')+0x1);if(_0x57e2c4===_0x42dde6){_0x408a4a[_0x4bcf54]=_0x312697[_0x5c5c('0x3a')];}}});}return _0x408a4a;}function getTicket(_0x147976,_0x1896f1,_0x53991c,_0x59e630,_0x1a88e2,_0x5972fc,_0x25df7d){return new BPromise(function(_0x7bfcea,_0x4bb611){var _0x2126d1;return getAuthToken(_0x1896f1,_0x53991c,_0x25df7d)[_0x5c5c('0x12')](function(_0x239ac3){if(_0x5972fc[_0x5c5c('0x3b')]===_0x5c5c('0x3c')){_0x2126d1={'method':'POST','uri':_0x59e630+_0x5c5c('0x3d'),'body':Object[_0x5c5c('0x3e')]({},{'title':intUtil['getString'](_0x5972fc[_0x5c5c('0x3f')],_0x1a88e2,'\x20'),'description':intUtil[_0x5c5c('0x40')](_0x5972fc[_0x5c5c('0x41')],_0x1a88e2,'\x0a'),'customerid_contact@odata.bind':_0x5c5c('0x42')+_0x147976['enduserId']+')','ownerid@odata.bind':_0x5c5c('0x28')+_0x147976[_0x5c5c('0x20')]+')','caseorigincode':'1'},getCustomFields(_0x5972fc[_0x5c5c('0x43')],_0x1a88e2,_0x5972fc['ticketType'])),'headers':{'Authorization':_0x5c5c('0x15')+_0x239ac3,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}if(_0x5972fc['ticketType']===_0x5c5c('0x44')){_0x2126d1={'method':'POST','uri':_0x59e630+_0x5c5c('0x45'),'body':Object[_0x5c5c('0x3e')]({},{'subject':intUtil[_0x5c5c('0x40')](_0x5972fc['Subjects'],_0x1a88e2,'\x20'),'phonenumber':String(_0x1a88e2['calleridnum']),'description':intUtil['getString'](_0x5972fc[_0x5c5c('0x41')],_0x1a88e2,'\x0a'),'regardingobjectid_contact@odata.bind':'/contacts('+_0x147976[_0x5c5c('0x31')]+')','ownerid@odata.bind':'/systemusers('+_0x147976[_0x5c5c('0x20')]+')','directioncode':_0x147976[_0x5c5c('0x46')]===_0x5c5c('0x47')?![]:!![],'phonecall_activity_parties':[{'partyid_systemuser@odata.bind':'/systemusers('+_0x147976[_0x5c5c('0x20')]+')','participationtypemask':_0x147976[_0x5c5c('0x46')]==='queue'?0x2:0x1},{'partyid_contact@odata.bind':_0x5c5c('0x42')+_0x147976[_0x5c5c('0x31')]+')','participationtypemask':_0x147976[_0x5c5c('0x46')]==='queue'?0x1:0x2}]},getCustomFields(_0x5972fc[_0x5c5c('0x43')],_0x1a88e2,_0x5972fc['ticketType'])),'headers':{'Authorization':_0x5c5c('0x15')+_0x239ac3,'OData-Version':_0x5c5c('0x29')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x2126d1);})[_0x5c5c('0x12')](function(_0x51e3f6){var _0x1034e9=_0x51e3f6[_0x5c5c('0x2a')][_0x5c5c('0x2b')];var _0x387af9=_0x1034e9['substring'](_0x1034e9[_0x5c5c('0x48')]('(')+0x1,_0x1034e9['lastIndexOf'](')'));_0x147976['ticketId']=_0x387af9;_0x7bfcea(_0x147976);})[_0x5c5c('0x22')](function(_0x43ccc2){_0x4bb611(_0x43ccc2[_0x5c5c('0x23')]);});});}function emit(_0x50c106,_0x599194,_0x2f33f5,_0x5d9a73){var _0x37542c={'uri':util[_0x5c5c('0x49')](_0x5c5c('0x4a'),_0x50c106,_0x2f33f5,_0x5d9a73)};io['to'](util['format'](_0x5c5c('0x4b'),_0x599194))[_0x5c5c('0x4c')](_0x5c5c('0x4d'),_0x37542c);}exports['cs']=function(_0x4e56e1,_0x519bd0,_0x5c1026,_0x4e6c45,_0x411e97,_0x462318,_0x328bf7,_0x14b31e){var _0x5a9e87={};_0x462318['remoteUri']=intUtil['stripTrailingSlash'](_0x462318[_0x5c5c('0xa')]);_0x462318[_0x5c5c('0x4e')]=intUtil[_0x5c5c('0x4f')](_0x462318[_0x5c5c('0x4e')]);_0x5a9e87['callDirection']=_0x14b31e===_0x5c5c('0x47')||_0x14b31e===_0x5c5c('0x50')?_0x5c5c('0x47'):_0x5c5c('0x30');var _0x362b23=util['format']('%s/api/data/v9.0/',_0x462318[_0x5c5c('0xa')]);var _0x1428bd=util[_0x5c5c('0x49')](_0x5c5c('0x51'),_0x462318[_0x5c5c('0x52')]);var _0x3fe55d=util[_0x5c5c('0x49')](_0x5c5c('0x53'),_0x462318[_0x5c5c('0x4e')],_0x519bd0['uniqueid'],md5(_0x519bd0['uniqueid']));if(_0x411e97&&_0x411e97[_0x5c5c('0x54')]){logger[_0x5c5c('0x1d')](_0x5c5c('0x55'),_0x5c5c('0x56'));_0x519bd0[_0x5c5c('0x57')]=_0x3fe55d;}else if(_0x328bf7&&_0x328bf7['recordingFormat']&&_0x328bf7[_0x5c5c('0x58')]!==_0x5c5c('0x59')){logger['info'](_0x5c5c('0x5a'),_0x5c5c('0x56'));_0x519bd0[_0x5c5c('0x57')]=_0x3fe55d;}else{_0x519bd0['recordingURL']='';}return getUser(_0x5a9e87,_0x462318,_0x4e6c45,_0x1428bd,_0x362b23,_0x14b31e)[_0x5c5c('0x12')](function(_0x16d63e){logger[_0x5c5c('0x1d')]('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x5b'),_0x16d63e[_0x5c5c('0x20')]);logger[_0x5c5c('0x1d')]('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x5c'),_0x16d63e[_0x5c5c('0x18')]);return getEndUser(_0x16d63e,_0x462318,_0x1428bd,_0x362b23,_0x519bd0,_0x14b31e);})[_0x5c5c('0x12')](function(_0x32a533){logger['info']('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x5d'),_0x32a533[_0x5c5c('0x31')]);logger['info']('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x5e'),_0x519bd0[_0x5c5c('0x25')]);return getTicket(_0x32a533,_0x462318,_0x1428bd,_0x362b23,_0x519bd0,_0x5c1026,_0x14b31e);})[_0x5c5c('0x12')](function(_0x2c50a5){logger[_0x5c5c('0x1d')](util[_0x5c5c('0x49')]('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x5f'),_0x5c1026[_0x5c5c('0x3b')],_0x2c50a5['ticketId']));logger[_0x5c5c('0x1d')](util['format']('['+_0x14b31e[_0x5c5c('0x10')]()+']\x20Call\x20direction:\x20%s',_0x14b31e));if(_0x14b31e!==_0x5c5c('0x50')){logger[_0x5c5c('0x1d')]('['+_0x14b31e['toUpperCase']()+']',_0x5c5c('0x60'));emit(_0x462318['remoteUri'],_0x4e6c45[_0x5c5c('0x61')],_0x5c1026['ticketType'],_0x2c50a5[_0x5c5c('0x62')]);}})['catch'](function(_0x1bd416){logger[_0x5c5c('0xf')]('['+_0x14b31e[_0x5c5c('0x10')]()+_0x5c5c('0x63'),util[_0x5c5c('0x64')](_0x1bd416,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file