cdd105f4c56d2237b8b9648f3eed56206d2e5e6a
[motion2.git] / server / services / ami / trigger / integration / zoho.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xbfc9=['Descriptions','Who_Id','Full_Name','First_Name','Last_Name','$se_module','talktime','utc','mm:ss','endtime','YYYY-MM-DDTHH:mm:ss','diff','lastevent','Called','complete','connect','Answered','rejected','Rejected','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','outbound','starttime','Call_Type','Inbound','Fields','Call\x20created!','details','err','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/api/voice/recordings/','uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','The\x20User\x20ID\x20is:','calleridname','calleridnum','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','Outbound','The\x20Call\x20ID\x20is:','unmanaged','toUpperCase','lodash','request-promise','util','moment','bluebird','../../../../config/environment','../../../../config/logger','zoho','defaults','redis','localhost','socket.io-emitter','emit','[HTTP]','stringify','length','includes','string','picklist','type','idField','content','toString','variable','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','isBefore','expires_in','https://accounts.zoho.eu','https://accounts.zoho.com.cn','/oauth/v2/token','refreshToken','clientId','clientSecret','refresh_token','then','access_token','add','seconds','catch','Failing\x20creating\x20the\x20access_token','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','Zoho-oauthtoken\x20','users','isArrayLikeObject','email','Using\x20the\x20admin\x20account!','findIndex','profile','Administrator','error','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','POST','https://www.zohoapis.','startCase','moduleCreate','role','first_name','last_name','code','SUCCESS','Error:\x20','log','CREATE\x20ERROR','moduleSearch','contact_lead','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','nothing','contact','lead','Owner','administrator','Subject','getString','Subjects','Description'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0xbfc9,0x173));var _0x9bfc=function(_0x40e21d,_0xe32def){_0x40e21d=_0x40e21d-0x0;var _0x30f13e=_0xbfc9[_0x40e21d];return _0x30f13e;};'use strict';var _=require(_0x9bfc('0x0'));var rp=require(_0x9bfc('0x1'));var md5=require('md5');var util=require(_0x9bfc('0x2'));var intUtil=require('./util');var moment=require(_0x9bfc('0x3'));var Redis=require('ioredis');var BPromise=require(_0x9bfc('0x4'));var config=require(_0x9bfc('0x5'));var logger=require(_0x9bfc('0x6'))(_0x9bfc('0x7'));config['redis']=_[_0x9bfc('0x8')](config[_0x9bfc('0x9')],{'host':_0x9bfc('0xa'),'port':0x18eb});var io=require(_0x9bfc('0xb'))(new Redis(config[_0x9bfc('0x9')]));function emit(_0x1a4789,_0x384dde,_0x3bbab4){io['to'](_0x1a4789)[_0x9bfc('0xc')](_0x384dde,_0x3bbab4);}function request(_0x82092){logger['debug'](_0x9bfc('0xd'),JSON[_0x9bfc('0xe')](_0x82092));return rp(_0x82092);}function getCustomFields(_0xbe23b4,_0x2b7333){var _0x1d9506={};if(_0xbe23b4[_0x9bfc('0xf')]>0x0){_['forEach'](_0xbe23b4,function(_0x32f083){if(_[_0x9bfc('0x10')]([_0x9bfc('0x11'),_0x9bfc('0x12')],_0x32f083[_0x9bfc('0x13')])&&_0x32f083[_0x9bfc('0x14')]){_0x1d9506[_0x32f083[_0x9bfc('0x14')]]=_0x32f083[_0x9bfc('0x15')][_0x9bfc('0x16')]();}else if(_0x32f083[_0x9bfc('0x13')]===_0x9bfc('0x17')&&_0x32f083['variableName']&&_0x32f083[_0x9bfc('0x14')]&&_0x2b7333[_0x32f083[_0x9bfc('0x18')]]){_0x1d9506[_0x32f083[_0x9bfc('0x14')]]=_0x2b7333[_0x32f083[_0x9bfc('0x18')]][_0x9bfc('0x16')]();}else if(_0x32f083[_0x9bfc('0x13')]===_0x9bfc('0x19')&&_0x32f083[_0x9bfc('0x1a')]&&_0x32f083['Variable'][_0x9bfc('0x1b')]&&_0x32f083[_0x9bfc('0x14')]&&_0x2b7333[_0x32f083[_0x9bfc('0x1a')]['name']['toLowerCase']()]){_0x1d9506[_0x32f083[_0x9bfc('0x14')]]=_0x2b7333[_0x32f083[_0x9bfc('0x1a')]['name'][_0x9bfc('0x1c')]()][_0x9bfc('0x16')]();}});}return _0x1d9506;}function getName(_0x32a350){if(_0x32a350[_0x9bfc('0x1d')]('\x20')>0x0){var _0xb771f3=_0x32a350[_0x9bfc('0x1e')](/ (.+)/);if(_0xb771f3[0x1]){return _0xb771f3;}}return[_0x32a350,_0x32a350];}var accountsTokens={};function getAccessToken(_0x3e1b4e){return new Promise(function(_0x32126d,_0x564633){if(!_['isNil'](accountsTokens[_0x3e1b4e['id']])&&!_[_0x9bfc('0x1f')](accountsTokens[_0x3e1b4e['id']]['access_token'])){if(moment()[_0x9bfc('0x20')](accountsTokens[_0x3e1b4e['id']][_0x9bfc('0x21')])){_0x32126d(accountsTokens[_0x3e1b4e['id']]['access_token']);}}var _0x181579;switch(_0x3e1b4e['zone']){case'US':_0x181579='https://accounts.zoho.com';break;case'AU':_0x181579='https://accounts.zoho.com.au';break;case'EU':_0x181579=_0x9bfc('0x22');break;case'IN':_0x181579='https://accounts.zoho.in';break;case'CN':_0x181579=_0x9bfc('0x23');break;default:_0x181579=_0x9bfc('0x22');break;}var _0x399a00={'method':'POST','uri':_0x181579+_0x9bfc('0x24'),'qs':{'refresh_token':_0x3e1b4e[_0x9bfc('0x25')],'client_id':_0x3e1b4e[_0x9bfc('0x26')],'client_secret':_0x3e1b4e[_0x9bfc('0x27')],'grant_type':_0x9bfc('0x28')},'json':!![]};return rp(_0x399a00)[_0x9bfc('0x29')](function(_0x32c09f){accountsTokens[_0x3e1b4e['id']]={'access_token':_0x32c09f[_0x9bfc('0x2a')],'expires_in':moment()[_0x9bfc('0x2b')](_0x32c09f[_0x9bfc('0x21')],_0x9bfc('0x2c'))};_0x32126d(_0x32c09f[_0x9bfc('0x2a')]);})[_0x9bfc('0x2d')](function(_0x28d823){logger['error'](_0x9bfc('0x2e'),_0x28d823[_0x9bfc('0x2f')]);_0x564633(_0x28d823);});});}function getUser(_0x295e69,_0x4b3b59,_0x35c7df,_0x2a346c){logger[_0x9bfc('0x30')](_0x9bfc('0x31'));return request({'method':_0x9bfc('0x32'),'uri':util[_0x9bfc('0x33')](_0x9bfc('0x34'),_0x4b3b59),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':_0x9bfc('0x35')+_0x295e69},'json':!![]})[_0x9bfc('0x29')](function(_0x5ad984){if(_0x5ad984[_0x9bfc('0x36')]){var _0x5ea0b5=-0x1;if(_[_0x9bfc('0x37')](_0x5ad984['users'])){if(!_[_0x9bfc('0x1f')](_0x2a346c)){_0x5ea0b5=_['findIndex'](_0x5ad984[_0x9bfc('0x36')],function(_0x4f2ec3){return _0x4f2ec3[_0x9bfc('0x38')]===_0x2a346c;});}if(_0x5ea0b5>=0x0){logger['info']('Agent\x20found!');}else{logger[_0x9bfc('0x30')](_0x9bfc('0x39'));_0x5ea0b5=_[_0x9bfc('0x3a')](_0x5ad984['users'],function(_0xc353f9){return _0xc353f9[_0x9bfc('0x3b')][_0x9bfc('0x1b')]===_0x9bfc('0x3c');});}return _0x5ad984['users'][_0x5ea0b5];}else{if(_0x5ad984['user'][_0x9bfc('0x3b')]['name']===_0x9bfc('0x3c')){logger[_0x9bfc('0x30')](_0x9bfc('0x39'));user=_0x5ad984['user'];return user;}else{logger[_0x9bfc('0x3d')](_0x9bfc('0x3e'),JSON[_0x9bfc('0xe')](_0x5ad984));throw new Error(_0x9bfc('0x3f')+JSON[_0x9bfc('0xe')](_0x5ad984));}}}else{logger[_0x9bfc('0x3d')]('The\x20failing\x20result\x20is',JSON[_0x9bfc('0xe')](_0x5ad984));throw new Error(_0x9bfc('0x3f')+JSON['stringify'](_0x5ad984));}})[_0x9bfc('0x2d')](function(_0x5513b7){console[_0x9bfc('0x3d')](_0x5513b7);});}function getZohoUser(_0x5645fe,_0x17b5e4){return new BPromise(function(_0x31e8db,_0x2cd575){request(_0x5645fe)[_0x9bfc('0x29')](function(_0x5cc9b6){var _0x1759f5=null;if(_0x5cc9b6){_0x1759f5=_0x5cc9b6[_0x9bfc('0x40')][0x0];_0x1759f5[_0x9bfc('0x41')]=_0x17b5e4;}_0x31e8db(_0x1759f5);})['catch'](function(_0x310053){_0x2cd575(_0x310053);});});}function createEndUser(_0x33923e,_0xcd2afd,_0x20e583,_0x2b7791,_0x1e31b0,_0x1e3dd4){var _0x20e583=getName(_0x20e583);return request({'method':_0x9bfc('0x42'),'uri':_0x9bfc('0x43')+_0xcd2afd+'/crm/v2/'+_[_0x9bfc('0x44')](_0x1e3dd4[_0x9bfc('0x45')])+'s','body':{'data':[{'Last_Name':_0x20e583[0x1],'First_Name':_0x20e583[0x0],'Phone':_0x2b7791,'Owner':{'name':!_[_0x9bfc('0x1f')](_0x1e31b0[_0x9bfc('0x46')][_0x9bfc('0x1b')])?_0x1e31b0[_0x9bfc('0x46')]['name']:!_[_0x9bfc('0x1f')](_0x1e31b0[_0x9bfc('0x47')])?_0x1e31b0[_0x9bfc('0x47')]+'\x20'+_0x1e31b0[_0x9bfc('0x48')]:_0x1e31b0[_0x9bfc('0x48')],'id':_0x1e31b0['id']}}]},'headers':{'Authorization':_0x9bfc('0x35')+_0x33923e},'json':!![]})['then'](function(_0x56f876){if(_0x56f876&&_0x56f876[_0x9bfc('0x40')][0x0][_0x9bfc('0x49')]===_0x9bfc('0x4a')){var _0x30562e=_0x56f876[_0x9bfc('0x40')][0x0]['details'];_0x30562e[_0x9bfc('0x41')]=_[_0x9bfc('0x44')](_0x1e3dd4[_0x9bfc('0x45')])+'s';return _0x30562e;}logger[_0x9bfc('0x3d')](_0x9bfc('0x3e'),JSON[_0x9bfc('0xe')](data));throw new Error(_0x9bfc('0x4b')+JSON[_0x9bfc('0xe')](data));})[_0x9bfc('0x2d')](function(_0x591598){console[_0x9bfc('0x4c')](_0x9bfc('0x4d'),_0x591598);});}function getEndUser(_0x5a4b7e,_0x567580,_0xf55e08,_0x5b8eab,_0x4d833b,_0x4d6aed,_0x2b38d0){var _0x3187a6={'method':_0x9bfc('0x32'),'uri':'','headers':{'Authorization':_0x9bfc('0x35')+_0x5a4b7e},'json':!![]};switch(_0x2b38d0[_0x9bfc('0x4e')]){case _0x9bfc('0x4f'):_0x3187a6[_0x9bfc('0x50')]=_0x9bfc('0x43')+_0x567580+_0x9bfc('0x51')+_0x4d833b+'))';return getZohoUser(_0x3187a6,_0x9bfc('0x52'))[_0x9bfc('0x29')](function(_0x499915){if(_0x499915)return _0x499915;_0x3187a6[_0x9bfc('0x50')]=_0x9bfc('0x43')+_0x567580+_0x9bfc('0x53')+_0x4d833b+'))';return getZohoUser(_0x3187a6,_0x9bfc('0x54'))['then'](function(_0x378335){if(_0x378335)return _0x378335;if(_0x2b38d0[_0x9bfc('0x45')]!=_0x9bfc('0x55')){return createEndUser(_0x5a4b7e,_0x567580,_0x5b8eab,_0x4d833b,_0x4d6aed,_0x2b38d0);}else{return{};}});});break;case _0x9bfc('0x56'):_0x3187a6[_0x9bfc('0x50')]=_0x9bfc('0x43')+_0x567580+_0x9bfc('0x51')+_0x4d833b+'))';return getZohoUser(_0x3187a6,_0x9bfc('0x52'))[_0x9bfc('0x29')](function(_0x16a5e4){if(_0x16a5e4)return _0x16a5e4;if(_0x2b38d0[_0x9bfc('0x45')]!=_0x9bfc('0x55')){return createEndUser(_0x5a4b7e,_0x567580,_0x5b8eab,_0x4d833b,_0x4d6aed,_0x2b38d0);}else{return{};}});break;case _0x9bfc('0x57'):_0x3187a6[_0x9bfc('0x50')]='https://www.zohoapis.'+_0x567580+_0x9bfc('0x53')+_0x4d833b+'))';return getZohoUser(_0x3187a6,_0x9bfc('0x54'))['then'](function(_0x57c538){if(_0x57c538)return _0x57c538;if(_0x2b38d0[_0x9bfc('0x45')]!='nothing'){return createEndUser(_0x5a4b7e,_0x567580,_0x5b8eab,_0x4d833b,_0x4d6aed,_0x2b38d0);}else{return{};}});break;}}function getCall(_0x485821,_0x248095,_0x310440,_0x537cb9,_0x251323,_0x349997,_0x1feb2c,_0x5271a9){logger['info']('Creating\x20new\x20call...');var _0xf36f24={};_0xf36f24[_0x9bfc('0x58')]={'name':!_['isNil'](_0x537cb9['role'][_0x9bfc('0x1b')])&&!_[_0x9bfc('0x1f')](_0x537cb9[_0x9bfc('0x3b')][_0x9bfc('0x1b')])&&_0x537cb9[_0x9bfc('0x3b')][_0x9bfc('0x1b')]===_0x9bfc('0x59')?_0x537cb9[_0x9bfc('0x46')][_0x9bfc('0x1b')]:!_[_0x9bfc('0x1f')](_0x537cb9[_0x9bfc('0x47')])?_0x537cb9['first_name']+'\x20'+_0x537cb9[_0x9bfc('0x48')]:_0x537cb9[_0x9bfc('0x48')],'id':_0x537cb9['id']};_0xf36f24[_0x9bfc('0x5a')]=intUtil[_0x9bfc('0x5b')](_0x349997[_0x9bfc('0x5c')],_0x1feb2c,'\x20');_0xf36f24[_0x9bfc('0x5d')]=intUtil[_0x9bfc('0x5b')](_0x349997[_0x9bfc('0x5e')],_0x1feb2c,'\x0a');if(_0x251323[_0x9bfc('0x41')]===_0x9bfc('0x52')){_0xf36f24[_0x9bfc('0x5f')]={'name':!_[_0x9bfc('0x1f')](_0x251323[_0x9bfc('0x60')])?_0x251323[_0x9bfc('0x60')]:!_[_0x9bfc('0x1f')](_0x251323[_0x9bfc('0x61')])?_0x251323[_0x9bfc('0x61')]+'\x20'+_0x251323[_0x9bfc('0x62')]:_0x251323[_0x9bfc('0x62')],'id':_0x251323['id']};}if(_0x251323[_0x9bfc('0x41')]==='Leads'){_0xf36f24['What_Id']={'name':!_['isNil'](_0x251323[_0x9bfc('0x60')])?_0x251323[_0x9bfc('0x60')]:!_['isNil'](_0x251323[_0x9bfc('0x61')])?_0x251323[_0x9bfc('0x61')]+'\x20'+_0x251323[_0x9bfc('0x62')]:_0x251323[_0x9bfc('0x62')],'id':_0x251323['id']};_0xf36f24[_0x9bfc('0x63')]=_['startCase'](_0x251323[_0x9bfc('0x41')]);}if(_0x1feb2c[_0x9bfc('0x64')]){_0xf36f24['Call_Duration']=moment[_0x9bfc('0x65')](parseInt(_0x1feb2c[_0x9bfc('0x64')])*0x3e8)[_0x9bfc('0x33')](_0x9bfc('0x66'));}else if(_0x1feb2c['answertime']&&_0x1feb2c[_0x9bfc('0x67')]){_0xf36f24['Call_Duration']=moment[_0x9bfc('0x65')](moment(_0x1feb2c['endtime'],_0x9bfc('0x68'))[_0x9bfc('0x69')](moment(_0x1feb2c['starttime'],_0x9bfc('0x68'))))['format']('mm:ss');}switch(_0x1feb2c[_0x9bfc('0x6a')]){case'called':_0xf36f24['Call_Result']=_0x9bfc('0x6b');break;case _0x9bfc('0x6c'):case _0x9bfc('0x6d'):_0xf36f24['Call_Result']=_0x9bfc('0x6e');break;case _0x9bfc('0x6f'):_0xf36f24['Call_Result']=_0x9bfc('0x70');break;case _0x9bfc('0x71'):_0xf36f24['Call_Result']=_0x9bfc('0x72');break;case _0x9bfc('0x73'):_0xf36f24['Call_Result']=_0x9bfc('0x74');default:}_0xf36f24[_0x9bfc('0x75')]=(_0x5271a9===_0x9bfc('0x76')?moment(_0x1feb2c[_0x9bfc('0x77')])[_0x9bfc('0x33')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x1feb2c['agentcalledAt'])[_0x9bfc('0x33')](_0x9bfc('0x68')))||moment()[_0x9bfc('0x33')](_0x9bfc('0x68'));_0xf36f24[_0x9bfc('0x78')]=_0x5271a9||_0x9bfc('0x79');_0xf36f24=_['merge'](_0xf36f24,getCustomFields(_0x349997[_0x9bfc('0x7a')],_0x1feb2c));return request({'method':_0x9bfc('0x42'),'uri':_0x9bfc('0x43')+_0x248095+'/crm/v2/Calls','headers':{'Authorization':_0x9bfc('0x35')+_0x485821},'body':{'data':[_0xf36f24]},'json':!![]})['then'](function(_0x4d6725){if(_0x4d6725&&_0x4d6725[_0x9bfc('0x40')][0x0]['code']==='SUCCESS'){logger[_0x9bfc('0x30')](_0x9bfc('0x7b'));return{'id':_0x4d6725[_0x9bfc('0x40')][0x0][_0x9bfc('0x7c')]['id']};}})[_0x9bfc('0x2d')](function(_0x4f4962){logger[_0x9bfc('0x30')]('err',_0x4f4962[_0x9bfc('0x2f')]);console['log'](_0x9bfc('0x7d'),_0x4f4962);});}exports['queue']=function(_0x25d31b,_0x3b0822,_0x22dd8d,_0x272fe9,_0x5278da,_0x2f561a){var _0x9bc00f,_0x4e1436,_0x41440f;_0x2f561a[_0x9bfc('0x7e')]=intUtil[_0x9bfc('0x7f')](_0x2f561a['host']);_0x2f561a[_0x9bfc('0x80')]=intUtil[_0x9bfc('0x7f')](_0x2f561a[_0x9bfc('0x80')]);if(_0x5278da&&_0x5278da[_0x9bfc('0x81')]){logger[_0x9bfc('0x30')](_0x9bfc('0x82'),_0x9bfc('0x83'));_0x3b0822[_0x9bfc('0x84')]=_0x2f561a[_0x9bfc('0x80')]+_0x9bfc('0x85')+_0x3b0822[_0x9bfc('0x86')]+_0x9bfc('0x87')+md5(_0x3b0822[_0x9bfc('0x86')]);}else{_0x3b0822[_0x9bfc('0x84')]='';}var _0xf3ebdc=_0x2f561a[_0x9bfc('0x7e')]===_0x9bfc('0x88')?'eu':_0x9bfc('0x89');return getAccessToken(_0x2f561a)[_0x9bfc('0x29')](function(_0x2369b8){_0x41440f=_0x2369b8;return getUser(_0x41440f,_0xf3ebdc,_0x2f561a,_0x272fe9['email']);})['then'](function(_0xaef2e8){_0x9bc00f=_0xaef2e8;logger[_0x9bfc('0x30')](_0x9bfc('0x8a'),_0x9bc00f['id']);return getEndUser(_0x41440f,_0xf3ebdc,_0x2f561a,_0x3b0822[_0x9bfc('0x8b')],_0x3b0822[_0x9bfc('0x8c')],_0x9bc00f,_0x22dd8d);})[_0x9bfc('0x29')](function(_0x2d43a1){_0x4e1436=_0x2d43a1;return getCall(_0x41440f,_0xf3ebdc,_0x2f561a,_0x9bc00f,_0x4e1436,_0x22dd8d,_0x3b0822,'Inbound');})[_0x9bfc('0x29')](function(_0x43b986){if(_0x43b986){logger[_0x9bfc('0x30')]('The\x20Call\x20ID\x20is:',_0x43b986['id']);logger['info']('[QUEUE]',_0x9bfc('0x8d'));emit(util[_0x9bfc('0x33')](_0x9bfc('0x8e'),_0x272fe9[_0x9bfc('0x1b')]),_0x9bfc('0x8f'),{'uri':_0x9bfc('0x90')+_0x2f561a[_0x9bfc('0x7e')]+_0x9bfc('0x91')+_0x43b986['id']});}})['catch'](function(_0x381409){logger['error']('[QUEUE]',JSON[_0x9bfc('0xe')](_0x381409));});};exports[_0x9bfc('0x76')]=function(_0x347547,_0x2a4906,_0x237f55,_0x51a982,_0x137170,_0xd2c23c,_0x11aa8d){var _0x5853a4,_0x34e447,_0x45c43f;_0xd2c23c[_0x9bfc('0x7e')]=intUtil[_0x9bfc('0x7f')](_0xd2c23c[_0x9bfc('0x7e')]);_0xd2c23c[_0x9bfc('0x80')]=intUtil['stripTrailingSlash'](_0xd2c23c[_0x9bfc('0x80')]);if(_0x11aa8d&&_0x11aa8d[_0x9bfc('0x92')]&&_0x11aa8d[_0x9bfc('0x92')]!==_0x9bfc('0x93')){logger[_0x9bfc('0x30')](_0x9bfc('0x94'),_0x9bfc('0x83'));_0x2a4906[_0x9bfc('0x84')]=_0xd2c23c['serverUrl']+_0x9bfc('0x85')+_0x2a4906[_0x9bfc('0x86')]+_0x9bfc('0x87')+md5(_0x2a4906[_0x9bfc('0x86')]);}var _0x3ce619=_0xd2c23c['host']===_0x9bfc('0x88')?'eu':_0x9bfc('0x89');return getAccessToken(_0xd2c23c)[_0x9bfc('0x29')](function(_0x2112a9){_0x45c43f=_0x2112a9;return getUser(_0x45c43f,_0x3ce619,_0xd2c23c,_0x51a982[_0x9bfc('0x38')]);})['then'](function(_0xb0f12){_0x5853a4=_0xb0f12;logger['info'](_0x9bfc('0x8a'),_0x5853a4['id']);return getEndUser(_0x45c43f,_0x3ce619,_0xd2c23c,_0x2a4906[_0x9bfc('0x95')],_0x2a4906[_0x9bfc('0x96')],_0x5853a4,_0x237f55);})[_0x9bfc('0x29')](function(_0x74c8d2){_0x34e447=_0x74c8d2;return getCall(_0x45c43f,_0x3ce619,_0xd2c23c,_0x5853a4,_0x34e447,_0x237f55,_0x2a4906,_0x9bfc('0x97'));})[_0x9bfc('0x29')](function(_0x46c2ca){if(_0x46c2ca){logger[_0x9bfc('0x30')](_0x9bfc('0x98'),_0x46c2ca['id']);logger[_0x9bfc('0x30')](_0x9bfc('0x94'),_0x9bfc('0x8d'));emit(util[_0x9bfc('0x33')](_0x9bfc('0x8e'),_0x51a982[_0x9bfc('0x1b')]),_0x9bfc('0x8f'),{'uri':_0x9bfc('0x90')+_0xd2c23c['host']+_0x9bfc('0x91')+_0x46c2ca['id']});}})[_0x9bfc('0x2d')](function(_0x2ab775){logger[_0x9bfc('0x3d')](_0x9bfc('0x94'),JSON[_0x9bfc('0xe')](_0x2ab775));});};exports[_0x9bfc('0x99')]=function(_0x42deaf,_0x4740be,_0x175838,_0x412c53,_0x46d3b1,_0x461732){var _0x7302d,_0x24d2d7,_0x22b4f3;_0x461732[_0x9bfc('0x7e')]=intUtil['stripTrailingSlash'](_0x461732[_0x9bfc('0x7e')]);_0x461732[_0x9bfc('0x80')]=intUtil[_0x9bfc('0x7f')](_0x461732['serverUrl']);if(_0x46d3b1&&_0x46d3b1[_0x9bfc('0x81')]){logger[_0x9bfc('0x30')]('['+_0x4740be['lastevent'][_0x9bfc('0x9a')]()+']',_0x9bfc('0x83'));_0x4740be[_0x9bfc('0x84')]=_0x461732['serverUrl']+_0x9bfc('0x85')+_0x4740be['uniqueid']+'/downloads?type=uniqueid&token='+md5(_0x4740be['uniqueid']);}else{_0x4740be[_0x9bfc('0x84')]='';}var _0x5cc9e7=_0x461732[_0x9bfc('0x7e')]===_0x9bfc('0x88')?'eu':_0x9bfc('0x89');return getAccessToken(_0x461732)['then'](function(_0x1f0ac2){_0x22b4f3=_0x1f0ac2;return getUser(_0x22b4f3,_0x5cc9e7,_0x461732);})['then'](function(_0x466498){_0x7302d=_0x466498;logger[_0x9bfc('0x30')](_0x9bfc('0x8a'),_0x7302d['id']);return getEndUser(_0x22b4f3,_0x5cc9e7,_0x461732,_0x4740be[_0x9bfc('0x8b')],_0x4740be[_0x9bfc('0x8c')],_0x7302d,_0x175838);})[_0x9bfc('0x29')](function(_0x977f27){_0x24d2d7=_0x977f27;return getCall(_0x22b4f3,_0x5cc9e7,_0x461732,_0x7302d,_0x24d2d7,_0x175838,_0x4740be,_0x9bfc('0x79'));})[_0x9bfc('0x29')](function(_0x1eda28){if(_0x1eda28){logger['info'](_0x9bfc('0x98'),_0x1eda28['id']);}})[_0x9bfc('0x2d')](function(_0x3ee740){logger['error']('['+_0x4740be[_0x9bfc('0x6a')][_0x9bfc('0x9a')]()+']',JSON[_0x9bfc('0xe')](_0x3ee740));});};