Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index e347757..839b097 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf2a8=['contactNumber','endUserId','Contact\x20found\x20mobile_number:','work_number','Contact\x20found\x20work_number:','POST','/api/contacts','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','error','Creating\x20new\x20task','/api/tasks','getString','Subjects','Descriptions','add','ticketId','task','Task\x20created:','emit','trigger:browser:url','apiKey','remoteUri','stripTrailingSlash','serverUrl','toLowerCase','destcalleridnum','callDirection','unmanaged','queue','outbound','uniqueid','monitor_format','[QUEUE]','recordingURL','recordingFormat','none','[OUTBOUND]','The\x20ticket\x20ID\x20is:\x20%s','name','inspect','lodash','request-promise','md5','util','moment','ioredis','./util','../../../../config/logger','freshsales','redis','defaults','localhost','socket.io-emitter','/api/selector/owners','headers','info','Getting\x20admin\x20information','then','length','email','adminEmail','Admin\x20found:','adminId','Requested\x20Resource\x20not\x20Found','catch','Getting\x20user\x20list','users','agentEmail','Getting\x20user\x20with\x20email','userEmail','User\x20found:','userId','Admin\x20selected','toUpperCase','message','GET','/api/lookup?q=','find','contacts','format','Searching\x20contact\x20with\x20phone\x20%s'];(function(_0x344d25,_0x2e6b18){var _0x20e27e=function(_0xc2a698){while(--_0xc2a698){_0x344d25['push'](_0x344d25['shift']());}};_0x20e27e(++_0x2e6b18);}(_0xf2a8,0x176));var _0x8f2a=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0xf2a8[_0x4a9fb1];return _0x348672;};'use strict';var _=require(_0x8f2a('0x0'));var rp=require(_0x8f2a('0x1'));var md5=require(_0x8f2a('0x2'));var util=require(_0x8f2a('0x3'));var moment=require(_0x8f2a('0x4'));var Promise=require('bluebird');var Redis=require(_0x8f2a('0x5'));var intUtil=require(_0x8f2a('0x6'));var config=require('../../../../config/environment');var logger=require(_0x8f2a('0x7'))(_0x8f2a('0x8'));config[_0x8f2a('0x9')]=_[_0x8f2a('0xa')](config[_0x8f2a('0x9')],{'host':_0x8f2a('0xb'),'port':0x18eb});var io=require(_0x8f2a('0xc'))(new Redis(config['redis']));function getAdminId(_0x2c6eee,_0x434355,_0x4e0d85,_0x44b924){return new Promise(function(_0x5cf654,_0x4db1fb){var _0x3e967b=![];var _0x49dbc1={'method':'GET','uri':_0x44b924+_0x8f2a('0xd'),'json':!![]};_0x49dbc1[_0x8f2a('0xe')]=_0x4e0d85;logger[_0x8f2a('0xf')](_0x8f2a('0x10'));return rp(_0x49dbc1)[_0x8f2a('0x11')](function(_0x596fac){if(_0x596fac){var _0x65e467=_0x596fac['users'];var _0x5717b5=null;for(_0x5717b5=0x0;_0x5717b5<_0x65e467[_0x8f2a('0x12')];_0x5717b5++){if(_0x65e467[_0x5717b5][_0x8f2a('0x13')]===_0x2c6eee[_0x8f2a('0x14')]){_0x2c6eee['adminId']=_0x65e467[_0x5717b5]['id'];_0x3e967b=!![];}}if(_0x3e967b){logger[_0x8f2a('0xf')](_0x8f2a('0x15'),_0x2c6eee[_0x8f2a('0x16')]);_0x5cf654(_0x2c6eee);}else{_0x4db1fb({'statusCode':0x194,'message':_0x8f2a('0x17')});}}else{_0x4db1fb({'statusCode':0x194,'message':_0x8f2a('0x17')});}})[_0x8f2a('0x18')](function(_0x1406ff){logger['error']('['+[_0x434355['toUpperCase']()]+']',_0x1406ff['message']);_0x4db1fb(_0x1406ff);});});}function getUser(_0xe1472b,_0xb0163a,_0x1182db){return function(_0x391ebc){return new Promise(function(_0x4c0028,_0x25f31a){var _0x2a1bf1={'method':'GET','uri':_0x1182db+_0x8f2a('0xd'),'json':!![]};_0x2a1bf1[_0x8f2a('0xe')]=_0xb0163a;logger[_0x8f2a('0xf')](_0x8f2a('0x19'));return rp(_0x2a1bf1)['then'](function(_0xc8abda){if(_0xc8abda){var _0x5926d3=_0xc8abda[_0x8f2a('0x1a')];var _0x35b5e6=![];var _0x1fdeb4=null;if(_0x391ebc[_0x8f2a('0x1b')]!==null){logger[_0x8f2a('0xf')](_0x8f2a('0x1c'),_0x391ebc[_0x8f2a('0x1b')]);_0x391ebc[_0x8f2a('0x1d')]=_0x391ebc['agentEmail'];for(_0x1fdeb4=0x0;_0x1fdeb4<_0x5926d3[_0x8f2a('0x12')];_0x1fdeb4++){if(_0x5926d3[_0x1fdeb4][_0x8f2a('0x13')]===_0x391ebc[_0x8f2a('0x1b')]){_0x35b5e6=!![];_0x391ebc['userId']=_0x5926d3[_0x1fdeb4]['id'];logger[_0x8f2a('0xf')](_0x8f2a('0x1e'),_0x391ebc[_0x8f2a('0x1f')]);}}}if(!_0x35b5e6){logger[_0x8f2a('0xf')](_0x8f2a('0x20'));_0x391ebc['userEmail']=_0x391ebc[_0x8f2a('0x14')];_0x391ebc['userId']=_0x391ebc[_0x8f2a('0x16')];_0x35b5e6=!![];}if(_0x35b5e6){_0x4c0028(_0x391ebc);}else{_0x25f31a({'statusCode':0x194,'message':_0x8f2a('0x17')});}}else{_0x25f31a({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}})[_0x8f2a('0x18')](function(_0x292fb2){logger['error']('['+[_0xe1472b[_0x8f2a('0x21')]()]+']',_0x292fb2[_0x8f2a('0x22')]);_0x25f31a(_0x292fb2);});});};}function searchContact(_0xf4b4b4,_0xf320af,_0x53733b,_0x352db4){return new Promise(function(_0xd93201,_0x132310){var _0x468ac1={'method':_0x8f2a('0x23'),'headers':_0xf320af,'uri':_0xf4b4b4+_0x8f2a('0x24')+_0x352db4+'&f='+_0x53733b+'&entities=contact','json':!![]};rp(_0x468ac1)['then'](function(_0x3e197e){var _0x4f488f=_[_0x8f2a('0x25')](_0x3e197e[_0x8f2a('0x26')][_0x8f2a('0x26')],[_0x53733b,_0x352db4]);_0xd93201(_0x4f488f);})[_0x8f2a('0x18')](function(_0x12df80){_0x132310(_0x12df80);});});}function getEndUser(_0x3a6135,_0x3ad3d0,_0x5ebd10){return function(_0x1c160e){return new Promise(function(_0x2454bf,_0x22845c){logger[_0x8f2a('0xf')](util[_0x8f2a('0x27')](_0x8f2a('0x28'),_0x1c160e[_0x8f2a('0x29')]));searchContact(_0x5ebd10,_0x3ad3d0,'mobile_number',_0x1c160e[_0x8f2a('0x29')])[_0x8f2a('0x11')](function(_0x10586f){if(_0x10586f){_0x1c160e[_0x8f2a('0x2a')]=_0x10586f['id'];logger[_0x8f2a('0xf')](_0x8f2a('0x2b'),_0x1c160e[_0x8f2a('0x2a')]);return _0x2454bf(_0x1c160e);}searchContact(_0x5ebd10,_0x3ad3d0,_0x8f2a('0x2c'),_0x1c160e[_0x8f2a('0x29')])[_0x8f2a('0x11')](function(_0x2b3c50){if(_0x2b3c50){_0x1c160e[_0x8f2a('0x2a')]=_0x2b3c50['id'];logger[_0x8f2a('0xf')](_0x8f2a('0x2d'),_0x1c160e['endUserId']);return _0x2454bf(_0x1c160e);}createEndUser(_0x1c160e,_0x3a6135,_0x3ad3d0,_0x5ebd10)['then'](function(_0x5182b8){logger[_0x8f2a('0xf')]('Contact\x20created:',_0x5182b8['endUserId']);return _0x2454bf(_0x5182b8);});});})[_0x8f2a('0x18')](function(_0x4f92f7){_0x22845c(_0x4f92f7);});});};}function createEndUser(_0x716e7b,_0x4fe198,_0x4de8c7,_0x107d3e){return new Promise(function(_0x1ba54a,_0x8100b9){var _0x277478=moment();var _0x42db77={'method':_0x8f2a('0x2e'),'uri':_0x107d3e+_0x8f2a('0x2f'),'body':{'contact':{'last_name':_0x716e7b[_0x8f2a('0x29')],'work_number':_0x716e7b[_0x8f2a('0x29')],'mobile_number':_0x716e7b[_0x8f2a('0x29')],'owner_id':_0x716e7b[_0x8f2a('0x1f')],'created_at':_0x277478[_0x8f2a('0x27')](_0x8f2a('0x30'))}},'json':!![]};_0x42db77[_0x8f2a('0xe')]=_0x4de8c7;logger[_0x8f2a('0xf')](_0x8f2a('0x31'));return rp(_0x42db77)[_0x8f2a('0x11')](function(_0x5b2ea5){_0x716e7b['endUserId']=_0x5b2ea5[_0x8f2a('0x32')]['id'];_0x1ba54a(_0x716e7b);})['catch'](function(_0x104979){logger[_0x8f2a('0x33')]('['+[_0x4fe198[_0x8f2a('0x21')]()]+']',_0x104979[_0x8f2a('0x22')]);_0x8100b9(_0x104979[_0x8f2a('0x22')]);});});}function getTicket(_0x1c0b1e,_0x5c8be1,_0x1a3458,_0x2f4fd8,_0x36c2ac){return function(_0x29dd7c){logger[_0x8f2a('0xf')](_0x8f2a('0x34'));return new Promise(function(_0x5d2f3e,_0x448bed){var _0xd152d3=moment();var _0x22f4d7={'method':_0x8f2a('0x2e'),'uri':_0x1a3458+_0x8f2a('0x35'),'body':{'title':intUtil[_0x8f2a('0x36')](_0x2f4fd8[_0x8f2a('0x37')],_0x36c2ac,'\x20'),'description':intUtil[_0x8f2a('0x36')](_0x2f4fd8[_0x8f2a('0x38')],_0x36c2ac,'\x0a'),'owner_id':_0x29dd7c[_0x8f2a('0x1f')],'creater_id':_0x29dd7c[_0x8f2a('0x16')],'targetable_id':_0x29dd7c[_0x8f2a('0x2a')],'targetable_type':'Contact','created_at':_0xd152d3[_0x8f2a('0x27')]('YYYY-MM-DDTHH:mm:ss'),'due_date':_0xd152d3[_0x8f2a('0x39')](0x1e,'m')[_0x8f2a('0x27')](_0x8f2a('0x30'))},'json':!![]};_0x22f4d7[_0x8f2a('0xe')]=_0x5c8be1;return rp(_0x22f4d7)[_0x8f2a('0x11')](function(_0x357079){_0x29dd7c[_0x8f2a('0x3a')]=_0x357079[_0x8f2a('0x3b')]['id'];logger[_0x8f2a('0xf')](_0x8f2a('0x3c'),_0x29dd7c[_0x8f2a('0x3a')]);_0x5d2f3e(_0x29dd7c);})[_0x8f2a('0x18')](function(_0xb72a64){logger[_0x8f2a('0x33')]('['+[_0x1c0b1e['toUpperCase']()]+']',_0xb72a64['message']);_0x448bed(_0xb72a64[_0x8f2a('0x22')]);});});};}function emit(_0x1f1fbb,_0x17d18f,_0x25277f){var _0x4c9a70={'uri':_0x1f1fbb+'/contacts/'+_0x25277f};io['to'](util[_0x8f2a('0x27')]('user:%s',_0x17d18f))[_0x8f2a('0x3d')](_0x8f2a('0x3e'),_0x4c9a70);}exports['cs']=function(_0x55cabf,_0x4f73d1,_0x5e1836,_0x3a4f8f,_0x47e935,_0x10f689,_0x1d2f13,_0x505444){var _0x5c39fc={};var _0x58e7af={'Authorization':'Token\x20token='+_0x10f689[_0x8f2a('0x3f')]};_0x10f689[_0x8f2a('0x40')]=intUtil[_0x8f2a('0x41')](_0x10f689['remoteUri']);_0x10f689['serverUrl']=intUtil[_0x8f2a('0x41')](_0x10f689[_0x8f2a('0x42')]);var _0x412522=_0x10f689[_0x8f2a('0x40')];_0x5c39fc[_0x8f2a('0x14')]=_0x10f689['username'];_0x5c39fc[_0x8f2a('0x29')]=_0x505444[_0x8f2a('0x43')]()==='outbound'?_0x4f73d1[_0x8f2a('0x44')]:_0x4f73d1['calleridnum'];_0x5c39fc[_0x8f2a('0x45')]=_0x505444==='queue'||_0x505444===_0x8f2a('0x46')?_0x8f2a('0x47'):_0x8f2a('0x48');if(_0x3a4f8f){_0x5c39fc[_0x8f2a('0x1b')]=_0x3a4f8f[_0x8f2a('0x13')];}var _0x352a6b=util[_0x8f2a('0x27')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x10f689[_0x8f2a('0x42')],_0x4f73d1[_0x8f2a('0x49')],md5(_0x4f73d1[_0x8f2a('0x49')]));if(_0x47e935&&_0x47e935[_0x8f2a('0x4a')]){logger[_0x8f2a('0xf')](_0x8f2a('0x4b'),'Recording\x20is\x20enabled!');_0x4f73d1[_0x8f2a('0x4c')]=_0x352a6b;}else if(_0x1d2f13&&_0x1d2f13[_0x8f2a('0x4d')]&&_0x1d2f13[_0x8f2a('0x4d')]!==_0x8f2a('0x4e')){logger[_0x8f2a('0xf')](_0x8f2a('0x4f'),'Recording\x20is\x20enabled!');_0x4f73d1['recordingURL']=_0x352a6b;}else{_0x4f73d1[_0x8f2a('0x4c')]='';}return getAdminId(_0x5c39fc,_0x505444,_0x58e7af,_0x412522)['then'](getUser(_0x505444,_0x58e7af,_0x412522))[_0x8f2a('0x11')](getEndUser(_0x505444,_0x58e7af,_0x412522))[_0x8f2a('0x11')](getTicket(_0x505444,_0x58e7af,_0x412522,_0x5e1836,_0x4f73d1))[_0x8f2a('0x11')](function(_0xd43f8f){logger['info'](util[_0x8f2a('0x27')](_0x8f2a('0x50'),_0xd43f8f[_0x8f2a('0x3a')]));if(_0x505444!==_0x8f2a('0x46')){logger[_0x8f2a('0xf')]('['+[_0x505444['toUpperCase']()]+']','Displaying\x20task\x20in\x20a\x20new\x20tab...');emit(_0x412522,_0x3a4f8f[_0x8f2a('0x51')],_0xd43f8f['endUserId']);}})[_0x8f2a('0x18')](function(_0x28cb62){logger[_0x8f2a('0x33')]('['+[_0x505444[_0x8f2a('0x21')]()]+']\x20Error\x20running\x20Freshsales\x20integration',util[_0x8f2a('0x52')](_0x28cb62,{'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