Built motion from commit fe909640.|2.6.8
[motion2.git] / server / services / ami / trigger / integration / freshsales.js
index 276b732..457faff 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa9b1=['adminEmail','catch','error','/api/lookup?q=','&entities=contact','find','contacts','format','Searching\x20contact\x20with\x20phone\x20%s','contactNumber','endUserId','Contact\x20found\x20mobile_number:','work_number','POST','/api/contacts','Contact\x20not\x20found,\x20creating\x20a\x20new\x20contact','contact','Creating\x20new\x20task','/api/tasks','getString','Subjects','Descriptions','Contact','YYYY-MM-DDTHH:mm:ss','add','ticketId','task','Task\x20created:','/contacts/','user:%s','emit','trigger:browser:url','Token\x20token=','remoteUri','stripTrailingSlash','serverUrl','toLowerCase','outbound','destcalleridnum','calleridnum','queue','unmanaged','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','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','md5','util','moment','bluebird','ioredis','./util','redis','defaults','localhost','socket.io-emitter','GET','/api/selector/owners','headers','users','length','email','adminId','info','Admin\x20found:','Requested\x20Resource\x20not\x20Found','toUpperCase','message','Getting\x20user\x20list','then','agentEmail','Getting\x20user\x20with\x20email','userId','User\x20found:','userEmail'];(function(_0x5c811c,_0x313b25){var _0x5df3af=function(_0x3460de){while(--_0x3460de){_0x5c811c['push'](_0x5c811c['shift']());}};_0x5df3af(++_0x313b25);}(_0xa9b1,0x133));var _0x1a9b=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xa9b1[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var rp=require('request-promise');var md5=require(_0x1a9b('0x0'));var util=require(_0x1a9b('0x1'));var moment=require(_0x1a9b('0x2'));var Promise=require(_0x1a9b('0x3'));var Redis=require(_0x1a9b('0x4'));var intUtil=require(_0x1a9b('0x5'));var config=require('../../../../config/environment');var logger=require('../../../../config/logger')('freshsales');config[_0x1a9b('0x6')]=_[_0x1a9b('0x7')](config[_0x1a9b('0x6')],{'host':_0x1a9b('0x8'),'port':0x18eb});var io=require(_0x1a9b('0x9'))(new Redis(config[_0x1a9b('0x6')]));function getAdminId(_0x263b84,_0x16e01a,_0x29932a,_0xec5160){return new Promise(function(_0x162d6a,_0x57659a){var _0x55f1aa=![];var _0x4e1aef={'method':_0x1a9b('0xa'),'uri':_0xec5160+_0x1a9b('0xb'),'json':!![]};_0x4e1aef[_0x1a9b('0xc')]=_0x29932a;logger['info']('Getting\x20admin\x20information');return rp(_0x4e1aef)['then'](function(_0x12bc7b){if(_0x12bc7b){var _0x3a49dd=_0x12bc7b[_0x1a9b('0xd')];var _0x11bf7e=null;for(_0x11bf7e=0x0;_0x11bf7e<_0x3a49dd[_0x1a9b('0xe')];_0x11bf7e++){if(_0x3a49dd[_0x11bf7e][_0x1a9b('0xf')]===_0x263b84['adminEmail']){_0x263b84[_0x1a9b('0x10')]=_0x3a49dd[_0x11bf7e]['id'];_0x55f1aa=!![];}}if(_0x55f1aa){logger[_0x1a9b('0x11')](_0x1a9b('0x12'),_0x263b84['adminId']);_0x162d6a(_0x263b84);}else{_0x57659a({'statusCode':0x194,'message':_0x1a9b('0x13')});}}else{_0x57659a({'statusCode':0x194,'message':_0x1a9b('0x13')});}})['catch'](function(_0x2a7d72){logger['error']('['+[_0x16e01a[_0x1a9b('0x14')]()]+']',_0x2a7d72[_0x1a9b('0x15')]);_0x57659a(_0x2a7d72);});});}function getUser(_0xa77d19,_0x3903b7,_0xeba9aa){return function(_0x20b8dc){return new Promise(function(_0x37057a,_0x205a0d){var _0x10acc3={'method':_0x1a9b('0xa'),'uri':_0xeba9aa+'/api/selector/owners','json':!![]};_0x10acc3[_0x1a9b('0xc')]=_0x3903b7;logger[_0x1a9b('0x11')](_0x1a9b('0x16'));return rp(_0x10acc3)[_0x1a9b('0x17')](function(_0x5687fc){if(_0x5687fc){var _0x208e1f=_0x5687fc[_0x1a9b('0xd')];var _0x4b3cd3=![];var _0x23e327=null;if(_0x20b8dc[_0x1a9b('0x18')]!==null){logger[_0x1a9b('0x11')](_0x1a9b('0x19'),_0x20b8dc[_0x1a9b('0x18')]);_0x20b8dc['userEmail']=_0x20b8dc[_0x1a9b('0x18')];for(_0x23e327=0x0;_0x23e327<_0x208e1f[_0x1a9b('0xe')];_0x23e327++){if(_0x208e1f[_0x23e327][_0x1a9b('0xf')]===_0x20b8dc[_0x1a9b('0x18')]){_0x4b3cd3=!![];_0x20b8dc[_0x1a9b('0x1a')]=_0x208e1f[_0x23e327]['id'];logger[_0x1a9b('0x11')](_0x1a9b('0x1b'),_0x20b8dc['userId']);}}}if(!_0x4b3cd3){logger[_0x1a9b('0x11')]('Admin\x20selected');_0x20b8dc[_0x1a9b('0x1c')]=_0x20b8dc[_0x1a9b('0x1d')];_0x20b8dc[_0x1a9b('0x1a')]=_0x20b8dc['adminId'];_0x4b3cd3=!![];}if(_0x4b3cd3){_0x37057a(_0x20b8dc);}else{_0x205a0d({'statusCode':0x194,'message':_0x1a9b('0x13')});}}else{_0x205a0d({'statusCode':0x194,'message':_0x1a9b('0x13')});}})[_0x1a9b('0x1e')](function(_0x181331){logger[_0x1a9b('0x1f')]('['+[_0xa77d19[_0x1a9b('0x14')]()]+']',_0x181331['message']);_0x205a0d(_0x181331);});});};}function searchContact(_0x3f7807,_0x129488,_0x566fb4,_0x165fc0){return new Promise(function(_0xbc54e3,_0x5d70dc){var _0x5d7e8c={'method':_0x1a9b('0xa'),'headers':_0x129488,'uri':_0x3f7807+_0x1a9b('0x20')+_0x165fc0+'&f='+_0x566fb4+_0x1a9b('0x21'),'json':!![]};rp(_0x5d7e8c)[_0x1a9b('0x17')](function(_0xc9726){var _0x36acbd=_[_0x1a9b('0x22')](_0xc9726[_0x1a9b('0x23')][_0x1a9b('0x23')],[_0x566fb4,_0x165fc0]);_0xbc54e3(_0x36acbd);})['catch'](function(_0x3ba2fe){_0x5d70dc(_0x3ba2fe);});});}function getEndUser(_0x27771b,_0x3af95c,_0x4185ad){return function(_0x3a1f70){return new Promise(function(_0x284b5f,_0xe0dd38){logger[_0x1a9b('0x11')](util[_0x1a9b('0x24')](_0x1a9b('0x25'),_0x3a1f70[_0x1a9b('0x26')]));searchContact(_0x4185ad,_0x3af95c,'mobile_number',_0x3a1f70['contactNumber'])[_0x1a9b('0x17')](function(_0x1d0179){if(_0x1d0179){_0x3a1f70[_0x1a9b('0x27')]=_0x1d0179['id'];logger['info'](_0x1a9b('0x28'),_0x3a1f70['endUserId']);return _0x284b5f(_0x3a1f70);}searchContact(_0x4185ad,_0x3af95c,_0x1a9b('0x29'),_0x3a1f70['contactNumber'])[_0x1a9b('0x17')](function(_0x30d39d){if(_0x30d39d){_0x3a1f70['endUserId']=_0x30d39d['id'];logger[_0x1a9b('0x11')]('Contact\x20found\x20work_number:',_0x3a1f70[_0x1a9b('0x27')]);return _0x284b5f(_0x3a1f70);}createEndUser(_0x3a1f70,_0x27771b,_0x3af95c,_0x4185ad)[_0x1a9b('0x17')](function(_0x2f303c){logger[_0x1a9b('0x11')]('Contact\x20created:',_0x2f303c[_0x1a9b('0x27')]);return _0x284b5f(_0x2f303c);});});})[_0x1a9b('0x1e')](function(_0x26bcb6){_0xe0dd38(_0x26bcb6);});});};}function createEndUser(_0x5ceda8,_0x126f89,_0x5be8b9,_0x51a28a){return new Promise(function(_0x54d959,_0x858591){var _0x476564=moment();var _0x42f540={'method':_0x1a9b('0x2a'),'uri':_0x51a28a+_0x1a9b('0x2b'),'body':{'contact':{'last_name':_0x5ceda8[_0x1a9b('0x26')],'work_number':_0x5ceda8['contactNumber'],'mobile_number':_0x5ceda8[_0x1a9b('0x26')],'owner_id':_0x5ceda8[_0x1a9b('0x1a')],'created_at':_0x476564[_0x1a9b('0x24')]('YYYY-MM-DDTHH:mm:ss')}},'json':!![]};_0x42f540[_0x1a9b('0xc')]=_0x5be8b9;logger[_0x1a9b('0x11')](_0x1a9b('0x2c'));return rp(_0x42f540)[_0x1a9b('0x17')](function(_0x5d6213){_0x5ceda8['endUserId']=_0x5d6213[_0x1a9b('0x2d')]['id'];_0x54d959(_0x5ceda8);})[_0x1a9b('0x1e')](function(_0x128e84){logger['error']('['+[_0x126f89['toUpperCase']()]+']',_0x128e84[_0x1a9b('0x15')]);_0x858591(_0x128e84[_0x1a9b('0x15')]);});});}function getTicket(_0x264f2c,_0x4b4d2b,_0x31014f,_0xa568d,_0x20dfad){return function(_0x4f3991){logger[_0x1a9b('0x11')](_0x1a9b('0x2e'));return new Promise(function(_0x366788,_0x1aa79f){var _0x2eb3f0=moment();var _0x1decb8={'method':_0x1a9b('0x2a'),'uri':_0x31014f+_0x1a9b('0x2f'),'body':{'title':intUtil[_0x1a9b('0x30')](_0xa568d[_0x1a9b('0x31')],_0x20dfad,'\x20'),'description':intUtil[_0x1a9b('0x30')](_0xa568d[_0x1a9b('0x32')],_0x20dfad,'\x0a'),'owner_id':_0x4f3991[_0x1a9b('0x1a')],'creater_id':_0x4f3991[_0x1a9b('0x10')],'targetable_id':_0x4f3991[_0x1a9b('0x27')],'targetable_type':_0x1a9b('0x33'),'created_at':_0x2eb3f0['format'](_0x1a9b('0x34')),'due_date':_0x2eb3f0[_0x1a9b('0x35')](0x1e,'m')['format'](_0x1a9b('0x34'))},'json':!![]};_0x1decb8['headers']=_0x4b4d2b;return rp(_0x1decb8)['then'](function(_0x2311eb){_0x4f3991[_0x1a9b('0x36')]=_0x2311eb[_0x1a9b('0x37')]['id'];logger[_0x1a9b('0x11')](_0x1a9b('0x38'),_0x4f3991[_0x1a9b('0x36')]);_0x366788(_0x4f3991);})[_0x1a9b('0x1e')](function(_0x4e92aa){logger[_0x1a9b('0x1f')]('['+[_0x264f2c[_0x1a9b('0x14')]()]+']',_0x4e92aa[_0x1a9b('0x15')]);_0x1aa79f(_0x4e92aa[_0x1a9b('0x15')]);});});};}function emit(_0x49f356,_0x12177f,_0x43d00a){var _0x1bb0d3={'uri':_0x49f356+_0x1a9b('0x39')+_0x43d00a};io['to'](util['format'](_0x1a9b('0x3a'),_0x12177f))[_0x1a9b('0x3b')](_0x1a9b('0x3c'),_0x1bb0d3);}exports['cs']=function(_0x1e93df,_0x38c609,_0x4f3f11,_0x4d20ee,_0x1ae427,_0xfece03,_0x5dad36,_0x52b06e){var _0x252140={};var _0x369156={'Authorization':_0x1a9b('0x3d')+_0xfece03['apiKey']};_0xfece03[_0x1a9b('0x3e')]=intUtil[_0x1a9b('0x3f')](_0xfece03[_0x1a9b('0x3e')]);_0xfece03[_0x1a9b('0x40')]=intUtil[_0x1a9b('0x3f')](_0xfece03[_0x1a9b('0x40')]);var _0x24c4de=_0xfece03['remoteUri'];_0x252140['adminEmail']=_0xfece03['username'];_0x252140[_0x1a9b('0x26')]=_0x52b06e[_0x1a9b('0x41')]()===_0x1a9b('0x42')?_0x38c609[_0x1a9b('0x43')]:_0x38c609[_0x1a9b('0x44')];_0x252140['callDirection']=_0x52b06e===_0x1a9b('0x45')||_0x52b06e===_0x1a9b('0x46')?_0x1a9b('0x45'):_0x1a9b('0x42');if(_0x4d20ee){_0x252140[_0x1a9b('0x18')]=_0x4d20ee[_0x1a9b('0xf')];}var _0xedb034=util[_0x1a9b('0x24')](_0x1a9b('0x47'),_0xfece03[_0x1a9b('0x40')],_0x38c609[_0x1a9b('0x48')],md5(_0x38c609[_0x1a9b('0x48')]));if(_0x1ae427&&_0x1ae427[_0x1a9b('0x49')]){logger[_0x1a9b('0x11')](_0x1a9b('0x4a'),_0x1a9b('0x4b'));_0x38c609[_0x1a9b('0x4c')]=_0xedb034;}else if(_0x5dad36&&_0x5dad36[_0x1a9b('0x4d')]&&_0x5dad36[_0x1a9b('0x4d')]!==_0x1a9b('0x4e')){logger[_0x1a9b('0x11')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x38c609[_0x1a9b('0x4c')]=_0xedb034;}else{_0x38c609[_0x1a9b('0x4c')]='';}return getAdminId(_0x252140,_0x52b06e,_0x369156,_0x24c4de)[_0x1a9b('0x17')](getUser(_0x52b06e,_0x369156,_0x24c4de))[_0x1a9b('0x17')](getEndUser(_0x52b06e,_0x369156,_0x24c4de))['then'](getTicket(_0x52b06e,_0x369156,_0x24c4de,_0x4f3f11,_0x38c609))[_0x1a9b('0x17')](function(_0x4ba93b){logger[_0x1a9b('0x11')](util[_0x1a9b('0x24')](_0x1a9b('0x4f'),_0x4ba93b[_0x1a9b('0x36')]));if(_0x52b06e!==_0x1a9b('0x46')){logger[_0x1a9b('0x11')]('['+[_0x52b06e[_0x1a9b('0x14')]()]+']',_0x1a9b('0x50'));emit(_0x24c4de,_0x4d20ee[_0x1a9b('0x51')],_0x4ba93b[_0x1a9b('0x27')]);}})[_0x1a9b('0x1e')](function(_0x1cbad7){logger[_0x1a9b('0x1f')]('['+[_0x52b06e[_0x1a9b('0x14')]()]+_0x1a9b('0x52'),util[_0x1a9b('0x53')](_0x1cbad7,{'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