Built motion from commit fe909640.|2.6.8
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 48200ad..457faff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd101=['getString','Descriptions','Contact','add','task','Task\x20created:','ticketId','/contacts/','user:%s','trigger:browser:url','Token\x20token=','apiKey','remoteUri','serverUrl','username','callDirection','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','monitor_format','Recording\x20is\x20enabled!','recordingURL','recordingFormat','none','The\x20ticket\x20ID\x20is:\x20%s','Displaying\x20task\x20in\x20a\x20new\x20tab...','name','inspect','lodash','md5','util','moment','bluebird','ioredis','./util','../../../../config/environment','../../../../config/logger','redis','defaults','localhost','socket.io-emitter','GET','/api/selector/owners','headers','Getting\x20admin\x20information','then','users','length','email','adminEmail','adminId','info','Admin\x20found:','Requested\x20Resource\x20not\x20Found','catch','toUpperCase','message','agentEmail','Getting\x20user\x20with\x20email','userId','User\x20found:','Admin\x20selected','userEmail','error','/api/lookup?q=','&entities=contact','find','contacts','format','Searching\x20contact\x20with\x20phone\x20%s','mobile_number','endUserId','work_number','contactNumber','Contact\x20found\x20work_number:','POST','YYYY-MM-DDTHH:mm:ss','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','Creating\x20new\x20task','Subjects'];(function(_0x3f29a1,_0xb9b6b2){var _0x961f04=function(_0x501f88){while(--_0x501f88){_0x3f29a1['push'](_0x3f29a1['shift']());}};_0x961f04(++_0xb9b6b2);}(_0xd101,0xc1));var _0x1d10=function(_0xddf7c3,_0x1649d0){_0xddf7c3=_0xddf7c3-0x0;var _0x223cfe=_0xd101[_0xddf7c3];return _0x223cfe;};'use strict';var _=require(_0x1d10('0x0'));var rp=require('request-promise');var md5=require(_0x1d10('0x1'));var util=require(_0x1d10('0x2'));var moment=require(_0x1d10('0x3'));var Promise=require(_0x1d10('0x4'));var Redis=require(_0x1d10('0x5'));var intUtil=require(_0x1d10('0x6'));var config=require(_0x1d10('0x7'));var logger=require(_0x1d10('0x8'))('freshsales');config[_0x1d10('0x9')]=_[_0x1d10('0xa')](config[_0x1d10('0x9')],{'host':_0x1d10('0xb'),'port':0x18eb});var io=require(_0x1d10('0xc'))(new Redis(config[_0x1d10('0x9')]));function getAdminId(_0x6d6def,_0x43df2c,_0x3a15c8,_0x182c87){return new Promise(function(_0xf7926b,_0x14e4df){var _0x1610b4=![];var _0x3fa4c1={'method':_0x1d10('0xd'),'uri':_0x182c87+_0x1d10('0xe'),'json':!![]};_0x3fa4c1[_0x1d10('0xf')]=_0x3a15c8;logger['info'](_0x1d10('0x10'));return rp(_0x3fa4c1)[_0x1d10('0x11')](function(_0x322bf4){if(_0x322bf4){var _0x190d4c=_0x322bf4[_0x1d10('0x12')];var _0x5b71d8=null;for(_0x5b71d8=0x0;_0x5b71d8<_0x190d4c[_0x1d10('0x13')];_0x5b71d8++){if(_0x190d4c[_0x5b71d8][_0x1d10('0x14')]===_0x6d6def[_0x1d10('0x15')]){_0x6d6def[_0x1d10('0x16')]=_0x190d4c[_0x5b71d8]['id'];_0x1610b4=!![];}}if(_0x1610b4){logger[_0x1d10('0x17')](_0x1d10('0x18'),_0x6d6def['adminId']);_0xf7926b(_0x6d6def);}else{_0x14e4df({'statusCode':0x194,'message':_0x1d10('0x19')});}}else{_0x14e4df({'statusCode':0x194,'message':_0x1d10('0x19')});}})[_0x1d10('0x1a')](function(_0x2ad3c0){logger['error']('['+[_0x43df2c[_0x1d10('0x1b')]()]+']',_0x2ad3c0[_0x1d10('0x1c')]);_0x14e4df(_0x2ad3c0);});});}function getUser(_0x41152c,_0x3f2f2b,_0x1b2051){return function(_0x382b37){return new Promise(function(_0x4528a6,_0x4f3e2a){var _0x23d604={'method':_0x1d10('0xd'),'uri':_0x1b2051+_0x1d10('0xe'),'json':!![]};_0x23d604[_0x1d10('0xf')]=_0x3f2f2b;logger[_0x1d10('0x17')]('Getting\x20user\x20list');return rp(_0x23d604)['then'](function(_0x44a253){if(_0x44a253){var _0x57ec1c=_0x44a253['users'];var _0x5774f9=![];var _0x237b92=null;if(_0x382b37[_0x1d10('0x1d')]!==null){logger[_0x1d10('0x17')](_0x1d10('0x1e'),_0x382b37['agentEmail']);_0x382b37['userEmail']=_0x382b37[_0x1d10('0x1d')];for(_0x237b92=0x0;_0x237b92<_0x57ec1c['length'];_0x237b92++){if(_0x57ec1c[_0x237b92][_0x1d10('0x14')]===_0x382b37[_0x1d10('0x1d')]){_0x5774f9=!![];_0x382b37[_0x1d10('0x1f')]=_0x57ec1c[_0x237b92]['id'];logger[_0x1d10('0x17')](_0x1d10('0x20'),_0x382b37[_0x1d10('0x1f')]);}}}if(!_0x5774f9){logger[_0x1d10('0x17')](_0x1d10('0x21'));_0x382b37[_0x1d10('0x22')]=_0x382b37[_0x1d10('0x15')];_0x382b37[_0x1d10('0x1f')]=_0x382b37['adminId'];_0x5774f9=!![];}if(_0x5774f9){_0x4528a6(_0x382b37);}else{_0x4f3e2a({'statusCode':0x194,'message':_0x1d10('0x19')});}}else{_0x4f3e2a({'statusCode':0x194,'message':_0x1d10('0x19')});}})[_0x1d10('0x1a')](function(_0x15f2ee){logger[_0x1d10('0x23')]('['+[_0x41152c[_0x1d10('0x1b')]()]+']',_0x15f2ee[_0x1d10('0x1c')]);_0x4f3e2a(_0x15f2ee);});});};}function searchContact(_0xaa8ab6,_0x4f7837,_0x355e10,_0x24eb47){return new Promise(function(_0x59b5eb,_0x13a3dc){var _0x52d514={'method':'GET','headers':_0x4f7837,'uri':_0xaa8ab6+_0x1d10('0x24')+_0x24eb47+'&f='+_0x355e10+_0x1d10('0x25'),'json':!![]};rp(_0x52d514)[_0x1d10('0x11')](function(_0x453737){var _0x15fdac=_[_0x1d10('0x26')](_0x453737[_0x1d10('0x27')]['contacts'],[_0x355e10,_0x24eb47]);_0x59b5eb(_0x15fdac);})['catch'](function(_0x1ada44){_0x13a3dc(_0x1ada44);});});}function getEndUser(_0x2a9dd7,_0x96756b,_0x2e870f){return function(_0xe89535){return new Promise(function(_0x400627,_0x2c9c59){logger[_0x1d10('0x17')](util[_0x1d10('0x28')](_0x1d10('0x29'),_0xe89535['contactNumber']));searchContact(_0x2e870f,_0x96756b,_0x1d10('0x2a'),_0xe89535['contactNumber'])[_0x1d10('0x11')](function(_0x376b1b){if(_0x376b1b){_0xe89535['endUserId']=_0x376b1b['id'];logger[_0x1d10('0x17')]('Contact\x20found\x20mobile_number:',_0xe89535[_0x1d10('0x2b')]);return _0x400627(_0xe89535);}searchContact(_0x2e870f,_0x96756b,_0x1d10('0x2c'),_0xe89535[_0x1d10('0x2d')])[_0x1d10('0x11')](function(_0xd50250){if(_0xd50250){_0xe89535['endUserId']=_0xd50250['id'];logger['info'](_0x1d10('0x2e'),_0xe89535[_0x1d10('0x2b')]);return _0x400627(_0xe89535);}createEndUser(_0xe89535,_0x2a9dd7,_0x96756b,_0x2e870f)[_0x1d10('0x11')](function(_0x47929d){logger['info']('Contact\x20created:',_0x47929d[_0x1d10('0x2b')]);return _0x400627(_0x47929d);});});})['catch'](function(_0x30f58c){_0x2c9c59(_0x30f58c);});});};}function createEndUser(_0x32e51b,_0x3fad02,_0x296dcf,_0x5e9f5d){return new Promise(function(_0x4c73e1,_0x34ad39){var _0x13049a=moment();var _0x1080b4={'method':_0x1d10('0x2f'),'uri':_0x5e9f5d+'/api/contacts','body':{'contact':{'last_name':_0x32e51b[_0x1d10('0x2d')],'work_number':_0x32e51b['contactNumber'],'mobile_number':_0x32e51b[_0x1d10('0x2d')],'owner_id':_0x32e51b[_0x1d10('0x1f')],'created_at':_0x13049a[_0x1d10('0x28')](_0x1d10('0x30'))}},'json':!![]};_0x1080b4[_0x1d10('0xf')]=_0x296dcf;logger[_0x1d10('0x17')](_0x1d10('0x31'));return rp(_0x1080b4)[_0x1d10('0x11')](function(_0x1a5126){_0x32e51b[_0x1d10('0x2b')]=_0x1a5126[_0x1d10('0x32')]['id'];_0x4c73e1(_0x32e51b);})[_0x1d10('0x1a')](function(_0x13822){logger['error']('['+[_0x3fad02['toUpperCase']()]+']',_0x13822[_0x1d10('0x1c')]);_0x34ad39(_0x13822[_0x1d10('0x1c')]);});});}function getTicket(_0x3be3b0,_0xb15892,_0x1368ef,_0x2be61e,_0x1ab775){return function(_0x4ebd4a){logger[_0x1d10('0x17')](_0x1d10('0x33'));return new Promise(function(_0xd8e8cc,_0x486dc2){var _0x37b718=moment();var _0x427cd7={'method':_0x1d10('0x2f'),'uri':_0x1368ef+'/api/tasks','body':{'title':intUtil['getString'](_0x2be61e[_0x1d10('0x34')],_0x1ab775,'\x20'),'description':intUtil[_0x1d10('0x35')](_0x2be61e[_0x1d10('0x36')],_0x1ab775,'\x0a'),'owner_id':_0x4ebd4a[_0x1d10('0x1f')],'creater_id':_0x4ebd4a[_0x1d10('0x16')],'targetable_id':_0x4ebd4a[_0x1d10('0x2b')],'targetable_type':_0x1d10('0x37'),'created_at':_0x37b718['format'](_0x1d10('0x30')),'due_date':_0x37b718[_0x1d10('0x38')](0x1e,'m')['format'](_0x1d10('0x30'))},'json':!![]};_0x427cd7['headers']=_0xb15892;return rp(_0x427cd7)[_0x1d10('0x11')](function(_0x5440c7){_0x4ebd4a['ticketId']=_0x5440c7[_0x1d10('0x39')]['id'];logger[_0x1d10('0x17')](_0x1d10('0x3a'),_0x4ebd4a[_0x1d10('0x3b')]);_0xd8e8cc(_0x4ebd4a);})[_0x1d10('0x1a')](function(_0x39d445){logger[_0x1d10('0x23')]('['+[_0x3be3b0[_0x1d10('0x1b')]()]+']',_0x39d445[_0x1d10('0x1c')]);_0x486dc2(_0x39d445['message']);});});};}function emit(_0x53e07b,_0x1ce4e9,_0x38bcba){var _0x121792={'uri':_0x53e07b+_0x1d10('0x3c')+_0x38bcba};io['to'](util[_0x1d10('0x28')](_0x1d10('0x3d'),_0x1ce4e9))['emit'](_0x1d10('0x3e'),_0x121792);}exports['cs']=function(_0x1b8513,_0x304342,_0x31fc7b,_0x76024d,_0x1ce21a,_0x8226b4,_0x2c036e,_0x39bf64){var _0x32a9a9={};var _0x1560df={'Authorization':_0x1d10('0x3f')+_0x8226b4[_0x1d10('0x40')]};_0x8226b4[_0x1d10('0x41')]=intUtil['stripTrailingSlash'](_0x8226b4['remoteUri']);_0x8226b4[_0x1d10('0x42')]=intUtil['stripTrailingSlash'](_0x8226b4['serverUrl']);var _0x231489=_0x8226b4[_0x1d10('0x41')];_0x32a9a9[_0x1d10('0x15')]=_0x8226b4[_0x1d10('0x43')];_0x32a9a9[_0x1d10('0x2d')]=_0x39bf64['toLowerCase']()==='outbound'?_0x304342['destcalleridnum']:_0x304342['calleridnum'];_0x32a9a9[_0x1d10('0x44')]=_0x39bf64===_0x1d10('0x45')||_0x39bf64===_0x1d10('0x46')?_0x1d10('0x45'):'outbound';if(_0x76024d){_0x32a9a9[_0x1d10('0x1d')]=_0x76024d[_0x1d10('0x14')];}var _0x3ee24d=util['format'](_0x1d10('0x47'),_0x8226b4['serverUrl'],_0x304342[_0x1d10('0x48')],md5(_0x304342[_0x1d10('0x48')]));if(_0x1ce21a&&_0x1ce21a[_0x1d10('0x49')]){logger[_0x1d10('0x17')]('[QUEUE]',_0x1d10('0x4a'));_0x304342[_0x1d10('0x4b')]=_0x3ee24d;}else if(_0x2c036e&&_0x2c036e[_0x1d10('0x4c')]&&_0x2c036e[_0x1d10('0x4c')]!==_0x1d10('0x4d')){logger[_0x1d10('0x17')]('[OUTBOUND]',_0x1d10('0x4a'));_0x304342['recordingURL']=_0x3ee24d;}else{_0x304342[_0x1d10('0x4b')]='';}return getAdminId(_0x32a9a9,_0x39bf64,_0x1560df,_0x231489)['then'](getUser(_0x39bf64,_0x1560df,_0x231489))[_0x1d10('0x11')](getEndUser(_0x39bf64,_0x1560df,_0x231489))[_0x1d10('0x11')](getTicket(_0x39bf64,_0x1560df,_0x231489,_0x31fc7b,_0x304342))[_0x1d10('0x11')](function(_0x1d27a2){logger['info'](util[_0x1d10('0x28')](_0x1d10('0x4e'),_0x1d27a2[_0x1d10('0x3b')]));if(_0x39bf64!==_0x1d10('0x46')){logger[_0x1d10('0x17')]('['+[_0x39bf64[_0x1d10('0x1b')]()]+']',_0x1d10('0x4f'));emit(_0x231489,_0x76024d[_0x1d10('0x50')],_0x1d27a2[_0x1d10('0x2b')]);}})[_0x1d10('0x1a')](function(_0x151ffb){logger['error']('['+[_0x39bf64[_0x1d10('0x1b')]()]+']\x20Error\x20running\x20Freshsales\x20integration',util[_0x1d10('0x51')](_0x151ffb,{'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