44b6a758ec36ed682c2573ac0a3300621a0ac553
[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 _0x5bc5=['trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','[OUTBOUND]','zoho.eu','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','The\x20Call\x20ID\x20is:','unmanaged','monitor_format','toUpperCase','/downloads?type=uniqueid&token=','calleridnum','lodash','request-promise','md5','util','./util','moment','ioredis','bluebird','../../../../config/environment','../../../../config/logger','zoho','redis','defaults','localhost','socket.io-emitter','emit','debug','[HTTP]','stringify','length','forEach','string','type','idField','toString','variable','variableName','customVariable','name','Variable','toLowerCase','split','access_token','isBefore','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.in','POST','/oauth/v2/token','refreshToken','clientId','refresh_token','then','add','expires_in','catch','error','Failing\x20creating\x20the\x20access_token','stack','info','Search\x20user','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','users','isArrayLikeObject','isNil','findIndex','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','Administrator','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','code','SUCCESS','details','Error:\x20','log','CREATE\x20ERROR','GET','moduleSearch','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','contact','nothing','lead','Creating\x20new\x20call...','administrator','Subject','getString','Subjects','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','What_Id','$se_module','Call_Duration','utc','talktime','mm:ss','answertime','endtime','YYYY-MM-DDTHH:mm:ss','diff','lastevent','Called','complete','Call_Result','Answered','rejected','Rejected','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','outbound','starttime','agentcalledAt','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','err','queue','serverUrl','stripTrailingSlash','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/api/voice/recordings/','uniqueid','host','com','calleridname','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s'];(function(_0x504e64,_0x52692c){var _0x1a0520=function(_0x54d98d){while(--_0x54d98d){_0x504e64['push'](_0x504e64['shift']());}};_0x1a0520(++_0x52692c);}(_0x5bc5,0xb2));var _0x55bc=function(_0x3207aa,_0xe86a72){_0x3207aa=_0x3207aa-0x0;var _0x51758f=_0x5bc5[_0x3207aa];return _0x51758f;};'use strict';var _=require(_0x55bc('0x0'));var rp=require(_0x55bc('0x1'));var md5=require(_0x55bc('0x2'));var util=require(_0x55bc('0x3'));var intUtil=require(_0x55bc('0x4'));var moment=require(_0x55bc('0x5'));var Redis=require(_0x55bc('0x6'));var BPromise=require(_0x55bc('0x7'));var config=require(_0x55bc('0x8'));var logger=require(_0x55bc('0x9'))(_0x55bc('0xa'));config[_0x55bc('0xb')]=_[_0x55bc('0xc')](config['redis'],{'host':_0x55bc('0xd'),'port':0x18eb});var io=require(_0x55bc('0xe'))(new Redis(config[_0x55bc('0xb')]));function emit(_0x38839e,_0x4d0610,_0x1d6e72){io['to'](_0x38839e)[_0x55bc('0xf')](_0x4d0610,_0x1d6e72);}function request(_0xc535ac){logger[_0x55bc('0x10')](_0x55bc('0x11'),JSON[_0x55bc('0x12')](_0xc535ac));return rp(_0xc535ac);}function getCustomFields(_0x72a619,_0x718891){var _0x4b905d={};if(_0x72a619[_0x55bc('0x13')]>0x0){_[_0x55bc('0x14')](_0x72a619,function(_0x41f298){if(_['includes']([_0x55bc('0x15'),'picklist'],_0x41f298[_0x55bc('0x16')])&&_0x41f298[_0x55bc('0x17')]){_0x4b905d[_0x41f298[_0x55bc('0x17')]]=_0x41f298['content'][_0x55bc('0x18')]();}else if(_0x41f298['type']===_0x55bc('0x19')&&_0x41f298[_0x55bc('0x1a')]&&_0x41f298[_0x55bc('0x17')]&&_0x718891[_0x41f298['variableName']]){_0x4b905d[_0x41f298[_0x55bc('0x17')]]=_0x718891[_0x41f298[_0x55bc('0x1a')]]['toString']();}else if(_0x41f298['type']===_0x55bc('0x1b')&&_0x41f298['Variable']&&_0x41f298['Variable'][_0x55bc('0x1c')]&&_0x41f298[_0x55bc('0x17')]&&_0x718891[_0x41f298[_0x55bc('0x1d')]['name'][_0x55bc('0x1e')]()]){_0x4b905d[_0x41f298[_0x55bc('0x17')]]=_0x718891[_0x41f298[_0x55bc('0x1d')]['name'][_0x55bc('0x1e')]()]['toString']();}});}return _0x4b905d;}function getName(_0x29f969){if(_0x29f969['indexOf']('\x20')>0x0){var _0x53f103=_0x29f969[_0x55bc('0x1f')](/ (.+)/);if(_0x53f103[0x1]){return _0x53f103;}}return[_0x29f969,_0x29f969];}var accountsTokens={};function getAccessToken(_0x390af6){return new Promise(function(_0x2dbfaf,_0x5781f2){if(!_['isNil'](accountsTokens[_0x390af6['id']])&&!_['isNil'](accountsTokens[_0x390af6['id']][_0x55bc('0x20')])){if(moment()[_0x55bc('0x21')](accountsTokens[_0x390af6['id']]['expires_in'])){_0x2dbfaf(accountsTokens[_0x390af6['id']]['access_token']);}}var _0x384433;switch(_0x390af6[_0x55bc('0x22')]){case'US':_0x384433=_0x55bc('0x23');break;case'AU':_0x384433=_0x55bc('0x24');break;case'EU':_0x384433='https://accounts.zoho.eu';break;case'IN':_0x384433=_0x55bc('0x25');break;case'CN':_0x384433='https://accounts.zoho.com.cn';break;default:_0x384433='https://accounts.zoho.eu';break;}var _0x3e6254={'method':_0x55bc('0x26'),'uri':_0x384433+_0x55bc('0x27'),'qs':{'refresh_token':_0x390af6[_0x55bc('0x28')],'client_id':_0x390af6[_0x55bc('0x29')],'client_secret':_0x390af6['clientSecret'],'grant_type':_0x55bc('0x2a')},'json':!![]};return rp(_0x3e6254)[_0x55bc('0x2b')](function(_0xa649a3){accountsTokens[_0x390af6['id']]={'access_token':_0xa649a3[_0x55bc('0x20')],'expires_in':moment()[_0x55bc('0x2c')](_0xa649a3[_0x55bc('0x2d')],'seconds')};_0x2dbfaf(_0xa649a3[_0x55bc('0x20')]);})[_0x55bc('0x2e')](function(_0x4227be){logger[_0x55bc('0x2f')](_0x55bc('0x30'),_0x4227be[_0x55bc('0x31')]);_0x5781f2(_0x4227be);});});}function getUser(_0x1268ac,_0x29cf97,_0x1d840f,_0x409295){logger[_0x55bc('0x32')](_0x55bc('0x33'));return request({'method':'GET','uri':util[_0x55bc('0x34')](_0x55bc('0x35'),_0x29cf97),'qs':{'type':_0x55bc('0x36')},'headers':{'Authorization':_0x55bc('0x37')+_0x1268ac},'json':!![]})[_0x55bc('0x2b')](function(_0x497681){if(_0x497681[_0x55bc('0x38')]){var _0x412d57=-0x1;if(_[_0x55bc('0x39')](_0x497681[_0x55bc('0x38')])){if(!_[_0x55bc('0x3a')](_0x409295)){_0x412d57=_[_0x55bc('0x3b')](_0x497681[_0x55bc('0x38')],function(_0x33ee3a){return _0x33ee3a[_0x55bc('0x3c')]===_0x409295;});}if(_0x412d57>=0x0){logger['info'](_0x55bc('0x3d'));}else{logger[_0x55bc('0x32')](_0x55bc('0x3e'));_0x412d57=_[_0x55bc('0x3b')](_0x497681[_0x55bc('0x38')],function(_0x2f7beb){return _0x2f7beb[_0x55bc('0x3f')]['name']===_0x55bc('0x40');});}return _0x497681[_0x55bc('0x38')][_0x412d57];}else{if(_0x497681['user'][_0x55bc('0x3f')][_0x55bc('0x1c')]===_0x55bc('0x40')){logger[_0x55bc('0x32')](_0x55bc('0x3e'));user=_0x497681['user'];return user;}else{logger['error'](_0x55bc('0x41'),JSON[_0x55bc('0x12')](_0x497681));throw new Error(_0x55bc('0x42')+JSON[_0x55bc('0x12')](_0x497681));}}}else{logger[_0x55bc('0x2f')](_0x55bc('0x41'),JSON[_0x55bc('0x12')](_0x497681));throw new Error(_0x55bc('0x42')+JSON['stringify'](_0x497681));}})[_0x55bc('0x2e')](function(_0x224342){console[_0x55bc('0x2f')](_0x224342);});}function getZohoUser(_0x53ae76,_0x5661de){return new BPromise(function(_0x32c468,_0x58b58d){request(_0x53ae76)[_0x55bc('0x2b')](function(_0x69d8b1){var _0x4c1e8e=null;if(_0x69d8b1){_0x4c1e8e=_0x69d8b1[_0x55bc('0x43')][0x0];_0x4c1e8e[_0x55bc('0x44')]=_0x5661de;}_0x32c468(_0x4c1e8e);})[_0x55bc('0x2e')](function(_0x1f8c9c){_0x58b58d(_0x1f8c9c);});});}function createEndUser(_0x26ae3e,_0x3bb55a,_0x334e24,_0x3e5b7c,_0x5ebce8,_0x339704){var _0x334e24=getName(_0x334e24);return request({'method':_0x55bc('0x26'),'uri':_0x55bc('0x45')+_0x3bb55a+_0x55bc('0x46')+_[_0x55bc('0x47')](_0x339704[_0x55bc('0x48')])+'s','body':{'data':[{'Last_Name':_0x334e24[0x1],'First_Name':_0x334e24[0x0],'Phone':_0x3e5b7c,'Owner':{'name':!_[_0x55bc('0x3a')](_0x5ebce8['role'][_0x55bc('0x1c')])?_0x5ebce8[_0x55bc('0x49')]['name']:!_[_0x55bc('0x3a')](_0x5ebce8[_0x55bc('0x4a')])?_0x5ebce8[_0x55bc('0x4a')]+'\x20'+_0x5ebce8[_0x55bc('0x4b')]:_0x5ebce8[_0x55bc('0x4b')],'id':_0x5ebce8['id']}}]},'headers':{'Authorization':_0x55bc('0x37')+_0x26ae3e},'json':!![]})[_0x55bc('0x2b')](function(_0x54e4f6){if(_0x54e4f6&&_0x54e4f6[_0x55bc('0x43')][0x0][_0x55bc('0x4c')]===_0x55bc('0x4d')){var _0x57c4e9=_0x54e4f6[_0x55bc('0x43')][0x0][_0x55bc('0x4e')];_0x57c4e9[_0x55bc('0x44')]=_[_0x55bc('0x47')](_0x339704['moduleCreate'])+'s';return _0x57c4e9;}logger[_0x55bc('0x2f')]('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error(_0x55bc('0x4f')+JSON['stringify'](data));})[_0x55bc('0x2e')](function(_0x41a2db){console[_0x55bc('0x50')](_0x55bc('0x51'),_0x41a2db);});}function getEndUser(_0x5f361d,_0x5894d9,_0x509c62,_0x5e2aea,_0x18f6f9,_0x1359a6,_0x55eaa7){var _0x37ff3e={'method':_0x55bc('0x52'),'uri':'','headers':{'Authorization':_0x55bc('0x37')+_0x5f361d},'json':!![]};switch(_0x55eaa7[_0x55bc('0x53')]){case'contact_lead':_0x37ff3e[_0x55bc('0x54')]=_0x55bc('0x45')+_0x5894d9+_0x55bc('0x55')+_0x18f6f9+'))';return getZohoUser(_0x37ff3e,_0x55bc('0x56'))[_0x55bc('0x2b')](function(_0x5bebda){if(_0x5bebda)return _0x5bebda;_0x37ff3e[_0x55bc('0x54')]=_0x55bc('0x45')+_0x5894d9+_0x55bc('0x57')+_0x18f6f9+'))';return getZohoUser(_0x37ff3e,_0x55bc('0x58'))[_0x55bc('0x2b')](function(_0x44d617){if(_0x44d617)return _0x44d617;if(_0x55eaa7[_0x55bc('0x48')]!='nothing'){return createEndUser(_0x5f361d,_0x5894d9,_0x5e2aea,_0x18f6f9,_0x1359a6,_0x55eaa7);}else{return{};}});});break;case _0x55bc('0x59'):_0x37ff3e[_0x55bc('0x54')]=_0x55bc('0x45')+_0x5894d9+_0x55bc('0x55')+_0x18f6f9+'))';return getZohoUser(_0x37ff3e,_0x55bc('0x56'))[_0x55bc('0x2b')](function(_0x3f77a8){if(_0x3f77a8)return _0x3f77a8;if(_0x55eaa7[_0x55bc('0x48')]!=_0x55bc('0x5a')){return createEndUser(_0x5f361d,_0x5894d9,_0x5e2aea,_0x18f6f9,_0x1359a6,_0x55eaa7);}else{return{};}});break;case _0x55bc('0x5b'):_0x37ff3e[_0x55bc('0x54')]=_0x55bc('0x45')+_0x5894d9+_0x55bc('0x57')+_0x18f6f9+'))';return getZohoUser(_0x37ff3e,_0x55bc('0x58'))['then'](function(_0x56dc07){if(_0x56dc07)return _0x56dc07;if(_0x55eaa7[_0x55bc('0x48')]!=_0x55bc('0x5a')){return createEndUser(_0x5f361d,_0x5894d9,_0x5e2aea,_0x18f6f9,_0x1359a6,_0x55eaa7);}else{return{};}});break;}}function getCall(_0x3de9b4,_0x4c161c,_0x42847b,_0x5b7ec0,_0x212560,_0x496448,_0x104960,_0x566be2){logger[_0x55bc('0x32')](_0x55bc('0x5c'));var _0x2630fa={};_0x2630fa['Owner']={'name':!_[_0x55bc('0x3a')](_0x5b7ec0[_0x55bc('0x49')][_0x55bc('0x1c')])&&!_[_0x55bc('0x3a')](_0x5b7ec0[_0x55bc('0x3f')]['name'])&&_0x5b7ec0[_0x55bc('0x3f')]['name']===_0x55bc('0x5d')?_0x5b7ec0[_0x55bc('0x49')][_0x55bc('0x1c')]:!_[_0x55bc('0x3a')](_0x5b7ec0[_0x55bc('0x4a')])?_0x5b7ec0[_0x55bc('0x4a')]+'\x20'+_0x5b7ec0[_0x55bc('0x4b')]:_0x5b7ec0[_0x55bc('0x4b')],'id':_0x5b7ec0['id']};_0x2630fa[_0x55bc('0x5e')]=intUtil[_0x55bc('0x5f')](_0x496448[_0x55bc('0x60')],_0x104960,'\x20');_0x2630fa[_0x55bc('0x61')]=intUtil[_0x55bc('0x5f')](_0x496448[_0x55bc('0x62')],_0x104960,'\x0a');if(_0x212560[_0x55bc('0x44')]==='Contacts'){_0x2630fa[_0x55bc('0x63')]={'name':!_['isNil'](_0x212560[_0x55bc('0x64')])?_0x212560[_0x55bc('0x64')]:!_[_0x55bc('0x3a')](_0x212560[_0x55bc('0x65')])?_0x212560[_0x55bc('0x65')]+'\x20'+_0x212560[_0x55bc('0x66')]:_0x212560['Last_Name'],'id':_0x212560['id']};}if(_0x212560['enduserType']===_0x55bc('0x58')){_0x2630fa[_0x55bc('0x67')]={'name':!_[_0x55bc('0x3a')](_0x212560['Full_Name'])?_0x212560[_0x55bc('0x64')]:!_[_0x55bc('0x3a')](_0x212560['First_Name'])?_0x212560[_0x55bc('0x65')]+'\x20'+_0x212560[_0x55bc('0x66')]:_0x212560['Last_Name'],'id':_0x212560['id']};_0x2630fa[_0x55bc('0x68')]=_[_0x55bc('0x47')](_0x212560[_0x55bc('0x44')]);}if(_0x104960['talktime']){_0x2630fa[_0x55bc('0x69')]=moment[_0x55bc('0x6a')](parseInt(_0x104960[_0x55bc('0x6b')])*0x3e8)[_0x55bc('0x34')](_0x55bc('0x6c'));}else if(_0x104960[_0x55bc('0x6d')]&&_0x104960[_0x55bc('0x6e')]){_0x2630fa[_0x55bc('0x69')]=moment[_0x55bc('0x6a')](moment(_0x104960[_0x55bc('0x6e')],_0x55bc('0x6f'))[_0x55bc('0x70')](moment(_0x104960['starttime'],_0x55bc('0x6f'))))['format']('mm:ss');}switch(_0x104960[_0x55bc('0x71')]){case'called':_0x2630fa['Call_Result']=_0x55bc('0x72');break;case _0x55bc('0x73'):case'connect':_0x2630fa[_0x55bc('0x74')]=_0x55bc('0x75');break;case _0x55bc('0x76'):_0x2630fa[_0x55bc('0x74')]=_0x55bc('0x77');break;case _0x55bc('0x78'):_0x2630fa['Call_Result']=_0x55bc('0x79');break;case _0x55bc('0x7a'):_0x2630fa[_0x55bc('0x74')]=_0x55bc('0x7b');default:}_0x2630fa[_0x55bc('0x7c')]=(_0x566be2===_0x55bc('0x7d')?moment(_0x104960[_0x55bc('0x7e')])[_0x55bc('0x34')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x104960[_0x55bc('0x7f')])[_0x55bc('0x34')](_0x55bc('0x6f')))||moment()[_0x55bc('0x34')]('YYYY-MM-DDTHH:mm:ss');_0x2630fa[_0x55bc('0x80')]=_0x566be2||_0x55bc('0x81');_0x2630fa=_[_0x55bc('0x82')](_0x2630fa,getCustomFields(_0x496448[_0x55bc('0x83')],_0x104960));return request({'method':_0x55bc('0x26'),'uri':_0x55bc('0x45')+_0x4c161c+_0x55bc('0x84'),'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x3de9b4},'body':{'data':[_0x2630fa]},'json':!![]})[_0x55bc('0x2b')](function(_0x1c127a){if(_0x1c127a&&_0x1c127a['data'][0x0][_0x55bc('0x4c')]===_0x55bc('0x4d')){logger[_0x55bc('0x32')](_0x55bc('0x85'));return{'id':_0x1c127a[_0x55bc('0x43')][0x0][_0x55bc('0x4e')]['id']};}})[_0x55bc('0x2e')](function(_0x845f2f){logger[_0x55bc('0x32')](_0x55bc('0x86'),_0x845f2f[_0x55bc('0x31')]);console[_0x55bc('0x50')](_0x55bc('0x86'),_0x845f2f);});}exports[_0x55bc('0x87')]=function(_0x27a66d,_0x55c509,_0xbf17b,_0x3a3e85,_0x56629f,_0x6faa0a){var _0x1d7981,_0x19e8d5,_0x4a4251;_0x6faa0a['host']=intUtil['stripTrailingSlash'](_0x6faa0a['host']);_0x6faa0a[_0x55bc('0x88')]=intUtil[_0x55bc('0x89')](_0x6faa0a[_0x55bc('0x88')]);if(_0x56629f&&_0x56629f['monitor_format']){logger[_0x55bc('0x32')](_0x55bc('0x8a'),_0x55bc('0x8b'));_0x55c509[_0x55bc('0x8c')]=_0x6faa0a[_0x55bc('0x88')]+_0x55bc('0x8d')+_0x55c509['uniqueid']+'/downloads?type=uniqueid&token='+md5(_0x55c509[_0x55bc('0x8e')]);}else{_0x55c509['recordingURL']='';}var _0x815490=_0x6faa0a[_0x55bc('0x8f')]==='zoho.eu'?'eu':_0x55bc('0x90');return getAccessToken(_0x6faa0a)[_0x55bc('0x2b')](function(_0x3857be){_0x4a4251=_0x3857be;return getUser(_0x4a4251,_0x815490,_0x6faa0a,_0x3a3e85[_0x55bc('0x3c')]);})[_0x55bc('0x2b')](function(_0x3937f0){_0x1d7981=_0x3937f0;logger[_0x55bc('0x32')]('The\x20User\x20ID\x20is:',_0x1d7981['id']);return getEndUser(_0x4a4251,_0x815490,_0x6faa0a,_0x55c509[_0x55bc('0x91')],_0x55c509['calleridnum'],_0x1d7981,_0xbf17b);})['then'](function(_0x5d94a9){_0x19e8d5=_0x5d94a9;return getCall(_0x4a4251,_0x815490,_0x6faa0a,_0x1d7981,_0x19e8d5,_0xbf17b,_0x55c509,_0x55bc('0x81'));})['then'](function(_0x9a802b){if(_0x9a802b){logger[_0x55bc('0x32')]('The\x20Call\x20ID\x20is:',_0x9a802b['id']);logger['info'](_0x55bc('0x8a'),_0x55bc('0x92'));emit(util[_0x55bc('0x34')](_0x55bc('0x93'),_0x3a3e85[_0x55bc('0x1c')]),_0x55bc('0x94'),{'uri':_0x55bc('0x95')+_0x6faa0a[_0x55bc('0x8f')]+_0x55bc('0x96')+_0x9a802b['id']});}})[_0x55bc('0x2e')](function(_0x3c24ba){logger['error'](_0x55bc('0x8a'),JSON['stringify'](_0x3c24ba));});};exports[_0x55bc('0x7d')]=function(_0x3266c5,_0x25a212,_0x22ffba,_0x524b0e,_0x494bf7,_0x26c677,_0x3d0a42){var _0x20dca2,_0xbb0d71,_0x5f4872;_0x26c677[_0x55bc('0x8f')]=intUtil['stripTrailingSlash'](_0x26c677[_0x55bc('0x8f')]);_0x26c677[_0x55bc('0x88')]=intUtil[_0x55bc('0x89')](_0x26c677[_0x55bc('0x88')]);if(_0x3d0a42&&_0x3d0a42[_0x55bc('0x97')]&&_0x3d0a42[_0x55bc('0x97')]!=='none'){logger['info'](_0x55bc('0x98'),_0x55bc('0x8b'));_0x25a212[_0x55bc('0x8c')]=_0x26c677['serverUrl']+_0x55bc('0x8d')+_0x25a212[_0x55bc('0x8e')]+'/downloads?type=uniqueid&token='+md5(_0x25a212[_0x55bc('0x8e')]);}var _0x283e74=_0x26c677[_0x55bc('0x8f')]===_0x55bc('0x99')?'eu':_0x55bc('0x90');return getAccessToken(_0x26c677)[_0x55bc('0x2b')](function(_0x26217e){_0x5f4872=_0x26217e;return getUser(_0x5f4872,_0x283e74,_0x26c677,_0x524b0e[_0x55bc('0x3c')]);})[_0x55bc('0x2b')](function(_0x89a067){_0x20dca2=_0x89a067;logger[_0x55bc('0x32')](_0x55bc('0x9a'),_0x20dca2['id']);return getEndUser(_0x5f4872,_0x283e74,_0x26c677,_0x25a212[_0x55bc('0x9b')],_0x25a212[_0x55bc('0x9c')],_0x20dca2,_0x22ffba);})[_0x55bc('0x2b')](function(_0x34d8b2){_0xbb0d71=_0x34d8b2;return getCall(_0x5f4872,_0x283e74,_0x26c677,_0x20dca2,_0xbb0d71,_0x22ffba,_0x25a212,'Outbound');})[_0x55bc('0x2b')](function(_0x3a673a){if(_0x3a673a){logger['info'](_0x55bc('0x9d'),_0x3a673a['id']);logger[_0x55bc('0x32')](_0x55bc('0x98'),_0x55bc('0x92'));emit(util[_0x55bc('0x34')](_0x55bc('0x93'),_0x524b0e['name']),_0x55bc('0x94'),{'uri':_0x55bc('0x95')+_0x26c677[_0x55bc('0x8f')]+_0x55bc('0x96')+_0x3a673a['id']});}})['catch'](function(_0x3067ba){logger[_0x55bc('0x2f')](_0x55bc('0x98'),JSON[_0x55bc('0x12')](_0x3067ba));});};exports[_0x55bc('0x9e')]=function(_0x510e30,_0x2bb33b,_0x5b8d5f,_0x126a1a,_0x400ad4,_0x953f62){var _0x50cfb5,_0x2c227b,_0x4d8bd0;_0x953f62['host']=intUtil[_0x55bc('0x89')](_0x953f62[_0x55bc('0x8f')]);_0x953f62[_0x55bc('0x88')]=intUtil[_0x55bc('0x89')](_0x953f62[_0x55bc('0x88')]);if(_0x400ad4&&_0x400ad4[_0x55bc('0x9f')]){logger[_0x55bc('0x32')]('['+_0x2bb33b[_0x55bc('0x71')][_0x55bc('0xa0')]()+']',_0x55bc('0x8b'));_0x2bb33b['recordingURL']=_0x953f62[_0x55bc('0x88')]+_0x55bc('0x8d')+_0x2bb33b['uniqueid']+_0x55bc('0xa1')+md5(_0x2bb33b[_0x55bc('0x8e')]);}else{_0x2bb33b['recordingURL']='';}var _0x1fab56=_0x953f62[_0x55bc('0x8f')]==='zoho.eu'?'eu':_0x55bc('0x90');return getAccessToken(_0x953f62)[_0x55bc('0x2b')](function(_0x1fa595){_0x4d8bd0=_0x1fa595;return getUser(_0x4d8bd0,_0x1fab56,_0x953f62);})[_0x55bc('0x2b')](function(_0x15c846){_0x50cfb5=_0x15c846;logger[_0x55bc('0x32')](_0x55bc('0x9a'),_0x50cfb5['id']);return getEndUser(_0x4d8bd0,_0x1fab56,_0x953f62,_0x2bb33b[_0x55bc('0x91')],_0x2bb33b[_0x55bc('0xa2')],_0x50cfb5,_0x5b8d5f);})[_0x55bc('0x2b')](function(_0x32b9d0){_0x2c227b=_0x32b9d0;return getCall(_0x4d8bd0,_0x1fab56,_0x953f62,_0x50cfb5,_0x2c227b,_0x5b8d5f,_0x2bb33b,'Inbound');})[_0x55bc('0x2b')](function(_0x1fd72c){if(_0x1fd72c){logger[_0x55bc('0x32')](_0x55bc('0x9d'),_0x1fd72c['id']);}})[_0x55bc('0x2e')](function(_0x552247){logger[_0x55bc('0x2f')]('['+_0x2bb33b[_0x55bc('0x71')][_0x55bc('0xa0')]()+']',JSON[_0x55bc('0x12')](_0x552247));});};