Built motion from commit 129fb4d95212661e48f0db455e75d668addbaddf. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / zoho.js
index da323d1..e4ed79a 100644 (file)
@@ -1 +1 @@
-const a1147_0x2a4f=['clientId','Description','Call_Result','recordingURL','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','stack','called','Creating\x20new\x20call...','user','Subjects','com','Administrator','[HTTP]','access_token','Leads','The\x20failing\x20result\x20is','findIndex','Timeout','split','Rejected','calleridname','variableName','YYYY-MM-DDTHH:mm:ss','POST','uniqueid','../../../../rediscache','Subject','Abandoned','ActiveUsers','recordingFormat','nothing','answertime','user:%s','queue','[QUEUE]','isBefore','outbound','destcalleridname','zoho.eu','Call_Type','host','/downloads?type=uniqueid&token=','none','talktime','connect','utc','https://www.zohoapis.','users','Contacts','uri','destcalleridnum','zone','toLowerCase','name','https://accounts.zoho.com.cn','complete','Descriptions','moment','abandoned','then','Call_Duration','trigger:browser:url','lastevent','/crm/v2/Calls','toUpperCase','last_name','refresh_token','util','endtime','refreshToken','moduleSearch','https://accounts.zoho.com.au','What_Id','SUCCESS','https://accounts.zoho.in','code','role','The\x20Call\x20ID\x20is:','The\x20User\x20ID\x20is:','isNil','info','https://www.zohoapis.%s/crm/v2/users','idField','/crm/v2/','emit','/crm/v2/Contacts/search?criteria=((Phone:equals:','details','startCase','toString','https://crm.','Full_Name','timeout','data','starttime','Zoho-oauthtoken\x20','stringify','profile','type','email','request-promise-native','https://accounts.zoho.eu','Agent\x20found!','[OUTBOUND]','isArrayLikeObject','GET','/oauth/v2/token','/api/voice/recordings/','md5','catch','string','add','moduleCreate','Who_Id','variable','https://accounts.zoho.com','Outbound','clientSecret','/crm/EntityInfo.do?module=Calls&id=','Call\x20created!','enduserType','Variable','indexOf','./util','error','Error:\x20','Last_Name','forEach','log','agentcalledAt','stripTrailingSlash','rejected','Answered','First_Name','serverUrl','mm:ss','Failing\x20creating\x20the\x20access_token','unmanaged','Using\x20the\x20admin\x20account!','expires_in','format','getString','first_name','contact','/crm/v2/Leads/search?criteria=((Phone:equals:','Recording\x20is\x20enabled!','Fields','Inbound','monitor_format','debug'];(function(_0x1c9a8f,_0x2a4fff){const _0x177573=function(_0x55a3d3){while(--_0x55a3d3){_0x1c9a8f['push'](_0x1c9a8f['shift']());}};_0x177573(++_0x2a4fff);}(a1147_0x2a4f,0xbb));const a1147_0x1775=function(_0x1c9a8f,_0x2a4fff){_0x1c9a8f=_0x1c9a8f-0x0;let _0x177573=a1147_0x2a4f[_0x1c9a8f];return _0x177573;};const _0x569ecb=a1147_0x1775;'use strict';const _=require('lodash'),rp=require(_0x569ecb('0x3f')),md5=require(_0x569ecb('0x47')),util=require(_0x569ecb('0x1f')),intUtil=require(_0x569ecb('0x56')),moment=require(_0x569ecb('0x15')),logger=require('../../../../config/logger')('zoho'),{getSocket}=require(_0x569ecb('0x8b')),io=getSocket();function emit(_0x55a3d3,_0x5d661c,_0x13513f){const _0xfe4f64=_0x569ecb;io['to'](_0x55a3d3)[_0xfe4f64('0x30')](_0x5d661c,_0x13513f);}function request(_0x2d53e1){const _0x345cd6=_0x569ecb;return logger[_0x345cd6('0x70')](_0x345cd6('0x7e'),JSON[_0x345cd6('0x3b')](_0x2d53e1)),rp(_0x2d53e1);}function getCustomFields(_0x22ec01,_0x45d5b4){const _0x208a98=_0x569ecb,_0x32b18d={};return _0x22ec01['length']>0x0&&_[_0x208a98('0x5a')](_0x22ec01,function(_0x4f974c){const _0x1c7f36=_0x208a98;if(_0x4f974c[_0x1c7f36('0x3d')]===_0x1c7f36('0x49')&&_0x4f974c[_0x1c7f36('0x2e')])_0x32b18d[_0x4f974c[_0x1c7f36('0x2e')]]=_0x4f974c['content'][_0x1c7f36('0x34')]();else{if(_0x4f974c[_0x1c7f36('0x3d')]===_0x1c7f36('0x4d')&&_0x4f974c['variableName']&&_0x4f974c['idField']&&_0x45d5b4[_0x4f974c[_0x1c7f36('0x87')]])_0x32b18d[_0x4f974c[_0x1c7f36('0x2e')]]=_0x45d5b4[_0x4f974c[_0x1c7f36('0x87')]][_0x1c7f36('0x34')]();else _0x4f974c[_0x1c7f36('0x3d')]==='customVariable'&&_0x4f974c[_0x1c7f36('0x54')]&&_0x4f974c['Variable'][_0x1c7f36('0x11')]&&_0x4f974c['idField']&&_0x45d5b4[_0x4f974c[_0x1c7f36('0x54')]['name'][_0x1c7f36('0x10')]()]&&(_0x32b18d[_0x4f974c[_0x1c7f36('0x2e')]]=_0x45d5b4[_0x4f974c[_0x1c7f36('0x54')][_0x1c7f36('0x11')]['toLowerCase']()][_0x1c7f36('0x34')]());}}),_0x32b18d;}function getName(_0x55a5b1){const _0x3bea2a=_0x569ecb;if(_0x55a5b1[_0x3bea2a('0x55')]('\x20')>0x0){const _0xfa2983=_0x55a5b1[_0x3bea2a('0x84')](/ (.+)/);if(_0xfa2983[0x1])return _0xfa2983;}return[_0x55a5b1,_0x55a5b1];}const accountsTokens={};function getAccessToken(_0x6430b1){return new Promise(function(_0x336b04,_0x5d81b2){const _0x2c6e76=a1147_0x1775;!_[_0x2c6e76('0x2b')](accountsTokens[_0x6430b1['id']])&&!_[_0x2c6e76('0x2b')](accountsTokens[_0x6430b1['id']]['access_token'])&&(moment()[_0x2c6e76('0x95')](accountsTokens[_0x6430b1['id']][_0x2c6e76('0x66')])&&_0x336b04(accountsTokens[_0x6430b1['id']][_0x2c6e76('0x7f')]));let _0x59f031;switch(_0x6430b1[_0x2c6e76('0xf')]){case'US':_0x59f031=_0x2c6e76('0x4e');break;case'AU':_0x59f031=_0x2c6e76('0x23');break;case'EU':_0x59f031='https://accounts.zoho.eu';break;case'IN':_0x59f031=_0x2c6e76('0x26');break;case'CN':_0x59f031=_0x2c6e76('0x12');break;default:_0x59f031=_0x2c6e76('0x40');break;}const _0x24015d={'method':'POST','uri':_0x59f031+_0x2c6e76('0x45'),'qs':{'refresh_token':_0x6430b1[_0x2c6e76('0x21')],'client_id':_0x6430b1[_0x2c6e76('0x71')],'client_secret':_0x6430b1[_0x2c6e76('0x50')],'grant_type':_0x2c6e76('0x1e')},'json':!![]};return rp(_0x24015d)[_0x2c6e76('0x17')](function(_0x22b52a){const _0x50b470=_0x2c6e76;accountsTokens[_0x6430b1['id']]={'access_token':_0x22b52a[_0x50b470('0x7f')],'expires_in':moment()[_0x50b470('0x4a')](_0x22b52a[_0x50b470('0x66')],'seconds')},_0x336b04(_0x22b52a[_0x50b470('0x7f')]);})[_0x2c6e76('0x48')](function(_0x176428){const _0x32ca49=_0x2c6e76;logger[_0x32ca49('0x57')](_0x32ca49('0x63'),_0x176428['stack']),_0x5d81b2(_0x176428);});});}function getUser(_0x8c8264,_0x2de600,_0xda588a,_0x386866){const _0x4f5e70=_0x569ecb;return logger[_0x4f5e70('0x2c')]('Search\x20user'),request({'method':'GET','uri':util[_0x4f5e70('0x67')](_0x4f5e70('0x2d'),_0x2de600),'qs':{'type':_0x4f5e70('0x8e')},'headers':{'Authorization':_0x4f5e70('0x3a')+_0x8c8264},'json':!![]})['then'](function(_0x3a069a){const _0x33e6e1=_0x4f5e70;if(_0x3a069a['users']){let _0x1b70a5=-0x1;if(_[_0x33e6e1('0x43')](_0x3a069a['users']))return!_[_0x33e6e1('0x2b')](_0x386866)&&(_0x1b70a5=_[_0x33e6e1('0x82')](_0x3a069a[_0x33e6e1('0xb')],function(_0x27dd33){const _0x7a44c5=_0x33e6e1;return _0x27dd33[_0x7a44c5('0x3e')]===_0x386866;})),_0x1b70a5>=0x0?logger['info'](_0x33e6e1('0x41')):(logger['info'](_0x33e6e1('0x65')),_0x1b70a5=_['findIndex'](_0x3a069a[_0x33e6e1('0xb')],function(_0x45b52c){const _0x35f403=_0x33e6e1;return _0x45b52c[_0x35f403('0x3c')]['name']==='Administrator';})),_0x3a069a['users'][_0x1b70a5];else{if(_0x3a069a[_0x33e6e1('0x7a')]['profile'][_0x33e6e1('0x11')]===_0x33e6e1('0x7d')){logger[_0x33e6e1('0x2c')](_0x33e6e1('0x65'));const _0x103868=_0x3a069a[_0x33e6e1('0x7a')];return _0x103868;}else{logger[_0x33e6e1('0x57')]('The\x20failing\x20result\x20is',JSON[_0x33e6e1('0x3b')](_0x3a069a));throw new Error(_0x33e6e1('0x76')+JSON[_0x33e6e1('0x3b')](_0x3a069a));}}}else{logger[_0x33e6e1('0x57')](_0x33e6e1('0x81'),JSON[_0x33e6e1('0x3b')](_0x3a069a));throw new Error(_0x33e6e1('0x76')+JSON[_0x33e6e1('0x3b')](_0x3a069a));}})[_0x4f5e70('0x48')](function(_0x19082d){const _0x195006=_0x4f5e70;console[_0x195006('0x57')](_0x19082d);});}function getZohoUser(_0x49139f,_0x394b2d){return new Promise(function(_0x42b645,_0x5e84f9){const _0x59a17f=a1147_0x1775;request(_0x49139f)[_0x59a17f('0x17')](function(_0x58803d){const _0x112244=_0x59a17f;let _0x436aaf=null;_0x58803d&&(_0x436aaf=_0x58803d[_0x112244('0x38')][0x0],_0x436aaf[_0x112244('0x53')]=_0x394b2d),_0x42b645(_0x436aaf);})[_0x59a17f('0x48')](function(_0x42433e){_0x5e84f9(_0x42433e);});});}function createEndUser(_0x53ce65,_0x14ad52,_0x31f76a,_0x299d57,_0x346d27,_0x175adc){const _0xb55057=_0x569ecb;return _0x31f76a=getName(_0x31f76a),request({'method':_0xb55057('0x89'),'uri':_0xb55057('0xa')+_0x14ad52+_0xb55057('0x2f')+_['startCase'](_0x175adc['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x31f76a[0x1],'First_Name':_0x31f76a[0x0],'Phone':_0x299d57,'Owner':{'name':!_[_0xb55057('0x2b')](_0x346d27['role'][_0xb55057('0x11')])?_0x346d27[_0xb55057('0x28')][_0xb55057('0x11')]:!_[_0xb55057('0x2b')](_0x346d27[_0xb55057('0x69')])?_0x346d27[_0xb55057('0x69')]+'\x20'+_0x346d27['last_name']:_0x346d27[_0xb55057('0x1d')],'id':_0x346d27['id']}}]},'headers':{'Authorization':_0xb55057('0x3a')+_0x53ce65},'json':!![]})['then'](function(_0x5716f3){const _0x43e750=_0xb55057;if(_0x5716f3&&_0x5716f3['data'][0x0][_0x43e750('0x27')]==='SUCCESS'){const _0x335010=_0x5716f3['data'][0x0][_0x43e750('0x32')];return _0x335010[_0x43e750('0x53')]=_[_0x43e750('0x33')](_0x175adc[_0x43e750('0x4b')])+'s',_0x335010;}const _0x5270d9=_0x5716f3[_0x43e750('0x38')];logger[_0x43e750('0x57')](_0x43e750('0x81'),JSON['stringify'](_0x5270d9));throw new Error(_0x43e750('0x58')+JSON[_0x43e750('0x3b')](_0x5270d9));})['catch'](function(_0x1d5664){const _0x1e00e4=_0xb55057;console[_0x1e00e4('0x5b')]('CREATE\x20ERROR',_0x1d5664);});}function getEndUser(_0x595a6e,_0x3acf46,_0x4f6467,_0x4c6105,_0x28af6a,_0x39c155,_0x57532e){const _0x1c4f6e=_0x569ecb,_0x4e44d3={'method':_0x1c4f6e('0x44'),'uri':'','headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x595a6e},'json':!![]};switch(_0x57532e[_0x1c4f6e('0x22')]){case'contact_lead':_0x4e44d3[_0x1c4f6e('0xd')]=_0x1c4f6e('0xa')+_0x3acf46+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x28af6a+'))';return getZohoUser(_0x4e44d3,_0x1c4f6e('0xc'))[_0x1c4f6e('0x17')](function(_0x15bf92){const _0x5f470b=_0x1c4f6e;if(_0x15bf92)return _0x15bf92;return _0x4e44d3[_0x5f470b('0xd')]=_0x5f470b('0xa')+_0x3acf46+_0x5f470b('0x6b')+_0x28af6a+'))',getZohoUser(_0x4e44d3,_0x5f470b('0x80'))[_0x5f470b('0x17')](function(_0x776244){const _0x4cfa62=_0x5f470b;if(_0x776244)return _0x776244;return _0x57532e['moduleCreate']!=_0x4cfa62('0x90')?createEndUser(_0x595a6e,_0x3acf46,_0x4c6105,_0x28af6a,_0x39c155,_0x57532e):{};});});case _0x1c4f6e('0x6a'):_0x4e44d3[_0x1c4f6e('0xd')]='https://www.zohoapis.'+_0x3acf46+_0x1c4f6e('0x31')+_0x28af6a+'))';return getZohoUser(_0x4e44d3,_0x1c4f6e('0xc'))[_0x1c4f6e('0x17')](function(_0x5e753a){const _0x1b43e9=_0x1c4f6e;if(_0x5e753a)return _0x5e753a;return _0x57532e[_0x1b43e9('0x4b')]!=_0x1b43e9('0x90')?createEndUser(_0x595a6e,_0x3acf46,_0x4c6105,_0x28af6a,_0x39c155,_0x57532e):{};});case'lead':_0x4e44d3['uri']=_0x1c4f6e('0xa')+_0x3acf46+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x28af6a+'))';return getZohoUser(_0x4e44d3,'Leads')['then'](function(_0x1eccd4){const _0x217804=_0x1c4f6e;if(_0x1eccd4)return _0x1eccd4;return _0x57532e[_0x217804('0x4b')]!=_0x217804('0x90')?createEndUser(_0x595a6e,_0x3acf46,_0x4c6105,_0x28af6a,_0x39c155,_0x57532e):{};});}}function getCall(_0x2f5452,_0x4129e0,_0x1c3582,_0x1dcd56,_0x2e967c,_0x3498cb,_0x59c546,_0x163b61){const _0x173ba8=_0x569ecb;logger[_0x173ba8('0x2c')](_0x173ba8('0x79'));let _0x16d759={};_0x16d759['Owner']={'name':!_[_0x173ba8('0x2b')](_0x1dcd56[_0x173ba8('0x28')][_0x173ba8('0x11')])&&!_['isNil'](_0x1dcd56[_0x173ba8('0x3c')][_0x173ba8('0x11')])&&_0x1dcd56[_0x173ba8('0x3c')][_0x173ba8('0x11')]==='administrator'?_0x1dcd56[_0x173ba8('0x28')][_0x173ba8('0x11')]:!_[_0x173ba8('0x2b')](_0x1dcd56[_0x173ba8('0x69')])?_0x1dcd56[_0x173ba8('0x69')]+'\x20'+_0x1dcd56['last_name']:_0x1dcd56['last_name'],'id':_0x1dcd56['id']},_0x16d759[_0x173ba8('0x8c')]=intUtil[_0x173ba8('0x68')](_0x3498cb[_0x173ba8('0x7b')],_0x59c546,'\x20'),_0x16d759[_0x173ba8('0x72')]=intUtil[_0x173ba8('0x68')](_0x3498cb[_0x173ba8('0x14')],_0x59c546,'\x0a');_0x2e967c[_0x173ba8('0x53')]===_0x173ba8('0xc')&&(_0x16d759[_0x173ba8('0x4c')]={'name':!_['isNil'](_0x2e967c[_0x173ba8('0x36')])?_0x2e967c[_0x173ba8('0x36')]:!_[_0x173ba8('0x2b')](_0x2e967c[_0x173ba8('0x60')])?_0x2e967c['First_Name']+'\x20'+_0x2e967c['Last_Name']:_0x2e967c['Last_Name'],'id':_0x2e967c['id']});_0x2e967c[_0x173ba8('0x53')]===_0x173ba8('0x80')&&(_0x16d759[_0x173ba8('0x24')]={'name':!_['isNil'](_0x2e967c[_0x173ba8('0x36')])?_0x2e967c[_0x173ba8('0x36')]:!_[_0x173ba8('0x2b')](_0x2e967c[_0x173ba8('0x60')])?_0x2e967c[_0x173ba8('0x60')]+'\x20'+_0x2e967c[_0x173ba8('0x59')]:_0x2e967c[_0x173ba8('0x59')],'id':_0x2e967c['id']},_0x16d759['$se_module']=_['startCase'](_0x2e967c[_0x173ba8('0x53')]));if(_0x59c546[_0x173ba8('0x7')])_0x16d759[_0x173ba8('0x18')]=moment[_0x173ba8('0x9')](parseInt(_0x59c546[_0x173ba8('0x7')])*0x3e8)[_0x173ba8('0x67')](_0x173ba8('0x62'));else _0x59c546[_0x173ba8('0x91')]&&_0x59c546[_0x173ba8('0x20')]&&(_0x16d759[_0x173ba8('0x18')]=moment['utc'](moment(_0x59c546['endtime'],_0x173ba8('0x88'))['diff'](moment(_0x59c546[_0x173ba8('0x39')],_0x173ba8('0x88'))))[_0x173ba8('0x67')](_0x173ba8('0x62')));switch(_0x59c546['lastevent']){case _0x173ba8('0x78'):_0x16d759[_0x173ba8('0x73')]='Called';break;case _0x173ba8('0x13'):case _0x173ba8('0x8'):_0x16d759['Call_Result']=_0x173ba8('0x5f');break;case _0x173ba8('0x5e'):_0x16d759[_0x173ba8('0x73')]=_0x173ba8('0x85');break;case _0x173ba8('0x16'):_0x16d759[_0x173ba8('0x73')]=_0x173ba8('0x8d');break;case _0x173ba8('0x37'):_0x16d759[_0x173ba8('0x73')]=_0x173ba8('0x83');break;default:break;}return _0x16d759['Call_Start_Time']=(_0x163b61===_0x173ba8('0x0')?moment(_0x59c546[_0x173ba8('0x39')])[_0x173ba8('0x67')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x59c546[_0x173ba8('0x5c')])[_0x173ba8('0x67')](_0x173ba8('0x88')))||moment()[_0x173ba8('0x67')](_0x173ba8('0x88')),_0x16d759[_0x173ba8('0x3')]=_0x163b61||_0x173ba8('0x6e'),_0x16d759=_['merge'](_0x16d759,getCustomFields(_0x3498cb[_0x173ba8('0x6d')],_0x59c546)),request({'method':'POST','uri':_0x173ba8('0xa')+_0x4129e0+_0x173ba8('0x1b'),'headers':{'Authorization':_0x173ba8('0x3a')+_0x2f5452},'body':{'data':[_0x16d759]},'json':!![]})['then'](function(_0x3da0ab){const _0x421264=_0x173ba8;if(_0x3da0ab&&_0x3da0ab[_0x421264('0x38')][0x0][_0x421264('0x27')]===_0x421264('0x25'))return logger[_0x421264('0x2c')](_0x421264('0x52')),{'id':_0x3da0ab[_0x421264('0x38')][0x0][_0x421264('0x32')]['id']};})[_0x173ba8('0x48')](function(_0x4f8e94){const _0x23d59a=_0x173ba8;logger['info']('err',_0x4f8e94[_0x23d59a('0x77')]),console[_0x23d59a('0x5b')]('err',_0x4f8e94);});}exports[_0x569ecb('0x93')]=function(_0x8c042b,_0x429484,_0x5cc2e0,_0x305b18,_0x307555,_0x42bff6){const _0x367589=_0x569ecb;let _0xccbb3b,_0x4eb2f1,_0x1744ca;_0x42bff6[_0x367589('0x4')]=intUtil[_0x367589('0x5d')](_0x42bff6[_0x367589('0x4')]),_0x42bff6['serverUrl']=intUtil['stripTrailingSlash'](_0x42bff6[_0x367589('0x61')]);_0x307555&&_0x307555['monitor_format']?(logger['info'](_0x367589('0x94'),_0x367589('0x6c')),_0x429484[_0x367589('0x74')]=_0x42bff6[_0x367589('0x61')]+_0x367589('0x46')+_0x429484[_0x367589('0x8a')]+'/downloads?type=uniqueid&token='+md5(_0x429484[_0x367589('0x8a')])):_0x429484['recordingURL']='';const _0x8810d9=_0x42bff6[_0x367589('0x4')]===_0x367589('0x2')?'eu':_0x367589('0x7c');return getAccessToken(_0x42bff6)[_0x367589('0x17')](function(_0x1098a8){const _0x4a471d=_0x367589;return _0x1744ca=_0x1098a8,getUser(_0x1744ca,_0x8810d9,_0x42bff6,_0x305b18[_0x4a471d('0x3e')]);})[_0x367589('0x17')](function(_0x4210ed){const _0x561f82=_0x367589;return _0xccbb3b=_0x4210ed,logger[_0x561f82('0x2c')]('The\x20User\x20ID\x20is:',_0xccbb3b['id']),getEndUser(_0x1744ca,_0x8810d9,_0x42bff6,_0x429484[_0x561f82('0x86')],_0x429484['calleridnum'],_0xccbb3b,_0x5cc2e0);})[_0x367589('0x17')](function(_0x290387){const _0x1af57d=_0x367589;return _0x4eb2f1=_0x290387,getCall(_0x1744ca,_0x8810d9,_0x42bff6,_0xccbb3b,_0x4eb2f1,_0x5cc2e0,_0x429484,_0x1af57d('0x6e'));})['then'](function(_0x3ca18a){const _0x20bd8e=_0x367589;_0x3ca18a&&(logger[_0x20bd8e('0x2c')](_0x20bd8e('0x29'),_0x3ca18a['id']),logger[_0x20bd8e('0x2c')](_0x20bd8e('0x94'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x20bd8e('0x67')]('user:%s',_0x305b18[_0x20bd8e('0x11')]),_0x20bd8e('0x19'),{'uri':_0x20bd8e('0x35')+_0x42bff6[_0x20bd8e('0x4')]+_0x20bd8e('0x51')+_0x3ca18a['id']}));})[_0x367589('0x48')](function(_0x4330d5){const _0x20dfec=_0x367589;logger[_0x20dfec('0x57')](_0x20dfec('0x94'),JSON[_0x20dfec('0x3b')](_0x4330d5));});},exports['outbound']=function(_0x4b11b5,_0x3bcadf,_0x483b82,_0xb936c2,_0x40e4fb,_0x30ef3c,_0x22f21c){const _0x512ec2=_0x569ecb;let _0x169c1a,_0x59315a,_0x3a6d74;_0x30ef3c[_0x512ec2('0x4')]=intUtil[_0x512ec2('0x5d')](_0x30ef3c['host']),_0x30ef3c[_0x512ec2('0x61')]=intUtil[_0x512ec2('0x5d')](_0x30ef3c[_0x512ec2('0x61')]);_0x22f21c&&_0x22f21c['recordingFormat']&&_0x22f21c[_0x512ec2('0x8f')]!==_0x512ec2('0x6')&&(logger[_0x512ec2('0x2c')](_0x512ec2('0x42'),_0x512ec2('0x6c')),_0x3bcadf[_0x512ec2('0x74')]=_0x30ef3c[_0x512ec2('0x61')]+'/api/voice/recordings/'+_0x3bcadf['uniqueid']+_0x512ec2('0x5')+md5(_0x3bcadf[_0x512ec2('0x8a')]));const _0x38db3c=_0x30ef3c['host']===_0x512ec2('0x2')?'eu':_0x512ec2('0x7c');return getAccessToken(_0x30ef3c)[_0x512ec2('0x17')](function(_0x368b71){const _0x5a55db=_0x512ec2;return _0x3a6d74=_0x368b71,getUser(_0x3a6d74,_0x38db3c,_0x30ef3c,_0xb936c2[_0x5a55db('0x3e')]);})[_0x512ec2('0x17')](function(_0x436fb6){const _0x1f855e=_0x512ec2;return _0x169c1a=_0x436fb6,logger[_0x1f855e('0x2c')](_0x1f855e('0x2a'),_0x169c1a['id']),getEndUser(_0x3a6d74,_0x38db3c,_0x30ef3c,_0x3bcadf[_0x1f855e('0x1')],_0x3bcadf[_0x1f855e('0xe')],_0x169c1a,_0x483b82);})[_0x512ec2('0x17')](function(_0x1aa98c){const _0x4bddf0=_0x512ec2;return _0x59315a=_0x1aa98c,getCall(_0x3a6d74,_0x38db3c,_0x30ef3c,_0x169c1a,_0x59315a,_0x483b82,_0x3bcadf,_0x4bddf0('0x4f'));})[_0x512ec2('0x17')](function(_0x5b33e7){const _0x51a341=_0x512ec2;_0x5b33e7&&(logger[_0x51a341('0x2c')](_0x51a341('0x29'),_0x5b33e7['id']),logger[_0x51a341('0x2c')]('[OUTBOUND]',_0x51a341('0x75')),emit(util[_0x51a341('0x67')](_0x51a341('0x92'),_0xb936c2['name']),_0x51a341('0x19'),{'uri':_0x51a341('0x35')+_0x30ef3c[_0x51a341('0x4')]+'/crm/EntityInfo.do?module=Calls&id='+_0x5b33e7['id']}));})['catch'](function(_0x383377){const _0x3e96d9=_0x512ec2;logger[_0x3e96d9('0x57')](_0x3e96d9('0x42'),JSON[_0x3e96d9('0x3b')](_0x383377));});},exports[_0x569ecb('0x64')]=function(_0x3639f8,_0x394079,_0x584456,_0x1dd447,_0x443b41,_0x3cbc47){const _0x104d04=_0x569ecb;let _0x26a3f7,_0x3a37ef,_0x2cdfc9;_0x3cbc47[_0x104d04('0x4')]=intUtil['stripTrailingSlash'](_0x3cbc47['host']),_0x3cbc47[_0x104d04('0x61')]=intUtil[_0x104d04('0x5d')](_0x3cbc47['serverUrl']);_0x443b41&&_0x443b41[_0x104d04('0x6f')]?(logger[_0x104d04('0x2c')]('['+_0x394079[_0x104d04('0x1a')][_0x104d04('0x1c')]()+']',_0x104d04('0x6c')),_0x394079['recordingURL']=_0x3cbc47[_0x104d04('0x61')]+_0x104d04('0x46')+_0x394079['uniqueid']+_0x104d04('0x5')+md5(_0x394079[_0x104d04('0x8a')])):_0x394079[_0x104d04('0x74')]='';const _0x380f8d=_0x3cbc47[_0x104d04('0x4')]===_0x104d04('0x2')?'eu':_0x104d04('0x7c');return getAccessToken(_0x3cbc47)[_0x104d04('0x17')](function(_0x5c30a8){return _0x2cdfc9=_0x5c30a8,getUser(_0x2cdfc9,_0x380f8d,_0x3cbc47);})['then'](function(_0x37b000){const _0x18cf97=_0x104d04;return _0x26a3f7=_0x37b000,logger[_0x18cf97('0x2c')](_0x18cf97('0x2a'),_0x26a3f7['id']),getEndUser(_0x2cdfc9,_0x380f8d,_0x3cbc47,_0x394079['calleridname'],_0x394079['calleridnum'],_0x26a3f7,_0x584456);})[_0x104d04('0x17')](function(_0x530336){const _0x2f7c3f=_0x104d04;return _0x3a37ef=_0x530336,getCall(_0x2cdfc9,_0x380f8d,_0x3cbc47,_0x26a3f7,_0x3a37ef,_0x584456,_0x394079,_0x2f7c3f('0x6e'));})[_0x104d04('0x17')](function(_0x212705){const _0x344d77=_0x104d04;_0x212705&&logger[_0x344d77('0x2c')](_0x344d77('0x29'),_0x212705['id']);})[_0x104d04('0x48')](function(_0x1141b1){const _0x3a0f2e=_0x104d04;logger[_0x3a0f2e('0x57')]('['+_0x394079[_0x3a0f2e('0x1a')][_0x3a0f2e('0x1c')]()+']',JSON['stringify'](_0x1141b1));});};
\ No newline at end of file
+const a1311_0x3c8c=['merge','https://accounts.zoho.in','data','idField','uniqueid','../../../../config/logger','monitor_format','refresh_token','Call_Type','/crm/EntityInfo.do?module=Calls&id=','trigger:browser:url','uri','unmanaged','GET','lead','variableName','startCase','toString','Contacts','connect','/api/voice/recordings/','Inbound','destcalleridnum','POST','clientId','agentcalledAt','log','Subjects','Abandoned','debug','The\x20failing\x20result\x20is','add','Agent\x20found!','stack','stringify','Timeout','catch','error','last_name','users','host','emit','access_token','enduserType','https://accounts.zoho.eu','details','content','talktime','getString','contact_lead','zoho.eu','https://www.zohoapis.%s/crm/v2/users','code','utc','Full_Name','Owner','/oauth/v2/token','err','abandoned','type','then','serverUrl','/downloads?type=uniqueid&token=','https://www.zohoapis.','indexOf','Call_Result','Variable','Creating\x20new\x20call...','Outbound','answertime','https://accounts.zoho.com.cn','profile','forEach','queue','https://accounts.zoho.com','/crm/v2/Contacts/search?criteria=((Phone:equals:','Who_Id','Using\x20the\x20admin\x20account!','recordingURL','util','calleridname','customVariable','rejected','/crm/v2/','seconds','request-promise-native','toUpperCase','endtime','https://crm.','user:%s','starttime','YYYY-MM-DDTHH:mm:ss','split','clientSecret','moduleSearch','administrator','moduleCreate','Answered','What_Id','Recording\x20is\x20enabled!','isNil','nothing','mm:ss','info','/crm/v2/Calls','https://accounts.zoho.com.au','lodash','Call_Start_Time','called','stripTrailingSlash','[OUTBOUND]','format','Subject','name','Zoho-oauthtoken\x20','first_name','/crm/v2/Leads/search?criteria=((Phone:equals:','[QUEUE]','com','variable','email','none','user','isArrayLikeObject','contact','expires_in','Leads','./util','zone','lastevent','Call\x20created!','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','Last_Name','Fields','The\x20User\x20ID\x20is:','isBefore','refreshToken','role','SUCCESS','Administrator','findIndex','outbound','First_Name','The\x20Call\x20ID\x20is:','toLowerCase','Call_Duration','calleridnum','recordingFormat'];(function(_0x1d37f5,_0x159ce4){const _0x3c8c49=function(_0x5bff8b){while(--_0x5bff8b){_0x1d37f5['push'](_0x1d37f5['shift']());}};_0x3c8c49(++_0x159ce4);}(a1311_0x3c8c,0x15f));const a1311_0x5bff=function(_0x1d37f5,_0x159ce4){_0x1d37f5=_0x1d37f5-0x17c;let _0x3c8c49=a1311_0x3c8c[_0x1d37f5];return _0x3c8c49;};const a1311_0x42e60a=a1311_0x5bff;'use strict';const _=require(a1311_0x42e60a(0x1af)),rp=require(a1311_0x42e60a(0x19a)),md5=require('md5'),util=require(a1311_0x42e60a(0x194)),intUtil=require(a1311_0x42e60a(0x1c4)),moment=require('moment'),logger=require(a1311_0x42e60a(0x1de))('zoho'),{getSocket}=require('../../../../rediscache'),io=getSocket();function emit(_0x218945,_0x24c31e,_0x2506c2){const _0x37a301=a1311_0x42e60a;io['to'](_0x218945)[_0x37a301(0x202)](_0x24c31e,_0x2506c2);}function request(_0x2751d5){const _0x3a9c8f=a1311_0x42e60a;return logger[_0x3a9c8f(0x1f6)]('[HTTP]',JSON[_0x3a9c8f(0x1fb)](_0x2751d5)),rp(_0x2751d5);}function getCustomFields(_0x44a3ee,_0x3dfcc9){const _0x1f4ce1=a1311_0x42e60a,_0x2bec8f={};return _0x44a3ee['length']>0x0&&_[_0x1f4ce1(0x18d)](_0x44a3ee,function(_0x1a98e0){const _0xa37d2c=_0x1f4ce1;if(_0x1a98e0[_0xa37d2c(0x180)]==='string'&&_0x1a98e0[_0xa37d2c(0x1dc)])_0x2bec8f[_0x1a98e0['idField']]=_0x1a98e0[_0xa37d2c(0x207)]['toString']();else{if(_0x1a98e0[_0xa37d2c(0x180)]===_0xa37d2c(0x1bc)&&_0x1a98e0[_0xa37d2c(0x1e8)]&&_0x1a98e0[_0xa37d2c(0x1dc)]&&_0x3dfcc9[_0x1a98e0[_0xa37d2c(0x1e8)]])_0x2bec8f[_0x1a98e0[_0xa37d2c(0x1dc)]]=_0x3dfcc9[_0x1a98e0[_0xa37d2c(0x1e8)]][_0xa37d2c(0x1ea)]();else _0x1a98e0[_0xa37d2c(0x180)]===_0xa37d2c(0x196)&&_0x1a98e0[_0xa37d2c(0x187)]&&_0x1a98e0[_0xa37d2c(0x187)][_0xa37d2c(0x1b6)]&&_0x1a98e0[_0xa37d2c(0x1dc)]&&_0x3dfcc9[_0x1a98e0[_0xa37d2c(0x187)][_0xa37d2c(0x1b6)][_0xa37d2c(0x1d5)]()]&&(_0x2bec8f[_0x1a98e0[_0xa37d2c(0x1dc)]]=_0x3dfcc9[_0x1a98e0['Variable'][_0xa37d2c(0x1b6)][_0xa37d2c(0x1d5)]()][_0xa37d2c(0x1ea)]());}}),_0x2bec8f;}function getName(_0x318e41){const _0x1e17fc=a1311_0x42e60a;if(_0x318e41[_0x1e17fc(0x185)]('\x20')>0x0){const _0x1a1f0d=_0x318e41[_0x1e17fc(0x1a1)](/ (.+)/);if(_0x1a1f0d[0x1])return _0x1a1f0d;}return[_0x318e41,_0x318e41];}const accountsTokens={};function getAccessToken(_0x2cd6a6){return new Promise(function(_0x762245,_0x4118d5){const _0x56758e=a1311_0x5bff;!_[_0x56758e(0x1a9)](accountsTokens[_0x2cd6a6['id']])&&!_[_0x56758e(0x1a9)](accountsTokens[_0x2cd6a6['id']]['access_token'])&&(moment()[_0x56758e(0x1cc)](accountsTokens[_0x2cd6a6['id']][_0x56758e(0x1c2)])&&_0x762245(accountsTokens[_0x2cd6a6['id']]['access_token']));let _0x2c0fa1;switch(_0x2cd6a6[_0x56758e(0x1c5)]){case'US':_0x2c0fa1=_0x56758e(0x18f);break;case'AU':_0x2c0fa1=_0x56758e(0x1ae);break;case'EU':_0x2c0fa1=_0x56758e(0x205);break;case'IN':_0x2c0fa1=_0x56758e(0x1da);break;case'CN':_0x2c0fa1=_0x56758e(0x18b);break;default:_0x2c0fa1=_0x56758e(0x205);break;}const _0x3638a8={'method':_0x56758e(0x1f0),'uri':_0x2c0fa1+_0x56758e(0x17d),'qs':{'refresh_token':_0x2cd6a6[_0x56758e(0x1cd)],'client_id':_0x2cd6a6[_0x56758e(0x1f1)],'client_secret':_0x2cd6a6[_0x56758e(0x1a2)],'grant_type':_0x56758e(0x1e0)},'json':!![]};return rp(_0x3638a8)[_0x56758e(0x181)](function(_0x2606ac){const _0x5d5173=_0x56758e;accountsTokens[_0x2cd6a6['id']]={'access_token':_0x2606ac[_0x5d5173(0x203)],'expires_in':moment()[_0x5d5173(0x1f8)](_0x2606ac['expires_in'],_0x5d5173(0x199))},_0x762245(_0x2606ac['access_token']);})[_0x56758e(0x1fd)](function(_0x2221ad){const _0x412f14=_0x56758e;logger['error']('Failing\x20creating\x20the\x20access_token',_0x2221ad[_0x412f14(0x1fa)]),_0x4118d5(_0x2221ad);});});}function getUser(_0x7e0615,_0x37983d,_0x44076d,_0x4284ce){const _0x160e3e=a1311_0x42e60a;return logger[_0x160e3e(0x1ac)]('Search\x20user'),request({'method':_0x160e3e(0x1e6),'uri':util['format'](_0x160e3e(0x20c),_0x37983d),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':_0x160e3e(0x1b7)+_0x7e0615},'json':!![]})[_0x160e3e(0x181)](function(_0x57882b){const _0x16fab2=_0x160e3e;if(_0x57882b[_0x16fab2(0x200)]){let _0x5e24a3=-0x1;if(_[_0x16fab2(0x1c0)](_0x57882b[_0x16fab2(0x200)]))return!_[_0x16fab2(0x1a9)](_0x4284ce)&&(_0x5e24a3=_[_0x16fab2(0x1d1)](_0x57882b['users'],function(_0x243210){return _0x243210['email']===_0x4284ce;})),_0x5e24a3>=0x0?logger[_0x16fab2(0x1ac)](_0x16fab2(0x1f9)):(logger[_0x16fab2(0x1ac)](_0x16fab2(0x192)),_0x5e24a3=_[_0x16fab2(0x1d1)](_0x57882b[_0x16fab2(0x200)],function(_0x1e6688){const _0x29fe42=_0x16fab2;return _0x1e6688[_0x29fe42(0x18c)][_0x29fe42(0x1b6)]===_0x29fe42(0x1d0);})),_0x57882b[_0x16fab2(0x200)][_0x5e24a3];else{if(_0x57882b[_0x16fab2(0x1bf)]['profile'][_0x16fab2(0x1b6)]===_0x16fab2(0x1d0)){logger[_0x16fab2(0x1ac)]('Using\x20the\x20admin\x20account!');const _0x426f7d=_0x57882b[_0x16fab2(0x1bf)];return _0x426f7d;}else{logger[_0x16fab2(0x1fe)](_0x16fab2(0x1f7),JSON[_0x16fab2(0x1fb)](_0x57882b));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0x16fab2(0x1fb)](_0x57882b));}}}else{logger['error']('The\x20failing\x20result\x20is',JSON[_0x16fab2(0x1fb)](_0x57882b));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0x16fab2(0x1fb)](_0x57882b));}})[_0x160e3e(0x1fd)](function(_0x3ed6a0){const _0x3fed5c=_0x160e3e;console[_0x3fed5c(0x1fe)](_0x3ed6a0);});}function getZohoUser(_0x34fc7c,_0x1dd1e7){return new Promise(function(_0x3c1c9f,_0x5ba615){const _0x129d6c=a1311_0x5bff;request(_0x34fc7c)[_0x129d6c(0x181)](function(_0x3be7b9){const _0x57c7d5=_0x129d6c;let _0x1692b9=null;_0x3be7b9&&(_0x1692b9=_0x3be7b9[_0x57c7d5(0x1db)][0x0],_0x1692b9[_0x57c7d5(0x204)]=_0x1dd1e7),_0x3c1c9f(_0x1692b9);})[_0x129d6c(0x1fd)](function(_0x1f39fe){_0x5ba615(_0x1f39fe);});});}function createEndUser(_0x938a8,_0x42f498,_0x2ec9ac,_0x385795,_0x5955d8,_0x56540b){const _0x345d23=a1311_0x42e60a;return _0x2ec9ac=getName(_0x2ec9ac),request({'method':_0x345d23(0x1f0),'uri':_0x345d23(0x184)+_0x42f498+_0x345d23(0x198)+_[_0x345d23(0x1e9)](_0x56540b[_0x345d23(0x1a5)])+'s','body':{'data':[{'Last_Name':_0x2ec9ac[0x1],'First_Name':_0x2ec9ac[0x0],'Phone':_0x385795,'Owner':{'name':!_[_0x345d23(0x1a9)](_0x5955d8['role'][_0x345d23(0x1b6)])?_0x5955d8[_0x345d23(0x1ce)][_0x345d23(0x1b6)]:!_['isNil'](_0x5955d8['first_name'])?_0x5955d8[_0x345d23(0x1b8)]+'\x20'+_0x5955d8[_0x345d23(0x1ff)]:_0x5955d8[_0x345d23(0x1ff)],'id':_0x5955d8['id']}}]},'headers':{'Authorization':_0x345d23(0x1b7)+_0x938a8},'json':!![]})[_0x345d23(0x181)](function(_0x4c5df8){const _0x458f50=_0x345d23;if(_0x4c5df8&&_0x4c5df8['data'][0x0]['code']===_0x458f50(0x1cf)){const _0x17136a=_0x4c5df8[_0x458f50(0x1db)][0x0][_0x458f50(0x206)];return _0x17136a['enduserType']=_['startCase'](_0x56540b[_0x458f50(0x1a5)])+'s',_0x17136a;}const _0x1f84d3=_0x4c5df8[_0x458f50(0x1db)];logger['error']('The\x20failing\x20result\x20is',JSON['stringify'](_0x1f84d3));throw new Error('Error:\x20'+JSON[_0x458f50(0x1fb)](_0x1f84d3));})[_0x345d23(0x1fd)](function(_0x1e3b8e){console['log']('CREATE\x20ERROR',_0x1e3b8e);});}function getEndUser(_0x5d2a14,_0x1d302d,_0x51a423,_0x39c86d,_0x1a1e12,_0x1d5775,_0x2d2ae8){const _0x427929=a1311_0x42e60a,_0x10d85b={'method':_0x427929(0x1e6),'uri':'','headers':{'Authorization':_0x427929(0x1b7)+_0x5d2a14},'json':!![]};switch(_0x2d2ae8[_0x427929(0x1a3)]){case _0x427929(0x20a):_0x10d85b[_0x427929(0x1e4)]=_0x427929(0x184)+_0x1d302d+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x1a1e12+'))';return getZohoUser(_0x10d85b,_0x427929(0x1eb))[_0x427929(0x181)](function(_0x3e428f){const _0x29ed4c=_0x427929;if(_0x3e428f)return _0x3e428f;return _0x10d85b['uri']=_0x29ed4c(0x184)+_0x1d302d+_0x29ed4c(0x1b9)+_0x1a1e12+'))',getZohoUser(_0x10d85b,'Leads')['then'](function(_0x2dd661){const _0x4e3d8d=_0x29ed4c;if(_0x2dd661)return _0x2dd661;return _0x2d2ae8[_0x4e3d8d(0x1a5)]!='nothing'?createEndUser(_0x5d2a14,_0x1d302d,_0x39c86d,_0x1a1e12,_0x1d5775,_0x2d2ae8):{};});});case _0x427929(0x1c1):_0x10d85b['uri']=_0x427929(0x184)+_0x1d302d+_0x427929(0x190)+_0x1a1e12+'))';return getZohoUser(_0x10d85b,_0x427929(0x1eb))['then'](function(_0x3c4935){const _0x480db6=_0x427929;if(_0x3c4935)return _0x3c4935;return _0x2d2ae8[_0x480db6(0x1a5)]!=_0x480db6(0x1aa)?createEndUser(_0x5d2a14,_0x1d302d,_0x39c86d,_0x1a1e12,_0x1d5775,_0x2d2ae8):{};});case _0x427929(0x1e7):_0x10d85b['uri']=_0x427929(0x184)+_0x1d302d+_0x427929(0x1b9)+_0x1a1e12+'))';return getZohoUser(_0x10d85b,_0x427929(0x1c3))[_0x427929(0x181)](function(_0x239362){const _0x101c51=_0x427929;if(_0x239362)return _0x239362;return _0x2d2ae8[_0x101c51(0x1a5)]!=_0x101c51(0x1aa)?createEndUser(_0x5d2a14,_0x1d302d,_0x39c86d,_0x1a1e12,_0x1d5775,_0x2d2ae8):{};});}}function getCall(_0x3ff4c4,_0x1c4c8e,_0x1af2c2,_0x585acb,_0x2fb0eb,_0x29bf43,_0x2a7acb,_0x1d3bb6){const _0x52450a=a1311_0x42e60a;logger[_0x52450a(0x1ac)](_0x52450a(0x188));let _0x5f03e6={};_0x5f03e6[_0x52450a(0x17c)]={'name':!_[_0x52450a(0x1a9)](_0x585acb[_0x52450a(0x1ce)][_0x52450a(0x1b6)])&&!_['isNil'](_0x585acb['profile'][_0x52450a(0x1b6)])&&_0x585acb[_0x52450a(0x18c)][_0x52450a(0x1b6)]===_0x52450a(0x1a4)?_0x585acb[_0x52450a(0x1ce)][_0x52450a(0x1b6)]:!_['isNil'](_0x585acb[_0x52450a(0x1b8)])?_0x585acb[_0x52450a(0x1b8)]+'\x20'+_0x585acb[_0x52450a(0x1ff)]:_0x585acb[_0x52450a(0x1ff)],'id':_0x585acb['id']},_0x5f03e6[_0x52450a(0x1b5)]=intUtil[_0x52450a(0x209)](_0x29bf43[_0x52450a(0x1f4)],_0x2a7acb,'\x20'),_0x5f03e6['Description']=intUtil['getString'](_0x29bf43['Descriptions'],_0x2a7acb,'\x0a');_0x2fb0eb['enduserType']===_0x52450a(0x1eb)&&(_0x5f03e6[_0x52450a(0x191)]={'name':!_[_0x52450a(0x1a9)](_0x2fb0eb[_0x52450a(0x20f)])?_0x2fb0eb[_0x52450a(0x20f)]:!_[_0x52450a(0x1a9)](_0x2fb0eb['First_Name'])?_0x2fb0eb[_0x52450a(0x1d3)]+'\x20'+_0x2fb0eb[_0x52450a(0x1c9)]:_0x2fb0eb[_0x52450a(0x1c9)],'id':_0x2fb0eb['id']});_0x2fb0eb[_0x52450a(0x204)]===_0x52450a(0x1c3)&&(_0x5f03e6[_0x52450a(0x1a7)]={'name':!_['isNil'](_0x2fb0eb[_0x52450a(0x20f)])?_0x2fb0eb[_0x52450a(0x20f)]:!_[_0x52450a(0x1a9)](_0x2fb0eb['First_Name'])?_0x2fb0eb[_0x52450a(0x1d3)]+'\x20'+_0x2fb0eb['Last_Name']:_0x2fb0eb[_0x52450a(0x1c9)],'id':_0x2fb0eb['id']},_0x5f03e6['$se_module']=_[_0x52450a(0x1e9)](_0x2fb0eb[_0x52450a(0x204)]));if(_0x2a7acb['talktime'])_0x5f03e6[_0x52450a(0x1d6)]=moment[_0x52450a(0x20e)](parseInt(_0x2a7acb[_0x52450a(0x208)])*0x3e8)[_0x52450a(0x1b4)](_0x52450a(0x1ab));else _0x2a7acb[_0x52450a(0x18a)]&&_0x2a7acb['endtime']&&(_0x5f03e6[_0x52450a(0x1d6)]=moment[_0x52450a(0x20e)](moment(_0x2a7acb[_0x52450a(0x19c)],_0x52450a(0x1a0))['diff'](moment(_0x2a7acb[_0x52450a(0x19f)],_0x52450a(0x1a0))))['format'](_0x52450a(0x1ab)));switch(_0x2a7acb[_0x52450a(0x1c6)]){case _0x52450a(0x1b1):_0x5f03e6[_0x52450a(0x186)]='Called';break;case'complete':case _0x52450a(0x1ec):_0x5f03e6[_0x52450a(0x186)]=_0x52450a(0x1a6);break;case _0x52450a(0x197):_0x5f03e6[_0x52450a(0x186)]='Rejected';break;case _0x52450a(0x17f):_0x5f03e6['Call_Result']=_0x52450a(0x1f5);break;case'timeout':_0x5f03e6[_0x52450a(0x186)]=_0x52450a(0x1fc);break;default:break;}return _0x5f03e6[_0x52450a(0x1b0)]=(_0x1d3bb6===_0x52450a(0x1d2)?moment(_0x2a7acb['starttime'])[_0x52450a(0x1b4)]('YYYY-MM-DDTHH:mm:ss'):moment(_0x2a7acb[_0x52450a(0x1f2)])[_0x52450a(0x1b4)]('YYYY-MM-DDTHH:mm:ss'))||moment()['format']('YYYY-MM-DDTHH:mm:ss'),_0x5f03e6[_0x52450a(0x1e1)]=_0x1d3bb6||'Inbound',_0x5f03e6=_[_0x52450a(0x1d9)](_0x5f03e6,getCustomFields(_0x29bf43[_0x52450a(0x1ca)],_0x2a7acb)),request({'method':_0x52450a(0x1f0),'uri':_0x52450a(0x184)+_0x1c4c8e+_0x52450a(0x1ad),'headers':{'Authorization':_0x52450a(0x1b7)+_0x3ff4c4},'body':{'data':[_0x5f03e6]},'json':!![]})['then'](function(_0x5edecf){const _0x44b20b=_0x52450a;if(_0x5edecf&&_0x5edecf[_0x44b20b(0x1db)][0x0][_0x44b20b(0x20d)]===_0x44b20b(0x1cf))return logger[_0x44b20b(0x1ac)](_0x44b20b(0x1c7)),{'id':_0x5edecf[_0x44b20b(0x1db)][0x0][_0x44b20b(0x206)]['id']};})[_0x52450a(0x1fd)](function(_0x109f14){const _0x754289=_0x52450a;logger[_0x754289(0x1ac)](_0x754289(0x17e),_0x109f14[_0x754289(0x1fa)]),console[_0x754289(0x1f3)](_0x754289(0x17e),_0x109f14);});}exports[a1311_0x42e60a(0x18e)]=function(_0x588a9a,_0x50a695,_0x16a7d1,_0x4f59d5,_0x3e04cd,_0x2c9515){const _0x7c39e7=a1311_0x42e60a;let _0x1c74d7,_0x40e7aa,_0x4e0b32;_0x2c9515[_0x7c39e7(0x201)]=intUtil[_0x7c39e7(0x1b2)](_0x2c9515[_0x7c39e7(0x201)]),_0x2c9515[_0x7c39e7(0x182)]=intUtil[_0x7c39e7(0x1b2)](_0x2c9515[_0x7c39e7(0x182)]);_0x3e04cd&&_0x3e04cd[_0x7c39e7(0x1df)]?(logger['info'](_0x7c39e7(0x1ba),'Recording\x20is\x20enabled!'),_0x50a695['recordingURL']=_0x2c9515[_0x7c39e7(0x182)]+'/api/voice/recordings/'+_0x50a695[_0x7c39e7(0x1dd)]+_0x7c39e7(0x183)+md5(_0x50a695[_0x7c39e7(0x1dd)])):_0x50a695['recordingURL']='';const _0x23b410=_0x2c9515[_0x7c39e7(0x201)]===_0x7c39e7(0x20b)?'eu':'com';return getAccessToken(_0x2c9515)[_0x7c39e7(0x181)](function(_0x239e9a){return _0x4e0b32=_0x239e9a,getUser(_0x4e0b32,_0x23b410,_0x2c9515,_0x4f59d5['email']);})['then'](function(_0x13e577){const _0x15ed42=_0x7c39e7;return _0x1c74d7=_0x13e577,logger['info'](_0x15ed42(0x1cb),_0x1c74d7['id']),getEndUser(_0x4e0b32,_0x23b410,_0x2c9515,_0x50a695[_0x15ed42(0x195)],_0x50a695[_0x15ed42(0x1d7)],_0x1c74d7,_0x16a7d1);})['then'](function(_0x252c79){const _0x410715=_0x7c39e7;return _0x40e7aa=_0x252c79,getCall(_0x4e0b32,_0x23b410,_0x2c9515,_0x1c74d7,_0x40e7aa,_0x16a7d1,_0x50a695,_0x410715(0x1ee));})['then'](function(_0x676c54){const _0x1843e0=_0x7c39e7;_0x676c54&&(logger[_0x1843e0(0x1ac)]('The\x20Call\x20ID\x20is:',_0x676c54['id']),logger[_0x1843e0(0x1ac)](_0x1843e0(0x1ba),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x1843e0(0x1b4)](_0x1843e0(0x19e),_0x4f59d5[_0x1843e0(0x1b6)]),_0x1843e0(0x1e3),{'uri':_0x1843e0(0x19d)+_0x2c9515['host']+'/crm/EntityInfo.do?module=Calls&id='+_0x676c54['id']}));})['catch'](function(_0x5a1f8d){const _0x54e108=_0x7c39e7;logger['error'](_0x54e108(0x1ba),JSON[_0x54e108(0x1fb)](_0x5a1f8d));});},exports[a1311_0x42e60a(0x1d2)]=function(_0x38cab3,_0x433b93,_0x46ece8,_0x3fe983,_0x5f4055,_0xce3fa3,_0x58b26a){const _0x56da12=a1311_0x42e60a;let _0x3a92a3,_0x4642d8,_0x3920d3;_0xce3fa3[_0x56da12(0x201)]=intUtil[_0x56da12(0x1b2)](_0xce3fa3[_0x56da12(0x201)]),_0xce3fa3[_0x56da12(0x182)]=intUtil['stripTrailingSlash'](_0xce3fa3[_0x56da12(0x182)]);_0x58b26a&&_0x58b26a[_0x56da12(0x1d8)]&&_0x58b26a['recordingFormat']!==_0x56da12(0x1be)&&(logger[_0x56da12(0x1ac)]('[OUTBOUND]',_0x56da12(0x1a8)),_0x433b93[_0x56da12(0x193)]=_0xce3fa3[_0x56da12(0x182)]+_0x56da12(0x1ed)+_0x433b93[_0x56da12(0x1dd)]+'/downloads?type=uniqueid&token='+md5(_0x433b93[_0x56da12(0x1dd)]));const _0x2eeb20=_0xce3fa3[_0x56da12(0x201)]==='zoho.eu'?'eu':_0x56da12(0x1bb);return getAccessToken(_0xce3fa3)[_0x56da12(0x181)](function(_0x28c967){const _0x11b785=_0x56da12;return _0x3920d3=_0x28c967,getUser(_0x3920d3,_0x2eeb20,_0xce3fa3,_0x3fe983[_0x11b785(0x1bd)]);})[_0x56da12(0x181)](function(_0x493925){const _0xbfd960=_0x56da12;return _0x3a92a3=_0x493925,logger[_0xbfd960(0x1ac)](_0xbfd960(0x1cb),_0x3a92a3['id']),getEndUser(_0x3920d3,_0x2eeb20,_0xce3fa3,_0x433b93['destcalleridname'],_0x433b93[_0xbfd960(0x1ef)],_0x3a92a3,_0x46ece8);})[_0x56da12(0x181)](function(_0x70b789){const _0x1226a4=_0x56da12;return _0x4642d8=_0x70b789,getCall(_0x3920d3,_0x2eeb20,_0xce3fa3,_0x3a92a3,_0x4642d8,_0x46ece8,_0x433b93,_0x1226a4(0x189));})['then'](function(_0x1b6610){const _0x7b3781=_0x56da12;_0x1b6610&&(logger[_0x7b3781(0x1ac)](_0x7b3781(0x1d4),_0x1b6610['id']),logger['info']('[OUTBOUND]',_0x7b3781(0x1c8)),emit(util[_0x7b3781(0x1b4)](_0x7b3781(0x19e),_0x3fe983[_0x7b3781(0x1b6)]),_0x7b3781(0x1e3),{'uri':'https://crm.'+_0xce3fa3['host']+_0x7b3781(0x1e2)+_0x1b6610['id']}));})['catch'](function(_0x4fb968){const _0x32b2de=_0x56da12;logger[_0x32b2de(0x1fe)](_0x32b2de(0x1b3),JSON['stringify'](_0x4fb968));});},exports[a1311_0x42e60a(0x1e5)]=function(_0x3c72b8,_0x21fab4,_0x4b06ea,_0x33627d,_0x2f2f3f,_0x564c6e){const _0x23a7bf=a1311_0x42e60a;let _0x29b29b,_0x513662,_0x1e1a76;_0x564c6e[_0x23a7bf(0x201)]=intUtil[_0x23a7bf(0x1b2)](_0x564c6e[_0x23a7bf(0x201)]),_0x564c6e[_0x23a7bf(0x182)]=intUtil[_0x23a7bf(0x1b2)](_0x564c6e[_0x23a7bf(0x182)]);_0x2f2f3f&&_0x2f2f3f[_0x23a7bf(0x1df)]?(logger[_0x23a7bf(0x1ac)]('['+_0x21fab4[_0x23a7bf(0x1c6)][_0x23a7bf(0x19b)]()+']',_0x23a7bf(0x1a8)),_0x21fab4[_0x23a7bf(0x193)]=_0x564c6e[_0x23a7bf(0x182)]+_0x23a7bf(0x1ed)+_0x21fab4[_0x23a7bf(0x1dd)]+'/downloads?type=uniqueid&token='+md5(_0x21fab4[_0x23a7bf(0x1dd)])):_0x21fab4[_0x23a7bf(0x193)]='';const _0x4ed370=_0x564c6e[_0x23a7bf(0x201)]===_0x23a7bf(0x20b)?'eu':_0x23a7bf(0x1bb);return getAccessToken(_0x564c6e)[_0x23a7bf(0x181)](function(_0x5edca2){return _0x1e1a76=_0x5edca2,getUser(_0x1e1a76,_0x4ed370,_0x564c6e);})[_0x23a7bf(0x181)](function(_0x219893){const _0x5d9a79=_0x23a7bf;return _0x29b29b=_0x219893,logger[_0x5d9a79(0x1ac)](_0x5d9a79(0x1cb),_0x29b29b['id']),getEndUser(_0x1e1a76,_0x4ed370,_0x564c6e,_0x21fab4[_0x5d9a79(0x195)],_0x21fab4['calleridnum'],_0x29b29b,_0x4b06ea);})[_0x23a7bf(0x181)](function(_0x309f61){const _0x2cb709=_0x23a7bf;return _0x513662=_0x309f61,getCall(_0x1e1a76,_0x4ed370,_0x564c6e,_0x29b29b,_0x513662,_0x4b06ea,_0x21fab4,_0x2cb709(0x1ee));})[_0x23a7bf(0x181)](function(_0x402f69){const _0x13b54a=_0x23a7bf;_0x402f69&&logger[_0x13b54a(0x1ac)](_0x13b54a(0x1d4),_0x402f69['id']);})[_0x23a7bf(0x1fd)](function(_0x3f56d7){const _0x5b8bc3=_0x23a7bf;logger[_0x5b8bc3(0x1fe)]('['+_0x21fab4[_0x5b8bc3(0x1c6)][_0x5b8bc3(0x19b)]()+']',JSON['stringify'](_0x3f56d7));});};
\ No newline at end of file