Built motion from commit cb845558.|2.6.34
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index 6b2667b..1179489 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc2cc=['stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','Zoho-oauthtoken\x20','isArrayLikeObject','findIndex','email','Agent\x20found!','users','profile','Administrator','user','Using\x20the\x20admin\x20account!','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','error','catch','data','enduserType','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','then','code','details','Error:\x20','log','CREATE\x20ERROR','moduleSearch','contact_lead','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Leads','Contacts','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','Creating\x20new\x20call...','Owner','administrator','Subject','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','$se_module','Call_Duration','talktime','mm:ss','answertime','endtime','utc','YYYY-MM-DDTHH:mm:ss','starttime','lastevent','Call_Result','Called','complete','connect','Answered','rejected','Rejected','Abandoned','timeout','Timeout','Call_Start_Time','outbound','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','calleridname','calleridnum','[QUEUE]','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','/api/voice/recordings/','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','unmanaged','toUpperCase','request-promise','md5','util','moment','bluebird','../../../../config/logger','redis','localhost','debug','[HTTP]','stringify','length','string','picklist','type','idField','variable','variableName','toString','customVariable','name','toLowerCase','Variable','indexOf','isNil','access_token','expires_in','zone','https://accounts.zoho.com.au','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','/oauth/v2/token','refreshToken','clientId','clientSecret','refresh_token','add','seconds','Failing\x20creating\x20the\x20access_token'];(function(_0x2cce4c,_0x1dfd1d){var _0x80f54d=function(_0x549e1f){while(--_0x549e1f){_0x2cce4c['push'](_0x2cce4c['shift']());}};_0x80f54d(++_0x1dfd1d);}(_0xc2cc,0x70));var _0xcc2c=function(_0x59ee6f,_0x450239){_0x59ee6f=_0x59ee6f-0x0;var _0x4c0979=_0xc2cc[_0x59ee6f];return _0x4c0979;};'use strict';var _=require('lodash');var rp=require(_0xcc2c('0x0'));var md5=require(_0xcc2c('0x1'));var util=require(_0xcc2c('0x2'));var intUtil=require('./util');var moment=require(_0xcc2c('0x3'));var Redis=require('ioredis');var BPromise=require(_0xcc2c('0x4'));var config=require('../../../../config/environment');var logger=require(_0xcc2c('0x5'))('zoho');config[_0xcc2c('0x6')]=_['defaults'](config['redis'],{'host':_0xcc2c('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xcc2c('0x6')]));function emit(_0x5a276f,_0x1d311f,_0x58c80c){io['to'](_0x5a276f)['emit'](_0x1d311f,_0x58c80c);}function request(_0x2bde97){logger[_0xcc2c('0x8')](_0xcc2c('0x9'),JSON[_0xcc2c('0xa')](_0x2bde97));return rp(_0x2bde97);}function getCustomFields(_0x2325be,_0x367881){var _0xb51804={};if(_0x2325be[_0xcc2c('0xb')]>0x0){_['forEach'](_0x2325be,function(_0x358306){if(_['includes']([_0xcc2c('0xc'),_0xcc2c('0xd')],_0x358306[_0xcc2c('0xe')])&&_0x358306[_0xcc2c('0xf')]){_0xb51804[_0x358306['idField']]=_0x358306['content']['toString']();}else if(_0x358306[_0xcc2c('0xe')]===_0xcc2c('0x10')&&_0x358306['variableName']&&_0x358306['idField']&&_0x367881[_0x358306[_0xcc2c('0x11')]]){_0xb51804[_0x358306['idField']]=_0x367881[_0x358306[_0xcc2c('0x11')]][_0xcc2c('0x12')]();}else if(_0x358306[_0xcc2c('0xe')]===_0xcc2c('0x13')&&_0x358306['Variable']&&_0x358306['Variable'][_0xcc2c('0x14')]&&_0x358306[_0xcc2c('0xf')]&&_0x367881[_0x358306['Variable'][_0xcc2c('0x14')][_0xcc2c('0x15')]()]){_0xb51804[_0x358306[_0xcc2c('0xf')]]=_0x367881[_0x358306[_0xcc2c('0x16')][_0xcc2c('0x14')][_0xcc2c('0x15')]()][_0xcc2c('0x12')]();}});}return _0xb51804;}function getName(_0x5a1f0a){if(_0x5a1f0a[_0xcc2c('0x17')]('\x20')>0x0){var _0x3acc89=_0x5a1f0a['split'](/ (.+)/);if(_0x3acc89[0x1]){return _0x3acc89;}}return[_0x5a1f0a,_0x5a1f0a];}var accountsTokens={};function getAccessToken(_0x4d22fe){return new Promise(function(_0x4a67f4,_0x15bbd6){if(!_['isNil'](accountsTokens[_0x4d22fe['id']])&&!_[_0xcc2c('0x18')](accountsTokens[_0x4d22fe['id']][_0xcc2c('0x19')])){if(moment()['isBefore'](accountsTokens[_0x4d22fe['id']][_0xcc2c('0x1a')])){_0x4a67f4(accountsTokens[_0x4d22fe['id']][_0xcc2c('0x19')]);}}var _0x5c7c53;switch(_0x4d22fe[_0xcc2c('0x1b')]){case'US':_0x5c7c53='https://accounts.zoho.com';break;case'AU':_0x5c7c53=_0xcc2c('0x1c');break;case'EU':_0x5c7c53='https://accounts.zoho.eu';break;case'IN':_0x5c7c53='https://accounts.zoho.in';break;case'CN':_0x5c7c53=_0xcc2c('0x1d');break;default:_0x5c7c53=_0xcc2c('0x1e');break;}var _0x5e491f={'method':_0xcc2c('0x1f'),'uri':_0x5c7c53+_0xcc2c('0x20'),'qs':{'refresh_token':_0x4d22fe[_0xcc2c('0x21')],'client_id':_0x4d22fe[_0xcc2c('0x22')],'client_secret':_0x4d22fe[_0xcc2c('0x23')],'grant_type':_0xcc2c('0x24')},'json':!![]};return rp(_0x5e491f)['then'](function(_0xaab877){accountsTokens[_0x4d22fe['id']]={'access_token':_0xaab877[_0xcc2c('0x19')],'expires_in':moment()[_0xcc2c('0x25')](_0xaab877[_0xcc2c('0x1a')],_0xcc2c('0x26'))};_0x4a67f4(_0xaab877['access_token']);})['catch'](function(_0x50c32b){logger['error'](_0xcc2c('0x27'),_0x50c32b[_0xcc2c('0x28')]);_0x15bbd6(_0x50c32b);});});}function getUser(_0x406515,_0x2c4ce9,_0x3ad1aa,_0x184de4){logger[_0xcc2c('0x29')](_0xcc2c('0x2a'));return request({'method':_0xcc2c('0x2b'),'uri':util[_0xcc2c('0x2c')](_0xcc2c('0x2d'),_0x2c4ce9),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':_0xcc2c('0x2e')+_0x406515},'json':!![]})['then'](function(_0x4fd79f){if(_0x4fd79f['users']){var _0x31778c=-0x1;if(_[_0xcc2c('0x2f')](_0x4fd79f['users'])){if(!_['isNil'](_0x184de4)){_0x31778c=_[_0xcc2c('0x30')](_0x4fd79f['users'],function(_0x2b7e0c){return _0x2b7e0c[_0xcc2c('0x31')]===_0x184de4;});}if(_0x31778c>=0x0){logger[_0xcc2c('0x29')](_0xcc2c('0x32'));}else{logger[_0xcc2c('0x29')]('Using\x20the\x20admin\x20account!');_0x31778c=_['findIndex'](_0x4fd79f[_0xcc2c('0x33')],function(_0x12863b){return _0x12863b[_0xcc2c('0x34')][_0xcc2c('0x14')]===_0xcc2c('0x35');});}return _0x4fd79f['users'][_0x31778c];}else{if(_0x4fd79f[_0xcc2c('0x36')]['profile'][_0xcc2c('0x14')]===_0xcc2c('0x35')){logger['info'](_0xcc2c('0x37'));user=_0x4fd79f['user'];return user;}else{logger['error'](_0xcc2c('0x38'),JSON['stringify'](_0x4fd79f));throw new Error(_0xcc2c('0x39')+JSON[_0xcc2c('0xa')](_0x4fd79f));}}}else{logger[_0xcc2c('0x3a')]('The\x20failing\x20result\x20is',JSON[_0xcc2c('0xa')](_0x4fd79f));throw new Error(_0xcc2c('0x39')+JSON['stringify'](_0x4fd79f));}})[_0xcc2c('0x3b')](function(_0x5432fb){console[_0xcc2c('0x3a')](_0x5432fb);});}function getZohoUser(_0x4cb5de,_0x29e59f){return new BPromise(function(_0x1b9884,_0x10afa7){request(_0x4cb5de)['then'](function(_0x40509e){var _0x31349b=null;if(_0x40509e){_0x31349b=_0x40509e[_0xcc2c('0x3c')][0x0];_0x31349b[_0xcc2c('0x3d')]=_0x29e59f;}_0x1b9884(_0x31349b);})[_0xcc2c('0x3b')](function(_0xcd9a0b){_0x10afa7(_0xcd9a0b);});});}function createEndUser(_0x5ef1a5,_0x279744,_0x1b4514,_0xd6e808,_0x43afd6,_0x5b6ec6){var _0x1b4514=getName(_0x1b4514);return request({'method':_0xcc2c('0x1f'),'uri':_0xcc2c('0x3e')+_0x279744+_0xcc2c('0x3f')+_[_0xcc2c('0x40')](_0x5b6ec6[_0xcc2c('0x41')])+'s','body':{'data':[{'Last_Name':_0x1b4514[0x1],'First_Name':_0x1b4514[0x0],'Phone':_0xd6e808,'Owner':{'name':!_[_0xcc2c('0x18')](_0x43afd6[_0xcc2c('0x42')][_0xcc2c('0x14')])?_0x43afd6[_0xcc2c('0x42')]['name']:!_[_0xcc2c('0x18')](_0x43afd6[_0xcc2c('0x43')])?_0x43afd6['first_name']+'\x20'+_0x43afd6[_0xcc2c('0x44')]:_0x43afd6[_0xcc2c('0x44')],'id':_0x43afd6['id']}}]},'headers':{'Authorization':_0xcc2c('0x2e')+_0x5ef1a5},'json':!![]})[_0xcc2c('0x45')](function(_0x3a1a80){if(_0x3a1a80&&_0x3a1a80[_0xcc2c('0x3c')][0x0][_0xcc2c('0x46')]==='SUCCESS'){var _0x3c3f29=_0x3a1a80[_0xcc2c('0x3c')][0x0][_0xcc2c('0x47')];_0x3c3f29[_0xcc2c('0x3d')]=_[_0xcc2c('0x40')](_0x5b6ec6[_0xcc2c('0x41')])+'s';return _0x3c3f29;}logger[_0xcc2c('0x3a')]('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error(_0xcc2c('0x48')+JSON[_0xcc2c('0xa')](data));})[_0xcc2c('0x3b')](function(_0x10c07d){console[_0xcc2c('0x49')](_0xcc2c('0x4a'),_0x10c07d);});}function getEndUser(_0x14a522,_0x15f6f0,_0xe5a8db,_0x3bbb34,_0x496a0b,_0x3e9860,_0x5b1440){var _0x1659b3={'method':_0xcc2c('0x2b'),'uri':'','headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x14a522},'json':!![]};switch(_0x5b1440[_0xcc2c('0x4b')]){case _0xcc2c('0x4c'):_0x1659b3[_0xcc2c('0x4d')]=_0xcc2c('0x3e')+_0x15f6f0+_0xcc2c('0x4e')+_0x496a0b+'))';return getZohoUser(_0x1659b3,'Contacts')['then'](function(_0x283d10){if(_0x283d10)return _0x283d10;_0x1659b3['uri']='https://www.zohoapis.'+_0x15f6f0+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x496a0b+'))';return getZohoUser(_0x1659b3,_0xcc2c('0x4f'))['then'](function(_0x4f9557){if(_0x4f9557)return _0x4f9557;if(_0x5b1440['moduleCreate']!='nothing'){return createEndUser(_0x14a522,_0x15f6f0,_0x3bbb34,_0x496a0b,_0x3e9860,_0x5b1440);}else{return{};}});});break;case'contact':_0x1659b3['uri']=_0xcc2c('0x3e')+_0x15f6f0+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x496a0b+'))';return getZohoUser(_0x1659b3,_0xcc2c('0x50'))[_0xcc2c('0x45')](function(_0xcd6ccf){if(_0xcd6ccf)return _0xcd6ccf;if(_0x5b1440[_0xcc2c('0x41')]!='nothing'){return createEndUser(_0x14a522,_0x15f6f0,_0x3bbb34,_0x496a0b,_0x3e9860,_0x5b1440);}else{return{};}});break;case _0xcc2c('0x51'):_0x1659b3[_0xcc2c('0x4d')]=_0xcc2c('0x3e')+_0x15f6f0+_0xcc2c('0x52')+_0x496a0b+'))';return getZohoUser(_0x1659b3,'Leads')[_0xcc2c('0x45')](function(_0x8a4cb1){if(_0x8a4cb1)return _0x8a4cb1;if(_0x5b1440[_0xcc2c('0x41')]!=_0xcc2c('0x53')){return createEndUser(_0x14a522,_0x15f6f0,_0x3bbb34,_0x496a0b,_0x3e9860,_0x5b1440);}else{return{};}});break;}}function getCall(_0x3f7c9f,_0x18b223,_0x455f59,_0x19c04e,_0x113660,_0x298c2d,_0x19176e,_0x46d7e4){logger['info'](_0xcc2c('0x54'));var _0x275268={};_0x275268[_0xcc2c('0x55')]={'name':!_[_0xcc2c('0x18')](_0x19c04e['role'][_0xcc2c('0x14')])&&!_[_0xcc2c('0x18')](_0x19c04e[_0xcc2c('0x34')][_0xcc2c('0x14')])&&_0x19c04e[_0xcc2c('0x34')]['name']===_0xcc2c('0x56')?_0x19c04e[_0xcc2c('0x42')][_0xcc2c('0x14')]:!_['isNil'](_0x19c04e[_0xcc2c('0x43')])?_0x19c04e[_0xcc2c('0x43')]+'\x20'+_0x19c04e[_0xcc2c('0x44')]:_0x19c04e[_0xcc2c('0x44')],'id':_0x19c04e['id']};_0x275268[_0xcc2c('0x57')]=intUtil['getString'](_0x298c2d['Subjects'],_0x19176e,'\x20');_0x275268[_0xcc2c('0x58')]=intUtil['getString'](_0x298c2d[_0xcc2c('0x59')],_0x19176e,'\x0a');if(_0x113660[_0xcc2c('0x3d')]==='Contacts'){_0x275268[_0xcc2c('0x5a')]={'name':!_[_0xcc2c('0x18')](_0x113660[_0xcc2c('0x5b')])?_0x113660[_0xcc2c('0x5b')]:!_[_0xcc2c('0x18')](_0x113660['First_Name'])?_0x113660[_0xcc2c('0x5c')]+'\x20'+_0x113660[_0xcc2c('0x5d')]:_0x113660[_0xcc2c('0x5d')],'id':_0x113660['id']};}if(_0x113660[_0xcc2c('0x3d')]===_0xcc2c('0x4f')){_0x275268['What_Id']={'name':!_[_0xcc2c('0x18')](_0x113660[_0xcc2c('0x5b')])?_0x113660[_0xcc2c('0x5b')]:!_['isNil'](_0x113660[_0xcc2c('0x5c')])?_0x113660[_0xcc2c('0x5c')]+'\x20'+_0x113660[_0xcc2c('0x5d')]:_0x113660[_0xcc2c('0x5d')],'id':_0x113660['id']};_0x275268[_0xcc2c('0x5e')]=_[_0xcc2c('0x40')](_0x113660[_0xcc2c('0x3d')]);}if(_0x19176e['talktime']){_0x275268[_0xcc2c('0x5f')]=moment['utc'](parseInt(_0x19176e[_0xcc2c('0x60')])*0x3e8)[_0xcc2c('0x2c')](_0xcc2c('0x61'));}else if(_0x19176e[_0xcc2c('0x62')]&&_0x19176e[_0xcc2c('0x63')]){_0x275268[_0xcc2c('0x5f')]=moment[_0xcc2c('0x64')](moment(_0x19176e[_0xcc2c('0x63')],_0xcc2c('0x65'))['diff'](moment(_0x19176e[_0xcc2c('0x66')],_0xcc2c('0x65'))))['format'](_0xcc2c('0x61'));}switch(_0x19176e[_0xcc2c('0x67')]){case'called':_0x275268[_0xcc2c('0x68')]=_0xcc2c('0x69');break;case _0xcc2c('0x6a'):case _0xcc2c('0x6b'):_0x275268[_0xcc2c('0x68')]=_0xcc2c('0x6c');break;case _0xcc2c('0x6d'):_0x275268[_0xcc2c('0x68')]=_0xcc2c('0x6e');break;case'abandoned':_0x275268['Call_Result']=_0xcc2c('0x6f');break;case _0xcc2c('0x70'):_0x275268[_0xcc2c('0x68')]=_0xcc2c('0x71');default:}_0x275268[_0xcc2c('0x72')]=(_0x46d7e4===_0xcc2c('0x73')?moment(_0x19176e['starttime'])[_0xcc2c('0x2c')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x19176e['agentcalledAt'])[_0xcc2c('0x2c')](_0xcc2c('0x65')))||moment()['format'](_0xcc2c('0x65'));_0x275268[_0xcc2c('0x74')]=_0x46d7e4||_0xcc2c('0x75');_0x275268=_[_0xcc2c('0x76')](_0x275268,getCustomFields(_0x298c2d[_0xcc2c('0x77')],_0x19176e));return request({'method':_0xcc2c('0x1f'),'uri':_0xcc2c('0x3e')+_0x18b223+_0xcc2c('0x78'),'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x3f7c9f},'body':{'data':[_0x275268]},'json':!![]})[_0xcc2c('0x45')](function(_0x16c8cf){if(_0x16c8cf&&_0x16c8cf[_0xcc2c('0x3c')][0x0][_0xcc2c('0x46')]==='SUCCESS'){logger[_0xcc2c('0x29')](_0xcc2c('0x79'));return{'id':_0x16c8cf['data'][0x0]['details']['id']};}})[_0xcc2c('0x3b')](function(_0x1e8121){logger['info'](_0xcc2c('0x7a'),_0x1e8121[_0xcc2c('0x28')]);console['log'](_0xcc2c('0x7a'),_0x1e8121);});}exports[_0xcc2c('0x7b')]=function(_0x57fce7,_0x3650a1,_0x2fb052,_0x583dad,_0x195be0,_0x4f1e89){var _0x56acdf,_0x4cfd41,_0x2b76fb;_0x4f1e89[_0xcc2c('0x7c')]=intUtil[_0xcc2c('0x7d')](_0x4f1e89[_0xcc2c('0x7c')]);_0x4f1e89[_0xcc2c('0x7e')]=intUtil['stripTrailingSlash'](_0x4f1e89[_0xcc2c('0x7e')]);if(_0x195be0&&_0x195be0[_0xcc2c('0x7f')]){logger[_0xcc2c('0x29')]('[QUEUE]',_0xcc2c('0x80'));_0x3650a1[_0xcc2c('0x81')]=_0x4f1e89[_0xcc2c('0x7e')]+'/api/voice/recordings/'+_0x3650a1[_0xcc2c('0x82')]+_0xcc2c('0x83')+md5(_0x3650a1['uniqueid']);}else{_0x3650a1[_0xcc2c('0x81')]='';}var _0x4ea3b8=_0x4f1e89[_0xcc2c('0x7c')]===_0xcc2c('0x84')?'eu':_0xcc2c('0x85');return getAccessToken(_0x4f1e89)[_0xcc2c('0x45')](function(_0x4dace2){_0x2b76fb=_0x4dace2;return getUser(_0x2b76fb,_0x4ea3b8,_0x4f1e89,_0x583dad[_0xcc2c('0x31')]);})['then'](function(_0xf9165a){_0x56acdf=_0xf9165a;logger[_0xcc2c('0x29')]('The\x20User\x20ID\x20is:',_0x56acdf['id']);return getEndUser(_0x2b76fb,_0x4ea3b8,_0x4f1e89,_0x3650a1[_0xcc2c('0x86')],_0x3650a1[_0xcc2c('0x87')],_0x56acdf,_0x2fb052);})[_0xcc2c('0x45')](function(_0x6bb1f6){_0x4cfd41=_0x6bb1f6;return getCall(_0x2b76fb,_0x4ea3b8,_0x4f1e89,_0x56acdf,_0x4cfd41,_0x2fb052,_0x3650a1,_0xcc2c('0x75'));})[_0xcc2c('0x45')](function(_0x29afbc){if(_0x29afbc){logger[_0xcc2c('0x29')]('The\x20Call\x20ID\x20is:',_0x29afbc['id']);logger[_0xcc2c('0x29')](_0xcc2c('0x88'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xcc2c('0x2c')]('user:%s',_0x583dad[_0xcc2c('0x14')]),_0xcc2c('0x89'),{'uri':_0xcc2c('0x8a')+_0x4f1e89['host']+_0xcc2c('0x8b')+_0x29afbc['id']});}})['catch'](function(_0x376f43){logger['error'](_0xcc2c('0x88'),JSON[_0xcc2c('0xa')](_0x376f43));});};exports[_0xcc2c('0x73')]=function(_0x27913e,_0x5daf98,_0x498e63,_0x5124ac,_0x394097,_0x3336f4,_0x467409){var _0x5b7d0b,_0xcc89f0,_0x35f998;_0x3336f4[_0xcc2c('0x7c')]=intUtil[_0xcc2c('0x7d')](_0x3336f4['host']);_0x3336f4[_0xcc2c('0x7e')]=intUtil[_0xcc2c('0x7d')](_0x3336f4[_0xcc2c('0x7e')]);if(_0x467409&&_0x467409[_0xcc2c('0x8c')]&&_0x467409['recordingFormat']!==_0xcc2c('0x8d')){logger[_0xcc2c('0x29')](_0xcc2c('0x8e'),_0xcc2c('0x80'));_0x5daf98['recordingURL']=_0x3336f4[_0xcc2c('0x7e')]+_0xcc2c('0x8f')+_0x5daf98[_0xcc2c('0x82')]+'/downloads?type=uniqueid&token='+md5(_0x5daf98['uniqueid']);}var _0x44c167=_0x3336f4['host']==='zoho.eu'?'eu':_0xcc2c('0x85');return getAccessToken(_0x3336f4)[_0xcc2c('0x45')](function(_0x595899){_0x35f998=_0x595899;return getUser(_0x35f998,_0x44c167,_0x3336f4,_0x5124ac[_0xcc2c('0x31')]);})[_0xcc2c('0x45')](function(_0x20e497){_0x5b7d0b=_0x20e497;logger[_0xcc2c('0x29')](_0xcc2c('0x90'),_0x5b7d0b['id']);return getEndUser(_0x35f998,_0x44c167,_0x3336f4,_0x5daf98[_0xcc2c('0x91')],_0x5daf98[_0xcc2c('0x92')],_0x5b7d0b,_0x498e63);})['then'](function(_0x545701){_0xcc89f0=_0x545701;return getCall(_0x35f998,_0x44c167,_0x3336f4,_0x5b7d0b,_0xcc89f0,_0x498e63,_0x5daf98,'Outbound');})[_0xcc2c('0x45')](function(_0x1b65c0){if(_0x1b65c0){logger[_0xcc2c('0x29')](_0xcc2c('0x93'),_0x1b65c0['id']);logger[_0xcc2c('0x29')]('[OUTBOUND]',_0xcc2c('0x94'));emit(util['format'](_0xcc2c('0x95'),_0x5124ac[_0xcc2c('0x14')]),_0xcc2c('0x89'),{'uri':_0xcc2c('0x8a')+_0x3336f4[_0xcc2c('0x7c')]+_0xcc2c('0x8b')+_0x1b65c0['id']});}})[_0xcc2c('0x3b')](function(_0x3d4e51){logger['error'](_0xcc2c('0x8e'),JSON[_0xcc2c('0xa')](_0x3d4e51));});};exports[_0xcc2c('0x96')]=function(_0x4bda0e,_0x51df89,_0x91f874,_0x53ec1f,_0xdd1c41,_0x2426dc){var _0xb77689,_0x581f5a,_0x545d4c;_0x2426dc[_0xcc2c('0x7c')]=intUtil[_0xcc2c('0x7d')](_0x2426dc[_0xcc2c('0x7c')]);_0x2426dc[_0xcc2c('0x7e')]=intUtil[_0xcc2c('0x7d')](_0x2426dc[_0xcc2c('0x7e')]);if(_0xdd1c41&&_0xdd1c41[_0xcc2c('0x7f')]){logger[_0xcc2c('0x29')]('['+_0x51df89[_0xcc2c('0x67')]['toUpperCase']()+']',_0xcc2c('0x80'));_0x51df89['recordingURL']=_0x2426dc[_0xcc2c('0x7e')]+_0xcc2c('0x8f')+_0x51df89[_0xcc2c('0x82')]+_0xcc2c('0x83')+md5(_0x51df89[_0xcc2c('0x82')]);}else{_0x51df89[_0xcc2c('0x81')]='';}var _0x8228d3=_0x2426dc[_0xcc2c('0x7c')]===_0xcc2c('0x84')?'eu':'com';return getAccessToken(_0x2426dc)[_0xcc2c('0x45')](function(_0x562592){_0x545d4c=_0x562592;return getUser(_0x545d4c,_0x8228d3,_0x2426dc);})[_0xcc2c('0x45')](function(_0x224575){_0xb77689=_0x224575;logger[_0xcc2c('0x29')](_0xcc2c('0x90'),_0xb77689['id']);return getEndUser(_0x545d4c,_0x8228d3,_0x2426dc,_0x51df89[_0xcc2c('0x86')],_0x51df89[_0xcc2c('0x87')],_0xb77689,_0x91f874);})['then'](function(_0x17073b){_0x581f5a=_0x17073b;return getCall(_0x545d4c,_0x8228d3,_0x2426dc,_0xb77689,_0x581f5a,_0x91f874,_0x51df89,_0xcc2c('0x75'));})[_0xcc2c('0x45')](function(_0x4c090d){if(_0x4c090d){logger['info'](_0xcc2c('0x93'),_0x4c090d['id']);}})['catch'](function(_0x49f68f){logger[_0xcc2c('0x3a')]('['+_0x51df89['lastevent'][_0xcc2c('0x97')]()+']',JSON[_0xcc2c('0xa')](_0x49f68f));});};
\ No newline at end of file
+var _0x5a0a=['split','isNil','isBefore','expires_in','access_token','zone','https://accounts.zoho.eu','https://accounts.zoho.com.cn','refreshToken','clientId','add','seconds','catch','error','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','users','isArrayLikeObject','findIndex','email','Agent\x20found!','profile','Administrator','user','Using\x20the\x20admin\x20account!','The\x20failing\x20result\x20is','data','POST','https://www.zohoapis.','/crm/v2/','startCase','first_name','last_name','code','SUCCESS','details','enduserType','moduleCreate','Error:\x20','CREATE\x20ERROR','moduleSearch','contact_lead','uri','Contacts','then','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','contact','/crm/v2/Contacts/search?criteria=((Phone:equals:','nothing','lead','Owner','role','administrator','Subject','Subjects','getString','Descriptions','Who_Id','First_Name','Last_Name','What_Id','Full_Name','$se_module','talktime','Call_Duration','utc','answertime','endtime','diff','starttime','mm:ss','called','Call_Result','complete','connect','Answered','rejected','Rejected','abandoned','Abandoned','Timeout','outbound','YYYY-MM-DDTHH:mm:ss','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','err','stack','log','host','stripTrailingSlash','serverUrl','[QUEUE]','recordingURL','/api/voice/recordings/','uniqueid','zoho.eu','com','calleridnum','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','/downloads?type=uniqueid&token=','destcalleridname','destcalleridnum','Outbound','[OUTBOUND]','lastevent','toUpperCase','The\x20User\x20ID\x20is:','The\x20Call\x20ID\x20is:','lodash','md5','./util','moment','ioredis','bluebird','../../../../config/environment','zoho','defaults','redis','localhost','socket.io-emitter','emit','[HTTP]','stringify','length','forEach','includes','string','picklist','type','idField','content','variable','variableName','toString','name','toLowerCase'];(function(_0x4b5049,_0x4d00ad){var _0x2f2e38=function(_0x5b0217){while(--_0x5b0217){_0x4b5049['push'](_0x4b5049['shift']());}};_0x2f2e38(++_0x4d00ad);}(_0x5a0a,0x1a9));var _0xa5a0=function(_0x52209a,_0x28ea97){_0x52209a=_0x52209a-0x0;var _0xb43ac9=_0x5a0a[_0x52209a];return _0xb43ac9;};'use strict';var _=require(_0xa5a0('0x0'));var rp=require('request-promise');var md5=require(_0xa5a0('0x1'));var util=require('util');var intUtil=require(_0xa5a0('0x2'));var moment=require(_0xa5a0('0x3'));var Redis=require(_0xa5a0('0x4'));var BPromise=require(_0xa5a0('0x5'));var config=require(_0xa5a0('0x6'));var logger=require('../../../../config/logger')(_0xa5a0('0x7'));config['redis']=_[_0xa5a0('0x8')](config[_0xa5a0('0x9')],{'host':_0xa5a0('0xa'),'port':0x18eb});var io=require(_0xa5a0('0xb'))(new Redis(config[_0xa5a0('0x9')]));function emit(_0x2bb71e,_0x10f14e,_0x1a9d47){io['to'](_0x2bb71e)[_0xa5a0('0xc')](_0x10f14e,_0x1a9d47);}function request(_0x547e2d){logger['debug'](_0xa5a0('0xd'),JSON[_0xa5a0('0xe')](_0x547e2d));return rp(_0x547e2d);}function getCustomFields(_0x4f6e0e,_0x2d39fc){var _0x329553={};if(_0x4f6e0e[_0xa5a0('0xf')]>0x0){_[_0xa5a0('0x10')](_0x4f6e0e,function(_0x69ee7e){if(_[_0xa5a0('0x11')]([_0xa5a0('0x12'),_0xa5a0('0x13')],_0x69ee7e[_0xa5a0('0x14')])&&_0x69ee7e['idField']){_0x329553[_0x69ee7e[_0xa5a0('0x15')]]=_0x69ee7e[_0xa5a0('0x16')]['toString']();}else if(_0x69ee7e[_0xa5a0('0x14')]===_0xa5a0('0x17')&&_0x69ee7e[_0xa5a0('0x18')]&&_0x69ee7e[_0xa5a0('0x15')]&&_0x2d39fc[_0x69ee7e[_0xa5a0('0x18')]]){_0x329553[_0x69ee7e[_0xa5a0('0x15')]]=_0x2d39fc[_0x69ee7e[_0xa5a0('0x18')]][_0xa5a0('0x19')]();}else if(_0x69ee7e[_0xa5a0('0x14')]==='customVariable'&&_0x69ee7e['Variable']&&_0x69ee7e['Variable'][_0xa5a0('0x1a')]&&_0x69ee7e['idField']&&_0x2d39fc[_0x69ee7e['Variable'][_0xa5a0('0x1a')][_0xa5a0('0x1b')]()]){_0x329553[_0x69ee7e[_0xa5a0('0x15')]]=_0x2d39fc[_0x69ee7e['Variable']['name'][_0xa5a0('0x1b')]()][_0xa5a0('0x19')]();}});}return _0x329553;}function getName(_0x5b7e8e){if(_0x5b7e8e['indexOf']('\x20')>0x0){var _0x29710c=_0x5b7e8e[_0xa5a0('0x1c')](/ (.+)/);if(_0x29710c[0x1]){return _0x29710c;}}return[_0x5b7e8e,_0x5b7e8e];}var accountsTokens={};function getAccessToken(_0x3fd650){return new Promise(function(_0x44adf3,_0x3fdf1b){if(!_[_0xa5a0('0x1d')](accountsTokens[_0x3fd650['id']])&&!_['isNil'](accountsTokens[_0x3fd650['id']]['access_token'])){if(moment()[_0xa5a0('0x1e')](accountsTokens[_0x3fd650['id']][_0xa5a0('0x1f')])){_0x44adf3(accountsTokens[_0x3fd650['id']][_0xa5a0('0x20')]);}}var _0x40654c;switch(_0x3fd650[_0xa5a0('0x21')]){case'US':_0x40654c='https://accounts.zoho.com';break;case'AU':_0x40654c='https://accounts.zoho.com.au';break;case'EU':_0x40654c=_0xa5a0('0x22');break;case'IN':_0x40654c='https://accounts.zoho.in';break;case'CN':_0x40654c=_0xa5a0('0x23');break;default:_0x40654c=_0xa5a0('0x22');break;}var _0x48467d={'method':'POST','uri':_0x40654c+'/oauth/v2/token','qs':{'refresh_token':_0x3fd650[_0xa5a0('0x24')],'client_id':_0x3fd650[_0xa5a0('0x25')],'client_secret':_0x3fd650['clientSecret'],'grant_type':'refresh_token'},'json':!![]};return rp(_0x48467d)['then'](function(_0x459f61){accountsTokens[_0x3fd650['id']]={'access_token':_0x459f61[_0xa5a0('0x20')],'expires_in':moment()[_0xa5a0('0x26')](_0x459f61[_0xa5a0('0x1f')],_0xa5a0('0x27'))};_0x44adf3(_0x459f61['access_token']);})[_0xa5a0('0x28')](function(_0x32e328){logger[_0xa5a0('0x29')]('Failing\x20creating\x20the\x20access_token',_0x32e328['stack']);_0x3fdf1b(_0x32e328);});});}function getUser(_0x1e7527,_0x40d634,_0x46873c,_0x528bd0){logger[_0xa5a0('0x2a')](_0xa5a0('0x2b'));return request({'method':_0xa5a0('0x2c'),'uri':util[_0xa5a0('0x2d')](_0xa5a0('0x2e'),_0x40d634),'qs':{'type':_0xa5a0('0x2f')},'headers':{'Authorization':_0xa5a0('0x30')+_0x1e7527},'json':!![]})['then'](function(_0x33cf11){if(_0x33cf11[_0xa5a0('0x31')]){var _0x2153a8=-0x1;if(_[_0xa5a0('0x32')](_0x33cf11[_0xa5a0('0x31')])){if(!_[_0xa5a0('0x1d')](_0x528bd0)){_0x2153a8=_[_0xa5a0('0x33')](_0x33cf11[_0xa5a0('0x31')],function(_0x1230d1){return _0x1230d1[_0xa5a0('0x34')]===_0x528bd0;});}if(_0x2153a8>=0x0){logger[_0xa5a0('0x2a')](_0xa5a0('0x35'));}else{logger[_0xa5a0('0x2a')]('Using\x20the\x20admin\x20account!');_0x2153a8=_['findIndex'](_0x33cf11['users'],function(_0x19c3f4){return _0x19c3f4[_0xa5a0('0x36')][_0xa5a0('0x1a')]===_0xa5a0('0x37');});}return _0x33cf11[_0xa5a0('0x31')][_0x2153a8];}else{if(_0x33cf11[_0xa5a0('0x38')][_0xa5a0('0x36')][_0xa5a0('0x1a')]==='Administrator'){logger[_0xa5a0('0x2a')](_0xa5a0('0x39'));user=_0x33cf11['user'];return user;}else{logger['error'](_0xa5a0('0x3a'),JSON[_0xa5a0('0xe')](_0x33cf11));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0xa5a0('0xe')](_0x33cf11));}}}else{logger['error']('The\x20failing\x20result\x20is',JSON[_0xa5a0('0xe')](_0x33cf11));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0xa5a0('0xe')](_0x33cf11));}})[_0xa5a0('0x28')](function(_0x194de5){console[_0xa5a0('0x29')](_0x194de5);});}function getZohoUser(_0x58a801,_0x1ef1c6){return new BPromise(function(_0x2ca515,_0x957326){request(_0x58a801)['then'](function(_0x79066){var _0x561fe2=null;if(_0x79066){_0x561fe2=_0x79066[_0xa5a0('0x3b')][0x0];_0x561fe2['enduserType']=_0x1ef1c6;}_0x2ca515(_0x561fe2);})[_0xa5a0('0x28')](function(_0x159378){_0x957326(_0x159378);});});}function createEndUser(_0x4c8a12,_0x74dc07,_0x1a869b,_0x405d94,_0x57291a,_0x1938a5){var _0x1a869b=getName(_0x1a869b);return request({'method':_0xa5a0('0x3c'),'uri':_0xa5a0('0x3d')+_0x74dc07+_0xa5a0('0x3e')+_[_0xa5a0('0x3f')](_0x1938a5['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x1a869b[0x1],'First_Name':_0x1a869b[0x0],'Phone':_0x405d94,'Owner':{'name':!_[_0xa5a0('0x1d')](_0x57291a['role'][_0xa5a0('0x1a')])?_0x57291a['role'][_0xa5a0('0x1a')]:!_[_0xa5a0('0x1d')](_0x57291a[_0xa5a0('0x40')])?_0x57291a[_0xa5a0('0x40')]+'\x20'+_0x57291a['last_name']:_0x57291a[_0xa5a0('0x41')],'id':_0x57291a['id']}}]},'headers':{'Authorization':_0xa5a0('0x30')+_0x4c8a12},'json':!![]})['then'](function(_0x451e61){if(_0x451e61&&_0x451e61[_0xa5a0('0x3b')][0x0][_0xa5a0('0x42')]===_0xa5a0('0x43')){var _0x14dfe2=_0x451e61[_0xa5a0('0x3b')][0x0][_0xa5a0('0x44')];_0x14dfe2[_0xa5a0('0x45')]=_[_0xa5a0('0x3f')](_0x1938a5[_0xa5a0('0x46')])+'s';return _0x14dfe2;}logger[_0xa5a0('0x29')]('The\x20failing\x20result\x20is',JSON[_0xa5a0('0xe')](data));throw new Error(_0xa5a0('0x47')+JSON[_0xa5a0('0xe')](data));})[_0xa5a0('0x28')](function(_0x3293de){console['log'](_0xa5a0('0x48'),_0x3293de);});}function getEndUser(_0x1fb8fe,_0x3fff0e,_0x1f3dfa,_0x407856,_0x5d89d0,_0x5362ef,_0x2ae180){var _0x237c8d={'method':_0xa5a0('0x2c'),'uri':'','headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x1fb8fe},'json':!![]};switch(_0x2ae180[_0xa5a0('0x49')]){case _0xa5a0('0x4a'):_0x237c8d[_0xa5a0('0x4b')]=_0xa5a0('0x3d')+_0x3fff0e+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x5d89d0+'))';return getZohoUser(_0x237c8d,_0xa5a0('0x4c'))[_0xa5a0('0x4d')](function(_0x28b70d){if(_0x28b70d)return _0x28b70d;_0x237c8d[_0xa5a0('0x4b')]=_0xa5a0('0x3d')+_0x3fff0e+_0xa5a0('0x4e')+_0x5d89d0+'))';return getZohoUser(_0x237c8d,_0xa5a0('0x4f'))['then'](function(_0xcae8db){if(_0xcae8db)return _0xcae8db;if(_0x2ae180[_0xa5a0('0x46')]!='nothing'){return createEndUser(_0x1fb8fe,_0x3fff0e,_0x407856,_0x5d89d0,_0x5362ef,_0x2ae180);}else{return{};}});});break;case _0xa5a0('0x50'):_0x237c8d[_0xa5a0('0x4b')]=_0xa5a0('0x3d')+_0x3fff0e+_0xa5a0('0x51')+_0x5d89d0+'))';return getZohoUser(_0x237c8d,_0xa5a0('0x4c'))['then'](function(_0x287a76){if(_0x287a76)return _0x287a76;if(_0x2ae180['moduleCreate']!=_0xa5a0('0x52')){return createEndUser(_0x1fb8fe,_0x3fff0e,_0x407856,_0x5d89d0,_0x5362ef,_0x2ae180);}else{return{};}});break;case _0xa5a0('0x53'):_0x237c8d[_0xa5a0('0x4b')]=_0xa5a0('0x3d')+_0x3fff0e+_0xa5a0('0x4e')+_0x5d89d0+'))';return getZohoUser(_0x237c8d,_0xa5a0('0x4f'))[_0xa5a0('0x4d')](function(_0x246f6a){if(_0x246f6a)return _0x246f6a;if(_0x2ae180[_0xa5a0('0x46')]!=_0xa5a0('0x52')){return createEndUser(_0x1fb8fe,_0x3fff0e,_0x407856,_0x5d89d0,_0x5362ef,_0x2ae180);}else{return{};}});break;}}function getCall(_0x3ca5cd,_0x54364a,_0x59bb87,_0x49038d,_0x43b5bd,_0x2c442c,_0x91e054,_0x480b99){logger[_0xa5a0('0x2a')]('Creating\x20new\x20call...');var _0x955639={};_0x955639[_0xa5a0('0x54')]={'name':!_[_0xa5a0('0x1d')](_0x49038d[_0xa5a0('0x55')][_0xa5a0('0x1a')])&&!_[_0xa5a0('0x1d')](_0x49038d['profile'][_0xa5a0('0x1a')])&&_0x49038d['profile'][_0xa5a0('0x1a')]===_0xa5a0('0x56')?_0x49038d[_0xa5a0('0x55')]['name']:!_[_0xa5a0('0x1d')](_0x49038d[_0xa5a0('0x40')])?_0x49038d['first_name']+'\x20'+_0x49038d[_0xa5a0('0x41')]:_0x49038d[_0xa5a0('0x41')],'id':_0x49038d['id']};_0x955639[_0xa5a0('0x57')]=intUtil['getString'](_0x2c442c[_0xa5a0('0x58')],_0x91e054,'\x20');_0x955639['Description']=intUtil[_0xa5a0('0x59')](_0x2c442c[_0xa5a0('0x5a')],_0x91e054,'\x0a');if(_0x43b5bd[_0xa5a0('0x45')]===_0xa5a0('0x4c')){_0x955639[_0xa5a0('0x5b')]={'name':!_['isNil'](_0x43b5bd['Full_Name'])?_0x43b5bd['Full_Name']:!_[_0xa5a0('0x1d')](_0x43b5bd['First_Name'])?_0x43b5bd[_0xa5a0('0x5c')]+'\x20'+_0x43b5bd[_0xa5a0('0x5d')]:_0x43b5bd[_0xa5a0('0x5d')],'id':_0x43b5bd['id']};}if(_0x43b5bd[_0xa5a0('0x45')]===_0xa5a0('0x4f')){_0x955639[_0xa5a0('0x5e')]={'name':!_['isNil'](_0x43b5bd[_0xa5a0('0x5f')])?_0x43b5bd[_0xa5a0('0x5f')]:!_[_0xa5a0('0x1d')](_0x43b5bd[_0xa5a0('0x5c')])?_0x43b5bd[_0xa5a0('0x5c')]+'\x20'+_0x43b5bd[_0xa5a0('0x5d')]:_0x43b5bd[_0xa5a0('0x5d')],'id':_0x43b5bd['id']};_0x955639[_0xa5a0('0x60')]=_['startCase'](_0x43b5bd[_0xa5a0('0x45')]);}if(_0x91e054[_0xa5a0('0x61')]){_0x955639[_0xa5a0('0x62')]=moment[_0xa5a0('0x63')](parseInt(_0x91e054[_0xa5a0('0x61')])*0x3e8)[_0xa5a0('0x2d')]('mm:ss');}else if(_0x91e054[_0xa5a0('0x64')]&&_0x91e054[_0xa5a0('0x65')]){_0x955639['Call_Duration']=moment[_0xa5a0('0x63')](moment(_0x91e054[_0xa5a0('0x65')],'YYYY-MM-DDTHH:mm:ss')[_0xa5a0('0x66')](moment(_0x91e054[_0xa5a0('0x67')],'YYYY-MM-DDTHH:mm:ss')))[_0xa5a0('0x2d')](_0xa5a0('0x68'));}switch(_0x91e054['lastevent']){case _0xa5a0('0x69'):_0x955639[_0xa5a0('0x6a')]='Called';break;case _0xa5a0('0x6b'):case _0xa5a0('0x6c'):_0x955639[_0xa5a0('0x6a')]=_0xa5a0('0x6d');break;case _0xa5a0('0x6e'):_0x955639[_0xa5a0('0x6a')]=_0xa5a0('0x6f');break;case _0xa5a0('0x70'):_0x955639[_0xa5a0('0x6a')]=_0xa5a0('0x71');break;case'timeout':_0x955639['Call_Result']=_0xa5a0('0x72');default:}_0x955639['Call_Start_Time']=(_0x480b99===_0xa5a0('0x73')?moment(_0x91e054[_0xa5a0('0x67')])['format'](_0xa5a0('0x74')):moment(_0x91e054['agentcalledAt'])['format'](_0xa5a0('0x74')))||moment()[_0xa5a0('0x2d')](_0xa5a0('0x74'));_0x955639[_0xa5a0('0x75')]=_0x480b99||_0xa5a0('0x76');_0x955639=_[_0xa5a0('0x77')](_0x955639,getCustomFields(_0x2c442c[_0xa5a0('0x78')],_0x91e054));return request({'method':_0xa5a0('0x3c'),'uri':_0xa5a0('0x3d')+_0x54364a+_0xa5a0('0x79'),'headers':{'Authorization':_0xa5a0('0x30')+_0x3ca5cd},'body':{'data':[_0x955639]},'json':!![]})[_0xa5a0('0x4d')](function(_0x13a6d8){if(_0x13a6d8&&_0x13a6d8[_0xa5a0('0x3b')][0x0][_0xa5a0('0x42')]==='SUCCESS'){logger[_0xa5a0('0x2a')](_0xa5a0('0x7a'));return{'id':_0x13a6d8[_0xa5a0('0x3b')][0x0][_0xa5a0('0x44')]['id']};}})[_0xa5a0('0x28')](function(_0x4b77f7){logger[_0xa5a0('0x2a')](_0xa5a0('0x7b'),_0x4b77f7[_0xa5a0('0x7c')]);console[_0xa5a0('0x7d')](_0xa5a0('0x7b'),_0x4b77f7);});}exports['queue']=function(_0x35ffa2,_0x253108,_0x4e1864,_0x3b078f,_0x25d2f5,_0x2d3d61){var _0x3aee28,_0x57132a,_0x47c406;_0x2d3d61[_0xa5a0('0x7e')]=intUtil[_0xa5a0('0x7f')](_0x2d3d61[_0xa5a0('0x7e')]);_0x2d3d61[_0xa5a0('0x80')]=intUtil[_0xa5a0('0x7f')](_0x2d3d61['serverUrl']);if(_0x25d2f5&&_0x25d2f5['monitor_format']){logger[_0xa5a0('0x2a')](_0xa5a0('0x81'),'Recording\x20is\x20enabled!');_0x253108[_0xa5a0('0x82')]=_0x2d3d61[_0xa5a0('0x80')]+_0xa5a0('0x83')+_0x253108[_0xa5a0('0x84')]+'/downloads?type=uniqueid&token='+md5(_0x253108[_0xa5a0('0x84')]);}else{_0x253108[_0xa5a0('0x82')]='';}var _0x5d7e1a=_0x2d3d61[_0xa5a0('0x7e')]===_0xa5a0('0x85')?'eu':_0xa5a0('0x86');return getAccessToken(_0x2d3d61)['then'](function(_0x30caa0){_0x47c406=_0x30caa0;return getUser(_0x47c406,_0x5d7e1a,_0x2d3d61,_0x3b078f['email']);})['then'](function(_0x4b2b7f){_0x3aee28=_0x4b2b7f;logger[_0xa5a0('0x2a')]('The\x20User\x20ID\x20is:',_0x3aee28['id']);return getEndUser(_0x47c406,_0x5d7e1a,_0x2d3d61,_0x253108['calleridname'],_0x253108[_0xa5a0('0x87')],_0x3aee28,_0x4e1864);})[_0xa5a0('0x4d')](function(_0x59e13e){_0x57132a=_0x59e13e;return getCall(_0x47c406,_0x5d7e1a,_0x2d3d61,_0x3aee28,_0x57132a,_0x4e1864,_0x253108,_0xa5a0('0x76'));})[_0xa5a0('0x4d')](function(_0x912db0){if(_0x912db0){logger[_0xa5a0('0x2a')]('The\x20Call\x20ID\x20is:',_0x912db0['id']);logger['info'](_0xa5a0('0x81'),_0xa5a0('0x88'));emit(util[_0xa5a0('0x2d')](_0xa5a0('0x89'),_0x3b078f[_0xa5a0('0x1a')]),_0xa5a0('0x8a'),{'uri':'https://crm.'+_0x2d3d61[_0xa5a0('0x7e')]+_0xa5a0('0x8b')+_0x912db0['id']});}})[_0xa5a0('0x28')](function(_0x56a069){logger[_0xa5a0('0x29')](_0xa5a0('0x81'),JSON['stringify'](_0x56a069));});};exports[_0xa5a0('0x73')]=function(_0x40feb0,_0x2d35c3,_0x50320b,_0x27bbf6,_0x3cb639,_0x4e2b99,_0x43c7fd){var _0x4542f5,_0x80c049,_0x2646e7;_0x4e2b99['host']=intUtil[_0xa5a0('0x7f')](_0x4e2b99[_0xa5a0('0x7e')]);_0x4e2b99[_0xa5a0('0x80')]=intUtil['stripTrailingSlash'](_0x4e2b99['serverUrl']);if(_0x43c7fd&&_0x43c7fd[_0xa5a0('0x8c')]&&_0x43c7fd[_0xa5a0('0x8c')]!==_0xa5a0('0x8d')){logger[_0xa5a0('0x2a')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x2d35c3[_0xa5a0('0x82')]=_0x4e2b99[_0xa5a0('0x80')]+_0xa5a0('0x83')+_0x2d35c3[_0xa5a0('0x84')]+_0xa5a0('0x8e')+md5(_0x2d35c3[_0xa5a0('0x84')]);}var _0x445ed2=_0x4e2b99['host']===_0xa5a0('0x85')?'eu':'com';return getAccessToken(_0x4e2b99)[_0xa5a0('0x4d')](function(_0x261bef){_0x2646e7=_0x261bef;return getUser(_0x2646e7,_0x445ed2,_0x4e2b99,_0x27bbf6[_0xa5a0('0x34')]);})[_0xa5a0('0x4d')](function(_0xacefc8){_0x4542f5=_0xacefc8;logger[_0xa5a0('0x2a')]('The\x20User\x20ID\x20is:',_0x4542f5['id']);return getEndUser(_0x2646e7,_0x445ed2,_0x4e2b99,_0x2d35c3[_0xa5a0('0x8f')],_0x2d35c3[_0xa5a0('0x90')],_0x4542f5,_0x50320b);})[_0xa5a0('0x4d')](function(_0x2c0106){_0x80c049=_0x2c0106;return getCall(_0x2646e7,_0x445ed2,_0x4e2b99,_0x4542f5,_0x80c049,_0x50320b,_0x2d35c3,_0xa5a0('0x91'));})[_0xa5a0('0x4d')](function(_0x3fffb2){if(_0x3fffb2){logger[_0xa5a0('0x2a')]('The\x20Call\x20ID\x20is:',_0x3fffb2['id']);logger[_0xa5a0('0x2a')](_0xa5a0('0x92'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0xa5a0('0x89'),_0x27bbf6[_0xa5a0('0x1a')]),'trigger:browser:url',{'uri':'https://crm.'+_0x4e2b99[_0xa5a0('0x7e')]+_0xa5a0('0x8b')+_0x3fffb2['id']});}})['catch'](function(_0x5cff0d){logger[_0xa5a0('0x29')](_0xa5a0('0x92'),JSON[_0xa5a0('0xe')](_0x5cff0d));});};exports['unmanaged']=function(_0xf84c1c,_0x2f4484,_0x4790fa,_0x1040bd,_0x3597c4,_0x258af3){var _0x494a43,_0x339e9d,_0x342e93;_0x258af3['host']=intUtil[_0xa5a0('0x7f')](_0x258af3['host']);_0x258af3[_0xa5a0('0x80')]=intUtil[_0xa5a0('0x7f')](_0x258af3[_0xa5a0('0x80')]);if(_0x3597c4&&_0x3597c4['monitor_format']){logger[_0xa5a0('0x2a')]('['+_0x2f4484[_0xa5a0('0x93')][_0xa5a0('0x94')]()+']','Recording\x20is\x20enabled!');_0x2f4484[_0xa5a0('0x82')]=_0x258af3[_0xa5a0('0x80')]+'/api/voice/recordings/'+_0x2f4484[_0xa5a0('0x84')]+_0xa5a0('0x8e')+md5(_0x2f4484[_0xa5a0('0x84')]);}else{_0x2f4484[_0xa5a0('0x82')]='';}var _0x531cc1=_0x258af3[_0xa5a0('0x7e')]===_0xa5a0('0x85')?'eu':'com';return getAccessToken(_0x258af3)[_0xa5a0('0x4d')](function(_0x4aedd7){_0x342e93=_0x4aedd7;return getUser(_0x342e93,_0x531cc1,_0x258af3);})[_0xa5a0('0x4d')](function(_0x2bb7ba){_0x494a43=_0x2bb7ba;logger[_0xa5a0('0x2a')](_0xa5a0('0x95'),_0x494a43['id']);return getEndUser(_0x342e93,_0x531cc1,_0x258af3,_0x2f4484['calleridname'],_0x2f4484[_0xa5a0('0x87')],_0x494a43,_0x4790fa);})[_0xa5a0('0x4d')](function(_0x2eaafb){_0x339e9d=_0x2eaafb;return getCall(_0x342e93,_0x531cc1,_0x258af3,_0x494a43,_0x339e9d,_0x4790fa,_0x2f4484,_0xa5a0('0x76'));})[_0xa5a0('0x4d')](function(_0x3bbf7d){if(_0x3bbf7d){logger['info'](_0xa5a0('0x96'),_0x3bbf7d['id']);}})[_0xa5a0('0x28')](function(_0x1018c3){logger[_0xa5a0('0x29')]('['+_0x2f4484['lastevent'][_0xa5a0('0x94')]()+']',JSON['stringify'](_0x1018c3));});};
\ No newline at end of file