Built motion from commit 980b26c3.|2.6.29
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index b43cbc4..304db19 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0903=['error','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','users','isArrayLikeObject','findIndex','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','Administrator','user','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','The\x20failing\x20result\x20is','data','enduserType','https://www.zohoapis.','/crm/v2/','moduleCreate','role','last_name','Zoho-oauthtoken\x20','code','SUCCESS','details','log','CREATE\x20ERROR','moduleSearch','contact_lead','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','Leads','nothing','contact','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','Creating\x20new\x20call...','Owner','administrator','first_name','Subject','getString','Subjects','Description','Who_Id','Full_Name','First_Name','Last_Name','$se_module','startCase','talktime','Call_Duration','utc','mm:ss','endtime','diff','YYYY-MM-DDTHH:mm:ss','Call_Result','Called','connect','Answered','rejected','Rejected','abandoned','Abandoned','Timeout','Call_Start_Time','outbound','starttime','Inbound','Fields','/crm/v2/Calls','Call\x20created!','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','recordingURL','/api/voice/recordings/','uniqueid','/downloads?type=uniqueid&token=','com','The\x20User\x20ID\x20is:','calleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','zoho.eu','destcalleridnum','Outbound','/crm/EntityInfo.do?module=Calls&id=','lastevent','calleridname','lodash','md5','util','./util','moment','../../../../config/environment','../../../../config/logger','zoho','redis','defaults','socket.io-emitter','emit','debug','[HTTP]','stringify','length','forEach','string','picklist','type','idField','content','variable','variableName','customVariable','Variable','name','toLowerCase','indexOf','isNil','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','POST','refreshToken','clientId','clientSecret','refresh_token','then','access_token','add','catch'];(function(_0x53f497,_0x196992){var _0x421ddb=function(_0x4e1b0d){while(--_0x4e1b0d){_0x53f497['push'](_0x53f497['shift']());}};_0x421ddb(++_0x196992);}(_0x0903,0x105));var _0x3090=function(_0x5af97c,_0x24a49f){_0x5af97c=_0x5af97c-0x0;var _0x3472ae=_0x0903[_0x5af97c];return _0x3472ae;};'use strict';var _=require(_0x3090('0x0'));var rp=require('request-promise');var md5=require(_0x3090('0x1'));var util=require(_0x3090('0x2'));var intUtil=require(_0x3090('0x3'));var moment=require(_0x3090('0x4'));var Redis=require('ioredis');var BPromise=require('bluebird');var config=require(_0x3090('0x5'));var logger=require(_0x3090('0x6'))(_0x3090('0x7'));config[_0x3090('0x8')]=_[_0x3090('0x9')](config[_0x3090('0x8')],{'host':'localhost','port':0x18eb});var io=require(_0x3090('0xa'))(new Redis(config[_0x3090('0x8')]));function emit(_0x20dda2,_0x47056c,_0xe378bb){io['to'](_0x20dda2)[_0x3090('0xb')](_0x47056c,_0xe378bb);}function request(_0x478a3e){logger[_0x3090('0xc')](_0x3090('0xd'),JSON[_0x3090('0xe')](_0x478a3e));return rp(_0x478a3e);}function getCustomFields(_0xb8e6a7,_0x210526){var _0x4e32f0={};if(_0xb8e6a7[_0x3090('0xf')]>0x0){_[_0x3090('0x10')](_0xb8e6a7,function(_0x1b5cef){if(_['includes']([_0x3090('0x11'),_0x3090('0x12')],_0x1b5cef[_0x3090('0x13')])&&_0x1b5cef[_0x3090('0x14')]){_0x4e32f0[_0x1b5cef[_0x3090('0x14')]]=_0x1b5cef[_0x3090('0x15')]['toString']();}else if(_0x1b5cef['type']===_0x3090('0x16')&&_0x1b5cef['variableName']&&_0x1b5cef[_0x3090('0x14')]&&_0x210526[_0x1b5cef[_0x3090('0x17')]]){_0x4e32f0[_0x1b5cef[_0x3090('0x14')]]=_0x210526[_0x1b5cef[_0x3090('0x17')]]['toString']();}else if(_0x1b5cef[_0x3090('0x13')]===_0x3090('0x18')&&_0x1b5cef[_0x3090('0x19')]&&_0x1b5cef[_0x3090('0x19')][_0x3090('0x1a')]&&_0x1b5cef[_0x3090('0x14')]&&_0x210526[_0x1b5cef['Variable']['name'][_0x3090('0x1b')]()]){_0x4e32f0[_0x1b5cef[_0x3090('0x14')]]=_0x210526[_0x1b5cef[_0x3090('0x19')]['name'][_0x3090('0x1b')]()]['toString']();}});}return _0x4e32f0;}function getName(_0x4c3d27){if(_0x4c3d27[_0x3090('0x1c')]('\x20')>0x0){var _0x1e5d93=_0x4c3d27['split'](/ (.+)/);if(_0x1e5d93[0x1]){return _0x1e5d93;}}return[_0x4c3d27,_0x4c3d27];}var accountsTokens={};function getAccessToken(_0x297237){return new Promise(function(_0x86ccdb,_0x2832d4){if(!_[_0x3090('0x1d')](accountsTokens[_0x297237['id']])&&!_[_0x3090('0x1d')](accountsTokens[_0x297237['id']]['access_token'])){if(moment()['isBefore'](accountsTokens[_0x297237['id']][_0x3090('0x1e')])){_0x86ccdb(accountsTokens[_0x297237['id']]['access_token']);}}var _0x27ebad;switch(_0x297237[_0x3090('0x1f')]){case'US':_0x27ebad=_0x3090('0x20');break;case'AU':_0x27ebad=_0x3090('0x21');break;case'EU':_0x27ebad=_0x3090('0x22');break;case'IN':_0x27ebad=_0x3090('0x23');break;case'CN':_0x27ebad='https://accounts.zoho.com.cn';break;default:_0x27ebad='https://accounts.zoho.eu';break;}var _0x1a819b={'method':_0x3090('0x24'),'uri':_0x27ebad+'/oauth/v2/token','qs':{'refresh_token':_0x297237[_0x3090('0x25')],'client_id':_0x297237[_0x3090('0x26')],'client_secret':_0x297237[_0x3090('0x27')],'grant_type':_0x3090('0x28')},'json':!![]};return rp(_0x1a819b)[_0x3090('0x29')](function(_0x5a2f32){accountsTokens[_0x297237['id']]={'access_token':_0x5a2f32[_0x3090('0x2a')],'expires_in':moment()[_0x3090('0x2b')](_0x5a2f32['expires_in'],'seconds')};_0x86ccdb(_0x5a2f32[_0x3090('0x2a')]);})[_0x3090('0x2c')](function(_0x1660a0){logger[_0x3090('0x2d')]('Failing\x20creating\x20the\x20access_token',_0x1660a0[_0x3090('0x2e')]);_0x2832d4(_0x1660a0);});});}function getUser(_0x1f6483,_0x3536ae,_0xc97d92,_0x5f4618){logger[_0x3090('0x2f')](_0x3090('0x30'));return request({'method':_0x3090('0x31'),'uri':util[_0x3090('0x32')](_0x3090('0x33'),_0x3536ae),'qs':{'type':_0x3090('0x34')},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x1f6483},'json':!![]})[_0x3090('0x29')](function(_0x403519){if(_0x403519[_0x3090('0x35')]){var _0x5db45c=-0x1;if(_[_0x3090('0x36')](_0x403519['users'])){if(!_[_0x3090('0x1d')](_0x5f4618)){_0x5db45c=_[_0x3090('0x37')](_0x403519[_0x3090('0x35')],function(_0x2f0dc8){return _0x2f0dc8[_0x3090('0x38')]===_0x5f4618;});}if(_0x5db45c>=0x0){logger[_0x3090('0x2f')](_0x3090('0x39'));}else{logger['info'](_0x3090('0x3a'));_0x5db45c=_[_0x3090('0x37')](_0x403519[_0x3090('0x35')],function(_0x8b4621){return _0x8b4621[_0x3090('0x3b')][_0x3090('0x1a')]===_0x3090('0x3c');});}return _0x403519[_0x3090('0x35')][_0x5db45c];}else{if(_0x403519[_0x3090('0x3d')][_0x3090('0x3b')][_0x3090('0x1a')]===_0x3090('0x3c')){logger[_0x3090('0x2f')](_0x3090('0x3a'));user=_0x403519['user'];return user;}else{logger[_0x3090('0x2d')]('The\x20failing\x20result\x20is',JSON['stringify'](_0x403519));throw new Error(_0x3090('0x3e')+JSON[_0x3090('0xe')](_0x403519));}}}else{logger[_0x3090('0x2d')](_0x3090('0x3f'),JSON[_0x3090('0xe')](_0x403519));throw new Error(_0x3090('0x3e')+JSON[_0x3090('0xe')](_0x403519));}})['catch'](function(_0x1fd058){console['error'](_0x1fd058);});}function getZohoUser(_0x24f733,_0x577c0d){return new BPromise(function(_0x16cb77,_0x300588){request(_0x24f733)['then'](function(_0x17e1f8){var _0x55937f=null;if(_0x17e1f8){_0x55937f=_0x17e1f8[_0x3090('0x40')][0x0];_0x55937f[_0x3090('0x41')]=_0x577c0d;}_0x16cb77(_0x55937f);})[_0x3090('0x2c')](function(_0x5d8313){_0x300588(_0x5d8313);});});}function createEndUser(_0x5babd6,_0x1e1373,_0x47f321,_0x17edea,_0x89e842,_0x189df1){var _0x47f321=getName(_0x47f321);return request({'method':'POST','uri':_0x3090('0x42')+_0x1e1373+_0x3090('0x43')+_['startCase'](_0x189df1[_0x3090('0x44')])+'s','body':{'data':[{'Last_Name':_0x47f321[0x1],'First_Name':_0x47f321[0x0],'Phone':_0x17edea,'Owner':{'name':!_[_0x3090('0x1d')](_0x89e842['role'][_0x3090('0x1a')])?_0x89e842[_0x3090('0x45')][_0x3090('0x1a')]:!_[_0x3090('0x1d')](_0x89e842['first_name'])?_0x89e842['first_name']+'\x20'+_0x89e842[_0x3090('0x46')]:_0x89e842[_0x3090('0x46')],'id':_0x89e842['id']}}]},'headers':{'Authorization':_0x3090('0x47')+_0x5babd6},'json':!![]})[_0x3090('0x29')](function(_0x3f8aa8){if(_0x3f8aa8&&_0x3f8aa8[_0x3090('0x40')][0x0][_0x3090('0x48')]===_0x3090('0x49')){var _0x55ee66=_0x3f8aa8[_0x3090('0x40')][0x0][_0x3090('0x4a')];_0x55ee66[_0x3090('0x41')]=_['startCase'](_0x189df1[_0x3090('0x44')])+'s';return _0x55ee66;}logger[_0x3090('0x2d')]('The\x20failing\x20result\x20is',JSON['stringify'](data));throw new Error('Error:\x20'+JSON[_0x3090('0xe')](data));})[_0x3090('0x2c')](function(_0x5add7a){console[_0x3090('0x4b')](_0x3090('0x4c'),_0x5add7a);});}function getEndUser(_0x4e7789,_0x5be69e,_0x20364d,_0x47df71,_0x28f0d6,_0x59a11b,_0x493645){var _0x1eb38c={'method':'GET','uri':'','headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x4e7789},'json':!![]};switch(_0x493645[_0x3090('0x4d')]){case _0x3090('0x4e'):_0x1eb38c[_0x3090('0x4f')]=_0x3090('0x42')+_0x5be69e+_0x3090('0x50')+_0x28f0d6+'))';return getZohoUser(_0x1eb38c,_0x3090('0x51'))[_0x3090('0x29')](function(_0x4592ba){if(_0x4592ba)return _0x4592ba;_0x1eb38c[_0x3090('0x4f')]=_0x3090('0x42')+_0x5be69e+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x28f0d6+'))';return getZohoUser(_0x1eb38c,_0x3090('0x52'))['then'](function(_0x4e34ec){if(_0x4e34ec)return _0x4e34ec;if(_0x493645['moduleCreate']!=_0x3090('0x53')){return createEndUser(_0x4e7789,_0x5be69e,_0x47df71,_0x28f0d6,_0x59a11b,_0x493645);}else{return{};}});});break;case _0x3090('0x54'):_0x1eb38c[_0x3090('0x4f')]=_0x3090('0x42')+_0x5be69e+_0x3090('0x50')+_0x28f0d6+'))';return getZohoUser(_0x1eb38c,_0x3090('0x51'))[_0x3090('0x29')](function(_0x538422){if(_0x538422)return _0x538422;if(_0x493645[_0x3090('0x44')]!=_0x3090('0x53')){return createEndUser(_0x4e7789,_0x5be69e,_0x47df71,_0x28f0d6,_0x59a11b,_0x493645);}else{return{};}});break;case _0x3090('0x55'):_0x1eb38c[_0x3090('0x4f')]=_0x3090('0x42')+_0x5be69e+_0x3090('0x56')+_0x28f0d6+'))';return getZohoUser(_0x1eb38c,'Leads')['then'](function(_0x271dcc){if(_0x271dcc)return _0x271dcc;if(_0x493645['moduleCreate']!='nothing'){return createEndUser(_0x4e7789,_0x5be69e,_0x47df71,_0x28f0d6,_0x59a11b,_0x493645);}else{return{};}});break;}}function getCall(_0x52658e,_0x5de0bb,_0x45672c,_0x4fa6eb,_0x2d600e,_0x493e83,_0x1cbd9c,_0xa0c486){logger[_0x3090('0x2f')](_0x3090('0x57'));var _0x2bf9d9={};_0x2bf9d9[_0x3090('0x58')]={'name':!_['isNil'](_0x4fa6eb['role'][_0x3090('0x1a')])&&!_['isNil'](_0x4fa6eb[_0x3090('0x3b')]['name'])&&_0x4fa6eb[_0x3090('0x3b')]['name']===_0x3090('0x59')?_0x4fa6eb[_0x3090('0x45')]['name']:!_[_0x3090('0x1d')](_0x4fa6eb[_0x3090('0x5a')])?_0x4fa6eb[_0x3090('0x5a')]+'\x20'+_0x4fa6eb[_0x3090('0x46')]:_0x4fa6eb[_0x3090('0x46')],'id':_0x4fa6eb['id']};_0x2bf9d9[_0x3090('0x5b')]=intUtil[_0x3090('0x5c')](_0x493e83[_0x3090('0x5d')],_0x1cbd9c,'\x20');_0x2bf9d9[_0x3090('0x5e')]=intUtil['getString'](_0x493e83['Descriptions'],_0x1cbd9c,'\x0a');if(_0x2d600e[_0x3090('0x41')]===_0x3090('0x51')){_0x2bf9d9[_0x3090('0x5f')]={'name':!_['isNil'](_0x2d600e[_0x3090('0x60')])?_0x2d600e[_0x3090('0x60')]:!_[_0x3090('0x1d')](_0x2d600e[_0x3090('0x61')])?_0x2d600e['First_Name']+'\x20'+_0x2d600e['Last_Name']:_0x2d600e[_0x3090('0x62')],'id':_0x2d600e['id']};}if(_0x2d600e[_0x3090('0x41')]===_0x3090('0x52')){_0x2bf9d9['What_Id']={'name':!_['isNil'](_0x2d600e[_0x3090('0x60')])?_0x2d600e[_0x3090('0x60')]:!_[_0x3090('0x1d')](_0x2d600e['First_Name'])?_0x2d600e[_0x3090('0x61')]+'\x20'+_0x2d600e['Last_Name']:_0x2d600e[_0x3090('0x62')],'id':_0x2d600e['id']};_0x2bf9d9[_0x3090('0x63')]=_[_0x3090('0x64')](_0x2d600e[_0x3090('0x41')]);}if(_0x1cbd9c[_0x3090('0x65')]){_0x2bf9d9[_0x3090('0x66')]=moment[_0x3090('0x67')](parseInt(_0x1cbd9c['talktime'])*0x3e8)[_0x3090('0x32')](_0x3090('0x68'));}else if(_0x1cbd9c['answertime']&&_0x1cbd9c[_0x3090('0x69')]){_0x2bf9d9[_0x3090('0x66')]=moment[_0x3090('0x67')](moment(_0x1cbd9c[_0x3090('0x69')],'YYYY-MM-DDTHH:mm:ss')[_0x3090('0x6a')](moment(_0x1cbd9c['starttime'],_0x3090('0x6b'))))['format']('mm:ss');}switch(_0x1cbd9c['lastevent']){case'called':_0x2bf9d9[_0x3090('0x6c')]=_0x3090('0x6d');break;case'complete':case _0x3090('0x6e'):_0x2bf9d9['Call_Result']=_0x3090('0x6f');break;case _0x3090('0x70'):_0x2bf9d9[_0x3090('0x6c')]=_0x3090('0x71');break;case _0x3090('0x72'):_0x2bf9d9['Call_Result']=_0x3090('0x73');break;case'timeout':_0x2bf9d9[_0x3090('0x6c')]=_0x3090('0x74');default:}_0x2bf9d9[_0x3090('0x75')]=(_0xa0c486===_0x3090('0x76')?moment(_0x1cbd9c[_0x3090('0x77')])['format'](_0x3090('0x6b')):moment(_0x1cbd9c['agentcalledAt'])[_0x3090('0x32')](_0x3090('0x6b')))||moment()['format'](_0x3090('0x6b'));_0x2bf9d9['Call_Type']=_0xa0c486||_0x3090('0x78');_0x2bf9d9=_['merge'](_0x2bf9d9,getCustomFields(_0x493e83[_0x3090('0x79')],_0x1cbd9c));return request({'method':'POST','uri':'https://www.zohoapis.'+_0x5de0bb+_0x3090('0x7a'),'headers':{'Authorization':_0x3090('0x47')+_0x52658e},'body':{'data':[_0x2bf9d9]},'json':!![]})[_0x3090('0x29')](function(_0x43af8b){if(_0x43af8b&&_0x43af8b['data'][0x0][_0x3090('0x48')]===_0x3090('0x49')){logger[_0x3090('0x2f')](_0x3090('0x7b'));return{'id':_0x43af8b[_0x3090('0x40')][0x0][_0x3090('0x4a')]['id']};}})[_0x3090('0x2c')](function(_0x2e9e01){logger['info'](_0x3090('0x7c'),_0x2e9e01[_0x3090('0x2e')]);console[_0x3090('0x4b')](_0x3090('0x7c'),_0x2e9e01);});}exports[_0x3090('0x7d')]=function(_0x242a42,_0x3503d7,_0x438ba1,_0x905042,_0xe603da,_0x48de19){var _0x1269e5,_0x451d1,_0x20b6dc;_0x48de19[_0x3090('0x7e')]=intUtil[_0x3090('0x7f')](_0x48de19[_0x3090('0x7e')]);_0x48de19['serverUrl']=intUtil[_0x3090('0x7f')](_0x48de19[_0x3090('0x80')]);if(_0xe603da&&_0xe603da[_0x3090('0x81')]){logger[_0x3090('0x2f')](_0x3090('0x82'),'Recording\x20is\x20enabled!');_0x3503d7[_0x3090('0x83')]=_0x48de19['serverUrl']+_0x3090('0x84')+_0x3503d7[_0x3090('0x85')]+_0x3090('0x86')+md5(_0x3503d7[_0x3090('0x85')]);}else{_0x3503d7[_0x3090('0x83')]='';}var _0x1e920e=_0x48de19[_0x3090('0x7e')]==='zoho.eu'?'eu':_0x3090('0x87');return getAccessToken(_0x48de19)['then'](function(_0x3b56a5){_0x20b6dc=_0x3b56a5;return getUser(_0x20b6dc,_0x1e920e,_0x48de19,_0x905042['email']);})['then'](function(_0x18fdc0){_0x1269e5=_0x18fdc0;logger['info'](_0x3090('0x88'),_0x1269e5['id']);return getEndUser(_0x20b6dc,_0x1e920e,_0x48de19,_0x3503d7['calleridname'],_0x3503d7[_0x3090('0x89')],_0x1269e5,_0x438ba1);})[_0x3090('0x29')](function(_0x57a76c){_0x451d1=_0x57a76c;return getCall(_0x20b6dc,_0x1e920e,_0x48de19,_0x1269e5,_0x451d1,_0x438ba1,_0x3503d7,_0x3090('0x78'));})[_0x3090('0x29')](function(_0x258860){if(_0x258860){logger['info'](_0x3090('0x8a'),_0x258860['id']);logger[_0x3090('0x2f')](_0x3090('0x82'),_0x3090('0x8b'));emit(util['format'](_0x3090('0x8c'),_0x905042[_0x3090('0x1a')]),_0x3090('0x8d'),{'uri':_0x3090('0x8e')+_0x48de19[_0x3090('0x7e')]+'/crm/EntityInfo.do?module=Calls&id='+_0x258860['id']});}})[_0x3090('0x2c')](function(_0x4a107c){logger[_0x3090('0x2d')](_0x3090('0x82'),JSON[_0x3090('0xe')](_0x4a107c));});};exports['outbound']=function(_0x3ce358,_0x3cc28f,_0x23ae8d,_0x7613d4,_0x260b37,_0x484422,_0x119ff6){var _0x1e285d,_0x24ef9c,_0x3d6da7;_0x484422[_0x3090('0x7e')]=intUtil[_0x3090('0x7f')](_0x484422['host']);_0x484422[_0x3090('0x80')]=intUtil['stripTrailingSlash'](_0x484422['serverUrl']);if(_0x119ff6&&_0x119ff6[_0x3090('0x8f')]&&_0x119ff6[_0x3090('0x8f')]!==_0x3090('0x90')){logger[_0x3090('0x2f')](_0x3090('0x91'),_0x3090('0x92'));_0x3cc28f[_0x3090('0x83')]=_0x484422[_0x3090('0x80')]+'/api/voice/recordings/'+_0x3cc28f['uniqueid']+_0x3090('0x86')+md5(_0x3cc28f[_0x3090('0x85')]);}var _0x324329=_0x484422[_0x3090('0x7e')]===_0x3090('0x93')?'eu':_0x3090('0x87');return getAccessToken(_0x484422)[_0x3090('0x29')](function(_0x136482){_0x3d6da7=_0x136482;return getUser(_0x3d6da7,_0x324329,_0x484422,_0x7613d4[_0x3090('0x38')]);})[_0x3090('0x29')](function(_0x8e717){_0x1e285d=_0x8e717;logger[_0x3090('0x2f')]('The\x20User\x20ID\x20is:',_0x1e285d['id']);return getEndUser(_0x3d6da7,_0x324329,_0x484422,_0x3cc28f['destcalleridname'],_0x3cc28f[_0x3090('0x94')],_0x1e285d,_0x23ae8d);})[_0x3090('0x29')](function(_0x42cf64){_0x24ef9c=_0x42cf64;return getCall(_0x3d6da7,_0x324329,_0x484422,_0x1e285d,_0x24ef9c,_0x23ae8d,_0x3cc28f,_0x3090('0x95'));})[_0x3090('0x29')](function(_0x4a06ab){if(_0x4a06ab){logger[_0x3090('0x2f')](_0x3090('0x8a'),_0x4a06ab['id']);logger[_0x3090('0x2f')](_0x3090('0x91'),_0x3090('0x8b'));emit(util[_0x3090('0x32')](_0x3090('0x8c'),_0x7613d4['name']),'trigger:browser:url',{'uri':_0x3090('0x8e')+_0x484422[_0x3090('0x7e')]+_0x3090('0x96')+_0x4a06ab['id']});}})[_0x3090('0x2c')](function(_0x20fc15){logger[_0x3090('0x2d')](_0x3090('0x91'),JSON[_0x3090('0xe')](_0x20fc15));});};exports['unmanaged']=function(_0x373684,_0x4f3b76,_0x540f10,_0x364754,_0x1c2bfe,_0x3c8867){var _0x5f4f24,_0x45777c,_0x3dc639;_0x3c8867['host']=intUtil['stripTrailingSlash'](_0x3c8867[_0x3090('0x7e')]);_0x3c8867[_0x3090('0x80')]=intUtil[_0x3090('0x7f')](_0x3c8867[_0x3090('0x80')]);if(_0x1c2bfe&&_0x1c2bfe['monitor_format']){logger['info']('['+_0x4f3b76[_0x3090('0x97')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x4f3b76[_0x3090('0x83')]=_0x3c8867[_0x3090('0x80')]+'/api/voice/recordings/'+_0x4f3b76[_0x3090('0x85')]+_0x3090('0x86')+md5(_0x4f3b76['uniqueid']);}else{_0x4f3b76['recordingURL']='';}var _0x283168=_0x3c8867[_0x3090('0x7e')]===_0x3090('0x93')?'eu':_0x3090('0x87');return getAccessToken(_0x3c8867)[_0x3090('0x29')](function(_0x260ff7){_0x3dc639=_0x260ff7;return getUser(_0x3dc639,_0x283168,_0x3c8867);})[_0x3090('0x29')](function(_0x5b2f83){_0x5f4f24=_0x5b2f83;logger[_0x3090('0x2f')](_0x3090('0x88'),_0x5f4f24['id']);return getEndUser(_0x3dc639,_0x283168,_0x3c8867,_0x4f3b76[_0x3090('0x98')],_0x4f3b76[_0x3090('0x89')],_0x5f4f24,_0x540f10);})[_0x3090('0x29')](function(_0x45065b){_0x45777c=_0x45065b;return getCall(_0x3dc639,_0x283168,_0x3c8867,_0x5f4f24,_0x45777c,_0x540f10,_0x4f3b76,_0x3090('0x78'));})['then'](function(_0x31d1e9){if(_0x31d1e9){logger[_0x3090('0x2f')](_0x3090('0x8a'),_0x31d1e9['id']);}})[_0x3090('0x2c')](function(_0x3c95b5){logger['error']('['+_0x4f3b76[_0x3090('0x97')]['toUpperCase']()+']',JSON[_0x3090('0xe')](_0x3c95b5));});};
\ No newline at end of file
+var _0x1f7f=['rejected','Rejected','abandoned','Abandoned','timeout','Timeout','Call_Start_Time','outbound','agentcalledAt','Inbound','/crm/v2/Calls','data','err','stack','stripTrailingSlash','host','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/api/voice/recordings/','uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Call\x20ID\x20is:','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','unmanaged','toUpperCase','lodash','request-promise','md5','./util','moment','ioredis','bluebird','../../../../config/logger','zoho','redis','defaults','localhost','[HTTP]','stringify','length','includes','string','picklist','type','idField','content','toString','variable','variableName','customVariable','Variable','name','split','isNil','access_token','isBefore','zone','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','refreshToken','refresh_token','then','add','expires_in','seconds','catch','error','Failing\x20creating\x20the\x20access_token','info','Search\x20user','GET','ActiveUsers','Zoho-oauthtoken\x20','users','isArrayLikeObject','findIndex','Agent\x20found!','profile','Administrator','user','Using\x20the\x20admin\x20account!','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','SUCCESS','details','enduserType','Error:\x20','log','contact_lead','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','Leads','nothing','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','Creating\x20new\x20call...','administrator','Subject','getString','Who_Id','Full_Name','First_Name','Last_Name','What_Id','Call_Duration','utc','talktime','format','mm:ss','answertime','endtime','diff','starttime','YYYY-MM-DDTHH:mm:ss','lastevent','called','connect','Call_Result'];(function(_0x3f465d,_0xbd2037){var _0x121ad1=function(_0x5b13d6){while(--_0x5b13d6){_0x3f465d['push'](_0x3f465d['shift']());}};_0x121ad1(++_0xbd2037);}(_0x1f7f,0xbd));var _0xf1f7=function(_0x337d93,_0x7908a5){_0x337d93=_0x337d93-0x0;var _0x52a98b=_0x1f7f[_0x337d93];return _0x52a98b;};'use strict';var _=require(_0xf1f7('0x0'));var rp=require(_0xf1f7('0x1'));var md5=require(_0xf1f7('0x2'));var util=require('util');var intUtil=require(_0xf1f7('0x3'));var moment=require(_0xf1f7('0x4'));var Redis=require(_0xf1f7('0x5'));var BPromise=require(_0xf1f7('0x6'));var config=require('../../../../config/environment');var logger=require(_0xf1f7('0x7'))(_0xf1f7('0x8'));config[_0xf1f7('0x9')]=_[_0xf1f7('0xa')](config[_0xf1f7('0x9')],{'host':_0xf1f7('0xb'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xf1f7('0x9')]));function emit(_0x1d4402,_0x2d5df5,_0x249349){io['to'](_0x1d4402)['emit'](_0x2d5df5,_0x249349);}function request(_0x4db612){logger['debug'](_0xf1f7('0xc'),JSON[_0xf1f7('0xd')](_0x4db612));return rp(_0x4db612);}function getCustomFields(_0x158281,_0x264431){var _0x1a1129={};if(_0x158281[_0xf1f7('0xe')]>0x0){_['forEach'](_0x158281,function(_0x2eda95){if(_[_0xf1f7('0xf')]([_0xf1f7('0x10'),_0xf1f7('0x11')],_0x2eda95[_0xf1f7('0x12')])&&_0x2eda95['idField']){_0x1a1129[_0x2eda95[_0xf1f7('0x13')]]=_0x2eda95[_0xf1f7('0x14')][_0xf1f7('0x15')]();}else if(_0x2eda95[_0xf1f7('0x12')]===_0xf1f7('0x16')&&_0x2eda95[_0xf1f7('0x17')]&&_0x2eda95[_0xf1f7('0x13')]&&_0x264431[_0x2eda95[_0xf1f7('0x17')]]){_0x1a1129[_0x2eda95[_0xf1f7('0x13')]]=_0x264431[_0x2eda95['variableName']][_0xf1f7('0x15')]();}else if(_0x2eda95[_0xf1f7('0x12')]===_0xf1f7('0x18')&&_0x2eda95[_0xf1f7('0x19')]&&_0x2eda95[_0xf1f7('0x19')][_0xf1f7('0x1a')]&&_0x2eda95['idField']&&_0x264431[_0x2eda95[_0xf1f7('0x19')][_0xf1f7('0x1a')]['toLowerCase']()]){_0x1a1129[_0x2eda95[_0xf1f7('0x13')]]=_0x264431[_0x2eda95['Variable'][_0xf1f7('0x1a')]['toLowerCase']()][_0xf1f7('0x15')]();}});}return _0x1a1129;}function getName(_0x28eec){if(_0x28eec['indexOf']('\x20')>0x0){var _0x4f8791=_0x28eec[_0xf1f7('0x1b')](/ (.+)/);if(_0x4f8791[0x1]){return _0x4f8791;}}return[_0x28eec,_0x28eec];}var accountsTokens={};function getAccessToken(_0x44b0ce){return new Promise(function(_0x953206,_0x6fcd81){if(!_[_0xf1f7('0x1c')](accountsTokens[_0x44b0ce['id']])&&!_[_0xf1f7('0x1c')](accountsTokens[_0x44b0ce['id']][_0xf1f7('0x1d')])){if(moment()[_0xf1f7('0x1e')](accountsTokens[_0x44b0ce['id']]['expires_in'])){_0x953206(accountsTokens[_0x44b0ce['id']][_0xf1f7('0x1d')]);}}var _0x2fc24c;switch(_0x44b0ce[_0xf1f7('0x1f')]){case'US':_0x2fc24c='https://accounts.zoho.com';break;case'AU':_0x2fc24c='https://accounts.zoho.com.au';break;case'EU':_0x2fc24c=_0xf1f7('0x20');break;case'IN':_0x2fc24c=_0xf1f7('0x21');break;case'CN':_0x2fc24c=_0xf1f7('0x22');break;default:_0x2fc24c=_0xf1f7('0x20');break;}var _0x1da0a8={'method':_0xf1f7('0x23'),'uri':_0x2fc24c+'/oauth/v2/token','qs':{'refresh_token':_0x44b0ce[_0xf1f7('0x24')],'client_id':_0x44b0ce['clientId'],'client_secret':_0x44b0ce['clientSecret'],'grant_type':_0xf1f7('0x25')},'json':!![]};return rp(_0x1da0a8)[_0xf1f7('0x26')](function(_0x212202){accountsTokens[_0x44b0ce['id']]={'access_token':_0x212202['access_token'],'expires_in':moment()[_0xf1f7('0x27')](_0x212202[_0xf1f7('0x28')],_0xf1f7('0x29'))};_0x953206(_0x212202[_0xf1f7('0x1d')]);})[_0xf1f7('0x2a')](function(_0x98241f){logger[_0xf1f7('0x2b')](_0xf1f7('0x2c'),_0x98241f['stack']);_0x6fcd81(_0x98241f);});});}function getUser(_0x27329d,_0x136def,_0x16715f,_0x2dd90e){logger[_0xf1f7('0x2d')](_0xf1f7('0x2e'));return request({'method':_0xf1f7('0x2f'),'uri':util['format']('https://www.zohoapis.%s/crm/v2/users',_0x136def),'qs':{'type':_0xf1f7('0x30')},'headers':{'Authorization':_0xf1f7('0x31')+_0x27329d},'json':!![]})['then'](function(_0x4bac5f){if(_0x4bac5f[_0xf1f7('0x32')]){var _0x40a792=-0x1;if(_[_0xf1f7('0x33')](_0x4bac5f[_0xf1f7('0x32')])){if(!_[_0xf1f7('0x1c')](_0x2dd90e)){_0x40a792=_[_0xf1f7('0x34')](_0x4bac5f[_0xf1f7('0x32')],function(_0x15f164){return _0x15f164['email']===_0x2dd90e;});}if(_0x40a792>=0x0){logger[_0xf1f7('0x2d')](_0xf1f7('0x35'));}else{logger['info']('Using\x20the\x20admin\x20account!');_0x40a792=_[_0xf1f7('0x34')](_0x4bac5f[_0xf1f7('0x32')],function(_0xf28755){return _0xf28755[_0xf1f7('0x36')][_0xf1f7('0x1a')]===_0xf1f7('0x37');});}return _0x4bac5f['users'][_0x40a792];}else{if(_0x4bac5f[_0xf1f7('0x38')]['profile'][_0xf1f7('0x1a')]===_0xf1f7('0x37')){logger[_0xf1f7('0x2d')](_0xf1f7('0x39'));user=_0x4bac5f[_0xf1f7('0x38')];return user;}else{logger['error'](_0xf1f7('0x3a'),JSON[_0xf1f7('0xd')](_0x4bac5f));throw new Error(_0xf1f7('0x3b')+JSON[_0xf1f7('0xd')](_0x4bac5f));}}}else{logger[_0xf1f7('0x2b')](_0xf1f7('0x3a'),JSON[_0xf1f7('0xd')](_0x4bac5f));throw new Error(_0xf1f7('0x3b')+JSON[_0xf1f7('0xd')](_0x4bac5f));}})[_0xf1f7('0x2a')](function(_0x485643){console[_0xf1f7('0x2b')](_0x485643);});}function getZohoUser(_0x44f83d,_0x3712f1){return new BPromise(function(_0x523a76,_0x18bc64){request(_0x44f83d)[_0xf1f7('0x26')](function(_0x3c045f){var _0x3f471a=null;if(_0x3c045f){_0x3f471a=_0x3c045f['data'][0x0];_0x3f471a['enduserType']=_0x3712f1;}_0x523a76(_0x3f471a);})[_0xf1f7('0x2a')](function(_0x5de960){_0x18bc64(_0x5de960);});});}function createEndUser(_0x50955f,_0x2e0e13,_0x42228d,_0x4357a2,_0x553c79,_0x21bf83){var _0x42228d=getName(_0x42228d);return request({'method':_0xf1f7('0x23'),'uri':_0xf1f7('0x3c')+_0x2e0e13+_0xf1f7('0x3d')+_[_0xf1f7('0x3e')](_0x21bf83[_0xf1f7('0x3f')])+'s','body':{'data':[{'Last_Name':_0x42228d[0x1],'First_Name':_0x42228d[0x0],'Phone':_0x4357a2,'Owner':{'name':!_[_0xf1f7('0x1c')](_0x553c79[_0xf1f7('0x40')]['name'])?_0x553c79['role'][_0xf1f7('0x1a')]:!_['isNil'](_0x553c79[_0xf1f7('0x41')])?_0x553c79[_0xf1f7('0x41')]+'\x20'+_0x553c79[_0xf1f7('0x42')]:_0x553c79[_0xf1f7('0x42')],'id':_0x553c79['id']}}]},'headers':{'Authorization':_0xf1f7('0x31')+_0x50955f},'json':!![]})[_0xf1f7('0x26')](function(_0x47fe13){if(_0x47fe13&&_0x47fe13['data'][0x0]['code']===_0xf1f7('0x43')){var _0x572fc5=_0x47fe13['data'][0x0][_0xf1f7('0x44')];_0x572fc5[_0xf1f7('0x45')]=_[_0xf1f7('0x3e')](_0x21bf83['moduleCreate'])+'s';return _0x572fc5;}logger[_0xf1f7('0x2b')](_0xf1f7('0x3a'),JSON['stringify'](data));throw new Error(_0xf1f7('0x46')+JSON[_0xf1f7('0xd')](data));})[_0xf1f7('0x2a')](function(_0x3cfafa){console[_0xf1f7('0x47')]('CREATE\x20ERROR',_0x3cfafa);});}function getEndUser(_0x1c6525,_0x36e384,_0x295bcf,_0x3cb579,_0x388e84,_0x140091,_0x3e92aa){var _0x410f5d={'method':'GET','uri':'','headers':{'Authorization':_0xf1f7('0x31')+_0x1c6525},'json':!![]};switch(_0x3e92aa['moduleSearch']){case _0xf1f7('0x48'):_0x410f5d[_0xf1f7('0x49')]=_0xf1f7('0x3c')+_0x36e384+_0xf1f7('0x4a')+_0x388e84+'))';return getZohoUser(_0x410f5d,_0xf1f7('0x4b'))[_0xf1f7('0x26')](function(_0x4951fb){if(_0x4951fb)return _0x4951fb;_0x410f5d[_0xf1f7('0x49')]=_0xf1f7('0x3c')+_0x36e384+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x388e84+'))';return getZohoUser(_0x410f5d,_0xf1f7('0x4c'))[_0xf1f7('0x26')](function(_0x7ef38b){if(_0x7ef38b)return _0x7ef38b;if(_0x3e92aa[_0xf1f7('0x3f')]!=_0xf1f7('0x4d')){return createEndUser(_0x1c6525,_0x36e384,_0x3cb579,_0x388e84,_0x140091,_0x3e92aa);}else{return{};}});});break;case'contact':_0x410f5d['uri']=_0xf1f7('0x3c')+_0x36e384+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x388e84+'))';return getZohoUser(_0x410f5d,_0xf1f7('0x4b'))[_0xf1f7('0x26')](function(_0x1a33d2){if(_0x1a33d2)return _0x1a33d2;if(_0x3e92aa[_0xf1f7('0x3f')]!=_0xf1f7('0x4d')){return createEndUser(_0x1c6525,_0x36e384,_0x3cb579,_0x388e84,_0x140091,_0x3e92aa);}else{return{};}});break;case _0xf1f7('0x4e'):_0x410f5d['uri']=_0xf1f7('0x3c')+_0x36e384+_0xf1f7('0x4f')+_0x388e84+'))';return getZohoUser(_0x410f5d,'Leads')[_0xf1f7('0x26')](function(_0x4a8ed1){if(_0x4a8ed1)return _0x4a8ed1;if(_0x3e92aa[_0xf1f7('0x3f')]!=_0xf1f7('0x4d')){return createEndUser(_0x1c6525,_0x36e384,_0x3cb579,_0x388e84,_0x140091,_0x3e92aa);}else{return{};}});break;}}function getCall(_0x54920b,_0x499499,_0x1b13c3,_0x1e38d7,_0x36613a,_0x158c31,_0x164a06,_0xb26840){logger[_0xf1f7('0x2d')](_0xf1f7('0x50'));var _0x365326={};_0x365326['Owner']={'name':!_[_0xf1f7('0x1c')](_0x1e38d7[_0xf1f7('0x40')][_0xf1f7('0x1a')])&&!_[_0xf1f7('0x1c')](_0x1e38d7[_0xf1f7('0x36')][_0xf1f7('0x1a')])&&_0x1e38d7[_0xf1f7('0x36')][_0xf1f7('0x1a')]===_0xf1f7('0x51')?_0x1e38d7['role'][_0xf1f7('0x1a')]:!_[_0xf1f7('0x1c')](_0x1e38d7[_0xf1f7('0x41')])?_0x1e38d7[_0xf1f7('0x41')]+'\x20'+_0x1e38d7[_0xf1f7('0x42')]:_0x1e38d7['last_name'],'id':_0x1e38d7['id']};_0x365326[_0xf1f7('0x52')]=intUtil[_0xf1f7('0x53')](_0x158c31['Subjects'],_0x164a06,'\x20');_0x365326['Description']=intUtil[_0xf1f7('0x53')](_0x158c31['Descriptions'],_0x164a06,'\x0a');if(_0x36613a[_0xf1f7('0x45')]===_0xf1f7('0x4b')){_0x365326[_0xf1f7('0x54')]={'name':!_[_0xf1f7('0x1c')](_0x36613a[_0xf1f7('0x55')])?_0x36613a['Full_Name']:!_[_0xf1f7('0x1c')](_0x36613a[_0xf1f7('0x56')])?_0x36613a[_0xf1f7('0x56')]+'\x20'+_0x36613a[_0xf1f7('0x57')]:_0x36613a['Last_Name'],'id':_0x36613a['id']};}if(_0x36613a[_0xf1f7('0x45')]==='Leads'){_0x365326[_0xf1f7('0x58')]={'name':!_[_0xf1f7('0x1c')](_0x36613a[_0xf1f7('0x55')])?_0x36613a[_0xf1f7('0x55')]:!_[_0xf1f7('0x1c')](_0x36613a[_0xf1f7('0x56')])?_0x36613a[_0xf1f7('0x56')]+'\x20'+_0x36613a['Last_Name']:_0x36613a['Last_Name'],'id':_0x36613a['id']};_0x365326['$se_module']=_['startCase'](_0x36613a[_0xf1f7('0x45')]);}if(_0x164a06['talktime']){_0x365326[_0xf1f7('0x59')]=moment[_0xf1f7('0x5a')](parseInt(_0x164a06[_0xf1f7('0x5b')])*0x3e8)[_0xf1f7('0x5c')](_0xf1f7('0x5d'));}else if(_0x164a06[_0xf1f7('0x5e')]&&_0x164a06['endtime']){_0x365326[_0xf1f7('0x59')]=moment[_0xf1f7('0x5a')](moment(_0x164a06[_0xf1f7('0x5f')],'YYYY-MM-DDTHH:mm:ss')[_0xf1f7('0x60')](moment(_0x164a06[_0xf1f7('0x61')],_0xf1f7('0x62'))))[_0xf1f7('0x5c')](_0xf1f7('0x5d'));}switch(_0x164a06[_0xf1f7('0x63')]){case _0xf1f7('0x64'):_0x365326['Call_Result']='Called';break;case'complete':case _0xf1f7('0x65'):_0x365326[_0xf1f7('0x66')]='Answered';break;case _0xf1f7('0x67'):_0x365326['Call_Result']=_0xf1f7('0x68');break;case _0xf1f7('0x69'):_0x365326[_0xf1f7('0x66')]=_0xf1f7('0x6a');break;case _0xf1f7('0x6b'):_0x365326['Call_Result']=_0xf1f7('0x6c');default:}_0x365326[_0xf1f7('0x6d')]=(_0xb26840===_0xf1f7('0x6e')?moment(_0x164a06[_0xf1f7('0x61')])[_0xf1f7('0x5c')](_0xf1f7('0x62')):moment(_0x164a06[_0xf1f7('0x6f')])[_0xf1f7('0x5c')](_0xf1f7('0x62')))||moment()[_0xf1f7('0x5c')](_0xf1f7('0x62'));_0x365326['Call_Type']=_0xb26840||_0xf1f7('0x70');_0x365326=_['merge'](_0x365326,getCustomFields(_0x158c31['Fields'],_0x164a06));return request({'method':'POST','uri':_0xf1f7('0x3c')+_0x499499+_0xf1f7('0x71'),'headers':{'Authorization':_0xf1f7('0x31')+_0x54920b},'body':{'data':[_0x365326]},'json':!![]})[_0xf1f7('0x26')](function(_0xb3c0ca){if(_0xb3c0ca&&_0xb3c0ca[_0xf1f7('0x72')][0x0]['code']===_0xf1f7('0x43')){logger[_0xf1f7('0x2d')]('Call\x20created!');return{'id':_0xb3c0ca[_0xf1f7('0x72')][0x0][_0xf1f7('0x44')]['id']};}})[_0xf1f7('0x2a')](function(_0xd8e3fb){logger[_0xf1f7('0x2d')](_0xf1f7('0x73'),_0xd8e3fb[_0xf1f7('0x74')]);console[_0xf1f7('0x47')](_0xf1f7('0x73'),_0xd8e3fb);});}exports['queue']=function(_0x4241fc,_0x1d6cc8,_0x3d8f08,_0x5693de,_0x53e501,_0x5418b0){var _0x5d68fc,_0x423c2a,_0x34d0e9;_0x5418b0['host']=intUtil[_0xf1f7('0x75')](_0x5418b0[_0xf1f7('0x76')]);_0x5418b0[_0xf1f7('0x77')]=intUtil[_0xf1f7('0x75')](_0x5418b0[_0xf1f7('0x77')]);if(_0x53e501&&_0x53e501[_0xf1f7('0x78')]){logger[_0xf1f7('0x2d')](_0xf1f7('0x79'),_0xf1f7('0x7a'));_0x1d6cc8[_0xf1f7('0x7b')]=_0x5418b0[_0xf1f7('0x77')]+_0xf1f7('0x7c')+_0x1d6cc8[_0xf1f7('0x7d')]+_0xf1f7('0x7e')+md5(_0x1d6cc8[_0xf1f7('0x7d')]);}else{_0x1d6cc8[_0xf1f7('0x7b')]='';}var _0x26832f=_0x5418b0[_0xf1f7('0x76')]===_0xf1f7('0x7f')?'eu':_0xf1f7('0x80');return getAccessToken(_0x5418b0)[_0xf1f7('0x26')](function(_0x3b733e){_0x34d0e9=_0x3b733e;return getUser(_0x34d0e9,_0x26832f,_0x5418b0,_0x5693de[_0xf1f7('0x81')]);})['then'](function(_0x19b3c7){_0x5d68fc=_0x19b3c7;logger[_0xf1f7('0x2d')](_0xf1f7('0x82'),_0x5d68fc['id']);return getEndUser(_0x34d0e9,_0x26832f,_0x5418b0,_0x1d6cc8[_0xf1f7('0x83')],_0x1d6cc8[_0xf1f7('0x84')],_0x5d68fc,_0x3d8f08);})['then'](function(_0x3746b0){_0x423c2a=_0x3746b0;return getCall(_0x34d0e9,_0x26832f,_0x5418b0,_0x5d68fc,_0x423c2a,_0x3d8f08,_0x1d6cc8,_0xf1f7('0x70'));})[_0xf1f7('0x26')](function(_0x11cc2b){if(_0x11cc2b){logger[_0xf1f7('0x2d')](_0xf1f7('0x85'),_0x11cc2b['id']);logger[_0xf1f7('0x2d')](_0xf1f7('0x79'),'Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xf1f7('0x5c')]('user:%s',_0x5693de[_0xf1f7('0x1a')]),_0xf1f7('0x86'),{'uri':_0xf1f7('0x87')+_0x5418b0[_0xf1f7('0x76')]+_0xf1f7('0x88')+_0x11cc2b['id']});}})['catch'](function(_0x3c6dcf){logger[_0xf1f7('0x2b')]('[QUEUE]',JSON[_0xf1f7('0xd')](_0x3c6dcf));});};exports['outbound']=function(_0x2ec445,_0x44a5d1,_0x386366,_0x2c8887,_0x3d14e2,_0x1aba71,_0x5cadaa){var _0x36e426,_0x5ec965,_0xa422be;_0x1aba71['host']=intUtil['stripTrailingSlash'](_0x1aba71['host']);_0x1aba71[_0xf1f7('0x77')]=intUtil['stripTrailingSlash'](_0x1aba71[_0xf1f7('0x77')]);if(_0x5cadaa&&_0x5cadaa[_0xf1f7('0x89')]&&_0x5cadaa[_0xf1f7('0x89')]!==_0xf1f7('0x8a')){logger[_0xf1f7('0x2d')](_0xf1f7('0x8b'),_0xf1f7('0x7a'));_0x44a5d1[_0xf1f7('0x7b')]=_0x1aba71[_0xf1f7('0x77')]+_0xf1f7('0x7c')+_0x44a5d1[_0xf1f7('0x7d')]+_0xf1f7('0x7e')+md5(_0x44a5d1[_0xf1f7('0x7d')]);}var _0x1edc78=_0x1aba71[_0xf1f7('0x76')]==='zoho.eu'?'eu':_0xf1f7('0x80');return getAccessToken(_0x1aba71)['then'](function(_0x4bf867){_0xa422be=_0x4bf867;return getUser(_0xa422be,_0x1edc78,_0x1aba71,_0x2c8887['email']);})[_0xf1f7('0x26')](function(_0x5aa1fd){_0x36e426=_0x5aa1fd;logger[_0xf1f7('0x2d')](_0xf1f7('0x82'),_0x36e426['id']);return getEndUser(_0xa422be,_0x1edc78,_0x1aba71,_0x44a5d1[_0xf1f7('0x8c')],_0x44a5d1[_0xf1f7('0x8d')],_0x36e426,_0x386366);})[_0xf1f7('0x26')](function(_0xbc9744){_0x5ec965=_0xbc9744;return getCall(_0xa422be,_0x1edc78,_0x1aba71,_0x36e426,_0x5ec965,_0x386366,_0x44a5d1,'Outbound');})[_0xf1f7('0x26')](function(_0x55aa20){if(_0x55aa20){logger['info'](_0xf1f7('0x85'),_0x55aa20['id']);logger[_0xf1f7('0x2d')](_0xf1f7('0x8b'),_0xf1f7('0x8e'));emit(util['format'](_0xf1f7('0x8f'),_0x2c8887[_0xf1f7('0x1a')]),'trigger:browser:url',{'uri':_0xf1f7('0x87')+_0x1aba71['host']+'/crm/EntityInfo.do?module=Calls&id='+_0x55aa20['id']});}})['catch'](function(_0x3e64df){logger[_0xf1f7('0x2b')](_0xf1f7('0x8b'),JSON[_0xf1f7('0xd')](_0x3e64df));});};exports[_0xf1f7('0x90')]=function(_0x3120e0,_0x338253,_0x426f37,_0xa6d200,_0x11f01a,_0x2b532d){var _0x4ab0ba,_0x5b0759,_0x496c14;_0x2b532d[_0xf1f7('0x76')]=intUtil[_0xf1f7('0x75')](_0x2b532d[_0xf1f7('0x76')]);_0x2b532d['serverUrl']=intUtil[_0xf1f7('0x75')](_0x2b532d[_0xf1f7('0x77')]);if(_0x11f01a&&_0x11f01a[_0xf1f7('0x78')]){logger[_0xf1f7('0x2d')]('['+_0x338253[_0xf1f7('0x63')][_0xf1f7('0x91')]()+']',_0xf1f7('0x7a'));_0x338253['recordingURL']=_0x2b532d[_0xf1f7('0x77')]+_0xf1f7('0x7c')+_0x338253[_0xf1f7('0x7d')]+_0xf1f7('0x7e')+md5(_0x338253['uniqueid']);}else{_0x338253[_0xf1f7('0x7b')]='';}var _0x4eeb43=_0x2b532d[_0xf1f7('0x76')]===_0xf1f7('0x7f')?'eu':_0xf1f7('0x80');return getAccessToken(_0x2b532d)[_0xf1f7('0x26')](function(_0x2a8988){_0x496c14=_0x2a8988;return getUser(_0x496c14,_0x4eeb43,_0x2b532d);})[_0xf1f7('0x26')](function(_0x14d31d){_0x4ab0ba=_0x14d31d;logger['info'](_0xf1f7('0x82'),_0x4ab0ba['id']);return getEndUser(_0x496c14,_0x4eeb43,_0x2b532d,_0x338253[_0xf1f7('0x83')],_0x338253[_0xf1f7('0x84')],_0x4ab0ba,_0x426f37);})[_0xf1f7('0x26')](function(_0x48e3aa){_0x5b0759=_0x48e3aa;return getCall(_0x496c14,_0x4eeb43,_0x2b532d,_0x4ab0ba,_0x5b0759,_0x426f37,_0x338253,'Inbound');})[_0xf1f7('0x26')](function(_0x4582b9){if(_0x4582b9){logger[_0xf1f7('0x2d')](_0xf1f7('0x85'),_0x4582b9['id']);}})[_0xf1f7('0x2a')](function(_0x3fa8e3){logger[_0xf1f7('0x2b')]('['+_0x338253[_0xf1f7('0x63')]['toUpperCase']()+']',JSON['stringify'](_0x3fa8e3));});};
\ No newline at end of file