dd31898da6803f69caa1403c2e3e2b553e08ddac
[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 _0xc7fa=['split','isNil','access_token','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','/oauth/v2/token','refreshToken','clientId','clientSecret','refresh_token','add','seconds','error','Failing\x20creating\x20the\x20access_token','info','format','https://www.zohoapis.%s/crm/v2/users','Zoho-oauthtoken\x20','then','users','isArrayLikeObject','findIndex','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','user','Administrator','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','catch','https://www.zohoapis.','startCase','role','first_name','last_name','code','SUCCESS','details','Error:\x20','log','CREATE\x20ERROR','GET','contact_lead','/crm/v2/Contacts/search?criteria=((Phone:equals:','uri','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','Contacts','moduleCreate','lead','Owner','getString','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','Leads','$se_module','talktime','Call_Duration','mm:ss','endtime','utc','YYYY-MM-DDTHH:mm:ss','starttime','lastevent','called','complete','connect','Call_Result','Answered','rejected','abandoned','Abandoned','timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','Inbound','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','uniqueid','/downloads?type=uniqueid&token=','calleridnum','The\x20Call\x20ID\x20is:','[QUEUE]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','/api/voice/recordings/','zoho.eu','com','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','Outbound','unmanaged','toUpperCase','calleridname','lodash','request-promise','md5','moment','ioredis','bluebird','../../../../config/environment','../../../../config/logger','zoho','redis','localhost','socket.io-emitter','emit','[HTTP]','stringify','length','includes','string','picklist','idField','content','toString','type','variable','variableName','Variable','name','toLowerCase','indexOf'];(function(_0x26a10d,_0xe5c001){var _0xf90201=function(_0x48535b){while(--_0x48535b){_0x26a10d['push'](_0x26a10d['shift']());}};_0xf90201(++_0xe5c001);}(_0xc7fa,0x7a));var _0xac7f=function(_0x908601,_0x52d9ea){_0x908601=_0x908601-0x0;var _0xfda901=_0xc7fa[_0x908601];return _0xfda901;};'use strict';var _=require(_0xac7f('0x0'));var rp=require(_0xac7f('0x1'));var md5=require(_0xac7f('0x2'));var util=require('util');var intUtil=require('./util');var moment=require(_0xac7f('0x3'));var Redis=require(_0xac7f('0x4'));var BPromise=require(_0xac7f('0x5'));var config=require(_0xac7f('0x6'));var logger=require(_0xac7f('0x7'))(_0xac7f('0x8'));config[_0xac7f('0x9')]=_['defaults'](config[_0xac7f('0x9')],{'host':_0xac7f('0xa'),'port':0x18eb});var io=require(_0xac7f('0xb'))(new Redis(config['redis']));function emit(_0x45ce97,_0x4f64e0,_0x416913){io['to'](_0x45ce97)[_0xac7f('0xc')](_0x4f64e0,_0x416913);}function request(_0x13e001){logger['debug'](_0xac7f('0xd'),JSON[_0xac7f('0xe')](_0x13e001));return rp(_0x13e001);}function getCustomFields(_0x82277b,_0x1de1d4){var _0x1f74e5={};if(_0x82277b[_0xac7f('0xf')]>0x0){_['forEach'](_0x82277b,function(_0x474467){if(_[_0xac7f('0x10')]([_0xac7f('0x11'),_0xac7f('0x12')],_0x474467['type'])&&_0x474467['idField']){_0x1f74e5[_0x474467[_0xac7f('0x13')]]=_0x474467[_0xac7f('0x14')][_0xac7f('0x15')]();}else if(_0x474467[_0xac7f('0x16')]===_0xac7f('0x17')&&_0x474467[_0xac7f('0x18')]&&_0x474467[_0xac7f('0x13')]&&_0x1de1d4[_0x474467[_0xac7f('0x18')]]){_0x1f74e5[_0x474467['idField']]=_0x1de1d4[_0x474467[_0xac7f('0x18')]][_0xac7f('0x15')]();}else if(_0x474467[_0xac7f('0x16')]==='customVariable'&&_0x474467[_0xac7f('0x19')]&&_0x474467[_0xac7f('0x19')]['name']&&_0x474467['idField']&&_0x1de1d4[_0x474467[_0xac7f('0x19')][_0xac7f('0x1a')][_0xac7f('0x1b')]()]){_0x1f74e5[_0x474467['idField']]=_0x1de1d4[_0x474467[_0xac7f('0x19')][_0xac7f('0x1a')][_0xac7f('0x1b')]()]['toString']();}});}return _0x1f74e5;}function getName(_0x30a7e6){if(_0x30a7e6[_0xac7f('0x1c')]('\x20')>0x0){var _0x1b1b36=_0x30a7e6[_0xac7f('0x1d')](/ (.+)/);if(_0x1b1b36[0x1]){return _0x1b1b36;}}return[_0x30a7e6,_0x30a7e6];}var accountsTokens={};function getAccessToken(_0x129235){return new Promise(function(_0x425ebc,_0x3b49e9){if(!_[_0xac7f('0x1e')](accountsTokens[_0x129235['id']])&&!_[_0xac7f('0x1e')](accountsTokens[_0x129235['id']][_0xac7f('0x1f')])){if(moment()['isBefore'](accountsTokens[_0x129235['id']][_0xac7f('0x20')])){_0x425ebc(accountsTokens[_0x129235['id']][_0xac7f('0x1f')]);}}var _0x3a9421;switch(_0x129235[_0xac7f('0x21')]){case'US':_0x3a9421=_0xac7f('0x22');break;case'AU':_0x3a9421=_0xac7f('0x23');break;case'EU':_0x3a9421=_0xac7f('0x24');break;case'IN':_0x3a9421=_0xac7f('0x25');break;case'CN':_0x3a9421=_0xac7f('0x26');break;default:_0x3a9421=_0xac7f('0x24');break;}var _0x4c84e3={'method':_0xac7f('0x27'),'uri':_0x3a9421+_0xac7f('0x28'),'qs':{'refresh_token':_0x129235[_0xac7f('0x29')],'client_id':_0x129235[_0xac7f('0x2a')],'client_secret':_0x129235[_0xac7f('0x2b')],'grant_type':_0xac7f('0x2c')},'json':!![]};return rp(_0x4c84e3)['then'](function(_0x53fe0d){accountsTokens[_0x129235['id']]={'access_token':_0x53fe0d[_0xac7f('0x1f')],'expires_in':moment()[_0xac7f('0x2d')](_0x53fe0d['expires_in'],_0xac7f('0x2e'))};_0x425ebc(_0x53fe0d['access_token']);})['catch'](function(_0x3abbbe){logger[_0xac7f('0x2f')](_0xac7f('0x30'),_0x3abbbe['stack']);_0x3b49e9(_0x3abbbe);});});}function getUser(_0x3e8b05,_0x4a98e7,_0x453249,_0x5c75c2){logger[_0xac7f('0x31')]('Search\x20user');return request({'method':'GET','uri':util[_0xac7f('0x32')](_0xac7f('0x33'),_0x4a98e7),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':_0xac7f('0x34')+_0x3e8b05},'json':!![]})[_0xac7f('0x35')](function(_0x37d850){if(_0x37d850[_0xac7f('0x36')]){var _0x421c03=-0x1;if(_[_0xac7f('0x37')](_0x37d850[_0xac7f('0x36')])){if(!_[_0xac7f('0x1e')](_0x5c75c2)){_0x421c03=_[_0xac7f('0x38')](_0x37d850['users'],function(_0x5d8785){return _0x5d8785[_0xac7f('0x39')]===_0x5c75c2;});}if(_0x421c03>=0x0){logger[_0xac7f('0x31')](_0xac7f('0x3a'));}else{logger['info'](_0xac7f('0x3b'));_0x421c03=_[_0xac7f('0x38')](_0x37d850[_0xac7f('0x36')],function(_0x211dad){return _0x211dad[_0xac7f('0x3c')][_0xac7f('0x1a')]==='Administrator';});}return _0x37d850['users'][_0x421c03];}else{if(_0x37d850[_0xac7f('0x3d')][_0xac7f('0x3c')][_0xac7f('0x1a')]===_0xac7f('0x3e')){logger[_0xac7f('0x31')](_0xac7f('0x3b'));user=_0x37d850['user'];return user;}else{logger['error'](_0xac7f('0x3f'),JSON[_0xac7f('0xe')](_0x37d850));throw new Error(_0xac7f('0x40')+JSON['stringify'](_0x37d850));}}}else{logger[_0xac7f('0x2f')]('The\x20failing\x20result\x20is',JSON[_0xac7f('0xe')](_0x37d850));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0xac7f('0xe')](_0x37d850));}})['catch'](function(_0x336922){console['error'](_0x336922);});}function getZohoUser(_0x291c1a,_0x2bd7eb){return new BPromise(function(_0x41749c,_0x1c6f6b){request(_0x291c1a)[_0xac7f('0x35')](function(_0x455e80){var _0x34b1f7=null;if(_0x455e80){_0x34b1f7=_0x455e80[_0xac7f('0x41')][0x0];_0x34b1f7[_0xac7f('0x42')]=_0x2bd7eb;}_0x41749c(_0x34b1f7);})[_0xac7f('0x43')](function(_0x586814){_0x1c6f6b(_0x586814);});});}function createEndUser(_0x3ad4c8,_0x27f95d,_0x3eaca4,_0xec6bee,_0x1c71ef,_0x4a67fd){var _0x3eaca4=getName(_0x3eaca4);return request({'method':_0xac7f('0x27'),'uri':_0xac7f('0x44')+_0x27f95d+'/crm/v2/'+_[_0xac7f('0x45')](_0x4a67fd['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x3eaca4[0x1],'First_Name':_0x3eaca4[0x0],'Phone':_0xec6bee,'Owner':{'name':!_['isNil'](_0x1c71ef['role']['name'])?_0x1c71ef[_0xac7f('0x46')][_0xac7f('0x1a')]:!_[_0xac7f('0x1e')](_0x1c71ef[_0xac7f('0x47')])?_0x1c71ef[_0xac7f('0x47')]+'\x20'+_0x1c71ef['last_name']:_0x1c71ef[_0xac7f('0x48')],'id':_0x1c71ef['id']}}]},'headers':{'Authorization':_0xac7f('0x34')+_0x3ad4c8},'json':!![]})['then'](function(_0x207e66){if(_0x207e66&&_0x207e66[_0xac7f('0x41')][0x0][_0xac7f('0x49')]===_0xac7f('0x4a')){var _0x25f52a=_0x207e66[_0xac7f('0x41')][0x0][_0xac7f('0x4b')];_0x25f52a['enduserType']=_[_0xac7f('0x45')](_0x4a67fd['moduleCreate'])+'s';return _0x25f52a;}logger[_0xac7f('0x2f')](_0xac7f('0x3f'),JSON[_0xac7f('0xe')](data));throw new Error(_0xac7f('0x4c')+JSON['stringify'](data));})[_0xac7f('0x43')](function(_0x3ddca9){console[_0xac7f('0x4d')](_0xac7f('0x4e'),_0x3ddca9);});}function getEndUser(_0x29fe62,_0x2d1993,_0x3c8d59,_0x31d186,_0x1da256,_0x45b282,_0x40917e){var _0x23cc5f={'method':_0xac7f('0x4f'),'uri':'','headers':{'Authorization':_0xac7f('0x34')+_0x29fe62},'json':!![]};switch(_0x40917e['moduleSearch']){case _0xac7f('0x50'):_0x23cc5f['uri']=_0xac7f('0x44')+_0x2d1993+_0xac7f('0x51')+_0x1da256+'))';return getZohoUser(_0x23cc5f,'Contacts')['then'](function(_0x2fa759){if(_0x2fa759)return _0x2fa759;_0x23cc5f[_0xac7f('0x52')]=_0xac7f('0x44')+_0x2d1993+_0xac7f('0x53')+_0x1da256+'))';return getZohoUser(_0x23cc5f,'Leads')[_0xac7f('0x35')](function(_0x26ef1a){if(_0x26ef1a)return _0x26ef1a;if(_0x40917e['moduleCreate']!=_0xac7f('0x54')){return createEndUser(_0x29fe62,_0x2d1993,_0x31d186,_0x1da256,_0x45b282,_0x40917e);}else{return{};}});});break;case _0xac7f('0x55'):_0x23cc5f['uri']=_0xac7f('0x44')+_0x2d1993+_0xac7f('0x51')+_0x1da256+'))';return getZohoUser(_0x23cc5f,_0xac7f('0x56'))[_0xac7f('0x35')](function(_0x274892){if(_0x274892)return _0x274892;if(_0x40917e[_0xac7f('0x57')]!=_0xac7f('0x54')){return createEndUser(_0x29fe62,_0x2d1993,_0x31d186,_0x1da256,_0x45b282,_0x40917e);}else{return{};}});break;case _0xac7f('0x58'):_0x23cc5f['uri']=_0xac7f('0x44')+_0x2d1993+_0xac7f('0x53')+_0x1da256+'))';return getZohoUser(_0x23cc5f,'Leads')['then'](function(_0x14085a){if(_0x14085a)return _0x14085a;if(_0x40917e[_0xac7f('0x57')]!='nothing'){return createEndUser(_0x29fe62,_0x2d1993,_0x31d186,_0x1da256,_0x45b282,_0x40917e);}else{return{};}});break;}}function getCall(_0x17e7c4,_0x1e65d7,_0x5b1f2d,_0xc73e81,_0x460bfa,_0x200564,_0x4dad36,_0xd8dae5){logger['info']('Creating\x20new\x20call...');var _0x1366f9={};_0x1366f9[_0xac7f('0x59')]={'name':!_[_0xac7f('0x1e')](_0xc73e81[_0xac7f('0x46')][_0xac7f('0x1a')])&&!_[_0xac7f('0x1e')](_0xc73e81['profile'][_0xac7f('0x1a')])&&_0xc73e81[_0xac7f('0x3c')][_0xac7f('0x1a')]==='administrator'?_0xc73e81[_0xac7f('0x46')][_0xac7f('0x1a')]:!_['isNil'](_0xc73e81[_0xac7f('0x47')])?_0xc73e81[_0xac7f('0x47')]+'\x20'+_0xc73e81[_0xac7f('0x48')]:_0xc73e81[_0xac7f('0x48')],'id':_0xc73e81['id']};_0x1366f9['Subject']=intUtil[_0xac7f('0x5a')](_0x200564['Subjects'],_0x4dad36,'\x20');_0x1366f9['Description']=intUtil['getString'](_0x200564[_0xac7f('0x5b')],_0x4dad36,'\x0a');if(_0x460bfa[_0xac7f('0x42')]==='Contacts'){_0x1366f9[_0xac7f('0x5c')]={'name':!_[_0xac7f('0x1e')](_0x460bfa[_0xac7f('0x5d')])?_0x460bfa['Full_Name']:!_[_0xac7f('0x1e')](_0x460bfa[_0xac7f('0x5e')])?_0x460bfa[_0xac7f('0x5e')]+'\x20'+_0x460bfa[_0xac7f('0x5f')]:_0x460bfa[_0xac7f('0x5f')],'id':_0x460bfa['id']};}if(_0x460bfa[_0xac7f('0x42')]===_0xac7f('0x60')){_0x1366f9['What_Id']={'name':!_[_0xac7f('0x1e')](_0x460bfa[_0xac7f('0x5d')])?_0x460bfa['Full_Name']:!_[_0xac7f('0x1e')](_0x460bfa[_0xac7f('0x5e')])?_0x460bfa[_0xac7f('0x5e')]+'\x20'+_0x460bfa['Last_Name']:_0x460bfa[_0xac7f('0x5f')],'id':_0x460bfa['id']};_0x1366f9[_0xac7f('0x61')]=_[_0xac7f('0x45')](_0x460bfa[_0xac7f('0x42')]);}if(_0x4dad36[_0xac7f('0x62')]){_0x1366f9[_0xac7f('0x63')]=moment['utc'](parseInt(_0x4dad36[_0xac7f('0x62')])*0x3e8)[_0xac7f('0x32')](_0xac7f('0x64'));}else if(_0x4dad36['answertime']&&_0x4dad36[_0xac7f('0x65')]){_0x1366f9[_0xac7f('0x63')]=moment[_0xac7f('0x66')](moment(_0x4dad36[_0xac7f('0x65')],_0xac7f('0x67'))['diff'](moment(_0x4dad36[_0xac7f('0x68')],_0xac7f('0x67'))))[_0xac7f('0x32')](_0xac7f('0x64'));}switch(_0x4dad36[_0xac7f('0x69')]){case _0xac7f('0x6a'):_0x1366f9['Call_Result']='Called';break;case _0xac7f('0x6b'):case _0xac7f('0x6c'):_0x1366f9[_0xac7f('0x6d')]=_0xac7f('0x6e');break;case _0xac7f('0x6f'):_0x1366f9[_0xac7f('0x6d')]='Rejected';break;case _0xac7f('0x70'):_0x1366f9['Call_Result']=_0xac7f('0x71');break;case _0xac7f('0x72'):_0x1366f9[_0xac7f('0x6d')]='Timeout';default:}_0x1366f9[_0xac7f('0x73')]=(_0xd8dae5===_0xac7f('0x74')?moment(_0x4dad36[_0xac7f('0x68')])[_0xac7f('0x32')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x4dad36[_0xac7f('0x75')])[_0xac7f('0x32')]('YYYY-MM-DDTHH:mm:ss'))||moment()[_0xac7f('0x32')](_0xac7f('0x67'));_0x1366f9[_0xac7f('0x76')]=_0xd8dae5||_0xac7f('0x77');_0x1366f9=_['merge'](_0x1366f9,getCustomFields(_0x200564['Fields'],_0x4dad36));return request({'method':_0xac7f('0x27'),'uri':'https://www.zohoapis.'+_0x1e65d7+'/crm/v2/Calls','headers':{'Authorization':_0xac7f('0x34')+_0x17e7c4},'body':{'data':[_0x1366f9]},'json':!![]})[_0xac7f('0x35')](function(_0x5d6c75){if(_0x5d6c75&&_0x5d6c75[_0xac7f('0x41')][0x0][_0xac7f('0x49')]===_0xac7f('0x4a')){logger[_0xac7f('0x31')]('Call\x20created!');return{'id':_0x5d6c75[_0xac7f('0x41')][0x0][_0xac7f('0x4b')]['id']};}})[_0xac7f('0x43')](function(_0x3087f3){logger[_0xac7f('0x31')](_0xac7f('0x78'),_0x3087f3['stack']);console[_0xac7f('0x4d')](_0xac7f('0x78'),_0x3087f3);});}exports[_0xac7f('0x79')]=function(_0x244323,_0x481b13,_0x1d60e5,_0x11bdc9,_0x5a3b9b,_0xf801ee){var _0x1820a7,_0x57a5f3,_0xa47bd;_0xf801ee[_0xac7f('0x7a')]=intUtil[_0xac7f('0x7b')](_0xf801ee[_0xac7f('0x7a')]);_0xf801ee[_0xac7f('0x7c')]=intUtil['stripTrailingSlash'](_0xf801ee['serverUrl']);if(_0x5a3b9b&&_0x5a3b9b[_0xac7f('0x7d')]){logger[_0xac7f('0x31')]('[QUEUE]',_0xac7f('0x7e'));_0x481b13[_0xac7f('0x7f')]=_0xf801ee['serverUrl']+'/api/voice/recordings/'+_0x481b13[_0xac7f('0x80')]+_0xac7f('0x81')+md5(_0x481b13['uniqueid']);}else{_0x481b13[_0xac7f('0x7f')]='';}var _0xa611e=_0xf801ee['host']==='zoho.eu'?'eu':'com';return getAccessToken(_0xf801ee)[_0xac7f('0x35')](function(_0xe8cade){_0xa47bd=_0xe8cade;return getUser(_0xa47bd,_0xa611e,_0xf801ee,_0x11bdc9[_0xac7f('0x39')]);})[_0xac7f('0x35')](function(_0x3cf30b){_0x1820a7=_0x3cf30b;logger[_0xac7f('0x31')]('The\x20User\x20ID\x20is:',_0x1820a7['id']);return getEndUser(_0xa47bd,_0xa611e,_0xf801ee,_0x481b13['calleridname'],_0x481b13[_0xac7f('0x82')],_0x1820a7,_0x1d60e5);})[_0xac7f('0x35')](function(_0x50c2d1){_0x57a5f3=_0x50c2d1;return getCall(_0xa47bd,_0xa611e,_0xf801ee,_0x1820a7,_0x57a5f3,_0x1d60e5,_0x481b13,_0xac7f('0x77'));})[_0xac7f('0x35')](function(_0x435bdf){if(_0x435bdf){logger['info'](_0xac7f('0x83'),_0x435bdf['id']);logger[_0xac7f('0x31')](_0xac7f('0x84'),_0xac7f('0x85'));emit(util[_0xac7f('0x32')](_0xac7f('0x86'),_0x11bdc9[_0xac7f('0x1a')]),_0xac7f('0x87'),{'uri':_0xac7f('0x88')+_0xf801ee['host']+_0xac7f('0x89')+_0x435bdf['id']});}})[_0xac7f('0x43')](function(_0x190952){logger[_0xac7f('0x2f')](_0xac7f('0x84'),JSON[_0xac7f('0xe')](_0x190952));});};exports['outbound']=function(_0x16bc29,_0x465e7f,_0x131ab4,_0x3b8853,_0x178edb,_0x10ffba,_0x302165){var _0x2af26e,_0x3de6d7,_0x56cd5d;_0x10ffba[_0xac7f('0x7a')]=intUtil[_0xac7f('0x7b')](_0x10ffba['host']);_0x10ffba[_0xac7f('0x7c')]=intUtil[_0xac7f('0x7b')](_0x10ffba['serverUrl']);if(_0x302165&&_0x302165[_0xac7f('0x8a')]&&_0x302165[_0xac7f('0x8a')]!==_0xac7f('0x8b')){logger['info'](_0xac7f('0x8c'),_0xac7f('0x7e'));_0x465e7f['recordingURL']=_0x10ffba[_0xac7f('0x7c')]+_0xac7f('0x8d')+_0x465e7f['uniqueid']+_0xac7f('0x81')+md5(_0x465e7f[_0xac7f('0x80')]);}var _0x51e949=_0x10ffba[_0xac7f('0x7a')]===_0xac7f('0x8e')?'eu':_0xac7f('0x8f');return getAccessToken(_0x10ffba)[_0xac7f('0x35')](function(_0x1d8fc1){_0x56cd5d=_0x1d8fc1;return getUser(_0x56cd5d,_0x51e949,_0x10ffba,_0x3b8853[_0xac7f('0x39')]);})[_0xac7f('0x35')](function(_0x4b8436){_0x2af26e=_0x4b8436;logger[_0xac7f('0x31')](_0xac7f('0x90'),_0x2af26e['id']);return getEndUser(_0x56cd5d,_0x51e949,_0x10ffba,_0x465e7f[_0xac7f('0x91')],_0x465e7f[_0xac7f('0x92')],_0x2af26e,_0x131ab4);})[_0xac7f('0x35')](function(_0x444cd3){_0x3de6d7=_0x444cd3;return getCall(_0x56cd5d,_0x51e949,_0x10ffba,_0x2af26e,_0x3de6d7,_0x131ab4,_0x465e7f,_0xac7f('0x93'));})[_0xac7f('0x35')](function(_0x123f43){if(_0x123f43){logger[_0xac7f('0x31')]('The\x20Call\x20ID\x20is:',_0x123f43['id']);logger[_0xac7f('0x31')](_0xac7f('0x8c'),_0xac7f('0x85'));emit(util[_0xac7f('0x32')](_0xac7f('0x86'),_0x3b8853['name']),_0xac7f('0x87'),{'uri':_0xac7f('0x88')+_0x10ffba['host']+_0xac7f('0x89')+_0x123f43['id']});}})[_0xac7f('0x43')](function(_0x15c022){logger['error'](_0xac7f('0x8c'),JSON[_0xac7f('0xe')](_0x15c022));});};exports[_0xac7f('0x94')]=function(_0x3af4ea,_0x93915d,_0x27b930,_0x5a4c12,_0x1aa7d0,_0x133982){var _0x1ad963,_0x265ebf,_0x40e543;_0x133982['host']=intUtil[_0xac7f('0x7b')](_0x133982['host']);_0x133982[_0xac7f('0x7c')]=intUtil[_0xac7f('0x7b')](_0x133982['serverUrl']);if(_0x1aa7d0&&_0x1aa7d0[_0xac7f('0x7d')]){logger['info']('['+_0x93915d[_0xac7f('0x69')][_0xac7f('0x95')]()+']','Recording\x20is\x20enabled!');_0x93915d[_0xac7f('0x7f')]=_0x133982[_0xac7f('0x7c')]+_0xac7f('0x8d')+_0x93915d['uniqueid']+_0xac7f('0x81')+md5(_0x93915d[_0xac7f('0x80')]);}else{_0x93915d['recordingURL']='';}var _0x51d11b=_0x133982[_0xac7f('0x7a')]===_0xac7f('0x8e')?'eu':_0xac7f('0x8f');return getAccessToken(_0x133982)[_0xac7f('0x35')](function(_0x282de9){_0x40e543=_0x282de9;return getUser(_0x40e543,_0x51d11b,_0x133982);})[_0xac7f('0x35')](function(_0x57f6d7){_0x1ad963=_0x57f6d7;logger['info']('The\x20User\x20ID\x20is:',_0x1ad963['id']);return getEndUser(_0x40e543,_0x51d11b,_0x133982,_0x93915d[_0xac7f('0x96')],_0x93915d[_0xac7f('0x82')],_0x1ad963,_0x27b930);})['then'](function(_0x4a9e28){_0x265ebf=_0x4a9e28;return getCall(_0x40e543,_0x51d11b,_0x133982,_0x1ad963,_0x265ebf,_0x27b930,_0x93915d,_0xac7f('0x77'));})[_0xac7f('0x35')](function(_0x3c5948){if(_0x3c5948){logger[_0xac7f('0x31')]('The\x20Call\x20ID\x20is:',_0x3c5948['id']);}})['catch'](function(_0x3b089b){logger[_0xac7f('0x2f')]('['+_0x93915d['lastevent'][_0xac7f('0x95')]()+']',JSON['stringify'](_0x3b089b));});};