Built motion from commit 9c91e9f5.|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 _0x938c=['/crm/EntityInfo.do?module=Calls&id=','recordingFormat','none','[OUTBOUND]','com','destcalleridname','destcalleridnum','Outbound','unmanaged','monitor_format','lastevent','toUpperCase','Inbound','lodash','request-promise','util','./util','ioredis','bluebird','../../../../config/environment','../../../../config/logger','zoho','redis','localhost','debug','[HTTP]','stringify','forEach','includes','string','type','idField','toString','variableName','customVariable','Variable','name','toLowerCase','indexOf','isNil','access_token','expires_in','zone','https://accounts.zoho.com','https://accounts.zoho.eu','https://accounts.zoho.com.cn','POST','/oauth/v2/token','clientId','clientSecret','refresh_token','add','seconds','error','stack','info','Search\x20user','GET','format','https://www.zohoapis.%s/crm/v2/users','ActiveUsers','Zoho-oauthtoken\x20','then','users','isArrayLikeObject','findIndex','email','Agent\x20found!','Using\x20the\x20admin\x20account!','Administrator','user','profile','Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20','catch','enduserType','https://www.zohoapis.','/crm/v2/','startCase','moduleCreate','role','first_name','last_name','code','data','details','The\x20failing\x20result\x20is','CREATE\x20ERROR','uri','/crm/v2/Contacts/search?criteria=((Phone:equals:','Contacts','/crm/v2/Leads/search?criteria=((Phone:equals:','nothing','contact','Leads','Creating\x20new\x20call...','Owner','administrator','Subject','Subjects','Description','getString','Descriptions','Who_Id','Full_Name','First_Name','Last_Name','What_Id','$se_module','talktime','Call_Duration','mm:ss','answertime','endtime','utc','diff','starttime','YYYY-MM-DDTHH:mm:ss','called','Call_Result','Called','complete','Answered','Rejected','abandoned','Abandoned','Timeout','Call_Start_Time','outbound','agentcalledAt','Call_Type','merge','/crm/v2/Calls','err','log','queue','host','stripTrailingSlash','serverUrl','[QUEUE]','Recording\x20is\x20enabled!','/api/voice/recordings/','uniqueid','/downloads?type=uniqueid&token=','recordingURL','zoho.eu','The\x20User\x20ID\x20is:','calleridnum','The\x20Call\x20ID\x20is:','Displaying\x20call\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','https://crm.'];(function(_0x33d9c5,_0x2c159d){var _0x28f547=function(_0x61fc92){while(--_0x61fc92){_0x33d9c5['push'](_0x33d9c5['shift']());}};_0x28f547(++_0x2c159d);}(_0x938c,0x1d5));var _0xc938=function(_0x86fd2b,_0x4eb13b){_0x86fd2b=_0x86fd2b-0x0;var _0x3cd0dc=_0x938c[_0x86fd2b];return _0x3cd0dc;};'use strict';var _=require(_0xc938('0x0'));var rp=require(_0xc938('0x1'));var md5=require('md5');var util=require(_0xc938('0x2'));var intUtil=require(_0xc938('0x3'));var moment=require('moment');var Redis=require(_0xc938('0x4'));var BPromise=require(_0xc938('0x5'));var config=require(_0xc938('0x6'));var logger=require(_0xc938('0x7'))(_0xc938('0x8'));config[_0xc938('0x9')]=_['defaults'](config[_0xc938('0x9')],{'host':_0xc938('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function emit(_0x4751bc,_0x4fe7d6,_0x5c558c){io['to'](_0x4751bc)['emit'](_0x4fe7d6,_0x5c558c);}function request(_0x57c5e1){logger[_0xc938('0xb')](_0xc938('0xc'),JSON[_0xc938('0xd')](_0x57c5e1));return rp(_0x57c5e1);}function getCustomFields(_0x3911f7,_0x15aa16){var _0x193eb7={};if(_0x3911f7['length']>0x0){_[_0xc938('0xe')](_0x3911f7,function(_0x4f1f64){if(_[_0xc938('0xf')]([_0xc938('0x10'),'picklist'],_0x4f1f64[_0xc938('0x11')])&&_0x4f1f64[_0xc938('0x12')]){_0x193eb7[_0x4f1f64['idField']]=_0x4f1f64['content'][_0xc938('0x13')]();}else if(_0x4f1f64[_0xc938('0x11')]==='variable'&&_0x4f1f64[_0xc938('0x14')]&&_0x4f1f64[_0xc938('0x12')]&&_0x15aa16[_0x4f1f64['variableName']]){_0x193eb7[_0x4f1f64['idField']]=_0x15aa16[_0x4f1f64['variableName']][_0xc938('0x13')]();}else if(_0x4f1f64['type']===_0xc938('0x15')&&_0x4f1f64[_0xc938('0x16')]&&_0x4f1f64[_0xc938('0x16')][_0xc938('0x17')]&&_0x4f1f64[_0xc938('0x12')]&&_0x15aa16[_0x4f1f64[_0xc938('0x16')]['name'][_0xc938('0x18')]()]){_0x193eb7[_0x4f1f64['idField']]=_0x15aa16[_0x4f1f64[_0xc938('0x16')][_0xc938('0x17')][_0xc938('0x18')]()]['toString']();}});}return _0x193eb7;}function getName(_0xd0d89e){if(_0xd0d89e[_0xc938('0x19')]('\x20')>0x0){var _0x20f1e2=_0xd0d89e['split'](/ (.+)/);if(_0x20f1e2[0x1]){return _0x20f1e2;}}return[_0xd0d89e,_0xd0d89e];}var accountsTokens={};function getAccessToken(_0x42671a){return new Promise(function(_0x41c257,_0x2813f6){if(!_[_0xc938('0x1a')](accountsTokens[_0x42671a['id']])&&!_[_0xc938('0x1a')](accountsTokens[_0x42671a['id']][_0xc938('0x1b')])){if(moment()['isBefore'](accountsTokens[_0x42671a['id']][_0xc938('0x1c')])){_0x41c257(accountsTokens[_0x42671a['id']][_0xc938('0x1b')]);}}var _0x661964;switch(_0x42671a[_0xc938('0x1d')]){case'US':_0x661964=_0xc938('0x1e');break;case'AU':_0x661964='https://accounts.zoho.com.au';break;case'EU':_0x661964=_0xc938('0x1f');break;case'IN':_0x661964='https://accounts.zoho.in';break;case'CN':_0x661964=_0xc938('0x20');break;default:_0x661964=_0xc938('0x1f');break;}var _0x29a23c={'method':_0xc938('0x21'),'uri':_0x661964+_0xc938('0x22'),'qs':{'refresh_token':_0x42671a['refreshToken'],'client_id':_0x42671a[_0xc938('0x23')],'client_secret':_0x42671a[_0xc938('0x24')],'grant_type':_0xc938('0x25')},'json':!![]};return rp(_0x29a23c)['then'](function(_0x1268c9){accountsTokens[_0x42671a['id']]={'access_token':_0x1268c9[_0xc938('0x1b')],'expires_in':moment()[_0xc938('0x26')](_0x1268c9['expires_in'],_0xc938('0x27'))};_0x41c257(_0x1268c9[_0xc938('0x1b')]);})['catch'](function(_0x2f22f6){logger[_0xc938('0x28')]('Failing\x20creating\x20the\x20access_token',_0x2f22f6[_0xc938('0x29')]);_0x2813f6(_0x2f22f6);});});}function getUser(_0x212db6,_0x26b56d,_0x11adff,_0x25fbbb){logger[_0xc938('0x2a')](_0xc938('0x2b'));return request({'method':_0xc938('0x2c'),'uri':util[_0xc938('0x2d')](_0xc938('0x2e'),_0x26b56d),'qs':{'type':_0xc938('0x2f')},'headers':{'Authorization':_0xc938('0x30')+_0x212db6},'json':!![]})[_0xc938('0x31')](function(_0x575158){if(_0x575158[_0xc938('0x32')]){var _0x3e46ac=-0x1;if(_[_0xc938('0x33')](_0x575158[_0xc938('0x32')])){if(!_[_0xc938('0x1a')](_0x25fbbb)){_0x3e46ac=_[_0xc938('0x34')](_0x575158[_0xc938('0x32')],function(_0x356e28){return _0x356e28[_0xc938('0x35')]===_0x25fbbb;});}if(_0x3e46ac>=0x0){logger['info'](_0xc938('0x36'));}else{logger['info'](_0xc938('0x37'));_0x3e46ac=_[_0xc938('0x34')](_0x575158[_0xc938('0x32')],function(_0x2d20a5){return _0x2d20a5['profile'][_0xc938('0x17')]===_0xc938('0x38');});}return _0x575158['users'][_0x3e46ac];}else{if(_0x575158[_0xc938('0x39')][_0xc938('0x3a')]['name']===_0xc938('0x38')){logger[_0xc938('0x2a')](_0xc938('0x37'));user=_0x575158[_0xc938('0x39')];return user;}else{logger[_0xc938('0x28')]('The\x20failing\x20result\x20is',JSON[_0xc938('0xd')](_0x575158));throw new Error(_0xc938('0x3b')+JSON[_0xc938('0xd')](_0x575158));}}}else{logger['error']('The\x20failing\x20result\x20is',JSON['stringify'](_0x575158));throw new Error('Unable\x20to\x20retrieve\x20zoho\x20account\x20users:\x20'+JSON[_0xc938('0xd')](_0x575158));}})[_0xc938('0x3c')](function(_0x360212){console[_0xc938('0x28')](_0x360212);});}function getZohoUser(_0x499dfb,_0xb31bfc){return new BPromise(function(_0x561dbf,_0x538ec9){request(_0x499dfb)[_0xc938('0x31')](function(_0x13663e){var _0x5ab6a4=null;if(_0x13663e){_0x5ab6a4=_0x13663e['data'][0x0];_0x5ab6a4[_0xc938('0x3d')]=_0xb31bfc;}_0x561dbf(_0x5ab6a4);})[_0xc938('0x3c')](function(_0x103464){_0x538ec9(_0x103464);});});}function createEndUser(_0x2da753,_0x1806b5,_0x41598b,_0x568785,_0x46fbcd,_0x4f975b){var _0x41598b=getName(_0x41598b);return request({'method':_0xc938('0x21'),'uri':_0xc938('0x3e')+_0x1806b5+_0xc938('0x3f')+_[_0xc938('0x40')](_0x4f975b[_0xc938('0x41')])+'s','body':{'data':[{'Last_Name':_0x41598b[0x1],'First_Name':_0x41598b[0x0],'Phone':_0x568785,'Owner':{'name':!_[_0xc938('0x1a')](_0x46fbcd['role'][_0xc938('0x17')])?_0x46fbcd[_0xc938('0x42')][_0xc938('0x17')]:!_[_0xc938('0x1a')](_0x46fbcd[_0xc938('0x43')])?_0x46fbcd[_0xc938('0x43')]+'\x20'+_0x46fbcd[_0xc938('0x44')]:_0x46fbcd[_0xc938('0x44')],'id':_0x46fbcd['id']}}]},'headers':{'Authorization':_0xc938('0x30')+_0x2da753},'json':!![]})['then'](function(_0x43dd70){if(_0x43dd70&&_0x43dd70['data'][0x0][_0xc938('0x45')]==='SUCCESS'){var _0x23a61a=_0x43dd70[_0xc938('0x46')][0x0][_0xc938('0x47')];_0x23a61a[_0xc938('0x3d')]=_[_0xc938('0x40')](_0x4f975b[_0xc938('0x41')])+'s';return _0x23a61a;}logger['error'](_0xc938('0x48'),JSON['stringify'](data));throw new Error('Error:\x20'+JSON[_0xc938('0xd')](data));})[_0xc938('0x3c')](function(_0xcb35e7){console['log'](_0xc938('0x49'),_0xcb35e7);});}function getEndUser(_0xb6316,_0x39c8aa,_0x295d4b,_0x155e2e,_0x32f59a,_0x10e25d,_0x4ef164){var _0x2f0218={'method':_0xc938('0x2c'),'uri':'','headers':{'Authorization':_0xc938('0x30')+_0xb6316},'json':!![]};switch(_0x4ef164['moduleSearch']){case'contact_lead':_0x2f0218[_0xc938('0x4a')]='https://www.zohoapis.'+_0x39c8aa+_0xc938('0x4b')+_0x32f59a+'))';return getZohoUser(_0x2f0218,_0xc938('0x4c'))[_0xc938('0x31')](function(_0x2863f3){if(_0x2863f3)return _0x2863f3;_0x2f0218[_0xc938('0x4a')]=_0xc938('0x3e')+_0x39c8aa+_0xc938('0x4d')+_0x32f59a+'))';return getZohoUser(_0x2f0218,'Leads')[_0xc938('0x31')](function(_0x5d3576){if(_0x5d3576)return _0x5d3576;if(_0x4ef164[_0xc938('0x41')]!=_0xc938('0x4e')){return createEndUser(_0xb6316,_0x39c8aa,_0x155e2e,_0x32f59a,_0x10e25d,_0x4ef164);}else{return{};}});});break;case _0xc938('0x4f'):_0x2f0218[_0xc938('0x4a')]='https://www.zohoapis.'+_0x39c8aa+_0xc938('0x4b')+_0x32f59a+'))';return getZohoUser(_0x2f0218,_0xc938('0x4c'))[_0xc938('0x31')](function(_0x370ac8){if(_0x370ac8)return _0x370ac8;if(_0x4ef164[_0xc938('0x41')]!=_0xc938('0x4e')){return createEndUser(_0xb6316,_0x39c8aa,_0x155e2e,_0x32f59a,_0x10e25d,_0x4ef164);}else{return{};}});break;case'lead':_0x2f0218['uri']='https://www.zohoapis.'+_0x39c8aa+_0xc938('0x4d')+_0x32f59a+'))';return getZohoUser(_0x2f0218,_0xc938('0x50'))[_0xc938('0x31')](function(_0x4205ef){if(_0x4205ef)return _0x4205ef;if(_0x4ef164['moduleCreate']!=_0xc938('0x4e')){return createEndUser(_0xb6316,_0x39c8aa,_0x155e2e,_0x32f59a,_0x10e25d,_0x4ef164);}else{return{};}});break;}}function getCall(_0x4df6c4,_0x49a95c,_0x3ab583,_0x1312d5,_0x20a273,_0x5bebfe,_0x48d5cb,_0x2f6dfa){logger[_0xc938('0x2a')](_0xc938('0x51'));var _0x5daa70={};_0x5daa70[_0xc938('0x52')]={'name':!_[_0xc938('0x1a')](_0x1312d5[_0xc938('0x42')][_0xc938('0x17')])&&!_['isNil'](_0x1312d5[_0xc938('0x3a')][_0xc938('0x17')])&&_0x1312d5[_0xc938('0x3a')][_0xc938('0x17')]===_0xc938('0x53')?_0x1312d5[_0xc938('0x42')][_0xc938('0x17')]:!_[_0xc938('0x1a')](_0x1312d5['first_name'])?_0x1312d5[_0xc938('0x43')]+'\x20'+_0x1312d5[_0xc938('0x44')]:_0x1312d5['last_name'],'id':_0x1312d5['id']};_0x5daa70[_0xc938('0x54')]=intUtil['getString'](_0x5bebfe[_0xc938('0x55')],_0x48d5cb,'\x20');_0x5daa70[_0xc938('0x56')]=intUtil[_0xc938('0x57')](_0x5bebfe[_0xc938('0x58')],_0x48d5cb,'\x0a');if(_0x20a273[_0xc938('0x3d')]==='Contacts'){_0x5daa70[_0xc938('0x59')]={'name':!_['isNil'](_0x20a273[_0xc938('0x5a')])?_0x20a273[_0xc938('0x5a')]:!_['isNil'](_0x20a273[_0xc938('0x5b')])?_0x20a273[_0xc938('0x5b')]+'\x20'+_0x20a273[_0xc938('0x5c')]:_0x20a273[_0xc938('0x5c')],'id':_0x20a273['id']};}if(_0x20a273[_0xc938('0x3d')]===_0xc938('0x50')){_0x5daa70[_0xc938('0x5d')]={'name':!_[_0xc938('0x1a')](_0x20a273[_0xc938('0x5a')])?_0x20a273['Full_Name']:!_[_0xc938('0x1a')](_0x20a273[_0xc938('0x5b')])?_0x20a273[_0xc938('0x5b')]+'\x20'+_0x20a273[_0xc938('0x5c')]:_0x20a273[_0xc938('0x5c')],'id':_0x20a273['id']};_0x5daa70[_0xc938('0x5e')]=_[_0xc938('0x40')](_0x20a273[_0xc938('0x3d')]);}if(_0x48d5cb[_0xc938('0x5f')]){_0x5daa70[_0xc938('0x60')]=moment['utc'](parseInt(_0x48d5cb[_0xc938('0x5f')])*0x3e8)[_0xc938('0x2d')](_0xc938('0x61'));}else if(_0x48d5cb[_0xc938('0x62')]&&_0x48d5cb[_0xc938('0x63')]){_0x5daa70[_0xc938('0x60')]=moment[_0xc938('0x64')](moment(_0x48d5cb['endtime'],'YYYY-MM-DDTHH:mm:ss')[_0xc938('0x65')](moment(_0x48d5cb[_0xc938('0x66')],_0xc938('0x67'))))[_0xc938('0x2d')]('mm:ss');}switch(_0x48d5cb['lastevent']){case _0xc938('0x68'):_0x5daa70[_0xc938('0x69')]=_0xc938('0x6a');break;case _0xc938('0x6b'):case'connect':_0x5daa70['Call_Result']=_0xc938('0x6c');break;case'rejected':_0x5daa70[_0xc938('0x69')]=_0xc938('0x6d');break;case _0xc938('0x6e'):_0x5daa70[_0xc938('0x69')]=_0xc938('0x6f');break;case'timeout':_0x5daa70['Call_Result']=_0xc938('0x70');default:}_0x5daa70[_0xc938('0x71')]=(_0x2f6dfa===_0xc938('0x72')?moment(_0x48d5cb[_0xc938('0x66')])[_0xc938('0x2d')]('YYYY-MM-DDTHH:mm:ss'):moment(_0x48d5cb[_0xc938('0x73')])[_0xc938('0x2d')](_0xc938('0x67')))||moment()[_0xc938('0x2d')](_0xc938('0x67'));_0x5daa70[_0xc938('0x74')]=_0x2f6dfa||'Inbound';_0x5daa70=_[_0xc938('0x75')](_0x5daa70,getCustomFields(_0x5bebfe['Fields'],_0x48d5cb));return request({'method':'POST','uri':_0xc938('0x3e')+_0x49a95c+_0xc938('0x76'),'headers':{'Authorization':_0xc938('0x30')+_0x4df6c4},'body':{'data':[_0x5daa70]},'json':!![]})[_0xc938('0x31')](function(_0x28a996){if(_0x28a996&&_0x28a996['data'][0x0][_0xc938('0x45')]==='SUCCESS'){logger['info']('Call\x20created!');return{'id':_0x28a996[_0xc938('0x46')][0x0][_0xc938('0x47')]['id']};}})[_0xc938('0x3c')](function(_0x349fdc){logger[_0xc938('0x2a')](_0xc938('0x77'),_0x349fdc[_0xc938('0x29')]);console[_0xc938('0x78')](_0xc938('0x77'),_0x349fdc);});}exports[_0xc938('0x79')]=function(_0x3cdd03,_0x3a0b55,_0x5bdf37,_0x229025,_0x70fb50,_0x2b085f){var _0x261267,_0x13b651,_0x6bbcfc;_0x2b085f[_0xc938('0x7a')]=intUtil[_0xc938('0x7b')](_0x2b085f['host']);_0x2b085f[_0xc938('0x7c')]=intUtil[_0xc938('0x7b')](_0x2b085f['serverUrl']);if(_0x70fb50&&_0x70fb50['monitor_format']){logger[_0xc938('0x2a')](_0xc938('0x7d'),_0xc938('0x7e'));_0x3a0b55['recordingURL']=_0x2b085f[_0xc938('0x7c')]+_0xc938('0x7f')+_0x3a0b55[_0xc938('0x80')]+_0xc938('0x81')+md5(_0x3a0b55[_0xc938('0x80')]);}else{_0x3a0b55[_0xc938('0x82')]='';}var _0x4f6c44=_0x2b085f[_0xc938('0x7a')]===_0xc938('0x83')?'eu':'com';return getAccessToken(_0x2b085f)[_0xc938('0x31')](function(_0x259e03){_0x6bbcfc=_0x259e03;return getUser(_0x6bbcfc,_0x4f6c44,_0x2b085f,_0x229025['email']);})[_0xc938('0x31')](function(_0x2c0350){_0x261267=_0x2c0350;logger['info'](_0xc938('0x84'),_0x261267['id']);return getEndUser(_0x6bbcfc,_0x4f6c44,_0x2b085f,_0x3a0b55['calleridname'],_0x3a0b55[_0xc938('0x85')],_0x261267,_0x5bdf37);})[_0xc938('0x31')](function(_0x43f2c9){_0x13b651=_0x43f2c9;return getCall(_0x6bbcfc,_0x4f6c44,_0x2b085f,_0x261267,_0x13b651,_0x5bdf37,_0x3a0b55,'Inbound');})[_0xc938('0x31')](function(_0x41fcfe){if(_0x41fcfe){logger[_0xc938('0x2a')](_0xc938('0x86'),_0x41fcfe['id']);logger[_0xc938('0x2a')]('[QUEUE]',_0xc938('0x87'));emit(util['format'](_0xc938('0x88'),_0x229025[_0xc938('0x17')]),_0xc938('0x89'),{'uri':_0xc938('0x8a')+_0x2b085f[_0xc938('0x7a')]+_0xc938('0x8b')+_0x41fcfe['id']});}})[_0xc938('0x3c')](function(_0x224b7d){logger[_0xc938('0x28')](_0xc938('0x7d'),JSON['stringify'](_0x224b7d));});};exports[_0xc938('0x72')]=function(_0x18be72,_0x13a460,_0x948c2,_0x2277a9,_0x4b51bc,_0x107e9d,_0x5c85ba){var _0x5e4282,_0x307348,_0x3ff88d;_0x107e9d['host']=intUtil[_0xc938('0x7b')](_0x107e9d[_0xc938('0x7a')]);_0x107e9d[_0xc938('0x7c')]=intUtil['stripTrailingSlash'](_0x107e9d[_0xc938('0x7c')]);if(_0x5c85ba&&_0x5c85ba[_0xc938('0x8c')]&&_0x5c85ba[_0xc938('0x8c')]!==_0xc938('0x8d')){logger[_0xc938('0x2a')](_0xc938('0x8e'),_0xc938('0x7e'));_0x13a460[_0xc938('0x82')]=_0x107e9d[_0xc938('0x7c')]+_0xc938('0x7f')+_0x13a460[_0xc938('0x80')]+_0xc938('0x81')+md5(_0x13a460[_0xc938('0x80')]);}var _0x9bf376=_0x107e9d[_0xc938('0x7a')]===_0xc938('0x83')?'eu':_0xc938('0x8f');return getAccessToken(_0x107e9d)[_0xc938('0x31')](function(_0x43c742){_0x3ff88d=_0x43c742;return getUser(_0x3ff88d,_0x9bf376,_0x107e9d,_0x2277a9['email']);})[_0xc938('0x31')](function(_0x1c4d89){_0x5e4282=_0x1c4d89;logger[_0xc938('0x2a')]('The\x20User\x20ID\x20is:',_0x5e4282['id']);return getEndUser(_0x3ff88d,_0x9bf376,_0x107e9d,_0x13a460[_0xc938('0x90')],_0x13a460[_0xc938('0x91')],_0x5e4282,_0x948c2);})[_0xc938('0x31')](function(_0x4e2f59){_0x307348=_0x4e2f59;return getCall(_0x3ff88d,_0x9bf376,_0x107e9d,_0x5e4282,_0x307348,_0x948c2,_0x13a460,_0xc938('0x92'));})[_0xc938('0x31')](function(_0x3489c8){if(_0x3489c8){logger[_0xc938('0x2a')](_0xc938('0x86'),_0x3489c8['id']);logger[_0xc938('0x2a')](_0xc938('0x8e'),_0xc938('0x87'));emit(util['format'](_0xc938('0x88'),_0x2277a9[_0xc938('0x17')]),_0xc938('0x89'),{'uri':_0xc938('0x8a')+_0x107e9d[_0xc938('0x7a')]+_0xc938('0x8b')+_0x3489c8['id']});}})[_0xc938('0x3c')](function(_0x244bcc){logger['error']('[OUTBOUND]',JSON[_0xc938('0xd')](_0x244bcc));});};exports[_0xc938('0x93')]=function(_0x199826,_0x36a243,_0x511729,_0x5c1565,_0x403335,_0xe0e7d7){var _0xb1fefa,_0x5bd118,_0x48908e;_0xe0e7d7[_0xc938('0x7a')]=intUtil[_0xc938('0x7b')](_0xe0e7d7[_0xc938('0x7a')]);_0xe0e7d7['serverUrl']=intUtil[_0xc938('0x7b')](_0xe0e7d7[_0xc938('0x7c')]);if(_0x403335&&_0x403335[_0xc938('0x94')]){logger[_0xc938('0x2a')]('['+_0x36a243[_0xc938('0x95')][_0xc938('0x96')]()+']',_0xc938('0x7e'));_0x36a243['recordingURL']=_0xe0e7d7[_0xc938('0x7c')]+_0xc938('0x7f')+_0x36a243[_0xc938('0x80')]+'/downloads?type=uniqueid&token='+md5(_0x36a243[_0xc938('0x80')]);}else{_0x36a243['recordingURL']='';}var _0x3448c3=_0xe0e7d7[_0xc938('0x7a')]==='zoho.eu'?'eu':_0xc938('0x8f');return getAccessToken(_0xe0e7d7)[_0xc938('0x31')](function(_0x454ac8){_0x48908e=_0x454ac8;return getUser(_0x48908e,_0x3448c3,_0xe0e7d7);})[_0xc938('0x31')](function(_0x2a38e8){_0xb1fefa=_0x2a38e8;logger[_0xc938('0x2a')](_0xc938('0x84'),_0xb1fefa['id']);return getEndUser(_0x48908e,_0x3448c3,_0xe0e7d7,_0x36a243['calleridname'],_0x36a243[_0xc938('0x85')],_0xb1fefa,_0x511729);})[_0xc938('0x31')](function(_0x4d7dd7){_0x5bd118=_0x4d7dd7;return getCall(_0x48908e,_0x3448c3,_0xe0e7d7,_0xb1fefa,_0x5bd118,_0x511729,_0x36a243,_0xc938('0x97'));})[_0xc938('0x31')](function(_0xedc904){if(_0xedc904){logger[_0xc938('0x2a')](_0xc938('0x86'),_0xedc904['id']);}})[_0xc938('0x3c')](function(_0x39611b){logger[_0xc938('0x28')]('['+_0x36a243[_0xc938('0x95')][_0xc938('0x96')]()+']',JSON[_0xc938('0xd')](_0x39611b));});};