Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 5bd8e38..839b097 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x598a=['[OUTBOUND]','recordingURL','Displaying\x20task\x20in\x20a\x20new\x20tab...','name','inspect','lodash','request-promise','md5','util','moment','ioredis','freshsales','redis','defaults','localhost','GET','/api/selector/owners','headers','info','Getting\x20admin\x20information','users','length','adminEmail','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','catch','toUpperCase','message','Getting\x20user\x20list','then','Getting\x20user\x20with\x20email','agentEmail','userEmail','userId','User\x20found:','Admin\x20selected','/api/lookup?q=','&f=','contacts','Searching\x20contact\x20with\x20phone\x20%s','contactNumber','mobile_number','endUserId','work_number','Contact\x20found\x20work_number:','Contact\x20created:','/api/contacts','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','error','Creating\x20new\x20task','/api/tasks','getString','Contact','format','YYYY-MM-DDTHH:mm:ss','add','ticketId','task','Task\x20created:','emit','trigger:browser:url','Token\x20token=','apiKey','remoteUri','stripTrailingSlash','serverUrl','username','toLowerCase','outbound','calleridnum','callDirection','queue','unmanaged','email','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','[QUEUE]','Recording\x20is\x20enabled!','recordingFormat','none'];(function(_0x485eb2,_0x309eae){var _0x4ee062=function(_0xc9dfa7){while(--_0xc9dfa7){_0x485eb2['push'](_0x485eb2['shift']());}};_0x4ee062(++_0x309eae);}(_0x598a,0xfb));var _0xa598=function(_0x526ea6,_0x40783d){_0x526ea6=_0x526ea6-0x0;var _0x1ebe9c=_0x598a[_0x526ea6];return _0x1ebe9c;};'use strict';var _=require(_0xa598('0x0'));var rp=require(_0xa598('0x1'));var md5=require(_0xa598('0x2'));var util=require(_0xa598('0x3'));var moment=require(_0xa598('0x4'));var Promise=require('bluebird');var Redis=require(_0xa598('0x5'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require('../../../../config/logger')(_0xa598('0x6'));config[_0xa598('0x7')]=_[_0xa598('0x8')](config[_0xa598('0x7')],{'host':_0xa598('0x9'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function getAdminId(_0x4279e3,_0xebf6e5,_0x1bd5c5,_0xe36e4f){return new Promise(function(_0x190ccf,_0x387afc){var _0x5207d5=![];var _0x5871a3={'method':_0xa598('0xa'),'uri':_0xe36e4f+_0xa598('0xb'),'json':!![]};_0x5871a3[_0xa598('0xc')]=_0x1bd5c5;logger[_0xa598('0xd')](_0xa598('0xe'));return rp(_0x5871a3)['then'](function(_0x186240){if(_0x186240){var _0x4109ff=_0x186240[_0xa598('0xf')];var _0x5041d4=null;for(_0x5041d4=0x0;_0x5041d4<_0x4109ff[_0xa598('0x10')];_0x5041d4++){if(_0x4109ff[_0x5041d4]['email']===_0x4279e3[_0xa598('0x11')]){_0x4279e3[_0xa598('0x12')]=_0x4109ff[_0x5041d4]['id'];_0x5207d5=!![];}}if(_0x5207d5){logger[_0xa598('0xd')](_0xa598('0x13'),_0x4279e3[_0xa598('0x12')]);_0x190ccf(_0x4279e3);}else{_0x387afc({'statusCode':0x194,'message':_0xa598('0x14')});}}else{_0x387afc({'statusCode':0x194,'message':_0xa598('0x14')});}})[_0xa598('0x15')](function(_0x28534a){logger['error']('['+[_0xebf6e5[_0xa598('0x16')]()]+']',_0x28534a[_0xa598('0x17')]);_0x387afc(_0x28534a);});});}function getUser(_0x6e6ff5,_0x27c34e,_0x1351e5){return function(_0xecb39d){return new Promise(function(_0x3cbb9f,_0x2746e3){var _0x36492f={'method':_0xa598('0xa'),'uri':_0x1351e5+'/api/selector/owners','json':!![]};_0x36492f[_0xa598('0xc')]=_0x27c34e;logger[_0xa598('0xd')](_0xa598('0x18'));return rp(_0x36492f)[_0xa598('0x19')](function(_0x2ad4ff){if(_0x2ad4ff){var _0xcdf1b6=_0x2ad4ff['users'];var _0x56fc63=![];var _0x2923d5=null;if(_0xecb39d['agentEmail']!==null){logger[_0xa598('0xd')](_0xa598('0x1a'),_0xecb39d[_0xa598('0x1b')]);_0xecb39d[_0xa598('0x1c')]=_0xecb39d[_0xa598('0x1b')];for(_0x2923d5=0x0;_0x2923d5<_0xcdf1b6[_0xa598('0x10')];_0x2923d5++){if(_0xcdf1b6[_0x2923d5]['email']===_0xecb39d[_0xa598('0x1b')]){_0x56fc63=!![];_0xecb39d[_0xa598('0x1d')]=_0xcdf1b6[_0x2923d5]['id'];logger[_0xa598('0xd')](_0xa598('0x1e'),_0xecb39d[_0xa598('0x1d')]);}}}if(!_0x56fc63){logger[_0xa598('0xd')](_0xa598('0x1f'));_0xecb39d[_0xa598('0x1c')]=_0xecb39d['adminEmail'];_0xecb39d[_0xa598('0x1d')]=_0xecb39d[_0xa598('0x12')];_0x56fc63=!![];}if(_0x56fc63){_0x3cbb9f(_0xecb39d);}else{_0x2746e3({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}else{_0x2746e3({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}})[_0xa598('0x15')](function(_0x559038){logger['error']('['+[_0x6e6ff5[_0xa598('0x16')]()]+']',_0x559038['message']);_0x2746e3(_0x559038);});});};}function searchContact(_0x34689e,_0x5eae63,_0x4dad9c,_0xaa38ac){return new Promise(function(_0x4138a1,_0x554d3b){var _0x16f00d={'method':_0xa598('0xa'),'headers':_0x5eae63,'uri':_0x34689e+_0xa598('0x20')+_0xaa38ac+_0xa598('0x21')+_0x4dad9c+'&entities=contact','json':!![]};rp(_0x16f00d)[_0xa598('0x19')](function(_0x5ab302){var _0x5d70aa=_['find'](_0x5ab302[_0xa598('0x22')]['contacts'],[_0x4dad9c,_0xaa38ac]);_0x4138a1(_0x5d70aa);})[_0xa598('0x15')](function(_0x3324df){_0x554d3b(_0x3324df);});});}function getEndUser(_0x282294,_0x5a18ec,_0x3ccace){return function(_0x196c22){return new Promise(function(_0x12c5b3,_0x21cd3a){logger[_0xa598('0xd')](util['format'](_0xa598('0x23'),_0x196c22[_0xa598('0x24')]));searchContact(_0x3ccace,_0x5a18ec,_0xa598('0x25'),_0x196c22[_0xa598('0x24')])['then'](function(_0x145fdf){if(_0x145fdf){_0x196c22[_0xa598('0x26')]=_0x145fdf['id'];logger['info']('Contact\x20found\x20mobile_number:',_0x196c22[_0xa598('0x26')]);return _0x12c5b3(_0x196c22);}searchContact(_0x3ccace,_0x5a18ec,_0xa598('0x27'),_0x196c22[_0xa598('0x24')])['then'](function(_0x1fed30){if(_0x1fed30){_0x196c22[_0xa598('0x26')]=_0x1fed30['id'];logger['info'](_0xa598('0x28'),_0x196c22['endUserId']);return _0x12c5b3(_0x196c22);}createEndUser(_0x196c22,_0x282294,_0x5a18ec,_0x3ccace)[_0xa598('0x19')](function(_0x4074b0){logger['info'](_0xa598('0x29'),_0x4074b0[_0xa598('0x26')]);return _0x12c5b3(_0x4074b0);});});})['catch'](function(_0x31e87e){_0x21cd3a(_0x31e87e);});});};}function createEndUser(_0x140c53,_0x1eec94,_0x4fd1b0,_0x1e3777){return new Promise(function(_0x39d695,_0x36cfc7){var _0x5baccf=moment();var _0x1007f4={'method':'POST','uri':_0x1e3777+_0xa598('0x2a'),'body':{'contact':{'last_name':_0x140c53[_0xa598('0x24')],'work_number':_0x140c53[_0xa598('0x24')],'mobile_number':_0x140c53['contactNumber'],'owner_id':_0x140c53['userId'],'created_at':_0x5baccf['format']('YYYY-MM-DDTHH:mm:ss')}},'json':!![]};_0x1007f4[_0xa598('0xc')]=_0x4fd1b0;logger[_0xa598('0xd')](_0xa598('0x2b'));return rp(_0x1007f4)[_0xa598('0x19')](function(_0x3fd322){_0x140c53[_0xa598('0x26')]=_0x3fd322[_0xa598('0x2c')]['id'];_0x39d695(_0x140c53);})[_0xa598('0x15')](function(_0x86ba15){logger[_0xa598('0x2d')]('['+[_0x1eec94['toUpperCase']()]+']',_0x86ba15[_0xa598('0x17')]);_0x36cfc7(_0x86ba15[_0xa598('0x17')]);});});}function getTicket(_0x603814,_0x50f42f,_0x331301,_0x3229ea,_0xc8382e){return function(_0x46b7a1){logger[_0xa598('0xd')](_0xa598('0x2e'));return new Promise(function(_0x5ef143,_0x4cfe9b){var _0x213ea6=moment();var _0x10f2f7={'method':'POST','uri':_0x331301+_0xa598('0x2f'),'body':{'title':intUtil['getString'](_0x3229ea['Subjects'],_0xc8382e,'\x20'),'description':intUtil[_0xa598('0x30')](_0x3229ea['Descriptions'],_0xc8382e,'\x0a'),'owner_id':_0x46b7a1[_0xa598('0x1d')],'creater_id':_0x46b7a1[_0xa598('0x12')],'targetable_id':_0x46b7a1[_0xa598('0x26')],'targetable_type':_0xa598('0x31'),'created_at':_0x213ea6[_0xa598('0x32')](_0xa598('0x33')),'due_date':_0x213ea6[_0xa598('0x34')](0x1e,'m')[_0xa598('0x32')](_0xa598('0x33'))},'json':!![]};_0x10f2f7[_0xa598('0xc')]=_0x50f42f;return rp(_0x10f2f7)['then'](function(_0x464e15){_0x46b7a1[_0xa598('0x35')]=_0x464e15[_0xa598('0x36')]['id'];logger[_0xa598('0xd')](_0xa598('0x37'),_0x46b7a1[_0xa598('0x35')]);_0x5ef143(_0x46b7a1);})[_0xa598('0x15')](function(_0x53acb7){logger[_0xa598('0x2d')]('['+[_0x603814[_0xa598('0x16')]()]+']',_0x53acb7[_0xa598('0x17')]);_0x4cfe9b(_0x53acb7[_0xa598('0x17')]);});});};}function emit(_0x1755b7,_0x1d1379,_0x475201){var _0x21656a={'uri':_0x1755b7+'/contacts/'+_0x475201};io['to'](util[_0xa598('0x32')]('user:%s',_0x1d1379))[_0xa598('0x38')](_0xa598('0x39'),_0x21656a);}exports['cs']=function(_0x2710d,_0x19628b,_0x46a567,_0x3fed82,_0x1cc087,_0x14f4fd,_0x415fa6,_0x51e0e9){var _0x57e82c={};var _0x74239d={'Authorization':_0xa598('0x3a')+_0x14f4fd[_0xa598('0x3b')]};_0x14f4fd[_0xa598('0x3c')]=intUtil['stripTrailingSlash'](_0x14f4fd['remoteUri']);_0x14f4fd['serverUrl']=intUtil[_0xa598('0x3d')](_0x14f4fd[_0xa598('0x3e')]);var _0x50b6ed=_0x14f4fd['remoteUri'];_0x57e82c['adminEmail']=_0x14f4fd[_0xa598('0x3f')];_0x57e82c[_0xa598('0x24')]=_0x51e0e9[_0xa598('0x40')]()===_0xa598('0x41')?_0x19628b['destcalleridnum']:_0x19628b[_0xa598('0x42')];_0x57e82c[_0xa598('0x43')]=_0x51e0e9===_0xa598('0x44')||_0x51e0e9===_0xa598('0x45')?_0xa598('0x44'):_0xa598('0x41');if(_0x3fed82){_0x57e82c[_0xa598('0x1b')]=_0x3fed82[_0xa598('0x46')];}var _0x3c1f2f=util['format'](_0xa598('0x47'),_0x14f4fd['serverUrl'],_0x19628b['uniqueid'],md5(_0x19628b[_0xa598('0x48')]));if(_0x1cc087&&_0x1cc087['monitor_format']){logger['info'](_0xa598('0x49'),_0xa598('0x4a'));_0x19628b['recordingURL']=_0x3c1f2f;}else if(_0x415fa6&&_0x415fa6[_0xa598('0x4b')]&&_0x415fa6['recordingFormat']!==_0xa598('0x4c')){logger[_0xa598('0xd')](_0xa598('0x4d'),_0xa598('0x4a'));_0x19628b[_0xa598('0x4e')]=_0x3c1f2f;}else{_0x19628b[_0xa598('0x4e')]='';}return getAdminId(_0x57e82c,_0x51e0e9,_0x74239d,_0x50b6ed)[_0xa598('0x19')](getUser(_0x51e0e9,_0x74239d,_0x50b6ed))[_0xa598('0x19')](getEndUser(_0x51e0e9,_0x74239d,_0x50b6ed))[_0xa598('0x19')](getTicket(_0x51e0e9,_0x74239d,_0x50b6ed,_0x46a567,_0x19628b))[_0xa598('0x19')](function(_0x462d16){logger[_0xa598('0xd')](util[_0xa598('0x32')]('The\x20ticket\x20ID\x20is:\x20%s',_0x462d16[_0xa598('0x35')]));if(_0x51e0e9!==_0xa598('0x45')){logger[_0xa598('0xd')]('['+[_0x51e0e9['toUpperCase']()]+']',_0xa598('0x4f'));emit(_0x50b6ed,_0x3fed82[_0xa598('0x50')],_0x462d16[_0xa598('0x26')]);}})['catch'](function(_0x469794){logger[_0xa598('0x2d')]('['+[_0x51e0e9['toUpperCase']()]+']\x20Error\x20running\x20Freshsales\x20integration',util[_0xa598('0x51')](_0x469794,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xfc8b=['user:%s','emit','trigger:browser:url','Token\x20token=','remoteUri','stripTrailingSlash','serverUrl','toLowerCase','destcalleridnum','calleridnum','callDirection','unmanaged','queue','outbound','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','Recording\x20is\x20enabled!','recordingURL','The\x20ticket\x20ID\x20is:\x20%s','name','lodash','request-promise','util','moment','ioredis','./util','../../../../config/environment','../../../../config/logger','freshsales','redis','defaults','localhost','socket.io-emitter','/api/selector/owners','headers','info','Getting\x20admin\x20information','then','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','catch','error','toUpperCase','GET','Getting\x20user\x20list','users','agentEmail','Getting\x20user\x20with\x20email','userEmail','length','email','User\x20found:','userId','adminEmail','/api/lookup?q=','&f=','&entities=contact','contacts','format','Searching\x20contact\x20with\x20phone\x20%s','contactNumber','endUserId','Contact\x20found\x20mobile_number:','Contact\x20found\x20work_number:','Contact\x20created:','POST','/api/contacts','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','message','Creating\x20new\x20task','/api/tasks','Subjects','getString','Descriptions','Contact','add','ticketId','task','Task\x20created:'];(function(_0x124d74,_0x18eda2){var _0x46418e=function(_0x75f580){while(--_0x75f580){_0x124d74['push'](_0x124d74['shift']());}};_0x46418e(++_0x18eda2);}(_0xfc8b,0xbb));var _0xbfc8=function(_0x8e98e6,_0x55b4bd){_0x8e98e6=_0x8e98e6-0x0;var _0x1d4063=_0xfc8b[_0x8e98e6];return _0x1d4063;};'use strict';var _=require(_0xbfc8('0x0'));var rp=require(_0xbfc8('0x1'));var md5=require('md5');var util=require(_0xbfc8('0x2'));var moment=require(_0xbfc8('0x3'));var Promise=require('bluebird');var Redis=require(_0xbfc8('0x4'));var intUtil=require(_0xbfc8('0x5'));var config=require(_0xbfc8('0x6'));var logger=require(_0xbfc8('0x7'))(_0xbfc8('0x8'));config[_0xbfc8('0x9')]=_[_0xbfc8('0xa')](config[_0xbfc8('0x9')],{'host':_0xbfc8('0xb'),'port':0x18eb});var io=require(_0xbfc8('0xc'))(new Redis(config[_0xbfc8('0x9')]));function getAdminId(_0x21c417,_0x311487,_0x5a4783,_0x4916d9){return new Promise(function(_0x5a044a,_0x2af829){var _0xdd4afc=![];var _0x15825c={'method':'GET','uri':_0x4916d9+_0xbfc8('0xd'),'json':!![]};_0x15825c[_0xbfc8('0xe')]=_0x5a4783;logger[_0xbfc8('0xf')](_0xbfc8('0x10'));return rp(_0x15825c)[_0xbfc8('0x11')](function(_0x2bdf9d){if(_0x2bdf9d){var _0x109e07=_0x2bdf9d['users'];var _0x28d3db=null;for(_0x28d3db=0x0;_0x28d3db<_0x109e07['length'];_0x28d3db++){if(_0x109e07[_0x28d3db]['email']===_0x21c417['adminEmail']){_0x21c417[_0xbfc8('0x12')]=_0x109e07[_0x28d3db]['id'];_0xdd4afc=!![];}}if(_0xdd4afc){logger[_0xbfc8('0xf')](_0xbfc8('0x13'),_0x21c417['adminId']);_0x5a044a(_0x21c417);}else{_0x2af829({'statusCode':0x194,'message':_0xbfc8('0x14')});}}else{_0x2af829({'statusCode':0x194,'message':_0xbfc8('0x14')});}})[_0xbfc8('0x15')](function(_0x62437e){logger[_0xbfc8('0x16')]('['+[_0x311487[_0xbfc8('0x17')]()]+']',_0x62437e['message']);_0x2af829(_0x62437e);});});}function getUser(_0x30d0d6,_0x19a0fa,_0x530122){return function(_0x5b6279){return new Promise(function(_0x39ea0d,_0x5eee63){var _0x183084={'method':_0xbfc8('0x18'),'uri':_0x530122+_0xbfc8('0xd'),'json':!![]};_0x183084[_0xbfc8('0xe')]=_0x19a0fa;logger['info'](_0xbfc8('0x19'));return rp(_0x183084)[_0xbfc8('0x11')](function(_0xa46d8){if(_0xa46d8){var _0x4e1914=_0xa46d8[_0xbfc8('0x1a')];var _0x44e4f8=![];var _0x6fa5df=null;if(_0x5b6279[_0xbfc8('0x1b')]!==null){logger[_0xbfc8('0xf')](_0xbfc8('0x1c'),_0x5b6279['agentEmail']);_0x5b6279[_0xbfc8('0x1d')]=_0x5b6279[_0xbfc8('0x1b')];for(_0x6fa5df=0x0;_0x6fa5df<_0x4e1914[_0xbfc8('0x1e')];_0x6fa5df++){if(_0x4e1914[_0x6fa5df][_0xbfc8('0x1f')]===_0x5b6279['agentEmail']){_0x44e4f8=!![];_0x5b6279['userId']=_0x4e1914[_0x6fa5df]['id'];logger[_0xbfc8('0xf')](_0xbfc8('0x20'),_0x5b6279[_0xbfc8('0x21')]);}}}if(!_0x44e4f8){logger[_0xbfc8('0xf')]('Admin\x20selected');_0x5b6279['userEmail']=_0x5b6279[_0xbfc8('0x22')];_0x5b6279[_0xbfc8('0x21')]=_0x5b6279[_0xbfc8('0x12')];_0x44e4f8=!![];}if(_0x44e4f8){_0x39ea0d(_0x5b6279);}else{_0x5eee63({'statusCode':0x194,'message':_0xbfc8('0x14')});}}else{_0x5eee63({'statusCode':0x194,'message':_0xbfc8('0x14')});}})[_0xbfc8('0x15')](function(_0x29fca9){logger[_0xbfc8('0x16')]('['+[_0x30d0d6['toUpperCase']()]+']',_0x29fca9['message']);_0x5eee63(_0x29fca9);});});};}function searchContact(_0x583d54,_0x2d3884,_0x4f02a0,_0x5df1ae){return new Promise(function(_0x413c45,_0x423953){var _0x3cce10={'method':'GET','headers':_0x2d3884,'uri':_0x583d54+_0xbfc8('0x23')+_0x5df1ae+_0xbfc8('0x24')+_0x4f02a0+_0xbfc8('0x25'),'json':!![]};rp(_0x3cce10)[_0xbfc8('0x11')](function(_0x361f12){var _0x3503e3=_['find'](_0x361f12[_0xbfc8('0x26')][_0xbfc8('0x26')],[_0x4f02a0,_0x5df1ae]);_0x413c45(_0x3503e3);})[_0xbfc8('0x15')](function(_0xa26e55){_0x423953(_0xa26e55);});});}function getEndUser(_0x2094ee,_0x15a97c,_0x3977af){return function(_0x1e3dcc){return new Promise(function(_0x17cfca,_0x40bd80){logger[_0xbfc8('0xf')](util[_0xbfc8('0x27')](_0xbfc8('0x28'),_0x1e3dcc[_0xbfc8('0x29')]));searchContact(_0x3977af,_0x15a97c,'mobile_number',_0x1e3dcc['contactNumber'])[_0xbfc8('0x11')](function(_0x54d854){if(_0x54d854){_0x1e3dcc[_0xbfc8('0x2a')]=_0x54d854['id'];logger[_0xbfc8('0xf')](_0xbfc8('0x2b'),_0x1e3dcc['endUserId']);return _0x17cfca(_0x1e3dcc);}searchContact(_0x3977af,_0x15a97c,'work_number',_0x1e3dcc['contactNumber'])[_0xbfc8('0x11')](function(_0x23304a){if(_0x23304a){_0x1e3dcc[_0xbfc8('0x2a')]=_0x23304a['id'];logger['info'](_0xbfc8('0x2c'),_0x1e3dcc[_0xbfc8('0x2a')]);return _0x17cfca(_0x1e3dcc);}createEndUser(_0x1e3dcc,_0x2094ee,_0x15a97c,_0x3977af)[_0xbfc8('0x11')](function(_0x1dab13){logger[_0xbfc8('0xf')](_0xbfc8('0x2d'),_0x1dab13[_0xbfc8('0x2a')]);return _0x17cfca(_0x1dab13);});});})[_0xbfc8('0x15')](function(_0x2dbe92){_0x40bd80(_0x2dbe92);});});};}function createEndUser(_0x2ebff2,_0x46dcbf,_0x318801,_0x306ebf){return new Promise(function(_0xb7cd38,_0x390610){var _0x24dbf2=moment();var _0x1c6e05={'method':_0xbfc8('0x2e'),'uri':_0x306ebf+_0xbfc8('0x2f'),'body':{'contact':{'last_name':_0x2ebff2[_0xbfc8('0x29')],'work_number':_0x2ebff2[_0xbfc8('0x29')],'mobile_number':_0x2ebff2['contactNumber'],'owner_id':_0x2ebff2[_0xbfc8('0x21')],'created_at':_0x24dbf2[_0xbfc8('0x27')](_0xbfc8('0x30'))}},'json':!![]};_0x1c6e05[_0xbfc8('0xe')]=_0x318801;logger[_0xbfc8('0xf')](_0xbfc8('0x31'));return rp(_0x1c6e05)[_0xbfc8('0x11')](function(_0x5d506a){_0x2ebff2[_0xbfc8('0x2a')]=_0x5d506a[_0xbfc8('0x32')]['id'];_0xb7cd38(_0x2ebff2);})[_0xbfc8('0x15')](function(_0x3ab6ea){logger[_0xbfc8('0x16')]('['+[_0x46dcbf[_0xbfc8('0x17')]()]+']',_0x3ab6ea['message']);_0x390610(_0x3ab6ea[_0xbfc8('0x33')]);});});}function getTicket(_0x385c69,_0x2afbac,_0x5c1449,_0x569943,_0x32ef79){return function(_0x54916c){logger[_0xbfc8('0xf')](_0xbfc8('0x34'));return new Promise(function(_0x3f461d,_0x46e908){var _0x1966f8=moment();var _0x5080ac={'method':_0xbfc8('0x2e'),'uri':_0x5c1449+_0xbfc8('0x35'),'body':{'title':intUtil['getString'](_0x569943[_0xbfc8('0x36')],_0x32ef79,'\x20'),'description':intUtil[_0xbfc8('0x37')](_0x569943[_0xbfc8('0x38')],_0x32ef79,'\x0a'),'owner_id':_0x54916c['userId'],'creater_id':_0x54916c[_0xbfc8('0x12')],'targetable_id':_0x54916c[_0xbfc8('0x2a')],'targetable_type':_0xbfc8('0x39'),'created_at':_0x1966f8[_0xbfc8('0x27')](_0xbfc8('0x30')),'due_date':_0x1966f8[_0xbfc8('0x3a')](0x1e,'m')['format'](_0xbfc8('0x30'))},'json':!![]};_0x5080ac['headers']=_0x2afbac;return rp(_0x5080ac)[_0xbfc8('0x11')](function(_0x58321b){_0x54916c[_0xbfc8('0x3b')]=_0x58321b[_0xbfc8('0x3c')]['id'];logger[_0xbfc8('0xf')](_0xbfc8('0x3d'),_0x54916c[_0xbfc8('0x3b')]);_0x3f461d(_0x54916c);})[_0xbfc8('0x15')](function(_0x3248dc){logger['error']('['+[_0x385c69[_0xbfc8('0x17')]()]+']',_0x3248dc[_0xbfc8('0x33')]);_0x46e908(_0x3248dc[_0xbfc8('0x33')]);});});};}function emit(_0x512001,_0x3d6fc2,_0x30042e){var _0x10d298={'uri':_0x512001+'/contacts/'+_0x30042e};io['to'](util[_0xbfc8('0x27')](_0xbfc8('0x3e'),_0x3d6fc2))[_0xbfc8('0x3f')](_0xbfc8('0x40'),_0x10d298);}exports['cs']=function(_0x42213e,_0x3fe18a,_0x3ad7d7,_0x32536f,_0x2800cb,_0x3509b2,_0x1a612c,_0x56b983){var _0x444756={};var _0x535e06={'Authorization':_0xbfc8('0x41')+_0x3509b2['apiKey']};_0x3509b2[_0xbfc8('0x42')]=intUtil[_0xbfc8('0x43')](_0x3509b2[_0xbfc8('0x42')]);_0x3509b2[_0xbfc8('0x44')]=intUtil[_0xbfc8('0x43')](_0x3509b2['serverUrl']);var _0x324e7e=_0x3509b2[_0xbfc8('0x42')];_0x444756[_0xbfc8('0x22')]=_0x3509b2['username'];_0x444756[_0xbfc8('0x29')]=_0x56b983[_0xbfc8('0x45')]()==='outbound'?_0x3fe18a[_0xbfc8('0x46')]:_0x3fe18a[_0xbfc8('0x47')];_0x444756[_0xbfc8('0x48')]=_0x56b983==='queue'||_0x56b983===_0xbfc8('0x49')?_0xbfc8('0x4a'):_0xbfc8('0x4b');if(_0x32536f){_0x444756['agentEmail']=_0x32536f['email'];}var _0x44fd1e=util[_0xbfc8('0x27')](_0xbfc8('0x4c'),_0x3509b2[_0xbfc8('0x44')],_0x3fe18a[_0xbfc8('0x4d')],md5(_0x3fe18a[_0xbfc8('0x4d')]));if(_0x2800cb&&_0x2800cb[_0xbfc8('0x4e')]){logger[_0xbfc8('0xf')]('[QUEUE]',_0xbfc8('0x4f'));_0x3fe18a[_0xbfc8('0x50')]=_0x44fd1e;}else if(_0x1a612c&&_0x1a612c['recordingFormat']&&_0x1a612c['recordingFormat']!=='none'){logger[_0xbfc8('0xf')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x3fe18a['recordingURL']=_0x44fd1e;}else{_0x3fe18a[_0xbfc8('0x50')]='';}return getAdminId(_0x444756,_0x56b983,_0x535e06,_0x324e7e)[_0xbfc8('0x11')](getUser(_0x56b983,_0x535e06,_0x324e7e))[_0xbfc8('0x11')](getEndUser(_0x56b983,_0x535e06,_0x324e7e))['then'](getTicket(_0x56b983,_0x535e06,_0x324e7e,_0x3ad7d7,_0x3fe18a))[_0xbfc8('0x11')](function(_0x58689a){logger[_0xbfc8('0xf')](util['format'](_0xbfc8('0x51'),_0x58689a[_0xbfc8('0x3b')]));if(_0x56b983!==_0xbfc8('0x49')){logger['info']('['+[_0x56b983['toUpperCase']()]+']','Displaying\x20task\x20in\x20a\x20new\x20tab...');emit(_0x324e7e,_0x32536f[_0xbfc8('0x52')],_0x58689a[_0xbfc8('0x2a')]);}})[_0xbfc8('0x15')](function(_0x3c9261){logger[_0xbfc8('0x16')]('['+[_0x56b983['toUpperCase']()]+']\x20Error\x20running\x20Freshsales\x20integration',util['inspect'](_0x3c9261,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file