5c0eeb25aa3f8706bc9c0c7e2e6b4ca8e85b0f8d
[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 _0xf793=['Variable','name','toLowerCase','split','isNil','isBefore','expires_in','zone','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.com.cn','POST','/oauth/v2/token','clientSecret','refresh_token','access_token','add','seconds','catch','error','stack','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','then','users','isArrayLikeObject','findIndex','email','info','Agent\x20found!','Using\x20the\x20admin\x20account!','Administrator','profile','user','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','enduserType','https://www.zohoapis.','/crm/v2/','role','last_name','data','code','SUCCESS','startCase','log','CREATE\x20ERROR','moduleSearch','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','Leads','moduleCreate','nothing','contact','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','Owner','administrator','first_name','Subject','getString','Subjects','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','What_Id','talktime','utc','endtime','Call_Duration','YYYY-MM-DDTHH:mm:ss','starttime','mm:ss','lastevent','called','Call_Result','Called','connect','Answered','rejected','Rejected','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','Inbound','Fields','/crm/v2/Calls','Call\x20created!','details','err','host','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','/downloads?type=uniqueid&token=','uniqueid','com','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Call\x20ID\x20is:','[QUEUE]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','https://crm.','none','[OUTBOUND]','recordingURL','/api/voice/recordings/','destcalleridname','Outbound','/crm/EntityInfo.do?module=Calls&id=','unmanaged','toUpperCase','zoho.eu','request-promise','./util','moment','ioredis','bluebird','../../../../config/environment','../../../../config/logger','zoho','redis','defaults','emit','debug','[HTTP]','stringify','length','forEach','type','idField','content','toString','variable','variableName'];(function(_0x2e6d36,_0xd9726e){var _0x1612f4=function(_0x2cad69){while(--_0x2cad69){_0x2e6d36['push'](_0x2e6d36['shift']());}};_0x1612f4(++_0xd9726e);}(_0xf793,0x1ac));var _0x3f79=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xf793[_0x321bb2];return _0x9c12ed;};'use strict';var _=require('lodash');var rp=require(_0x3f79('0x0'));var md5=require('md5');var util=require('util');var intUtil=require(_0x3f79('0x1'));var moment=require(_0x3f79('0x2'));var Redis=require(_0x3f79('0x3'));var BPromise=require(_0x3f79('0x4'));var config=require(_0x3f79('0x5'));var logger=require(_0x3f79('0x6'))(_0x3f79('0x7'));config[_0x3f79('0x8')]=_[_0x3f79('0x9')](config[_0x3f79('0x8')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function emit(_0x5f4ddc,_0x5d64d8,_0x244e6d){io['to'](_0x5f4ddc)[_0x3f79('0xa')](_0x5d64d8,_0x244e6d);}function request(_0x1bbf9f){logger[_0x3f79('0xb')](_0x3f79('0xc'),JSON[_0x3f79('0xd')](_0x1bbf9f));return rp(_0x1bbf9f);}function getCustomFields(_0xf97932,_0x2f0c1f){var _0x1fb280={};if(_0xf97932[_0x3f79('0xe')]>0x0){_[_0x3f79('0xf')](_0xf97932,function(_0x520c87){if(_0x520c87[_0x3f79('0x10')]==='string'&&_0x520c87[_0x3f79('0x11')]){_0x1fb280[_0x520c87[_0x3f79('0x11')]]=_0x520c87[_0x3f79('0x12')][_0x3f79('0x13')]();}else if(_0x520c87[_0x3f79('0x10')]===_0x3f79('0x14')&&_0x520c87[_0x3f79('0x15')]&&_0x520c87['idField']&&_0x2f0c1f[_0x520c87[_0x3f79('0x15')]]){_0x1fb280[_0x520c87[_0x3f79('0x11')]]=_0x2f0c1f[_0x520c87['variableName']]['toString']();}else if(_0x520c87[_0x3f79('0x10')]==='customVariable'&&_0x520c87[_0x3f79('0x16')]&&_0x520c87[_0x3f79('0x16')][_0x3f79('0x17')]&&_0x520c87['idField']&&_0x2f0c1f[_0x520c87[_0x3f79('0x16')]['name'][_0x3f79('0x18')]()]){_0x1fb280[_0x520c87[_0x3f79('0x11')]]=_0x2f0c1f[_0x520c87['Variable'][_0x3f79('0x17')]['toLowerCase']()]['toString']();}});}return _0x1fb280;}function getName(_0xa19ada){if(_0xa19ada['indexOf']('\x20')>0x0){var _0x337766=_0xa19ada[_0x3f79('0x19')](/ (.+)/);if(_0x337766[0x1]){return _0x337766;}}return[_0xa19ada,_0xa19ada];}var accountsTokens={};function getAccessToken(_0x1c9ccf){return new Promise(function(_0xf26e0e,_0x2f421c){if(!_['isNil'](accountsTokens[_0x1c9ccf['id']])&&!_[_0x3f79('0x1a')](accountsTokens[_0x1c9ccf['id']]['access_token'])){if(moment()[_0x3f79('0x1b')](accountsTokens[_0x1c9ccf['id']][_0x3f79('0x1c')])){_0xf26e0e(accountsTokens[_0x1c9ccf['id']]['access_token']);}}var _0x2cd3f4;switch(_0x1c9ccf[_0x3f79('0x1d')]){case'US':_0x2cd3f4='https://accounts.zoho.com';break;case'AU':_0x2cd3f4=_0x3f79('0x1e');break;case'EU':_0x2cd3f4=_0x3f79('0x1f');break;case'IN':_0x2cd3f4='https://accounts.zoho.in';break;case'CN':_0x2cd3f4=_0x3f79('0x20');break;default:_0x2cd3f4=_0x3f79('0x1f');break;}var _0x276f98={'method':_0x3f79('0x21'),'uri':_0x2cd3f4+_0x3f79('0x22'),'qs':{'refresh_token':_0x1c9ccf['refreshToken'],'client_id':_0x1c9ccf['clientId'],'client_secret':_0x1c9ccf[_0x3f79('0x23')],'grant_type':_0x3f79('0x24')},'json':!![]};return rp(_0x276f98)['then'](function(_0x170417){accountsTokens[_0x1c9ccf['id']]={'access_token':_0x170417[_0x3f79('0x25')],'expires_in':moment()[_0x3f79('0x26')](_0x170417[_0x3f79('0x1c')],_0x3f79('0x27'))};_0xf26e0e(_0x170417[_0x3f79('0x25')]);})[_0x3f79('0x28')](function(_0x9e561d){logger[_0x3f79('0x29')]('Failing\x20creating\x20the\x20access_token',_0x9e561d[_0x3f79('0x2a')]);_0x2f421c(_0x9e561d);});});}function getUser(_0x230988,_0x20db03,_0xd47ba0,_0x39b9ad){logger['info']('Search\x20user');return request({'method':_0x3f79('0x2b'),'uri':util[_0x3f79('0x2c')](_0x3f79('0x2d'),_0x20db03),'qs':{'type':_0x3f79('0x2e')},'headers':{'Authorization':_0x3f79('0x2f')+_0x230988},'json':!![]})[_0x3f79('0x30')](function(_0x1570da){if(_0x1570da[_0x3f79('0x31')]){var _0x4d5cfc=-0x1;if(_[_0x3f79('0x32')](_0x1570da[_0x3f79('0x31')])){if(!_[_0x3f79('0x1a')](_0x39b9ad)){_0x4d5cfc=_[_0x3f79('0x33')](_0x1570da[_0x3f79('0x31')],function(_0x592870){return _0x592870[_0x3f79('0x34')]===_0x39b9ad;});}if(_0x4d5cfc>=0x0){logger[_0x3f79('0x35')](_0x3f79('0x36'));}else{logger[_0x3f79('0x35')](_0x3f79('0x37'));_0x4d5cfc=_['findIndex'](_0x1570da[_0x3f79('0x31')],function(_0x33248c){return _0x33248c['profile'][_0x3f79('0x17')]===_0x3f79('0x38');});}return _0x1570da[_0x3f79('0x31')][_0x4d5cfc];}else{if(_0x1570da['user'][_0x3f79('0x39')]['name']===_0x3f79('0x38')){logger['info'](_0x3f79('0x37'));user=_0x1570da[_0x3f79('0x3a')];return user;}else{logger[_0x3f79('0x29')](_0x3f79('0x3b'),JSON[_0x3f79('0xd')](_0x1570da));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0x3f79('0xd')](_0x1570da));}}}else{logger[_0x3f79('0x29')](_0x3f79('0x3b'),JSON[_0x3f79('0xd')](_0x1570da));throw new Error(_0x3f79('0x3c')+JSON[_0x3f79('0xd')](_0x1570da));}})['catch'](function(_0x174ebb){console[_0x3f79('0x29')](_0x174ebb);});}function getZohoUser(_0x5f35c4,_0x561c81){return new BPromise(function(_0x1e71df,_0xb56ce9){request(_0x5f35c4)[_0x3f79('0x30')](function(_0x4d70a8){var _0x56d36b=null;if(_0x4d70a8){_0x56d36b=_0x4d70a8['data'][0x0];_0x56d36b[_0x3f79('0x3d')]=_0x561c81;}_0x1e71df(_0x56d36b);})[_0x3f79('0x28')](function(_0x4af77e){_0xb56ce9(_0x4af77e);});});}function createEndUser(_0xe9a580,_0x16739d,_0x352f6d,_0x398cf8,_0x3c9296,_0x3a8a5b){var _0x352f6d=getName(_0x352f6d);return request({'method':_0x3f79('0x21'),'uri':_0x3f79('0x3e')+_0x16739d+_0x3f79('0x3f')+_['startCase'](_0x3a8a5b['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x352f6d[0x1],'First_Name':_0x352f6d[0x0],'Phone':_0x398cf8,'Owner':{'name':!_[_0x3f79('0x1a')](_0x3c9296[_0x3f79('0x40')][_0x3f79('0x17')])?_0x3c9296['role'][_0x3f79('0x17')]:!_[_0x3f79('0x1a')](_0x3c9296['first_name'])?_0x3c9296['first_name']+'\x20'+_0x3c9296[_0x3f79('0x41')]:_0x3c9296['last_name'],'id':_0x3c9296['id']}}]},'headers':{'Authorization':_0x3f79('0x2f')+_0xe9a580},'json':!![]})[_0x3f79('0x30')](function(_0x1fdd15){if(_0x1fdd15&&_0x1fdd15[_0x3f79('0x42')][0x0][_0x3f79('0x43')]===_0x3f79('0x44')){var _0x1a4f60=_0x1fdd15[_0x3f79('0x42')][0x0]['details'];_0x1a4f60[_0x3f79('0x3d')]=_[_0x3f79('0x45')](_0x3a8a5b['moduleCreate'])+'s';return _0x1a4f60;}logger['error']('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error('Error:\x20'+JSON[_0x3f79('0xd')](data));})[_0x3f79('0x28')](function(_0x2aa3b6){console[_0x3f79('0x46')](_0x3f79('0x47'),_0x2aa3b6);});}function getEndUser(_0x29ae44,_0x1f4c6b,_0x2031a0,_0x124711,_0xc8338f,_0x3b760c,_0x2972b1){var _0x3d08b0={'method':_0x3f79('0x2b'),'uri':'','headers':{'Authorization':_0x3f79('0x2f')+_0x29ae44},'json':!![]};switch(_0x2972b1[_0x3f79('0x48')]){case'contact_lead':_0x3d08b0[_0x3f79('0x49')]=_0x3f79('0x3e')+_0x1f4c6b+_0x3f79('0x4a')+_0xc8338f+'))';return getZohoUser(_0x3d08b0,_0x3f79('0x4b'))[_0x3f79('0x30')](function(_0x2a48a2){if(_0x2a48a2)return _0x2a48a2;_0x3d08b0[_0x3f79('0x49')]=_0x3f79('0x3e')+_0x1f4c6b+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0xc8338f+'))';return getZohoUser(_0x3d08b0,_0x3f79('0x4c'))['then'](function(_0x6db9ae){if(_0x6db9ae)return _0x6db9ae;if(_0x2972b1[_0x3f79('0x4d')]!=_0x3f79('0x4e')){return createEndUser(_0x29ae44,_0x1f4c6b,_0x124711,_0xc8338f,_0x3b760c,_0x2972b1);}else{return{};}});});break;case _0x3f79('0x4f'):_0x3d08b0[_0x3f79('0x49')]=_0x3f79('0x3e')+_0x1f4c6b+_0x3f79('0x4a')+_0xc8338f+'))';return getZohoUser(_0x3d08b0,_0x3f79('0x4b'))[_0x3f79('0x30')](function(_0x4c7695){if(_0x4c7695)return _0x4c7695;if(_0x2972b1[_0x3f79('0x4d')]!='nothing'){return createEndUser(_0x29ae44,_0x1f4c6b,_0x124711,_0xc8338f,_0x3b760c,_0x2972b1);}else{return{};}});break;case _0x3f79('0x50'):_0x3d08b0[_0x3f79('0x49')]=_0x3f79('0x3e')+_0x1f4c6b+_0x3f79('0x51')+_0xc8338f+'))';return getZohoUser(_0x3d08b0,_0x3f79('0x4c'))[_0x3f79('0x30')](function(_0x140d01){if(_0x140d01)return _0x140d01;if(_0x2972b1[_0x3f79('0x4d')]!=_0x3f79('0x4e')){return createEndUser(_0x29ae44,_0x1f4c6b,_0x124711,_0xc8338f,_0x3b760c,_0x2972b1);}else{return{};}});break;}}function getCall(_0x4169a3,_0x472666,_0xd280ab,_0x52e36e,_0x160586,_0x34d2d8,_0x168e96,_0x380d50){logger[_0x3f79('0x35')]('Creating\x20new\x20call...');var _0x10e323={};_0x10e323[_0x3f79('0x52')]={'name':!_[_0x3f79('0x1a')](_0x52e36e[_0x3f79('0x40')][_0x3f79('0x17')])&&!_[_0x3f79('0x1a')](_0x52e36e[_0x3f79('0x39')]['name'])&&_0x52e36e[_0x3f79('0x39')]['name']===_0x3f79('0x53')?_0x52e36e[_0x3f79('0x40')][_0x3f79('0x17')]:!_[_0x3f79('0x1a')](_0x52e36e['first_name'])?_0x52e36e[_0x3f79('0x54')]+'\x20'+_0x52e36e[_0x3f79('0x41')]:_0x52e36e['last_name'],'id':_0x52e36e['id']};_0x10e323[_0x3f79('0x55')]=intUtil[_0x3f79('0x56')](_0x34d2d8[_0x3f79('0x57')],_0x168e96,'\x20');_0x10e323[_0x3f79('0x58')]=intUtil['getString'](_0x34d2d8[_0x3f79('0x59')],_0x168e96,'\x0a');if(_0x160586['enduserType']==='Contacts'){_0x10e323[_0x3f79('0x5a')]={'name':!_[_0x3f79('0x1a')](_0x160586[_0x3f79('0x5b')])?_0x160586[_0x3f79('0x5b')]:!_[_0x3f79('0x1a')](_0x160586[_0x3f79('0x5c')])?_0x160586[_0x3f79('0x5c')]+'\x20'+_0x160586['Last_Name']:_0x160586[_0x3f79('0x5d')],'id':_0x160586['id']};}if(_0x160586[_0x3f79('0x3d')]===_0x3f79('0x4c')){_0x10e323[_0x3f79('0x5e')]={'name':!_[_0x3f79('0x1a')](_0x160586[_0x3f79('0x5b')])?_0x160586[_0x3f79('0x5b')]:!_[_0x3f79('0x1a')](_0x160586['First_Name'])?_0x160586[_0x3f79('0x5c')]+'\x20'+_0x160586[_0x3f79('0x5d')]:_0x160586[_0x3f79('0x5d')],'id':_0x160586['id']};_0x10e323['$se_module']=_[_0x3f79('0x45')](_0x160586['enduserType']);}if(_0x168e96[_0x3f79('0x5f')]){_0x10e323['Call_Duration']=moment[_0x3f79('0x60')](parseInt(_0x168e96['talktime'])*0x3e8)[_0x3f79('0x2c')]('mm:ss');}else if(_0x168e96['answertime']&&_0x168e96[_0x3f79('0x61')]){_0x10e323[_0x3f79('0x62')]=moment[_0x3f79('0x60')](moment(_0x168e96['endtime'],_0x3f79('0x63'))['diff'](moment(_0x168e96[_0x3f79('0x64')],'YYYY-MM-DDTHH:mm:ss')))[_0x3f79('0x2c')](_0x3f79('0x65'));}switch(_0x168e96[_0x3f79('0x66')]){case _0x3f79('0x67'):_0x10e323[_0x3f79('0x68')]=_0x3f79('0x69');break;case'complete':case _0x3f79('0x6a'):_0x10e323[_0x3f79('0x68')]=_0x3f79('0x6b');break;case _0x3f79('0x6c'):_0x10e323[_0x3f79('0x68')]=_0x3f79('0x6d');break;case _0x3f79('0x6e'):_0x10e323[_0x3f79('0x68')]=_0x3f79('0x6f');break;case _0x3f79('0x70'):_0x10e323[_0x3f79('0x68')]=_0x3f79('0x71');default:}_0x10e323[_0x3f79('0x72')]=(_0x380d50===_0x3f79('0x73')?moment(_0x168e96[_0x3f79('0x64')])[_0x3f79('0x2c')](_0x3f79('0x63')):moment(_0x168e96[_0x3f79('0x74')])[_0x3f79('0x2c')](_0x3f79('0x63')))||moment()[_0x3f79('0x2c')](_0x3f79('0x63'));_0x10e323[_0x3f79('0x75')]=_0x380d50||_0x3f79('0x76');_0x10e323=_['merge'](_0x10e323,getCustomFields(_0x34d2d8[_0x3f79('0x77')],_0x168e96));return request({'method':_0x3f79('0x21'),'uri':'https://www.zohoapis.'+_0x472666+_0x3f79('0x78'),'headers':{'Authorization':_0x3f79('0x2f')+_0x4169a3},'body':{'data':[_0x10e323]},'json':!![]})['then'](function(_0x3f4aa7){if(_0x3f4aa7&&_0x3f4aa7['data'][0x0][_0x3f79('0x43')]===_0x3f79('0x44')){logger['info'](_0x3f79('0x79'));return{'id':_0x3f4aa7['data'][0x0][_0x3f79('0x7a')]['id']};}})[_0x3f79('0x28')](function(_0x17f97c){logger['info'](_0x3f79('0x7b'),_0x17f97c[_0x3f79('0x2a')]);console[_0x3f79('0x46')](_0x3f79('0x7b'),_0x17f97c);});}exports['queue']=function(_0x5e2e7e,_0x22bdbc,_0x421f26,_0x4fd951,_0x2d99cc,_0x132060){var _0x2cecd5,_0x46fd20,_0x41c78e;_0x132060[_0x3f79('0x7c')]=intUtil[_0x3f79('0x7d')](_0x132060['host']);_0x132060[_0x3f79('0x7e')]=intUtil[_0x3f79('0x7d')](_0x132060[_0x3f79('0x7e')]);if(_0x2d99cc&&_0x2d99cc[_0x3f79('0x7f')]){logger[_0x3f79('0x35')]('[QUEUE]',_0x3f79('0x80'));_0x22bdbc['recordingURL']=_0x132060[_0x3f79('0x7e')]+'/api/voice/recordings/'+_0x22bdbc['uniqueid']+_0x3f79('0x81')+md5(_0x22bdbc[_0x3f79('0x82')]);}else{_0x22bdbc['recordingURL']='';}var _0x3fdd56=_0x132060['host']==='zoho.eu'?'eu':_0x3f79('0x83');return getAccessToken(_0x132060)[_0x3f79('0x30')](function(_0x578918){_0x41c78e=_0x578918;return getUser(_0x41c78e,_0x3fdd56,_0x132060,_0x4fd951[_0x3f79('0x34')]);})[_0x3f79('0x30')](function(_0xaa7fec){_0x2cecd5=_0xaa7fec;logger[_0x3f79('0x35')](_0x3f79('0x84'),_0x2cecd5['id']);return getEndUser(_0x41c78e,_0x3fdd56,_0x132060,_0x22bdbc[_0x3f79('0x85')],_0x22bdbc[_0x3f79('0x86')],_0x2cecd5,_0x421f26);})['then'](function(_0x436e4f){_0x46fd20=_0x436e4f;return getCall(_0x41c78e,_0x3fdd56,_0x132060,_0x2cecd5,_0x46fd20,_0x421f26,_0x22bdbc,_0x3f79('0x76'));})[_0x3f79('0x30')](function(_0x4876ce){if(_0x4876ce){logger[_0x3f79('0x35')](_0x3f79('0x87'),_0x4876ce['id']);logger[_0x3f79('0x35')](_0x3f79('0x88'),_0x3f79('0x89'));emit(util[_0x3f79('0x2c')](_0x3f79('0x8a'),_0x4fd951[_0x3f79('0x17')]),'trigger:browser:url',{'uri':_0x3f79('0x8b')+_0x132060[_0x3f79('0x7c')]+'/crm/EntityInfo.do?module=Calls&id='+_0x4876ce['id']});}})[_0x3f79('0x28')](function(_0x3223e0){logger[_0x3f79('0x29')](_0x3f79('0x88'),JSON[_0x3f79('0xd')](_0x3223e0));});};exports[_0x3f79('0x73')]=function(_0x34a043,_0x4a14a0,_0x3af74e,_0x474a9f,_0x3de798,_0x2b9dd5,_0x1768ed){var _0x5cfb80,_0x2a4158,_0x4c52ac;_0x2b9dd5[_0x3f79('0x7c')]=intUtil['stripTrailingSlash'](_0x2b9dd5[_0x3f79('0x7c')]);_0x2b9dd5[_0x3f79('0x7e')]=intUtil[_0x3f79('0x7d')](_0x2b9dd5['serverUrl']);if(_0x1768ed&&_0x1768ed['recordingFormat']&&_0x1768ed['recordingFormat']!==_0x3f79('0x8c')){logger[_0x3f79('0x35')](_0x3f79('0x8d'),_0x3f79('0x80'));_0x4a14a0[_0x3f79('0x8e')]=_0x2b9dd5['serverUrl']+_0x3f79('0x8f')+_0x4a14a0[_0x3f79('0x82')]+_0x3f79('0x81')+md5(_0x4a14a0[_0x3f79('0x82')]);}var _0x395d66=_0x2b9dd5[_0x3f79('0x7c')]==='zoho.eu'?'eu':_0x3f79('0x83');return getAccessToken(_0x2b9dd5)[_0x3f79('0x30')](function(_0x7ea41b){_0x4c52ac=_0x7ea41b;return getUser(_0x4c52ac,_0x395d66,_0x2b9dd5,_0x474a9f['email']);})[_0x3f79('0x30')](function(_0x2a38b1){_0x5cfb80=_0x2a38b1;logger[_0x3f79('0x35')](_0x3f79('0x84'),_0x5cfb80['id']);return getEndUser(_0x4c52ac,_0x395d66,_0x2b9dd5,_0x4a14a0[_0x3f79('0x90')],_0x4a14a0['destcalleridnum'],_0x5cfb80,_0x3af74e);})[_0x3f79('0x30')](function(_0x5ea178){_0x2a4158=_0x5ea178;return getCall(_0x4c52ac,_0x395d66,_0x2b9dd5,_0x5cfb80,_0x2a4158,_0x3af74e,_0x4a14a0,_0x3f79('0x91'));})[_0x3f79('0x30')](function(_0x466d7a){if(_0x466d7a){logger[_0x3f79('0x35')](_0x3f79('0x87'),_0x466d7a['id']);logger['info']('[OUTBOUND]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0x3f79('0x8a'),_0x474a9f['name']),'trigger:browser:url',{'uri':_0x3f79('0x8b')+_0x2b9dd5['host']+_0x3f79('0x92')+_0x466d7a['id']});}})[_0x3f79('0x28')](function(_0x298dff){logger[_0x3f79('0x29')](_0x3f79('0x8d'),JSON[_0x3f79('0xd')](_0x298dff));});};exports[_0x3f79('0x93')]=function(_0x59f92a,_0x4e5bc7,_0x3b8f97,_0x322ba1,_0x168165,_0x5a6e7f){var _0x1d4973,_0x11018c,_0x2f8a8f;_0x5a6e7f[_0x3f79('0x7c')]=intUtil[_0x3f79('0x7d')](_0x5a6e7f[_0x3f79('0x7c')]);_0x5a6e7f[_0x3f79('0x7e')]=intUtil[_0x3f79('0x7d')](_0x5a6e7f[_0x3f79('0x7e')]);if(_0x168165&&_0x168165[_0x3f79('0x7f')]){logger[_0x3f79('0x35')]('['+_0x4e5bc7[_0x3f79('0x66')][_0x3f79('0x94')]()+']',_0x3f79('0x80'));_0x4e5bc7[_0x3f79('0x8e')]=_0x5a6e7f[_0x3f79('0x7e')]+'/api/voice/recordings/'+_0x4e5bc7['uniqueid']+_0x3f79('0x81')+md5(_0x4e5bc7[_0x3f79('0x82')]);}else{_0x4e5bc7[_0x3f79('0x8e')]='';}var _0x58c3bb=_0x5a6e7f['host']===_0x3f79('0x95')?'eu':_0x3f79('0x83');return getAccessToken(_0x5a6e7f)[_0x3f79('0x30')](function(_0x24bfe6){_0x2f8a8f=_0x24bfe6;return getUser(_0x2f8a8f,_0x58c3bb,_0x5a6e7f);})[_0x3f79('0x30')](function(_0x2e6ff6){_0x1d4973=_0x2e6ff6;logger[_0x3f79('0x35')](_0x3f79('0x84'),_0x1d4973['id']);return getEndUser(_0x2f8a8f,_0x58c3bb,_0x5a6e7f,_0x4e5bc7[_0x3f79('0x85')],_0x4e5bc7[_0x3f79('0x86')],_0x1d4973,_0x3b8f97);})[_0x3f79('0x30')](function(_0x338183){_0x11018c=_0x338183;return getCall(_0x2f8a8f,_0x58c3bb,_0x5a6e7f,_0x1d4973,_0x11018c,_0x3b8f97,_0x4e5bc7,'Inbound');})[_0x3f79('0x30')](function(_0x37d8a5){if(_0x37d8a5){logger[_0x3f79('0x35')](_0x3f79('0x87'),_0x37d8a5['id']);}})[_0x3f79('0x28')](function(_0x3cdbc3){logger[_0x3f79('0x29')]('['+_0x4e5bc7[_0x3f79('0x66')][_0x3f79('0x94')]()+']',JSON[_0x3f79('0xd')](_0x3cdbc3));});};