Built motion from commit fe909640.|2.6.8
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 7a56695..457faff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa6c6=['Contact\x20found:','Contact\x20created:','POST','/api/contacts','format','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','Creating\x20new\x20task','/api/tasks','getString','Subjects','Descriptions','YYYY-MM-DDTHH:mm:ss','add','ticketId','Task\x20created:','/contacts/','user:%s','emit','remoteUri','stripTrailingSlash','serverUrl','username','toLowerCase','outbound','destcalleridnum','calleridnum','callDirection','queue','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','none','recordingURL','unmanaged','Displaying\x20task\x20in\x20a\x20new\x20tab...','inspect','lodash','request-promise','md5','util','moment','bluebird','ioredis','./util','../../../../config/environment','../../../../config/logger','freshsales','redis','localhost','socket.io-emitter','headers','info','users','length','email','adminEmail','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','catch','error','toUpperCase','message','GET','/api/selector/owners','then','agentEmail','Getting\x20user\x20with\x20email','userEmail','User\x20found:','userId','Admin\x20selected','/api/contacts/filters','Getting\x20contacts\x20filter','filters','name','All\x20Contacts','Getting\x20contact\x20list','/api/contacts/view/','Searching\x20contact\x20with\x20phone','contacts','find','work_number','contactNumber','mobile_number','endUserId'];(function(_0x2b7764,_0x2606f1){var _0x848dcb=function(_0x1ae85b){while(--_0x1ae85b){_0x2b7764['push'](_0x2b7764['shift']());}};_0x848dcb(++_0x2606f1);}(_0xa6c6,0x12e));var _0x6a6c=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xa6c6[_0x2641f9];return _0x585741;};'use strict';var _=require(_0x6a6c('0x0'));var rp=require(_0x6a6c('0x1'));var md5=require(_0x6a6c('0x2'));var util=require(_0x6a6c('0x3'));var moment=require(_0x6a6c('0x4'));var Promise=require(_0x6a6c('0x5'));var Redis=require(_0x6a6c('0x6'));var intUtil=require(_0x6a6c('0x7'));var config=require(_0x6a6c('0x8'));var logger=require(_0x6a6c('0x9'))(_0x6a6c('0xa'));config[_0x6a6c('0xb')]=_['defaults'](config[_0x6a6c('0xb')],{'host':_0x6a6c('0xc'),'port':0x18eb});var io=require(_0x6a6c('0xd'))(new Redis(config['redis']));function getAdminId(_0x282b0c,_0x1e7f00,_0x54a3f0,_0x51acdc){return new Promise(function(_0x891302,_0xbeac5){var _0xb92990=![];var _0x1069a1={'method':'GET','uri':_0x51acdc+'/api/selector/owners','json':!![]};_0x1069a1[_0x6a6c('0xe')]=_0x54a3f0;logger[_0x6a6c('0xf')]('Getting\x20admin\x20information');return rp(_0x1069a1)['then'](function(_0x2956e2){if(_0x2956e2){var _0x37b464=_0x2956e2[_0x6a6c('0x10')];var _0x41b08e=null;for(_0x41b08e=0x0;_0x41b08e<_0x37b464[_0x6a6c('0x11')];_0x41b08e++){if(_0x37b464[_0x41b08e][_0x6a6c('0x12')]===_0x282b0c[_0x6a6c('0x13')]){_0x282b0c[_0x6a6c('0x14')]=_0x37b464[_0x41b08e]['id'];_0xb92990=!![];}}if(_0xb92990){logger[_0x6a6c('0xf')](_0x6a6c('0x15'),_0x282b0c[_0x6a6c('0x14')]);_0x891302(_0x282b0c);}else{_0xbeac5({'statusCode':0x194,'message':_0x6a6c('0x16')});}}else{_0xbeac5({'statusCode':0x194,'message':_0x6a6c('0x16')});}})[_0x6a6c('0x17')](function(_0x4eddb5){logger[_0x6a6c('0x18')]('['+[_0x1e7f00[_0x6a6c('0x19')]()]+']',_0x4eddb5[_0x6a6c('0x1a')]);_0xbeac5(_0x4eddb5);});});}function getUser(_0x55d2c2,_0x1aba56,_0x46841c){return function(_0x271009){return new Promise(function(_0x1720e2,_0x41b93c){var _0x3becc1={'method':_0x6a6c('0x1b'),'uri':_0x46841c+_0x6a6c('0x1c'),'json':!![]};_0x3becc1[_0x6a6c('0xe')]=_0x1aba56;logger[_0x6a6c('0xf')]('Getting\x20user\x20list');return rp(_0x3becc1)[_0x6a6c('0x1d')](function(_0x324f59){if(_0x324f59){var _0x1f2394=_0x324f59[_0x6a6c('0x10')];var _0x51f9c5=![];var _0x192f72=null;if(_0x271009[_0x6a6c('0x1e')]!==null){logger[_0x6a6c('0xf')](_0x6a6c('0x1f'),_0x271009[_0x6a6c('0x1e')]);_0x271009[_0x6a6c('0x20')]=_0x271009[_0x6a6c('0x1e')];for(_0x192f72=0x0;_0x192f72<_0x1f2394[_0x6a6c('0x11')];_0x192f72++){if(_0x1f2394[_0x192f72][_0x6a6c('0x12')]===_0x271009[_0x6a6c('0x1e')]){_0x51f9c5=!![];_0x271009['userId']=_0x1f2394[_0x192f72]['id'];logger[_0x6a6c('0xf')](_0x6a6c('0x21'),_0x271009[_0x6a6c('0x22')]);}}}if(!_0x51f9c5){logger[_0x6a6c('0xf')](_0x6a6c('0x23'));_0x271009[_0x6a6c('0x20')]=_0x271009[_0x6a6c('0x13')];_0x271009['userId']=_0x271009[_0x6a6c('0x14')];_0x51f9c5=!![];}if(_0x51f9c5){_0x1720e2(_0x271009);}else{_0x41b93c({'statusCode':0x194,'message':_0x6a6c('0x16')});}}else{_0x41b93c({'statusCode':0x194,'message':_0x6a6c('0x16')});}})[_0x6a6c('0x17')](function(_0x4a9e2a){logger[_0x6a6c('0x18')]('['+[_0x55d2c2[_0x6a6c('0x19')]()]+']',_0x4a9e2a[_0x6a6c('0x1a')]);_0x41b93c(_0x4a9e2a);});});};}function getEndUser(_0x5e800a,_0x12b08c,_0x5b483a){return function(_0x586302){return new Promise(function(_0x559219,_0xc7ffa4){var _0x437170=0x0;var _0x300e0f={'method':_0x6a6c('0x1b'),'uri':_0x5b483a+_0x6a6c('0x24'),'json':!![]};_0x300e0f[_0x6a6c('0xe')]=_0x12b08c;logger[_0x6a6c('0xf')](_0x6a6c('0x25'));return rp(_0x300e0f)['then'](function(_0x164818){_0x164818[_0x6a6c('0x26')]['forEach'](function(_0x167ff2){if(_0x167ff2[_0x6a6c('0x27')]===_0x6a6c('0x28')){_0x437170=_0x167ff2['id'];}});})[_0x6a6c('0x1d')](function(){logger[_0x6a6c('0xf')](_0x6a6c('0x29'));var _0x4e0120={'method':_0x6a6c('0x1b'),'uri':_0x5b483a+_0x6a6c('0x2a')+_0x437170,'json':!![]};_0x4e0120[_0x6a6c('0xe')]=_0x12b08c;return rp(_0x4e0120);})['then'](function(_0x3b84aa){logger[_0x6a6c('0xf')](_0x6a6c('0x2b'),_0x586302['contactNumber']);if(_0x3b84aa[_0x6a6c('0x2c')][_0x6a6c('0x11')]>0x0){var _0xfc53dc=_[_0x6a6c('0x2d')](_0x3b84aa[_0x6a6c('0x2c')],function(_0x132b8f){if(_0x132b8f[_0x6a6c('0x2e')]===_0x586302[_0x6a6c('0x2f')]||_0x132b8f[_0x6a6c('0x30')]===_0x586302[_0x6a6c('0x2f')]){return _0x132b8f;}});if(_0xfc53dc){_0x586302[_0x6a6c('0x31')]=_0xfc53dc['id'];logger[_0x6a6c('0xf')](_0x6a6c('0x32'),_0x586302['endUserId']);_0x559219(_0x586302);}else{return createEndUser(_0x586302,_0x5e800a,_0x12b08c,_0x5b483a)[_0x6a6c('0x1d')](function(_0x3fc2f8){logger[_0x6a6c('0xf')](_0x6a6c('0x33'),_0x586302[_0x6a6c('0x31')]);_0x559219(_0x3fc2f8);});}}else{return createEndUser(_0x586302,_0x5e800a,_0x12b08c,_0x5b483a)[_0x6a6c('0x1d')](function(_0x507490){logger['info'](_0x6a6c('0x33'),_0x586302[_0x6a6c('0x31')]);_0x559219(_0x507490);});}})[_0x6a6c('0x17')](function(_0x3d4062){throw new Error(_0x3d4062[_0x6a6c('0x1a')]);});});};}function createEndUser(_0x41c583,_0x59d91f,_0x438790,_0x2fb738){return new Promise(function(_0x82f5fe,_0x5578ee){var _0x1bd6f6=moment();var _0x5a7f3a={'method':_0x6a6c('0x34'),'uri':_0x2fb738+_0x6a6c('0x35'),'body':{'contact':{'last_name':_0x41c583[_0x6a6c('0x2f')],'work_number':_0x41c583[_0x6a6c('0x2f')],'mobile_number':_0x41c583[_0x6a6c('0x2f')],'owner_id':_0x41c583[_0x6a6c('0x22')],'created_at':_0x1bd6f6[_0x6a6c('0x36')]('YYYY-MM-DDTHH:mm:ss')}},'json':!![]};_0x5a7f3a['headers']=_0x438790;logger[_0x6a6c('0xf')](_0x6a6c('0x37'));return rp(_0x5a7f3a)[_0x6a6c('0x1d')](function(_0x2cbb5b){_0x41c583[_0x6a6c('0x31')]=_0x2cbb5b[_0x6a6c('0x38')]['id'];_0x82f5fe(_0x41c583);})[_0x6a6c('0x17')](function(_0x5baee1){logger[_0x6a6c('0x18')]('['+[_0x59d91f[_0x6a6c('0x19')]()]+']',_0x5baee1['message']);_0x5578ee(_0x5baee1[_0x6a6c('0x1a')]);});});}function getTicket(_0x4fa94e,_0x39ec56,_0x97e8d5,_0x467235,_0x2a000d){return function(_0x2c71bb){logger[_0x6a6c('0xf')](_0x6a6c('0x39'));return new Promise(function(_0x4a4f7f,_0xb0c40a){var _0x21fdca=moment();var _0x4cb4c4={'method':_0x6a6c('0x34'),'uri':_0x97e8d5+_0x6a6c('0x3a'),'body':{'title':intUtil[_0x6a6c('0x3b')](_0x467235[_0x6a6c('0x3c')],_0x2a000d,'\x20'),'description':intUtil[_0x6a6c('0x3b')](_0x467235[_0x6a6c('0x3d')],_0x2a000d,'\x0a'),'owner_id':_0x2c71bb[_0x6a6c('0x22')],'creater_id':_0x2c71bb['adminId'],'targetable_id':_0x2c71bb[_0x6a6c('0x31')],'targetable_type':'Contact','created_at':_0x21fdca[_0x6a6c('0x36')](_0x6a6c('0x3e')),'due_date':_0x21fdca[_0x6a6c('0x3f')](0x1e,'m')['format'](_0x6a6c('0x3e'))},'json':!![]};_0x4cb4c4[_0x6a6c('0xe')]=_0x39ec56;return rp(_0x4cb4c4)[_0x6a6c('0x1d')](function(_0x8e76fe){_0x2c71bb[_0x6a6c('0x40')]=_0x8e76fe['task']['id'];logger[_0x6a6c('0xf')](_0x6a6c('0x41'),_0x2c71bb['ticketId']);_0x4a4f7f(_0x2c71bb);})['catch'](function(_0x561a19){logger['error']('['+[_0x4fa94e['toUpperCase']()]+']',_0x561a19[_0x6a6c('0x1a')]);_0xb0c40a(_0x561a19[_0x6a6c('0x1a')]);});});};}function emit(_0x1a1d5e,_0x5fa2e2,_0x56296b){var _0x2c9afd={'uri':_0x1a1d5e+_0x6a6c('0x42')+_0x56296b};io['to'](util[_0x6a6c('0x36')](_0x6a6c('0x43'),_0x5fa2e2))[_0x6a6c('0x44')]('trigger:browser:url',_0x2c9afd);}exports['cs']=function(_0x2115e9,_0x31e0dc,_0x385808,_0xd08f7,_0x27087a,_0x3aec7e,_0x15764d,_0x562fee){var _0x278e89={};var _0x39b86a={'Authorization':'Token\x20token='+_0x3aec7e['apiKey']};_0x3aec7e[_0x6a6c('0x45')]=intUtil['stripTrailingSlash'](_0x3aec7e[_0x6a6c('0x45')]);_0x3aec7e['serverUrl']=intUtil[_0x6a6c('0x46')](_0x3aec7e[_0x6a6c('0x47')]);var _0x3a5664=_0x3aec7e[_0x6a6c('0x45')];_0x278e89['adminEmail']=_0x3aec7e[_0x6a6c('0x48')];_0x278e89[_0x6a6c('0x2f')]=_0x562fee[_0x6a6c('0x49')]()===_0x6a6c('0x4a')?_0x31e0dc[_0x6a6c('0x4b')]:_0x31e0dc[_0x6a6c('0x4c')];_0x278e89[_0x6a6c('0x4d')]=_0x562fee==='queue'||_0x562fee==='unmanaged'?_0x6a6c('0x4e'):_0x6a6c('0x4a');if(_0xd08f7){_0x278e89[_0x6a6c('0x1e')]=_0xd08f7[_0x6a6c('0x12')];}var _0x3f1f4f=util[_0x6a6c('0x36')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x3aec7e['serverUrl'],_0x31e0dc['uniqueid'],md5(_0x31e0dc[_0x6a6c('0x4f')]));if(_0x27087a&&_0x27087a['monitor_format']){logger[_0x6a6c('0xf')](_0x6a6c('0x50'),_0x6a6c('0x51'));_0x31e0dc['recordingURL']=_0x3f1f4f;}else if(_0x15764d&&_0x15764d[_0x6a6c('0x52')]&&_0x15764d[_0x6a6c('0x52')]!==_0x6a6c('0x53')){logger[_0x6a6c('0xf')]('[OUTBOUND]',_0x6a6c('0x51'));_0x31e0dc[_0x6a6c('0x54')]=_0x3f1f4f;}else{_0x31e0dc[_0x6a6c('0x54')]='';}return getAdminId(_0x278e89,_0x562fee,_0x39b86a,_0x3a5664)[_0x6a6c('0x1d')](getUser(_0x562fee,_0x39b86a,_0x3a5664))[_0x6a6c('0x1d')](getEndUser(_0x562fee,_0x39b86a,_0x3a5664))['then'](getTicket(_0x562fee,_0x39b86a,_0x3a5664,_0x385808,_0x31e0dc))[_0x6a6c('0x1d')](function(_0x5b5653){logger[_0x6a6c('0xf')](util[_0x6a6c('0x36')]('The\x20ticket\x20ID\x20is:\x20%s',_0x5b5653[_0x6a6c('0x40')]));if(_0x562fee!==_0x6a6c('0x55')){logger[_0x6a6c('0xf')]('['+[_0x562fee[_0x6a6c('0x19')]()]+']',_0x6a6c('0x56'));emit(_0x3a5664,_0xd08f7[_0x6a6c('0x27')],_0x5b5653['endUserId']);}})[_0x6a6c('0x17')](function(_0x4d239e){logger[_0x6a6c('0x18')]('['+[_0x562fee['toUpperCase']()]+']\x20Error\x20running\x20Freshsales\x20integration',util[_0x6a6c('0x57')](_0x4d239e,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x76f9=['contactNumber','mobile_number','then','Contact\x20found\x20mobile_number:','endUserId','Contact\x20found\x20work_number:','Contact\x20created:','POST','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','Creating\x20new\x20task','/api/tasks','getString','Subjects','Contact','task','Task\x20created:','ticketId','/contacts/','user:%s','emit','trigger:browser:url','apiKey','remoteUri','stripTrailingSlash','serverUrl','toLowerCase','outbound','destcalleridnum','callDirection','queue','unmanaged','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','The\x20ticket\x20ID\x20is:\x20%s','Displaying\x20task\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Freshsales\x20integration','inspect','request-promise','md5','moment','bluebird','ioredis','./util','../../../../config/environment','../../../../config/logger','freshsales','defaults','socket.io-emitter','redis','GET','/api/selector/owners','headers','info','Getting\x20admin\x20information','length','email','adminEmail','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','error','toUpperCase','message','Getting\x20user\x20list','users','agentEmail','userEmail','userId','User\x20found:','Admin\x20selected','catch','/api/lookup?q=','&f=','&entities=contact','contacts','format','Searching\x20contact\x20with\x20phone\x20%s'];(function(_0x113f06,_0xdd48ea){var _0x58ff7b=function(_0x1b0eb2){while(--_0x1b0eb2){_0x113f06['push'](_0x113f06['shift']());}};_0x58ff7b(++_0xdd48ea);}(_0x76f9,0xd7));var _0x976f=function(_0x40ebef,_0x4c544d){_0x40ebef=_0x40ebef-0x0;var _0x3fdef5=_0x76f9[_0x40ebef];return _0x3fdef5;};'use strict';var _=require('lodash');var rp=require(_0x976f('0x0'));var md5=require(_0x976f('0x1'));var util=require('util');var moment=require(_0x976f('0x2'));var Promise=require(_0x976f('0x3'));var Redis=require(_0x976f('0x4'));var intUtil=require(_0x976f('0x5'));var config=require(_0x976f('0x6'));var logger=require(_0x976f('0x7'))(_0x976f('0x8'));config['redis']=_[_0x976f('0x9')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x976f('0xa'))(new Redis(config[_0x976f('0xb')]));function getAdminId(_0x64c5e6,_0x32e681,_0x461c5c,_0x7115cc){return new Promise(function(_0x4cf89d,_0x211830){var _0x5da156=![];var _0x5e662f={'method':_0x976f('0xc'),'uri':_0x7115cc+_0x976f('0xd'),'json':!![]};_0x5e662f[_0x976f('0xe')]=_0x461c5c;logger[_0x976f('0xf')](_0x976f('0x10'));return rp(_0x5e662f)['then'](function(_0x875ae1){if(_0x875ae1){var _0x4b0707=_0x875ae1['users'];var _0x182f94=null;for(_0x182f94=0x0;_0x182f94<_0x4b0707[_0x976f('0x11')];_0x182f94++){if(_0x4b0707[_0x182f94][_0x976f('0x12')]===_0x64c5e6[_0x976f('0x13')]){_0x64c5e6[_0x976f('0x14')]=_0x4b0707[_0x182f94]['id'];_0x5da156=!![];}}if(_0x5da156){logger[_0x976f('0xf')](_0x976f('0x15'),_0x64c5e6[_0x976f('0x14')]);_0x4cf89d(_0x64c5e6);}else{_0x211830({'statusCode':0x194,'message':_0x976f('0x16')});}}else{_0x211830({'statusCode':0x194,'message':_0x976f('0x16')});}})['catch'](function(_0x4716b6){logger[_0x976f('0x17')]('['+[_0x32e681[_0x976f('0x18')]()]+']',_0x4716b6[_0x976f('0x19')]);_0x211830(_0x4716b6);});});}function getUser(_0x1e741d,_0x3ac4dc,_0x2a1a7e){return function(_0x40ab03){return new Promise(function(_0x79c800,_0x51dfbb){var _0x580652={'method':_0x976f('0xc'),'uri':_0x2a1a7e+_0x976f('0xd'),'json':!![]};_0x580652['headers']=_0x3ac4dc;logger['info'](_0x976f('0x1a'));return rp(_0x580652)['then'](function(_0x23ca91){if(_0x23ca91){var _0x22787f=_0x23ca91[_0x976f('0x1b')];var _0x301ce4=![];var _0xda891f=null;if(_0x40ab03[_0x976f('0x1c')]!==null){logger[_0x976f('0xf')]('Getting\x20user\x20with\x20email',_0x40ab03[_0x976f('0x1c')]);_0x40ab03[_0x976f('0x1d')]=_0x40ab03[_0x976f('0x1c')];for(_0xda891f=0x0;_0xda891f<_0x22787f[_0x976f('0x11')];_0xda891f++){if(_0x22787f[_0xda891f]['email']===_0x40ab03[_0x976f('0x1c')]){_0x301ce4=!![];_0x40ab03[_0x976f('0x1e')]=_0x22787f[_0xda891f]['id'];logger['info'](_0x976f('0x1f'),_0x40ab03[_0x976f('0x1e')]);}}}if(!_0x301ce4){logger[_0x976f('0xf')](_0x976f('0x20'));_0x40ab03[_0x976f('0x1d')]=_0x40ab03['adminEmail'];_0x40ab03[_0x976f('0x1e')]=_0x40ab03[_0x976f('0x14')];_0x301ce4=!![];}if(_0x301ce4){_0x79c800(_0x40ab03);}else{_0x51dfbb({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}else{_0x51dfbb({'statusCode':0x194,'message':_0x976f('0x16')});}})[_0x976f('0x21')](function(_0x367fb0){logger[_0x976f('0x17')]('['+[_0x1e741d[_0x976f('0x18')]()]+']',_0x367fb0[_0x976f('0x19')]);_0x51dfbb(_0x367fb0);});});};}function searchContact(_0x39ced6,_0xc320e0,_0x4a564c,_0x5b9991){return new Promise(function(_0x419ab8,_0x5dbf39){var _0x5795f4={'method':_0x976f('0xc'),'headers':_0xc320e0,'uri':_0x39ced6+_0x976f('0x22')+_0x5b9991+_0x976f('0x23')+_0x4a564c+_0x976f('0x24'),'json':!![]};rp(_0x5795f4)['then'](function(_0x23825f){var _0x122000=_['find'](_0x23825f[_0x976f('0x25')][_0x976f('0x25')],[_0x4a564c,_0x5b9991]);_0x419ab8(_0x122000);})['catch'](function(_0x1fa372){_0x5dbf39(_0x1fa372);});});}function getEndUser(_0x5e4ff6,_0x36aaef,_0x304cbb){return function(_0x599e60){return new Promise(function(_0x498425,_0x15459e){logger[_0x976f('0xf')](util[_0x976f('0x26')](_0x976f('0x27'),_0x599e60[_0x976f('0x28')]));searchContact(_0x304cbb,_0x36aaef,_0x976f('0x29'),_0x599e60[_0x976f('0x28')])[_0x976f('0x2a')](function(_0x3eda0d){if(_0x3eda0d){_0x599e60['endUserId']=_0x3eda0d['id'];logger[_0x976f('0xf')](_0x976f('0x2b'),_0x599e60[_0x976f('0x2c')]);return _0x498425(_0x599e60);}searchContact(_0x304cbb,_0x36aaef,'work_number',_0x599e60['contactNumber'])[_0x976f('0x2a')](function(_0x210975){if(_0x210975){_0x599e60['endUserId']=_0x210975['id'];logger[_0x976f('0xf')](_0x976f('0x2d'),_0x599e60['endUserId']);return _0x498425(_0x599e60);}createEndUser(_0x599e60,_0x5e4ff6,_0x36aaef,_0x304cbb)[_0x976f('0x2a')](function(_0x40024f){logger[_0x976f('0xf')](_0x976f('0x2e'),_0x40024f[_0x976f('0x2c')]);return _0x498425(_0x40024f);});});})[_0x976f('0x21')](function(_0x11cc1f){_0x15459e(_0x11cc1f);});});};}function createEndUser(_0x4e7d64,_0x43f8b9,_0x1161ee,_0x39e1d1){return new Promise(function(_0x3828c1,_0x2e7a78){var _0x955df6=moment();var _0x56fdfa={'method':_0x976f('0x2f'),'uri':_0x39e1d1+'/api/contacts','body':{'contact':{'last_name':_0x4e7d64['contactNumber'],'work_number':_0x4e7d64['contactNumber'],'mobile_number':_0x4e7d64[_0x976f('0x28')],'owner_id':_0x4e7d64[_0x976f('0x1e')],'created_at':_0x955df6['format'](_0x976f('0x30'))}},'json':!![]};_0x56fdfa[_0x976f('0xe')]=_0x1161ee;logger[_0x976f('0xf')](_0x976f('0x31'));return rp(_0x56fdfa)[_0x976f('0x2a')](function(_0x5f483b){_0x4e7d64[_0x976f('0x2c')]=_0x5f483b[_0x976f('0x32')]['id'];_0x3828c1(_0x4e7d64);})['catch'](function(_0x5f259a){logger[_0x976f('0x17')]('['+[_0x43f8b9['toUpperCase']()]+']',_0x5f259a[_0x976f('0x19')]);_0x2e7a78(_0x5f259a[_0x976f('0x19')]);});});}function getTicket(_0x55c413,_0x3b8bc2,_0x2ee2f6,_0x38714a,_0x4c4839){return function(_0x3b8e21){logger[_0x976f('0xf')](_0x976f('0x33'));return new Promise(function(_0x5ca1bc,_0x423eca){var _0x8779f6=moment();var _0x5c111a={'method':_0x976f('0x2f'),'uri':_0x2ee2f6+_0x976f('0x34'),'body':{'title':intUtil[_0x976f('0x35')](_0x38714a[_0x976f('0x36')],_0x4c4839,'\x20'),'description':intUtil[_0x976f('0x35')](_0x38714a['Descriptions'],_0x4c4839,'\x0a'),'owner_id':_0x3b8e21[_0x976f('0x1e')],'creater_id':_0x3b8e21[_0x976f('0x14')],'targetable_id':_0x3b8e21['endUserId'],'targetable_type':_0x976f('0x37'),'created_at':_0x8779f6[_0x976f('0x26')](_0x976f('0x30')),'due_date':_0x8779f6['add'](0x1e,'m')[_0x976f('0x26')](_0x976f('0x30'))},'json':!![]};_0x5c111a[_0x976f('0xe')]=_0x3b8bc2;return rp(_0x5c111a)['then'](function(_0x56bdcf){_0x3b8e21['ticketId']=_0x56bdcf[_0x976f('0x38')]['id'];logger['info'](_0x976f('0x39'),_0x3b8e21[_0x976f('0x3a')]);_0x5ca1bc(_0x3b8e21);})[_0x976f('0x21')](function(_0x4000e5){logger[_0x976f('0x17')]('['+[_0x55c413[_0x976f('0x18')]()]+']',_0x4000e5[_0x976f('0x19')]);_0x423eca(_0x4000e5[_0x976f('0x19')]);});});};}function emit(_0x259434,_0x2005bf,_0x238f02){var _0x470a78={'uri':_0x259434+_0x976f('0x3b')+_0x238f02};io['to'](util[_0x976f('0x26')](_0x976f('0x3c'),_0x2005bf))[_0x976f('0x3d')](_0x976f('0x3e'),_0x470a78);}exports['cs']=function(_0x8a2ed1,_0x187160,_0x58aac8,_0x512599,_0x31bd0a,_0x107061,_0x3077bc,_0x1fe160){var _0x279153={};var _0x434092={'Authorization':'Token\x20token='+_0x107061[_0x976f('0x3f')]};_0x107061[_0x976f('0x40')]=intUtil[_0x976f('0x41')](_0x107061['remoteUri']);_0x107061[_0x976f('0x42')]=intUtil[_0x976f('0x41')](_0x107061[_0x976f('0x42')]);var _0x90e3c5=_0x107061[_0x976f('0x40')];_0x279153['adminEmail']=_0x107061['username'];_0x279153[_0x976f('0x28')]=_0x1fe160[_0x976f('0x43')]()===_0x976f('0x44')?_0x187160[_0x976f('0x45')]:_0x187160['calleridnum'];_0x279153[_0x976f('0x46')]=_0x1fe160===_0x976f('0x47')||_0x1fe160===_0x976f('0x48')?'queue':_0x976f('0x44');if(_0x512599){_0x279153[_0x976f('0x1c')]=_0x512599[_0x976f('0x12')];}var _0x2d39ec=util[_0x976f('0x26')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x107061[_0x976f('0x42')],_0x187160[_0x976f('0x49')],md5(_0x187160[_0x976f('0x49')]));if(_0x31bd0a&&_0x31bd0a[_0x976f('0x4a')]){logger[_0x976f('0xf')](_0x976f('0x4b'),_0x976f('0x4c'));_0x187160[_0x976f('0x4d')]=_0x2d39ec;}else if(_0x3077bc&&_0x3077bc[_0x976f('0x4e')]&&_0x3077bc[_0x976f('0x4e')]!==_0x976f('0x4f')){logger['info']('[OUTBOUND]','Recording\x20is\x20enabled!');_0x187160[_0x976f('0x4d')]=_0x2d39ec;}else{_0x187160[_0x976f('0x4d')]='';}return getAdminId(_0x279153,_0x1fe160,_0x434092,_0x90e3c5)[_0x976f('0x2a')](getUser(_0x1fe160,_0x434092,_0x90e3c5))[_0x976f('0x2a')](getEndUser(_0x1fe160,_0x434092,_0x90e3c5))[_0x976f('0x2a')](getTicket(_0x1fe160,_0x434092,_0x90e3c5,_0x58aac8,_0x187160))[_0x976f('0x2a')](function(_0x395a08){logger[_0x976f('0xf')](util[_0x976f('0x26')](_0x976f('0x50'),_0x395a08[_0x976f('0x3a')]));if(_0x1fe160!==_0x976f('0x48')){logger['info']('['+[_0x1fe160[_0x976f('0x18')]()]+']',_0x976f('0x51'));emit(_0x90e3c5,_0x512599[_0x976f('0x52')],_0x395a08['endUserId']);}})[_0x976f('0x21')](function(_0x583083){logger[_0x976f('0x17')]('['+[_0x1fe160[_0x976f('0x18')]()]+_0x976f('0x53'),util[_0x976f('0x54')](_0x583083,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file