Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 2ceef8f..839b097 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2b4a=['Contact\x20created:','POST','/api/contacts','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','/api/tasks','getString','Subjects','Descriptions','Contact','add','ticketId','task','Task\x20created:','emit','trigger:browser:url','Token\x20token=','apiKey','stripTrailingSlash','remoteUri','serverUrl','username','toLowerCase','outbound','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','Displaying\x20task\x20in\x20a\x20new\x20tab...','name',']\x20Error\x20running\x20Freshsales\x20integration','lodash','md5','util','bluebird','./util','../../../../config/environment','freshsales','redis','socket.io-emitter','GET','headers','info','Getting\x20admin\x20information','then','users','length','email','adminEmail','adminId','Admin\x20found:','Requested\x20Resource\x20not\x20Found','error','toUpperCase','message','/api/selector/owners','Getting\x20user\x20list','agentEmail','Getting\x20user\x20with\x20email','User\x20found:','userId','Admin\x20selected','userEmail','catch','/api/lookup?q=','&f=','&entities=contact','find','contacts','format','contactNumber','mobile_number','endUserId','Contact\x20found\x20mobile_number:','Contact\x20found\x20work_number:'];(function(_0x491468,_0x42f169){var _0x5b8c22=function(_0x407a9b){while(--_0x407a9b){_0x491468['push'](_0x491468['shift']());}};_0x5b8c22(++_0x42f169);}(_0x2b4a,0x187));var _0xa2b4=function(_0x124f88,_0x3ad501){_0x124f88=_0x124f88-0x0;var _0xed0e3b=_0x2b4a[_0x124f88];return _0xed0e3b;};'use strict';var _=require(_0xa2b4('0x0'));var rp=require('request-promise');var md5=require(_0xa2b4('0x1'));var util=require(_0xa2b4('0x2'));var moment=require('moment');var Promise=require(_0xa2b4('0x3'));var Redis=require('ioredis');var intUtil=require(_0xa2b4('0x4'));var config=require(_0xa2b4('0x5'));var logger=require('../../../../config/logger')(_0xa2b4('0x6'));config[_0xa2b4('0x7')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0xa2b4('0x8'))(new Redis(config[_0xa2b4('0x7')]));function getAdminId(_0x37039f,_0x3f4fec,_0x57177c,_0x351796){return new Promise(function(_0x142c8c,_0x35ebdd){var _0x269cc0=![];var _0xd0b022={'method':_0xa2b4('0x9'),'uri':_0x351796+'/api/selector/owners','json':!![]};_0xd0b022[_0xa2b4('0xa')]=_0x57177c;logger[_0xa2b4('0xb')](_0xa2b4('0xc'));return rp(_0xd0b022)[_0xa2b4('0xd')](function(_0x418021){if(_0x418021){var _0x5c8a98=_0x418021[_0xa2b4('0xe')];var _0x12a20b=null;for(_0x12a20b=0x0;_0x12a20b<_0x5c8a98[_0xa2b4('0xf')];_0x12a20b++){if(_0x5c8a98[_0x12a20b][_0xa2b4('0x10')]===_0x37039f[_0xa2b4('0x11')]){_0x37039f[_0xa2b4('0x12')]=_0x5c8a98[_0x12a20b]['id'];_0x269cc0=!![];}}if(_0x269cc0){logger[_0xa2b4('0xb')](_0xa2b4('0x13'),_0x37039f['adminId']);_0x142c8c(_0x37039f);}else{_0x35ebdd({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}else{_0x35ebdd({'statusCode':0x194,'message':_0xa2b4('0x14')});}})['catch'](function(_0x39f053){logger[_0xa2b4('0x15')]('['+[_0x3f4fec[_0xa2b4('0x16')]()]+']',_0x39f053[_0xa2b4('0x17')]);_0x35ebdd(_0x39f053);});});}function getUser(_0x180078,_0x153b47,_0x286d2c){return function(_0x1397ee){return new Promise(function(_0x40830d,_0x3c68d2){var _0x1dbed1={'method':_0xa2b4('0x9'),'uri':_0x286d2c+_0xa2b4('0x18'),'json':!![]};_0x1dbed1[_0xa2b4('0xa')]=_0x153b47;logger[_0xa2b4('0xb')](_0xa2b4('0x19'));return rp(_0x1dbed1)[_0xa2b4('0xd')](function(_0x59d9a0){if(_0x59d9a0){var _0x1b4651=_0x59d9a0[_0xa2b4('0xe')];var _0x141100=![];var _0x3f33c3=null;if(_0x1397ee[_0xa2b4('0x1a')]!==null){logger['info'](_0xa2b4('0x1b'),_0x1397ee[_0xa2b4('0x1a')]);_0x1397ee['userEmail']=_0x1397ee[_0xa2b4('0x1a')];for(_0x3f33c3=0x0;_0x3f33c3<_0x1b4651[_0xa2b4('0xf')];_0x3f33c3++){if(_0x1b4651[_0x3f33c3][_0xa2b4('0x10')]===_0x1397ee[_0xa2b4('0x1a')]){_0x141100=!![];_0x1397ee['userId']=_0x1b4651[_0x3f33c3]['id'];logger['info'](_0xa2b4('0x1c'),_0x1397ee[_0xa2b4('0x1d')]);}}}if(!_0x141100){logger['info'](_0xa2b4('0x1e'));_0x1397ee[_0xa2b4('0x1f')]=_0x1397ee['adminEmail'];_0x1397ee[_0xa2b4('0x1d')]=_0x1397ee[_0xa2b4('0x12')];_0x141100=!![];}if(_0x141100){_0x40830d(_0x1397ee);}else{_0x3c68d2({'statusCode':0x194,'message':_0xa2b4('0x14')});}}else{_0x3c68d2({'statusCode':0x194,'message':_0xa2b4('0x14')});}})[_0xa2b4('0x20')](function(_0x5b3078){logger[_0xa2b4('0x15')]('['+[_0x180078['toUpperCase']()]+']',_0x5b3078[_0xa2b4('0x17')]);_0x3c68d2(_0x5b3078);});});};}function searchContact(_0x48a5ed,_0x18c8e0,_0x4cb468,_0xaf3c4d){return new Promise(function(_0x4e83fd,_0x536e71){var _0x4ed2b5={'method':_0xa2b4('0x9'),'headers':_0x18c8e0,'uri':_0x48a5ed+_0xa2b4('0x21')+_0xaf3c4d+_0xa2b4('0x22')+_0x4cb468+_0xa2b4('0x23'),'json':!![]};rp(_0x4ed2b5)[_0xa2b4('0xd')](function(_0x53c4db){var _0x3aca2b=_[_0xa2b4('0x24')](_0x53c4db[_0xa2b4('0x25')][_0xa2b4('0x25')],[_0x4cb468,_0xaf3c4d]);_0x4e83fd(_0x3aca2b);})[_0xa2b4('0x20')](function(_0x43bed0){_0x536e71(_0x43bed0);});});}function getEndUser(_0x3c8ce9,_0x122758,_0x231203){return function(_0x80d5db){return new Promise(function(_0x16ad10,_0x69b506){logger['info'](util[_0xa2b4('0x26')]('Searching\x20contact\x20with\x20phone\x20%s',_0x80d5db[_0xa2b4('0x27')]));searchContact(_0x231203,_0x122758,_0xa2b4('0x28'),_0x80d5db['contactNumber'])[_0xa2b4('0xd')](function(_0x1239ba){if(_0x1239ba){_0x80d5db[_0xa2b4('0x29')]=_0x1239ba['id'];logger[_0xa2b4('0xb')](_0xa2b4('0x2a'),_0x80d5db[_0xa2b4('0x29')]);return _0x16ad10(_0x80d5db);}searchContact(_0x231203,_0x122758,'work_number',_0x80d5db['contactNumber'])['then'](function(_0x2003b4){if(_0x2003b4){_0x80d5db[_0xa2b4('0x29')]=_0x2003b4['id'];logger[_0xa2b4('0xb')](_0xa2b4('0x2b'),_0x80d5db['endUserId']);return _0x16ad10(_0x80d5db);}createEndUser(_0x80d5db,_0x3c8ce9,_0x122758,_0x231203)['then'](function(_0x100dfa){logger['info'](_0xa2b4('0x2c'),_0x100dfa[_0xa2b4('0x29')]);return _0x16ad10(_0x100dfa);});});})[_0xa2b4('0x20')](function(_0x498a4f){_0x69b506(_0x498a4f);});});};}function createEndUser(_0xe23df3,_0x38d57d,_0x1f664a,_0xc23b30){return new Promise(function(_0x245c07,_0x106609){var _0x54e4c5=moment();var _0x27bf8a={'method':_0xa2b4('0x2d'),'uri':_0xc23b30+_0xa2b4('0x2e'),'body':{'contact':{'last_name':_0xe23df3['contactNumber'],'work_number':_0xe23df3[_0xa2b4('0x27')],'mobile_number':_0xe23df3[_0xa2b4('0x27')],'owner_id':_0xe23df3['userId'],'created_at':_0x54e4c5[_0xa2b4('0x26')](_0xa2b4('0x2f'))}},'json':!![]};_0x27bf8a[_0xa2b4('0xa')]=_0x1f664a;logger[_0xa2b4('0xb')](_0xa2b4('0x30'));return rp(_0x27bf8a)['then'](function(_0x330169){_0xe23df3[_0xa2b4('0x29')]=_0x330169[_0xa2b4('0x31')]['id'];_0x245c07(_0xe23df3);})[_0xa2b4('0x20')](function(_0x347dec){logger['error']('['+[_0x38d57d[_0xa2b4('0x16')]()]+']',_0x347dec['message']);_0x106609(_0x347dec['message']);});});}function getTicket(_0x2c0110,_0x3b932a,_0x217a3d,_0x27daa2,_0x319cf6){return function(_0x5d5a58){logger[_0xa2b4('0xb')]('Creating\x20new\x20task');return new Promise(function(_0x21023b,_0x526ed2){var _0x263688=moment();var _0x3edfc4={'method':_0xa2b4('0x2d'),'uri':_0x217a3d+_0xa2b4('0x32'),'body':{'title':intUtil[_0xa2b4('0x33')](_0x27daa2[_0xa2b4('0x34')],_0x319cf6,'\x20'),'description':intUtil[_0xa2b4('0x33')](_0x27daa2[_0xa2b4('0x35')],_0x319cf6,'\x0a'),'owner_id':_0x5d5a58[_0xa2b4('0x1d')],'creater_id':_0x5d5a58[_0xa2b4('0x12')],'targetable_id':_0x5d5a58[_0xa2b4('0x29')],'targetable_type':_0xa2b4('0x36'),'created_at':_0x263688[_0xa2b4('0x26')](_0xa2b4('0x2f')),'due_date':_0x263688[_0xa2b4('0x37')](0x1e,'m')['format'](_0xa2b4('0x2f'))},'json':!![]};_0x3edfc4['headers']=_0x3b932a;return rp(_0x3edfc4)[_0xa2b4('0xd')](function(_0x248f51){_0x5d5a58[_0xa2b4('0x38')]=_0x248f51[_0xa2b4('0x39')]['id'];logger[_0xa2b4('0xb')](_0xa2b4('0x3a'),_0x5d5a58['ticketId']);_0x21023b(_0x5d5a58);})[_0xa2b4('0x20')](function(_0x37dbfc){logger['error']('['+[_0x2c0110[_0xa2b4('0x16')]()]+']',_0x37dbfc[_0xa2b4('0x17')]);_0x526ed2(_0x37dbfc[_0xa2b4('0x17')]);});});};}function emit(_0x1835da,_0x28cf27,_0x39cce6){var _0x4edeb2={'uri':_0x1835da+'/contacts/'+_0x39cce6};io['to'](util[_0xa2b4('0x26')]('user:%s',_0x28cf27))[_0xa2b4('0x3b')](_0xa2b4('0x3c'),_0x4edeb2);}exports['cs']=function(_0x460bba,_0x3fa33b,_0x4c2d7d,_0x354c0a,_0x3a8fc6,_0x5a5956,_0x413626,_0x14cf0e){var _0x5cf50b={};var _0x258fe1={'Authorization':_0xa2b4('0x3d')+_0x5a5956[_0xa2b4('0x3e')]};_0x5a5956['remoteUri']=intUtil[_0xa2b4('0x3f')](_0x5a5956[_0xa2b4('0x40')]);_0x5a5956[_0xa2b4('0x41')]=intUtil[_0xa2b4('0x3f')](_0x5a5956[_0xa2b4('0x41')]);var _0x38b396=_0x5a5956[_0xa2b4('0x40')];_0x5cf50b[_0xa2b4('0x11')]=_0x5a5956[_0xa2b4('0x42')];_0x5cf50b[_0xa2b4('0x27')]=_0x14cf0e[_0xa2b4('0x43')]()===_0xa2b4('0x44')?_0x3fa33b[_0xa2b4('0x45')]:_0x3fa33b[_0xa2b4('0x46')];_0x5cf50b[_0xa2b4('0x47')]=_0x14cf0e===_0xa2b4('0x48')||_0x14cf0e===_0xa2b4('0x49')?_0xa2b4('0x48'):_0xa2b4('0x44');if(_0x354c0a){_0x5cf50b[_0xa2b4('0x1a')]=_0x354c0a['email'];}var _0xb2ebbd=util[_0xa2b4('0x26')](_0xa2b4('0x4a'),_0x5a5956[_0xa2b4('0x41')],_0x3fa33b[_0xa2b4('0x4b')],md5(_0x3fa33b[_0xa2b4('0x4b')]));if(_0x3a8fc6&&_0x3a8fc6[_0xa2b4('0x4c')]){logger[_0xa2b4('0xb')](_0xa2b4('0x4d'),_0xa2b4('0x4e'));_0x3fa33b[_0xa2b4('0x4f')]=_0xb2ebbd;}else if(_0x413626&&_0x413626[_0xa2b4('0x50')]&&_0x413626['recordingFormat']!==_0xa2b4('0x51')){logger[_0xa2b4('0xb')](_0xa2b4('0x52'),'Recording\x20is\x20enabled!');_0x3fa33b[_0xa2b4('0x4f')]=_0xb2ebbd;}else{_0x3fa33b[_0xa2b4('0x4f')]='';}return getAdminId(_0x5cf50b,_0x14cf0e,_0x258fe1,_0x38b396)['then'](getUser(_0x14cf0e,_0x258fe1,_0x38b396))[_0xa2b4('0xd')](getEndUser(_0x14cf0e,_0x258fe1,_0x38b396))['then'](getTicket(_0x14cf0e,_0x258fe1,_0x38b396,_0x4c2d7d,_0x3fa33b))[_0xa2b4('0xd')](function(_0x25725a){logger[_0xa2b4('0xb')](util[_0xa2b4('0x26')](_0xa2b4('0x53'),_0x25725a['ticketId']));if(_0x14cf0e!=='unmanaged'){logger[_0xa2b4('0xb')]('['+[_0x14cf0e[_0xa2b4('0x16')]()]+']',_0xa2b4('0x54'));emit(_0x38b396,_0x354c0a[_0xa2b4('0x55')],_0x25725a[_0xa2b4('0x29')]);}})[_0xa2b4('0x20')](function(_0x5ca4a8){logger[_0xa2b4('0x15')]('['+[_0x14cf0e[_0xa2b4('0x16')]()]+_0xa2b4('0x56'),util['inspect'](_0x5ca4a8,{'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