621ca8653287146a5f47cc0878cf5e449d224a72
[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 _0xb01f=['moduleCreate','The\x20failing\x20result\x20is','log','CREATE\x20ERROR','moduleSearch','contact_lead','https://www.zohoapis.','/crm/v2/Contacts/search?criteria=((Phone:equals:','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','uri','Contacts','lead','Leads','Owner','getString','Subjects','Description','Full_Name','First_Name','Last_Name','What_Id','talktime','Call_Duration','utc','format','mm:ss','answertime','endtime','YYYY-MM-DDTHH:mm:ss','starttime','lastevent','called','Call_Result','Called','Answered','rejected','Rejected','Abandoned','timeout','Timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','merge','Fields','/crm/v2/Calls','Call\x20created!','err','stack','queue','host','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','/downloads?type=uniqueid&token=','uniqueid','zoho.eu','com','calleridnum','Inbound','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.','recordingFormat','none','[OUTBOUND]','/api/voice/recordings/','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','Outbound','toUpperCase','lodash','request-promise','md5','util','moment','bluebird','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','debug','[HTTP]','stringify','includes','string','picklist','type','idField','content','toString','variable','variableName','customVariable','Variable','name','toLowerCase','indexOf','split','isNil','access_token','isBefore','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','refreshToken','clientId','clientSecret','then','add','seconds','catch','Failing\x20creating\x20the\x20access_token','info','Search\x20user','GET','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','users','isArrayLikeObject','findIndex','email','Agent\x20found!','profile','Administrator','user','Using\x20the\x20admin\x20account!','error','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','data','enduserType','/crm/v2/','role','first_name','last_name','Zoho-oauthtoken\x20','code','details','startCase'];(function(_0x2a528b,_0x2dfd60){var _0x3a2f1d=function(_0x25b6e5){while(--_0x25b6e5){_0x2a528b['push'](_0x2a528b['shift']());}};_0x3a2f1d(++_0x2dfd60);}(_0xb01f,0x184));var _0xfb01=function(_0x2567f1,_0x16d4c1){_0x2567f1=_0x2567f1-0x0;var _0x8a4cda=_0xb01f[_0x2567f1];return _0x8a4cda;};'use strict';var _=require(_0xfb01('0x0'));var rp=require(_0xfb01('0x1'));var md5=require(_0xfb01('0x2'));var util=require(_0xfb01('0x3'));var intUtil=require('./util');var moment=require(_0xfb01('0x4'));var Redis=require('ioredis');var BPromise=require(_0xfb01('0x5'));var config=require(_0xfb01('0x6'));var logger=require(_0xfb01('0x7'))('zoho');config[_0xfb01('0x8')]=_[_0xfb01('0x9')](config[_0xfb01('0x8')],{'host':_0xfb01('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xfb01('0x8')]));function emit(_0x38d3be,_0x125316,_0x2c3917){io['to'](_0x38d3be)['emit'](_0x125316,_0x2c3917);}function request(_0x4d456b){logger[_0xfb01('0xb')](_0xfb01('0xc'),JSON[_0xfb01('0xd')](_0x4d456b));return rp(_0x4d456b);}function getCustomFields(_0x33bae4,_0x2183ec){var _0x3be1e7={};if(_0x33bae4['length']>0x0){_['forEach'](_0x33bae4,function(_0x1f98f8){if(_[_0xfb01('0xe')]([_0xfb01('0xf'),_0xfb01('0x10')],_0x1f98f8[_0xfb01('0x11')])&&_0x1f98f8[_0xfb01('0x12')]){_0x3be1e7[_0x1f98f8[_0xfb01('0x12')]]=_0x1f98f8[_0xfb01('0x13')][_0xfb01('0x14')]();}else if(_0x1f98f8['type']===_0xfb01('0x15')&&_0x1f98f8[_0xfb01('0x16')]&&_0x1f98f8[_0xfb01('0x12')]&&_0x2183ec[_0x1f98f8[_0xfb01('0x16')]]){_0x3be1e7[_0x1f98f8[_0xfb01('0x12')]]=_0x2183ec[_0x1f98f8['variableName']][_0xfb01('0x14')]();}else if(_0x1f98f8[_0xfb01('0x11')]===_0xfb01('0x17')&&_0x1f98f8[_0xfb01('0x18')]&&_0x1f98f8[_0xfb01('0x18')][_0xfb01('0x19')]&&_0x1f98f8[_0xfb01('0x12')]&&_0x2183ec[_0x1f98f8['Variable'][_0xfb01('0x19')][_0xfb01('0x1a')]()]){_0x3be1e7[_0x1f98f8['idField']]=_0x2183ec[_0x1f98f8[_0xfb01('0x18')][_0xfb01('0x19')][_0xfb01('0x1a')]()][_0xfb01('0x14')]();}});}return _0x3be1e7;}function getName(_0x8526c8){if(_0x8526c8[_0xfb01('0x1b')]('\x20')>0x0){var _0x5dd0be=_0x8526c8[_0xfb01('0x1c')](/ (.+)/);if(_0x5dd0be[0x1]){return _0x5dd0be;}}return[_0x8526c8,_0x8526c8];}var accountsTokens={};function getAccessToken(_0x3e74dd){return new Promise(function(_0x4ae1c7,_0x1413d2){if(!_[_0xfb01('0x1d')](accountsTokens[_0x3e74dd['id']])&&!_[_0xfb01('0x1d')](accountsTokens[_0x3e74dd['id']][_0xfb01('0x1e')])){if(moment()[_0xfb01('0x1f')](accountsTokens[_0x3e74dd['id']][_0xfb01('0x20')])){_0x4ae1c7(accountsTokens[_0x3e74dd['id']][_0xfb01('0x1e')]);}}var _0x26a0d2;switch(_0x3e74dd[_0xfb01('0x21')]){case'US':_0x26a0d2=_0xfb01('0x22');break;case'AU':_0x26a0d2=_0xfb01('0x23');break;case'EU':_0x26a0d2=_0xfb01('0x24');break;case'IN':_0x26a0d2=_0xfb01('0x25');break;case'CN':_0x26a0d2=_0xfb01('0x26');break;default:_0x26a0d2=_0xfb01('0x24');break;}var _0x1f3eb4={'method':_0xfb01('0x27'),'uri':_0x26a0d2+'/oauth/v2/token','qs':{'refresh_token':_0x3e74dd[_0xfb01('0x28')],'client_id':_0x3e74dd[_0xfb01('0x29')],'client_secret':_0x3e74dd[_0xfb01('0x2a')],'grant_type':'refresh_token'},'json':!![]};return rp(_0x1f3eb4)[_0xfb01('0x2b')](function(_0x365c64){accountsTokens[_0x3e74dd['id']]={'access_token':_0x365c64[_0xfb01('0x1e')],'expires_in':moment()[_0xfb01('0x2c')](_0x365c64[_0xfb01('0x20')],_0xfb01('0x2d'))};_0x4ae1c7(_0x365c64['access_token']);})[_0xfb01('0x2e')](function(_0x93887c){logger['error'](_0xfb01('0x2f'),_0x93887c['stack']);_0x1413d2(_0x93887c);});});}function getUser(_0x363ca9,_0x4b475a,_0x23e8b4,_0x1eebe7){logger[_0xfb01('0x30')](_0xfb01('0x31'));return request({'method':_0xfb01('0x32'),'uri':util['format'](_0xfb01('0x33'),_0x4b475a),'qs':{'type':_0xfb01('0x34')},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x363ca9},'json':!![]})[_0xfb01('0x2b')](function(_0x488362){if(_0x488362[_0xfb01('0x35')]){var _0x2e4a96=-0x1;if(_[_0xfb01('0x36')](_0x488362[_0xfb01('0x35')])){if(!_['isNil'](_0x1eebe7)){_0x2e4a96=_[_0xfb01('0x37')](_0x488362['users'],function(_0x234df6){return _0x234df6[_0xfb01('0x38')]===_0x1eebe7;});}if(_0x2e4a96>=0x0){logger[_0xfb01('0x30')](_0xfb01('0x39'));}else{logger['info']('Using\x20the\x20admin\x20account!');_0x2e4a96=_[_0xfb01('0x37')](_0x488362[_0xfb01('0x35')],function(_0x5df729){return _0x5df729[_0xfb01('0x3a')][_0xfb01('0x19')]===_0xfb01('0x3b');});}return _0x488362[_0xfb01('0x35')][_0x2e4a96];}else{if(_0x488362[_0xfb01('0x3c')][_0xfb01('0x3a')][_0xfb01('0x19')]===_0xfb01('0x3b')){logger['info'](_0xfb01('0x3d'));user=_0x488362[_0xfb01('0x3c')];return user;}else{logger[_0xfb01('0x3e')]('The\x20failing\x20result\x20is',JSON[_0xfb01('0xd')](_0x488362));throw new Error(_0xfb01('0x3f')+JSON[_0xfb01('0xd')](_0x488362));}}}else{logger[_0xfb01('0x3e')]('The\x20failing\x20result\x20is',JSON['stringify'](_0x488362));throw new Error(_0xfb01('0x3f')+JSON[_0xfb01('0xd')](_0x488362));}})[_0xfb01('0x2e')](function(_0x583e51){console[_0xfb01('0x3e')](_0x583e51);});}function getZohoUser(_0x3ff4c5,_0x1fa665){return new BPromise(function(_0x3b1a30,_0x51bb66){request(_0x3ff4c5)[_0xfb01('0x2b')](function(_0x2a571f){var _0x4f419c=null;if(_0x2a571f){_0x4f419c=_0x2a571f[_0xfb01('0x40')][0x0];_0x4f419c[_0xfb01('0x41')]=_0x1fa665;}_0x3b1a30(_0x4f419c);})[_0xfb01('0x2e')](function(_0x402628){_0x51bb66(_0x402628);});});}function createEndUser(_0x3fb9ca,_0x18c8a6,_0x471887,_0x57a6ad,_0x334648,_0x304e08){var _0x471887=getName(_0x471887);return request({'method':_0xfb01('0x27'),'uri':'https://www.zohoapis.'+_0x18c8a6+_0xfb01('0x42')+_['startCase'](_0x304e08['moduleCreate'])+'s','body':{'data':[{'Last_Name':_0x471887[0x1],'First_Name':_0x471887[0x0],'Phone':_0x57a6ad,'Owner':{'name':!_['isNil'](_0x334648[_0xfb01('0x43')][_0xfb01('0x19')])?_0x334648[_0xfb01('0x43')]['name']:!_[_0xfb01('0x1d')](_0x334648[_0xfb01('0x44')])?_0x334648[_0xfb01('0x44')]+'\x20'+_0x334648['last_name']:_0x334648[_0xfb01('0x45')],'id':_0x334648['id']}}]},'headers':{'Authorization':_0xfb01('0x46')+_0x3fb9ca},'json':!![]})['then'](function(_0xbadf23){if(_0xbadf23&&_0xbadf23[_0xfb01('0x40')][0x0][_0xfb01('0x47')]==='SUCCESS'){var _0x1c89c2=_0xbadf23['data'][0x0][_0xfb01('0x48')];_0x1c89c2['enduserType']=_[_0xfb01('0x49')](_0x304e08[_0xfb01('0x4a')])+'s';return _0x1c89c2;}logger[_0xfb01('0x3e')](_0xfb01('0x4b'),JSON[_0xfb01('0xd')](data));throw new Error('Error:\x20'+JSON[_0xfb01('0xd')](data));})[_0xfb01('0x2e')](function(_0x35f24a){console[_0xfb01('0x4c')](_0xfb01('0x4d'),_0x35f24a);});}function getEndUser(_0x1953ed,_0x3754a3,_0x2c30b9,_0x491f9f,_0x35fcd5,_0x59661c,_0x42d236){var _0x4afe6f={'method':'GET','uri':'','headers':{'Authorization':_0xfb01('0x46')+_0x1953ed},'json':!![]};switch(_0x42d236[_0xfb01('0x4e')]){case _0xfb01('0x4f'):_0x4afe6f['uri']=_0xfb01('0x50')+_0x3754a3+_0xfb01('0x51')+_0x35fcd5+'))';return getZohoUser(_0x4afe6f,'Contacts')['then'](function(_0xafe69a){if(_0xafe69a)return _0xafe69a;_0x4afe6f['uri']=_0xfb01('0x50')+_0x3754a3+_0xfb01('0x52')+_0x35fcd5+'))';return getZohoUser(_0x4afe6f,'Leads')[_0xfb01('0x2b')](function(_0x4262bc){if(_0x4262bc)return _0x4262bc;if(_0x42d236[_0xfb01('0x4a')]!=_0xfb01('0x53')){return createEndUser(_0x1953ed,_0x3754a3,_0x491f9f,_0x35fcd5,_0x59661c,_0x42d236);}else{return{};}});});break;case _0xfb01('0x54'):_0x4afe6f[_0xfb01('0x55')]=_0xfb01('0x50')+_0x3754a3+_0xfb01('0x51')+_0x35fcd5+'))';return getZohoUser(_0x4afe6f,_0xfb01('0x56'))['then'](function(_0x23ff41){if(_0x23ff41)return _0x23ff41;if(_0x42d236['moduleCreate']!=_0xfb01('0x53')){return createEndUser(_0x1953ed,_0x3754a3,_0x491f9f,_0x35fcd5,_0x59661c,_0x42d236);}else{return{};}});break;case _0xfb01('0x57'):_0x4afe6f[_0xfb01('0x55')]='https://www.zohoapis.'+_0x3754a3+_0xfb01('0x52')+_0x35fcd5+'))';return getZohoUser(_0x4afe6f,_0xfb01('0x58'))[_0xfb01('0x2b')](function(_0x35f488){if(_0x35f488)return _0x35f488;if(_0x42d236['moduleCreate']!='nothing'){return createEndUser(_0x1953ed,_0x3754a3,_0x491f9f,_0x35fcd5,_0x59661c,_0x42d236);}else{return{};}});break;}}function getCall(_0x332ba0,_0x45ceca,_0x582638,_0x12a533,_0x69848b,_0x5b45b3,_0x518bd1,_0x53e4f5){logger['info']('Creating\x20new\x20call...');var _0x448f35={};_0x448f35[_0xfb01('0x59')]={'name':!_['isNil'](_0x12a533[_0xfb01('0x43')][_0xfb01('0x19')])&&!_[_0xfb01('0x1d')](_0x12a533['profile'][_0xfb01('0x19')])&&_0x12a533[_0xfb01('0x3a')][_0xfb01('0x19')]==='administrator'?_0x12a533[_0xfb01('0x43')]['name']:!_['isNil'](_0x12a533[_0xfb01('0x44')])?_0x12a533[_0xfb01('0x44')]+'\x20'+_0x12a533[_0xfb01('0x45')]:_0x12a533[_0xfb01('0x45')],'id':_0x12a533['id']};_0x448f35['Subject']=intUtil[_0xfb01('0x5a')](_0x5b45b3[_0xfb01('0x5b')],_0x518bd1,'\x20');_0x448f35[_0xfb01('0x5c')]=intUtil[_0xfb01('0x5a')](_0x5b45b3['Descriptions'],_0x518bd1,'\x0a');if(_0x69848b[_0xfb01('0x41')]===_0xfb01('0x56')){_0x448f35['Who_Id']={'name':!_[_0xfb01('0x1d')](_0x69848b[_0xfb01('0x5d')])?_0x69848b[_0xfb01('0x5d')]:!_[_0xfb01('0x1d')](_0x69848b[_0xfb01('0x5e')])?_0x69848b['First_Name']+'\x20'+_0x69848b[_0xfb01('0x5f')]:_0x69848b[_0xfb01('0x5f')],'id':_0x69848b['id']};}if(_0x69848b['enduserType']===_0xfb01('0x58')){_0x448f35[_0xfb01('0x60')]={'name':!_['isNil'](_0x69848b[_0xfb01('0x5d')])?_0x69848b[_0xfb01('0x5d')]:!_[_0xfb01('0x1d')](_0x69848b['First_Name'])?_0x69848b['First_Name']+'\x20'+_0x69848b[_0xfb01('0x5f')]:_0x69848b[_0xfb01('0x5f')],'id':_0x69848b['id']};_0x448f35['$se_module']=_[_0xfb01('0x49')](_0x69848b[_0xfb01('0x41')]);}if(_0x518bd1[_0xfb01('0x61')]){_0x448f35[_0xfb01('0x62')]=moment[_0xfb01('0x63')](parseInt(_0x518bd1[_0xfb01('0x61')])*0x3e8)[_0xfb01('0x64')](_0xfb01('0x65'));}else if(_0x518bd1[_0xfb01('0x66')]&&_0x518bd1[_0xfb01('0x67')]){_0x448f35[_0xfb01('0x62')]=moment[_0xfb01('0x63')](moment(_0x518bd1[_0xfb01('0x67')],_0xfb01('0x68'))['diff'](moment(_0x518bd1[_0xfb01('0x69')],_0xfb01('0x68'))))[_0xfb01('0x64')](_0xfb01('0x65'));}switch(_0x518bd1[_0xfb01('0x6a')]){case _0xfb01('0x6b'):_0x448f35[_0xfb01('0x6c')]=_0xfb01('0x6d');break;case'complete':case'connect':_0x448f35[_0xfb01('0x6c')]=_0xfb01('0x6e');break;case _0xfb01('0x6f'):_0x448f35[_0xfb01('0x6c')]=_0xfb01('0x70');break;case'abandoned':_0x448f35[_0xfb01('0x6c')]=_0xfb01('0x71');break;case _0xfb01('0x72'):_0x448f35[_0xfb01('0x6c')]=_0xfb01('0x73');default:}_0x448f35[_0xfb01('0x74')]=(_0x53e4f5===_0xfb01('0x75')?moment(_0x518bd1['starttime'])[_0xfb01('0x64')](_0xfb01('0x68')):moment(_0x518bd1[_0xfb01('0x76')])[_0xfb01('0x64')](_0xfb01('0x68')))||moment()[_0xfb01('0x64')](_0xfb01('0x68'));_0x448f35[_0xfb01('0x77')]=_0x53e4f5||'Inbound';_0x448f35=_[_0xfb01('0x78')](_0x448f35,getCustomFields(_0x5b45b3[_0xfb01('0x79')],_0x518bd1));return request({'method':_0xfb01('0x27'),'uri':_0xfb01('0x50')+_0x45ceca+_0xfb01('0x7a'),'headers':{'Authorization':_0xfb01('0x46')+_0x332ba0},'body':{'data':[_0x448f35]},'json':!![]})[_0xfb01('0x2b')](function(_0x53f437){if(_0x53f437&&_0x53f437[_0xfb01('0x40')][0x0][_0xfb01('0x47')]==='SUCCESS'){logger[_0xfb01('0x30')](_0xfb01('0x7b'));return{'id':_0x53f437[_0xfb01('0x40')][0x0][_0xfb01('0x48')]['id']};}})[_0xfb01('0x2e')](function(_0x2cf144){logger['info'](_0xfb01('0x7c'),_0x2cf144[_0xfb01('0x7d')]);console[_0xfb01('0x4c')]('err',_0x2cf144);});}exports[_0xfb01('0x7e')]=function(_0x1e9b45,_0x1b6e3a,_0x3dd083,_0x291926,_0x2958e8,_0x1d40bd){var _0x50aa91,_0x5b502e,_0x19a1e6;_0x1d40bd[_0xfb01('0x7f')]=intUtil[_0xfb01('0x80')](_0x1d40bd[_0xfb01('0x7f')]);_0x1d40bd[_0xfb01('0x81')]=intUtil[_0xfb01('0x80')](_0x1d40bd[_0xfb01('0x81')]);if(_0x2958e8&&_0x2958e8[_0xfb01('0x82')]){logger['info'](_0xfb01('0x83'),_0xfb01('0x84'));_0x1b6e3a[_0xfb01('0x85')]=_0x1d40bd[_0xfb01('0x81')]+'/api/voice/recordings/'+_0x1b6e3a['uniqueid']+_0xfb01('0x86')+md5(_0x1b6e3a[_0xfb01('0x87')]);}else{_0x1b6e3a[_0xfb01('0x85')]='';}var _0x894c50=_0x1d40bd['host']===_0xfb01('0x88')?'eu':_0xfb01('0x89');return getAccessToken(_0x1d40bd)[_0xfb01('0x2b')](function(_0x5bdb85){_0x19a1e6=_0x5bdb85;return getUser(_0x19a1e6,_0x894c50,_0x1d40bd,_0x291926['email']);})['then'](function(_0x15e00b){_0x50aa91=_0x15e00b;logger[_0xfb01('0x30')]('The\x20User\x20ID\x20is:',_0x50aa91['id']);return getEndUser(_0x19a1e6,_0x894c50,_0x1d40bd,_0x1b6e3a['calleridname'],_0x1b6e3a[_0xfb01('0x8a')],_0x50aa91,_0x3dd083);})['then'](function(_0x164cda){_0x5b502e=_0x164cda;return getCall(_0x19a1e6,_0x894c50,_0x1d40bd,_0x50aa91,_0x5b502e,_0x3dd083,_0x1b6e3a,_0xfb01('0x8b'));})['then'](function(_0x2600d7){if(_0x2600d7){logger['info'](_0xfb01('0x8c'),_0x2600d7['id']);logger[_0xfb01('0x30')](_0xfb01('0x83'),_0xfb01('0x8d'));emit(util[_0xfb01('0x64')](_0xfb01('0x8e'),_0x291926['name']),_0xfb01('0x8f'),{'uri':_0xfb01('0x90')+_0x1d40bd[_0xfb01('0x7f')]+'/crm/EntityInfo.do?module=Calls&id='+_0x2600d7['id']});}})['catch'](function(_0x557b63){logger[_0xfb01('0x3e')]('[QUEUE]',JSON[_0xfb01('0xd')](_0x557b63));});};exports[_0xfb01('0x75')]=function(_0x18a8b1,_0x243d65,_0xfc7949,_0x158e68,_0x5a48ff,_0x43293a,_0x2dda9d){var _0x5d7a87,_0x4d9eef,_0x36ac68;_0x43293a['host']=intUtil[_0xfb01('0x80')](_0x43293a[_0xfb01('0x7f')]);_0x43293a['serverUrl']=intUtil[_0xfb01('0x80')](_0x43293a[_0xfb01('0x81')]);if(_0x2dda9d&&_0x2dda9d[_0xfb01('0x91')]&&_0x2dda9d['recordingFormat']!==_0xfb01('0x92')){logger['info'](_0xfb01('0x93'),'Recording\x20is\x20enabled!');_0x243d65[_0xfb01('0x85')]=_0x43293a[_0xfb01('0x81')]+_0xfb01('0x94')+_0x243d65[_0xfb01('0x87')]+_0xfb01('0x86')+md5(_0x243d65[_0xfb01('0x87')]);}var _0x266671=_0x43293a['host']===_0xfb01('0x88')?'eu':_0xfb01('0x89');return getAccessToken(_0x43293a)[_0xfb01('0x2b')](function(_0x50bc4d){_0x36ac68=_0x50bc4d;return getUser(_0x36ac68,_0x266671,_0x43293a,_0x158e68[_0xfb01('0x38')]);})['then'](function(_0x45c0c1){_0x5d7a87=_0x45c0c1;logger['info'](_0xfb01('0x95'),_0x5d7a87['id']);return getEndUser(_0x36ac68,_0x266671,_0x43293a,_0x243d65[_0xfb01('0x96')],_0x243d65[_0xfb01('0x97')],_0x5d7a87,_0xfc7949);})['then'](function(_0x12c07c){_0x4d9eef=_0x12c07c;return getCall(_0x36ac68,_0x266671,_0x43293a,_0x5d7a87,_0x4d9eef,_0xfc7949,_0x243d65,_0xfb01('0x98'));})[_0xfb01('0x2b')](function(_0x4035a3){if(_0x4035a3){logger['info'](_0xfb01('0x8c'),_0x4035a3['id']);logger[_0xfb01('0x30')]('[OUTBOUND]','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xfb01('0x64')](_0xfb01('0x8e'),_0x158e68[_0xfb01('0x19')]),_0xfb01('0x8f'),{'uri':_0xfb01('0x90')+_0x43293a[_0xfb01('0x7f')]+'/crm/EntityInfo.do?module=Calls&id='+_0x4035a3['id']});}})[_0xfb01('0x2e')](function(_0x14d496){logger[_0xfb01('0x3e')]('[OUTBOUND]',JSON[_0xfb01('0xd')](_0x14d496));});};exports['unmanaged']=function(_0xa2c2e9,_0x2af4dc,_0x31b5d7,_0x2e02d5,_0x43d8d5,_0x12a242){var _0x65431d,_0x25687a,_0x757ec;_0x12a242[_0xfb01('0x7f')]=intUtil[_0xfb01('0x80')](_0x12a242[_0xfb01('0x7f')]);_0x12a242['serverUrl']=intUtil[_0xfb01('0x80')](_0x12a242[_0xfb01('0x81')]);if(_0x43d8d5&&_0x43d8d5['monitor_format']){logger[_0xfb01('0x30')]('['+_0x2af4dc[_0xfb01('0x6a')][_0xfb01('0x99')]()+']',_0xfb01('0x84'));_0x2af4dc[_0xfb01('0x85')]=_0x12a242[_0xfb01('0x81')]+_0xfb01('0x94')+_0x2af4dc[_0xfb01('0x87')]+'/downloads?type=uniqueid&token='+md5(_0x2af4dc[_0xfb01('0x87')]);}else{_0x2af4dc[_0xfb01('0x85')]='';}var _0x40712e=_0x12a242[_0xfb01('0x7f')]===_0xfb01('0x88')?'eu':'com';return getAccessToken(_0x12a242)['then'](function(_0x1e0b93){_0x757ec=_0x1e0b93;return getUser(_0x757ec,_0x40712e,_0x12a242);})[_0xfb01('0x2b')](function(_0x21c8fc){_0x65431d=_0x21c8fc;logger[_0xfb01('0x30')](_0xfb01('0x95'),_0x65431d['id']);return getEndUser(_0x757ec,_0x40712e,_0x12a242,_0x2af4dc['calleridname'],_0x2af4dc[_0xfb01('0x8a')],_0x65431d,_0x31b5d7);})[_0xfb01('0x2b')](function(_0xf48197){_0x25687a=_0xf48197;return getCall(_0x757ec,_0x40712e,_0x12a242,_0x65431d,_0x25687a,_0x31b5d7,_0x2af4dc,_0xfb01('0x8b'));})[_0xfb01('0x2b')](function(_0x4f67f5){if(_0x4f67f5){logger[_0xfb01('0x30')](_0xfb01('0x8c'),_0x4f67f5['id']);}})[_0xfb01('0x2e')](function(_0x74df49){logger[_0xfb01('0x3e')]('['+_0x2af4dc[_0xfb01('0x6a')]['toUpperCase']()+']',JSON[_0xfb01('0xd')](_0x74df49));});};