407d37dfac73190c816143cdbc130aaff338dc15
[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 _0x923f=['indexOf','isBefore','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.com.cn','POST','/oauth/v2/token','refreshToken','clientSecret','access_token','add','catch','error','Failing\x20creating\x20the\x20access_token','info','format','https://www.zohoapis.%s/crm/v2/users','then','users','isArrayLikeObject','isNil','findIndex','email','Using\x20the\x20admin\x20account!','profile','Administrator','user','The\x20failing\x20result\x20is','stringify','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','https://www.zohoapis.','startCase','moduleCreate','role','first_name','last_name','code','details','Error:\x20','log','CREATE\x20ERROR','GET','Zoho-oauthtoken\x20','moduleSearch','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','uri','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','nothing','lead','administrator','Subject','getString','Descriptions','enduserType','Who_Id','Full_Name','First_Name','Last_Name','What_Id','$se_module','utc','talktime','mm:ss','answertime','endtime','Call_Duration','YYYY-MM-DDTHH:mm:ss','starttime','lastevent','called','Called','complete','connect','Call_Result','Answered','Rejected','abandoned','Abandoned','timeout','Call_Start_Time','outbound','Call_Type','Inbound','Fields','/crm/v2/Calls','SUCCESS','Call\x20created!','err','stack','queue','stripTrailingSlash','host','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','serverUrl','/downloads?type=uniqueid&token=','uniqueid','zoho.eu','com','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','/api/voice/recordings/','destcalleridnum','Outbound','user:%s','unmanaged','lodash','request-promise','md5','util','./util','ioredis','bluebird','../../../../config/environment','zoho','defaults','localhost','socket.io-emitter','redis','[HTTP]','length','forEach','includes','string','type','idField','toString','variable','variableName','customVariable','Variable','name','toLowerCase'];(function(_0x2fff6b,_0x29752f){var _0xc562b2=function(_0x19bd81){while(--_0x19bd81){_0x2fff6b['push'](_0x2fff6b['shift']());}};_0xc562b2(++_0x29752f);}(_0x923f,0x7b));var _0xf923=function(_0x354489,_0x4f148f){_0x354489=_0x354489-0x0;var _0x5ae6e9=_0x923f[_0x354489];return _0x5ae6e9;};'use strict';var _=require(_0xf923('0x0'));var rp=require(_0xf923('0x1'));var md5=require(_0xf923('0x2'));var util=require(_0xf923('0x3'));var intUtil=require(_0xf923('0x4'));var moment=require('moment');var Redis=require(_0xf923('0x5'));var BPromise=require(_0xf923('0x6'));var config=require(_0xf923('0x7'));var logger=require('../../../../config/logger')(_0xf923('0x8'));config['redis']=_[_0xf923('0x9')](config['redis'],{'host':_0xf923('0xa'),'port':0x18eb});var io=require(_0xf923('0xb'))(new Redis(config[_0xf923('0xc')]));function emit(_0x3db5ab,_0x2cfc53,_0x447318){io['to'](_0x3db5ab)['emit'](_0x2cfc53,_0x447318);}function request(_0x3ab9b){logger['debug'](_0xf923('0xd'),JSON['stringify'](_0x3ab9b));return rp(_0x3ab9b);}function getCustomFields(_0x3616e0,_0x38a25d){var _0x20276d={};if(_0x3616e0[_0xf923('0xe')]>0x0){_[_0xf923('0xf')](_0x3616e0,function(_0x49f972){if(_[_0xf923('0x10')]([_0xf923('0x11'),'picklist'],_0x49f972[_0xf923('0x12')])&&_0x49f972['idField']){_0x20276d[_0x49f972[_0xf923('0x13')]]=_0x49f972['content'][_0xf923('0x14')]();}else if(_0x49f972[_0xf923('0x12')]===_0xf923('0x15')&&_0x49f972[_0xf923('0x16')]&&_0x49f972[_0xf923('0x13')]&&_0x38a25d[_0x49f972[_0xf923('0x16')]]){_0x20276d[_0x49f972['idField']]=_0x38a25d[_0x49f972[_0xf923('0x16')]][_0xf923('0x14')]();}else if(_0x49f972[_0xf923('0x12')]===_0xf923('0x17')&&_0x49f972[_0xf923('0x18')]&&_0x49f972[_0xf923('0x18')][_0xf923('0x19')]&&_0x49f972[_0xf923('0x13')]&&_0x38a25d[_0x49f972[_0xf923('0x18')][_0xf923('0x19')][_0xf923('0x1a')]()]){_0x20276d[_0x49f972['idField']]=_0x38a25d[_0x49f972['Variable'][_0xf923('0x19')]['toLowerCase']()][_0xf923('0x14')]();}});}return _0x20276d;}function getName(_0x20f469){if(_0x20f469[_0xf923('0x1b')]('\x20')>0x0){var _0x15d231=_0x20f469['split'](/ (.+)/);if(_0x15d231[0x1]){return _0x15d231;}}return[_0x20f469,_0x20f469];}var accountsTokens={};function getAccessToken(_0x5d091f){return new Promise(function(_0x1b7c21,_0x3d1b30){if(!_['isNil'](accountsTokens[_0x5d091f['id']])&&!_['isNil'](accountsTokens[_0x5d091f['id']]['access_token'])){if(moment()[_0xf923('0x1c')](accountsTokens[_0x5d091f['id']][_0xf923('0x1d')])){_0x1b7c21(accountsTokens[_0x5d091f['id']]['access_token']);}}var _0x355dd0;switch(_0x5d091f[_0xf923('0x1e')]){case'US':_0x355dd0=_0xf923('0x1f');break;case'AU':_0x355dd0=_0xf923('0x20');break;case'EU':_0x355dd0=_0xf923('0x21');break;case'IN':_0x355dd0='https://accounts.zoho.in';break;case'CN':_0x355dd0=_0xf923('0x22');break;default:_0x355dd0=_0xf923('0x21');break;}var _0x318a34={'method':_0xf923('0x23'),'uri':_0x355dd0+_0xf923('0x24'),'qs':{'refresh_token':_0x5d091f[_0xf923('0x25')],'client_id':_0x5d091f['clientId'],'client_secret':_0x5d091f[_0xf923('0x26')],'grant_type':'refresh_token'},'json':!![]};return rp(_0x318a34)['then'](function(_0x578c51){accountsTokens[_0x5d091f['id']]={'access_token':_0x578c51[_0xf923('0x27')],'expires_in':moment()[_0xf923('0x28')](_0x578c51['expires_in'],'seconds')};_0x1b7c21(_0x578c51['access_token']);})[_0xf923('0x29')](function(_0x48dbeb){logger[_0xf923('0x2a')](_0xf923('0x2b'),_0x48dbeb['stack']);_0x3d1b30(_0x48dbeb);});});}function getUser(_0x299568,_0x11b72a,_0x24e4c8,_0x2b3a4b){logger[_0xf923('0x2c')]('Search\x20user');return request({'method':'GET','uri':util[_0xf923('0x2d')](_0xf923('0x2e'),_0x11b72a),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x299568},'json':!![]})[_0xf923('0x2f')](function(_0x55d484){if(_0x55d484[_0xf923('0x30')]){var _0x31d279=-0x1;if(_[_0xf923('0x31')](_0x55d484[_0xf923('0x30')])){if(!_[_0xf923('0x32')](_0x2b3a4b)){_0x31d279=_[_0xf923('0x33')](_0x55d484[_0xf923('0x30')],function(_0x13079f){return _0x13079f[_0xf923('0x34')]===_0x2b3a4b;});}if(_0x31d279>=0x0){logger['info']('Agent\x20found!');}else{logger[_0xf923('0x2c')](_0xf923('0x35'));_0x31d279=_['findIndex'](_0x55d484[_0xf923('0x30')],function(_0x38f2b6){return _0x38f2b6[_0xf923('0x36')]['name']===_0xf923('0x37');});}return _0x55d484[_0xf923('0x30')][_0x31d279];}else{if(_0x55d484[_0xf923('0x38')][_0xf923('0x36')][_0xf923('0x19')]===_0xf923('0x37')){logger[_0xf923('0x2c')](_0xf923('0x35'));user=_0x55d484['user'];return user;}else{logger[_0xf923('0x2a')](_0xf923('0x39'),JSON[_0xf923('0x3a')](_0x55d484));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON['stringify'](_0x55d484));}}}else{logger[_0xf923('0x2a')](_0xf923('0x39'),JSON[_0xf923('0x3a')](_0x55d484));throw new Error(_0xf923('0x3b')+JSON[_0xf923('0x3a')](_0x55d484));}})[_0xf923('0x29')](function(_0x34592f){console[_0xf923('0x2a')](_0x34592f);});}function getZohoUser(_0x19f268,_0x591988){return new BPromise(function(_0xf20ed6,_0x3c2a63){request(_0x19f268)[_0xf923('0x2f')](function(_0x3280fa){var _0x2720b2=null;if(_0x3280fa){_0x2720b2=_0x3280fa[_0xf923('0x3c')][0x0];_0x2720b2['enduserType']=_0x591988;}_0xf20ed6(_0x2720b2);})['catch'](function(_0xe11b54){_0x3c2a63(_0xe11b54);});});}function createEndUser(_0x3b17be,_0x74f565,_0x4d2702,_0x22d9c5,_0x46def4,_0x44f903){var _0x4d2702=getName(_0x4d2702);return request({'method':_0xf923('0x23'),'uri':_0xf923('0x3d')+_0x74f565+'/crm/v2/'+_[_0xf923('0x3e')](_0x44f903[_0xf923('0x3f')])+'s','body':{'data':[{'Last_Name':_0x4d2702[0x1],'First_Name':_0x4d2702[0x0],'Phone':_0x22d9c5,'Owner':{'name':!_[_0xf923('0x32')](_0x46def4[_0xf923('0x40')][_0xf923('0x19')])?_0x46def4['role'][_0xf923('0x19')]:!_['isNil'](_0x46def4[_0xf923('0x41')])?_0x46def4[_0xf923('0x41')]+'\x20'+_0x46def4[_0xf923('0x42')]:_0x46def4[_0xf923('0x42')],'id':_0x46def4['id']}}]},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x3b17be},'json':!![]})['then'](function(_0x30f9ef){if(_0x30f9ef&&_0x30f9ef[_0xf923('0x3c')][0x0][_0xf923('0x43')]==='SUCCESS'){var _0x22c633=_0x30f9ef['data'][0x0][_0xf923('0x44')];_0x22c633['enduserType']=_[_0xf923('0x3e')](_0x44f903[_0xf923('0x3f')])+'s';return _0x22c633;}logger['error'](_0xf923('0x39'),JSON[_0xf923('0x3a')](data));throw new Error(_0xf923('0x45')+JSON[_0xf923('0x3a')](data));})[_0xf923('0x29')](function(_0x1d039f){console[_0xf923('0x46')](_0xf923('0x47'),_0x1d039f);});}function getEndUser(_0x172e9f,_0x5c80ba,_0x2e216a,_0x43bcf8,_0x152176,_0xea614e,_0x45d41e){var _0x2ba784={'method':_0xf923('0x48'),'uri':'','headers':{'Authorization':_0xf923('0x49')+_0x172e9f},'json':!![]};switch(_0x45d41e[_0xf923('0x4a')]){case'contact_lead':_0x2ba784['uri']=_0xf923('0x3d')+_0x5c80ba+_0xf923('0x4b')+_0x152176+'))';return getZohoUser(_0x2ba784,_0xf923('0x4c'))[_0xf923('0x2f')](function(_0x31a705){if(_0x31a705)return _0x31a705;_0x2ba784[_0xf923('0x4d')]=_0xf923('0x3d')+_0x5c80ba+_0xf923('0x4e')+_0x152176+'))';return getZohoUser(_0x2ba784,_0xf923('0x4f'))[_0xf923('0x2f')](function(_0x1a6070){if(_0x1a6070)return _0x1a6070;if(_0x45d41e[_0xf923('0x3f')]!=_0xf923('0x50')){return createEndUser(_0x172e9f,_0x5c80ba,_0x43bcf8,_0x152176,_0xea614e,_0x45d41e);}else{return{};}});});break;case'contact':_0x2ba784[_0xf923('0x4d')]=_0xf923('0x3d')+_0x5c80ba+_0xf923('0x4b')+_0x152176+'))';return getZohoUser(_0x2ba784,_0xf923('0x4c'))[_0xf923('0x2f')](function(_0x229dd9){if(_0x229dd9)return _0x229dd9;if(_0x45d41e[_0xf923('0x3f')]!=_0xf923('0x50')){return createEndUser(_0x172e9f,_0x5c80ba,_0x43bcf8,_0x152176,_0xea614e,_0x45d41e);}else{return{};}});break;case _0xf923('0x51'):_0x2ba784['uri']='https://www.zohoapis.'+_0x5c80ba+_0xf923('0x4e')+_0x152176+'))';return getZohoUser(_0x2ba784,_0xf923('0x4f'))[_0xf923('0x2f')](function(_0x443d61){if(_0x443d61)return _0x443d61;if(_0x45d41e[_0xf923('0x3f')]!=_0xf923('0x50')){return createEndUser(_0x172e9f,_0x5c80ba,_0x43bcf8,_0x152176,_0xea614e,_0x45d41e);}else{return{};}});break;}}function getCall(_0x31ae93,_0x8acd5d,_0x3a6dd6,_0x577bf6,_0x3c9626,_0x3f5c84,_0x137c19,_0x20a192){logger[_0xf923('0x2c')]('Creating\x20new\x20call...');var _0x366a4f={};_0x366a4f['Owner']={'name':!_['isNil'](_0x577bf6[_0xf923('0x40')][_0xf923('0x19')])&&!_[_0xf923('0x32')](_0x577bf6['profile']['name'])&&_0x577bf6[_0xf923('0x36')][_0xf923('0x19')]===_0xf923('0x52')?_0x577bf6[_0xf923('0x40')][_0xf923('0x19')]:!_['isNil'](_0x577bf6[_0xf923('0x41')])?_0x577bf6['first_name']+'\x20'+_0x577bf6['last_name']:_0x577bf6['last_name'],'id':_0x577bf6['id']};_0x366a4f[_0xf923('0x53')]=intUtil[_0xf923('0x54')](_0x3f5c84['Subjects'],_0x137c19,'\x20');_0x366a4f['Description']=intUtil['getString'](_0x3f5c84[_0xf923('0x55')],_0x137c19,'\x0a');if(_0x3c9626[_0xf923('0x56')]===_0xf923('0x4c')){_0x366a4f[_0xf923('0x57')]={'name':!_[_0xf923('0x32')](_0x3c9626[_0xf923('0x58')])?_0x3c9626['Full_Name']:!_[_0xf923('0x32')](_0x3c9626[_0xf923('0x59')])?_0x3c9626[_0xf923('0x59')]+'\x20'+_0x3c9626[_0xf923('0x5a')]:_0x3c9626[_0xf923('0x5a')],'id':_0x3c9626['id']};}if(_0x3c9626[_0xf923('0x56')]===_0xf923('0x4f')){_0x366a4f[_0xf923('0x5b')]={'name':!_['isNil'](_0x3c9626[_0xf923('0x58')])?_0x3c9626[_0xf923('0x58')]:!_[_0xf923('0x32')](_0x3c9626[_0xf923('0x59')])?_0x3c9626[_0xf923('0x59')]+'\x20'+_0x3c9626[_0xf923('0x5a')]:_0x3c9626[_0xf923('0x5a')],'id':_0x3c9626['id']};_0x366a4f[_0xf923('0x5c')]=_[_0xf923('0x3e')](_0x3c9626[_0xf923('0x56')]);}if(_0x137c19['talktime']){_0x366a4f['Call_Duration']=moment[_0xf923('0x5d')](parseInt(_0x137c19[_0xf923('0x5e')])*0x3e8)['format'](_0xf923('0x5f'));}else if(_0x137c19[_0xf923('0x60')]&&_0x137c19[_0xf923('0x61')]){_0x366a4f[_0xf923('0x62')]=moment['utc'](moment(_0x137c19[_0xf923('0x61')],_0xf923('0x63'))['diff'](moment(_0x137c19[_0xf923('0x64')],_0xf923('0x63'))))[_0xf923('0x2d')](_0xf923('0x5f'));}switch(_0x137c19[_0xf923('0x65')]){case _0xf923('0x66'):_0x366a4f['Call_Result']=_0xf923('0x67');break;case _0xf923('0x68'):case _0xf923('0x69'):_0x366a4f[_0xf923('0x6a')]=_0xf923('0x6b');break;case'rejected':_0x366a4f[_0xf923('0x6a')]=_0xf923('0x6c');break;case _0xf923('0x6d'):_0x366a4f[_0xf923('0x6a')]=_0xf923('0x6e');break;case _0xf923('0x6f'):_0x366a4f['Call_Result']='Timeout';default:}_0x366a4f[_0xf923('0x70')]=(_0x20a192===_0xf923('0x71')?moment(_0x137c19[_0xf923('0x64')])[_0xf923('0x2d')](_0xf923('0x63')):moment(_0x137c19['agentcalledAt'])[_0xf923('0x2d')](_0xf923('0x63')))||moment()[_0xf923('0x2d')]('YYYY-MM-DDTHH:mm:ss');_0x366a4f[_0xf923('0x72')]=_0x20a192||_0xf923('0x73');_0x366a4f=_['merge'](_0x366a4f,getCustomFields(_0x3f5c84[_0xf923('0x74')],_0x137c19));return request({'method':_0xf923('0x23'),'uri':_0xf923('0x3d')+_0x8acd5d+_0xf923('0x75'),'headers':{'Authorization':_0xf923('0x49')+_0x31ae93},'body':{'data':[_0x366a4f]},'json':!![]})[_0xf923('0x2f')](function(_0x1ac922){if(_0x1ac922&&_0x1ac922[_0xf923('0x3c')][0x0][_0xf923('0x43')]===_0xf923('0x76')){logger[_0xf923('0x2c')](_0xf923('0x77'));return{'id':_0x1ac922[_0xf923('0x3c')][0x0]['details']['id']};}})['catch'](function(_0x449366){logger['info'](_0xf923('0x78'),_0x449366[_0xf923('0x79')]);console[_0xf923('0x46')](_0xf923('0x78'),_0x449366);});}exports[_0xf923('0x7a')]=function(_0x4f589b,_0x247c79,_0xc23758,_0x40af24,_0x187306,_0x4c5e2a){var _0x46057b,_0x17b532,_0x1c5c08;_0x4c5e2a['host']=intUtil[_0xf923('0x7b')](_0x4c5e2a[_0xf923('0x7c')]);_0x4c5e2a['serverUrl']=intUtil[_0xf923('0x7b')](_0x4c5e2a['serverUrl']);if(_0x187306&&_0x187306[_0xf923('0x7d')]){logger['info'](_0xf923('0x7e'),_0xf923('0x7f'));_0x247c79[_0xf923('0x80')]=_0x4c5e2a[_0xf923('0x81')]+'/api/voice/recordings/'+_0x247c79['uniqueid']+_0xf923('0x82')+md5(_0x247c79[_0xf923('0x83')]);}else{_0x247c79[_0xf923('0x80')]='';}var _0x2e95cd=_0x4c5e2a[_0xf923('0x7c')]===_0xf923('0x84')?'eu':_0xf923('0x85');return getAccessToken(_0x4c5e2a)[_0xf923('0x2f')](function(_0x2e79d2){_0x1c5c08=_0x2e79d2;return getUser(_0x1c5c08,_0x2e95cd,_0x4c5e2a,_0x40af24['email']);})[_0xf923('0x2f')](function(_0x41b5f1){_0x46057b=_0x41b5f1;logger[_0xf923('0x2c')](_0xf923('0x86'),_0x46057b['id']);return getEndUser(_0x1c5c08,_0x2e95cd,_0x4c5e2a,_0x247c79[_0xf923('0x87')],_0x247c79[_0xf923('0x88')],_0x46057b,_0xc23758);})[_0xf923('0x2f')](function(_0x4b5b24){_0x17b532=_0x4b5b24;return getCall(_0x1c5c08,_0x2e95cd,_0x4c5e2a,_0x46057b,_0x17b532,_0xc23758,_0x247c79,_0xf923('0x73'));})['then'](function(_0x57b1c4){if(_0x57b1c4){logger[_0xf923('0x2c')](_0xf923('0x89'),_0x57b1c4['id']);logger[_0xf923('0x2c')](_0xf923('0x7e'),_0xf923('0x8a'));emit(util[_0xf923('0x2d')]('user:%s',_0x40af24[_0xf923('0x19')]),_0xf923('0x8b'),{'uri':_0xf923('0x8c')+_0x4c5e2a[_0xf923('0x7c')]+_0xf923('0x8d')+_0x57b1c4['id']});}})['catch'](function(_0x333504){logger[_0xf923('0x2a')](_0xf923('0x7e'),JSON[_0xf923('0x3a')](_0x333504));});};exports[_0xf923('0x71')]=function(_0xb04f2f,_0x420f85,_0x191110,_0x3ffb97,_0x330a8b,_0x48aff4,_0x52e295){var _0x1234e2,_0x4d1a21,_0x1222b2;_0x48aff4[_0xf923('0x7c')]=intUtil['stripTrailingSlash'](_0x48aff4['host']);_0x48aff4['serverUrl']=intUtil[_0xf923('0x7b')](_0x48aff4['serverUrl']);if(_0x52e295&&_0x52e295[_0xf923('0x8e')]&&_0x52e295[_0xf923('0x8e')]!==_0xf923('0x8f')){logger[_0xf923('0x2c')](_0xf923('0x90'),_0xf923('0x7f'));_0x420f85[_0xf923('0x80')]=_0x48aff4[_0xf923('0x81')]+_0xf923('0x91')+_0x420f85[_0xf923('0x83')]+_0xf923('0x82')+md5(_0x420f85[_0xf923('0x83')]);}var _0x2c036e=_0x48aff4[_0xf923('0x7c')]===_0xf923('0x84')?'eu':_0xf923('0x85');return getAccessToken(_0x48aff4)[_0xf923('0x2f')](function(_0x2011d2){_0x1222b2=_0x2011d2;return getUser(_0x1222b2,_0x2c036e,_0x48aff4,_0x3ffb97[_0xf923('0x34')]);})[_0xf923('0x2f')](function(_0x3c4c9b){_0x1234e2=_0x3c4c9b;logger[_0xf923('0x2c')]('The\x20User\x20ID\x20is:',_0x1234e2['id']);return getEndUser(_0x1222b2,_0x2c036e,_0x48aff4,_0x420f85['destcalleridname'],_0x420f85[_0xf923('0x92')],_0x1234e2,_0x191110);})[_0xf923('0x2f')](function(_0x355410){_0x4d1a21=_0x355410;return getCall(_0x1222b2,_0x2c036e,_0x48aff4,_0x1234e2,_0x4d1a21,_0x191110,_0x420f85,_0xf923('0x93'));})['then'](function(_0x2dce20){if(_0x2dce20){logger[_0xf923('0x2c')](_0xf923('0x89'),_0x2dce20['id']);logger[_0xf923('0x2c')](_0xf923('0x90'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xf923('0x2d')](_0xf923('0x94'),_0x3ffb97[_0xf923('0x19')]),_0xf923('0x8b'),{'uri':_0xf923('0x8c')+_0x48aff4[_0xf923('0x7c')]+_0xf923('0x8d')+_0x2dce20['id']});}})[_0xf923('0x29')](function(_0xd1df82){logger['error'](_0xf923('0x90'),JSON[_0xf923('0x3a')](_0xd1df82));});};exports[_0xf923('0x95')]=function(_0x20cc1d,_0x2d8e8b,_0x280b13,_0xeba518,_0x6a0104,_0x1d561e){var _0x8b37a9,_0x41659d,_0x1a7e44;_0x1d561e[_0xf923('0x7c')]=intUtil[_0xf923('0x7b')](_0x1d561e[_0xf923('0x7c')]);_0x1d561e[_0xf923('0x81')]=intUtil[_0xf923('0x7b')](_0x1d561e[_0xf923('0x81')]);if(_0x6a0104&&_0x6a0104['monitor_format']){logger['info']('['+_0x2d8e8b[_0xf923('0x65')]['toUpperCase']()+']',_0xf923('0x7f'));_0x2d8e8b[_0xf923('0x80')]=_0x1d561e[_0xf923('0x81')]+_0xf923('0x91')+_0x2d8e8b[_0xf923('0x83')]+_0xf923('0x82')+md5(_0x2d8e8b[_0xf923('0x83')]);}else{_0x2d8e8b[_0xf923('0x80')]='';}var _0x538e6b=_0x1d561e['host']==='zoho.eu'?'eu':_0xf923('0x85');return getAccessToken(_0x1d561e)['then'](function(_0x1bf66d){_0x1a7e44=_0x1bf66d;return getUser(_0x1a7e44,_0x538e6b,_0x1d561e);})[_0xf923('0x2f')](function(_0x155a2d){_0x8b37a9=_0x155a2d;logger[_0xf923('0x2c')](_0xf923('0x86'),_0x8b37a9['id']);return getEndUser(_0x1a7e44,_0x538e6b,_0x1d561e,_0x2d8e8b[_0xf923('0x87')],_0x2d8e8b[_0xf923('0x88')],_0x8b37a9,_0x280b13);})[_0xf923('0x2f')](function(_0x2f3232){_0x41659d=_0x2f3232;return getCall(_0x1a7e44,_0x538e6b,_0x1d561e,_0x8b37a9,_0x41659d,_0x280b13,_0x2d8e8b,'Inbound');})['then'](function(_0x280422){if(_0x280422){logger[_0xf923('0x2c')](_0xf923('0x89'),_0x280422['id']);}})[_0xf923('0x29')](function(_0x5b8b08){logger[_0xf923('0x2a')]('['+_0x2d8e8b[_0xf923('0x65')]['toUpperCase']()+']',JSON[_0xf923('0x3a')](_0x5b8b08));});};