b0a6b51d4fd2492743fb463d46f574e1a41a5a17
[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 _0x5dd2=['toLowerCase','indexOf','isNil','access_token','isBefore','expires_in','zone','https://accounts.zoho.eu','https://accounts.zoho.in','POST','/oauth/v2/token','refreshToken','clientSecret','refresh_token','add','seconds','catch','error','stack','info','Search\x20user','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','then','users','isArrayLikeObject','email','Agent\x20found!','Using\x20the\x20admin\x20account!','findIndex','profile','Administrator','user','The\x20failing\x20result\x20is','stringify','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','https://www.zohoapis.','role','first_name','last_name','code','SUCCESS','details','startCase','Error:\x20','log','moduleSearch','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','uri','/crm/v2/Leads/search?criteria=((Phone:equals:','Leads','moduleCreate','nothing','contact','lead','Creating\x20new\x20call...','Owner','administrator','Subject','getString','Description','Descriptions','Who_Id','Full_Name','First_Name','What_Id','Last_Name','$se_module','Call_Duration','utc','talktime','mm:ss','answertime','endtime','YYYY-MM-DDTHH:mm:ss','diff','lastevent','Called','complete','connect','Answered','rejected','Rejected','Abandoned','Call_Result','Timeout','starttime','agentcalledAt','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','recordingURL','/api/voice/recordings/','uniqueid','zoho.eu','com','The\x20User\x20ID\x20is:','calleridname','user:%s','trigger:browser:url','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','destcalleridname','The\x20Call\x20ID\x20is:','[OUTBOUND]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','https://crm.','toUpperCase','Recording\x20is\x20enabled!','/downloads?type=uniqueid&token=','calleridnum','lodash','md5','./util','moment','ioredis','bluebird','../../../../config/environment','zoho','defaults','redis','localhost','socket.io-emitter','debug','length','includes','picklist','idField','content','toString','type','variable','customVariable','Variable','name'];(function(_0x2b8862,_0x22c1c0){var _0x41983d=function(_0x1e1deb){while(--_0x1e1deb){_0x2b8862['push'](_0x2b8862['shift']());}};_0x41983d(++_0x22c1c0);}(_0x5dd2,0x1a7));var _0x25dd=function(_0xaa1b3e,_0x47d976){_0xaa1b3e=_0xaa1b3e-0x0;var _0x454d7d=_0x5dd2[_0xaa1b3e];return _0x454d7d;};'use strict';var _=require(_0x25dd('0x0'));var rp=require('request-promise');var md5=require(_0x25dd('0x1'));var util=require('util');var intUtil=require(_0x25dd('0x2'));var moment=require(_0x25dd('0x3'));var Redis=require(_0x25dd('0x4'));var BPromise=require(_0x25dd('0x5'));var config=require(_0x25dd('0x6'));var logger=require('../../../../config/logger')(_0x25dd('0x7'));config['redis']=_[_0x25dd('0x8')](config[_0x25dd('0x9')],{'host':_0x25dd('0xa'),'port':0x18eb});var io=require(_0x25dd('0xb'))(new Redis(config[_0x25dd('0x9')]));function emit(_0x362dd0,_0x1fc3aa,_0x2ca243){io['to'](_0x362dd0)['emit'](_0x1fc3aa,_0x2ca243);}function request(_0x805229){logger[_0x25dd('0xc')]('[HTTP]',JSON['stringify'](_0x805229));return rp(_0x805229);}function getCustomFields(_0x3a58c2,_0x274864){var _0x156714={};if(_0x3a58c2[_0x25dd('0xd')]>0x0){_['forEach'](_0x3a58c2,function(_0x5d5d90){if(_[_0x25dd('0xe')](['string',_0x25dd('0xf')],_0x5d5d90['type'])&&_0x5d5d90[_0x25dd('0x10')]){_0x156714[_0x5d5d90[_0x25dd('0x10')]]=_0x5d5d90[_0x25dd('0x11')][_0x25dd('0x12')]();}else if(_0x5d5d90[_0x25dd('0x13')]===_0x25dd('0x14')&&_0x5d5d90['variableName']&&_0x5d5d90[_0x25dd('0x10')]&&_0x274864[_0x5d5d90['variableName']]){_0x156714[_0x5d5d90[_0x25dd('0x10')]]=_0x274864[_0x5d5d90['variableName']]['toString']();}else if(_0x5d5d90[_0x25dd('0x13')]===_0x25dd('0x15')&&_0x5d5d90['Variable']&&_0x5d5d90[_0x25dd('0x16')][_0x25dd('0x17')]&&_0x5d5d90[_0x25dd('0x10')]&&_0x274864[_0x5d5d90[_0x25dd('0x16')]['name'][_0x25dd('0x18')]()]){_0x156714[_0x5d5d90[_0x25dd('0x10')]]=_0x274864[_0x5d5d90[_0x25dd('0x16')]['name'][_0x25dd('0x18')]()][_0x25dd('0x12')]();}});}return _0x156714;}function getName(_0xcf40a3){if(_0xcf40a3[_0x25dd('0x19')]('\x20')>0x0){var _0x27bf58=_0xcf40a3['split'](/ (.+)/);if(_0x27bf58[0x1]){return _0x27bf58;}}return[_0xcf40a3,_0xcf40a3];}var accountsTokens={};function getAccessToken(_0xf51101){return new Promise(function(_0x562f5d,_0xd9ff90){if(!_[_0x25dd('0x1a')](accountsTokens[_0xf51101['id']])&&!_['isNil'](accountsTokens[_0xf51101['id']][_0x25dd('0x1b')])){if(moment()[_0x25dd('0x1c')](accountsTokens[_0xf51101['id']][_0x25dd('0x1d')])){_0x562f5d(accountsTokens[_0xf51101['id']][_0x25dd('0x1b')]);}}var _0x5a972f;switch(_0xf51101[_0x25dd('0x1e')]){case'US':_0x5a972f='https://accounts.zoho.com';break;case'AU':_0x5a972f='https://accounts.zoho.com.au';break;case'EU':_0x5a972f=_0x25dd('0x1f');break;case'IN':_0x5a972f=_0x25dd('0x20');break;case'CN':_0x5a972f='https://accounts.zoho.com.cn';break;default:_0x5a972f=_0x25dd('0x1f');break;}var _0x2486bc={'method':_0x25dd('0x21'),'uri':_0x5a972f+_0x25dd('0x22'),'qs':{'refresh_token':_0xf51101[_0x25dd('0x23')],'client_id':_0xf51101['clientId'],'client_secret':_0xf51101[_0x25dd('0x24')],'grant_type':_0x25dd('0x25')},'json':!![]};return rp(_0x2486bc)['then'](function(_0x395f59){accountsTokens[_0xf51101['id']]={'access_token':_0x395f59[_0x25dd('0x1b')],'expires_in':moment()[_0x25dd('0x26')](_0x395f59[_0x25dd('0x1d')],_0x25dd('0x27'))};_0x562f5d(_0x395f59[_0x25dd('0x1b')]);})[_0x25dd('0x28')](function(_0x5de3e4){logger[_0x25dd('0x29')]('Failing\x20creating\x20the\x20access_token',_0x5de3e4[_0x25dd('0x2a')]);_0xd9ff90(_0x5de3e4);});});}function getUser(_0x394877,_0x262a79,_0x1a8532,_0x26ae27){logger[_0x25dd('0x2b')](_0x25dd('0x2c'));return request({'method':'GET','uri':util[_0x25dd('0x2d')](_0x25dd('0x2e'),_0x262a79),'qs':{'type':_0x25dd('0x2f')},'headers':{'Authorization':_0x25dd('0x30')+_0x394877},'json':!![]})[_0x25dd('0x31')](function(_0x113841){if(_0x113841[_0x25dd('0x32')]){var _0x449636=-0x1;if(_[_0x25dd('0x33')](_0x113841[_0x25dd('0x32')])){if(!_['isNil'](_0x26ae27)){_0x449636=_['findIndex'](_0x113841['users'],function(_0x1c797c){return _0x1c797c[_0x25dd('0x34')]===_0x26ae27;});}if(_0x449636>=0x0){logger[_0x25dd('0x2b')](_0x25dd('0x35'));}else{logger[_0x25dd('0x2b')](_0x25dd('0x36'));_0x449636=_[_0x25dd('0x37')](_0x113841[_0x25dd('0x32')],function(_0x57f7f7){return _0x57f7f7[_0x25dd('0x38')]['name']===_0x25dd('0x39');});}return _0x113841['users'][_0x449636];}else{if(_0x113841[_0x25dd('0x3a')][_0x25dd('0x38')][_0x25dd('0x17')]===_0x25dd('0x39')){logger['info'](_0x25dd('0x36'));user=_0x113841[_0x25dd('0x3a')];return user;}else{logger[_0x25dd('0x29')](_0x25dd('0x3b'),JSON[_0x25dd('0x3c')](_0x113841));throw new Error(_0x25dd('0x3d')+JSON[_0x25dd('0x3c')](_0x113841));}}}else{logger[_0x25dd('0x29')](_0x25dd('0x3b'),JSON[_0x25dd('0x3c')](_0x113841));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON['stringify'](_0x113841));}})[_0x25dd('0x28')](function(_0x1eb950){console[_0x25dd('0x29')](_0x1eb950);});}function getZohoUser(_0x322468,_0x2c39fc){return new BPromise(function(_0x41a362,_0x5180d5){request(_0x322468)[_0x25dd('0x31')](function(_0x27f06e){var _0x5371a0=null;if(_0x27f06e){_0x5371a0=_0x27f06e[_0x25dd('0x3e')][0x0];_0x5371a0[_0x25dd('0x3f')]=_0x2c39fc;}_0x41a362(_0x5371a0);})['catch'](function(_0x125258){_0x5180d5(_0x125258);});});}function createEndUser(_0x141516,_0x559907,_0x1afc85,_0x412086,_0x85fa86,_0x592aa9){var _0x1afc85=getName(_0x1afc85);return request({'method':_0x25dd('0x21'),'uri':_0x25dd('0x40')+_0x559907+'/crm/v2/'+_['startCase'](_0x592aa9['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x1afc85[0x1],'First_Name':_0x1afc85[0x0],'Phone':_0x412086,'Owner':{'name':!_[_0x25dd('0x1a')](_0x85fa86[_0x25dd('0x41')][_0x25dd('0x17')])?_0x85fa86[_0x25dd('0x41')]['name']:!_['isNil'](_0x85fa86[_0x25dd('0x42')])?_0x85fa86['first_name']+'\x20'+_0x85fa86[_0x25dd('0x43')]:_0x85fa86[_0x25dd('0x43')],'id':_0x85fa86['id']}}]},'headers':{'Authorization':_0x25dd('0x30')+_0x141516},'json':!![]})['then'](function(_0x5f376f){if(_0x5f376f&&_0x5f376f[_0x25dd('0x3e')][0x0][_0x25dd('0x44')]===_0x25dd('0x45')){var _0x33b901=_0x5f376f[_0x25dd('0x3e')][0x0][_0x25dd('0x46')];_0x33b901['enduserType']=_[_0x25dd('0x47')](_0x592aa9['moduleCreate'])+'s';return _0x33b901;}logger['error'](_0x25dd('0x3b'),JSON[_0x25dd('0x3c')](data));throw new Error(_0x25dd('0x48')+JSON[_0x25dd('0x3c')](data));})['catch'](function(_0x500fe7){console[_0x25dd('0x49')]('CREATE\x20ERROR',_0x500fe7);});}function getEndUser(_0xc2f5c3,_0x5c9464,_0x57efbd,_0x590ace,_0x53574f,_0x11b667,_0x5625e7){var _0x5f442a={'method':'GET','uri':'','headers':{'Authorization':_0x25dd('0x30')+_0xc2f5c3},'json':!![]};switch(_0x5625e7[_0x25dd('0x4a')]){case'contact_lead':_0x5f442a['uri']='https://www.zohoapis.'+_0x5c9464+_0x25dd('0x4b')+_0x53574f+'))';return getZohoUser(_0x5f442a,_0x25dd('0x4c'))[_0x25dd('0x31')](function(_0x2ad2eb){if(_0x2ad2eb)return _0x2ad2eb;_0x5f442a[_0x25dd('0x4d')]=_0x25dd('0x40')+_0x5c9464+_0x25dd('0x4e')+_0x53574f+'))';return getZohoUser(_0x5f442a,_0x25dd('0x4f'))['then'](function(_0x34113f){if(_0x34113f)return _0x34113f;if(_0x5625e7[_0x25dd('0x50')]!=_0x25dd('0x51')){return createEndUser(_0xc2f5c3,_0x5c9464,_0x590ace,_0x53574f,_0x11b667,_0x5625e7);}else{return{};}});});break;case _0x25dd('0x52'):_0x5f442a[_0x25dd('0x4d')]=_0x25dd('0x40')+_0x5c9464+_0x25dd('0x4b')+_0x53574f+'))';return getZohoUser(_0x5f442a,_0x25dd('0x4c'))[_0x25dd('0x31')](function(_0xd29c81){if(_0xd29c81)return _0xd29c81;if(_0x5625e7[_0x25dd('0x50')]!=_0x25dd('0x51')){return createEndUser(_0xc2f5c3,_0x5c9464,_0x590ace,_0x53574f,_0x11b667,_0x5625e7);}else{return{};}});break;case _0x25dd('0x53'):_0x5f442a[_0x25dd('0x4d')]=_0x25dd('0x40')+_0x5c9464+_0x25dd('0x4e')+_0x53574f+'))';return getZohoUser(_0x5f442a,_0x25dd('0x4f'))['then'](function(_0x2dfe5a){if(_0x2dfe5a)return _0x2dfe5a;if(_0x5625e7[_0x25dd('0x50')]!=_0x25dd('0x51')){return createEndUser(_0xc2f5c3,_0x5c9464,_0x590ace,_0x53574f,_0x11b667,_0x5625e7);}else{return{};}});break;}}function getCall(_0x45e054,_0x188f39,_0x17e9fa,_0x3c6c90,_0x46d9b2,_0x1b2b0f,_0x4f4698,_0x311c0c){logger[_0x25dd('0x2b')](_0x25dd('0x54'));var _0x5163fa={};_0x5163fa[_0x25dd('0x55')]={'name':!_['isNil'](_0x3c6c90[_0x25dd('0x41')][_0x25dd('0x17')])&&!_[_0x25dd('0x1a')](_0x3c6c90[_0x25dd('0x38')][_0x25dd('0x17')])&&_0x3c6c90['profile'][_0x25dd('0x17')]===_0x25dd('0x56')?_0x3c6c90[_0x25dd('0x41')][_0x25dd('0x17')]:!_[_0x25dd('0x1a')](_0x3c6c90[_0x25dd('0x42')])?_0x3c6c90['first_name']+'\x20'+_0x3c6c90[_0x25dd('0x43')]:_0x3c6c90[_0x25dd('0x43')],'id':_0x3c6c90['id']};_0x5163fa[_0x25dd('0x57')]=intUtil[_0x25dd('0x58')](_0x1b2b0f['Subjects'],_0x4f4698,'\x20');_0x5163fa[_0x25dd('0x59')]=intUtil[_0x25dd('0x58')](_0x1b2b0f[_0x25dd('0x5a')],_0x4f4698,'\x0a');if(_0x46d9b2[_0x25dd('0x3f')]===_0x25dd('0x4c')){_0x5163fa[_0x25dd('0x5b')]={'name':!_[_0x25dd('0x1a')](_0x46d9b2[_0x25dd('0x5c')])?_0x46d9b2[_0x25dd('0x5c')]:!_[_0x25dd('0x1a')](_0x46d9b2['First_Name'])?_0x46d9b2[_0x25dd('0x5d')]+'\x20'+_0x46d9b2['Last_Name']:_0x46d9b2['Last_Name'],'id':_0x46d9b2['id']};}if(_0x46d9b2['enduserType']==='Leads'){_0x5163fa[_0x25dd('0x5e')]={'name':!_['isNil'](_0x46d9b2[_0x25dd('0x5c')])?_0x46d9b2[_0x25dd('0x5c')]:!_[_0x25dd('0x1a')](_0x46d9b2['First_Name'])?_0x46d9b2[_0x25dd('0x5d')]+'\x20'+_0x46d9b2[_0x25dd('0x5f')]:_0x46d9b2['Last_Name'],'id':_0x46d9b2['id']};_0x5163fa[_0x25dd('0x60')]=_[_0x25dd('0x47')](_0x46d9b2['enduserType']);}if(_0x4f4698['talktime']){_0x5163fa[_0x25dd('0x61')]=moment[_0x25dd('0x62')](parseInt(_0x4f4698[_0x25dd('0x63')])*0x3e8)['format'](_0x25dd('0x64'));}else if(_0x4f4698[_0x25dd('0x65')]&&_0x4f4698[_0x25dd('0x66')]){_0x5163fa[_0x25dd('0x61')]=moment['utc'](moment(_0x4f4698[_0x25dd('0x66')],_0x25dd('0x67'))[_0x25dd('0x68')](moment(_0x4f4698['starttime'],_0x25dd('0x67'))))[_0x25dd('0x2d')](_0x25dd('0x64'));}switch(_0x4f4698[_0x25dd('0x69')]){case'called':_0x5163fa['Call_Result']=_0x25dd('0x6a');break;case _0x25dd('0x6b'):case _0x25dd('0x6c'):_0x5163fa['Call_Result']=_0x25dd('0x6d');break;case _0x25dd('0x6e'):_0x5163fa['Call_Result']=_0x25dd('0x6f');break;case'abandoned':_0x5163fa['Call_Result']=_0x25dd('0x70');break;case'timeout':_0x5163fa[_0x25dd('0x71')]=_0x25dd('0x72');default:}_0x5163fa['Call_Start_Time']=(_0x311c0c==='outbound'?moment(_0x4f4698[_0x25dd('0x73')])[_0x25dd('0x2d')](_0x25dd('0x67')):moment(_0x4f4698[_0x25dd('0x74')])[_0x25dd('0x2d')](_0x25dd('0x67')))||moment()[_0x25dd('0x2d')](_0x25dd('0x67'));_0x5163fa[_0x25dd('0x75')]=_0x311c0c||_0x25dd('0x76');_0x5163fa=_[_0x25dd('0x77')](_0x5163fa,getCustomFields(_0x1b2b0f[_0x25dd('0x78')],_0x4f4698));return request({'method':_0x25dd('0x21'),'uri':_0x25dd('0x40')+_0x188f39+_0x25dd('0x79'),'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x45e054},'body':{'data':[_0x5163fa]},'json':!![]})[_0x25dd('0x31')](function(_0x1ea8b2){if(_0x1ea8b2&&_0x1ea8b2[_0x25dd('0x3e')][0x0][_0x25dd('0x44')]==='SUCCESS'){logger[_0x25dd('0x2b')]('Call\x20created!');return{'id':_0x1ea8b2[_0x25dd('0x3e')][0x0][_0x25dd('0x46')]['id']};}})['catch'](function(_0xa02a86){logger[_0x25dd('0x2b')]('err',_0xa02a86[_0x25dd('0x2a')]);console[_0x25dd('0x49')]('err',_0xa02a86);});}exports[_0x25dd('0x7a')]=function(_0x4847d7,_0xe41e2d,_0x296e47,_0x4cdf83,_0x5111a5,_0x41db3e){var _0x196eaa,_0x46d156,_0xa39796;_0x41db3e[_0x25dd('0x7b')]=intUtil[_0x25dd('0x7c')](_0x41db3e[_0x25dd('0x7b')]);_0x41db3e[_0x25dd('0x7d')]=intUtil['stripTrailingSlash'](_0x41db3e['serverUrl']);if(_0x5111a5&&_0x5111a5[_0x25dd('0x7e')]){logger[_0x25dd('0x2b')](_0x25dd('0x7f'),'Recording\x20is\x20enabled!');_0xe41e2d[_0x25dd('0x80')]=_0x41db3e['serverUrl']+_0x25dd('0x81')+_0xe41e2d[_0x25dd('0x82')]+'/downloads?type=uniqueid&token='+md5(_0xe41e2d[_0x25dd('0x82')]);}else{_0xe41e2d[_0x25dd('0x80')]='';}var _0x6b586e=_0x41db3e[_0x25dd('0x7b')]===_0x25dd('0x83')?'eu':_0x25dd('0x84');return getAccessToken(_0x41db3e)[_0x25dd('0x31')](function(_0x49984d){_0xa39796=_0x49984d;return getUser(_0xa39796,_0x6b586e,_0x41db3e,_0x4cdf83['email']);})[_0x25dd('0x31')](function(_0x14c634){_0x196eaa=_0x14c634;logger['info'](_0x25dd('0x85'),_0x196eaa['id']);return getEndUser(_0xa39796,_0x6b586e,_0x41db3e,_0xe41e2d[_0x25dd('0x86')],_0xe41e2d['calleridnum'],_0x196eaa,_0x296e47);})['then'](function(_0x16723a){_0x46d156=_0x16723a;return getCall(_0xa39796,_0x6b586e,_0x41db3e,_0x196eaa,_0x46d156,_0x296e47,_0xe41e2d,_0x25dd('0x76'));})[_0x25dd('0x31')](function(_0x41ba84){if(_0x41ba84){logger[_0x25dd('0x2b')]('The\x20Call\x20ID\x20is:',_0x41ba84['id']);logger[_0x25dd('0x2b')]('[QUEUE]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x25dd('0x2d')](_0x25dd('0x87'),_0x4cdf83[_0x25dd('0x17')]),_0x25dd('0x88'),{'uri':'https://crm.'+_0x41db3e[_0x25dd('0x7b')]+_0x25dd('0x89')+_0x41ba84['id']});}})['catch'](function(_0x5a82b6){logger['error'](_0x25dd('0x7f'),JSON['stringify'](_0x5a82b6));});};exports['outbound']=function(_0x2b5a20,_0x14b165,_0x3f94fe,_0xced6e3,_0x4a06fa,_0x7a3b22,_0x42f8b1){var _0x3be927,_0x428cea,_0xbf98ad;_0x7a3b22[_0x25dd('0x7b')]=intUtil[_0x25dd('0x7c')](_0x7a3b22['host']);_0x7a3b22['serverUrl']=intUtil['stripTrailingSlash'](_0x7a3b22['serverUrl']);if(_0x42f8b1&&_0x42f8b1[_0x25dd('0x8a')]&&_0x42f8b1[_0x25dd('0x8a')]!==_0x25dd('0x8b')){logger[_0x25dd('0x2b')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x14b165[_0x25dd('0x80')]=_0x7a3b22['serverUrl']+'/api/voice/recordings/'+_0x14b165[_0x25dd('0x82')]+'/downloads?type=uniqueid&token='+md5(_0x14b165['uniqueid']);}var _0x53aa48=_0x7a3b22['host']===_0x25dd('0x83')?'eu':_0x25dd('0x84');return getAccessToken(_0x7a3b22)[_0x25dd('0x31')](function(_0x4c1b97){_0xbf98ad=_0x4c1b97;return getUser(_0xbf98ad,_0x53aa48,_0x7a3b22,_0xced6e3[_0x25dd('0x34')]);})[_0x25dd('0x31')](function(_0x4b2a6a){_0x3be927=_0x4b2a6a;logger['info'](_0x25dd('0x85'),_0x3be927['id']);return getEndUser(_0xbf98ad,_0x53aa48,_0x7a3b22,_0x14b165[_0x25dd('0x8c')],_0x14b165['destcalleridnum'],_0x3be927,_0x3f94fe);})[_0x25dd('0x31')](function(_0x2925cf){_0x428cea=_0x2925cf;return getCall(_0xbf98ad,_0x53aa48,_0x7a3b22,_0x3be927,_0x428cea,_0x3f94fe,_0x14b165,'Outbound');})['then'](function(_0x2a7b02){if(_0x2a7b02){logger[_0x25dd('0x2b')](_0x25dd('0x8d'),_0x2a7b02['id']);logger[_0x25dd('0x2b')](_0x25dd('0x8e'),_0x25dd('0x8f'));emit(util[_0x25dd('0x2d')](_0x25dd('0x87'),_0xced6e3[_0x25dd('0x17')]),_0x25dd('0x88'),{'uri':_0x25dd('0x90')+_0x7a3b22[_0x25dd('0x7b')]+'/crm/EntityInfo.do?module=Calls&id='+_0x2a7b02['id']});}})[_0x25dd('0x28')](function(_0x46aa94){logger[_0x25dd('0x29')]('[OUTBOUND]',JSON[_0x25dd('0x3c')](_0x46aa94));});};exports['unmanaged']=function(_0x1c800a,_0xe70b43,_0x48da4e,_0x14036c,_0x16ee75,_0x858873){var _0x22e791,_0x3cdf26,_0x2822fe;_0x858873[_0x25dd('0x7b')]=intUtil[_0x25dd('0x7c')](_0x858873[_0x25dd('0x7b')]);_0x858873[_0x25dd('0x7d')]=intUtil[_0x25dd('0x7c')](_0x858873['serverUrl']);if(_0x16ee75&&_0x16ee75[_0x25dd('0x7e')]){logger['info']('['+_0xe70b43[_0x25dd('0x69')][_0x25dd('0x91')]()+']',_0x25dd('0x92'));_0xe70b43[_0x25dd('0x80')]=_0x858873['serverUrl']+_0x25dd('0x81')+_0xe70b43[_0x25dd('0x82')]+_0x25dd('0x93')+md5(_0xe70b43[_0x25dd('0x82')]);}else{_0xe70b43[_0x25dd('0x80')]='';}var _0x354ec9=_0x858873[_0x25dd('0x7b')]==='zoho.eu'?'eu':_0x25dd('0x84');return getAccessToken(_0x858873)[_0x25dd('0x31')](function(_0x282420){_0x2822fe=_0x282420;return getUser(_0x2822fe,_0x354ec9,_0x858873);})[_0x25dd('0x31')](function(_0x5a95c1){_0x22e791=_0x5a95c1;logger[_0x25dd('0x2b')]('The\x20User\x20ID\x20is:',_0x22e791['id']);return getEndUser(_0x2822fe,_0x354ec9,_0x858873,_0xe70b43[_0x25dd('0x86')],_0xe70b43[_0x25dd('0x94')],_0x22e791,_0x48da4e);})[_0x25dd('0x31')](function(_0x4b1386){_0x3cdf26=_0x4b1386;return getCall(_0x2822fe,_0x354ec9,_0x858873,_0x22e791,_0x3cdf26,_0x48da4e,_0xe70b43,_0x25dd('0x76'));})[_0x25dd('0x31')](function(_0x47ba0e){if(_0x47ba0e){logger['info']('The\x20Call\x20ID\x20is:',_0x47ba0e['id']);}})['catch'](function(_0x59f4ca){logger[_0x25dd('0x29')]('['+_0xe70b43[_0x25dd('0x69')][_0x25dd('0x91')]()+']',JSON[_0x25dd('0x3c')](_0x59f4ca));});};