Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index 193085f..0381f18 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbfe0=['stack','info','format','ActiveUsers','isArrayLikeObject','findIndex','users','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','Administrator','user','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','Zoho-oauthtoken\x20','data','SUCCESS','details','enduserType','CREATE\x20ERROR','GET','moduleSearch','uri','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','/crm/v2/Contacts/search?criteria=((Phone:equals:','lead','Leads','Creating\x20new\x20call...','Owner','Subject','getString','Subjects','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','What_Id','$se_module','talktime','utc','mm:ss','answertime','endtime','Call_Duration','YYYY-MM-DDTHH:mm:ss','diff','called','Called','complete','Answered','Rejected','abandoned','Call_Result','Abandoned','timeout','Timeout','Call_Start_Time','outbound','starttime','agentcalledAt','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','code','Call\x20created!','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','/api/voice/recordings/','uniqueid','recordingURL','com','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','zoho.eu','Outbound','https://crm.','lastevent','/downloads?type=uniqueid&token=','toUpperCase','lodash','md5','util','moment','ioredis','bluebird','../../../../config/environment','../../../../config/logger','redis','defaults','debug','stringify','length','includes','string','picklist','toString','type','variable','idField','variableName','customVariable','name','Variable','toLowerCase','indexOf','split','isNil','access_token','isBefore','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','POST','refreshToken','refresh_token','then','seconds','catch','error','Failing\x20creating\x20the\x20access_token'];(function(_0x1a51c8,_0x2ff411){var _0x13bd4c=function(_0x4f0117){while(--_0x4f0117){_0x1a51c8['push'](_0x1a51c8['shift']());}};_0x13bd4c(++_0x2ff411);}(_0xbfe0,0x6d));var _0x0bfe=function(_0x9aada2,_0xd2d349){_0x9aada2=_0x9aada2-0x0;var _0x196dff=_0xbfe0[_0x9aada2];return _0x196dff;};'use strict';var _=require(_0x0bfe('0x0'));var rp=require('request-promise');var md5=require(_0x0bfe('0x1'));var util=require(_0x0bfe('0x2'));var intUtil=require('./util');var moment=require(_0x0bfe('0x3'));var Redis=require(_0x0bfe('0x4'));var BPromise=require(_0x0bfe('0x5'));var config=require(_0x0bfe('0x6'));var logger=require(_0x0bfe('0x7'))('zoho');config[_0x0bfe('0x8')]=_[_0x0bfe('0x9')](config['redis'],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x0bfe('0x8')]));function emit(_0x547026,_0xaa5e8e,_0x3761ff){io['to'](_0x547026)['emit'](_0xaa5e8e,_0x3761ff);}function request(_0x55c532){logger[_0x0bfe('0xa')]('[HTTP]',JSON[_0x0bfe('0xb')](_0x55c532));return rp(_0x55c532);}function getCustomFields(_0x2dacf8,_0x1acf04){var _0x2ea0aa={};if(_0x2dacf8[_0x0bfe('0xc')]>0x0){_['forEach'](_0x2dacf8,function(_0x3abde6){if(_[_0x0bfe('0xd')]([_0x0bfe('0xe'),_0x0bfe('0xf')],_0x3abde6['type'])&&_0x3abde6['idField']){_0x2ea0aa[_0x3abde6['idField']]=_0x3abde6['content'][_0x0bfe('0x10')]();}else if(_0x3abde6[_0x0bfe('0x11')]===_0x0bfe('0x12')&&_0x3abde6['variableName']&&_0x3abde6[_0x0bfe('0x13')]&&_0x1acf04[_0x3abde6[_0x0bfe('0x14')]]){_0x2ea0aa[_0x3abde6['idField']]=_0x1acf04[_0x3abde6['variableName']][_0x0bfe('0x10')]();}else if(_0x3abde6[_0x0bfe('0x11')]===_0x0bfe('0x15')&&_0x3abde6['Variable']&&_0x3abde6['Variable'][_0x0bfe('0x16')]&&_0x3abde6[_0x0bfe('0x13')]&&_0x1acf04[_0x3abde6[_0x0bfe('0x17')]['name']['toLowerCase']()]){_0x2ea0aa[_0x3abde6[_0x0bfe('0x13')]]=_0x1acf04[_0x3abde6['Variable'][_0x0bfe('0x16')][_0x0bfe('0x18')]()][_0x0bfe('0x10')]();}});}return _0x2ea0aa;}function getName(_0x2b85a5){if(_0x2b85a5[_0x0bfe('0x19')]('\x20')>0x0){var _0x58cdee=_0x2b85a5[_0x0bfe('0x1a')](/ (.+)/);if(_0x58cdee[0x1]){return _0x58cdee;}}return[_0x2b85a5,_0x2b85a5];}var accountsTokens={};function getAccessToken(_0x484e27){return new Promise(function(_0x26abfc,_0x227c9c){if(!_[_0x0bfe('0x1b')](accountsTokens[_0x484e27['id']])&&!_[_0x0bfe('0x1b')](accountsTokens[_0x484e27['id']][_0x0bfe('0x1c')])){if(moment()[_0x0bfe('0x1d')](accountsTokens[_0x484e27['id']][_0x0bfe('0x1e')])){_0x26abfc(accountsTokens[_0x484e27['id']][_0x0bfe('0x1c')]);}}var _0x15ff34;switch(_0x484e27[_0x0bfe('0x1f')]){case'US':_0x15ff34=_0x0bfe('0x20');break;case'AU':_0x15ff34=_0x0bfe('0x21');break;case'EU':_0x15ff34=_0x0bfe('0x22');break;case'IN':_0x15ff34=_0x0bfe('0x23');break;case'CN':_0x15ff34='https://accounts.zoho.com.cn';break;default:_0x15ff34=_0x0bfe('0x22');break;}var _0x40c936={'method':_0x0bfe('0x24'),'uri':_0x15ff34+'/oauth/v2/token','qs':{'refresh_token':_0x484e27[_0x0bfe('0x25')],'client_id':_0x484e27['clientId'],'client_secret':_0x484e27['clientSecret'],'grant_type':_0x0bfe('0x26')},'json':!![]};return rp(_0x40c936)[_0x0bfe('0x27')](function(_0x29edc6){accountsTokens[_0x484e27['id']]={'access_token':_0x29edc6['access_token'],'expires_in':moment()['add'](_0x29edc6['expires_in'],_0x0bfe('0x28'))};_0x26abfc(_0x29edc6[_0x0bfe('0x1c')]);})[_0x0bfe('0x29')](function(_0xf2be94){logger[_0x0bfe('0x2a')](_0x0bfe('0x2b'),_0xf2be94[_0x0bfe('0x2c')]);_0x227c9c(_0xf2be94);});});}function getUser(_0xe2c4ed,_0x1d260d,_0x3593ac,_0x30cea7){logger[_0x0bfe('0x2d')]('Search\x20user');return request({'method':'GET','uri':util[_0x0bfe('0x2e')]('https://www.zohoapis.%s/crm/v2/users',_0x1d260d),'qs':{'type':_0x0bfe('0x2f')},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0xe2c4ed},'json':!![]})[_0x0bfe('0x27')](function(_0x15bcd4){if(_0x15bcd4['users']){var _0x319981=-0x1;if(_[_0x0bfe('0x30')](_0x15bcd4['users'])){if(!_[_0x0bfe('0x1b')](_0x30cea7)){_0x319981=_[_0x0bfe('0x31')](_0x15bcd4[_0x0bfe('0x32')],function(_0x4dd897){return _0x4dd897[_0x0bfe('0x33')]===_0x30cea7;});}if(_0x319981>=0x0){logger[_0x0bfe('0x2d')](_0x0bfe('0x34'));}else{logger[_0x0bfe('0x2d')](_0x0bfe('0x35'));_0x319981=_[_0x0bfe('0x31')](_0x15bcd4[_0x0bfe('0x32')],function(_0x56de79){return _0x56de79[_0x0bfe('0x36')][_0x0bfe('0x16')]===_0x0bfe('0x37');});}return _0x15bcd4['users'][_0x319981];}else{if(_0x15bcd4[_0x0bfe('0x38')][_0x0bfe('0x36')]['name']===_0x0bfe('0x37')){logger[_0x0bfe('0x2d')](_0x0bfe('0x35'));user=_0x15bcd4[_0x0bfe('0x38')];return user;}else{logger[_0x0bfe('0x2a')](_0x0bfe('0x39'),JSON[_0x0bfe('0xb')](_0x15bcd4));throw new Error(_0x0bfe('0x3a')+JSON[_0x0bfe('0xb')](_0x15bcd4));}}}else{logger[_0x0bfe('0x2a')](_0x0bfe('0x39'),JSON[_0x0bfe('0xb')](_0x15bcd4));throw new Error(_0x0bfe('0x3a')+JSON['stringify'](_0x15bcd4));}})['catch'](function(_0x56b422){console[_0x0bfe('0x2a')](_0x56b422);});}function getZohoUser(_0x5e4ba2,_0x394d81){return new BPromise(function(_0x455ab3,_0x4bea48){request(_0x5e4ba2)[_0x0bfe('0x27')](function(_0x2940c7){var _0x1f388a=null;if(_0x2940c7){_0x1f388a=_0x2940c7['data'][0x0];_0x1f388a['enduserType']=_0x394d81;}_0x455ab3(_0x1f388a);})[_0x0bfe('0x29')](function(_0x1fa15c){_0x4bea48(_0x1fa15c);});});}function createEndUser(_0x4b4569,_0x679fd9,_0x29902e,_0x5646fd,_0x1ed174,_0x311f4b){var _0x29902e=getName(_0x29902e);return request({'method':'POST','uri':_0x0bfe('0x3b')+_0x679fd9+_0x0bfe('0x3c')+_[_0x0bfe('0x3d')](_0x311f4b[_0x0bfe('0x3e')])+'s','body':{'data':[{'Last_Name':_0x29902e[0x1],'First_Name':_0x29902e[0x0],'Phone':_0x5646fd,'Owner':{'name':!_[_0x0bfe('0x1b')](_0x1ed174[_0x0bfe('0x3f')]['name'])?_0x1ed174[_0x0bfe('0x3f')][_0x0bfe('0x16')]:!_['isNil'](_0x1ed174[_0x0bfe('0x40')])?_0x1ed174[_0x0bfe('0x40')]+'\x20'+_0x1ed174[_0x0bfe('0x41')]:_0x1ed174[_0x0bfe('0x41')],'id':_0x1ed174['id']}}]},'headers':{'Authorization':_0x0bfe('0x42')+_0x4b4569},'json':!![]})['then'](function(_0xdb5d72){if(_0xdb5d72&&_0xdb5d72[_0x0bfe('0x43')][0x0]['code']===_0x0bfe('0x44')){var _0x1cf30f=_0xdb5d72[_0x0bfe('0x43')][0x0][_0x0bfe('0x45')];_0x1cf30f[_0x0bfe('0x46')]=_[_0x0bfe('0x3d')](_0x311f4b['moduleCreate'])+'s';return _0x1cf30f;}logger[_0x0bfe('0x2a')]('The\x20failing\x20result\x20is',JSON[_0x0bfe('0xb')](data));throw new Error('Error:\x20'+JSON[_0x0bfe('0xb')](data));})[_0x0bfe('0x29')](function(_0x18ca23){console['log'](_0x0bfe('0x47'),_0x18ca23);});}function getEndUser(_0x3df733,_0x7e4c51,_0x4bf9f3,_0x2173ad,_0x56b388,_0x298ae0,_0x438c72){var _0xd48696={'method':_0x0bfe('0x48'),'uri':'','headers':{'Authorization':_0x0bfe('0x42')+_0x3df733},'json':!![]};switch(_0x438c72[_0x0bfe('0x49')]){case'contact_lead':_0xd48696[_0x0bfe('0x4a')]='https://www.zohoapis.'+_0x7e4c51+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x56b388+'))';return getZohoUser(_0xd48696,_0x0bfe('0x4b'))['then'](function(_0x261576){if(_0x261576)return _0x261576;_0xd48696[_0x0bfe('0x4a')]=_0x0bfe('0x3b')+_0x7e4c51+_0x0bfe('0x4c')+_0x56b388+'))';return getZohoUser(_0xd48696,'Leads')['then'](function(_0x16b3d5){if(_0x16b3d5)return _0x16b3d5;if(_0x438c72['moduleCreate']!=_0x0bfe('0x4d')){return createEndUser(_0x3df733,_0x7e4c51,_0x2173ad,_0x56b388,_0x298ae0,_0x438c72);}else{return{};}});});break;case _0x0bfe('0x4e'):_0xd48696[_0x0bfe('0x4a')]=_0x0bfe('0x3b')+_0x7e4c51+_0x0bfe('0x4f')+_0x56b388+'))';return getZohoUser(_0xd48696,_0x0bfe('0x4b'))[_0x0bfe('0x27')](function(_0x17e805){if(_0x17e805)return _0x17e805;if(_0x438c72[_0x0bfe('0x3e')]!=_0x0bfe('0x4d')){return createEndUser(_0x3df733,_0x7e4c51,_0x2173ad,_0x56b388,_0x298ae0,_0x438c72);}else{return{};}});break;case _0x0bfe('0x50'):_0xd48696[_0x0bfe('0x4a')]=_0x0bfe('0x3b')+_0x7e4c51+_0x0bfe('0x4c')+_0x56b388+'))';return getZohoUser(_0xd48696,_0x0bfe('0x51'))['then'](function(_0x54cffb){if(_0x54cffb)return _0x54cffb;if(_0x438c72[_0x0bfe('0x3e')]!='nothing'){return createEndUser(_0x3df733,_0x7e4c51,_0x2173ad,_0x56b388,_0x298ae0,_0x438c72);}else{return{};}});break;}}function getCall(_0x2e7e76,_0x110d9,_0xeb1b1f,_0x5a6985,_0x25c085,_0x576afc,_0x19f856,_0x3432b4){logger['info'](_0x0bfe('0x52'));var _0x3a9b43={};_0x3a9b43[_0x0bfe('0x53')]={'name':!_[_0x0bfe('0x1b')](_0x5a6985[_0x0bfe('0x3f')]['name'])&&!_['isNil'](_0x5a6985['profile'][_0x0bfe('0x16')])&&_0x5a6985[_0x0bfe('0x36')][_0x0bfe('0x16')]==='administrator'?_0x5a6985[_0x0bfe('0x3f')][_0x0bfe('0x16')]:!_[_0x0bfe('0x1b')](_0x5a6985['first_name'])?_0x5a6985[_0x0bfe('0x40')]+'\x20'+_0x5a6985[_0x0bfe('0x41')]:_0x5a6985[_0x0bfe('0x41')],'id':_0x5a6985['id']};_0x3a9b43[_0x0bfe('0x54')]=intUtil[_0x0bfe('0x55')](_0x576afc[_0x0bfe('0x56')],_0x19f856,'\x20');_0x3a9b43[_0x0bfe('0x57')]=intUtil['getString'](_0x576afc[_0x0bfe('0x58')],_0x19f856,'\x0a');if(_0x25c085[_0x0bfe('0x46')]===_0x0bfe('0x4b')){_0x3a9b43[_0x0bfe('0x59')]={'name':!_['isNil'](_0x25c085['Full_Name'])?_0x25c085[_0x0bfe('0x5a')]:!_[_0x0bfe('0x1b')](_0x25c085['First_Name'])?_0x25c085[_0x0bfe('0x5b')]+'\x20'+_0x25c085[_0x0bfe('0x5c')]:_0x25c085[_0x0bfe('0x5c')],'id':_0x25c085['id']};}if(_0x25c085[_0x0bfe('0x46')]===_0x0bfe('0x51')){_0x3a9b43[_0x0bfe('0x5d')]={'name':!_['isNil'](_0x25c085[_0x0bfe('0x5a')])?_0x25c085[_0x0bfe('0x5a')]:!_['isNil'](_0x25c085[_0x0bfe('0x5b')])?_0x25c085[_0x0bfe('0x5b')]+'\x20'+_0x25c085[_0x0bfe('0x5c')]:_0x25c085[_0x0bfe('0x5c')],'id':_0x25c085['id']};_0x3a9b43[_0x0bfe('0x5e')]=_[_0x0bfe('0x3d')](_0x25c085[_0x0bfe('0x46')]);}if(_0x19f856[_0x0bfe('0x5f')]){_0x3a9b43['Call_Duration']=moment[_0x0bfe('0x60')](parseInt(_0x19f856[_0x0bfe('0x5f')])*0x3e8)['format'](_0x0bfe('0x61'));}else if(_0x19f856[_0x0bfe('0x62')]&&_0x19f856[_0x0bfe('0x63')]){_0x3a9b43[_0x0bfe('0x64')]=moment[_0x0bfe('0x60')](moment(_0x19f856[_0x0bfe('0x63')],_0x0bfe('0x65'))[_0x0bfe('0x66')](moment(_0x19f856['starttime'],_0x0bfe('0x65'))))['format']('mm:ss');}switch(_0x19f856['lastevent']){case _0x0bfe('0x67'):_0x3a9b43['Call_Result']=_0x0bfe('0x68');break;case _0x0bfe('0x69'):case'connect':_0x3a9b43['Call_Result']=_0x0bfe('0x6a');break;case'rejected':_0x3a9b43['Call_Result']=_0x0bfe('0x6b');break;case _0x0bfe('0x6c'):_0x3a9b43[_0x0bfe('0x6d')]=_0x0bfe('0x6e');break;case _0x0bfe('0x6f'):_0x3a9b43['Call_Result']=_0x0bfe('0x70');default:}_0x3a9b43[_0x0bfe('0x71')]=(_0x3432b4===_0x0bfe('0x72')?moment(_0x19f856[_0x0bfe('0x73')])['format']('YYYY-MM-DDTHH:mm:ss'):moment(_0x19f856[_0x0bfe('0x74')])[_0x0bfe('0x2e')](_0x0bfe('0x65')))||moment()[_0x0bfe('0x2e')]('YYYY-MM-DDTHH:mm:ss');_0x3a9b43[_0x0bfe('0x75')]=_0x3432b4||_0x0bfe('0x76');_0x3a9b43=_[_0x0bfe('0x77')](_0x3a9b43,getCustomFields(_0x576afc[_0x0bfe('0x78')],_0x19f856));return request({'method':_0x0bfe('0x24'),'uri':_0x0bfe('0x3b')+_0x110d9+_0x0bfe('0x79'),'headers':{'Authorization':_0x0bfe('0x42')+_0x2e7e76},'body':{'data':[_0x3a9b43]},'json':!![]})['then'](function(_0x28e4a7){if(_0x28e4a7&&_0x28e4a7[_0x0bfe('0x43')][0x0][_0x0bfe('0x7a')]==='SUCCESS'){logger[_0x0bfe('0x2d')](_0x0bfe('0x7b'));return{'id':_0x28e4a7[_0x0bfe('0x43')][0x0][_0x0bfe('0x45')]['id']};}})['catch'](function(_0xe687c){logger['info'](_0x0bfe('0x7c'),_0xe687c[_0x0bfe('0x2c')]);console['log'](_0x0bfe('0x7c'),_0xe687c);});}exports[_0x0bfe('0x7d')]=function(_0x3db0ab,_0x40d8bc,_0x5e0794,_0x5ae16,_0x3c1e03,_0x4c4245){var _0x409fa9,_0x337afd,_0x3b2000;_0x4c4245[_0x0bfe('0x7e')]=intUtil[_0x0bfe('0x7f')](_0x4c4245['host']);_0x4c4245['serverUrl']=intUtil['stripTrailingSlash'](_0x4c4245[_0x0bfe('0x80')]);if(_0x3c1e03&&_0x3c1e03[_0x0bfe('0x81')]){logger[_0x0bfe('0x2d')](_0x0bfe('0x82'),_0x0bfe('0x83'));_0x40d8bc['recordingURL']=_0x4c4245[_0x0bfe('0x80')]+_0x0bfe('0x84')+_0x40d8bc['uniqueid']+'/downloads?type=uniqueid&token='+md5(_0x40d8bc[_0x0bfe('0x85')]);}else{_0x40d8bc[_0x0bfe('0x86')]='';}var _0xa9e50a=_0x4c4245[_0x0bfe('0x7e')]==='zoho.eu'?'eu':_0x0bfe('0x87');return getAccessToken(_0x4c4245)[_0x0bfe('0x27')](function(_0x107417){_0x3b2000=_0x107417;return getUser(_0x3b2000,_0xa9e50a,_0x4c4245,_0x5ae16[_0x0bfe('0x33')]);})[_0x0bfe('0x27')](function(_0x27bd23){_0x409fa9=_0x27bd23;logger['info'](_0x0bfe('0x88'),_0x409fa9['id']);return getEndUser(_0x3b2000,_0xa9e50a,_0x4c4245,_0x40d8bc[_0x0bfe('0x89')],_0x40d8bc[_0x0bfe('0x8a')],_0x409fa9,_0x5e0794);})[_0x0bfe('0x27')](function(_0x2402da){_0x337afd=_0x2402da;return getCall(_0x3b2000,_0xa9e50a,_0x4c4245,_0x409fa9,_0x337afd,_0x5e0794,_0x40d8bc,'Inbound');})[_0x0bfe('0x27')](function(_0x402dc5){if(_0x402dc5){logger[_0x0bfe('0x2d')](_0x0bfe('0x8b'),_0x402dc5['id']);logger['info'](_0x0bfe('0x82'),_0x0bfe('0x8c'));emit(util[_0x0bfe('0x2e')](_0x0bfe('0x8d'),_0x5ae16['name']),_0x0bfe('0x8e'),{'uri':'https://crm.'+_0x4c4245[_0x0bfe('0x7e')]+_0x0bfe('0x8f')+_0x402dc5['id']});}})['catch'](function(_0x55673c){logger[_0x0bfe('0x2a')](_0x0bfe('0x82'),JSON[_0x0bfe('0xb')](_0x55673c));});};exports['outbound']=function(_0x33eb11,_0x3b128e,_0x20b049,_0x553c20,_0x2d94c9,_0x355f35,_0x5ec396){var _0x4127d0,_0x284354,_0x54e928;_0x355f35['host']=intUtil[_0x0bfe('0x7f')](_0x355f35[_0x0bfe('0x7e')]);_0x355f35[_0x0bfe('0x80')]=intUtil[_0x0bfe('0x7f')](_0x355f35[_0x0bfe('0x80')]);if(_0x5ec396&&_0x5ec396[_0x0bfe('0x90')]&&_0x5ec396[_0x0bfe('0x90')]!==_0x0bfe('0x91')){logger[_0x0bfe('0x2d')](_0x0bfe('0x92'),_0x0bfe('0x83'));_0x3b128e['recordingURL']=_0x355f35[_0x0bfe('0x80')]+_0x0bfe('0x84')+_0x3b128e[_0x0bfe('0x85')]+'/downloads?type=uniqueid&token='+md5(_0x3b128e['uniqueid']);}var _0x333772=_0x355f35['host']===_0x0bfe('0x93')?'eu':_0x0bfe('0x87');return getAccessToken(_0x355f35)['then'](function(_0x2b7124){_0x54e928=_0x2b7124;return getUser(_0x54e928,_0x333772,_0x355f35,_0x553c20[_0x0bfe('0x33')]);})[_0x0bfe('0x27')](function(_0x3021c3){_0x4127d0=_0x3021c3;logger['info'](_0x0bfe('0x88'),_0x4127d0['id']);return getEndUser(_0x54e928,_0x333772,_0x355f35,_0x3b128e['destcalleridname'],_0x3b128e['destcalleridnum'],_0x4127d0,_0x20b049);})[_0x0bfe('0x27')](function(_0x44401f){_0x284354=_0x44401f;return getCall(_0x54e928,_0x333772,_0x355f35,_0x4127d0,_0x284354,_0x20b049,_0x3b128e,_0x0bfe('0x94'));})[_0x0bfe('0x27')](function(_0x27cbe1){if(_0x27cbe1){logger[_0x0bfe('0x2d')](_0x0bfe('0x8b'),_0x27cbe1['id']);logger[_0x0bfe('0x2d')]('[OUTBOUND]',_0x0bfe('0x8c'));emit(util[_0x0bfe('0x2e')](_0x0bfe('0x8d'),_0x553c20[_0x0bfe('0x16')]),_0x0bfe('0x8e'),{'uri':_0x0bfe('0x95')+_0x355f35[_0x0bfe('0x7e')]+'/crm/EntityInfo.do?module=Calls&id='+_0x27cbe1['id']});}})[_0x0bfe('0x29')](function(_0x17ec08){logger['error'](_0x0bfe('0x92'),JSON['stringify'](_0x17ec08));});};exports['unmanaged']=function(_0xbe1c8c,_0x1fffdb,_0x25e44d,_0x1c7fb4,_0x32fb36,_0x11438b){var _0x31c09d,_0x57efd5,_0x201324;_0x11438b[_0x0bfe('0x7e')]=intUtil[_0x0bfe('0x7f')](_0x11438b['host']);_0x11438b[_0x0bfe('0x80')]=intUtil[_0x0bfe('0x7f')](_0x11438b[_0x0bfe('0x80')]);if(_0x32fb36&&_0x32fb36[_0x0bfe('0x81')]){logger[_0x0bfe('0x2d')]('['+_0x1fffdb[_0x0bfe('0x96')]['toUpperCase']()+']',_0x0bfe('0x83'));_0x1fffdb[_0x0bfe('0x86')]=_0x11438b[_0x0bfe('0x80')]+'/api/voice/recordings/'+_0x1fffdb[_0x0bfe('0x85')]+_0x0bfe('0x97')+md5(_0x1fffdb[_0x0bfe('0x85')]);}else{_0x1fffdb[_0x0bfe('0x86')]='';}var _0x241c0b=_0x11438b[_0x0bfe('0x7e')]===_0x0bfe('0x93')?'eu':_0x0bfe('0x87');return getAccessToken(_0x11438b)[_0x0bfe('0x27')](function(_0xb8cd26){_0x201324=_0xb8cd26;return getUser(_0x201324,_0x241c0b,_0x11438b);})[_0x0bfe('0x27')](function(_0x5b4e28){_0x31c09d=_0x5b4e28;logger[_0x0bfe('0x2d')](_0x0bfe('0x88'),_0x31c09d['id']);return getEndUser(_0x201324,_0x241c0b,_0x11438b,_0x1fffdb[_0x0bfe('0x89')],_0x1fffdb[_0x0bfe('0x8a')],_0x31c09d,_0x25e44d);})['then'](function(_0x96c390){_0x57efd5=_0x96c390;return getCall(_0x201324,_0x241c0b,_0x11438b,_0x31c09d,_0x57efd5,_0x25e44d,_0x1fffdb,'Inbound');})['then'](function(_0x290144){if(_0x290144){logger[_0x0bfe('0x2d')](_0x0bfe('0x8b'),_0x290144['id']);}})[_0x0bfe('0x29')](function(_0x32aa47){logger['error']('['+_0x1fffdb['lastevent'][_0x0bfe('0x98')]()+']',JSON[_0x0bfe('0xb')](_0x32aa47));});};
\ No newline at end of file
+var _0x2f90=['Recording\x20is\x20enabled!','/api/voice/recordings/','uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','calleridname','calleridnum','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','/crm/EntityInfo.do?module=Calls&id=','[QUEUE]','recordingFormat','none','[OUTBOUND]','recordingURL','destcalleridname','destcalleridnum','Outbound','The\x20Call\x20ID\x20is:','trigger:browser:url','https://crm.','toUpperCase','The\x20User\x20ID\x20is:','request-promise','md5','util','./util','moment','ioredis','bluebird','../../../../config/environment','../../../../config/logger','redis','defaults','socket.io-emitter','emit','debug','[HTTP]','stringify','length','includes','picklist','type','idField','content','toString','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','access_token','isBefore','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','refreshToken','clientId','clientSecret','refresh_token','then','add','expires_in','seconds','catch','error','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','users','findIndex','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','The\x20failing\x20result\x20is','data','https://www.zohoapis.','/crm/v2/','startCase','role','first_name','last_name','Zoho-oauthtoken\x20','SUCCESS','details','enduserType','moduleCreate','Error:\x20','log','CREATE\x20ERROR','moduleSearch','contact_lead','uri','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','/crm/v2/Contacts/search?criteria=((Phone:equals:','lead','Leads','Owner','administrator','Subject','getString','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','$se_module','talktime','Call_Duration','utc','endtime','YYYY-MM-DDTHH:mm:ss','diff','starttime','mm:ss','lastevent','called','Called','complete','Call_Result','Answered','Rejected','abandoned','Abandoned','timeout','Timeout','outbound','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','code','queue','host','stripTrailingSlash','serverUrl','monitor_format'];(function(_0x23c217,_0x3aee12){var _0x53fcf8=function(_0x133202){while(--_0x133202){_0x23c217['push'](_0x23c217['shift']());}};_0x53fcf8(++_0x3aee12);}(_0x2f90,0x1e9));var _0x02f9=function(_0xfd80d5,_0x303f80){_0xfd80d5=_0xfd80d5-0x0;var _0xeb957d=_0x2f90[_0xfd80d5];return _0xeb957d;};'use strict';var _=require('lodash');var rp=require(_0x02f9('0x0'));var md5=require(_0x02f9('0x1'));var util=require(_0x02f9('0x2'));var intUtil=require(_0x02f9('0x3'));var moment=require(_0x02f9('0x4'));var Redis=require(_0x02f9('0x5'));var BPromise=require(_0x02f9('0x6'));var config=require(_0x02f9('0x7'));var logger=require(_0x02f9('0x8'))('zoho');config[_0x02f9('0x9')]=_[_0x02f9('0xa')](config[_0x02f9('0x9')],{'host':'localhost','port':0x18eb});var io=require(_0x02f9('0xb'))(new Redis(config['redis']));function emit(_0x34135f,_0x3b8788,_0x30ed8){io['to'](_0x34135f)[_0x02f9('0xc')](_0x3b8788,_0x30ed8);}function request(_0x180237){logger[_0x02f9('0xd')](_0x02f9('0xe'),JSON[_0x02f9('0xf')](_0x180237));return rp(_0x180237);}function getCustomFields(_0x45fbc8,_0x312a4a){var _0xff761d={};if(_0x45fbc8[_0x02f9('0x10')]>0x0){_['forEach'](_0x45fbc8,function(_0x3ff58f){if(_[_0x02f9('0x11')](['string',_0x02f9('0x12')],_0x3ff58f[_0x02f9('0x13')])&&_0x3ff58f['idField']){_0xff761d[_0x3ff58f[_0x02f9('0x14')]]=_0x3ff58f[_0x02f9('0x15')][_0x02f9('0x16')]();}else if(_0x3ff58f[_0x02f9('0x13')]==='variable'&&_0x3ff58f[_0x02f9('0x17')]&&_0x3ff58f[_0x02f9('0x14')]&&_0x312a4a[_0x3ff58f['variableName']]){_0xff761d[_0x3ff58f[_0x02f9('0x14')]]=_0x312a4a[_0x3ff58f[_0x02f9('0x17')]][_0x02f9('0x16')]();}else if(_0x3ff58f['type']===_0x02f9('0x18')&&_0x3ff58f[_0x02f9('0x19')]&&_0x3ff58f[_0x02f9('0x19')][_0x02f9('0x1a')]&&_0x3ff58f[_0x02f9('0x14')]&&_0x312a4a[_0x3ff58f[_0x02f9('0x19')][_0x02f9('0x1a')][_0x02f9('0x1b')]()]){_0xff761d[_0x3ff58f[_0x02f9('0x14')]]=_0x312a4a[_0x3ff58f[_0x02f9('0x19')]['name'][_0x02f9('0x1b')]()][_0x02f9('0x16')]();}});}return _0xff761d;}function getName(_0x19679a){if(_0x19679a[_0x02f9('0x1c')]('\x20')>0x0){var _0x2a8591=_0x19679a[_0x02f9('0x1d')](/ (.+)/);if(_0x2a8591[0x1]){return _0x2a8591;}}return[_0x19679a,_0x19679a];}var accountsTokens={};function getAccessToken(_0x3fedd5){return new Promise(function(_0xcf61b8,_0x498438){if(!_['isNil'](accountsTokens[_0x3fedd5['id']])&&!_[_0x02f9('0x1e')](accountsTokens[_0x3fedd5['id']][_0x02f9('0x1f')])){if(moment()[_0x02f9('0x20')](accountsTokens[_0x3fedd5['id']]['expires_in'])){_0xcf61b8(accountsTokens[_0x3fedd5['id']][_0x02f9('0x1f')]);}}var _0xcbc145;switch(_0x3fedd5[_0x02f9('0x21')]){case'US':_0xcbc145=_0x02f9('0x22');break;case'AU':_0xcbc145=_0x02f9('0x23');break;case'EU':_0xcbc145=_0x02f9('0x24');break;case'IN':_0xcbc145=_0x02f9('0x25');break;case'CN':_0xcbc145=_0x02f9('0x26');break;default:_0xcbc145=_0x02f9('0x24');break;}var _0x4f8ea6={'method':_0x02f9('0x27'),'uri':_0xcbc145+'/oauth/v2/token','qs':{'refresh_token':_0x3fedd5[_0x02f9('0x28')],'client_id':_0x3fedd5[_0x02f9('0x29')],'client_secret':_0x3fedd5[_0x02f9('0x2a')],'grant_type':_0x02f9('0x2b')},'json':!![]};return rp(_0x4f8ea6)[_0x02f9('0x2c')](function(_0x25e78f){accountsTokens[_0x3fedd5['id']]={'access_token':_0x25e78f[_0x02f9('0x1f')],'expires_in':moment()[_0x02f9('0x2d')](_0x25e78f[_0x02f9('0x2e')],_0x02f9('0x2f'))};_0xcf61b8(_0x25e78f[_0x02f9('0x1f')]);})[_0x02f9('0x30')](function(_0x3210b9){logger[_0x02f9('0x31')]('Failing\x20creating\x20the\x20access_token',_0x3210b9[_0x02f9('0x32')]);_0x498438(_0x3210b9);});});}function getUser(_0x2398d3,_0xef1e04,_0x24ad4b,_0x104fac){logger[_0x02f9('0x33')](_0x02f9('0x34'));return request({'method':_0x02f9('0x35'),'uri':util[_0x02f9('0x36')](_0x02f9('0x37'),_0xef1e04),'qs':{'type':_0x02f9('0x38')},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x2398d3},'json':!![]})['then'](function(_0x18e432){if(_0x18e432[_0x02f9('0x39')]){var _0x284f8f=-0x1;if(_['isArrayLikeObject'](_0x18e432[_0x02f9('0x39')])){if(!_[_0x02f9('0x1e')](_0x104fac)){_0x284f8f=_[_0x02f9('0x3a')](_0x18e432['users'],function(_0x3f3438){return _0x3f3438[_0x02f9('0x3b')]===_0x104fac;});}if(_0x284f8f>=0x0){logger[_0x02f9('0x33')](_0x02f9('0x3c'));}else{logger[_0x02f9('0x33')](_0x02f9('0x3d'));_0x284f8f=_[_0x02f9('0x3a')](_0x18e432[_0x02f9('0x39')],function(_0xe9e13d){return _0xe9e13d[_0x02f9('0x3e')][_0x02f9('0x1a')]==='Administrator';});}return _0x18e432[_0x02f9('0x39')][_0x284f8f];}else{if(_0x18e432['user']['profile'][_0x02f9('0x1a')]==='Administrator'){logger['info'](_0x02f9('0x3d'));user=_0x18e432['user'];return user;}else{logger[_0x02f9('0x31')]('The\x20failing\x20result\x20is',JSON[_0x02f9('0xf')](_0x18e432));throw new Error(_0x02f9('0x3f')+JSON[_0x02f9('0xf')](_0x18e432));}}}else{logger['error'](_0x02f9('0x40'),JSON['stringify'](_0x18e432));throw new Error(_0x02f9('0x3f')+JSON[_0x02f9('0xf')](_0x18e432));}})['catch'](function(_0x1a0bbd){console['error'](_0x1a0bbd);});}function getZohoUser(_0x329033,_0x2353ae){return new BPromise(function(_0x31e031,_0x56d69f){request(_0x329033)[_0x02f9('0x2c')](function(_0x415d10){var _0x593678=null;if(_0x415d10){_0x593678=_0x415d10[_0x02f9('0x41')][0x0];_0x593678['enduserType']=_0x2353ae;}_0x31e031(_0x593678);})[_0x02f9('0x30')](function(_0xa0d739){_0x56d69f(_0xa0d739);});});}function createEndUser(_0x252a35,_0x50e1b4,_0x30a722,_0x21c7ed,_0x1e4f98,_0x18ae6e){var _0x30a722=getName(_0x30a722);return request({'method':_0x02f9('0x27'),'uri':_0x02f9('0x42')+_0x50e1b4+_0x02f9('0x43')+_[_0x02f9('0x44')](_0x18ae6e['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x30a722[0x1],'First_Name':_0x30a722[0x0],'Phone':_0x21c7ed,'Owner':{'name':!_[_0x02f9('0x1e')](_0x1e4f98['role'][_0x02f9('0x1a')])?_0x1e4f98[_0x02f9('0x45')][_0x02f9('0x1a')]:!_[_0x02f9('0x1e')](_0x1e4f98[_0x02f9('0x46')])?_0x1e4f98[_0x02f9('0x46')]+'\x20'+_0x1e4f98[_0x02f9('0x47')]:_0x1e4f98[_0x02f9('0x47')],'id':_0x1e4f98['id']}}]},'headers':{'Authorization':_0x02f9('0x48')+_0x252a35},'json':!![]})[_0x02f9('0x2c')](function(_0x24460c){if(_0x24460c&&_0x24460c[_0x02f9('0x41')][0x0]['code']===_0x02f9('0x49')){var _0x5d578b=_0x24460c[_0x02f9('0x41')][0x0][_0x02f9('0x4a')];_0x5d578b[_0x02f9('0x4b')]=_[_0x02f9('0x44')](_0x18ae6e[_0x02f9('0x4c')])+'s';return _0x5d578b;}logger[_0x02f9('0x31')]('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error(_0x02f9('0x4d')+JSON['stringify'](data));})[_0x02f9('0x30')](function(_0x1d0a85){console[_0x02f9('0x4e')](_0x02f9('0x4f'),_0x1d0a85);});}function getEndUser(_0x32adca,_0x1b736d,_0x398b90,_0xd1baec,_0x1f6df0,_0x20c544,_0x268eac){var _0x1dd3be={'method':_0x02f9('0x35'),'uri':'','headers':{'Authorization':_0x02f9('0x48')+_0x32adca},'json':!![]};switch(_0x268eac[_0x02f9('0x50')]){case _0x02f9('0x51'):_0x1dd3be[_0x02f9('0x52')]=_0x02f9('0x42')+_0x1b736d+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x1f6df0+'))';return getZohoUser(_0x1dd3be,_0x02f9('0x53'))['then'](function(_0x29c442){if(_0x29c442)return _0x29c442;_0x1dd3be['uri']='https://www.zohoapis.'+_0x1b736d+_0x02f9('0x54')+_0x1f6df0+'))';return getZohoUser(_0x1dd3be,'Leads')[_0x02f9('0x2c')](function(_0xbc23c1){if(_0xbc23c1)return _0xbc23c1;if(_0x268eac[_0x02f9('0x4c')]!=_0x02f9('0x55')){return createEndUser(_0x32adca,_0x1b736d,_0xd1baec,_0x1f6df0,_0x20c544,_0x268eac);}else{return{};}});});break;case _0x02f9('0x56'):_0x1dd3be[_0x02f9('0x52')]=_0x02f9('0x42')+_0x1b736d+_0x02f9('0x57')+_0x1f6df0+'))';return getZohoUser(_0x1dd3be,_0x02f9('0x53'))[_0x02f9('0x2c')](function(_0x16a816){if(_0x16a816)return _0x16a816;if(_0x268eac[_0x02f9('0x4c')]!='nothing'){return createEndUser(_0x32adca,_0x1b736d,_0xd1baec,_0x1f6df0,_0x20c544,_0x268eac);}else{return{};}});break;case _0x02f9('0x58'):_0x1dd3be[_0x02f9('0x52')]=_0x02f9('0x42')+_0x1b736d+_0x02f9('0x54')+_0x1f6df0+'))';return getZohoUser(_0x1dd3be,_0x02f9('0x59'))[_0x02f9('0x2c')](function(_0x4341e0){if(_0x4341e0)return _0x4341e0;if(_0x268eac[_0x02f9('0x4c')]!=_0x02f9('0x55')){return createEndUser(_0x32adca,_0x1b736d,_0xd1baec,_0x1f6df0,_0x20c544,_0x268eac);}else{return{};}});break;}}function getCall(_0x5f14e7,_0x502368,_0x295781,_0x6e6d21,_0xddefd8,_0x2f8a7a,_0x3181f8,_0x18c331){logger[_0x02f9('0x33')]('Creating\x20new\x20call...');var _0x45689c={};_0x45689c[_0x02f9('0x5a')]={'name':!_[_0x02f9('0x1e')](_0x6e6d21[_0x02f9('0x45')][_0x02f9('0x1a')])&&!_[_0x02f9('0x1e')](_0x6e6d21[_0x02f9('0x3e')]['name'])&&_0x6e6d21[_0x02f9('0x3e')][_0x02f9('0x1a')]===_0x02f9('0x5b')?_0x6e6d21[_0x02f9('0x45')][_0x02f9('0x1a')]:!_['isNil'](_0x6e6d21['first_name'])?_0x6e6d21[_0x02f9('0x46')]+'\x20'+_0x6e6d21[_0x02f9('0x47')]:_0x6e6d21['last_name'],'id':_0x6e6d21['id']};_0x45689c[_0x02f9('0x5c')]=intUtil[_0x02f9('0x5d')](_0x2f8a7a['Subjects'],_0x3181f8,'\x20');_0x45689c['Description']=intUtil[_0x02f9('0x5d')](_0x2f8a7a[_0x02f9('0x5e')],_0x3181f8,'\x0a');if(_0xddefd8[_0x02f9('0x4b')]===_0x02f9('0x53')){_0x45689c[_0x02f9('0x5f')]={'name':!_['isNil'](_0xddefd8[_0x02f9('0x60')])?_0xddefd8[_0x02f9('0x60')]:!_['isNil'](_0xddefd8[_0x02f9('0x61')])?_0xddefd8[_0x02f9('0x61')]+'\x20'+_0xddefd8['Last_Name']:_0xddefd8['Last_Name'],'id':_0xddefd8['id']};}if(_0xddefd8[_0x02f9('0x4b')]==='Leads'){_0x45689c['What_Id']={'name':!_[_0x02f9('0x1e')](_0xddefd8['Full_Name'])?_0xddefd8[_0x02f9('0x60')]:!_[_0x02f9('0x1e')](_0xddefd8[_0x02f9('0x61')])?_0xddefd8['First_Name']+'\x20'+_0xddefd8[_0x02f9('0x62')]:_0xddefd8[_0x02f9('0x62')],'id':_0xddefd8['id']};_0x45689c[_0x02f9('0x63')]=_['startCase'](_0xddefd8[_0x02f9('0x4b')]);}if(_0x3181f8[_0x02f9('0x64')]){_0x45689c[_0x02f9('0x65')]=moment[_0x02f9('0x66')](parseInt(_0x3181f8['talktime'])*0x3e8)['format']('mm:ss');}else if(_0x3181f8['answertime']&&_0x3181f8[_0x02f9('0x67')]){_0x45689c[_0x02f9('0x65')]=moment['utc'](moment(_0x3181f8[_0x02f9('0x67')],_0x02f9('0x68'))[_0x02f9('0x69')](moment(_0x3181f8[_0x02f9('0x6a')],_0x02f9('0x68'))))[_0x02f9('0x36')](_0x02f9('0x6b'));}switch(_0x3181f8[_0x02f9('0x6c')]){case _0x02f9('0x6d'):_0x45689c['Call_Result']=_0x02f9('0x6e');break;case _0x02f9('0x6f'):case'connect':_0x45689c[_0x02f9('0x70')]=_0x02f9('0x71');break;case'rejected':_0x45689c[_0x02f9('0x70')]=_0x02f9('0x72');break;case _0x02f9('0x73'):_0x45689c['Call_Result']=_0x02f9('0x74');break;case _0x02f9('0x75'):_0x45689c[_0x02f9('0x70')]=_0x02f9('0x76');default:}_0x45689c['Call_Start_Time']=(_0x18c331===_0x02f9('0x77')?moment(_0x3181f8[_0x02f9('0x6a')])['format']('YYYY-MM-DDTHH:mm:ss'):moment(_0x3181f8['agentcalledAt'])[_0x02f9('0x36')](_0x02f9('0x68')))||moment()[_0x02f9('0x36')](_0x02f9('0x68'));_0x45689c[_0x02f9('0x78')]=_0x18c331||_0x02f9('0x79');_0x45689c=_[_0x02f9('0x7a')](_0x45689c,getCustomFields(_0x2f8a7a[_0x02f9('0x7b')],_0x3181f8));return request({'method':_0x02f9('0x27'),'uri':_0x02f9('0x42')+_0x502368+_0x02f9('0x7c'),'headers':{'Authorization':_0x02f9('0x48')+_0x5f14e7},'body':{'data':[_0x45689c]},'json':!![]})['then'](function(_0x3896cf){if(_0x3896cf&&_0x3896cf[_0x02f9('0x41')][0x0][_0x02f9('0x7d')]===_0x02f9('0x49')){logger[_0x02f9('0x33')]('Call\x20created!');return{'id':_0x3896cf[_0x02f9('0x41')][0x0]['details']['id']};}})[_0x02f9('0x30')](function(_0x91c036){logger[_0x02f9('0x33')]('err',_0x91c036[_0x02f9('0x32')]);console['log']('err',_0x91c036);});}exports[_0x02f9('0x7e')]=function(_0x1a5e46,_0x354a76,_0x8b0e4f,_0x9c0c48,_0x238ea0,_0x3befa6){var _0x25a9a1,_0x2bb96a,_0x4997c5;_0x3befa6[_0x02f9('0x7f')]=intUtil[_0x02f9('0x80')](_0x3befa6[_0x02f9('0x7f')]);_0x3befa6['serverUrl']=intUtil[_0x02f9('0x80')](_0x3befa6[_0x02f9('0x81')]);if(_0x238ea0&&_0x238ea0[_0x02f9('0x82')]){logger[_0x02f9('0x33')]('[QUEUE]',_0x02f9('0x83'));_0x354a76['recordingURL']=_0x3befa6[_0x02f9('0x81')]+_0x02f9('0x84')+_0x354a76[_0x02f9('0x85')]+_0x02f9('0x86')+md5(_0x354a76[_0x02f9('0x85')]);}else{_0x354a76['recordingURL']='';}var _0x2028b5=_0x3befa6[_0x02f9('0x7f')]===_0x02f9('0x87')?'eu':_0x02f9('0x88');return getAccessToken(_0x3befa6)[_0x02f9('0x2c')](function(_0x3f6104){_0x4997c5=_0x3f6104;return getUser(_0x4997c5,_0x2028b5,_0x3befa6,_0x9c0c48[_0x02f9('0x3b')]);})[_0x02f9('0x2c')](function(_0x3fd056){_0x25a9a1=_0x3fd056;logger[_0x02f9('0x33')]('The\x20User\x20ID\x20is:',_0x25a9a1['id']);return getEndUser(_0x4997c5,_0x2028b5,_0x3befa6,_0x354a76[_0x02f9('0x89')],_0x354a76[_0x02f9('0x8a')],_0x25a9a1,_0x8b0e4f);})[_0x02f9('0x2c')](function(_0x41d74a){_0x2bb96a=_0x41d74a;return getCall(_0x4997c5,_0x2028b5,_0x3befa6,_0x25a9a1,_0x2bb96a,_0x8b0e4f,_0x354a76,_0x02f9('0x79'));})['then'](function(_0x2fd37c){if(_0x2fd37c){logger['info']('The\x20Call\x20ID\x20is:',_0x2fd37c['id']);logger[_0x02f9('0x33')]('[QUEUE]',_0x02f9('0x8b'));emit(util[_0x02f9('0x36')](_0x02f9('0x8c'),_0x9c0c48[_0x02f9('0x1a')]),'trigger:browser:url',{'uri':'https://crm.'+_0x3befa6[_0x02f9('0x7f')]+_0x02f9('0x8d')+_0x2fd37c['id']});}})[_0x02f9('0x30')](function(_0x19f883){logger[_0x02f9('0x31')](_0x02f9('0x8e'),JSON['stringify'](_0x19f883));});};exports[_0x02f9('0x77')]=function(_0x3f0868,_0xb785fc,_0x58061a,_0x4c26af,_0x534133,_0x79fc13,_0x3f5ba8){var _0x2fcb5a,_0x2bdffc,_0x1b1e67;_0x79fc13['host']=intUtil[_0x02f9('0x80')](_0x79fc13[_0x02f9('0x7f')]);_0x79fc13['serverUrl']=intUtil[_0x02f9('0x80')](_0x79fc13[_0x02f9('0x81')]);if(_0x3f5ba8&&_0x3f5ba8[_0x02f9('0x8f')]&&_0x3f5ba8[_0x02f9('0x8f')]!==_0x02f9('0x90')){logger[_0x02f9('0x33')](_0x02f9('0x91'),_0x02f9('0x83'));_0xb785fc[_0x02f9('0x92')]=_0x79fc13[_0x02f9('0x81')]+_0x02f9('0x84')+_0xb785fc[_0x02f9('0x85')]+_0x02f9('0x86')+md5(_0xb785fc[_0x02f9('0x85')]);}var _0x4592ea=_0x79fc13[_0x02f9('0x7f')]==='zoho.eu'?'eu':'com';return getAccessToken(_0x79fc13)[_0x02f9('0x2c')](function(_0x2e6f59){_0x1b1e67=_0x2e6f59;return getUser(_0x1b1e67,_0x4592ea,_0x79fc13,_0x4c26af[_0x02f9('0x3b')]);})[_0x02f9('0x2c')](function(_0x527efc){_0x2fcb5a=_0x527efc;logger['info']('The\x20User\x20ID\x20is:',_0x2fcb5a['id']);return getEndUser(_0x1b1e67,_0x4592ea,_0x79fc13,_0xb785fc[_0x02f9('0x93')],_0xb785fc[_0x02f9('0x94')],_0x2fcb5a,_0x58061a);})[_0x02f9('0x2c')](function(_0x30a91b){_0x2bdffc=_0x30a91b;return getCall(_0x1b1e67,_0x4592ea,_0x79fc13,_0x2fcb5a,_0x2bdffc,_0x58061a,_0xb785fc,_0x02f9('0x95'));})['then'](function(_0x2f3bef){if(_0x2f3bef){logger['info'](_0x02f9('0x96'),_0x2f3bef['id']);logger[_0x02f9('0x33')]('[OUTBOUND]',_0x02f9('0x8b'));emit(util[_0x02f9('0x36')](_0x02f9('0x8c'),_0x4c26af[_0x02f9('0x1a')]),_0x02f9('0x97'),{'uri':_0x02f9('0x98')+_0x79fc13['host']+_0x02f9('0x8d')+_0x2f3bef['id']});}})[_0x02f9('0x30')](function(_0x1c14cf){logger[_0x02f9('0x31')](_0x02f9('0x91'),JSON['stringify'](_0x1c14cf));});};exports['unmanaged']=function(_0x913985,_0x18e7f1,_0x5c592b,_0x3fc590,_0x5e8bac,_0x2368a0){var _0x461703,_0x4a0911,_0xa497f;_0x2368a0[_0x02f9('0x7f')]=intUtil[_0x02f9('0x80')](_0x2368a0[_0x02f9('0x7f')]);_0x2368a0[_0x02f9('0x81')]=intUtil['stripTrailingSlash'](_0x2368a0[_0x02f9('0x81')]);if(_0x5e8bac&&_0x5e8bac[_0x02f9('0x82')]){logger[_0x02f9('0x33')]('['+_0x18e7f1['lastevent'][_0x02f9('0x99')]()+']',_0x02f9('0x83'));_0x18e7f1[_0x02f9('0x92')]=_0x2368a0[_0x02f9('0x81')]+_0x02f9('0x84')+_0x18e7f1['uniqueid']+'/downloads?type=uniqueid&token='+md5(_0x18e7f1[_0x02f9('0x85')]);}else{_0x18e7f1[_0x02f9('0x92')]='';}var _0x10f858=_0x2368a0['host']===_0x02f9('0x87')?'eu':_0x02f9('0x88');return getAccessToken(_0x2368a0)[_0x02f9('0x2c')](function(_0x4e5490){_0xa497f=_0x4e5490;return getUser(_0xa497f,_0x10f858,_0x2368a0);})[_0x02f9('0x2c')](function(_0xc3ec5){_0x461703=_0xc3ec5;logger[_0x02f9('0x33')](_0x02f9('0x9a'),_0x461703['id']);return getEndUser(_0xa497f,_0x10f858,_0x2368a0,_0x18e7f1[_0x02f9('0x89')],_0x18e7f1[_0x02f9('0x8a')],_0x461703,_0x5c592b);})[_0x02f9('0x2c')](function(_0x42d3b4){_0x4a0911=_0x42d3b4;return getCall(_0xa497f,_0x10f858,_0x2368a0,_0x461703,_0x4a0911,_0x5c592b,_0x18e7f1,_0x02f9('0x79'));})[_0x02f9('0x2c')](function(_0x12dd35){if(_0x12dd35){logger[_0x02f9('0x33')]('The\x20Call\x20ID\x20is:',_0x12dd35['id']);}})['catch'](function(_0x30b6e1){logger[_0x02f9('0x31')]('['+_0x18e7f1['lastevent'][_0x02f9('0x99')]()+']',JSON[_0x02f9('0xf')](_0x30b6e1));});};
\ No newline at end of file