Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index e4870e6..b56aaea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x34e2=['defaults','localhost','socket.io-emitter','redis','emit','debug','stringify','length','forEach','includes','idField','content','toString','variable','variableName','type','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','access_token','isBefore','https://accounts.zoho.com.au','https://accounts.zoho.com.cn','https://accounts.zoho.eu','/oauth/v2/token','clientId','refresh_token','then','add','expires_in','seconds','catch','error','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','users','findIndex','email','info','profile','Using\x20the\x20admin\x20account!','user','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','code','SUCCESS','details','enduserType','Error:\x20','log','CREATE\x20ERROR','contact_lead','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','uri','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','nothing','lead','Creating\x20new\x20call...','Owner','administrator','Subject','getString','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','What_Id','$se_module','utc','answertime','YYYY-MM-DDTHH:mm:ss','diff','starttime','lastevent','called','Call_Result','Called','Answered','rejected','Rejected','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','Inbound','merge','Fields','POST','/crm/v2/Calls','Call\x20created!','err','stack','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','destcalleridnum','Outbound','[OUTBOUND]','https://crm.','unmanaged','/api/voice/recordings/','toUpperCase','lodash','md5','util','bluebird','../../../../config/environment','../../../../config/logger'];(function(_0x43e755,_0x1f7d9c){var _0x87e899=function(_0x3574c0){while(--_0x3574c0){_0x43e755['push'](_0x43e755['shift']());}};_0x87e899(++_0x1f7d9c);}(_0x34e2,0x126));var _0x234e=function(_0x492530,_0x1c2d3c){_0x492530=_0x492530-0x0;var _0x145cb0=_0x34e2[_0x492530];return _0x145cb0;};'use strict';var _=require(_0x234e('0x0'));var rp=require('request-promise');var md5=require(_0x234e('0x1'));var util=require(_0x234e('0x2'));var intUtil=require('./util');var moment=require('moment');var Redis=require('ioredis');var BPromise=require(_0x234e('0x3'));var config=require(_0x234e('0x4'));var logger=require(_0x234e('0x5'))('zoho');config['redis']=_[_0x234e('0x6')](config['redis'],{'host':_0x234e('0x7'),'port':0x18eb});var io=require(_0x234e('0x8'))(new Redis(config[_0x234e('0x9')]));function emit(_0x3d81aa,_0x3fb603,_0x183895){io['to'](_0x3d81aa)[_0x234e('0xa')](_0x3fb603,_0x183895);}function request(_0x490557){logger[_0x234e('0xb')]('[HTTP]',JSON[_0x234e('0xc')](_0x490557));return rp(_0x490557);}function getCustomFields(_0x15c5cb,_0x81ac40){var _0x21394d={};if(_0x15c5cb[_0x234e('0xd')]>0x0){_[_0x234e('0xe')](_0x15c5cb,function(_0x3a861e){if(_[_0x234e('0xf')](['string','picklist'],_0x3a861e['type'])&&_0x3a861e[_0x234e('0x10')]){_0x21394d[_0x3a861e[_0x234e('0x10')]]=_0x3a861e[_0x234e('0x11')][_0x234e('0x12')]();}else if(_0x3a861e['type']===_0x234e('0x13')&&_0x3a861e[_0x234e('0x14')]&&_0x3a861e[_0x234e('0x10')]&&_0x81ac40[_0x3a861e[_0x234e('0x14')]]){_0x21394d[_0x3a861e['idField']]=_0x81ac40[_0x3a861e[_0x234e('0x14')]][_0x234e('0x12')]();}else if(_0x3a861e[_0x234e('0x15')]===_0x234e('0x16')&&_0x3a861e[_0x234e('0x17')]&&_0x3a861e[_0x234e('0x17')][_0x234e('0x18')]&&_0x3a861e[_0x234e('0x10')]&&_0x81ac40[_0x3a861e[_0x234e('0x17')][_0x234e('0x18')][_0x234e('0x19')]()]){_0x21394d[_0x3a861e[_0x234e('0x10')]]=_0x81ac40[_0x3a861e[_0x234e('0x17')]['name'][_0x234e('0x19')]()][_0x234e('0x12')]();}});}return _0x21394d;}function getName(_0x564d46){if(_0x564d46[_0x234e('0x1a')]('\x20')>0x0){var _0x2689b5=_0x564d46[_0x234e('0x1b')](/ (.+)/);if(_0x2689b5[0x1]){return _0x2689b5;}}return[_0x564d46,_0x564d46];}var accountsTokens={};function getAccessToken(_0x22d761){return new Promise(function(_0x57f050,_0x542c53){if(!_[_0x234e('0x1c')](accountsTokens[_0x22d761['id']])&&!_['isNil'](accountsTokens[_0x22d761['id']][_0x234e('0x1d')])){if(moment()[_0x234e('0x1e')](accountsTokens[_0x22d761['id']]['expires_in'])){_0x57f050(accountsTokens[_0x22d761['id']][_0x234e('0x1d')]);}}var _0x58b194;switch(_0x22d761['zone']){case'US':_0x58b194='https://accounts.zoho.com';break;case'AU':_0x58b194=_0x234e('0x1f');break;case'EU':_0x58b194='https://accounts.zoho.eu';break;case'IN':_0x58b194='https://accounts.zoho.in';break;case'CN':_0x58b194=_0x234e('0x20');break;default:_0x58b194=_0x234e('0x21');break;}var _0x1a59fc={'method':'POST','uri':_0x58b194+_0x234e('0x22'),'qs':{'refresh_token':_0x22d761['refreshToken'],'client_id':_0x22d761[_0x234e('0x23')],'client_secret':_0x22d761['clientSecret'],'grant_type':_0x234e('0x24')},'json':!![]};return rp(_0x1a59fc)[_0x234e('0x25')](function(_0x24d983){accountsTokens[_0x22d761['id']]={'access_token':_0x24d983[_0x234e('0x1d')],'expires_in':moment()[_0x234e('0x26')](_0x24d983[_0x234e('0x27')],_0x234e('0x28'))};_0x57f050(_0x24d983[_0x234e('0x1d')]);})[_0x234e('0x29')](function(_0xa821e0){logger[_0x234e('0x2a')]('Failing\x20creating\x20the\x20access_token',_0xa821e0['stack']);_0x542c53(_0xa821e0);});});}function getUser(_0x5ea7ae,_0x3971e7,_0x36cfd4,_0x512f97){logger['info'](_0x234e('0x2b'));return request({'method':_0x234e('0x2c'),'uri':util[_0x234e('0x2d')](_0x234e('0x2e'),_0x3971e7),'qs':{'type':_0x234e('0x2f')},'headers':{'Authorization':_0x234e('0x30')+_0x5ea7ae},'json':!![]})[_0x234e('0x25')](function(_0x5e9d29){if(_0x5e9d29[_0x234e('0x31')]){var _0x404e7c=-0x1;if(_['isArrayLikeObject'](_0x5e9d29[_0x234e('0x31')])){if(!_['isNil'](_0x512f97)){_0x404e7c=_[_0x234e('0x32')](_0x5e9d29[_0x234e('0x31')],function(_0x526f4a){return _0x526f4a[_0x234e('0x33')]===_0x512f97;});}if(_0x404e7c>=0x0){logger[_0x234e('0x34')]('Agent\x20found!');}else{logger['info']('Using\x20the\x20admin\x20account!');_0x404e7c=_[_0x234e('0x32')](_0x5e9d29[_0x234e('0x31')],function(_0x23407d){return _0x23407d[_0x234e('0x35')][_0x234e('0x18')]==='Administrator';});}return _0x5e9d29[_0x234e('0x31')][_0x404e7c];}else{if(_0x5e9d29['user']['profile'][_0x234e('0x18')]==='Administrator'){logger[_0x234e('0x34')](_0x234e('0x36'));user=_0x5e9d29[_0x234e('0x37')];return user;}else{logger[_0x234e('0x2a')](_0x234e('0x38'),JSON[_0x234e('0xc')](_0x5e9d29));throw new Error(_0x234e('0x39')+JSON[_0x234e('0xc')](_0x5e9d29));}}}else{logger[_0x234e('0x2a')](_0x234e('0x38'),JSON[_0x234e('0xc')](_0x5e9d29));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON['stringify'](_0x5e9d29));}})['catch'](function(_0xb5aaad){console[_0x234e('0x2a')](_0xb5aaad);});}function getZohoUser(_0x199994,_0x3663e7){return new BPromise(function(_0x2f8120,_0x46de57){request(_0x199994)[_0x234e('0x25')](function(_0x14f453){var _0x3d3aa3=null;if(_0x14f453){_0x3d3aa3=_0x14f453[_0x234e('0x3a')][0x0];_0x3d3aa3['enduserType']=_0x3663e7;}_0x2f8120(_0x3d3aa3);})[_0x234e('0x29')](function(_0x33ecb3){_0x46de57(_0x33ecb3);});});}function createEndUser(_0x3a4ec5,_0x320ef4,_0x213aa7,_0x241b33,_0x210b92,_0x18cd7a){var _0x213aa7=getName(_0x213aa7);return request({'method':'POST','uri':_0x234e('0x3b')+_0x320ef4+_0x234e('0x3c')+_[_0x234e('0x3d')](_0x18cd7a[_0x234e('0x3e')])+'s','body':{'data':[{'Last_Name':_0x213aa7[0x1],'First_Name':_0x213aa7[0x0],'Phone':_0x241b33,'Owner':{'name':!_[_0x234e('0x1c')](_0x210b92[_0x234e('0x3f')][_0x234e('0x18')])?_0x210b92[_0x234e('0x3f')][_0x234e('0x18')]:!_['isNil'](_0x210b92[_0x234e('0x40')])?_0x210b92['first_name']+'\x20'+_0x210b92[_0x234e('0x41')]:_0x210b92['last_name'],'id':_0x210b92['id']}}]},'headers':{'Authorization':_0x234e('0x30')+_0x3a4ec5},'json':!![]})[_0x234e('0x25')](function(_0x1dc86d){if(_0x1dc86d&&_0x1dc86d[_0x234e('0x3a')][0x0][_0x234e('0x42')]===_0x234e('0x43')){var _0x297354=_0x1dc86d[_0x234e('0x3a')][0x0][_0x234e('0x44')];_0x297354[_0x234e('0x45')]=_[_0x234e('0x3d')](_0x18cd7a[_0x234e('0x3e')])+'s';return _0x297354;}logger[_0x234e('0x2a')]('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error(_0x234e('0x46')+JSON[_0x234e('0xc')](data));})[_0x234e('0x29')](function(_0x2cd401){console[_0x234e('0x47')](_0x234e('0x48'),_0x2cd401);});}function getEndUser(_0x5f2395,_0x303c79,_0xc232d1,_0x4f244b,_0x7e9574,_0x1aed9f,_0x11321d){var _0x1aee0c={'method':_0x234e('0x2c'),'uri':'','headers':{'Authorization':_0x234e('0x30')+_0x5f2395},'json':!![]};switch(_0x11321d['moduleSearch']){case _0x234e('0x49'):_0x1aee0c['uri']=_0x234e('0x3b')+_0x303c79+_0x234e('0x4a')+_0x7e9574+'))';return getZohoUser(_0x1aee0c,_0x234e('0x4b'))[_0x234e('0x25')](function(_0x54a59b){if(_0x54a59b)return _0x54a59b;_0x1aee0c[_0x234e('0x4c')]='https://www.zohoapis.'+_0x303c79+_0x234e('0x4d')+_0x7e9574+'))';return getZohoUser(_0x1aee0c,_0x234e('0x4e'))[_0x234e('0x25')](function(_0x436545){if(_0x436545)return _0x436545;if(_0x11321d[_0x234e('0x3e')]!=_0x234e('0x4f')){return createEndUser(_0x5f2395,_0x303c79,_0x4f244b,_0x7e9574,_0x1aed9f,_0x11321d);}else{return{};}});});break;case'contact':_0x1aee0c['uri']=_0x234e('0x3b')+_0x303c79+_0x234e('0x4a')+_0x7e9574+'))';return getZohoUser(_0x1aee0c,'Contacts')[_0x234e('0x25')](function(_0x2bca9b){if(_0x2bca9b)return _0x2bca9b;if(_0x11321d[_0x234e('0x3e')]!=_0x234e('0x4f')){return createEndUser(_0x5f2395,_0x303c79,_0x4f244b,_0x7e9574,_0x1aed9f,_0x11321d);}else{return{};}});break;case _0x234e('0x50'):_0x1aee0c['uri']=_0x234e('0x3b')+_0x303c79+_0x234e('0x4d')+_0x7e9574+'))';return getZohoUser(_0x1aee0c,_0x234e('0x4e'))[_0x234e('0x25')](function(_0x5b087b){if(_0x5b087b)return _0x5b087b;if(_0x11321d['moduleCreate']!=_0x234e('0x4f')){return createEndUser(_0x5f2395,_0x303c79,_0x4f244b,_0x7e9574,_0x1aed9f,_0x11321d);}else{return{};}});break;}}function getCall(_0x2a3f05,_0x27931b,_0x568280,_0x13c7ee,_0xfa15df,_0x3c11d2,_0x1df58e,_0x54073a){logger[_0x234e('0x34')](_0x234e('0x51'));var _0x6374a1={};_0x6374a1[_0x234e('0x52')]={'name':!_[_0x234e('0x1c')](_0x13c7ee[_0x234e('0x3f')][_0x234e('0x18')])&&!_[_0x234e('0x1c')](_0x13c7ee[_0x234e('0x35')][_0x234e('0x18')])&&_0x13c7ee[_0x234e('0x35')][_0x234e('0x18')]===_0x234e('0x53')?_0x13c7ee[_0x234e('0x3f')][_0x234e('0x18')]:!_[_0x234e('0x1c')](_0x13c7ee[_0x234e('0x40')])?_0x13c7ee['first_name']+'\x20'+_0x13c7ee[_0x234e('0x41')]:_0x13c7ee[_0x234e('0x41')],'id':_0x13c7ee['id']};_0x6374a1[_0x234e('0x54')]=intUtil[_0x234e('0x55')](_0x3c11d2['Subjects'],_0x1df58e,'\x20');_0x6374a1[_0x234e('0x56')]=intUtil[_0x234e('0x55')](_0x3c11d2[_0x234e('0x57')],_0x1df58e,'\x0a');if(_0xfa15df[_0x234e('0x45')]===_0x234e('0x4b')){_0x6374a1[_0x234e('0x58')]={'name':!_[_0x234e('0x1c')](_0xfa15df[_0x234e('0x59')])?_0xfa15df[_0x234e('0x59')]:!_['isNil'](_0xfa15df['First_Name'])?_0xfa15df[_0x234e('0x5a')]+'\x20'+_0xfa15df['Last_Name']:_0xfa15df[_0x234e('0x5b')],'id':_0xfa15df['id']};}if(_0xfa15df['enduserType']===_0x234e('0x4e')){_0x6374a1[_0x234e('0x5c')]={'name':!_[_0x234e('0x1c')](_0xfa15df['Full_Name'])?_0xfa15df[_0x234e('0x59')]:!_[_0x234e('0x1c')](_0xfa15df[_0x234e('0x5a')])?_0xfa15df[_0x234e('0x5a')]+'\x20'+_0xfa15df[_0x234e('0x5b')]:_0xfa15df[_0x234e('0x5b')],'id':_0xfa15df['id']};_0x6374a1[_0x234e('0x5d')]=_[_0x234e('0x3d')](_0xfa15df['enduserType']);}if(_0x1df58e['talktime']){_0x6374a1['Call_Duration']=moment[_0x234e('0x5e')](parseInt(_0x1df58e['talktime'])*0x3e8)[_0x234e('0x2d')]('mm:ss');}else if(_0x1df58e[_0x234e('0x5f')]&&_0x1df58e['endtime']){_0x6374a1['Call_Duration']=moment[_0x234e('0x5e')](moment(_0x1df58e['endtime'],_0x234e('0x60'))[_0x234e('0x61')](moment(_0x1df58e[_0x234e('0x62')],_0x234e('0x60'))))[_0x234e('0x2d')]('mm:ss');}switch(_0x1df58e[_0x234e('0x63')]){case _0x234e('0x64'):_0x6374a1[_0x234e('0x65')]=_0x234e('0x66');break;case'complete':case'connect':_0x6374a1[_0x234e('0x65')]=_0x234e('0x67');break;case _0x234e('0x68'):_0x6374a1['Call_Result']=_0x234e('0x69');break;case _0x234e('0x6a'):_0x6374a1[_0x234e('0x65')]=_0x234e('0x6b');break;case _0x234e('0x6c'):_0x6374a1[_0x234e('0x65')]=_0x234e('0x6d');default:}_0x6374a1[_0x234e('0x6e')]=(_0x54073a===_0x234e('0x6f')?moment(_0x1df58e[_0x234e('0x62')])[_0x234e('0x2d')](_0x234e('0x60')):moment(_0x1df58e[_0x234e('0x70')])[_0x234e('0x2d')](_0x234e('0x60')))||moment()['format'](_0x234e('0x60'));_0x6374a1[_0x234e('0x71')]=_0x54073a||_0x234e('0x72');_0x6374a1=_[_0x234e('0x73')](_0x6374a1,getCustomFields(_0x3c11d2[_0x234e('0x74')],_0x1df58e));return request({'method':_0x234e('0x75'),'uri':_0x234e('0x3b')+_0x27931b+_0x234e('0x76'),'headers':{'Authorization':_0x234e('0x30')+_0x2a3f05},'body':{'data':[_0x6374a1]},'json':!![]})['then'](function(_0x4d927a){if(_0x4d927a&&_0x4d927a[_0x234e('0x3a')][0x0][_0x234e('0x42')]==='SUCCESS'){logger[_0x234e('0x34')](_0x234e('0x77'));return{'id':_0x4d927a[_0x234e('0x3a')][0x0][_0x234e('0x44')]['id']};}})[_0x234e('0x29')](function(_0x2599ac){logger[_0x234e('0x34')](_0x234e('0x78'),_0x2599ac[_0x234e('0x79')]);console['log'](_0x234e('0x78'),_0x2599ac);});}exports['queue']=function(_0x566796,_0x4ee861,_0x3851d8,_0x1807b4,_0x4708ff,_0x16faf8){var _0x54c9a9,_0x266d36,_0x3a5f71;_0x16faf8[_0x234e('0x7a')]=intUtil[_0x234e('0x7b')](_0x16faf8[_0x234e('0x7a')]);_0x16faf8[_0x234e('0x7c')]=intUtil['stripTrailingSlash'](_0x16faf8[_0x234e('0x7c')]);if(_0x4708ff&&_0x4708ff[_0x234e('0x7d')]){logger[_0x234e('0x34')](_0x234e('0x7e'),_0x234e('0x7f'));_0x4ee861[_0x234e('0x80')]=_0x16faf8[_0x234e('0x7c')]+'/api/voice/recordings/'+_0x4ee861[_0x234e('0x81')]+_0x234e('0x82')+md5(_0x4ee861[_0x234e('0x81')]);}else{_0x4ee861[_0x234e('0x80')]='';}var _0x5c8935=_0x16faf8['host']===_0x234e('0x83')?'eu':_0x234e('0x84');return getAccessToken(_0x16faf8)[_0x234e('0x25')](function(_0x1782ff){_0x3a5f71=_0x1782ff;return getUser(_0x3a5f71,_0x5c8935,_0x16faf8,_0x1807b4[_0x234e('0x33')]);})[_0x234e('0x25')](function(_0x5989ad){_0x54c9a9=_0x5989ad;logger['info'](_0x234e('0x85'),_0x54c9a9['id']);return getEndUser(_0x3a5f71,_0x5c8935,_0x16faf8,_0x4ee861[_0x234e('0x86')],_0x4ee861[_0x234e('0x87')],_0x54c9a9,_0x3851d8);})[_0x234e('0x25')](function(_0x23ad17){_0x266d36=_0x23ad17;return getCall(_0x3a5f71,_0x5c8935,_0x16faf8,_0x54c9a9,_0x266d36,_0x3851d8,_0x4ee861,_0x234e('0x72'));})[_0x234e('0x25')](function(_0x5346c3){if(_0x5346c3){logger[_0x234e('0x34')](_0x234e('0x88'),_0x5346c3['id']);logger['info'](_0x234e('0x7e'),_0x234e('0x89'));emit(util[_0x234e('0x2d')](_0x234e('0x8a'),_0x1807b4[_0x234e('0x18')]),_0x234e('0x8b'),{'uri':'https://crm.'+_0x16faf8[_0x234e('0x7a')]+_0x234e('0x8c')+_0x5346c3['id']});}})[_0x234e('0x29')](function(_0x38b239){logger[_0x234e('0x2a')]('[QUEUE]',JSON['stringify'](_0x38b239));});};exports[_0x234e('0x6f')]=function(_0x9087d3,_0x32d2af,_0x38bbe0,_0x33d2b7,_0x5e3220,_0x5058d3,_0x2fbc12){var _0xffb15d,_0x21157f,_0x233917;_0x5058d3['host']=intUtil['stripTrailingSlash'](_0x5058d3['host']);_0x5058d3['serverUrl']=intUtil[_0x234e('0x7b')](_0x5058d3[_0x234e('0x7c')]);if(_0x2fbc12&&_0x2fbc12[_0x234e('0x8d')]&&_0x2fbc12[_0x234e('0x8d')]!==_0x234e('0x8e')){logger[_0x234e('0x34')]('[OUTBOUND]',_0x234e('0x7f'));_0x32d2af[_0x234e('0x80')]=_0x5058d3['serverUrl']+'/api/voice/recordings/'+_0x32d2af[_0x234e('0x81')]+_0x234e('0x82')+md5(_0x32d2af[_0x234e('0x81')]);}var _0x545ced=_0x5058d3[_0x234e('0x7a')]===_0x234e('0x83')?'eu':_0x234e('0x84');return getAccessToken(_0x5058d3)[_0x234e('0x25')](function(_0x5e2675){_0x233917=_0x5e2675;return getUser(_0x233917,_0x545ced,_0x5058d3,_0x33d2b7[_0x234e('0x33')]);})[_0x234e('0x25')](function(_0x4c530a){_0xffb15d=_0x4c530a;logger['info'](_0x234e('0x85'),_0xffb15d['id']);return getEndUser(_0x233917,_0x545ced,_0x5058d3,_0x32d2af['destcalleridname'],_0x32d2af[_0x234e('0x8f')],_0xffb15d,_0x38bbe0);})[_0x234e('0x25')](function(_0x1be3a8){_0x21157f=_0x1be3a8;return getCall(_0x233917,_0x545ced,_0x5058d3,_0xffb15d,_0x21157f,_0x38bbe0,_0x32d2af,_0x234e('0x90'));})[_0x234e('0x25')](function(_0x52456a){if(_0x52456a){logger[_0x234e('0x34')](_0x234e('0x88'),_0x52456a['id']);logger[_0x234e('0x34')](_0x234e('0x91'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0x234e('0x8a'),_0x33d2b7[_0x234e('0x18')]),_0x234e('0x8b'),{'uri':_0x234e('0x92')+_0x5058d3['host']+'/crm/EntityInfo.do?module=Calls&id='+_0x52456a['id']});}})[_0x234e('0x29')](function(_0x2d5e57){logger[_0x234e('0x2a')]('[OUTBOUND]',JSON[_0x234e('0xc')](_0x2d5e57));});};exports[_0x234e('0x93')]=function(_0xdcbfe7,_0x3ca2fc,_0x38a6ae,_0x2e20ee,_0x1a9d52,_0x557b12){var _0x42237d,_0x36de88,_0x2203f2;_0x557b12['host']=intUtil['stripTrailingSlash'](_0x557b12[_0x234e('0x7a')]);_0x557b12['serverUrl']=intUtil['stripTrailingSlash'](_0x557b12[_0x234e('0x7c')]);if(_0x1a9d52&&_0x1a9d52[_0x234e('0x7d')]){logger[_0x234e('0x34')]('['+_0x3ca2fc[_0x234e('0x63')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x3ca2fc[_0x234e('0x80')]=_0x557b12['serverUrl']+_0x234e('0x94')+_0x3ca2fc[_0x234e('0x81')]+'/downloads?type=uniqueid&token='+md5(_0x3ca2fc[_0x234e('0x81')]);}else{_0x3ca2fc[_0x234e('0x80')]='';}var _0x581271=_0x557b12[_0x234e('0x7a')]==='zoho.eu'?'eu':_0x234e('0x84');return getAccessToken(_0x557b12)[_0x234e('0x25')](function(_0x41f178){_0x2203f2=_0x41f178;return getUser(_0x2203f2,_0x581271,_0x557b12);})['then'](function(_0x361667){_0x42237d=_0x361667;logger[_0x234e('0x34')](_0x234e('0x85'),_0x42237d['id']);return getEndUser(_0x2203f2,_0x581271,_0x557b12,_0x3ca2fc[_0x234e('0x86')],_0x3ca2fc[_0x234e('0x87')],_0x42237d,_0x38a6ae);})[_0x234e('0x25')](function(_0x275a2b){_0x36de88=_0x275a2b;return getCall(_0x2203f2,_0x581271,_0x557b12,_0x42237d,_0x36de88,_0x38a6ae,_0x3ca2fc,_0x234e('0x72'));})[_0x234e('0x25')](function(_0x99017b){if(_0x99017b){logger[_0x234e('0x34')](_0x234e('0x88'),_0x99017b['id']);}})[_0x234e('0x29')](function(_0x35aca0){logger[_0x234e('0x2a')]('['+_0x3ca2fc[_0x234e('0x63')][_0x234e('0x95')]()+']',JSON['stringify'](_0x35aca0));});};
\ No newline at end of file
+var _0x628a=['defaults','socket.io-emitter','emit','[HTTP]','stringify','length','forEach','string','picklist','type','idField','toString','variable','variableName','customVariable','Variable','name','toLowerCase','split','isNil','access_token','isBefore','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.in','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','refreshToken','clientId','clientSecret','refresh_token','then','add','expires_in','catch','error','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','users','findIndex','Agent\x20found!','Using\x20the\x20admin\x20account!','user','Administrator','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','/crm/v2/','moduleCreate','role','first_name','last_name','code','SUCCESS','details','startCase','Error:\x20','log','CREATE\x20ERROR','moduleSearch','contact_lead','uri','Contacts','https://www.zohoapis.','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','nothing','contact','Creating\x20new\x20call...','Owner','profile','administrator','Subject','getString','Subjects','Who_Id','Full_Name','First_Name','Last_Name','What_Id','talktime','Call_Duration','utc','mm:ss','endtime','YYYY-MM-DDTHH:mm:ss','diff','starttime','lastevent','called','Call_Result','Called','complete','connect','rejected','Rejected','timeout','Timeout','outbound','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','recordingURL','/api/voice/recordings/','/downloads?type=uniqueid&token=','uniqueid','zoho.eu','com','email','calleridname','calleridnum','The\x20Call\x20ID\x20is:','user:%s','recordingFormat','[OUTBOUND]','Recording\x20is\x20enabled!','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','https://crm.','/crm/EntityInfo.do?module=Calls&id=','toUpperCase','lodash','request-promise','util','./util','moment','ioredis','bluebird','../../../../config/environment','zoho','redis'];(function(_0x4ff09b,_0x53f67d){var _0x3f5c2e=function(_0x124592){while(--_0x124592){_0x4ff09b['push'](_0x4ff09b['shift']());}};_0x3f5c2e(++_0x53f67d);}(_0x628a,0x1bb));var _0xa628=function(_0x5c2f8b,_0x44d93e){_0x5c2f8b=_0x5c2f8b-0x0;var _0xc143a4=_0x628a[_0x5c2f8b];return _0xc143a4;};'use strict';var _=require(_0xa628('0x0'));var rp=require(_0xa628('0x1'));var md5=require('md5');var util=require(_0xa628('0x2'));var intUtil=require(_0xa628('0x3'));var moment=require(_0xa628('0x4'));var Redis=require(_0xa628('0x5'));var BPromise=require(_0xa628('0x6'));var config=require(_0xa628('0x7'));var logger=require('../../../../config/logger')(_0xa628('0x8'));config[_0xa628('0x9')]=_[_0xa628('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0xa628('0xb'))(new Redis(config[_0xa628('0x9')]));function emit(_0x1024eb,_0x21d8a8,_0x40f0ad){io['to'](_0x1024eb)[_0xa628('0xc')](_0x21d8a8,_0x40f0ad);}function request(_0x2ec8b3){logger['debug'](_0xa628('0xd'),JSON[_0xa628('0xe')](_0x2ec8b3));return rp(_0x2ec8b3);}function getCustomFields(_0x1577d6,_0x58f628){var _0x2c4c69={};if(_0x1577d6[_0xa628('0xf')]>0x0){_[_0xa628('0x10')](_0x1577d6,function(_0x538816){if(_['includes']([_0xa628('0x11'),_0xa628('0x12')],_0x538816[_0xa628('0x13')])&&_0x538816['idField']){_0x2c4c69[_0x538816[_0xa628('0x14')]]=_0x538816['content'][_0xa628('0x15')]();}else if(_0x538816['type']===_0xa628('0x16')&&_0x538816[_0xa628('0x17')]&&_0x538816['idField']&&_0x58f628[_0x538816[_0xa628('0x17')]]){_0x2c4c69[_0x538816[_0xa628('0x14')]]=_0x58f628[_0x538816[_0xa628('0x17')]][_0xa628('0x15')]();}else if(_0x538816[_0xa628('0x13')]===_0xa628('0x18')&&_0x538816[_0xa628('0x19')]&&_0x538816['Variable'][_0xa628('0x1a')]&&_0x538816[_0xa628('0x14')]&&_0x58f628[_0x538816[_0xa628('0x19')][_0xa628('0x1a')][_0xa628('0x1b')]()]){_0x2c4c69[_0x538816[_0xa628('0x14')]]=_0x58f628[_0x538816[_0xa628('0x19')][_0xa628('0x1a')][_0xa628('0x1b')]()][_0xa628('0x15')]();}});}return _0x2c4c69;}function getName(_0x39d617){if(_0x39d617['indexOf']('\x20')>0x0){var _0x147aae=_0x39d617[_0xa628('0x1c')](/ (.+)/);if(_0x147aae[0x1]){return _0x147aae;}}return[_0x39d617,_0x39d617];}var accountsTokens={};function getAccessToken(_0x540a22){return new Promise(function(_0x5c4e94,_0x207d08){if(!_[_0xa628('0x1d')](accountsTokens[_0x540a22['id']])&&!_[_0xa628('0x1d')](accountsTokens[_0x540a22['id']][_0xa628('0x1e')])){if(moment()[_0xa628('0x1f')](accountsTokens[_0x540a22['id']]['expires_in'])){_0x5c4e94(accountsTokens[_0x540a22['id']][_0xa628('0x1e')]);}}var _0x879b2;switch(_0x540a22[_0xa628('0x20')]){case'US':_0x879b2=_0xa628('0x21');break;case'AU':_0x879b2=_0xa628('0x22');break;case'EU':_0x879b2='https://accounts.zoho.eu';break;case'IN':_0x879b2=_0xa628('0x23');break;case'CN':_0x879b2=_0xa628('0x24');break;default:_0x879b2=_0xa628('0x25');break;}var _0x36dfca={'method':_0xa628('0x26'),'uri':_0x879b2+'/oauth/v2/token','qs':{'refresh_token':_0x540a22[_0xa628('0x27')],'client_id':_0x540a22[_0xa628('0x28')],'client_secret':_0x540a22[_0xa628('0x29')],'grant_type':_0xa628('0x2a')},'json':!![]};return rp(_0x36dfca)[_0xa628('0x2b')](function(_0x5364f6){accountsTokens[_0x540a22['id']]={'access_token':_0x5364f6[_0xa628('0x1e')],'expires_in':moment()[_0xa628('0x2c')](_0x5364f6[_0xa628('0x2d')],'seconds')};_0x5c4e94(_0x5364f6['access_token']);})[_0xa628('0x2e')](function(_0x25bae0){logger[_0xa628('0x2f')]('Failing\x20creating\x20the\x20access_token',_0x25bae0[_0xa628('0x30')]);_0x207d08(_0x25bae0);});});}function getUser(_0x158fef,_0x1eb962,_0x309ba0,_0x1a5c16){logger[_0xa628('0x31')](_0xa628('0x32'));return request({'method':_0xa628('0x33'),'uri':util[_0xa628('0x34')](_0xa628('0x35'),_0x1eb962),'qs':{'type':_0xa628('0x36')},'headers':{'Authorization':_0xa628('0x37')+_0x158fef},'json':!![]})[_0xa628('0x2b')](function(_0x496b1e){if(_0x496b1e[_0xa628('0x38')]){var _0x12c1bb=-0x1;if(_['isArrayLikeObject'](_0x496b1e[_0xa628('0x38')])){if(!_['isNil'](_0x1a5c16)){_0x12c1bb=_[_0xa628('0x39')](_0x496b1e['users'],function(_0x56c7ef){return _0x56c7ef['email']===_0x1a5c16;});}if(_0x12c1bb>=0x0){logger[_0xa628('0x31')](_0xa628('0x3a'));}else{logger[_0xa628('0x31')](_0xa628('0x3b'));_0x12c1bb=_['findIndex'](_0x496b1e['users'],function(_0x112391){return _0x112391['profile']['name']==='Administrator';});}return _0x496b1e['users'][_0x12c1bb];}else{if(_0x496b1e[_0xa628('0x3c')]['profile']['name']===_0xa628('0x3d')){logger[_0xa628('0x31')](_0xa628('0x3b'));user=_0x496b1e[_0xa628('0x3c')];return user;}else{logger[_0xa628('0x2f')](_0xa628('0x3e'),JSON[_0xa628('0xe')](_0x496b1e));throw new Error(_0xa628('0x3f')+JSON[_0xa628('0xe')](_0x496b1e));}}}else{logger[_0xa628('0x2f')]('The\x20failing\x20result\x20is',JSON[_0xa628('0xe')](_0x496b1e));throw new Error(_0xa628('0x3f')+JSON[_0xa628('0xe')](_0x496b1e));}})[_0xa628('0x2e')](function(_0x1bc192){console[_0xa628('0x2f')](_0x1bc192);});}function getZohoUser(_0x2234bc,_0x2d2b92){return new BPromise(function(_0x44b056,_0x2ff66d){request(_0x2234bc)[_0xa628('0x2b')](function(_0x215dbe){var _0x1330cb=null;if(_0x215dbe){_0x1330cb=_0x215dbe[_0xa628('0x40')][0x0];_0x1330cb[_0xa628('0x41')]=_0x2d2b92;}_0x44b056(_0x1330cb);})[_0xa628('0x2e')](function(_0x2ac458){_0x2ff66d(_0x2ac458);});});}function createEndUser(_0x562ac7,_0x275540,_0x5b05ec,_0x5b8a0c,_0x2f5554,_0x7edd20){var _0x5b05ec=getName(_0x5b05ec);return request({'method':'POST','uri':'https://www.zohoapis.'+_0x275540+_0xa628('0x42')+_['startCase'](_0x7edd20[_0xa628('0x43')])+'s','body':{'data':[{'Last_Name':_0x5b05ec[0x1],'First_Name':_0x5b05ec[0x0],'Phone':_0x5b8a0c,'Owner':{'name':!_[_0xa628('0x1d')](_0x2f5554[_0xa628('0x44')]['name'])?_0x2f5554[_0xa628('0x44')][_0xa628('0x1a')]:!_[_0xa628('0x1d')](_0x2f5554[_0xa628('0x45')])?_0x2f5554[_0xa628('0x45')]+'\x20'+_0x2f5554['last_name']:_0x2f5554[_0xa628('0x46')],'id':_0x2f5554['id']}}]},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x562ac7},'json':!![]})[_0xa628('0x2b')](function(_0x307349){if(_0x307349&&_0x307349['data'][0x0][_0xa628('0x47')]===_0xa628('0x48')){var _0x413362=_0x307349[_0xa628('0x40')][0x0][_0xa628('0x49')];_0x413362[_0xa628('0x41')]=_[_0xa628('0x4a')](_0x7edd20['moduleCreate'])+'s';return _0x413362;}logger[_0xa628('0x2f')](_0xa628('0x3e'),JSON[_0xa628('0xe')](data));throw new Error(_0xa628('0x4b')+JSON[_0xa628('0xe')](data));})[_0xa628('0x2e')](function(_0x4c4e74){console[_0xa628('0x4c')](_0xa628('0x4d'),_0x4c4e74);});}function getEndUser(_0xdcbb9a,_0x331fdc,_0x1e16b7,_0x518031,_0x5da970,_0x2d4f8a,_0x6c5a1c){var _0x4917c7={'method':_0xa628('0x33'),'uri':'','headers':{'Authorization':'Zoho-oauthtoken\x20'+_0xdcbb9a},'json':!![]};switch(_0x6c5a1c[_0xa628('0x4e')]){case _0xa628('0x4f'):_0x4917c7[_0xa628('0x50')]='https://www.zohoapis.'+_0x331fdc+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x5da970+'))';return getZohoUser(_0x4917c7,_0xa628('0x51'))['then'](function(_0x2894db){if(_0x2894db)return _0x2894db;_0x4917c7['uri']=_0xa628('0x52')+_0x331fdc+_0xa628('0x53')+_0x5da970+'))';return getZohoUser(_0x4917c7,_0xa628('0x54'))[_0xa628('0x2b')](function(_0x4753ea){if(_0x4753ea)return _0x4753ea;if(_0x6c5a1c['moduleCreate']!=_0xa628('0x55')){return createEndUser(_0xdcbb9a,_0x331fdc,_0x518031,_0x5da970,_0x2d4f8a,_0x6c5a1c);}else{return{};}});});break;case _0xa628('0x56'):_0x4917c7[_0xa628('0x50')]=_0xa628('0x52')+_0x331fdc+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x5da970+'))';return getZohoUser(_0x4917c7,'Contacts')['then'](function(_0x5708d9){if(_0x5708d9)return _0x5708d9;if(_0x6c5a1c['moduleCreate']!=_0xa628('0x55')){return createEndUser(_0xdcbb9a,_0x331fdc,_0x518031,_0x5da970,_0x2d4f8a,_0x6c5a1c);}else{return{};}});break;case'lead':_0x4917c7[_0xa628('0x50')]=_0xa628('0x52')+_0x331fdc+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x5da970+'))';return getZohoUser(_0x4917c7,_0xa628('0x54'))[_0xa628('0x2b')](function(_0x5257f6){if(_0x5257f6)return _0x5257f6;if(_0x6c5a1c[_0xa628('0x43')]!=_0xa628('0x55')){return createEndUser(_0xdcbb9a,_0x331fdc,_0x518031,_0x5da970,_0x2d4f8a,_0x6c5a1c);}else{return{};}});break;}}function getCall(_0x5e71ed,_0x19124e,_0x383fa3,_0x325c2,_0x5a22a3,_0x331a24,_0x4f6c80,_0x24ae21){logger[_0xa628('0x31')](_0xa628('0x57'));var _0x4298a5={};_0x4298a5[_0xa628('0x58')]={'name':!_[_0xa628('0x1d')](_0x325c2[_0xa628('0x44')][_0xa628('0x1a')])&&!_['isNil'](_0x325c2['profile'][_0xa628('0x1a')])&&_0x325c2[_0xa628('0x59')][_0xa628('0x1a')]===_0xa628('0x5a')?_0x325c2[_0xa628('0x44')][_0xa628('0x1a')]:!_['isNil'](_0x325c2['first_name'])?_0x325c2[_0xa628('0x45')]+'\x20'+_0x325c2[_0xa628('0x46')]:_0x325c2['last_name'],'id':_0x325c2['id']};_0x4298a5[_0xa628('0x5b')]=intUtil[_0xa628('0x5c')](_0x331a24[_0xa628('0x5d')],_0x4f6c80,'\x20');_0x4298a5['Description']=intUtil[_0xa628('0x5c')](_0x331a24['Descriptions'],_0x4f6c80,'\x0a');if(_0x5a22a3[_0xa628('0x41')]==='Contacts'){_0x4298a5[_0xa628('0x5e')]={'name':!_[_0xa628('0x1d')](_0x5a22a3[_0xa628('0x5f')])?_0x5a22a3[_0xa628('0x5f')]:!_['isNil'](_0x5a22a3[_0xa628('0x60')])?_0x5a22a3[_0xa628('0x60')]+'\x20'+_0x5a22a3[_0xa628('0x61')]:_0x5a22a3['Last_Name'],'id':_0x5a22a3['id']};}if(_0x5a22a3[_0xa628('0x41')]===_0xa628('0x54')){_0x4298a5[_0xa628('0x62')]={'name':!_[_0xa628('0x1d')](_0x5a22a3[_0xa628('0x5f')])?_0x5a22a3[_0xa628('0x5f')]:!_[_0xa628('0x1d')](_0x5a22a3[_0xa628('0x60')])?_0x5a22a3[_0xa628('0x60')]+'\x20'+_0x5a22a3[_0xa628('0x61')]:_0x5a22a3['Last_Name'],'id':_0x5a22a3['id']};_0x4298a5['$se_module']=_['startCase'](_0x5a22a3[_0xa628('0x41')]);}if(_0x4f6c80[_0xa628('0x63')]){_0x4298a5[_0xa628('0x64')]=moment[_0xa628('0x65')](parseInt(_0x4f6c80['talktime'])*0x3e8)[_0xa628('0x34')](_0xa628('0x66'));}else if(_0x4f6c80['answertime']&&_0x4f6c80[_0xa628('0x67')]){_0x4298a5[_0xa628('0x64')]=moment[_0xa628('0x65')](moment(_0x4f6c80[_0xa628('0x67')],_0xa628('0x68'))[_0xa628('0x69')](moment(_0x4f6c80[_0xa628('0x6a')],_0xa628('0x68'))))['format'](_0xa628('0x66'));}switch(_0x4f6c80[_0xa628('0x6b')]){case _0xa628('0x6c'):_0x4298a5[_0xa628('0x6d')]=_0xa628('0x6e');break;case _0xa628('0x6f'):case _0xa628('0x70'):_0x4298a5[_0xa628('0x6d')]='Answered';break;case _0xa628('0x71'):_0x4298a5['Call_Result']=_0xa628('0x72');break;case'abandoned':_0x4298a5[_0xa628('0x6d')]='Abandoned';break;case _0xa628('0x73'):_0x4298a5[_0xa628('0x6d')]=_0xa628('0x74');default:}_0x4298a5['Call_Start_Time']=(_0x24ae21===_0xa628('0x75')?moment(_0x4f6c80[_0xa628('0x6a')])['format'](_0xa628('0x68')):moment(_0x4f6c80['agentcalledAt'])[_0xa628('0x34')](_0xa628('0x68')))||moment()[_0xa628('0x34')]('YYYY-MM-DDTHH:mm:ss');_0x4298a5[_0xa628('0x76')]=_0x24ae21||_0xa628('0x77');_0x4298a5=_[_0xa628('0x78')](_0x4298a5,getCustomFields(_0x331a24[_0xa628('0x79')],_0x4f6c80));return request({'method':_0xa628('0x26'),'uri':_0xa628('0x52')+_0x19124e+_0xa628('0x7a'),'headers':{'Authorization':_0xa628('0x37')+_0x5e71ed},'body':{'data':[_0x4298a5]},'json':!![]})[_0xa628('0x2b')](function(_0x43cb93){if(_0x43cb93&&_0x43cb93['data'][0x0][_0xa628('0x47')]===_0xa628('0x48')){logger[_0xa628('0x31')](_0xa628('0x7b'));return{'id':_0x43cb93[_0xa628('0x40')][0x0][_0xa628('0x49')]['id']};}})[_0xa628('0x2e')](function(_0x3b236a){logger['info'](_0xa628('0x7c'),_0x3b236a[_0xa628('0x30')]);console[_0xa628('0x4c')](_0xa628('0x7c'),_0x3b236a);});}exports[_0xa628('0x7d')]=function(_0x504946,_0x175632,_0x136c4b,_0x3fdfbd,_0xc90ce9,_0x5372d4){var _0x5845dc,_0x2bf7a5,_0x4507a1;_0x5372d4[_0xa628('0x7e')]=intUtil[_0xa628('0x7f')](_0x5372d4[_0xa628('0x7e')]);_0x5372d4[_0xa628('0x80')]=intUtil[_0xa628('0x7f')](_0x5372d4[_0xa628('0x80')]);if(_0xc90ce9&&_0xc90ce9[_0xa628('0x81')]){logger[_0xa628('0x31')](_0xa628('0x82'),'Recording\x20is\x20enabled!');_0x175632[_0xa628('0x83')]=_0x5372d4[_0xa628('0x80')]+_0xa628('0x84')+_0x175632['uniqueid']+_0xa628('0x85')+md5(_0x175632[_0xa628('0x86')]);}else{_0x175632[_0xa628('0x83')]='';}var _0x7b17bc=_0x5372d4[_0xa628('0x7e')]===_0xa628('0x87')?'eu':_0xa628('0x88');return getAccessToken(_0x5372d4)[_0xa628('0x2b')](function(_0x5823be){_0x4507a1=_0x5823be;return getUser(_0x4507a1,_0x7b17bc,_0x5372d4,_0x3fdfbd[_0xa628('0x89')]);})[_0xa628('0x2b')](function(_0x1612f8){_0x5845dc=_0x1612f8;logger['info']('The\x20User\x20ID\x20is:',_0x5845dc['id']);return getEndUser(_0x4507a1,_0x7b17bc,_0x5372d4,_0x175632[_0xa628('0x8a')],_0x175632[_0xa628('0x8b')],_0x5845dc,_0x136c4b);})[_0xa628('0x2b')](function(_0x1138b2){_0x2bf7a5=_0x1138b2;return getCall(_0x4507a1,_0x7b17bc,_0x5372d4,_0x5845dc,_0x2bf7a5,_0x136c4b,_0x175632,_0xa628('0x77'));})[_0xa628('0x2b')](function(_0x2ed1a3){if(_0x2ed1a3){logger[_0xa628('0x31')](_0xa628('0x8c'),_0x2ed1a3['id']);logger[_0xa628('0x31')](_0xa628('0x82'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0xa628('0x8d'),_0x3fdfbd['name']),'trigger:browser:url',{'uri':'https://crm.'+_0x5372d4['host']+'/crm/EntityInfo.do?module=Calls&id='+_0x2ed1a3['id']});}})[_0xa628('0x2e')](function(_0x2c7bac){logger[_0xa628('0x2f')]('[QUEUE]',JSON['stringify'](_0x2c7bac));});};exports['outbound']=function(_0x526f28,_0x10646a,_0x275813,_0x928cf8,_0x5da35d,_0x23ff82,_0x4502e3){var _0x175515,_0xb2f36e,_0x552eb2;_0x23ff82[_0xa628('0x7e')]=intUtil[_0xa628('0x7f')](_0x23ff82['host']);_0x23ff82['serverUrl']=intUtil['stripTrailingSlash'](_0x23ff82[_0xa628('0x80')]);if(_0x4502e3&&_0x4502e3[_0xa628('0x8e')]&&_0x4502e3[_0xa628('0x8e')]!=='none'){logger[_0xa628('0x31')](_0xa628('0x8f'),_0xa628('0x90'));_0x10646a[_0xa628('0x83')]=_0x23ff82[_0xa628('0x80')]+'/api/voice/recordings/'+_0x10646a[_0xa628('0x86')]+'/downloads?type=uniqueid&token='+md5(_0x10646a[_0xa628('0x86')]);}var _0x3a4c0f=_0x23ff82[_0xa628('0x7e')]===_0xa628('0x87')?'eu':_0xa628('0x88');return getAccessToken(_0x23ff82)[_0xa628('0x2b')](function(_0x3ead53){_0x552eb2=_0x3ead53;return getUser(_0x552eb2,_0x3a4c0f,_0x23ff82,_0x928cf8[_0xa628('0x89')]);})[_0xa628('0x2b')](function(_0x131995){_0x175515=_0x131995;logger['info'](_0xa628('0x91'),_0x175515['id']);return getEndUser(_0x552eb2,_0x3a4c0f,_0x23ff82,_0x10646a[_0xa628('0x92')],_0x10646a[_0xa628('0x93')],_0x175515,_0x275813);})[_0xa628('0x2b')](function(_0x19965a){_0xb2f36e=_0x19965a;return getCall(_0x552eb2,_0x3a4c0f,_0x23ff82,_0x175515,_0xb2f36e,_0x275813,_0x10646a,'Outbound');})['then'](function(_0x206672){if(_0x206672){logger[_0xa628('0x31')]('The\x20Call\x20ID\x20is:',_0x206672['id']);logger[_0xa628('0x31')](_0xa628('0x8f'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util['format'](_0xa628('0x8d'),_0x928cf8[_0xa628('0x1a')]),'trigger:browser:url',{'uri':_0xa628('0x94')+_0x23ff82[_0xa628('0x7e')]+_0xa628('0x95')+_0x206672['id']});}})['catch'](function(_0x4bdeca){logger[_0xa628('0x2f')](_0xa628('0x8f'),JSON[_0xa628('0xe')](_0x4bdeca));});};exports['unmanaged']=function(_0x18b1f7,_0x2ea1cb,_0x2653d3,_0x55ee27,_0x3fbcc8,_0x4b1a78){var _0x167ee8,_0x5131eb,_0xcdffce;_0x4b1a78['host']=intUtil[_0xa628('0x7f')](_0x4b1a78[_0xa628('0x7e')]);_0x4b1a78[_0xa628('0x80')]=intUtil['stripTrailingSlash'](_0x4b1a78[_0xa628('0x80')]);if(_0x3fbcc8&&_0x3fbcc8[_0xa628('0x81')]){logger[_0xa628('0x31')]('['+_0x2ea1cb[_0xa628('0x6b')][_0xa628('0x96')]()+']','Recording\x20is\x20enabled!');_0x2ea1cb[_0xa628('0x83')]=_0x4b1a78['serverUrl']+_0xa628('0x84')+_0x2ea1cb['uniqueid']+_0xa628('0x85')+md5(_0x2ea1cb[_0xa628('0x86')]);}else{_0x2ea1cb[_0xa628('0x83')]='';}var _0x1335c5=_0x4b1a78[_0xa628('0x7e')]===_0xa628('0x87')?'eu':_0xa628('0x88');return getAccessToken(_0x4b1a78)['then'](function(_0xa4b7c5){_0xcdffce=_0xa4b7c5;return getUser(_0xcdffce,_0x1335c5,_0x4b1a78);})[_0xa628('0x2b')](function(_0x522e89){_0x167ee8=_0x522e89;logger[_0xa628('0x31')](_0xa628('0x91'),_0x167ee8['id']);return getEndUser(_0xcdffce,_0x1335c5,_0x4b1a78,_0x2ea1cb[_0xa628('0x8a')],_0x2ea1cb[_0xa628('0x8b')],_0x167ee8,_0x2653d3);})['then'](function(_0x2dd6eb){_0x5131eb=_0x2dd6eb;return getCall(_0xcdffce,_0x1335c5,_0x4b1a78,_0x167ee8,_0x5131eb,_0x2653d3,_0x2ea1cb,_0xa628('0x77'));})[_0xa628('0x2b')](function(_0x347362){if(_0x347362){logger[_0xa628('0x31')]('The\x20Call\x20ID\x20is:',_0x347362['id']);}})['catch'](function(_0x4fffce){logger[_0xa628('0x2f')]('['+_0x2ea1cb[_0xa628('0x6b')][_0xa628('0x96')]()+']',JSON[_0xa628('0xe')](_0x4fffce));});};
\ No newline at end of file