Built motion from commit 56b8093a.|2.6.29
[motion2.git] / server / services / ami / trigger / integration / zoho.js
index fc3ea6e..aacd8ff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb81d=['uniqueid','/downloads?type=uniqueid&token=','zoho.eu','com','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','[QUEUE]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','recordingURL','destcalleridname','Outbound','The\x20Call\x20ID\x20is:','[OUTBOUND]','unmanaged','toUpperCase','md5','util','./util','ioredis','bluebird','../../../../config/environment','../../../../config/logger','zoho','redis','defaults','localhost','socket.io-emitter','emit','[HTTP]','stringify','length','forEach','string','picklist','idField','content','toString','type','variable','variableName','customVariable','Variable','name','toLowerCase','split','isNil','expires_in','access_token','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.in','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','/oauth/v2/token','clientId','clientSecret','refresh_token','then','add','catch','error','Failing\x20creating\x20the\x20access_token','stack','Search\x20user','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','users','info','Agent\x20found!','Using\x20the\x20admin\x20account!','user','profile','Administrator','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','/crm/v2/','role','first_name','last_name','code','details','startCase','moduleCreate','Error:\x20','log','CREATE\x20ERROR','moduleSearch','/crm/v2/Contacts/search?criteria=((Phone:equals:','uri','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','https://www.zohoapis.','Contacts','lead','Creating\x20new\x20call...','Owner','administrator','Subject','getString','Subjects','Description','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','$se_module','talktime','Call_Duration','utc','mm:ss','answertime','endtime','YYYY-MM-DDTHH:mm:ss','starttime','lastevent','called','Call_Result','Called','complete','connect','Answered','rejected','abandoned','timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','Inbound','merge','Fields','/crm/v2/Calls','Call\x20created!','err','queue','host','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','/api/voice/recordings/'];(function(_0x18829e,_0x41e22c){var _0x229790=function(_0x5d7771){while(--_0x5d7771){_0x18829e['push'](_0x18829e['shift']());}};_0x229790(++_0x41e22c);}(_0xb81d,0xb4));var _0xdb81=function(_0x492012,_0x32ae87){_0x492012=_0x492012-0x0;var _0x2a75b6=_0xb81d[_0x492012];return _0x2a75b6;};'use strict';var _=require('lodash');var rp=require('request-promise');var md5=require(_0xdb81('0x0'));var util=require(_0xdb81('0x1'));var intUtil=require(_0xdb81('0x2'));var moment=require('moment');var Redis=require(_0xdb81('0x3'));var BPromise=require(_0xdb81('0x4'));var config=require(_0xdb81('0x5'));var logger=require(_0xdb81('0x6'))(_0xdb81('0x7'));config[_0xdb81('0x8')]=_[_0xdb81('0x9')](config['redis'],{'host':_0xdb81('0xa'),'port':0x18eb});var io=require(_0xdb81('0xb'))(new Redis(config[_0xdb81('0x8')]));function emit(_0x24c045,_0x700360,_0x18c4f0){io['to'](_0x24c045)[_0xdb81('0xc')](_0x700360,_0x18c4f0);}function request(_0x1db3a1){logger['debug'](_0xdb81('0xd'),JSON[_0xdb81('0xe')](_0x1db3a1));return rp(_0x1db3a1);}function getCustomFields(_0x8fe01b,_0xafa4b3){var _0x5cf70d={};if(_0x8fe01b[_0xdb81('0xf')]>0x0){_[_0xdb81('0x10')](_0x8fe01b,function(_0x559076){if(_['includes']([_0xdb81('0x11'),_0xdb81('0x12')],_0x559076['type'])&&_0x559076[_0xdb81('0x13')]){_0x5cf70d[_0x559076[_0xdb81('0x13')]]=_0x559076[_0xdb81('0x14')][_0xdb81('0x15')]();}else if(_0x559076[_0xdb81('0x16')]===_0xdb81('0x17')&&_0x559076[_0xdb81('0x18')]&&_0x559076[_0xdb81('0x13')]&&_0xafa4b3[_0x559076[_0xdb81('0x18')]]){_0x5cf70d[_0x559076[_0xdb81('0x13')]]=_0xafa4b3[_0x559076[_0xdb81('0x18')]][_0xdb81('0x15')]();}else if(_0x559076[_0xdb81('0x16')]===_0xdb81('0x19')&&_0x559076[_0xdb81('0x1a')]&&_0x559076[_0xdb81('0x1a')][_0xdb81('0x1b')]&&_0x559076['idField']&&_0xafa4b3[_0x559076['Variable'][_0xdb81('0x1b')][_0xdb81('0x1c')]()]){_0x5cf70d[_0x559076[_0xdb81('0x13')]]=_0xafa4b3[_0x559076['Variable']['name'][_0xdb81('0x1c')]()][_0xdb81('0x15')]();}});}return _0x5cf70d;}function getName(_0x1ba4c2){if(_0x1ba4c2['indexOf']('\x20')>0x0){var _0x2cd492=_0x1ba4c2[_0xdb81('0x1d')](/ (.+)/);if(_0x2cd492[0x1]){return _0x2cd492;}}return[_0x1ba4c2,_0x1ba4c2];}var accountsTokens={};function getAccessToken(_0x6db7f3){return new Promise(function(_0x2be4c8,_0x12a0f7){if(!_[_0xdb81('0x1e')](accountsTokens[_0x6db7f3['id']])&&!_[_0xdb81('0x1e')](accountsTokens[_0x6db7f3['id']]['access_token'])){if(moment()['isBefore'](accountsTokens[_0x6db7f3['id']][_0xdb81('0x1f')])){_0x2be4c8(accountsTokens[_0x6db7f3['id']][_0xdb81('0x20')]);}}var _0x370739;switch(_0x6db7f3[_0xdb81('0x21')]){case'US':_0x370739=_0xdb81('0x22');break;case'AU':_0x370739=_0xdb81('0x23');break;case'EU':_0x370739='https://accounts.zoho.eu';break;case'IN':_0x370739=_0xdb81('0x24');break;case'CN':_0x370739=_0xdb81('0x25');break;default:_0x370739=_0xdb81('0x26');break;}var _0x1a97ba={'method':_0xdb81('0x27'),'uri':_0x370739+_0xdb81('0x28'),'qs':{'refresh_token':_0x6db7f3['refreshToken'],'client_id':_0x6db7f3[_0xdb81('0x29')],'client_secret':_0x6db7f3[_0xdb81('0x2a')],'grant_type':_0xdb81('0x2b')},'json':!![]};return rp(_0x1a97ba)[_0xdb81('0x2c')](function(_0x2568ef){accountsTokens[_0x6db7f3['id']]={'access_token':_0x2568ef[_0xdb81('0x20')],'expires_in':moment()[_0xdb81('0x2d')](_0x2568ef[_0xdb81('0x1f')],'seconds')};_0x2be4c8(_0x2568ef[_0xdb81('0x20')]);})[_0xdb81('0x2e')](function(_0x3ab95f){logger[_0xdb81('0x2f')](_0xdb81('0x30'),_0x3ab95f[_0xdb81('0x31')]);_0x12a0f7(_0x3ab95f);});});}function getUser(_0x4bdb21,_0x12b494,_0x3abf84,_0xaece3e){logger['info'](_0xdb81('0x32'));return request({'method':'GET','uri':util[_0xdb81('0x33')](_0xdb81('0x34'),_0x12b494),'qs':{'type':_0xdb81('0x35')},'headers':{'Authorization':_0xdb81('0x36')+_0x4bdb21},'json':!![]})['then'](function(_0x3de5b4){if(_0x3de5b4[_0xdb81('0x37')]){var _0x37b621=-0x1;if(_['isArrayLikeObject'](_0x3de5b4['users'])){if(!_[_0xdb81('0x1e')](_0xaece3e)){_0x37b621=_['findIndex'](_0x3de5b4['users'],function(_0x4a7f49){return _0x4a7f49['email']===_0xaece3e;});}if(_0x37b621>=0x0){logger[_0xdb81('0x38')](_0xdb81('0x39'));}else{logger[_0xdb81('0x38')](_0xdb81('0x3a'));_0x37b621=_['findIndex'](_0x3de5b4['users'],function(_0xa8d91e){return _0xa8d91e['profile'][_0xdb81('0x1b')]==='Administrator';});}return _0x3de5b4[_0xdb81('0x37')][_0x37b621];}else{if(_0x3de5b4[_0xdb81('0x3b')][_0xdb81('0x3c')][_0xdb81('0x1b')]===_0xdb81('0x3d')){logger[_0xdb81('0x38')]('Using\x20the\x20admin\x20account!');user=_0x3de5b4[_0xdb81('0x3b')];return user;}else{logger[_0xdb81('0x2f')](_0xdb81('0x3e'),JSON[_0xdb81('0xe')](_0x3de5b4));throw new Error(_0xdb81('0x3f')+JSON['stringify'](_0x3de5b4));}}}else{logger['error'](_0xdb81('0x3e'),JSON['stringify'](_0x3de5b4));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0xdb81('0xe')](_0x3de5b4));}})[_0xdb81('0x2e')](function(_0xc2e97d){console['error'](_0xc2e97d);});}function getZohoUser(_0x1b0c1d,_0x2c86d3){return new BPromise(function(_0xf7b59d,_0xe2a94){request(_0x1b0c1d)[_0xdb81('0x2c')](function(_0x219b85){var _0x26e73e=null;if(_0x219b85){_0x26e73e=_0x219b85[_0xdb81('0x40')][0x0];_0x26e73e[_0xdb81('0x41')]=_0x2c86d3;}_0xf7b59d(_0x26e73e);})[_0xdb81('0x2e')](function(_0x1a47d8){_0xe2a94(_0x1a47d8);});});}function createEndUser(_0x21ab45,_0x29b040,_0x52040b,_0x43fc17,_0x177538,_0x3e0e68){var _0x52040b=getName(_0x52040b);return request({'method':'POST','uri':'https://www.zohoapis.'+_0x29b040+_0xdb81('0x42')+_['startCase'](_0x3e0e68['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x52040b[0x1],'First_Name':_0x52040b[0x0],'Phone':_0x43fc17,'Owner':{'name':!_[_0xdb81('0x1e')](_0x177538[_0xdb81('0x43')][_0xdb81('0x1b')])?_0x177538[_0xdb81('0x43')][_0xdb81('0x1b')]:!_[_0xdb81('0x1e')](_0x177538[_0xdb81('0x44')])?_0x177538[_0xdb81('0x44')]+'\x20'+_0x177538[_0xdb81('0x45')]:_0x177538['last_name'],'id':_0x177538['id']}}]},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x21ab45},'json':!![]})['then'](function(_0x1b6505){if(_0x1b6505&&_0x1b6505[_0xdb81('0x40')][0x0][_0xdb81('0x46')]==='SUCCESS'){var _0x3ced2b=_0x1b6505[_0xdb81('0x40')][0x0][_0xdb81('0x47')];_0x3ced2b[_0xdb81('0x41')]=_[_0xdb81('0x48')](_0x3e0e68[_0xdb81('0x49')])+'s';return _0x3ced2b;}logger[_0xdb81('0x2f')](_0xdb81('0x3e'),JSON[_0xdb81('0xe')](data));throw new Error(_0xdb81('0x4a')+JSON[_0xdb81('0xe')](data));})[_0xdb81('0x2e')](function(_0x244ef2){console[_0xdb81('0x4b')](_0xdb81('0x4c'),_0x244ef2);});}function getEndUser(_0x1ba11b,_0x3ea2c8,_0x485f01,_0x2eb552,_0xd8d451,_0x32d8ee,_0x492988){var _0x1f902b={'method':'GET','uri':'','headers':{'Authorization':_0xdb81('0x36')+_0x1ba11b},'json':!![]};switch(_0x492988[_0xdb81('0x4d')]){case'contact_lead':_0x1f902b['uri']='https://www.zohoapis.'+_0x3ea2c8+_0xdb81('0x4e')+_0xd8d451+'))';return getZohoUser(_0x1f902b,'Contacts')['then'](function(_0x4dec20){if(_0x4dec20)return _0x4dec20;_0x1f902b[_0xdb81('0x4f')]='https://www.zohoapis.'+_0x3ea2c8+_0xdb81('0x50')+_0xd8d451+'))';return getZohoUser(_0x1f902b,'Leads')['then'](function(_0x27a921){if(_0x27a921)return _0x27a921;if(_0x492988['moduleCreate']!=_0xdb81('0x51')){return createEndUser(_0x1ba11b,_0x3ea2c8,_0x2eb552,_0xd8d451,_0x32d8ee,_0x492988);}else{return{};}});});break;case _0xdb81('0x52'):_0x1f902b[_0xdb81('0x4f')]=_0xdb81('0x53')+_0x3ea2c8+_0xdb81('0x4e')+_0xd8d451+'))';return getZohoUser(_0x1f902b,_0xdb81('0x54'))[_0xdb81('0x2c')](function(_0x18e3aa){if(_0x18e3aa)return _0x18e3aa;if(_0x492988[_0xdb81('0x49')]!=_0xdb81('0x51')){return createEndUser(_0x1ba11b,_0x3ea2c8,_0x2eb552,_0xd8d451,_0x32d8ee,_0x492988);}else{return{};}});break;case _0xdb81('0x55'):_0x1f902b[_0xdb81('0x4f')]=_0xdb81('0x53')+_0x3ea2c8+_0xdb81('0x50')+_0xd8d451+'))';return getZohoUser(_0x1f902b,'Leads')['then'](function(_0x122cfc){if(_0x122cfc)return _0x122cfc;if(_0x492988['moduleCreate']!=_0xdb81('0x51')){return createEndUser(_0x1ba11b,_0x3ea2c8,_0x2eb552,_0xd8d451,_0x32d8ee,_0x492988);}else{return{};}});break;}}function getCall(_0x42c28f,_0x27bd46,_0x1f057a,_0x48572e,_0x307535,_0x41cfce,_0x2f8345,_0x14dac5){logger[_0xdb81('0x38')](_0xdb81('0x56'));var _0x181078={};_0x181078[_0xdb81('0x57')]={'name':!_[_0xdb81('0x1e')](_0x48572e[_0xdb81('0x43')][_0xdb81('0x1b')])&&!_[_0xdb81('0x1e')](_0x48572e['profile'][_0xdb81('0x1b')])&&_0x48572e['profile'][_0xdb81('0x1b')]===_0xdb81('0x58')?_0x48572e[_0xdb81('0x43')][_0xdb81('0x1b')]:!_[_0xdb81('0x1e')](_0x48572e[_0xdb81('0x44')])?_0x48572e[_0xdb81('0x44')]+'\x20'+_0x48572e[_0xdb81('0x45')]:_0x48572e[_0xdb81('0x45')],'id':_0x48572e['id']};_0x181078[_0xdb81('0x59')]=intUtil[_0xdb81('0x5a')](_0x41cfce[_0xdb81('0x5b')],_0x2f8345,'\x20');_0x181078[_0xdb81('0x5c')]=intUtil['getString'](_0x41cfce[_0xdb81('0x5d')],_0x2f8345,'\x0a');if(_0x307535[_0xdb81('0x41')]===_0xdb81('0x54')){_0x181078[_0xdb81('0x5e')]={'name':!_[_0xdb81('0x1e')](_0x307535[_0xdb81('0x5f')])?_0x307535[_0xdb81('0x5f')]:!_['isNil'](_0x307535[_0xdb81('0x60')])?_0x307535[_0xdb81('0x60')]+'\x20'+_0x307535[_0xdb81('0x61')]:_0x307535[_0xdb81('0x61')],'id':_0x307535['id']};}if(_0x307535['enduserType']==='Leads'){_0x181078['What_Id']={'name':!_[_0xdb81('0x1e')](_0x307535[_0xdb81('0x5f')])?_0x307535[_0xdb81('0x5f')]:!_['isNil'](_0x307535[_0xdb81('0x60')])?_0x307535['First_Name']+'\x20'+_0x307535['Last_Name']:_0x307535[_0xdb81('0x61')],'id':_0x307535['id']};_0x181078[_0xdb81('0x62')]=_['startCase'](_0x307535[_0xdb81('0x41')]);}if(_0x2f8345[_0xdb81('0x63')]){_0x181078[_0xdb81('0x64')]=moment[_0xdb81('0x65')](parseInt(_0x2f8345[_0xdb81('0x63')])*0x3e8)[_0xdb81('0x33')](_0xdb81('0x66'));}else if(_0x2f8345[_0xdb81('0x67')]&&_0x2f8345[_0xdb81('0x68')]){_0x181078['Call_Duration']=moment[_0xdb81('0x65')](moment(_0x2f8345[_0xdb81('0x68')],_0xdb81('0x69'))['diff'](moment(_0x2f8345[_0xdb81('0x6a')],'YYYY-MM-DDTHH:mm:ss')))[_0xdb81('0x33')](_0xdb81('0x66'));}switch(_0x2f8345[_0xdb81('0x6b')]){case _0xdb81('0x6c'):_0x181078[_0xdb81('0x6d')]=_0xdb81('0x6e');break;case _0xdb81('0x6f'):case _0xdb81('0x70'):_0x181078[_0xdb81('0x6d')]=_0xdb81('0x71');break;case _0xdb81('0x72'):_0x181078[_0xdb81('0x6d')]='Rejected';break;case _0xdb81('0x73'):_0x181078['Call_Result']='Abandoned';break;case _0xdb81('0x74'):_0x181078[_0xdb81('0x6d')]='Timeout';default:}_0x181078[_0xdb81('0x75')]=(_0x14dac5===_0xdb81('0x76')?moment(_0x2f8345[_0xdb81('0x6a')])['format']('YYYY-MM-DDTHH:mm:ss'):moment(_0x2f8345[_0xdb81('0x77')])['format'](_0xdb81('0x69')))||moment()[_0xdb81('0x33')]('YYYY-MM-DDTHH:mm:ss');_0x181078[_0xdb81('0x78')]=_0x14dac5||_0xdb81('0x79');_0x181078=_[_0xdb81('0x7a')](_0x181078,getCustomFields(_0x41cfce[_0xdb81('0x7b')],_0x2f8345));return request({'method':'POST','uri':_0xdb81('0x53')+_0x27bd46+_0xdb81('0x7c'),'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x42c28f},'body':{'data':[_0x181078]},'json':!![]})[_0xdb81('0x2c')](function(_0x401aaf){if(_0x401aaf&&_0x401aaf[_0xdb81('0x40')][0x0]['code']==='SUCCESS'){logger[_0xdb81('0x38')](_0xdb81('0x7d'));return{'id':_0x401aaf[_0xdb81('0x40')][0x0][_0xdb81('0x47')]['id']};}})[_0xdb81('0x2e')](function(_0x202e1e){logger[_0xdb81('0x38')](_0xdb81('0x7e'),_0x202e1e[_0xdb81('0x31')]);console['log'](_0xdb81('0x7e'),_0x202e1e);});}exports[_0xdb81('0x7f')]=function(_0x1dac54,_0x308a71,_0x247a33,_0x1c522f,_0x54d827,_0x393924){var _0xf6aa3c,_0xd07cf0,_0x11814b;_0x393924[_0xdb81('0x80')]=intUtil[_0xdb81('0x81')](_0x393924[_0xdb81('0x80')]);_0x393924[_0xdb81('0x82')]=intUtil[_0xdb81('0x81')](_0x393924[_0xdb81('0x82')]);if(_0x54d827&&_0x54d827[_0xdb81('0x83')]){logger['info']('[QUEUE]',_0xdb81('0x84'));_0x308a71['recordingURL']=_0x393924[_0xdb81('0x82')]+_0xdb81('0x85')+_0x308a71[_0xdb81('0x86')]+_0xdb81('0x87')+md5(_0x308a71[_0xdb81('0x86')]);}else{_0x308a71['recordingURL']='';}var _0x434720=_0x393924[_0xdb81('0x80')]===_0xdb81('0x88')?'eu':_0xdb81('0x89');return getAccessToken(_0x393924)[_0xdb81('0x2c')](function(_0x590421){_0x11814b=_0x590421;return getUser(_0x11814b,_0x434720,_0x393924,_0x1c522f[_0xdb81('0x8a')]);})[_0xdb81('0x2c')](function(_0x50209f){_0xf6aa3c=_0x50209f;logger[_0xdb81('0x38')](_0xdb81('0x8b'),_0xf6aa3c['id']);return getEndUser(_0x11814b,_0x434720,_0x393924,_0x308a71[_0xdb81('0x8c')],_0x308a71[_0xdb81('0x8d')],_0xf6aa3c,_0x247a33);})[_0xdb81('0x2c')](function(_0x277912){_0xd07cf0=_0x277912;return getCall(_0x11814b,_0x434720,_0x393924,_0xf6aa3c,_0xd07cf0,_0x247a33,_0x308a71,_0xdb81('0x79'));})[_0xdb81('0x2c')](function(_0xa7a43e){if(_0xa7a43e){logger[_0xdb81('0x38')]('The\x20Call\x20ID\x20is:',_0xa7a43e['id']);logger[_0xdb81('0x38')](_0xdb81('0x8e'),_0xdb81('0x8f'));emit(util[_0xdb81('0x33')](_0xdb81('0x90'),_0x1c522f[_0xdb81('0x1b')]),_0xdb81('0x91'),{'uri':_0xdb81('0x92')+_0x393924[_0xdb81('0x80')]+_0xdb81('0x93')+_0xa7a43e['id']});}})[_0xdb81('0x2e')](function(_0x2755f3){logger['error'](_0xdb81('0x8e'),JSON[_0xdb81('0xe')](_0x2755f3));});};exports[_0xdb81('0x76')]=function(_0x1a3106,_0x2ec92d,_0x5ebe58,_0x30d6a2,_0x22afdc,_0x2316ac,_0x4fc356){var _0x119884,_0x58a658,_0x4ed924;_0x2316ac['host']=intUtil['stripTrailingSlash'](_0x2316ac[_0xdb81('0x80')]);_0x2316ac[_0xdb81('0x82')]=intUtil[_0xdb81('0x81')](_0x2316ac[_0xdb81('0x82')]);if(_0x4fc356&&_0x4fc356[_0xdb81('0x94')]&&_0x4fc356[_0xdb81('0x94')]!==_0xdb81('0x95')){logger[_0xdb81('0x38')]('[OUTBOUND]',_0xdb81('0x84'));_0x2ec92d[_0xdb81('0x96')]=_0x2316ac[_0xdb81('0x82')]+_0xdb81('0x85')+_0x2ec92d[_0xdb81('0x86')]+_0xdb81('0x87')+md5(_0x2ec92d['uniqueid']);}var _0x39ca69=_0x2316ac[_0xdb81('0x80')]===_0xdb81('0x88')?'eu':'com';return getAccessToken(_0x2316ac)['then'](function(_0x2cf56d){_0x4ed924=_0x2cf56d;return getUser(_0x4ed924,_0x39ca69,_0x2316ac,_0x30d6a2[_0xdb81('0x8a')]);})[_0xdb81('0x2c')](function(_0x39b1c1){_0x119884=_0x39b1c1;logger[_0xdb81('0x38')]('The\x20User\x20ID\x20is:',_0x119884['id']);return getEndUser(_0x4ed924,_0x39ca69,_0x2316ac,_0x2ec92d[_0xdb81('0x97')],_0x2ec92d['destcalleridnum'],_0x119884,_0x5ebe58);})['then'](function(_0x1d3959){_0x58a658=_0x1d3959;return getCall(_0x4ed924,_0x39ca69,_0x2316ac,_0x119884,_0x58a658,_0x5ebe58,_0x2ec92d,_0xdb81('0x98'));})[_0xdb81('0x2c')](function(_0x417ba1){if(_0x417ba1){logger[_0xdb81('0x38')](_0xdb81('0x99'),_0x417ba1['id']);logger[_0xdb81('0x38')]('[OUTBOUND]',_0xdb81('0x8f'));emit(util[_0xdb81('0x33')]('user:%s',_0x30d6a2[_0xdb81('0x1b')]),_0xdb81('0x91'),{'uri':_0xdb81('0x92')+_0x2316ac[_0xdb81('0x80')]+_0xdb81('0x93')+_0x417ba1['id']});}})[_0xdb81('0x2e')](function(_0x2bd1ea){logger[_0xdb81('0x2f')](_0xdb81('0x9a'),JSON[_0xdb81('0xe')](_0x2bd1ea));});};exports[_0xdb81('0x9b')]=function(_0x282b04,_0x6472dc,_0x4c7c64,_0x26ea8a,_0x14d1d4,_0x38467b){var _0x1cd03f,_0x5e1e06,_0x29c4db;_0x38467b[_0xdb81('0x80')]=intUtil['stripTrailingSlash'](_0x38467b[_0xdb81('0x80')]);_0x38467b[_0xdb81('0x82')]=intUtil[_0xdb81('0x81')](_0x38467b['serverUrl']);if(_0x14d1d4&&_0x14d1d4[_0xdb81('0x83')]){logger[_0xdb81('0x38')]('['+_0x6472dc[_0xdb81('0x6b')][_0xdb81('0x9c')]()+']',_0xdb81('0x84'));_0x6472dc[_0xdb81('0x96')]=_0x38467b[_0xdb81('0x82')]+'/api/voice/recordings/'+_0x6472dc[_0xdb81('0x86')]+_0xdb81('0x87')+md5(_0x6472dc[_0xdb81('0x86')]);}else{_0x6472dc[_0xdb81('0x96')]='';}var _0x59e910=_0x38467b['host']===_0xdb81('0x88')?'eu':'com';return getAccessToken(_0x38467b)['then'](function(_0x2eac58){_0x29c4db=_0x2eac58;return getUser(_0x29c4db,_0x59e910,_0x38467b);})[_0xdb81('0x2c')](function(_0x48aa9){_0x1cd03f=_0x48aa9;logger[_0xdb81('0x38')](_0xdb81('0x8b'),_0x1cd03f['id']);return getEndUser(_0x29c4db,_0x59e910,_0x38467b,_0x6472dc[_0xdb81('0x8c')],_0x6472dc[_0xdb81('0x8d')],_0x1cd03f,_0x4c7c64);})[_0xdb81('0x2c')](function(_0x55e37e){_0x5e1e06=_0x55e37e;return getCall(_0x29c4db,_0x59e910,_0x38467b,_0x1cd03f,_0x5e1e06,_0x4c7c64,_0x6472dc,'Inbound');})[_0xdb81('0x2c')](function(_0x341458){if(_0x341458){logger[_0xdb81('0x38')](_0xdb81('0x99'),_0x341458['id']);}})[_0xdb81('0x2e')](function(_0x511e21){logger[_0xdb81('0x2f')]('['+_0x6472dc['lastevent'][_0xdb81('0x9c')]()+']',JSON[_0xdb81('0xe')](_0x511e21));});};
\ No newline at end of file
+var _0x2f74=['timeout','Timeout','outbound','YYYY-MM-DDTHH:mm:ss','merge','/crm/v2/Calls','log','err','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','/api/voice/recordings/','/downloads?type=uniqueid&token=','uniqueid','recordingURL','zoho.eu','calleridname','calleridnum','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','/crm/EntityInfo.do?module=Calls&id=','recordingFormat','[OUTBOUND]','Recording\x20is\x20enabled!','com','destcalleridname','Outbound','The\x20Call\x20ID\x20is:','unmanaged','lastevent','The\x20User\x20ID\x20is:','toUpperCase','lodash','request-promise','md5','util','./util','ioredis','bluebird','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','emit','debug','stringify','length','forEach','includes','picklist','type','idField','toString','variable','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','isBefore','expires_in','access_token','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','/oauth/v2/token','refreshToken','clientId','clientSecret','then','catch','error','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','Zoho-oauthtoken\x20','isArrayLikeObject','users','email','Agent\x20found!','Using\x20the\x20admin\x20account!','profile','user','The\x20failing\x20result\x20is','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','https://www.zohoapis.','startCase','moduleCreate','role','first_name','last_name','code','SUCCESS','details','Error:\x20','moduleSearch','contact_lead','uri','Contacts','Leads','nothing','contact','/crm/v2/Contacts/search?criteria=((Phone:equals:','lead','/crm/v2/Leads/search?criteria=((Phone:equals:','Creating\x20new\x20call...','Owner','getString','Subjects','Description','Descriptions','Who_Id','Full_Name','First_Name','What_Id','Last_Name','$se_module','talktime','mm:ss','endtime','Call_Duration','diff','starttime','called','Called','connect','rejected','Call_Result','Rejected','abandoned','Abandoned'];(function(_0x420d8d,_0x78b67f){var _0x4865d7=function(_0x2965df){while(--_0x2965df){_0x420d8d['push'](_0x420d8d['shift']());}};_0x4865d7(++_0x78b67f);}(_0x2f74,0xb7));var _0x42f7=function(_0x2958a7,_0x569f19){_0x2958a7=_0x2958a7-0x0;var _0x1e0865=_0x2f74[_0x2958a7];return _0x1e0865;};'use strict';var _=require(_0x42f7('0x0'));var rp=require(_0x42f7('0x1'));var md5=require(_0x42f7('0x2'));var util=require(_0x42f7('0x3'));var intUtil=require(_0x42f7('0x4'));var moment=require('moment');var Redis=require(_0x42f7('0x5'));var BPromise=require(_0x42f7('0x6'));var config=require(_0x42f7('0x7'));var logger=require('../../../../config/logger')('zoho');config[_0x42f7('0x8')]=_[_0x42f7('0x9')](config[_0x42f7('0x8')],{'host':_0x42f7('0xa'),'port':0x18eb});var io=require(_0x42f7('0xb'))(new Redis(config['redis']));function emit(_0x346d22,_0x1a07f2,_0x260e8f){io['to'](_0x346d22)[_0x42f7('0xc')](_0x1a07f2,_0x260e8f);}function request(_0x51d26c){logger[_0x42f7('0xd')]('[HTTP]',JSON[_0x42f7('0xe')](_0x51d26c));return rp(_0x51d26c);}function getCustomFields(_0x49437c,_0x2264db){var _0x181360={};if(_0x49437c[_0x42f7('0xf')]>0x0){_[_0x42f7('0x10')](_0x49437c,function(_0xf46574){if(_[_0x42f7('0x11')](['string',_0x42f7('0x12')],_0xf46574[_0x42f7('0x13')])&&_0xf46574[_0x42f7('0x14')]){_0x181360[_0xf46574[_0x42f7('0x14')]]=_0xf46574['content'][_0x42f7('0x15')]();}else if(_0xf46574[_0x42f7('0x13')]===_0x42f7('0x16')&&_0xf46574[_0x42f7('0x17')]&&_0xf46574[_0x42f7('0x14')]&&_0x2264db[_0xf46574[_0x42f7('0x17')]]){_0x181360[_0xf46574[_0x42f7('0x14')]]=_0x2264db[_0xf46574[_0x42f7('0x17')]][_0x42f7('0x15')]();}else if(_0xf46574[_0x42f7('0x13')]===_0x42f7('0x18')&&_0xf46574[_0x42f7('0x19')]&&_0xf46574[_0x42f7('0x19')]['name']&&_0xf46574[_0x42f7('0x14')]&&_0x2264db[_0xf46574[_0x42f7('0x19')][_0x42f7('0x1a')][_0x42f7('0x1b')]()]){_0x181360[_0xf46574[_0x42f7('0x14')]]=_0x2264db[_0xf46574[_0x42f7('0x19')][_0x42f7('0x1a')][_0x42f7('0x1b')]()][_0x42f7('0x15')]();}});}return _0x181360;}function getName(_0x2b75e0){if(_0x2b75e0[_0x42f7('0x1c')]('\x20')>0x0){var _0x10b51a=_0x2b75e0[_0x42f7('0x1d')](/ (.+)/);if(_0x10b51a[0x1]){return _0x10b51a;}}return[_0x2b75e0,_0x2b75e0];}var accountsTokens={};function getAccessToken(_0x3be2e7){return new Promise(function(_0x1aa12e,_0x2f4a24){if(!_[_0x42f7('0x1e')](accountsTokens[_0x3be2e7['id']])&&!_[_0x42f7('0x1e')](accountsTokens[_0x3be2e7['id']]['access_token'])){if(moment()[_0x42f7('0x1f')](accountsTokens[_0x3be2e7['id']][_0x42f7('0x20')])){_0x1aa12e(accountsTokens[_0x3be2e7['id']][_0x42f7('0x21')]);}}var _0x577e3c;switch(_0x3be2e7['zone']){case'US':_0x577e3c=_0x42f7('0x22');break;case'AU':_0x577e3c=_0x42f7('0x23');break;case'EU':_0x577e3c=_0x42f7('0x24');break;case'IN':_0x577e3c=_0x42f7('0x25');break;case'CN':_0x577e3c=_0x42f7('0x26');break;default:_0x577e3c=_0x42f7('0x24');break;}var _0x1179a7={'method':_0x42f7('0x27'),'uri':_0x577e3c+_0x42f7('0x28'),'qs':{'refresh_token':_0x3be2e7[_0x42f7('0x29')],'client_id':_0x3be2e7[_0x42f7('0x2a')],'client_secret':_0x3be2e7[_0x42f7('0x2b')],'grant_type':'refresh_token'},'json':!![]};return rp(_0x1179a7)[_0x42f7('0x2c')](function(_0x453183){accountsTokens[_0x3be2e7['id']]={'access_token':_0x453183[_0x42f7('0x21')],'expires_in':moment()['add'](_0x453183[_0x42f7('0x20')],'seconds')};_0x1aa12e(_0x453183[_0x42f7('0x21')]);})[_0x42f7('0x2d')](function(_0x4d1608){logger[_0x42f7('0x2e')]('Failing\x20creating\x20the\x20access_token',_0x4d1608[_0x42f7('0x2f')]);_0x2f4a24(_0x4d1608);});});}function getUser(_0x33142d,_0x2a1f76,_0x34836e,_0x3d877f){logger[_0x42f7('0x30')](_0x42f7('0x31'));return request({'method':_0x42f7('0x32'),'uri':util[_0x42f7('0x33')](_0x42f7('0x34'),_0x2a1f76),'qs':{'type':'ActiveUsers'},'headers':{'Authorization':_0x42f7('0x35')+_0x33142d},'json':!![]})[_0x42f7('0x2c')](function(_0x4b2a23){if(_0x4b2a23['users']){var _0x554449=-0x1;if(_[_0x42f7('0x36')](_0x4b2a23[_0x42f7('0x37')])){if(!_[_0x42f7('0x1e')](_0x3d877f)){_0x554449=_['findIndex'](_0x4b2a23[_0x42f7('0x37')],function(_0xa88576){return _0xa88576[_0x42f7('0x38')]===_0x3d877f;});}if(_0x554449>=0x0){logger[_0x42f7('0x30')](_0x42f7('0x39'));}else{logger[_0x42f7('0x30')](_0x42f7('0x3a'));_0x554449=_['findIndex'](_0x4b2a23[_0x42f7('0x37')],function(_0x2f655b){return _0x2f655b[_0x42f7('0x3b')][_0x42f7('0x1a')]==='Administrator';});}return _0x4b2a23[_0x42f7('0x37')][_0x554449];}else{if(_0x4b2a23[_0x42f7('0x3c')][_0x42f7('0x3b')][_0x42f7('0x1a')]==='Administrator'){logger['info'](_0x42f7('0x3a'));user=_0x4b2a23[_0x42f7('0x3c')];return user;}else{logger['error'](_0x42f7('0x3d'),JSON[_0x42f7('0xe')](_0x4b2a23));throw new Error(_0x42f7('0x3e')+JSON['stringify'](_0x4b2a23));}}}else{logger['error'](_0x42f7('0x3d'),JSON[_0x42f7('0xe')](_0x4b2a23));throw new Error(_0x42f7('0x3e')+JSON[_0x42f7('0xe')](_0x4b2a23));}})[_0x42f7('0x2d')](function(_0x5f043e){console[_0x42f7('0x2e')](_0x5f043e);});}function getZohoUser(_0x851c16,_0xaf2d45){return new BPromise(function(_0x4faade,_0x485b7b){request(_0x851c16)[_0x42f7('0x2c')](function(_0x39c287){var _0x1f881a=null;if(_0x39c287){_0x1f881a=_0x39c287[_0x42f7('0x3f')][0x0];_0x1f881a[_0x42f7('0x40')]=_0xaf2d45;}_0x4faade(_0x1f881a);})[_0x42f7('0x2d')](function(_0x393e3c){_0x485b7b(_0x393e3c);});});}function createEndUser(_0x3077bc,_0xead50c,_0x190309,_0x190453,_0x55f4ce,_0x5663b3){var _0x190309=getName(_0x190309);return request({'method':_0x42f7('0x27'),'uri':_0x42f7('0x41')+_0xead50c+'/crm/v2/'+_[_0x42f7('0x42')](_0x5663b3[_0x42f7('0x43')])+'s','body':{'data':[{'Last_Name':_0x190309[0x1],'First_Name':_0x190309[0x0],'Phone':_0x190453,'Owner':{'name':!_[_0x42f7('0x1e')](_0x55f4ce['role'][_0x42f7('0x1a')])?_0x55f4ce[_0x42f7('0x44')][_0x42f7('0x1a')]:!_[_0x42f7('0x1e')](_0x55f4ce['first_name'])?_0x55f4ce[_0x42f7('0x45')]+'\x20'+_0x55f4ce[_0x42f7('0x46')]:_0x55f4ce[_0x42f7('0x46')],'id':_0x55f4ce['id']}}]},'headers':{'Authorization':_0x42f7('0x35')+_0x3077bc},'json':!![]})['then'](function(_0x35e08c){if(_0x35e08c&&_0x35e08c[_0x42f7('0x3f')][0x0][_0x42f7('0x47')]===_0x42f7('0x48')){var _0x45e4bb=_0x35e08c[_0x42f7('0x3f')][0x0][_0x42f7('0x49')];_0x45e4bb['enduserType']=_[_0x42f7('0x42')](_0x5663b3[_0x42f7('0x43')])+'s';return _0x45e4bb;}logger[_0x42f7('0x2e')](_0x42f7('0x3d'),JSON[_0x42f7('0xe')](data));throw new Error(_0x42f7('0x4a')+JSON[_0x42f7('0xe')](data));})[_0x42f7('0x2d')](function(_0xbdb869){console['log']('CREATE\x20ERROR',_0xbdb869);});}function getEndUser(_0xa6fe2,_0x5e69f6,_0x5a2434,_0x46ef7,_0x233f29,_0x1a6ca5,_0x239d0a){var _0x53c2c1={'method':'GET','uri':'','headers':{'Authorization':_0x42f7('0x35')+_0xa6fe2},'json':!![]};switch(_0x239d0a[_0x42f7('0x4b')]){case _0x42f7('0x4c'):_0x53c2c1[_0x42f7('0x4d')]=_0x42f7('0x41')+_0x5e69f6+'/crm/v2/Contacts/search?criteria=((Phone:equals:'+_0x233f29+'))';return getZohoUser(_0x53c2c1,_0x42f7('0x4e'))[_0x42f7('0x2c')](function(_0x3e6171){if(_0x3e6171)return _0x3e6171;_0x53c2c1[_0x42f7('0x4d')]='https://www.zohoapis.'+_0x5e69f6+'/crm/v2/Leads/search?criteria=((Phone:equals:'+_0x233f29+'))';return getZohoUser(_0x53c2c1,_0x42f7('0x4f'))[_0x42f7('0x2c')](function(_0x2cf71b){if(_0x2cf71b)return _0x2cf71b;if(_0x239d0a['moduleCreate']!=_0x42f7('0x50')){return createEndUser(_0xa6fe2,_0x5e69f6,_0x46ef7,_0x233f29,_0x1a6ca5,_0x239d0a);}else{return{};}});});break;case _0x42f7('0x51'):_0x53c2c1[_0x42f7('0x4d')]=_0x42f7('0x41')+_0x5e69f6+_0x42f7('0x52')+_0x233f29+'))';return getZohoUser(_0x53c2c1,_0x42f7('0x4e'))['then'](function(_0x23ef48){if(_0x23ef48)return _0x23ef48;if(_0x239d0a[_0x42f7('0x43')]!=_0x42f7('0x50')){return createEndUser(_0xa6fe2,_0x5e69f6,_0x46ef7,_0x233f29,_0x1a6ca5,_0x239d0a);}else{return{};}});break;case _0x42f7('0x53'):_0x53c2c1[_0x42f7('0x4d')]=_0x42f7('0x41')+_0x5e69f6+_0x42f7('0x54')+_0x233f29+'))';return getZohoUser(_0x53c2c1,_0x42f7('0x4f'))['then'](function(_0x2a9e43){if(_0x2a9e43)return _0x2a9e43;if(_0x239d0a[_0x42f7('0x43')]!=_0x42f7('0x50')){return createEndUser(_0xa6fe2,_0x5e69f6,_0x46ef7,_0x233f29,_0x1a6ca5,_0x239d0a);}else{return{};}});break;}}function getCall(_0x417540,_0x32a9f0,_0x5f7ce8,_0x5294fe,_0x360c67,_0x780000,_0x59ea0b,_0x2b468a){logger['info'](_0x42f7('0x55'));var _0x10926d={};_0x10926d[_0x42f7('0x56')]={'name':!_[_0x42f7('0x1e')](_0x5294fe[_0x42f7('0x44')][_0x42f7('0x1a')])&&!_[_0x42f7('0x1e')](_0x5294fe[_0x42f7('0x3b')][_0x42f7('0x1a')])&&_0x5294fe[_0x42f7('0x3b')][_0x42f7('0x1a')]==='administrator'?_0x5294fe['role'][_0x42f7('0x1a')]:!_[_0x42f7('0x1e')](_0x5294fe['first_name'])?_0x5294fe[_0x42f7('0x45')]+'\x20'+_0x5294fe['last_name']:_0x5294fe[_0x42f7('0x46')],'id':_0x5294fe['id']};_0x10926d['Subject']=intUtil[_0x42f7('0x57')](_0x780000[_0x42f7('0x58')],_0x59ea0b,'\x20');_0x10926d[_0x42f7('0x59')]=intUtil['getString'](_0x780000[_0x42f7('0x5a')],_0x59ea0b,'\x0a');if(_0x360c67[_0x42f7('0x40')]===_0x42f7('0x4e')){_0x10926d[_0x42f7('0x5b')]={'name':!_[_0x42f7('0x1e')](_0x360c67[_0x42f7('0x5c')])?_0x360c67[_0x42f7('0x5c')]:!_['isNil'](_0x360c67['First_Name'])?_0x360c67[_0x42f7('0x5d')]+'\x20'+_0x360c67['Last_Name']:_0x360c67['Last_Name'],'id':_0x360c67['id']};}if(_0x360c67[_0x42f7('0x40')]===_0x42f7('0x4f')){_0x10926d[_0x42f7('0x5e')]={'name':!_[_0x42f7('0x1e')](_0x360c67[_0x42f7('0x5c')])?_0x360c67[_0x42f7('0x5c')]:!_[_0x42f7('0x1e')](_0x360c67[_0x42f7('0x5d')])?_0x360c67[_0x42f7('0x5d')]+'\x20'+_0x360c67[_0x42f7('0x5f')]:_0x360c67[_0x42f7('0x5f')],'id':_0x360c67['id']};_0x10926d[_0x42f7('0x60')]=_[_0x42f7('0x42')](_0x360c67[_0x42f7('0x40')]);}if(_0x59ea0b[_0x42f7('0x61')]){_0x10926d['Call_Duration']=moment['utc'](parseInt(_0x59ea0b[_0x42f7('0x61')])*0x3e8)[_0x42f7('0x33')](_0x42f7('0x62'));}else if(_0x59ea0b['answertime']&&_0x59ea0b[_0x42f7('0x63')]){_0x10926d[_0x42f7('0x64')]=moment['utc'](moment(_0x59ea0b[_0x42f7('0x63')],'YYYY-MM-DDTHH:mm:ss')[_0x42f7('0x65')](moment(_0x59ea0b[_0x42f7('0x66')],'YYYY-MM-DDTHH:mm:ss')))[_0x42f7('0x33')](_0x42f7('0x62'));}switch(_0x59ea0b['lastevent']){case _0x42f7('0x67'):_0x10926d['Call_Result']=_0x42f7('0x68');break;case'complete':case _0x42f7('0x69'):_0x10926d['Call_Result']='Answered';break;case _0x42f7('0x6a'):_0x10926d[_0x42f7('0x6b')]=_0x42f7('0x6c');break;case _0x42f7('0x6d'):_0x10926d['Call_Result']=_0x42f7('0x6e');break;case _0x42f7('0x6f'):_0x10926d[_0x42f7('0x6b')]=_0x42f7('0x70');default:}_0x10926d['Call_Start_Time']=(_0x2b468a===_0x42f7('0x71')?moment(_0x59ea0b['starttime'])['format'](_0x42f7('0x72')):moment(_0x59ea0b['agentcalledAt'])[_0x42f7('0x33')](_0x42f7('0x72')))||moment()[_0x42f7('0x33')](_0x42f7('0x72'));_0x10926d['Call_Type']=_0x2b468a||'Inbound';_0x10926d=_[_0x42f7('0x73')](_0x10926d,getCustomFields(_0x780000['Fields'],_0x59ea0b));return request({'method':_0x42f7('0x27'),'uri':_0x42f7('0x41')+_0x32a9f0+_0x42f7('0x74'),'headers':{'Authorization':_0x42f7('0x35')+_0x417540},'body':{'data':[_0x10926d]},'json':!![]})[_0x42f7('0x2c')](function(_0x5b0384){if(_0x5b0384&&_0x5b0384['data'][0x0][_0x42f7('0x47')]===_0x42f7('0x48')){logger[_0x42f7('0x30')]('Call\x20created!');return{'id':_0x5b0384[_0x42f7('0x3f')][0x0][_0x42f7('0x49')]['id']};}})[_0x42f7('0x2d')](function(_0x19ae4b){logger[_0x42f7('0x30')]('err',_0x19ae4b[_0x42f7('0x2f')]);console[_0x42f7('0x75')](_0x42f7('0x76'),_0x19ae4b);});}exports['queue']=function(_0x1aa7b9,_0x527efa,_0x4ae5cb,_0x1b5d55,_0xa91ea4,_0x614c69){var _0x48c6ea,_0x529581,_0x328aae;_0x614c69[_0x42f7('0x77')]=intUtil[_0x42f7('0x78')](_0x614c69['host']);_0x614c69[_0x42f7('0x79')]=intUtil['stripTrailingSlash'](_0x614c69['serverUrl']);if(_0xa91ea4&&_0xa91ea4[_0x42f7('0x7a')]){logger[_0x42f7('0x30')](_0x42f7('0x7b'),'Recording\x20is\x20enabled!');_0x527efa['recordingURL']=_0x614c69[_0x42f7('0x79')]+_0x42f7('0x7c')+_0x527efa['uniqueid']+_0x42f7('0x7d')+md5(_0x527efa[_0x42f7('0x7e')]);}else{_0x527efa[_0x42f7('0x7f')]='';}var _0x57c709=_0x614c69[_0x42f7('0x77')]===_0x42f7('0x80')?'eu':'com';return getAccessToken(_0x614c69)[_0x42f7('0x2c')](function(_0x5d25f0){_0x328aae=_0x5d25f0;return getUser(_0x328aae,_0x57c709,_0x614c69,_0x1b5d55[_0x42f7('0x38')]);})['then'](function(_0xcdeabd){_0x48c6ea=_0xcdeabd;logger[_0x42f7('0x30')]('The\x20User\x20ID\x20is:',_0x48c6ea['id']);return getEndUser(_0x328aae,_0x57c709,_0x614c69,_0x527efa[_0x42f7('0x81')],_0x527efa[_0x42f7('0x82')],_0x48c6ea,_0x4ae5cb);})[_0x42f7('0x2c')](function(_0x50d5d9){_0x529581=_0x50d5d9;return getCall(_0x328aae,_0x57c709,_0x614c69,_0x48c6ea,_0x529581,_0x4ae5cb,_0x527efa,'Inbound');})[_0x42f7('0x2c')](function(_0x1afcbf){if(_0x1afcbf){logger[_0x42f7('0x30')]('The\x20Call\x20ID\x20is:',_0x1afcbf['id']);logger[_0x42f7('0x30')](_0x42f7('0x7b'),_0x42f7('0x83'));emit(util[_0x42f7('0x33')](_0x42f7('0x84'),_0x1b5d55[_0x42f7('0x1a')]),_0x42f7('0x85'),{'uri':_0x42f7('0x86')+_0x614c69['host']+_0x42f7('0x87')+_0x1afcbf['id']});}})[_0x42f7('0x2d')](function(_0x45601a){logger[_0x42f7('0x2e')](_0x42f7('0x7b'),JSON[_0x42f7('0xe')](_0x45601a));});};exports['outbound']=function(_0x779583,_0x2b3879,_0x2f8527,_0x52f9aa,_0x561976,_0x3afcaf,_0x198e8e){var _0x1c208d,_0x3b2b2d,_0x255c69;_0x3afcaf[_0x42f7('0x77')]=intUtil[_0x42f7('0x78')](_0x3afcaf[_0x42f7('0x77')]);_0x3afcaf['serverUrl']=intUtil[_0x42f7('0x78')](_0x3afcaf[_0x42f7('0x79')]);if(_0x198e8e&&_0x198e8e[_0x42f7('0x88')]&&_0x198e8e[_0x42f7('0x88')]!=='none'){logger[_0x42f7('0x30')](_0x42f7('0x89'),_0x42f7('0x8a'));_0x2b3879[_0x42f7('0x7f')]=_0x3afcaf[_0x42f7('0x79')]+_0x42f7('0x7c')+_0x2b3879[_0x42f7('0x7e')]+_0x42f7('0x7d')+md5(_0x2b3879['uniqueid']);}var _0xa0e875=_0x3afcaf[_0x42f7('0x77')]===_0x42f7('0x80')?'eu':_0x42f7('0x8b');return getAccessToken(_0x3afcaf)['then'](function(_0x478bbd){_0x255c69=_0x478bbd;return getUser(_0x255c69,_0xa0e875,_0x3afcaf,_0x52f9aa[_0x42f7('0x38')]);})[_0x42f7('0x2c')](function(_0x2c22f9){_0x1c208d=_0x2c22f9;logger['info']('The\x20User\x20ID\x20is:',_0x1c208d['id']);return getEndUser(_0x255c69,_0xa0e875,_0x3afcaf,_0x2b3879[_0x42f7('0x8c')],_0x2b3879['destcalleridnum'],_0x1c208d,_0x2f8527);})['then'](function(_0x2ef3e1){_0x3b2b2d=_0x2ef3e1;return getCall(_0x255c69,_0xa0e875,_0x3afcaf,_0x1c208d,_0x3b2b2d,_0x2f8527,_0x2b3879,_0x42f7('0x8d'));})[_0x42f7('0x2c')](function(_0x258103){if(_0x258103){logger[_0x42f7('0x30')](_0x42f7('0x8e'),_0x258103['id']);logger['info']('[OUTBOUND]',_0x42f7('0x83'));emit(util[_0x42f7('0x33')]('user:%s',_0x52f9aa[_0x42f7('0x1a')]),_0x42f7('0x85'),{'uri':'https://crm.'+_0x3afcaf[_0x42f7('0x77')]+_0x42f7('0x87')+_0x258103['id']});}})[_0x42f7('0x2d')](function(_0x3a2008){logger[_0x42f7('0x2e')](_0x42f7('0x89'),JSON[_0x42f7('0xe')](_0x3a2008));});};exports[_0x42f7('0x8f')]=function(_0x51c645,_0x234120,_0x5c1fd0,_0x3b4a1a,_0x5f50da,_0x82f7b2){var _0x33ad54,_0x54dcc7,_0x442ca9;_0x82f7b2['host']=intUtil[_0x42f7('0x78')](_0x82f7b2[_0x42f7('0x77')]);_0x82f7b2['serverUrl']=intUtil[_0x42f7('0x78')](_0x82f7b2[_0x42f7('0x79')]);if(_0x5f50da&&_0x5f50da[_0x42f7('0x7a')]){logger[_0x42f7('0x30')]('['+_0x234120[_0x42f7('0x90')]['toUpperCase']()+']','Recording\x20is\x20enabled!');_0x234120['recordingURL']=_0x82f7b2[_0x42f7('0x79')]+_0x42f7('0x7c')+_0x234120[_0x42f7('0x7e')]+_0x42f7('0x7d')+md5(_0x234120[_0x42f7('0x7e')]);}else{_0x234120[_0x42f7('0x7f')]='';}var _0x171391=_0x82f7b2[_0x42f7('0x77')]===_0x42f7('0x80')?'eu':_0x42f7('0x8b');return getAccessToken(_0x82f7b2)[_0x42f7('0x2c')](function(_0x59e02b){_0x442ca9=_0x59e02b;return getUser(_0x442ca9,_0x171391,_0x82f7b2);})['then'](function(_0x5fc95e){_0x33ad54=_0x5fc95e;logger[_0x42f7('0x30')](_0x42f7('0x91'),_0x33ad54['id']);return getEndUser(_0x442ca9,_0x171391,_0x82f7b2,_0x234120['calleridname'],_0x234120[_0x42f7('0x82')],_0x33ad54,_0x5c1fd0);})[_0x42f7('0x2c')](function(_0x3ca6be){_0x54dcc7=_0x3ca6be;return getCall(_0x442ca9,_0x171391,_0x82f7b2,_0x33ad54,_0x54dcc7,_0x5c1fd0,_0x234120,'Inbound');})[_0x42f7('0x2c')](function(_0x235c0b){if(_0x235c0b){logger['info']('The\x20Call\x20ID\x20is:',_0x235c0b['id']);}})['catch'](function(_0x239f41){logger[_0x42f7('0x2e')]('['+_0x234120['lastevent'][_0x42f7('0x92')]()+']',JSON['stringify'](_0x239f41));});};
\ No newline at end of file