Built motion from commit da617fac.|2.6.6
[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 _0x3b43=['refresh_token','then','add','catch','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','isArrayLikeObject','findIndex','users','info','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','Administrator','user','error','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','https://www.zohoapis.','/crm/v2/','startCase','role','first_name','last_name','code','details','Error:\x20','log','moduleSearch','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','moduleCreate','nothing','contact','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','Creating\x20new\x20call...','Owner','administrator','getString','Subjects','Description','Descriptions','enduserType','Who_Id','Full_Name','First_Name','Last_Name','Leads','$se_module','Call_Duration','utc','talktime','mm:ss','answertime','endtime','YYYY-MM-DDTHH:mm:ss','diff','starttime','called','Call_Result','Answered','rejected','Rejected','abandoned','Abandoned','Timeout','Call_Start_Time','outbound','Call_Type','Inbound','Fields','/crm/v2/Calls','SUCCESS','Call\x20created!','err','stack','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/api/voice/recordings/','/downloads?type=uniqueid&token=','uniqueid','zoho.eu','com','email','calleridname','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','https://crm.','recordingFormat','destcalleridname','destcalleridnum','Outbound','[OUTBOUND]','trigger:browser:url','/crm/EntityInfo.do?module=Calls&id=','lastevent','toUpperCase','The\x20User\x20ID\x20is:','calleridnum','lodash','request-promise','md5','util','./util','moment','bluebird','../../../../config/environment','zoho','defaults','localhost','socket.io-emitter','redis','emit','[HTTP]','stringify','forEach','string','picklist','type','idField','variable','variableName','toString','Variable','name','toLowerCase','indexOf','split','isNil','access_token','isBefore','expires_in','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','POST','refreshToken','clientId','clientSecret'];(function(_0x545712,_0x5cb4da){var _0xb4bd69=function(_0x1dae3d){while(--_0x1dae3d){_0x545712['push'](_0x545712['shift']());}};_0xb4bd69(++_0x5cb4da);}(_0x3b43,0x71));var _0x33b4=function(_0x45a8e6,_0x3b7119){_0x45a8e6=_0x45a8e6-0x0;var _0x4ff90e=_0x3b43[_0x45a8e6];return _0x4ff90e;};'use strict';var _=require(_0x33b4('0x0'));var rp=require(_0x33b4('0x1'));var md5=require(_0x33b4('0x2'));var util=require(_0x33b4('0x3'));var intUtil=require(_0x33b4('0x4'));var moment=require(_0x33b4('0x5'));var Redis=require('ioredis');var BPromise=require(_0x33b4('0x6'));var config=require(_0x33b4('0x7'));var logger=require('../../../../config/logger')(_0x33b4('0x8'));config['redis']=_[_0x33b4('0x9')](config['redis'],{'host':_0x33b4('0xa'),'port':0x18eb});var io=require(_0x33b4('0xb'))(new Redis(config[_0x33b4('0xc')]));function emit(_0x2ca486,_0x15f06e,_0x1e616b){io['to'](_0x2ca486)[_0x33b4('0xd')](_0x15f06e,_0x1e616b);}function request(_0x3b743e){logger['debug'](_0x33b4('0xe'),JSON[_0x33b4('0xf')](_0x3b743e));return rp(_0x3b743e);}function getCustomFields(_0x11105d,_0x6b05ae){var _0x5568cc={};if(_0x11105d['length']>0x0){_[_0x33b4('0x10')](_0x11105d,function(_0x4ed59b){if(_['includes']([_0x33b4('0x11'),_0x33b4('0x12')],_0x4ed59b[_0x33b4('0x13')])&&_0x4ed59b[_0x33b4('0x14')]){_0x5568cc[_0x4ed59b[_0x33b4('0x14')]]=_0x4ed59b['content']['toString']();}else if(_0x4ed59b[_0x33b4('0x13')]===_0x33b4('0x15')&&_0x4ed59b['variableName']&&_0x4ed59b[_0x33b4('0x14')]&&_0x6b05ae[_0x4ed59b[_0x33b4('0x16')]]){_0x5568cc[_0x4ed59b[_0x33b4('0x14')]]=_0x6b05ae[_0x4ed59b['variableName']][_0x33b4('0x17')]();}else if(_0x4ed59b['type']==='customVariable'&&_0x4ed59b[_0x33b4('0x18')]&&_0x4ed59b[_0x33b4('0x18')]['name']&&_0x4ed59b[_0x33b4('0x14')]&&_0x6b05ae[_0x4ed59b['Variable'][_0x33b4('0x19')][_0x33b4('0x1a')]()]){_0x5568cc[_0x4ed59b[_0x33b4('0x14')]]=_0x6b05ae[_0x4ed59b[_0x33b4('0x18')][_0x33b4('0x19')][_0x33b4('0x1a')]()][_0x33b4('0x17')]();}});}return _0x5568cc;}function getName(_0x1b356f){if(_0x1b356f[_0x33b4('0x1b')]('\x20')>0x0){var _0x3142b3=_0x1b356f[_0x33b4('0x1c')](/ (.+)/);if(_0x3142b3[0x1]){return _0x3142b3;}}return[_0x1b356f,_0x1b356f];}var accountsTokens={};function getAccessToken(_0x49220b){return new Promise(function(_0x24df08,_0x248949){if(!_[_0x33b4('0x1d')](accountsTokens[_0x49220b['id']])&&!_['isNil'](accountsTokens[_0x49220b['id']][_0x33b4('0x1e')])){if(moment()[_0x33b4('0x1f')](accountsTokens[_0x49220b['id']][_0x33b4('0x20')])){_0x24df08(accountsTokens[_0x49220b['id']]['access_token']);}}var _0x22c2d2;switch(_0x49220b['zone']){case'US':_0x22c2d2=_0x33b4('0x21');break;case'AU':_0x22c2d2=_0x33b4('0x22');break;case'EU':_0x22c2d2=_0x33b4('0x23');break;case'IN':_0x22c2d2=_0x33b4('0x24');break;case'CN':_0x22c2d2='https://accounts.zoho.com.cn';break;default:_0x22c2d2=_0x33b4('0x23');break;}var _0x1a005c={'method':_0x33b4('0x25'),'uri':_0x22c2d2+'/oauth/v2/token','qs':{'refresh_token':_0x49220b[_0x33b4('0x26')],'client_id':_0x49220b[_0x33b4('0x27')],'client_secret':_0x49220b[_0x33b4('0x28')],'grant_type':_0x33b4('0x29')},'json':!![]};return rp(_0x1a005c)[_0x33b4('0x2a')](function(_0x33bff0){accountsTokens[_0x49220b['id']]={'access_token':_0x33bff0[_0x33b4('0x1e')],'expires_in':moment()[_0x33b4('0x2b')](_0x33bff0[_0x33b4('0x20')],'seconds')};_0x24df08(_0x33bff0[_0x33b4('0x1e')]);})[_0x33b4('0x2c')](function(_0x1ab3d4){logger['error']('Failing\x20creating\x20the\x20access_token',_0x1ab3d4['stack']);_0x248949(_0x1ab3d4);});});}function getUser(_0x3e0b8e,_0xf1e1c6,_0x1ebb5e,_0x560437){logger['info'](_0x33b4('0x2d'));return request({'method':_0x33b4('0x2e'),'uri':util[_0x33b4('0x2f')](_0x33b4('0x30'),_0xf1e1c6),'qs':{'type':_0x33b4('0x31')},'headers':{'Authorization':_0x33b4('0x32')+_0x3e0b8e},'json':!![]})['then'](function(_0x3f4e10){if(_0x3f4e10['users']){var _0x110e56=-0x1;if(_[_0x33b4('0x33')](_0x3f4e10['users'])){if(!_[_0x33b4('0x1d')](_0x560437)){_0x110e56=_[_0x33b4('0x34')](_0x3f4e10[_0x33b4('0x35')],function(_0x81146e){return _0x81146e['email']===_0x560437;});}if(_0x110e56>=0x0){logger[_0x33b4('0x36')](_0x33b4('0x37'));}else{logger[_0x33b4('0x36')](_0x33b4('0x38'));_0x110e56=_[_0x33b4('0x34')](_0x3f4e10[_0x33b4('0x35')],function(_0x42daf7){return _0x42daf7[_0x33b4('0x39')][_0x33b4('0x19')]===_0x33b4('0x3a');});}return _0x3f4e10[_0x33b4('0x35')][_0x110e56];}else{if(_0x3f4e10[_0x33b4('0x3b')][_0x33b4('0x39')][_0x33b4('0x19')]==='Administrator'){logger[_0x33b4('0x36')]('Using\x20the\x20admin\x20account!');user=_0x3f4e10[_0x33b4('0x3b')];return user;}else{logger[_0x33b4('0x3c')](_0x33b4('0x3d'),JSON['stringify'](_0x3f4e10));throw new Error(_0x33b4('0x3e')+JSON[_0x33b4('0xf')](_0x3f4e10));}}}else{logger[_0x33b4('0x3c')](_0x33b4('0x3d'),JSON[_0x33b4('0xf')](_0x3f4e10));throw new Error(_0x33b4('0x3e')+JSON['stringify'](_0x3f4e10));}})[_0x33b4('0x2c')](function(_0x36d96a){console[_0x33b4('0x3c')](_0x36d96a);});}function getZohoUser(_0x5dad76,_0x17c78){return new BPromise(function(_0x13143b,_0x29e4d1){request(_0x5dad76)['then'](function(_0x564a9f){var _0x332733=null;if(_0x564a9f){_0x332733=_0x564a9f[_0x33b4('0x3f')][0x0];_0x332733['enduserType']=_0x17c78;}_0x13143b(_0x332733);})[_0x33b4('0x2c')](function(_0x3700b8){_0x29e4d1(_0x3700b8);});});}function createEndUser(_0x2bef15,_0x373c61,_0x3d77c9,_0x3e13ef,_0x318584,_0x48d77f){var _0x3d77c9=getName(_0x3d77c9);return request({'method':_0x33b4('0x25'),'uri':_0x33b4('0x40')+_0x373c61+_0x33b4('0x41')+_[_0x33b4('0x42')](_0x48d77f['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x3d77c9[0x1],'First_Name':_0x3d77c9[0x0],'Phone':_0x3e13ef,'Owner':{'name':!_[_0x33b4('0x1d')](_0x318584[_0x33b4('0x43')]['name'])?_0x318584[_0x33b4('0x43')][_0x33b4('0x19')]:!_[_0x33b4('0x1d')](_0x318584[_0x33b4('0x44')])?_0x318584[_0x33b4('0x44')]+'\x20'+_0x318584[_0x33b4('0x45')]:_0x318584[_0x33b4('0x45')],'id':_0x318584['id']}}]},'headers':{'Authorization':_0x33b4('0x32')+_0x2bef15},'json':!![]})['then'](function(_0x3b5122){if(_0x3b5122&&_0x3b5122[_0x33b4('0x3f')][0x0][_0x33b4('0x46')]==='SUCCESS'){var _0x1bab1f=_0x3b5122[_0x33b4('0x3f')][0x0][_0x33b4('0x47')];_0x1bab1f['enduserType']=_[_0x33b4('0x42')](_0x48d77f['moduleCreate'])+'s';return _0x1bab1f;}logger[_0x33b4('0x3c')](_0x33b4('0x3d'),JSON['stringify'](data));throw new Error(_0x33b4('0x48')+JSON[_0x33b4('0xf')](data));})['catch'](function(_0x555cf8){console[_0x33b4('0x49')]('CREATE\x20ERROR',_0x555cf8);});}function getEndUser(_0x806980,_0x32855a,_0x497a5a,_0x335674,_0x2126da,_0x547707,_0x36d913){var _0xa18ca6={'method':'GET','uri':'','headers':{'Authorization':_0x33b4('0x32')+_0x806980},'json':!![]};switch(_0x36d913[_0x33b4('0x4a')]){case'contact_lead':_0xa18ca6[_0x33b4('0x4b')]='https://www.zohoapis.'+_0x32855a+_0x33b4('0x4c')+_0x2126da+'))';return getZohoUser(_0xa18ca6,_0x33b4('0x4d'))[_0x33b4('0x2a')](function(_0x24394a){if(_0x24394a)return _0x24394a;_0xa18ca6[_0x33b4('0x4b')]=_0x33b4('0x40')+_0x32855a+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x2126da+'))';return getZohoUser(_0xa18ca6,'Leads')['then'](function(_0x2c68f7){if(_0x2c68f7)return _0x2c68f7;if(_0x36d913[_0x33b4('0x4e')]!=_0x33b4('0x4f')){return createEndUser(_0x806980,_0x32855a,_0x335674,_0x2126da,_0x547707,_0x36d913);}else{return{};}});});break;case _0x33b4('0x50'):_0xa18ca6[_0x33b4('0x4b')]='https://www.zohoapis.'+_0x32855a+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x2126da+'))';return getZohoUser(_0xa18ca6,_0x33b4('0x4d'))['then'](function(_0x5bf802){if(_0x5bf802)return _0x5bf802;if(_0x36d913[_0x33b4('0x4e')]!='nothing'){return createEndUser(_0x806980,_0x32855a,_0x335674,_0x2126da,_0x547707,_0x36d913);}else{return{};}});break;case _0x33b4('0x51'):_0xa18ca6[_0x33b4('0x4b')]='https://www.zohoapis.'+_0x32855a+_0x33b4('0x52')+_0x2126da+'))';return getZohoUser(_0xa18ca6,'Leads')[_0x33b4('0x2a')](function(_0x1016aa){if(_0x1016aa)return _0x1016aa;if(_0x36d913['moduleCreate']!='nothing'){return createEndUser(_0x806980,_0x32855a,_0x335674,_0x2126da,_0x547707,_0x36d913);}else{return{};}});break;}}function getCall(_0x555894,_0x40f90a,_0x55b7fd,_0x47d190,_0x28d7c0,_0x18c35f,_0x1c3a09,_0x6483cc){logger[_0x33b4('0x36')](_0x33b4('0x53'));var _0x47e9f1={};_0x47e9f1[_0x33b4('0x54')]={'name':!_['isNil'](_0x47d190[_0x33b4('0x43')][_0x33b4('0x19')])&&!_['isNil'](_0x47d190[_0x33b4('0x39')][_0x33b4('0x19')])&&_0x47d190[_0x33b4('0x39')][_0x33b4('0x19')]===_0x33b4('0x55')?_0x47d190[_0x33b4('0x43')]['name']:!_['isNil'](_0x47d190['first_name'])?_0x47d190[_0x33b4('0x44')]+'\x20'+_0x47d190[_0x33b4('0x45')]:_0x47d190[_0x33b4('0x45')],'id':_0x47d190['id']};_0x47e9f1['Subject']=intUtil[_0x33b4('0x56')](_0x18c35f[_0x33b4('0x57')],_0x1c3a09,'\x20');_0x47e9f1[_0x33b4('0x58')]=intUtil[_0x33b4('0x56')](_0x18c35f[_0x33b4('0x59')],_0x1c3a09,'\x0a');if(_0x28d7c0[_0x33b4('0x5a')]===_0x33b4('0x4d')){_0x47e9f1[_0x33b4('0x5b')]={'name':!_[_0x33b4('0x1d')](_0x28d7c0[_0x33b4('0x5c')])?_0x28d7c0['Full_Name']:!_[_0x33b4('0x1d')](_0x28d7c0[_0x33b4('0x5d')])?_0x28d7c0[_0x33b4('0x5d')]+'\x20'+_0x28d7c0[_0x33b4('0x5e')]:_0x28d7c0[_0x33b4('0x5e')],'id':_0x28d7c0['id']};}if(_0x28d7c0['enduserType']===_0x33b4('0x5f')){_0x47e9f1['What_Id']={'name':!_[_0x33b4('0x1d')](_0x28d7c0[_0x33b4('0x5c')])?_0x28d7c0['Full_Name']:!_['isNil'](_0x28d7c0[_0x33b4('0x5d')])?_0x28d7c0[_0x33b4('0x5d')]+'\x20'+_0x28d7c0[_0x33b4('0x5e')]:_0x28d7c0['Last_Name'],'id':_0x28d7c0['id']};_0x47e9f1[_0x33b4('0x60')]=_[_0x33b4('0x42')](_0x28d7c0[_0x33b4('0x5a')]);}if(_0x1c3a09['talktime']){_0x47e9f1[_0x33b4('0x61')]=moment[_0x33b4('0x62')](parseInt(_0x1c3a09[_0x33b4('0x63')])*0x3e8)['format'](_0x33b4('0x64'));}else if(_0x1c3a09[_0x33b4('0x65')]&&_0x1c3a09[_0x33b4('0x66')]){_0x47e9f1[_0x33b4('0x61')]=moment[_0x33b4('0x62')](moment(_0x1c3a09[_0x33b4('0x66')],_0x33b4('0x67'))[_0x33b4('0x68')](moment(_0x1c3a09[_0x33b4('0x69')],_0x33b4('0x67'))))[_0x33b4('0x2f')](_0x33b4('0x64'));}switch(_0x1c3a09['lastevent']){case _0x33b4('0x6a'):_0x47e9f1[_0x33b4('0x6b')]='Called';break;case'complete':case'connect':_0x47e9f1[_0x33b4('0x6b')]=_0x33b4('0x6c');break;case _0x33b4('0x6d'):_0x47e9f1[_0x33b4('0x6b')]=_0x33b4('0x6e');break;case _0x33b4('0x6f'):_0x47e9f1[_0x33b4('0x6b')]=_0x33b4('0x70');break;case'timeout':_0x47e9f1[_0x33b4('0x6b')]=_0x33b4('0x71');default:}_0x47e9f1[_0x33b4('0x72')]=(_0x6483cc===_0x33b4('0x73')?moment(_0x1c3a09[_0x33b4('0x69')])[_0x33b4('0x2f')](_0x33b4('0x67')):moment(_0x1c3a09['agentcalledAt'])['format'](_0x33b4('0x67')))||moment()[_0x33b4('0x2f')](_0x33b4('0x67'));_0x47e9f1[_0x33b4('0x74')]=_0x6483cc||_0x33b4('0x75');_0x47e9f1=_['merge'](_0x47e9f1,getCustomFields(_0x18c35f[_0x33b4('0x76')],_0x1c3a09));return request({'method':'POST','uri':'https://www.zohoapis.'+_0x40f90a+_0x33b4('0x77'),'headers':{'Authorization':_0x33b4('0x32')+_0x555894},'body':{'data':[_0x47e9f1]},'json':!![]})['then'](function(_0x48864d){if(_0x48864d&&_0x48864d[_0x33b4('0x3f')][0x0][_0x33b4('0x46')]===_0x33b4('0x78')){logger[_0x33b4('0x36')](_0x33b4('0x79'));return{'id':_0x48864d[_0x33b4('0x3f')][0x0][_0x33b4('0x47')]['id']};}})['catch'](function(_0x5e423a){logger['info'](_0x33b4('0x7a'),_0x5e423a[_0x33b4('0x7b')]);console[_0x33b4('0x49')](_0x33b4('0x7a'),_0x5e423a);});}exports[_0x33b4('0x7c')]=function(_0x107023,_0xa46eef,_0x309d6a,_0x103c92,_0x2f964e,_0x3829b1){var _0x1350f9,_0x7dbf50,_0x2445d7;_0x3829b1[_0x33b4('0x7d')]=intUtil[_0x33b4('0x7e')](_0x3829b1[_0x33b4('0x7d')]);_0x3829b1[_0x33b4('0x7f')]=intUtil[_0x33b4('0x7e')](_0x3829b1[_0x33b4('0x7f')]);if(_0x2f964e&&_0x2f964e[_0x33b4('0x80')]){logger[_0x33b4('0x36')](_0x33b4('0x81'),_0x33b4('0x82'));_0xa46eef[_0x33b4('0x83')]=_0x3829b1[_0x33b4('0x7f')]+_0x33b4('0x84')+_0xa46eef['uniqueid']+_0x33b4('0x85')+md5(_0xa46eef[_0x33b4('0x86')]);}else{_0xa46eef[_0x33b4('0x83')]='';}var _0x2b8fbf=_0x3829b1[_0x33b4('0x7d')]===_0x33b4('0x87')?'eu':_0x33b4('0x88');return getAccessToken(_0x3829b1)[_0x33b4('0x2a')](function(_0x446116){_0x2445d7=_0x446116;return getUser(_0x2445d7,_0x2b8fbf,_0x3829b1,_0x103c92[_0x33b4('0x89')]);})[_0x33b4('0x2a')](function(_0x4d9fdc){_0x1350f9=_0x4d9fdc;logger[_0x33b4('0x36')]('The\x20User\x20ID\x20is:',_0x1350f9['id']);return getEndUser(_0x2445d7,_0x2b8fbf,_0x3829b1,_0xa46eef[_0x33b4('0x8a')],_0xa46eef['calleridnum'],_0x1350f9,_0x309d6a);})[_0x33b4('0x2a')](function(_0x579e6b){_0x7dbf50=_0x579e6b;return getCall(_0x2445d7,_0x2b8fbf,_0x3829b1,_0x1350f9,_0x7dbf50,_0x309d6a,_0xa46eef,'Inbound');})['then'](function(_0x1844cd){if(_0x1844cd){logger[_0x33b4('0x36')](_0x33b4('0x8b'),_0x1844cd['id']);logger[_0x33b4('0x36')](_0x33b4('0x81'),_0x33b4('0x8c'));emit(util[_0x33b4('0x2f')](_0x33b4('0x8d'),_0x103c92[_0x33b4('0x19')]),'trigger:browser:url',{'uri':_0x33b4('0x8e')+_0x3829b1[_0x33b4('0x7d')]+'/crm/EntityInfo.do?module=Calls&id='+_0x1844cd['id']});}})['catch'](function(_0x5cb308){logger[_0x33b4('0x3c')](_0x33b4('0x81'),JSON[_0x33b4('0xf')](_0x5cb308));});};exports['outbound']=function(_0x58f877,_0x32c6fd,_0x2fbc68,_0x548d94,_0x20faa3,_0x10a2d0,_0x59213b){var _0x20bce6,_0x6758b8,_0x4087ba;_0x10a2d0['host']=intUtil[_0x33b4('0x7e')](_0x10a2d0[_0x33b4('0x7d')]);_0x10a2d0[_0x33b4('0x7f')]=intUtil[_0x33b4('0x7e')](_0x10a2d0['serverUrl']);if(_0x59213b&&_0x59213b[_0x33b4('0x8f')]&&_0x59213b[_0x33b4('0x8f')]!=='none'){logger[_0x33b4('0x36')]('[OUTBOUND]',_0x33b4('0x82'));_0x32c6fd[_0x33b4('0x83')]=_0x10a2d0[_0x33b4('0x7f')]+_0x33b4('0x84')+_0x32c6fd[_0x33b4('0x86')]+_0x33b4('0x85')+md5(_0x32c6fd['uniqueid']);}var _0x3bd1c0=_0x10a2d0[_0x33b4('0x7d')]===_0x33b4('0x87')?'eu':_0x33b4('0x88');return getAccessToken(_0x10a2d0)[_0x33b4('0x2a')](function(_0x457e78){_0x4087ba=_0x457e78;return getUser(_0x4087ba,_0x3bd1c0,_0x10a2d0,_0x548d94[_0x33b4('0x89')]);})[_0x33b4('0x2a')](function(_0x21dc5d){_0x20bce6=_0x21dc5d;logger[_0x33b4('0x36')]('The\x20User\x20ID\x20is:',_0x20bce6['id']);return getEndUser(_0x4087ba,_0x3bd1c0,_0x10a2d0,_0x32c6fd[_0x33b4('0x90')],_0x32c6fd[_0x33b4('0x91')],_0x20bce6,_0x2fbc68);})[_0x33b4('0x2a')](function(_0x31c0bb){_0x6758b8=_0x31c0bb;return getCall(_0x4087ba,_0x3bd1c0,_0x10a2d0,_0x20bce6,_0x6758b8,_0x2fbc68,_0x32c6fd,_0x33b4('0x92'));})[_0x33b4('0x2a')](function(_0x53fd4f){if(_0x53fd4f){logger[_0x33b4('0x36')](_0x33b4('0x8b'),_0x53fd4f['id']);logger['info'](_0x33b4('0x93'),_0x33b4('0x8c'));emit(util[_0x33b4('0x2f')]('user:%s',_0x548d94[_0x33b4('0x19')]),_0x33b4('0x94'),{'uri':_0x33b4('0x8e')+_0x10a2d0['host']+_0x33b4('0x95')+_0x53fd4f['id']});}})['catch'](function(_0xf2a49e){logger[_0x33b4('0x3c')](_0x33b4('0x93'),JSON['stringify'](_0xf2a49e));});};exports['unmanaged']=function(_0x8ed985,_0x1af8cf,_0x466551,_0x1be726,_0xad391f,_0x4a9a99){var _0xcd1eed,_0x294250,_0xfb4cc6;_0x4a9a99[_0x33b4('0x7d')]=intUtil[_0x33b4('0x7e')](_0x4a9a99[_0x33b4('0x7d')]);_0x4a9a99[_0x33b4('0x7f')]=intUtil[_0x33b4('0x7e')](_0x4a9a99[_0x33b4('0x7f')]);if(_0xad391f&&_0xad391f['monitor_format']){logger[_0x33b4('0x36')]('['+_0x1af8cf[_0x33b4('0x96')][_0x33b4('0x97')]()+']',_0x33b4('0x82'));_0x1af8cf[_0x33b4('0x83')]=_0x4a9a99['serverUrl']+_0x33b4('0x84')+_0x1af8cf[_0x33b4('0x86')]+_0x33b4('0x85')+md5(_0x1af8cf['uniqueid']);}else{_0x1af8cf[_0x33b4('0x83')]='';}var _0xd30942=_0x4a9a99[_0x33b4('0x7d')]===_0x33b4('0x87')?'eu':_0x33b4('0x88');return getAccessToken(_0x4a9a99)[_0x33b4('0x2a')](function(_0x26cd89){_0xfb4cc6=_0x26cd89;return getUser(_0xfb4cc6,_0xd30942,_0x4a9a99);})[_0x33b4('0x2a')](function(_0x146fa1){_0xcd1eed=_0x146fa1;logger['info'](_0x33b4('0x98'),_0xcd1eed['id']);return getEndUser(_0xfb4cc6,_0xd30942,_0x4a9a99,_0x1af8cf[_0x33b4('0x8a')],_0x1af8cf[_0x33b4('0x99')],_0xcd1eed,_0x466551);})[_0x33b4('0x2a')](function(_0x28650b){_0x294250=_0x28650b;return getCall(_0xfb4cc6,_0xd30942,_0x4a9a99,_0xcd1eed,_0x294250,_0x466551,_0x1af8cf,'Inbound');})[_0x33b4('0x2a')](function(_0x500561){if(_0x500561){logger['info'](_0x33b4('0x8b'),_0x500561['id']);}})[_0x33b4('0x2c')](function(_0x5dd026){logger[_0x33b4('0x3c')]('['+_0x1af8cf[_0x33b4('0x96')][_0x33b4('0x97')]()+']',JSON[_0x33b4('0xf')](_0x5dd026));});};