Built motion from commit 64440dd5.|2.6.29
[motion2.git] / server / services / ami / trigger / integration / dynamics365.js
index d203b89..37c6c4b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb0f5=['type','nameField','customField','idField','indexOf','content','assign','getString','Subjects','Descriptions','/contacts(','Fields','ticketType','phonecall','queue','callDirection','phonecalls','ticketId','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','trigger:browser:url','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!','recordingURL','recordingFormat','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:','moduleCreate',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20Enduser\x20phone\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s',']\x20Call\x20direction:\x20%s','openNewTab','name',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','request-promise','md5','../../../../config/logger','dynamics365','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','modernAuthentication','remoteUri','CloudProvider','data7','data2','data5','POST','clientId','password','access_token','error','toUpperCase','message','then','GET','systemusers?$select=internalemailaddress,isdisabled,systemuserid','Bearer\x20','4.0','value','validateEmail','email','length','internalemailaddress','isdisabled','info','systemuserid',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userEmail','username','userId','outbound','calleridnum','contacts','/systemusers(','headers','odata-entityid','substring','lastIndexOf','enduserId','catch','toLowerCase','destcalleridnum','telephone1','&$filter=','\x20eq\x20\x27','replace','%2b','contactid','nothing',']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing',']\x20Enduser\x20created!','forEach','includes','string','picklist'];(function(_0x1add1b,_0x32f5fb){var _0x2821df=function(_0x34d3a5){while(--_0x34d3a5){_0x1add1b['push'](_0x1add1b['shift']());}};_0x2821df(++_0x32f5fb);}(_0xb0f5,0x1e1));var _0x5b0f=function(_0x342baa,_0x4a110f){_0x342baa=_0x342baa-0x0;var _0x1208f3=_0xb0f5[_0x342baa];return _0x1208f3;};'use strict';var _=require('lodash');var rp=require(_0x5b0f('0x0'));var util=require('util');var intUtil=require('./util');var md5=require(_0x5b0f('0x1'));var Redis=require('ioredis');var logger=require(_0x5b0f('0x2'))(_0x5b0f('0x3'));var config=require(_0x5b0f('0x4'));config[_0x5b0f('0x5')]=_[_0x5b0f('0x6')](config['redis'],{'host':_0x5b0f('0x7'),'port':0x18eb});var io=require(_0x5b0f('0x8'))(new Redis(config['redis']));function getAuthToken(_0x61521f,_0x15233d,_0x2d9776){if(_0x61521f[_0x5b0f('0x9')]){_0x61521f[_0x5b0f('0xa')]=_0x61521f[_0x5b0f('0xb')][_0x5b0f('0xc')];_0x61521f['tenantId']=_0x61521f[_0x5b0f('0xb')][_0x5b0f('0xd')];return Promise['resolve'](_0x61521f[_0x5b0f('0xb')][_0x5b0f('0xe')]);}var _0x1f7c4c={'method':_0x5b0f('0xf'),'uri':_0x15233d,'form':{'client_id':_0x61521f[_0x5b0f('0x10')],'resource':_0x61521f[_0x5b0f('0xa')],'username':_0x61521f['username'],'password':_0x61521f[_0x5b0f('0x11')],'grant_type':'password','client_secret':_0x61521f['clientSecret']},'json':!![]};return rp(_0x1f7c4c)['then'](function(_0x6276b7){return _0x6276b7[_0x5b0f('0x12')];})['catch'](function(_0x3fd142){logger[_0x5b0f('0x13')]('['+[_0x2d9776[_0x5b0f('0x14')]()]+']\x20Wrong\x20credentials!');return _0x3fd142[_0x5b0f('0x15')];});}function getUser(_0x589ab3,_0x2d04f0,_0x351f30,_0x59b66f,_0x2fbf9d,_0x4d0780){return new Promise(function(_0x10775b,_0x10f4c6){return getAuthToken(_0x2d04f0,_0x59b66f,_0x4d0780)[_0x5b0f('0x16')](function(_0x25f61d){var _0x2fcc73={'method':_0x5b0f('0x17'),'uri':_0x2fbf9d+_0x5b0f('0x18'),'headers':{'Authorization':_0x5b0f('0x19')+_0x25f61d,'OData-Version':_0x5b0f('0x1a')},'json':!![]};return rp(_0x2fcc73);})[_0x5b0f('0x16')](function(_0x2d754e){var _0x2ecece=_0x2d754e[_0x5b0f('0x1b')];var _0x1d222c=![];var _0x42cf17=null;if(!_['isNil'](_0x351f30)){if(intUtil[_0x5b0f('0x1c')](_0x351f30[_0x5b0f('0x1d')])){_0x589ab3['userEmail']=_0x351f30[_0x5b0f('0x1d')];for(_0x42cf17=0x0;_0x42cf17<_0x2ecece[_0x5b0f('0x1e')];_0x42cf17++){if(_0x2ecece[_0x42cf17][_0x5b0f('0x1f')]===_0x351f30[_0x5b0f('0x1d')]&&!_0x2ecece[_0x42cf17][_0x5b0f('0x20')]){_0x1d222c=!![];logger[_0x5b0f('0x21')]('['+[_0x4d0780['toUpperCase']()]+']\x20Agent\x20found\x20'+_0x2ecece[_0x42cf17][_0x5b0f('0x22')]+'!');_0x589ab3['userId']=_0x2ecece[_0x42cf17][_0x5b0f('0x22')];}}}}if(!_0x1d222c){logger[_0x5b0f('0x21')]('['+[_0x4d0780[_0x5b0f('0x14')]()]+_0x5b0f('0x23'));_0x589ab3[_0x5b0f('0x24')]=_0x2d04f0[_0x5b0f('0x25')];for(_0x42cf17=0x0;_0x42cf17<_0x2ecece[_0x5b0f('0x1e')];_0x42cf17++){if(_0x2ecece[_0x42cf17]['internalemailaddress']===_0x2d04f0[_0x5b0f('0x25')]){_0x589ab3[_0x5b0f('0x26')]=_0x2ecece[_0x42cf17][_0x5b0f('0x22')];}}}_0x10775b(_0x589ab3);})['catch'](function(_0x3a5d07){_0x10f4c6(_0x3a5d07[_0x5b0f('0x15')]);});});}function createEndUser(_0x2ae96,_0x225427,_0x4feda7,_0x1ea3fa,_0x5cb459,_0x472176,_0x5c5665){return new Promise(function(_0x271f5e,_0x57151){return getAuthToken(_0x225427,_0x4feda7,_0x472176)[_0x5b0f('0x16')](function(_0x44dafe){var _0x18cef9=_0x472176['toLowerCase']()===_0x5b0f('0x27')?_0x5cb459['destcalleridnum']:_0x5cb459[_0x5b0f('0x28')];var _0x127a1f={'method':_0x5b0f('0xf'),'uri':_0x1ea3fa+_0x5b0f('0x29'),'body':{'fullname':_0x18cef9,'firstname':_0x18cef9,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':_0x5b0f('0x2a')+_0x2ae96[_0x5b0f('0x26')]+')'},'headers':{'Authorization':'Bearer\x20'+_0x44dafe,'OData-Version':_0x5b0f('0x1a')},'json':!![],'resolveWithFullResponse':!![]};_0x127a1f['body'][_0x5c5665]=_0x18cef9;return rp(_0x127a1f);})[_0x5b0f('0x16')](function(_0x3eaee5){var _0x7d234e=_0x3eaee5[_0x5b0f('0x2b')][_0x5b0f('0x2c')];var _0x128399=_0x7d234e[_0x5b0f('0x2d')](_0x7d234e[_0x5b0f('0x2e')]('(')+0x1,_0x7d234e[_0x5b0f('0x2e')](')'));_0x2ae96[_0x5b0f('0x2f')]=_0x128399;_0x271f5e(_0x2ae96);})[_0x5b0f('0x30')](function(_0x6b5c4f){_0x57151(_0x6b5c4f[_0x5b0f('0x15')]);});});}function getEndUser(_0x44d175,_0x1ffe8c,_0x37b2cb,_0x2ca967,_0x25778f,_0x228a65,_0x2ea257,_0x34e3fd){var _0x2c5c4d=_0x228a65[_0x5b0f('0x31')]()===_0x5b0f('0x27')?_0x25778f[_0x5b0f('0x32')]:_0x25778f['calleridnum'];return getAuthToken(_0x1ffe8c,_0x37b2cb,_0x228a65)[_0x5b0f('0x16')](function(_0x371919){_0x34e3fd=_0x34e3fd?_0x34e3fd:_0x5b0f('0x33');var _0x2ab246={'method':'GET','uri':_0x2ca967+'contacts?$select='+_0x34e3fd+_0x5b0f('0x34')+_0x34e3fd+_0x5b0f('0x35')+_0x2c5c4d[_0x5b0f('0x36')]('+',_0x5b0f('0x37'))+'\x27','headers':{'Authorization':_0x5b0f('0x19')+_0x371919,'If-None-Match':null,'OData-Version':_0x5b0f('0x1a')},'json':!![]};return rp(_0x2ab246);})[_0x5b0f('0x16')](function(_0x5be5ba){var _0x35072a=![];if(!_0x5be5ba)return _0x35072a;var _0x3b8bf5=_0x5be5ba[_0x5b0f('0x1b')];for(var _0x12c7f7=0x0;_0x12c7f7<_0x3b8bf5[_0x5b0f('0x1e')];_0x12c7f7++){if(_0x3b8bf5[_0x12c7f7][_0x34e3fd]===_0x2c5c4d){_0x35072a=!![];_0x44d175[_0x5b0f('0x2f')]=_0x3b8bf5[_0x12c7f7][_0x5b0f('0x38')];}}return _0x35072a;})[_0x5b0f('0x16')](function(_0x453b8c){if(_0x453b8c)return _0x44d175;if(_0x2ea257===_0x5b0f('0x39')){logger['info']('['+[_0x228a65[_0x5b0f('0x14')]()]+_0x5b0f('0x3a'));return _0x44d175;}return createEndUser(_0x44d175,_0x1ffe8c,_0x37b2cb,_0x2ca967,_0x25778f,_0x228a65,_0x34e3fd)['then'](function(_0xebbd5){logger[_0x5b0f('0x21')]('['+[_0x228a65[_0x5b0f('0x14')]()]+_0x5b0f('0x3b'),_0xebbd5['enduserId']);return _0xebbd5;});});}function getCustomFields(_0x51667d,_0x3f680d,_0x2948c1){var _0xdd2dc2={};if(_0x51667d['length']>0x0){_[_0x5b0f('0x3c')](_0x51667d,function(_0xb06e77){if(_[_0x5b0f('0x3d')]([_0x5b0f('0x3e'),_0x5b0f('0x3f')],_0xb06e77[_0x5b0f('0x40')])&&_0xb06e77[_0x5b0f('0x41')]&&!_0xb06e77[_0x5b0f('0x42')]){var _0xe89265=_0xb06e77[_0x5b0f('0x43')][_0x5b0f('0x31')]();var _0x1fe3ed=_0xe89265['substring'](0x0,_0xe89265[_0x5b0f('0x44')]('_'));var _0x288177=_0xe89265['substring'](_0xe89265['indexOf']('_')+0x1);if(_0x1fe3ed===_0x2948c1){_0xdd2dc2[_0x288177]=_0xb06e77[_0x5b0f('0x45')];}}});}return _0xdd2dc2;}function getTicket(_0x2b628e,_0x6dfda9,_0xc8d2db,_0x1a0743,_0x5d6c4e,_0x59e76a,_0x3753d3){return new Promise(function(_0x3baccd,_0x6a1b64){var _0x35e03b;return getAuthToken(_0x6dfda9,_0xc8d2db,_0x3753d3)['then'](function(_0x27ed2d){if(_0x59e76a['ticketType']==='incident'){_0x35e03b={'method':_0x5b0f('0xf'),'uri':_0x1a0743+'incidents','body':Object[_0x5b0f('0x46')]({},{'title':intUtil[_0x5b0f('0x47')](_0x59e76a[_0x5b0f('0x48')],_0x5d6c4e,'\x20'),'description':intUtil[_0x5b0f('0x47')](_0x59e76a[_0x5b0f('0x49')],_0x5d6c4e,'\x0a'),'customerid_contact@odata.bind':_0x2b628e['enduserId']?_0x5b0f('0x4a')+_0x2b628e[_0x5b0f('0x2f')]+')':undefined,'ownerid@odata.bind':_0x5b0f('0x2a')+_0x2b628e['userId']+')','caseorigincode':'1'},getCustomFields(_0x59e76a[_0x5b0f('0x4b')],_0x5d6c4e,_0x59e76a[_0x5b0f('0x4c')])),'headers':{'Authorization':'Bearer\x20'+_0x27ed2d,'OData-Version':_0x5b0f('0x1a')},'json':!![],'resolveWithFullResponse':!![]};}if(_0x59e76a[_0x5b0f('0x4c')]===_0x5b0f('0x4d')){var _0x5b6ed0=_0x2b628e['enduserId']?[{'partyid_systemuser@odata.bind':_0x5b0f('0x2a')+_0x2b628e[_0x5b0f('0x26')]+')','participationtypemask':_0x2b628e['callDirection']===_0x5b0f('0x4e')?0x2:0x1},{'partyid_contact@odata.bind':_0x5b0f('0x4a')+_0x2b628e[_0x5b0f('0x2f')]+')','participationtypemask':_0x2b628e[_0x5b0f('0x4f')]===_0x5b0f('0x4e')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':_0x5b0f('0x2a')+_0x2b628e[_0x5b0f('0x26')]+')','participationtypemask':_0x2b628e[_0x5b0f('0x4f')]===_0x5b0f('0x4e')?0x2:0x1}];_0x35e03b={'method':'POST','uri':_0x1a0743+_0x5b0f('0x50'),'body':Object['assign']({},{'subject':intUtil[_0x5b0f('0x47')](_0x59e76a['Subjects'],_0x5d6c4e,'\x20'),'phonenumber':String(_0x5d6c4e['calleridnum']),'description':intUtil['getString'](_0x59e76a[_0x5b0f('0x49')],_0x5d6c4e,'\x0a'),'regardingobjectid_contact@odata.bind':_0x2b628e[_0x5b0f('0x2f')]?_0x5b0f('0x4a')+_0x2b628e[_0x5b0f('0x2f')]+')':undefined,'ownerid@odata.bind':'/systemusers('+_0x2b628e['userId']+')','directioncode':_0x2b628e['callDirection']===_0x5b0f('0x4e')?![]:!![],'phonecall_activity_parties':_0x5b6ed0},getCustomFields(_0x59e76a['Fields'],_0x5d6c4e,_0x59e76a['ticketType'])),'headers':{'Authorization':'Bearer\x20'+_0x27ed2d,'OData-Version':_0x5b0f('0x1a')},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x35e03b);})[_0x5b0f('0x16')](function(_0x2ee354){var _0x16a951=_0x2ee354[_0x5b0f('0x2b')]['odata-entityid'];var _0x1aae8f=_0x16a951['substring'](_0x16a951[_0x5b0f('0x2e')]('(')+0x1,_0x16a951['lastIndexOf'](')'));_0x2b628e[_0x5b0f('0x51')]=_0x1aae8f;_0x3baccd(_0x2b628e);})['catch'](function(_0x1debf8){_0x6a1b64(_0x1debf8['message']);});});}function emit(_0x4402d6,_0x4109ad,_0x517ce5,_0x161030){var _0x5e6282={'uri':util[_0x5b0f('0x52')](_0x5b0f('0x53'),_0x4402d6,_0x517ce5,_0x161030)};io['to'](util[_0x5b0f('0x52')]('user:%s',_0x4109ad))['emit'](_0x5b0f('0x54'),_0x5e6282);}exports['cs']=function(_0x3773b2,_0x2114be,_0x26f4f8,_0x5d375a,_0x5e5f25,_0xaac4b0,_0xc1f9b7,_0x3cc80b){var _0x575568={};_0xaac4b0[_0x5b0f('0xa')]=_0xaac4b0[_0x5b0f('0x9')]?intUtil[_0x5b0f('0x55')](_0xaac4b0[_0x5b0f('0xb')][_0x5b0f('0xc')]):intUtil[_0x5b0f('0x55')](_0xaac4b0[_0x5b0f('0xa')]);_0xaac4b0[_0x5b0f('0x56')]=intUtil[_0x5b0f('0x55')](_0xaac4b0[_0x5b0f('0x56')]);_0x575568['callDirection']=_0x3cc80b===_0x5b0f('0x4e')||_0x3cc80b===_0x5b0f('0x57')?_0x5b0f('0x4e'):_0x5b0f('0x27');var _0x1a2272=_0xaac4b0[_0x5b0f('0x9')]?util[_0x5b0f('0x52')](_0x5b0f('0x58'),_0xaac4b0[_0x5b0f('0xb')][_0x5b0f('0xc')]):util[_0x5b0f('0x52')]('%s/api/data/v9.0/',_0xaac4b0['remoteUri']);var _0x36fdd2=util['format'](_0x5b0f('0x59'),_0xaac4b0[_0x5b0f('0x5a')]);var _0x3c244f=util[_0x5b0f('0x52')](_0x5b0f('0x5b'),_0xaac4b0[_0x5b0f('0x56')],_0x2114be[_0x5b0f('0x5c')],md5(_0x2114be[_0x5b0f('0x5c')]));if(_0x5e5f25&&_0x5e5f25[_0x5b0f('0x5d')]){logger['info'](_0x5b0f('0x5e'),_0x5b0f('0x5f'));_0x2114be[_0x5b0f('0x60')]=_0x3c244f;}else if(_0xc1f9b7&&_0xc1f9b7[_0x5b0f('0x61')]&&_0xc1f9b7[_0x5b0f('0x61')]!=='none'){logger['info'](_0x5b0f('0x62'),_0x5b0f('0x5f'));_0x2114be[_0x5b0f('0x60')]=_0x3c244f;}else{_0x2114be['recordingURL']='';}return getUser(_0x575568,_0xaac4b0,_0x5d375a,_0x36fdd2,_0x1a2272,_0x3cc80b)[_0x5b0f('0x16')](function(_0x4ebc57){logger[_0x5b0f('0x21')]('['+_0x3cc80b[_0x5b0f('0x14')]()+_0x5b0f('0x63'),_0x4ebc57[_0x5b0f('0x26')]);logger[_0x5b0f('0x21')]('['+_0x3cc80b[_0x5b0f('0x14')]()+']\x20The\x20User\x20email\x20is:',_0x4ebc57[_0x5b0f('0x24')]);return getEndUser(_0x4ebc57,_0xaac4b0,_0x36fdd2,_0x1a2272,_0x2114be,_0x3cc80b,_0x26f4f8[_0x5b0f('0x64')],_0x26f4f8['additionalSearchContact']);})[_0x5b0f('0x16')](function(_0x5157a2){logger[_0x5b0f('0x21')]('['+_0x3cc80b[_0x5b0f('0x14')]()+_0x5b0f('0x65'),_0x5157a2['enduserId']);logger[_0x5b0f('0x21')]('['+_0x3cc80b['toUpperCase']()+_0x5b0f('0x66'),_0x2114be[_0x5b0f('0x28')]);return getTicket(_0x5157a2,_0xaac4b0,_0x36fdd2,_0x1a2272,_0x2114be,_0x26f4f8,_0x3cc80b);})[_0x5b0f('0x16')](function(_0xc1c11d){logger['info'](util[_0x5b0f('0x52')]('['+_0x3cc80b['toUpperCase']()+_0x5b0f('0x67'),_0x26f4f8[_0x5b0f('0x4c')],_0xc1c11d['ticketId']));logger['info'](util[_0x5b0f('0x52')]('['+_0x3cc80b[_0x5b0f('0x14')]()+_0x5b0f('0x68'),_0x3cc80b));if(_0x3cc80b!==_0x5b0f('0x57')&&_0x26f4f8[_0x5b0f('0x69')]){logger[_0x5b0f('0x21')]('['+_0x3cc80b[_0x5b0f('0x14')]()+']','Displaying\x20call\x20in\x20a\x20new\x20tab...');emit(_0xaac4b0[_0x5b0f('0xa')],_0x5d375a[_0x5b0f('0x6a')],_0x26f4f8[_0x5b0f('0x4c')],_0xc1c11d[_0x5b0f('0x51')]);}})['catch'](function(_0xf5bae1){logger['error']('['+_0x3cc80b['toUpperCase']()+_0x5b0f('0x6b'),_0xf5bae1[_0x5b0f('0x15')]);console['error'](_0x5b0f('0x6c'),_0xf5bae1);});};
\ No newline at end of file
+var _0x7bf3=['ticketType','incident','incidents','assign','getString','Subjects','Descriptions','/contacts(','/systemusers(','Fields','phonecall','callDirection','queue','phonecalls','format','%s/main.aspx?pagetype=entityrecord&etn=%s&id=%s','user:%s','emit','trigger:browser:url','stripTrailingSlash','serverUrl','unmanaged','%s/api/data/v9.0/','https://login.microsoftonline.com/%s/oauth2/token','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]',']\x20The\x20User\x20ID\x20is:','additionalSearchContact',']\x20The\x20Enduser\x20ID\x20is:',']\x20The\x20%s\x20ID\x20is:\x20%s','ticketId','openNewTab','Displaying\x20call\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Dynamics365\x20integration','Error\x20running\x20Dynamics365\x20integration','request-promise','md5','ioredis','dynamics365','redis','defaults','localhost','modernAuthentication','remoteUri','CloudProvider','data7','tenantId','data2','username','password','clientSecret','then','access_token','catch','error','toUpperCase','message','Bearer\x20','4.0','value','validateEmail','email','internalemailaddress','isdisabled','info','systemuserid','userId',']\x20Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','userEmail','toLowerCase','outbound','calleridnum','POST','contacts','body','headers','odata-entityid','substring','lastIndexOf','enduserId','contacts?$select=','&$filter=','replace','length','nothing',']\x20Enduser\x20created!','string','nameField','customField','idField','indexOf','content'];(function(_0x51cc43,_0x39ec57){var _0x52b127=function(_0x8b75bc){while(--_0x8b75bc){_0x51cc43['push'](_0x51cc43['shift']());}};_0x52b127(++_0x39ec57);}(_0x7bf3,0x153));var _0x37bf=function(_0x2bf77d,_0x5bab3a){_0x2bf77d=_0x2bf77d-0x0;var _0x1f1e23=_0x7bf3[_0x2bf77d];return _0x1f1e23;};'use strict';var _=require('lodash');var rp=require(_0x37bf('0x0'));var util=require('util');var intUtil=require('./util');var md5=require(_0x37bf('0x1'));var Redis=require(_0x37bf('0x2'));var logger=require('../../../../config/logger')(_0x37bf('0x3'));var config=require('../../../../config/environment');config[_0x37bf('0x4')]=_[_0x37bf('0x5')](config['redis'],{'host':_0x37bf('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x37bf('0x4')]));function getAuthToken(_0x492b8b,_0x278d33,_0xe5cc2b){if(_0x492b8b[_0x37bf('0x7')]){_0x492b8b[_0x37bf('0x8')]=_0x492b8b[_0x37bf('0x9')][_0x37bf('0xa')];_0x492b8b[_0x37bf('0xb')]=_0x492b8b[_0x37bf('0x9')][_0x37bf('0xc')];return Promise['resolve'](_0x492b8b[_0x37bf('0x9')]['data5']);}var _0x326fe5={'method':'POST','uri':_0x278d33,'form':{'client_id':_0x492b8b['clientId'],'resource':_0x492b8b[_0x37bf('0x8')],'username':_0x492b8b[_0x37bf('0xd')],'password':_0x492b8b['password'],'grant_type':_0x37bf('0xe'),'client_secret':_0x492b8b[_0x37bf('0xf')]},'json':!![]};return rp(_0x326fe5)[_0x37bf('0x10')](function(_0x4c8c04){return _0x4c8c04[_0x37bf('0x11')];})[_0x37bf('0x12')](function(_0x477fc6){logger[_0x37bf('0x13')]('['+[_0xe5cc2b[_0x37bf('0x14')]()]+']\x20Wrong\x20credentials!');return _0x477fc6[_0x37bf('0x15')];});}function getUser(_0x1b9f08,_0x5a2ae7,_0x7b4d7c,_0xf1dd2d,_0xc191da,_0x17d1a7){return new Promise(function(_0x5ce336,_0x3da92f){return getAuthToken(_0x5a2ae7,_0xf1dd2d,_0x17d1a7)[_0x37bf('0x10')](function(_0x2ee91e){var _0x39dba8={'method':'GET','uri':_0xc191da+'systemusers?$select=internalemailaddress,isdisabled,systemuserid','headers':{'Authorization':_0x37bf('0x16')+_0x2ee91e,'OData-Version':_0x37bf('0x17')},'json':!![]};return rp(_0x39dba8);})[_0x37bf('0x10')](function(_0x1779f1){var _0x2bd632=_0x1779f1[_0x37bf('0x18')];var _0x1c01b0=![];var _0x373eeb=null;if(!_['isNil'](_0x7b4d7c)){if(intUtil[_0x37bf('0x19')](_0x7b4d7c[_0x37bf('0x1a')])){_0x1b9f08['userEmail']=_0x7b4d7c[_0x37bf('0x1a')];for(_0x373eeb=0x0;_0x373eeb<_0x2bd632['length'];_0x373eeb++){if(_0x2bd632[_0x373eeb][_0x37bf('0x1b')]===_0x7b4d7c[_0x37bf('0x1a')]&&!_0x2bd632[_0x373eeb][_0x37bf('0x1c')]){_0x1c01b0=!![];logger[_0x37bf('0x1d')]('['+[_0x17d1a7[_0x37bf('0x14')]()]+']\x20Agent\x20found\x20'+_0x2bd632[_0x373eeb][_0x37bf('0x1e')]+'!');_0x1b9f08[_0x37bf('0x1f')]=_0x2bd632[_0x373eeb][_0x37bf('0x1e')];}}}}if(!_0x1c01b0){logger[_0x37bf('0x1d')]('['+[_0x17d1a7['toUpperCase']()]+_0x37bf('0x20'));_0x1b9f08[_0x37bf('0x21')]=_0x5a2ae7['username'];for(_0x373eeb=0x0;_0x373eeb<_0x2bd632['length'];_0x373eeb++){if(_0x2bd632[_0x373eeb][_0x37bf('0x1b')]===_0x5a2ae7[_0x37bf('0xd')]){_0x1b9f08['userId']=_0x2bd632[_0x373eeb][_0x37bf('0x1e')];}}}_0x5ce336(_0x1b9f08);})['catch'](function(_0x367e71){_0x3da92f(_0x367e71['message']);});});}function createEndUser(_0x481438,_0x463336,_0x3ac1cd,_0x2546b6,_0x143425,_0x3b7d26,_0x409100){return new Promise(function(_0x5b47e1,_0x1f9646){return getAuthToken(_0x463336,_0x3ac1cd,_0x3b7d26)[_0x37bf('0x10')](function(_0xc81fb4){var _0x57928f=_0x3b7d26[_0x37bf('0x22')]()===_0x37bf('0x23')?_0x143425['destcalleridnum']:_0x143425[_0x37bf('0x24')];var _0x388415={'method':_0x37bf('0x25'),'uri':_0x2546b6+_0x37bf('0x26'),'body':{'fullname':_0x57928f,'firstname':_0x57928f,'lastname':'_','mobilephone':null,'address1_telephone1':null,'ownerid@odata.bind':'/systemusers('+_0x481438[_0x37bf('0x1f')]+')'},'headers':{'Authorization':_0x37bf('0x16')+_0xc81fb4,'OData-Version':_0x37bf('0x17')},'json':!![],'resolveWithFullResponse':!![]};_0x388415[_0x37bf('0x27')][_0x409100]=_0x57928f;return rp(_0x388415);})[_0x37bf('0x10')](function(_0x59fe22){var _0x435b50=_0x59fe22[_0x37bf('0x28')][_0x37bf('0x29')];var _0x431cfe=_0x435b50[_0x37bf('0x2a')](_0x435b50[_0x37bf('0x2b')]('(')+0x1,_0x435b50[_0x37bf('0x2b')](')'));_0x481438[_0x37bf('0x2c')]=_0x431cfe;_0x5b47e1(_0x481438);})['catch'](function(_0x4f3e45){_0x1f9646(_0x4f3e45[_0x37bf('0x15')]);});});}function getEndUser(_0x57219f,_0x846c1a,_0x35c011,_0x1192b4,_0x334614,_0x5340cf,_0xb86a82,_0x5276d8){var _0x4b2317=_0x5340cf[_0x37bf('0x22')]()===_0x37bf('0x23')?_0x334614['destcalleridnum']:_0x334614[_0x37bf('0x24')];return getAuthToken(_0x846c1a,_0x35c011,_0x5340cf)[_0x37bf('0x10')](function(_0x9e9f45){_0x5276d8=_0x5276d8?_0x5276d8:'telephone1';var _0x179db7={'method':'GET','uri':_0x1192b4+_0x37bf('0x2d')+_0x5276d8+_0x37bf('0x2e')+_0x5276d8+'\x20eq\x20\x27'+_0x4b2317[_0x37bf('0x2f')]('+','%2b')+'\x27','headers':{'Authorization':'Bearer\x20'+_0x9e9f45,'If-None-Match':null,'OData-Version':_0x37bf('0x17')},'json':!![]};return rp(_0x179db7);})[_0x37bf('0x10')](function(_0xde2407){var _0x15a529=![];if(!_0xde2407)return _0x15a529;var _0x5316aa=_0xde2407[_0x37bf('0x18')];for(var _0x26ee82=0x0;_0x26ee82<_0x5316aa[_0x37bf('0x30')];_0x26ee82++){if(_0x5316aa[_0x26ee82][_0x5276d8]===_0x4b2317){_0x15a529=!![];_0x57219f['enduserId']=_0x5316aa[_0x26ee82]['contactid'];}}return _0x15a529;})[_0x37bf('0x10')](function(_0x1be3de){if(_0x1be3de)return _0x57219f;if(_0xb86a82===_0x37bf('0x31')){logger[_0x37bf('0x1d')]('['+[_0x5340cf[_0x37bf('0x14')]()]+']\x20Enduser\x20NOT\x20Created\x20-\x20ModuleCreate\x20=\x20Nothing');return _0x57219f;}return createEndUser(_0x57219f,_0x846c1a,_0x35c011,_0x1192b4,_0x334614,_0x5340cf,_0x5276d8)[_0x37bf('0x10')](function(_0x19d669){logger['info']('['+[_0x5340cf[_0x37bf('0x14')]()]+_0x37bf('0x32'),_0x19d669['enduserId']);return _0x19d669;});});}function getCustomFields(_0x262bb9,_0x4d7dd5,_0x505494){var _0x4bbf65={};if(_0x262bb9[_0x37bf('0x30')]>0x0){_['forEach'](_0x262bb9,function(_0x254720){if(_['includes']([_0x37bf('0x33'),'picklist'],_0x254720['type'])&&_0x254720[_0x37bf('0x34')]&&!_0x254720[_0x37bf('0x35')]){var _0x2ccd8b=_0x254720[_0x37bf('0x36')]['toLowerCase']();var _0x4744e7=_0x2ccd8b['substring'](0x0,_0x2ccd8b[_0x37bf('0x37')]('_'));var _0x23cbc1=_0x2ccd8b[_0x37bf('0x2a')](_0x2ccd8b['indexOf']('_')+0x1);if(_0x4744e7===_0x505494){_0x4bbf65[_0x23cbc1]=_0x254720[_0x37bf('0x38')];}}});}return _0x4bbf65;}function getTicket(_0xbc4260,_0x1da5a9,_0xb853a2,_0x4016c7,_0x406715,_0x54e432,_0x52283d){return new Promise(function(_0x1dad73,_0x22ca56){var _0x1d0ad8;return getAuthToken(_0x1da5a9,_0xb853a2,_0x52283d)['then'](function(_0x4f15b5){if(_0x54e432[_0x37bf('0x39')]===_0x37bf('0x3a')){_0x1d0ad8={'method':'POST','uri':_0x4016c7+_0x37bf('0x3b'),'body':Object[_0x37bf('0x3c')]({},{'title':intUtil[_0x37bf('0x3d')](_0x54e432[_0x37bf('0x3e')],_0x406715,'\x20'),'description':intUtil[_0x37bf('0x3d')](_0x54e432[_0x37bf('0x3f')],_0x406715,'\x0a'),'customerid_contact@odata.bind':_0xbc4260[_0x37bf('0x2c')]?_0x37bf('0x40')+_0xbc4260[_0x37bf('0x2c')]+')':undefined,'ownerid@odata.bind':_0x37bf('0x41')+_0xbc4260[_0x37bf('0x1f')]+')','caseorigincode':'1'},getCustomFields(_0x54e432[_0x37bf('0x42')],_0x406715,_0x54e432[_0x37bf('0x39')])),'headers':{'Authorization':_0x37bf('0x16')+_0x4f15b5,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}if(_0x54e432['ticketType']===_0x37bf('0x43')){var _0x138bfc=_0xbc4260[_0x37bf('0x2c')]?[{'partyid_systemuser@odata.bind':_0x37bf('0x41')+_0xbc4260[_0x37bf('0x1f')]+')','participationtypemask':_0xbc4260[_0x37bf('0x44')]==='queue'?0x2:0x1},{'partyid_contact@odata.bind':_0x37bf('0x40')+_0xbc4260[_0x37bf('0x2c')]+')','participationtypemask':_0xbc4260[_0x37bf('0x44')]===_0x37bf('0x45')?0x1:0x2}]:[{'partyid_systemuser@odata.bind':'/systemusers('+_0xbc4260[_0x37bf('0x1f')]+')','participationtypemask':_0xbc4260[_0x37bf('0x44')]===_0x37bf('0x45')?0x2:0x1}];_0x1d0ad8={'method':_0x37bf('0x25'),'uri':_0x4016c7+_0x37bf('0x46'),'body':Object[_0x37bf('0x3c')]({},{'subject':intUtil[_0x37bf('0x3d')](_0x54e432['Subjects'],_0x406715,'\x20'),'phonenumber':String(_0x406715[_0x37bf('0x24')]),'description':intUtil[_0x37bf('0x3d')](_0x54e432[_0x37bf('0x3f')],_0x406715,'\x0a'),'regardingobjectid_contact@odata.bind':_0xbc4260[_0x37bf('0x2c')]?'/contacts('+_0xbc4260[_0x37bf('0x2c')]+')':undefined,'ownerid@odata.bind':_0x37bf('0x41')+_0xbc4260[_0x37bf('0x1f')]+')','directioncode':_0xbc4260['callDirection']===_0x37bf('0x45')?![]:!![],'phonecall_activity_parties':_0x138bfc},getCustomFields(_0x54e432['Fields'],_0x406715,_0x54e432[_0x37bf('0x39')])),'headers':{'Authorization':'Bearer\x20'+_0x4f15b5,'OData-Version':'4.0'},'json':!![],'resolveWithFullResponse':!![]};}return rp(_0x1d0ad8);})[_0x37bf('0x10')](function(_0x10570){var _0x78c88b=_0x10570['headers'][_0x37bf('0x29')];var _0x46ba90=_0x78c88b[_0x37bf('0x2a')](_0x78c88b['lastIndexOf']('(')+0x1,_0x78c88b['lastIndexOf'](')'));_0xbc4260['ticketId']=_0x46ba90;_0x1dad73(_0xbc4260);})['catch'](function(_0xec0639){_0x22ca56(_0xec0639[_0x37bf('0x15')]);});});}function emit(_0x482f70,_0x3ed503,_0x3d39c7,_0x79de5c){var _0x55f22c={'uri':util[_0x37bf('0x47')](_0x37bf('0x48'),_0x482f70,_0x3d39c7,_0x79de5c)};io['to'](util[_0x37bf('0x47')](_0x37bf('0x49'),_0x3ed503))[_0x37bf('0x4a')](_0x37bf('0x4b'),_0x55f22c);}exports['cs']=function(_0x2b4d7,_0x2c544a,_0x5aea6c,_0x128ddf,_0x2a4478,_0x39d8c,_0x321746,_0x258003){var _0x1b663b={};_0x39d8c[_0x37bf('0x8')]=_0x39d8c[_0x37bf('0x7')]?intUtil['stripTrailingSlash'](_0x39d8c['CloudProvider']['data7']):intUtil[_0x37bf('0x4c')](_0x39d8c[_0x37bf('0x8')]);_0x39d8c[_0x37bf('0x4d')]=intUtil[_0x37bf('0x4c')](_0x39d8c['serverUrl']);_0x1b663b[_0x37bf('0x44')]=_0x258003==='queue'||_0x258003===_0x37bf('0x4e')?_0x37bf('0x45'):_0x37bf('0x23');var _0x5c610e=_0x39d8c['modernAuthentication']?util[_0x37bf('0x47')](_0x37bf('0x4f'),_0x39d8c[_0x37bf('0x9')]['data7']):util[_0x37bf('0x47')](_0x37bf('0x4f'),_0x39d8c[_0x37bf('0x8')]);var _0x126c14=util[_0x37bf('0x47')](_0x37bf('0x50'),_0x39d8c[_0x37bf('0xb')]);var _0x1d0070=util[_0x37bf('0x47')](_0x37bf('0x51'),_0x39d8c[_0x37bf('0x4d')],_0x2c544a[_0x37bf('0x52')],md5(_0x2c544a[_0x37bf('0x52')]));if(_0x2a4478&&_0x2a4478['monitor_format']){logger[_0x37bf('0x1d')](_0x37bf('0x53'),_0x37bf('0x54'));_0x2c544a[_0x37bf('0x55')]=_0x1d0070;}else if(_0x321746&&_0x321746[_0x37bf('0x56')]&&_0x321746[_0x37bf('0x56')]!==_0x37bf('0x57')){logger['info'](_0x37bf('0x58'),'Recording\x20is\x20enabled!');_0x2c544a['recordingURL']=_0x1d0070;}else{_0x2c544a[_0x37bf('0x55')]='';}return getUser(_0x1b663b,_0x39d8c,_0x128ddf,_0x126c14,_0x5c610e,_0x258003)[_0x37bf('0x10')](function(_0x354bf1){logger[_0x37bf('0x1d')]('['+_0x258003[_0x37bf('0x14')]()+_0x37bf('0x59'),_0x354bf1[_0x37bf('0x1f')]);logger[_0x37bf('0x1d')]('['+_0x258003[_0x37bf('0x14')]()+']\x20The\x20User\x20email\x20is:',_0x354bf1[_0x37bf('0x21')]);return getEndUser(_0x354bf1,_0x39d8c,_0x126c14,_0x5c610e,_0x2c544a,_0x258003,_0x5aea6c['moduleCreate'],_0x5aea6c[_0x37bf('0x5a')]);})[_0x37bf('0x10')](function(_0x4a8c63){logger[_0x37bf('0x1d')]('['+_0x258003['toUpperCase']()+_0x37bf('0x5b'),_0x4a8c63[_0x37bf('0x2c')]);logger['info']('['+_0x258003['toUpperCase']()+']\x20The\x20Enduser\x20phone\x20is:',_0x2c544a['calleridnum']);return getTicket(_0x4a8c63,_0x39d8c,_0x126c14,_0x5c610e,_0x2c544a,_0x5aea6c,_0x258003);})['then'](function(_0x50f449){logger[_0x37bf('0x1d')](util[_0x37bf('0x47')]('['+_0x258003['toUpperCase']()+_0x37bf('0x5c'),_0x5aea6c[_0x37bf('0x39')],_0x50f449[_0x37bf('0x5d')]));logger[_0x37bf('0x1d')](util[_0x37bf('0x47')]('['+_0x258003['toUpperCase']()+']\x20Call\x20direction:\x20%s',_0x258003));if(_0x258003!==_0x37bf('0x4e')&&_0x5aea6c[_0x37bf('0x5e')]){logger[_0x37bf('0x1d')]('['+_0x258003[_0x37bf('0x14')]()+']',_0x37bf('0x5f'));emit(_0x39d8c[_0x37bf('0x8')],_0x128ddf[_0x37bf('0x60')],_0x5aea6c[_0x37bf('0x39')],_0x50f449[_0x37bf('0x5d')]);}})[_0x37bf('0x12')](function(_0x36e433){logger['error']('['+_0x258003[_0x37bf('0x14')]()+_0x37bf('0x61'),_0x36e433[_0x37bf('0x15')]);console[_0x37bf('0x13')](_0x37bf('0x62'),_0x36e433);});};
\ No newline at end of file