Built motion from commit 56b8093a.|2.6.29
[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 _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));});};