Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 0f131e2..e28a9ea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xafc4=['queue','unmanaged','outbound','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]','Displaying\x20task\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Freshsales\x20integration','inspect','lodash','md5','moment','bluebird','ioredis','./util','redis','defaults','localhost','socket.io-emitter','/api/selector/owners','info','Getting\x20admin\x20information','users','length','email','adminEmail','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','error','message','GET','headers','Getting\x20user\x20list','then','agentEmail','Getting\x20user\x20with\x20email','userEmail','userId','User\x20found:','Admin\x20selected','catch','/api/lookup?q=','&f=','find','contacts','format','Searching\x20contact\x20with\x20phone\x20%s','mobile_number','endUserId','Contact\x20found\x20mobile_number:','work_number','Contact\x20found\x20work_number:','Contact\x20created:','POST','/api/contacts','contactNumber','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','toUpperCase','/api/tasks','getString','Subjects','Descriptions','add','ticketId','task','Task\x20created:','/contacts/','user:%s','emit','trigger:browser:url','Token\x20token=','apiKey','remoteUri','stripTrailingSlash','serverUrl','username','toLowerCase','destcalleridnum','callDirection'];(function(_0x1ea034,_0x476985){var _0x2a16c1=function(_0x2d8a2c){while(--_0x2d8a2c){_0x1ea034['push'](_0x1ea034['shift']());}};_0x2a16c1(++_0x476985);}(_0xafc4,0x69));var _0x4afc=function(_0x2177ae,_0x2e9815){_0x2177ae=_0x2177ae-0x0;var _0x31e38f=_0xafc4[_0x2177ae];return _0x31e38f;};'use strict';var _=require(_0x4afc('0x0'));var rp=require('request-promise');var md5=require(_0x4afc('0x1'));var util=require('util');var moment=require(_0x4afc('0x2'));var Promise=require(_0x4afc('0x3'));var Redis=require(_0x4afc('0x4'));var intUtil=require(_0x4afc('0x5'));var config=require('../../../../config/environment');var logger=require('../../../../config/logger')('freshsales');config[_0x4afc('0x6')]=_[_0x4afc('0x7')](config[_0x4afc('0x6')],{'host':_0x4afc('0x8'),'port':0x18eb});var io=require(_0x4afc('0x9'))(new Redis(config[_0x4afc('0x6')]));function getAdminId(_0x5e1e29,_0x31e165,_0x1c740c,_0x134aad){return new Promise(function(_0x1e6bf5,_0x1b8981){var _0x458fde=![];var _0x5542ec={'method':'GET','uri':_0x134aad+_0x4afc('0xa'),'json':!![]};_0x5542ec['headers']=_0x1c740c;logger[_0x4afc('0xb')](_0x4afc('0xc'));return rp(_0x5542ec)['then'](function(_0x38b322){if(_0x38b322){var _0x3fb54a=_0x38b322[_0x4afc('0xd')];var _0x2768bf=null;for(_0x2768bf=0x0;_0x2768bf<_0x3fb54a[_0x4afc('0xe')];_0x2768bf++){if(_0x3fb54a[_0x2768bf][_0x4afc('0xf')]===_0x5e1e29[_0x4afc('0x10')]){_0x5e1e29[_0x4afc('0x11')]=_0x3fb54a[_0x2768bf]['id'];_0x458fde=!![];}}if(_0x458fde){logger['info'](_0x4afc('0x12'),_0x5e1e29[_0x4afc('0x11')]);_0x1e6bf5(_0x5e1e29);}else{_0x1b8981({'statusCode':0x194,'message':_0x4afc('0x13')});}}else{_0x1b8981({'statusCode':0x194,'message':_0x4afc('0x13')});}})['catch'](function(_0x4e32e8){logger[_0x4afc('0x14')]('['+[_0x31e165['toUpperCase']()]+']',_0x4e32e8[_0x4afc('0x15')]);_0x1b8981(_0x4e32e8);});});}function getUser(_0x24ed6d,_0x2b928b,_0x31eec4){return function(_0x3a306f){return new Promise(function(_0x3ebdc8,_0x22f809){var _0x3ad418={'method':_0x4afc('0x16'),'uri':_0x31eec4+_0x4afc('0xa'),'json':!![]};_0x3ad418[_0x4afc('0x17')]=_0x2b928b;logger['info'](_0x4afc('0x18'));return rp(_0x3ad418)[_0x4afc('0x19')](function(_0x32865e){if(_0x32865e){var _0x14558a=_0x32865e['users'];var _0x3bddc0=![];var _0x30eda3=null;if(_0x3a306f[_0x4afc('0x1a')]!==null){logger[_0x4afc('0xb')](_0x4afc('0x1b'),_0x3a306f[_0x4afc('0x1a')]);_0x3a306f[_0x4afc('0x1c')]=_0x3a306f['agentEmail'];for(_0x30eda3=0x0;_0x30eda3<_0x14558a[_0x4afc('0xe')];_0x30eda3++){if(_0x14558a[_0x30eda3][_0x4afc('0xf')]===_0x3a306f['agentEmail']){_0x3bddc0=!![];_0x3a306f[_0x4afc('0x1d')]=_0x14558a[_0x30eda3]['id'];logger['info'](_0x4afc('0x1e'),_0x3a306f[_0x4afc('0x1d')]);}}}if(!_0x3bddc0){logger[_0x4afc('0xb')](_0x4afc('0x1f'));_0x3a306f[_0x4afc('0x1c')]=_0x3a306f[_0x4afc('0x10')];_0x3a306f[_0x4afc('0x1d')]=_0x3a306f[_0x4afc('0x11')];_0x3bddc0=!![];}if(_0x3bddc0){_0x3ebdc8(_0x3a306f);}else{_0x22f809({'statusCode':0x194,'message':_0x4afc('0x13')});}}else{_0x22f809({'statusCode':0x194,'message':_0x4afc('0x13')});}})[_0x4afc('0x20')](function(_0x359c07){logger[_0x4afc('0x14')]('['+[_0x24ed6d['toUpperCase']()]+']',_0x359c07[_0x4afc('0x15')]);_0x22f809(_0x359c07);});});};}function searchContact(_0x244f6c,_0x2d6112,_0x4e254d,_0x52212d){return new Promise(function(_0x54433f,_0x426e9d){var _0x5db47e={'method':'GET','headers':_0x2d6112,'uri':_0x244f6c+_0x4afc('0x21')+_0x52212d+_0x4afc('0x22')+_0x4e254d+'&entities=contact','json':!![]};rp(_0x5db47e)['then'](function(_0x52e3dd){var _0x3bae1a=_[_0x4afc('0x23')](_0x52e3dd[_0x4afc('0x24')][_0x4afc('0x24')],[_0x4e254d,_0x52212d]);_0x54433f(_0x3bae1a);})[_0x4afc('0x20')](function(_0x28cd3e){_0x426e9d(_0x28cd3e);});});}function getEndUser(_0x566389,_0x290391,_0x3d1693){return function(_0x1ba6b5){return new Promise(function(_0x2f178c,_0x2b115d){logger[_0x4afc('0xb')](util[_0x4afc('0x25')](_0x4afc('0x26'),_0x1ba6b5['contactNumber']));searchContact(_0x3d1693,_0x290391,_0x4afc('0x27'),_0x1ba6b5['contactNumber'])['then'](function(_0x324a12){if(_0x324a12){_0x1ba6b5[_0x4afc('0x28')]=_0x324a12['id'];logger[_0x4afc('0xb')](_0x4afc('0x29'),_0x1ba6b5[_0x4afc('0x28')]);return _0x2f178c(_0x1ba6b5);}searchContact(_0x3d1693,_0x290391,_0x4afc('0x2a'),_0x1ba6b5['contactNumber'])[_0x4afc('0x19')](function(_0x2d0ad8){if(_0x2d0ad8){_0x1ba6b5[_0x4afc('0x28')]=_0x2d0ad8['id'];logger[_0x4afc('0xb')](_0x4afc('0x2b'),_0x1ba6b5[_0x4afc('0x28')]);return _0x2f178c(_0x1ba6b5);}createEndUser(_0x1ba6b5,_0x566389,_0x290391,_0x3d1693)['then'](function(_0x22eea2){logger[_0x4afc('0xb')](_0x4afc('0x2c'),_0x22eea2[_0x4afc('0x28')]);return _0x2f178c(_0x22eea2);});});})['catch'](function(_0x4be1e6){_0x2b115d(_0x4be1e6);});});};}function createEndUser(_0x43c341,_0x22bd75,_0x17ea03,_0x5edfe1){return new Promise(function(_0x5790a2,_0x391120){var _0x4a06cf=moment();var _0x5947bb={'method':_0x4afc('0x2d'),'uri':_0x5edfe1+_0x4afc('0x2e'),'body':{'contact':{'last_name':_0x43c341[_0x4afc('0x2f')],'work_number':_0x43c341[_0x4afc('0x2f')],'mobile_number':_0x43c341[_0x4afc('0x2f')],'owner_id':_0x43c341[_0x4afc('0x1d')],'created_at':_0x4a06cf[_0x4afc('0x25')](_0x4afc('0x30'))}},'json':!![]};_0x5947bb[_0x4afc('0x17')]=_0x17ea03;logger[_0x4afc('0xb')](_0x4afc('0x31'));return rp(_0x5947bb)[_0x4afc('0x19')](function(_0x15c6cb){_0x43c341[_0x4afc('0x28')]=_0x15c6cb[_0x4afc('0x32')]['id'];_0x5790a2(_0x43c341);})['catch'](function(_0xd48eea){logger[_0x4afc('0x14')]('['+[_0x22bd75[_0x4afc('0x33')]()]+']',_0xd48eea[_0x4afc('0x15')]);_0x391120(_0xd48eea[_0x4afc('0x15')]);});});}function getTicket(_0x260b06,_0x3e87f0,_0x50d53f,_0x5e97f4,_0x5ee5d7){return function(_0x43bd0f){logger[_0x4afc('0xb')]('Creating\x20new\x20task');return new Promise(function(_0xe62748,_0x38a1bb){var _0x8ba5e6=moment();var _0x397996={'method':'POST','uri':_0x50d53f+_0x4afc('0x34'),'body':{'title':intUtil[_0x4afc('0x35')](_0x5e97f4[_0x4afc('0x36')],_0x5ee5d7,'\x20'),'description':intUtil[_0x4afc('0x35')](_0x5e97f4[_0x4afc('0x37')],_0x5ee5d7,'\x0a'),'owner_id':_0x43bd0f[_0x4afc('0x1d')],'creater_id':_0x43bd0f['adminId'],'targetable_id':_0x43bd0f[_0x4afc('0x28')],'targetable_type':'Contact','created_at':_0x8ba5e6[_0x4afc('0x25')](_0x4afc('0x30')),'due_date':_0x8ba5e6[_0x4afc('0x38')](0x1e,'m')['format']('YYYY-MM-DDTHH:mm:ss')},'json':!![]};_0x397996[_0x4afc('0x17')]=_0x3e87f0;return rp(_0x397996)[_0x4afc('0x19')](function(_0x2cf64e){_0x43bd0f[_0x4afc('0x39')]=_0x2cf64e[_0x4afc('0x3a')]['id'];logger[_0x4afc('0xb')](_0x4afc('0x3b'),_0x43bd0f[_0x4afc('0x39')]);_0xe62748(_0x43bd0f);})['catch'](function(_0x658c5b){logger[_0x4afc('0x14')]('['+[_0x260b06['toUpperCase']()]+']',_0x658c5b[_0x4afc('0x15')]);_0x38a1bb(_0x658c5b['message']);});});};}function emit(_0x20a2d3,_0x24a731,_0x16c6c4){var _0x5e0ebd={'uri':_0x20a2d3+_0x4afc('0x3c')+_0x16c6c4};io['to'](util[_0x4afc('0x25')](_0x4afc('0x3d'),_0x24a731))[_0x4afc('0x3e')](_0x4afc('0x3f'),_0x5e0ebd);}exports['cs']=function(_0x19a0ac,_0x5d9d90,_0x4e470d,_0x4f4e46,_0x32f3b9,_0x1c5661,_0x42e274,_0x269c24){var _0xb5cca9={};var _0x122cbc={'Authorization':_0x4afc('0x40')+_0x1c5661[_0x4afc('0x41')]};_0x1c5661[_0x4afc('0x42')]=intUtil[_0x4afc('0x43')](_0x1c5661['remoteUri']);_0x1c5661[_0x4afc('0x44')]=intUtil['stripTrailingSlash'](_0x1c5661['serverUrl']);var _0x46599a=_0x1c5661['remoteUri'];_0xb5cca9[_0x4afc('0x10')]=_0x1c5661[_0x4afc('0x45')];_0xb5cca9[_0x4afc('0x2f')]=_0x269c24[_0x4afc('0x46')]()==='outbound'?_0x5d9d90[_0x4afc('0x47')]:_0x5d9d90['calleridnum'];_0xb5cca9[_0x4afc('0x48')]=_0x269c24===_0x4afc('0x49')||_0x269c24===_0x4afc('0x4a')?_0x4afc('0x49'):_0x4afc('0x4b');if(_0x4f4e46){_0xb5cca9[_0x4afc('0x1a')]=_0x4f4e46[_0x4afc('0xf')];}var _0x12fa43=util[_0x4afc('0x25')](_0x4afc('0x4c'),_0x1c5661[_0x4afc('0x44')],_0x5d9d90[_0x4afc('0x4d')],md5(_0x5d9d90['uniqueid']));if(_0x32f3b9&&_0x32f3b9[_0x4afc('0x4e')]){logger[_0x4afc('0xb')](_0x4afc('0x4f'),_0x4afc('0x50'));_0x5d9d90[_0x4afc('0x51')]=_0x12fa43;}else if(_0x42e274&&_0x42e274[_0x4afc('0x52')]&&_0x42e274[_0x4afc('0x52')]!==_0x4afc('0x53')){logger[_0x4afc('0xb')](_0x4afc('0x54'),_0x4afc('0x50'));_0x5d9d90[_0x4afc('0x51')]=_0x12fa43;}else{_0x5d9d90[_0x4afc('0x51')]='';}return getAdminId(_0xb5cca9,_0x269c24,_0x122cbc,_0x46599a)['then'](getUser(_0x269c24,_0x122cbc,_0x46599a))[_0x4afc('0x19')](getEndUser(_0x269c24,_0x122cbc,_0x46599a))['then'](getTicket(_0x269c24,_0x122cbc,_0x46599a,_0x4e470d,_0x5d9d90))[_0x4afc('0x19')](function(_0x2abc1b){logger[_0x4afc('0xb')](util[_0x4afc('0x25')]('The\x20ticket\x20ID\x20is:\x20%s',_0x2abc1b['ticketId']));if(_0x269c24!==_0x4afc('0x4a')){logger[_0x4afc('0xb')]('['+[_0x269c24['toUpperCase']()]+']',_0x4afc('0x55'));emit(_0x46599a,_0x4f4e46[_0x4afc('0x56')],_0x2abc1b[_0x4afc('0x28')]);}})[_0x4afc('0x20')](function(_0x329550){logger[_0x4afc('0x14')]('['+[_0x269c24[_0x4afc('0x33')]()]+_0x4afc('0x57'),util[_0x4afc('0x58')](_0x329550,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xb0d1=['bluebird','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','socket.io-emitter','GET','/api/selector/owners','headers','Getting\x20admin\x20information','then','users','length','email','adminEmail','info','Admin\x20found:','adminId','Requested\x20Resource\x20not\x20Found','catch','toUpperCase','Getting\x20user\x20with\x20email','agentEmail','userEmail','userId','Admin\x20selected','error','message','&f=','&entities=contact','find','contacts','format','contactNumber','mobile_number','endUserId','work_number','Contact\x20found\x20work_number:','Contact\x20created:','POST','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','Creating\x20new\x20task','Subjects','getString','Descriptions','Contact','ticketId','Task\x20created:','emit','trigger:browser:url','Token\x20token=','apiKey','remoteUri','serverUrl','username','toLowerCase','destcalleridnum','calleridnum','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','name','lodash','util','moment'];(function(_0x1facfa,_0x1acf7d){var _0x9ec701=function(_0x115e37){while(--_0x115e37){_0x1facfa['push'](_0x1facfa['shift']());}};_0x9ec701(++_0x1acf7d);}(_0xb0d1,0x9b));var _0x1b0d=function(_0x2b12f7,_0x39f636){_0x2b12f7=_0x2b12f7-0x0;var _0x33942b=_0xb0d1[_0x2b12f7];return _0x33942b;};'use strict';var _=require(_0x1b0d('0x0'));var rp=require('request-promise');var md5=require('md5');var util=require(_0x1b0d('0x1'));var moment=require(_0x1b0d('0x2'));var Promise=require(_0x1b0d('0x3'));var Redis=require(_0x1b0d('0x4'));var intUtil=require(_0x1b0d('0x5'));var config=require(_0x1b0d('0x6'));var logger=require(_0x1b0d('0x7'))('freshsales');config[_0x1b0d('0x8')]=_[_0x1b0d('0x9')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x1b0d('0xa'))(new Redis(config[_0x1b0d('0x8')]));function getAdminId(_0x39fac8,_0x23fb7b,_0x2863e6,_0x43cc0f){return new Promise(function(_0x3c8b5b,_0x2a6c0f){var _0x4629b3=![];var _0x4b4eb2={'method':_0x1b0d('0xb'),'uri':_0x43cc0f+_0x1b0d('0xc'),'json':!![]};_0x4b4eb2[_0x1b0d('0xd')]=_0x2863e6;logger['info'](_0x1b0d('0xe'));return rp(_0x4b4eb2)[_0x1b0d('0xf')](function(_0x4d18c6){if(_0x4d18c6){var _0x378430=_0x4d18c6[_0x1b0d('0x10')];var _0x15d829=null;for(_0x15d829=0x0;_0x15d829<_0x378430[_0x1b0d('0x11')];_0x15d829++){if(_0x378430[_0x15d829][_0x1b0d('0x12')]===_0x39fac8[_0x1b0d('0x13')]){_0x39fac8['adminId']=_0x378430[_0x15d829]['id'];_0x4629b3=!![];}}if(_0x4629b3){logger[_0x1b0d('0x14')](_0x1b0d('0x15'),_0x39fac8[_0x1b0d('0x16')]);_0x3c8b5b(_0x39fac8);}else{_0x2a6c0f({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}else{_0x2a6c0f({'statusCode':0x194,'message':_0x1b0d('0x17')});}})[_0x1b0d('0x18')](function(_0x9330b0){logger['error']('['+[_0x23fb7b[_0x1b0d('0x19')]()]+']',_0x9330b0['message']);_0x2a6c0f(_0x9330b0);});});}function getUser(_0x171bfa,_0x508640,_0x3e521b){return function(_0x35b72e){return new Promise(function(_0x1f8443,_0x3076bf){var _0x58357f={'method':_0x1b0d('0xb'),'uri':_0x3e521b+_0x1b0d('0xc'),'json':!![]};_0x58357f['headers']=_0x508640;logger[_0x1b0d('0x14')]('Getting\x20user\x20list');return rp(_0x58357f)[_0x1b0d('0xf')](function(_0x349c17){if(_0x349c17){var _0x12af86=_0x349c17[_0x1b0d('0x10')];var _0x2f1171=![];var _0x584c5c=null;if(_0x35b72e['agentEmail']!==null){logger[_0x1b0d('0x14')](_0x1b0d('0x1a'),_0x35b72e[_0x1b0d('0x1b')]);_0x35b72e[_0x1b0d('0x1c')]=_0x35b72e['agentEmail'];for(_0x584c5c=0x0;_0x584c5c<_0x12af86[_0x1b0d('0x11')];_0x584c5c++){if(_0x12af86[_0x584c5c][_0x1b0d('0x12')]===_0x35b72e[_0x1b0d('0x1b')]){_0x2f1171=!![];_0x35b72e[_0x1b0d('0x1d')]=_0x12af86[_0x584c5c]['id'];logger[_0x1b0d('0x14')]('User\x20found:',_0x35b72e[_0x1b0d('0x1d')]);}}}if(!_0x2f1171){logger[_0x1b0d('0x14')](_0x1b0d('0x1e'));_0x35b72e[_0x1b0d('0x1c')]=_0x35b72e['adminEmail'];_0x35b72e[_0x1b0d('0x1d')]=_0x35b72e[_0x1b0d('0x16')];_0x2f1171=!![];}if(_0x2f1171){_0x1f8443(_0x35b72e);}else{_0x3076bf({'statusCode':0x194,'message':_0x1b0d('0x17')});}}else{_0x3076bf({'statusCode':0x194,'message':_0x1b0d('0x17')});}})[_0x1b0d('0x18')](function(_0x35d7f6){logger[_0x1b0d('0x1f')]('['+[_0x171bfa[_0x1b0d('0x19')]()]+']',_0x35d7f6[_0x1b0d('0x20')]);_0x3076bf(_0x35d7f6);});});};}function searchContact(_0x22b95b,_0x5bcb12,_0x116311,_0x1e1f0f){return new Promise(function(_0x30cdfd,_0x235659){var _0x390f37={'method':_0x1b0d('0xb'),'headers':_0x5bcb12,'uri':_0x22b95b+'/api/lookup?q='+_0x1e1f0f+_0x1b0d('0x21')+_0x116311+_0x1b0d('0x22'),'json':!![]};rp(_0x390f37)[_0x1b0d('0xf')](function(_0x3cfedb){var _0xac8957=_[_0x1b0d('0x23')](_0x3cfedb[_0x1b0d('0x24')]['contacts'],[_0x116311,_0x1e1f0f]);_0x30cdfd(_0xac8957);})[_0x1b0d('0x18')](function(_0x67f048){_0x235659(_0x67f048);});});}function getEndUser(_0x12cf58,_0x16a079,_0x3e29c7){return function(_0x45f23c){return new Promise(function(_0x573db2,_0x2ca5e5){logger['info'](util[_0x1b0d('0x25')]('Searching\x20contact\x20with\x20phone\x20%s',_0x45f23c[_0x1b0d('0x26')]));searchContact(_0x3e29c7,_0x16a079,_0x1b0d('0x27'),_0x45f23c[_0x1b0d('0x26')])[_0x1b0d('0xf')](function(_0x1b3e67){if(_0x1b3e67){_0x45f23c['endUserId']=_0x1b3e67['id'];logger['info']('Contact\x20found\x20mobile_number:',_0x45f23c[_0x1b0d('0x28')]);return _0x573db2(_0x45f23c);}searchContact(_0x3e29c7,_0x16a079,_0x1b0d('0x29'),_0x45f23c[_0x1b0d('0x26')])[_0x1b0d('0xf')](function(_0xe1a528){if(_0xe1a528){_0x45f23c[_0x1b0d('0x28')]=_0xe1a528['id'];logger[_0x1b0d('0x14')](_0x1b0d('0x2a'),_0x45f23c[_0x1b0d('0x28')]);return _0x573db2(_0x45f23c);}createEndUser(_0x45f23c,_0x12cf58,_0x16a079,_0x3e29c7)['then'](function(_0x2d8f7a){logger['info'](_0x1b0d('0x2b'),_0x2d8f7a[_0x1b0d('0x28')]);return _0x573db2(_0x2d8f7a);});});})[_0x1b0d('0x18')](function(_0x16b11b){_0x2ca5e5(_0x16b11b);});});};}function createEndUser(_0x49e889,_0x2967f1,_0x1530ac,_0x16214b){return new Promise(function(_0x227fec,_0x4ab664){var _0xa1b53a=moment();var _0x461863={'method':_0x1b0d('0x2c'),'uri':_0x16214b+'/api/contacts','body':{'contact':{'last_name':_0x49e889[_0x1b0d('0x26')],'work_number':_0x49e889[_0x1b0d('0x26')],'mobile_number':_0x49e889[_0x1b0d('0x26')],'owner_id':_0x49e889[_0x1b0d('0x1d')],'created_at':_0xa1b53a[_0x1b0d('0x25')](_0x1b0d('0x2d'))}},'json':!![]};_0x461863[_0x1b0d('0xd')]=_0x1530ac;logger[_0x1b0d('0x14')](_0x1b0d('0x2e'));return rp(_0x461863)['then'](function(_0xdbf740){_0x49e889[_0x1b0d('0x28')]=_0xdbf740[_0x1b0d('0x2f')]['id'];_0x227fec(_0x49e889);})[_0x1b0d('0x18')](function(_0x4012aa){logger[_0x1b0d('0x1f')]('['+[_0x2967f1[_0x1b0d('0x19')]()]+']',_0x4012aa['message']);_0x4ab664(_0x4012aa['message']);});});}function getTicket(_0x39753a,_0x1cb35f,_0x30befc,_0x466cd5,_0x412f3d){return function(_0x278786){logger[_0x1b0d('0x14')](_0x1b0d('0x30'));return new Promise(function(_0x27ad53,_0x15db7e){var _0x54ca73=moment();var _0x4573b5={'method':'POST','uri':_0x30befc+'/api/tasks','body':{'title':intUtil['getString'](_0x466cd5[_0x1b0d('0x31')],_0x412f3d,'\x20'),'description':intUtil[_0x1b0d('0x32')](_0x466cd5[_0x1b0d('0x33')],_0x412f3d,'\x0a'),'owner_id':_0x278786[_0x1b0d('0x1d')],'creater_id':_0x278786[_0x1b0d('0x16')],'targetable_id':_0x278786[_0x1b0d('0x28')],'targetable_type':_0x1b0d('0x34'),'created_at':_0x54ca73[_0x1b0d('0x25')](_0x1b0d('0x2d')),'due_date':_0x54ca73['add'](0x1e,'m')[_0x1b0d('0x25')](_0x1b0d('0x2d'))},'json':!![]};_0x4573b5['headers']=_0x1cb35f;return rp(_0x4573b5)['then'](function(_0x47f8c6){_0x278786[_0x1b0d('0x35')]=_0x47f8c6['task']['id'];logger[_0x1b0d('0x14')](_0x1b0d('0x36'),_0x278786[_0x1b0d('0x35')]);_0x27ad53(_0x278786);})[_0x1b0d('0x18')](function(_0x2ab217){logger[_0x1b0d('0x1f')]('['+[_0x39753a[_0x1b0d('0x19')]()]+']',_0x2ab217['message']);_0x15db7e(_0x2ab217['message']);});});};}function emit(_0x48dd87,_0x16cf54,_0x55b665){var _0x571a7c={'uri':_0x48dd87+'/contacts/'+_0x55b665};io['to'](util[_0x1b0d('0x25')]('user:%s',_0x16cf54))[_0x1b0d('0x37')](_0x1b0d('0x38'),_0x571a7c);}exports['cs']=function(_0x5767bb,_0x48cd89,_0x535f03,_0x122091,_0x167f91,_0x428ab0,_0x83145a,_0x1db841){var _0xa9cd0e={};var _0x107a59={'Authorization':_0x1b0d('0x39')+_0x428ab0[_0x1b0d('0x3a')]};_0x428ab0[_0x1b0d('0x3b')]=intUtil['stripTrailingSlash'](_0x428ab0[_0x1b0d('0x3b')]);_0x428ab0['serverUrl']=intUtil['stripTrailingSlash'](_0x428ab0[_0x1b0d('0x3c')]);var _0x56d077=_0x428ab0[_0x1b0d('0x3b')];_0xa9cd0e[_0x1b0d('0x13')]=_0x428ab0[_0x1b0d('0x3d')];_0xa9cd0e[_0x1b0d('0x26')]=_0x1db841[_0x1b0d('0x3e')]()==='outbound'?_0x48cd89[_0x1b0d('0x3f')]:_0x48cd89[_0x1b0d('0x40')];_0xa9cd0e[_0x1b0d('0x41')]=_0x1db841===_0x1b0d('0x42')||_0x1db841===_0x1b0d('0x43')?_0x1b0d('0x42'):'outbound';if(_0x122091){_0xa9cd0e['agentEmail']=_0x122091[_0x1b0d('0x12')];}var _0x2ec4af=util[_0x1b0d('0x25')](_0x1b0d('0x44'),_0x428ab0[_0x1b0d('0x3c')],_0x48cd89[_0x1b0d('0x45')],md5(_0x48cd89[_0x1b0d('0x45')]));if(_0x167f91&&_0x167f91[_0x1b0d('0x46')]){logger[_0x1b0d('0x14')](_0x1b0d('0x47'),_0x1b0d('0x48'));_0x48cd89[_0x1b0d('0x49')]=_0x2ec4af;}else if(_0x83145a&&_0x83145a[_0x1b0d('0x4a')]&&_0x83145a[_0x1b0d('0x4a')]!==_0x1b0d('0x4b')){logger[_0x1b0d('0x14')](_0x1b0d('0x4c'),'Recording\x20is\x20enabled!');_0x48cd89[_0x1b0d('0x49')]=_0x2ec4af;}else{_0x48cd89[_0x1b0d('0x49')]='';}return getAdminId(_0xa9cd0e,_0x1db841,_0x107a59,_0x56d077)[_0x1b0d('0xf')](getUser(_0x1db841,_0x107a59,_0x56d077))[_0x1b0d('0xf')](getEndUser(_0x1db841,_0x107a59,_0x56d077))[_0x1b0d('0xf')](getTicket(_0x1db841,_0x107a59,_0x56d077,_0x535f03,_0x48cd89))[_0x1b0d('0xf')](function(_0x4e6bd3){logger[_0x1b0d('0x14')](util[_0x1b0d('0x25')](_0x1b0d('0x4d'),_0x4e6bd3['ticketId']));if(_0x1db841!=='unmanaged'){logger[_0x1b0d('0x14')]('['+[_0x1db841['toUpperCase']()]+']','Displaying\x20task\x20in\x20a\x20new\x20tab...');emit(_0x56d077,_0x122091[_0x1b0d('0x4e')],_0x4e6bd3[_0x1b0d('0x28')]);}})[_0x1b0d('0x18')](function(_0x5cbffd){logger[_0x1b0d('0x1f')]('['+[_0x1db841['toUpperCase']()]+']\x20Error\x20running\x20Freshsales\x20integration',util['inspect'](_0x5cbffd,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file