Built motion from commit 3c2ce842.|2.6.31
[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 _0xf547=['variable','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','access_token','isBefore','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','/oauth/v2/token','refreshToken','clientId','clientSecret','refresh_token','add','catch','error','Failing\x20creating\x20the\x20access_token','info','Search\x20user','GET','ActiveUsers','Zoho-oauthtoken\x20','then','users','findIndex','email','Using\x20the\x20admin\x20account!','profile','Administrator','user','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','POST','startCase','role','first_name','last_name','code','SUCCESS','details','moduleCreate','Error:\x20','CREATE\x20ERROR','contact_lead','uri','https://www.zohoapis.','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','Leads','Creating\x20new\x20call...','Owner','administrator','Subject','getString','Subjects','Description','Descriptions','Full_Name','First_Name','Last_Name','What_Id','$se_module','Call_Duration','utc','format','answertime','endtime','YYYY-MM-DDTHH:mm:ss','diff','starttime','lastevent','Called','complete','Answered','Call_Result','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','stack','log','host','serverUrl','stripTrailingSlash','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/api/voice/recordings/','/downloads?type=uniqueid&token=','uniqueid','zoho.eu','com','The\x20User\x20ID\x20is:','calleridname','user:%s','trigger:browser:url','https://crm.','outbound','recordingFormat','[OUTBOUND]','destcalleridname','destcalleridnum','Outbound','The\x20Call\x20ID\x20is:','/crm/EntityInfo.do?module=Calls&id=','unmanaged','toUpperCase','calleridnum','lodash','request-promise','md5','./util','ioredis','bluebird','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','socket.io-emitter','emit','debug','stringify','length','forEach','includes','string','picklist','type','idField','content'];(function(_0xefd519,_0xc62635){var _0x4bb882=function(_0x37e0a1){while(--_0x37e0a1){_0xefd519['push'](_0xefd519['shift']());}};_0x4bb882(++_0xc62635);}(_0xf547,0x1b7));var _0x7f54=function(_0x187ee1,_0x3fd1e6){_0x187ee1=_0x187ee1-0x0;var _0x388160=_0xf547[_0x187ee1];return _0x388160;};'use strict';var _=require(_0x7f54('0x0'));var rp=require(_0x7f54('0x1'));var md5=require(_0x7f54('0x2'));var util=require('util');var intUtil=require(_0x7f54('0x3'));var moment=require('moment');var Redis=require(_0x7f54('0x4'));var BPromise=require(_0x7f54('0x5'));var config=require(_0x7f54('0x6'));var logger=require(_0x7f54('0x7'))('zoho');config[_0x7f54('0x8')]=_[_0x7f54('0x9')](config['redis'],{'host':_0x7f54('0xa'),'port':0x18eb});var io=require(_0x7f54('0xb'))(new Redis(config[_0x7f54('0x8')]));function emit(_0x7f3055,_0x18c7a9,_0x2799ef){io['to'](_0x7f3055)[_0x7f54('0xc')](_0x18c7a9,_0x2799ef);}function request(_0x183c25){logger[_0x7f54('0xd')]('[HTTP]',JSON[_0x7f54('0xe')](_0x183c25));return rp(_0x183c25);}function getCustomFields(_0x323d3c,_0x5696fe){var _0x3f88e3={};if(_0x323d3c[_0x7f54('0xf')]>0x0){_[_0x7f54('0x10')](_0x323d3c,function(_0x284691){if(_[_0x7f54('0x11')]([_0x7f54('0x12'),_0x7f54('0x13')],_0x284691[_0x7f54('0x14')])&&_0x284691[_0x7f54('0x15')]){_0x3f88e3[_0x284691[_0x7f54('0x15')]]=_0x284691[_0x7f54('0x16')]['toString']();}else if(_0x284691['type']===_0x7f54('0x17')&&_0x284691[_0x7f54('0x18')]&&_0x284691[_0x7f54('0x15')]&&_0x5696fe[_0x284691[_0x7f54('0x18')]]){_0x3f88e3[_0x284691[_0x7f54('0x15')]]=_0x5696fe[_0x284691[_0x7f54('0x18')]]['toString']();}else if(_0x284691[_0x7f54('0x14')]===_0x7f54('0x19')&&_0x284691[_0x7f54('0x1a')]&&_0x284691[_0x7f54('0x1a')]['name']&&_0x284691['idField']&&_0x5696fe[_0x284691[_0x7f54('0x1a')][_0x7f54('0x1b')][_0x7f54('0x1c')]()]){_0x3f88e3[_0x284691['idField']]=_0x5696fe[_0x284691[_0x7f54('0x1a')]['name'][_0x7f54('0x1c')]()]['toString']();}});}return _0x3f88e3;}function getName(_0x429db1){if(_0x429db1[_0x7f54('0x1d')]('\x20')>0x0){var _0x59c83e=_0x429db1[_0x7f54('0x1e')](/ (.+)/);if(_0x59c83e[0x1]){return _0x59c83e;}}return[_0x429db1,_0x429db1];}var accountsTokens={};function getAccessToken(_0x27b462){return new Promise(function(_0x137360,_0x44a269){if(!_[_0x7f54('0x1f')](accountsTokens[_0x27b462['id']])&&!_[_0x7f54('0x1f')](accountsTokens[_0x27b462['id']][_0x7f54('0x20')])){if(moment()[_0x7f54('0x21')](accountsTokens[_0x27b462['id']][_0x7f54('0x22')])){_0x137360(accountsTokens[_0x27b462['id']][_0x7f54('0x20')]);}}var _0x4c7c0a;switch(_0x27b462[_0x7f54('0x23')]){case'US':_0x4c7c0a=_0x7f54('0x24');break;case'AU':_0x4c7c0a=_0x7f54('0x25');break;case'EU':_0x4c7c0a=_0x7f54('0x26');break;case'IN':_0x4c7c0a=_0x7f54('0x27');break;case'CN':_0x4c7c0a=_0x7f54('0x28');break;default:_0x4c7c0a=_0x7f54('0x26');break;}var _0x38e73d={'method':'POST','uri':_0x4c7c0a+_0x7f54('0x29'),'qs':{'refresh_token':_0x27b462[_0x7f54('0x2a')],'client_id':_0x27b462[_0x7f54('0x2b')],'client_secret':_0x27b462[_0x7f54('0x2c')],'grant_type':_0x7f54('0x2d')},'json':!![]};return rp(_0x38e73d)['then'](function(_0x1c8e4d){accountsTokens[_0x27b462['id']]={'access_token':_0x1c8e4d[_0x7f54('0x20')],'expires_in':moment()[_0x7f54('0x2e')](_0x1c8e4d[_0x7f54('0x22')],'seconds')};_0x137360(_0x1c8e4d[_0x7f54('0x20')]);})[_0x7f54('0x2f')](function(_0x47be17){logger[_0x7f54('0x30')](_0x7f54('0x31'),_0x47be17['stack']);_0x44a269(_0x47be17);});});}function getUser(_0x2fe61b,_0x3713b8,_0x2d5bdc,_0x16cfbf){logger[_0x7f54('0x32')](_0x7f54('0x33'));return request({'method':_0x7f54('0x34'),'uri':util['format']('https://www.zohoapis.%s/crm/v2/users',_0x3713b8),'qs':{'type':_0x7f54('0x35')},'headers':{'Authorization':_0x7f54('0x36')+_0x2fe61b},'json':!![]})[_0x7f54('0x37')](function(_0x1ab51d){if(_0x1ab51d['users']){var _0x317cef=-0x1;if(_['isArrayLikeObject'](_0x1ab51d[_0x7f54('0x38')])){if(!_[_0x7f54('0x1f')](_0x16cfbf)){_0x317cef=_[_0x7f54('0x39')](_0x1ab51d[_0x7f54('0x38')],function(_0xa37237){return _0xa37237[_0x7f54('0x3a')]===_0x16cfbf;});}if(_0x317cef>=0x0){logger[_0x7f54('0x32')]('Agent\x20found!');}else{logger[_0x7f54('0x32')](_0x7f54('0x3b'));_0x317cef=_['findIndex'](_0x1ab51d[_0x7f54('0x38')],function(_0x3ccaa4){return _0x3ccaa4[_0x7f54('0x3c')][_0x7f54('0x1b')]===_0x7f54('0x3d');});}return _0x1ab51d[_0x7f54('0x38')][_0x317cef];}else{if(_0x1ab51d[_0x7f54('0x3e')][_0x7f54('0x3c')][_0x7f54('0x1b')]===_0x7f54('0x3d')){logger['info'](_0x7f54('0x3b'));user=_0x1ab51d[_0x7f54('0x3e')];return user;}else{logger[_0x7f54('0x30')](_0x7f54('0x3f'),JSON[_0x7f54('0xe')](_0x1ab51d));throw new Error(_0x7f54('0x40')+JSON[_0x7f54('0xe')](_0x1ab51d));}}}else{logger[_0x7f54('0x30')]('The\x20failing\x20result\x20is',JSON[_0x7f54('0xe')](_0x1ab51d));throw new Error(_0x7f54('0x40')+JSON[_0x7f54('0xe')](_0x1ab51d));}})[_0x7f54('0x2f')](function(_0x3c3ae9){console[_0x7f54('0x30')](_0x3c3ae9);});}function getZohoUser(_0x3ce1b2,_0xcd1591){return new BPromise(function(_0x3df367,_0x2a5ae8){request(_0x3ce1b2)[_0x7f54('0x37')](function(_0x1f9de6){var _0x240b4d=null;if(_0x1f9de6){_0x240b4d=_0x1f9de6[_0x7f54('0x41')][0x0];_0x240b4d[_0x7f54('0x42')]=_0xcd1591;}_0x3df367(_0x240b4d);})[_0x7f54('0x2f')](function(_0x38ea48){_0x2a5ae8(_0x38ea48);});});}function createEndUser(_0x59b13f,_0xbe16d1,_0x4a3b5a,_0x427aee,_0x7f0afa,_0x40599f){var _0x4a3b5a=getName(_0x4a3b5a);return request({'method':_0x7f54('0x43'),'uri':'https://www.zohoapis.'+_0xbe16d1+'/crm/v2/'+_[_0x7f54('0x44')](_0x40599f['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x4a3b5a[0x1],'First_Name':_0x4a3b5a[0x0],'Phone':_0x427aee,'Owner':{'name':!_['isNil'](_0x7f0afa[_0x7f54('0x45')][_0x7f54('0x1b')])?_0x7f0afa[_0x7f54('0x45')][_0x7f54('0x1b')]:!_[_0x7f54('0x1f')](_0x7f0afa['first_name'])?_0x7f0afa[_0x7f54('0x46')]+'\x20'+_0x7f0afa[_0x7f54('0x47')]:_0x7f0afa[_0x7f54('0x47')],'id':_0x7f0afa['id']}}]},'headers':{'Authorization':_0x7f54('0x36')+_0x59b13f},'json':!![]})[_0x7f54('0x37')](function(_0x13ed05){if(_0x13ed05&&_0x13ed05[_0x7f54('0x41')][0x0][_0x7f54('0x48')]===_0x7f54('0x49')){var _0x1f209b=_0x13ed05[_0x7f54('0x41')][0x0][_0x7f54('0x4a')];_0x1f209b[_0x7f54('0x42')]=_['startCase'](_0x40599f[_0x7f54('0x4b')])+'s';return _0x1f209b;}logger['error']('The\x20failing\x20result\x20is',JSON[_0x7f54('0xe')](data));throw new Error(_0x7f54('0x4c')+JSON[_0x7f54('0xe')](data));})[_0x7f54('0x2f')](function(_0x38e33e){console['log'](_0x7f54('0x4d'),_0x38e33e);});}function getEndUser(_0x415f36,_0x4d00c2,_0x5ef375,_0x336c54,_0x477e25,_0x182ffc,_0x528a25){var _0x45d400={'method':_0x7f54('0x34'),'uri':'','headers':{'Authorization':_0x7f54('0x36')+_0x415f36},'json':!![]};switch(_0x528a25['moduleSearch']){case _0x7f54('0x4e'):_0x45d400[_0x7f54('0x4f')]=_0x7f54('0x50')+_0x4d00c2+_0x7f54('0x51')+_0x477e25+'))';return getZohoUser(_0x45d400,_0x7f54('0x52'))[_0x7f54('0x37')](function(_0xa8a304){if(_0xa8a304)return _0xa8a304;_0x45d400[_0x7f54('0x4f')]=_0x7f54('0x50')+_0x4d00c2+_0x7f54('0x53')+_0x477e25+'))';return getZohoUser(_0x45d400,'Leads')['then'](function(_0x51d76c){if(_0x51d76c)return _0x51d76c;if(_0x528a25[_0x7f54('0x4b')]!=_0x7f54('0x54')){return createEndUser(_0x415f36,_0x4d00c2,_0x336c54,_0x477e25,_0x182ffc,_0x528a25);}else{return{};}});});break;case _0x7f54('0x55'):_0x45d400[_0x7f54('0x4f')]=_0x7f54('0x50')+_0x4d00c2+_0x7f54('0x51')+_0x477e25+'))';return getZohoUser(_0x45d400,_0x7f54('0x52'))[_0x7f54('0x37')](function(_0x4fb8e7){if(_0x4fb8e7)return _0x4fb8e7;if(_0x528a25['moduleCreate']!=_0x7f54('0x54')){return createEndUser(_0x415f36,_0x4d00c2,_0x336c54,_0x477e25,_0x182ffc,_0x528a25);}else{return{};}});break;case'lead':_0x45d400[_0x7f54('0x4f')]='https://www.zohoapis.'+_0x4d00c2+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x477e25+'))';return getZohoUser(_0x45d400,_0x7f54('0x56'))['then'](function(_0x2e7050){if(_0x2e7050)return _0x2e7050;if(_0x528a25[_0x7f54('0x4b')]!=_0x7f54('0x54')){return createEndUser(_0x415f36,_0x4d00c2,_0x336c54,_0x477e25,_0x182ffc,_0x528a25);}else{return{};}});break;}}function getCall(_0x4a1fc8,_0x22231e,_0x225ff9,_0x3ba0d2,_0x10b81a,_0x548400,_0x3d8452,_0x59864d){logger['info'](_0x7f54('0x57'));var _0x57e5da={};_0x57e5da[_0x7f54('0x58')]={'name':!_[_0x7f54('0x1f')](_0x3ba0d2[_0x7f54('0x45')][_0x7f54('0x1b')])&&!_[_0x7f54('0x1f')](_0x3ba0d2[_0x7f54('0x3c')][_0x7f54('0x1b')])&&_0x3ba0d2[_0x7f54('0x3c')][_0x7f54('0x1b')]===_0x7f54('0x59')?_0x3ba0d2[_0x7f54('0x45')]['name']:!_[_0x7f54('0x1f')](_0x3ba0d2[_0x7f54('0x46')])?_0x3ba0d2[_0x7f54('0x46')]+'\x20'+_0x3ba0d2[_0x7f54('0x47')]:_0x3ba0d2[_0x7f54('0x47')],'id':_0x3ba0d2['id']};_0x57e5da[_0x7f54('0x5a')]=intUtil[_0x7f54('0x5b')](_0x548400[_0x7f54('0x5c')],_0x3d8452,'\x20');_0x57e5da[_0x7f54('0x5d')]=intUtil[_0x7f54('0x5b')](_0x548400[_0x7f54('0x5e')],_0x3d8452,'\x0a');if(_0x10b81a[_0x7f54('0x42')]===_0x7f54('0x52')){_0x57e5da['Who_Id']={'name':!_[_0x7f54('0x1f')](_0x10b81a[_0x7f54('0x5f')])?_0x10b81a[_0x7f54('0x5f')]:!_['isNil'](_0x10b81a['First_Name'])?_0x10b81a[_0x7f54('0x60')]+'\x20'+_0x10b81a[_0x7f54('0x61')]:_0x10b81a[_0x7f54('0x61')],'id':_0x10b81a['id']};}if(_0x10b81a['enduserType']===_0x7f54('0x56')){_0x57e5da[_0x7f54('0x62')]={'name':!_[_0x7f54('0x1f')](_0x10b81a['Full_Name'])?_0x10b81a['Full_Name']:!_[_0x7f54('0x1f')](_0x10b81a['First_Name'])?_0x10b81a['First_Name']+'\x20'+_0x10b81a[_0x7f54('0x61')]:_0x10b81a[_0x7f54('0x61')],'id':_0x10b81a['id']};_0x57e5da[_0x7f54('0x63')]=_[_0x7f54('0x44')](_0x10b81a[_0x7f54('0x42')]);}if(_0x3d8452['talktime']){_0x57e5da[_0x7f54('0x64')]=moment[_0x7f54('0x65')](parseInt(_0x3d8452['talktime'])*0x3e8)[_0x7f54('0x66')]('mm:ss');}else if(_0x3d8452[_0x7f54('0x67')]&&_0x3d8452[_0x7f54('0x68')]){_0x57e5da[_0x7f54('0x64')]=moment[_0x7f54('0x65')](moment(_0x3d8452[_0x7f54('0x68')],_0x7f54('0x69'))[_0x7f54('0x6a')](moment(_0x3d8452[_0x7f54('0x6b')],'YYYY-MM-DDTHH:mm:ss')))['format']('mm:ss');}switch(_0x3d8452[_0x7f54('0x6c')]){case'called':_0x57e5da['Call_Result']=_0x7f54('0x6d');break;case _0x7f54('0x6e'):case'connect':_0x57e5da['Call_Result']=_0x7f54('0x6f');break;case'rejected':_0x57e5da[_0x7f54('0x70')]='Rejected';break;case _0x7f54('0x71'):_0x57e5da[_0x7f54('0x70')]=_0x7f54('0x72');break;case _0x7f54('0x73'):_0x57e5da['Call_Result']=_0x7f54('0x74');default:}_0x57e5da[_0x7f54('0x75')]=(_0x59864d==='outbound'?moment(_0x3d8452[_0x7f54('0x6b')])[_0x7f54('0x66')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x3d8452['agentcalledAt'])[_0x7f54('0x66')](_0x7f54('0x69')))||moment()[_0x7f54('0x66')](_0x7f54('0x69'));_0x57e5da[_0x7f54('0x76')]=_0x59864d||_0x7f54('0x77');_0x57e5da=_[_0x7f54('0x78')](_0x57e5da,getCustomFields(_0x548400[_0x7f54('0x79')],_0x3d8452));return request({'method':'POST','uri':_0x7f54('0x50')+_0x22231e+_0x7f54('0x7a'),'headers':{'Authorization':_0x7f54('0x36')+_0x4a1fc8},'body':{'data':[_0x57e5da]},'json':!![]})['then'](function(_0xe511a6){if(_0xe511a6&&_0xe511a6[_0x7f54('0x41')][0x0][_0x7f54('0x48')]===_0x7f54('0x49')){logger['info'](_0x7f54('0x7b'));return{'id':_0xe511a6['data'][0x0][_0x7f54('0x4a')]['id']};}})[_0x7f54('0x2f')](function(_0x13675f){logger['info']('err',_0x13675f[_0x7f54('0x7c')]);console[_0x7f54('0x7d')]('err',_0x13675f);});}exports['queue']=function(_0x29240f,_0x5685df,_0x30ec2d,_0x5758aa,_0x7afe9b,_0x1cda56){var _0xf3352f,_0xf465d,_0xca0fa8;_0x1cda56[_0x7f54('0x7e')]=intUtil['stripTrailingSlash'](_0x1cda56['host']);_0x1cda56[_0x7f54('0x7f')]=intUtil[_0x7f54('0x80')](_0x1cda56[_0x7f54('0x7f')]);if(_0x7afe9b&&_0x7afe9b[_0x7f54('0x81')]){logger[_0x7f54('0x32')](_0x7f54('0x82'),_0x7f54('0x83'));_0x5685df[_0x7f54('0x84')]=_0x1cda56[_0x7f54('0x7f')]+_0x7f54('0x85')+_0x5685df['uniqueid']+_0x7f54('0x86')+md5(_0x5685df[_0x7f54('0x87')]);}else{_0x5685df[_0x7f54('0x84')]='';}var _0x4d677b=_0x1cda56[_0x7f54('0x7e')]===_0x7f54('0x88')?'eu':_0x7f54('0x89');return getAccessToken(_0x1cda56)[_0x7f54('0x37')](function(_0x1f9a70){_0xca0fa8=_0x1f9a70;return getUser(_0xca0fa8,_0x4d677b,_0x1cda56,_0x5758aa[_0x7f54('0x3a')]);})['then'](function(_0x3b3774){_0xf3352f=_0x3b3774;logger[_0x7f54('0x32')](_0x7f54('0x8a'),_0xf3352f['id']);return getEndUser(_0xca0fa8,_0x4d677b,_0x1cda56,_0x5685df[_0x7f54('0x8b')],_0x5685df['calleridnum'],_0xf3352f,_0x30ec2d);})[_0x7f54('0x37')](function(_0x3e4b81){_0xf465d=_0x3e4b81;return getCall(_0xca0fa8,_0x4d677b,_0x1cda56,_0xf3352f,_0xf465d,_0x30ec2d,_0x5685df,_0x7f54('0x77'));})[_0x7f54('0x37')](function(_0x21f9d4){if(_0x21f9d4){logger[_0x7f54('0x32')]('The\x20Call\x20ID\x20is:',_0x21f9d4['id']);logger[_0x7f54('0x32')](_0x7f54('0x82'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x7f54('0x66')](_0x7f54('0x8c'),_0x5758aa[_0x7f54('0x1b')]),_0x7f54('0x8d'),{'uri':_0x7f54('0x8e')+_0x1cda56['host']+'/crm/EntityInfo.do?module=Calls&id='+_0x21f9d4['id']});}})['catch'](function(_0x42107e){logger[_0x7f54('0x30')]('[QUEUE]',JSON[_0x7f54('0xe')](_0x42107e));});};exports[_0x7f54('0x8f')]=function(_0x18fd82,_0x394c03,_0x335fca,_0x4ac588,_0x3ae50f,_0x49d0f2,_0x78b619){var _0x9677d6,_0x2590b2,_0xba1a36;_0x49d0f2[_0x7f54('0x7e')]=intUtil['stripTrailingSlash'](_0x49d0f2['host']);_0x49d0f2[_0x7f54('0x7f')]=intUtil[_0x7f54('0x80')](_0x49d0f2[_0x7f54('0x7f')]);if(_0x78b619&&_0x78b619['recordingFormat']&&_0x78b619[_0x7f54('0x90')]!=='none'){logger[_0x7f54('0x32')](_0x7f54('0x91'),_0x7f54('0x83'));_0x394c03['recordingURL']=_0x49d0f2['serverUrl']+_0x7f54('0x85')+_0x394c03[_0x7f54('0x87')]+'/downloads?type=uniqueid&token='+md5(_0x394c03[_0x7f54('0x87')]);}var _0x4132a1=_0x49d0f2[_0x7f54('0x7e')]===_0x7f54('0x88')?'eu':_0x7f54('0x89');return getAccessToken(_0x49d0f2)['then'](function(_0x4f390){_0xba1a36=_0x4f390;return getUser(_0xba1a36,_0x4132a1,_0x49d0f2,_0x4ac588[_0x7f54('0x3a')]);})['then'](function(_0x18a3cd){_0x9677d6=_0x18a3cd;logger[_0x7f54('0x32')](_0x7f54('0x8a'),_0x9677d6['id']);return getEndUser(_0xba1a36,_0x4132a1,_0x49d0f2,_0x394c03[_0x7f54('0x92')],_0x394c03[_0x7f54('0x93')],_0x9677d6,_0x335fca);})[_0x7f54('0x37')](function(_0x40607f){_0x2590b2=_0x40607f;return getCall(_0xba1a36,_0x4132a1,_0x49d0f2,_0x9677d6,_0x2590b2,_0x335fca,_0x394c03,_0x7f54('0x94'));})[_0x7f54('0x37')](function(_0x5ccc41){if(_0x5ccc41){logger['info'](_0x7f54('0x95'),_0x5ccc41['id']);logger[_0x7f54('0x32')](_0x7f54('0x91'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x7f54('0x66')](_0x7f54('0x8c'),_0x4ac588[_0x7f54('0x1b')]),'trigger:browser:url',{'uri':'https://crm.'+_0x49d0f2[_0x7f54('0x7e')]+_0x7f54('0x96')+_0x5ccc41['id']});}})['catch'](function(_0x5169d7){logger[_0x7f54('0x30')](_0x7f54('0x91'),JSON[_0x7f54('0xe')](_0x5169d7));});};exports[_0x7f54('0x97')]=function(_0x158187,_0x44a7fc,_0x352778,_0x47d02d,_0x54270a,_0x3d3ff6){var _0x11f42b,_0x365b8b,_0x267742;_0x3d3ff6['host']=intUtil[_0x7f54('0x80')](_0x3d3ff6[_0x7f54('0x7e')]);_0x3d3ff6['serverUrl']=intUtil['stripTrailingSlash'](_0x3d3ff6[_0x7f54('0x7f')]);if(_0x54270a&&_0x54270a[_0x7f54('0x81')]){logger['info']('['+_0x44a7fc[_0x7f54('0x6c')][_0x7f54('0x98')]()+']','Recording\x20is\x20enabled!');_0x44a7fc[_0x7f54('0x84')]=_0x3d3ff6['serverUrl']+'/api/voice/recordings/'+_0x44a7fc[_0x7f54('0x87')]+_0x7f54('0x86')+md5(_0x44a7fc[_0x7f54('0x87')]);}else{_0x44a7fc[_0x7f54('0x84')]='';}var _0x3f8065=_0x3d3ff6[_0x7f54('0x7e')]===_0x7f54('0x88')?'eu':_0x7f54('0x89');return getAccessToken(_0x3d3ff6)[_0x7f54('0x37')](function(_0x593eb7){_0x267742=_0x593eb7;return getUser(_0x267742,_0x3f8065,_0x3d3ff6);})[_0x7f54('0x37')](function(_0x1cf714){_0x11f42b=_0x1cf714;logger[_0x7f54('0x32')](_0x7f54('0x8a'),_0x11f42b['id']);return getEndUser(_0x267742,_0x3f8065,_0x3d3ff6,_0x44a7fc['calleridname'],_0x44a7fc[_0x7f54('0x99')],_0x11f42b,_0x352778);})[_0x7f54('0x37')](function(_0x14ed06){_0x365b8b=_0x14ed06;return getCall(_0x267742,_0x3f8065,_0x3d3ff6,_0x11f42b,_0x365b8b,_0x352778,_0x44a7fc,'Inbound');})[_0x7f54('0x37')](function(_0x41e4f1){if(_0x41e4f1){logger[_0x7f54('0x32')](_0x7f54('0x95'),_0x41e4f1['id']);}})[_0x7f54('0x2f')](function(_0x544280){logger[_0x7f54('0x30')]('['+_0x44a7fc[_0x7f54('0x6c')][_0x7f54('0x98')]()+']',JSON[_0x7f54('0xe')](_0x544280));});};