Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / services / ami / trigger / integration / freshdesk.js
index e4263bf..5add06c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf5dd=['calleridnum','getString','Subjects','<br>','Tags','name','mapValues','keyBy','custom_fields','%s/api/v2/tickets','POST','then','Ticket\x20created!','validateEmail','%s/api/v2/agents','remoteUri','info','Agent\x20found!','find','email','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/api/v2/agents/me','Admin\x20account\x20selected.','Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!','%s/api/v2/contacts','length','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Enduser\x20created.','Basic\x20%s','apiKey','base64','debug','[HTTP]','map','string','nameField','customField','content','toString','type','push','idField','variable','variableName','customVariable','Variable','toLowerCase','queue','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/helpdesk/tickets/%d','catch','error','outbound','recordingFormat','none','Authorization','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','[OUTBOUND]','unmanaged','lastevent','toUpperCase','md5','ioredis','./util','../../../../config/environment','../../../../config/logger','freshdesk','redis','defaults','localhost','socket.io-emitter','application/json','Creating\x20new\x20ticket...','merge','format','Caller\x20-\x20%s','calleridname'];(function(_0x42b545,_0x217935){var _0x27de0e=function(_0xe54e13){while(--_0xe54e13){_0x42b545['push'](_0x42b545['shift']());}};_0x27de0e(++_0x217935);}(_0xf5dd,0xa6));var _0xdf5d=function(_0x57b54c,_0x54ce0d){_0x57b54c=_0x57b54c-0x0;var _0x59cc19=_0xf5dd[_0x57b54c];return _0x59cc19;};'use strict';var _=require('lodash');var rp=require('request-promise');var md5=require(_0xdf5d('0x0'));var util=require('util');var Redis=require(_0xdf5d('0x1'));var intUtil=require(_0xdf5d('0x2'));var config=require(_0xdf5d('0x3'));var logger=require(_0xdf5d('0x4'))(_0xdf5d('0x5'));config[_0xdf5d('0x6')]=_[_0xdf5d('0x7')](config[_0xdf5d('0x6')],{'host':_0xdf5d('0x8'),'port':0x18eb});var io=require(_0xdf5d('0x9'))(new Redis(config[_0xdf5d('0x6')]));var headers={'Content-Type':_0xdf5d('0xa'),'Accept':_0xdf5d('0xa')};function emit(_0x316d65,_0x14af76,_0x301364){io['to'](_0x316d65)['emit'](_0x14af76,_0x301364);}function getTicket(_0x4f104c,_0x345121,_0x3720ae,_0x431a83,_0x3ad9cd){logger['info'](_0xdf5d('0xb'));var _0x348dcc=_[_0xdf5d('0xc')]({'responder_id':_0x345121['id'],'requester_id':_0x3720ae['id'],'name':util[_0xdf5d('0xd')](_0xdf5d('0xe'),_0x3ad9cd[_0xdf5d('0xf')]),'phone':_0x3ad9cd[_0xdf5d('0x10')],'source':0x3,'priority':0x1,'status':0x2,'subject':intUtil[_0xdf5d('0x11')](_0x431a83[_0xdf5d('0x12')],_0x3ad9cd,'\x20'),'description':intUtil[_0xdf5d('0x11')](_0x431a83['Descriptions'],_0x3ad9cd,_0xdf5d('0x13')),'tags':getTags(_0x431a83[_0xdf5d('0x14')],_0xdf5d('0x15'))},getCustomFields(_0x431a83['Fields'],_0x3ad9cd));_0x348dcc['custom_fields']=_[_0xdf5d('0x16')](_[_0xdf5d('0x17')](_0x348dcc[_0xdf5d('0x18')],'id'),'value');return request({'uri':util[_0xdf5d('0xd')](_0xdf5d('0x19'),_0x4f104c['remoteUri']),'method':_0xdf5d('0x1a'),'body':_0x348dcc})[_0xdf5d('0x1b')](function(_0x299f73){logger['info'](_0xdf5d('0x1c'));return _0x299f73;});}function getUser(_0x25b4c1,_0x136e92){if(intUtil[_0xdf5d('0x1d')](_0x136e92)){return request({'uri':util['format'](_0xdf5d('0x1e'),_0x25b4c1[_0xdf5d('0x1f')]),'qs':{'email':_0x136e92}})[_0xdf5d('0x1b')](function(_0x264c15){if(_0x264c15['length']){logger[_0xdf5d('0x20')](_0xdf5d('0x21'));return _[_0xdf5d('0x22')](_0x264c15,function(_0x530a98){return _0x530a98['contact'][_0xdf5d('0x23')]===_0x136e92;});}else{logger[_0xdf5d('0x20')](_0xdf5d('0x24'));return request({'uri':util[_0xdf5d('0xd')](_0xdf5d('0x25'),_0x25b4c1['remoteUri'])})[_0xdf5d('0x1b')](function(_0x36d44c){logger[_0xdf5d('0x20')](_0xdf5d('0x26'));return _0x36d44c;});}});}else{logger[_0xdf5d('0x20')](_0xdf5d('0x27'));return request({'uri':util[_0xdf5d('0xd')](_0xdf5d('0x25'),_0x25b4c1[_0xdf5d('0x1f')])})[_0xdf5d('0x1b')](function(_0x217078){logger[_0xdf5d('0x20')]('Admin\x20account\x20selected.');return _0x217078;});}}function getEndUser(_0x400598,_0x5b03dd,_0x46cb24){logger['info']('Searching\x20enduser\x20with\x20phone',_0x46cb24);return request({'uri':util[_0xdf5d('0xd')](_0xdf5d('0x28'),_0x400598[_0xdf5d('0x1f')]),'qs':{'phone':_0x46cb24}})[_0xdf5d('0x1b')](function(_0x452c2){if(_0x452c2[_0xdf5d('0x29')]){logger[_0xdf5d('0x20')]('Enduser\x20found!');return _[_0xdf5d('0x22')](_0x452c2,{'phone':_0x46cb24});}else{logger[_0xdf5d('0x20')](_0xdf5d('0x2a'));return request({'uri':util['format'](_0xdf5d('0x28'),_0x400598['remoteUri']),'method':_0xdf5d('0x1a'),'body':{'name':_0x5b03dd,'phone':_0x46cb24}})[_0xdf5d('0x1b')](function(_0x1b5f97){logger[_0xdf5d('0x20')](_0xdf5d('0x2b'));return _0x1b5f97;});}});}function getAuth(_0x301d6c){return util[_0xdf5d('0xd')](_0xdf5d('0x2c'),new Buffer(_0x301d6c[_0xdf5d('0x2d')]+':X')['toString'](_0xdf5d('0x2e')));}function request(_0x21e8cd){logger[_0xdf5d('0x2f')](_0xdf5d('0x30'),JSON['stringify'](_0x21e8cd));return rp(_[_0xdf5d('0x7')](_0x21e8cd,{'method':'GET','headers':headers,'json':!![]}));}function getTags(_0x2d8fcb,_0x264253){var _0x9d8e18=[];if(_0x2d8fcb&&_0x2d8fcb[_0xdf5d('0x29')]>0x0){_0x9d8e18=_[_0xdf5d('0x31')](_0x2d8fcb,_0x264253);}return _0x9d8e18;}function getCustomFields(_0x40fc62,_0x40eb26){var _0x9a8b8b=[];var _0x5300c0={'custom_fields':[]};if(_0x40fc62[_0xdf5d('0x29')]>0x0){_['forEach'](_0x40fc62,function(_0x1ce9ef){if(_0x1ce9ef['type']===_0xdf5d('0x32')&&_0x1ce9ef[_0xdf5d('0x33')]&&!_0x1ce9ef[_0xdf5d('0x34')]){_0x5300c0[_0x1ce9ef[_0xdf5d('0x33')]['toLowerCase']()]=_0x1ce9ef[_0xdf5d('0x35')][_0xdf5d('0x36')]();}else if(_0x1ce9ef[_0xdf5d('0x37')]==='string'&&_0x1ce9ef['idField']&&_0x1ce9ef[_0xdf5d('0x34')]){_0x5300c0[_0xdf5d('0x18')][_0xdf5d('0x38')]({'id':_0x1ce9ef[_0xdf5d('0x39')],'value':_0x1ce9ef[_0xdf5d('0x35')]['toString']()});}else if(_0x1ce9ef['type']===_0xdf5d('0x3a')&&_0x1ce9ef[_0xdf5d('0x3b')]&&_0x1ce9ef[_0xdf5d('0x39')]&&_0x1ce9ef[_0xdf5d('0x34')]){_0x40eb26[_0x1ce9ef['variableName']]&&_0x5300c0[_0xdf5d('0x18')][_0xdf5d('0x38')]({'id':_0x1ce9ef[_0xdf5d('0x39')],'value':_0x40eb26[_0x1ce9ef[_0xdf5d('0x3b')]]['toString']()});}else if(_0x1ce9ef[_0xdf5d('0x37')]===_0xdf5d('0x3c')&&_0x1ce9ef[_0xdf5d('0x3d')]&&_0x1ce9ef['Variable'][_0xdf5d('0x15')]&&_0x1ce9ef['idField']&&_0x1ce9ef[_0xdf5d('0x34')]){_0x40eb26[_0x1ce9ef[_0xdf5d('0x3d')][_0xdf5d('0x15')]['toLowerCase']()]&&_0x5300c0['custom_fields'][_0xdf5d('0x38')]({'id':_0x1ce9ef['idField'],'value':_0x40eb26[_0x1ce9ef[_0xdf5d('0x3d')][_0xdf5d('0x15')][_0xdf5d('0x3e')]()][_0xdf5d('0x36')]()});}});}return _0x5300c0;}exports[_0xdf5d('0x3f')]=function(_0x552e9a,_0x3023d8,_0x4a1f2f,_0x3b97c4,_0x5dbe4c,_0x218d47){var _0x3d1f5e,_0x37f1f3;_0x218d47[_0xdf5d('0x1f')]=intUtil[_0xdf5d('0x40')](_0x218d47['remoteUri']);_0x218d47[_0xdf5d('0x41')]=intUtil[_0xdf5d('0x40')](_0x218d47[_0xdf5d('0x41')]);if(_0x5dbe4c&&_0x5dbe4c[_0xdf5d('0x42')]){logger[_0xdf5d('0x20')]('[QUEUE]',_0xdf5d('0x43'));_0x3023d8[_0xdf5d('0x44')]=util[_0xdf5d('0xd')](_0xdf5d('0x45'),_0x218d47[_0xdf5d('0x41')],_0x3023d8[_0xdf5d('0x46')],md5(_0x3023d8['uniqueid']));}else{_0x3023d8[_0xdf5d('0x44')]='';}headers['Authorization']=getAuth(_0x218d47);return getUser(_0x218d47,_0x3b97c4[_0xdf5d('0x23')])[_0xdf5d('0x1b')](function(_0x236105){_0x3d1f5e=_0x236105;logger[_0xdf5d('0x20')]('The\x20User\x20ID\x20is:',_0x3d1f5e['id']);return getEndUser(_0x218d47,_0x3023d8['calleridname'],_0x3023d8[_0xdf5d('0x10')]);})[_0xdf5d('0x1b')](function(_0x39b353){_0x37f1f3=_0x39b353;logger[_0xdf5d('0x20')](_0xdf5d('0x47'),_0x37f1f3['id']);return getTicket(_0x218d47,_0x3d1f5e,_0x37f1f3,_0x4a1f2f,_0x3023d8);})[_0xdf5d('0x1b')](function(_0x50764a){if(_0x50764a&&_0x50764a['id']){logger[_0xdf5d('0x20')](_0xdf5d('0x1c'));logger[_0xdf5d('0x20')](_0xdf5d('0x48'),_0x50764a['id']);logger[_0xdf5d('0x20')](_0xdf5d('0x49'),_0xdf5d('0x4a'));emit(util[_0xdf5d('0xd')](_0xdf5d('0x4b'),_0x3b97c4[_0xdf5d('0x15')]),_0xdf5d('0x4c'),{'uri':util[_0xdf5d('0xd')](_0xdf5d('0x4d'),_0x218d47[_0xdf5d('0x1f')],_0x50764a['id'])});}})[_0xdf5d('0x4e')](function(_0x1e83d6){logger[_0xdf5d('0x4f')]('[QUEUE]',JSON['stringify'](_0x1e83d6));});};exports[_0xdf5d('0x50')]=function(_0x2cd608,_0x30255a,_0x52333d,_0x38228e,_0x20f83f,_0x488fff,_0x522a17){var _0x185676,_0x2b0ff1;_0x488fff['remoteUri']=intUtil['stripTrailingSlash'](_0x488fff[_0xdf5d('0x1f')]);_0x488fff['serverUrl']=intUtil['stripTrailingSlash'](_0x488fff[_0xdf5d('0x41')]);if(_0x522a17&&_0x522a17[_0xdf5d('0x51')]&&_0x522a17['recordingFormat']!==_0xdf5d('0x52')){logger[_0xdf5d('0x20')]('[OUTBOUND]',_0xdf5d('0x43'));_0x30255a[_0xdf5d('0x44')]=util[_0xdf5d('0xd')](_0xdf5d('0x45'),_0x488fff[_0xdf5d('0x41')],_0x30255a[_0xdf5d('0x46')],md5(_0x30255a['uniqueid']));}headers[_0xdf5d('0x53')]=getAuth(_0x488fff);return getUser(_0x488fff,_0x38228e[_0xdf5d('0x23')])['then'](function(_0x226c0e){_0x185676=_0x226c0e;logger[_0xdf5d('0x20')](_0xdf5d('0x54'),_0x185676['id']);return getEndUser(_0x488fff,_0x30255a[_0xdf5d('0x55')],_0x30255a[_0xdf5d('0x56')]);})[_0xdf5d('0x1b')](function(_0x32faa7){_0x2b0ff1=_0x32faa7;logger[_0xdf5d('0x20')](_0xdf5d('0x47'),_0x2b0ff1['id']);return getTicket(_0x488fff,_0x185676,_0x2b0ff1,_0x52333d,_0x30255a);})[_0xdf5d('0x1b')](function(_0x29ff5e){if(_0x29ff5e&&_0x29ff5e['id']){logger[_0xdf5d('0x20')](_0xdf5d('0x1c'));logger[_0xdf5d('0x20')](_0xdf5d('0x48'),_0x29ff5e['id']);logger[_0xdf5d('0x20')](_0xdf5d('0x57'),_0xdf5d('0x4a'));emit(util[_0xdf5d('0xd')](_0xdf5d('0x4b'),_0x38228e[_0xdf5d('0x15')]),'trigger:browser:url',{'uri':util[_0xdf5d('0xd')]('%s/helpdesk/tickets/%d',_0x488fff['remoteUri'],_0x29ff5e['id'])});}})[_0xdf5d('0x4e')](function(_0x3ee88d){logger[_0xdf5d('0x4f')]('[OUTBOUND]',JSON['stringify'](_0x3ee88d));});};exports[_0xdf5d('0x58')]=function(_0x16b033,_0x2c6136,_0x3bd016,_0x7d7277,_0x3c462f,_0x435534){var _0x277011,_0x465b68;_0x435534[_0xdf5d('0x1f')]=intUtil['stripTrailingSlash'](_0x435534[_0xdf5d('0x1f')]);_0x435534[_0xdf5d('0x41')]=intUtil[_0xdf5d('0x40')](_0x435534[_0xdf5d('0x41')]);if(_0x3c462f&&_0x3c462f[_0xdf5d('0x42')]){logger['info']('['+_0x2c6136[_0xdf5d('0x59')][_0xdf5d('0x5a')]()+']',_0xdf5d('0x43'));_0x2c6136['recordingURL']=util[_0xdf5d('0xd')](_0xdf5d('0x45'),_0x435534['serverUrl'],_0x2c6136[_0xdf5d('0x46')],md5(_0x2c6136[_0xdf5d('0x46')]));}else{_0x2c6136[_0xdf5d('0x44')]='';}headers[_0xdf5d('0x53')]=getAuth(_0x435534);return getUser(_0x435534,'')['then'](function(_0x38f467){_0x277011=_0x38f467;logger[_0xdf5d('0x20')]('The\x20User\x20ID\x20is:',_0x277011['id']);return getEndUser(_0x435534,_0x2c6136[_0xdf5d('0xf')],_0x2c6136[_0xdf5d('0x10')]);})[_0xdf5d('0x1b')](function(_0x129b84){_0x465b68=_0x129b84;logger[_0xdf5d('0x20')](_0xdf5d('0x47'),_0x465b68['id']);return getTicket(_0x435534,_0x277011,_0x465b68,_0x3bd016,_0x2c6136);})[_0xdf5d('0x1b')](function(_0x3e560e){if(_0x3e560e){logger[_0xdf5d('0x20')](_0xdf5d('0x1c'));logger[_0xdf5d('0x20')](_0xdf5d('0x48'),_0x3e560e['id']);}})[_0xdf5d('0x4e')](function(_0x394605){logger[_0xdf5d('0x4f')]('['+_0x2c6136[_0xdf5d('0x59')][_0xdf5d('0x5a')]()+']',JSON['stringify'](_0x394605));});};
\ No newline at end of file
+var _0xcbee=['picklist','customField','nameField','toLowerCase','content','type','idField','variable','push','variableName','customVariable','Variable','queue','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','The\x20User\x20ID\x20is:','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/helpdesk/tickets/%d','catch','error','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','stringify','toUpperCase','lastevent','lodash','request-promise','util','ioredis','./util','../../../../config/environment','redis','localhost','application/json','emit','Creating\x20new\x20ticket...','merge','format','Caller\x20-\x20%s','calleridname','calleridnum','getString','Descriptions','<br>','Tags','name','Fields','mapValues','keyBy','custom_fields','value','%s/api/v2/tickets','remoteUri','POST','info','Ticket\x20created!','validateEmail','%s/api/v2/agents','length','Agent\x20found!','find','email','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/api/v2/agents/me','Admin\x20account\x20selected.','then','Searching\x20enduser\x20with\x20phone','%s/api/v2/contacts','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Enduser\x20created.','Basic\x20%s','toString','debug','[HTTP]','defaults','GET','map','forEach','includes','string'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xcbee,0x1a8));var _0xecbe=function(_0x39af5a,_0x5c5bf0){_0x39af5a=_0x39af5a-0x0;var _0xea428e=_0xcbee[_0x39af5a];return _0xea428e;};'use strict';var _=require(_0xecbe('0x0'));var rp=require(_0xecbe('0x1'));var md5=require('md5');var util=require(_0xecbe('0x2'));var Redis=require(_0xecbe('0x3'));var intUtil=require(_0xecbe('0x4'));var config=require(_0xecbe('0x5'));var logger=require('../../../../config/logger')('freshdesk');config[_0xecbe('0x6')]=_['defaults'](config['redis'],{'host':_0xecbe('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));var headers={'Content-Type':_0xecbe('0x8'),'Accept':_0xecbe('0x8')};function emit(_0x177705,_0x53600d,_0x1fc455){io['to'](_0x177705)[_0xecbe('0x9')](_0x53600d,_0x1fc455);}function getTicket(_0x50471f,_0x365173,_0x1437ff,_0x549422,_0x1a1166){logger['info'](_0xecbe('0xa'));var _0xe7ad5f=_[_0xecbe('0xb')]({'responder_id':_0x365173['id'],'requester_id':_0x1437ff['id'],'name':util[_0xecbe('0xc')](_0xecbe('0xd'),_0x1a1166[_0xecbe('0xe')]),'phone':_0x1a1166[_0xecbe('0xf')],'source':0x3,'priority':0x1,'status':0x2,'subject':intUtil[_0xecbe('0x10')](_0x549422['Subjects'],_0x1a1166,'\x20'),'description':intUtil[_0xecbe('0x10')](_0x549422[_0xecbe('0x11')],_0x1a1166,_0xecbe('0x12')),'tags':getTags(_0x549422[_0xecbe('0x13')],_0xecbe('0x14'))},getCustomFields(_0x549422[_0xecbe('0x15')],_0x1a1166));_0xe7ad5f['custom_fields']=_[_0xecbe('0x16')](_[_0xecbe('0x17')](_0xe7ad5f[_0xecbe('0x18')],'id'),_0xecbe('0x19'));return request({'uri':util[_0xecbe('0xc')](_0xecbe('0x1a'),_0x50471f[_0xecbe('0x1b')]),'method':_0xecbe('0x1c'),'body':_0xe7ad5f})['then'](function(_0x405ab2){logger[_0xecbe('0x1d')](_0xecbe('0x1e'));return _0x405ab2;});}function getUser(_0x5cc878,_0x2cdcf9){if(intUtil[_0xecbe('0x1f')](_0x2cdcf9)){return request({'uri':util[_0xecbe('0xc')](_0xecbe('0x20'),_0x5cc878[_0xecbe('0x1b')]),'qs':{'email':_0x2cdcf9}})['then'](function(_0x1695e5){if(_0x1695e5[_0xecbe('0x21')]){logger['info'](_0xecbe('0x22'));return _[_0xecbe('0x23')](_0x1695e5,function(_0x595f9b){return _0x595f9b['contact'][_0xecbe('0x24')]===_0x2cdcf9;});}else{logger[_0xecbe('0x1d')](_0xecbe('0x25'));return request({'uri':util['format'](_0xecbe('0x26'),_0x5cc878['remoteUri'])})['then'](function(_0x9d6345){logger[_0xecbe('0x1d')](_0xecbe('0x27'));return _0x9d6345;});}});}else{logger[_0xecbe('0x1d')]('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!');return request({'uri':util['format']('%s/api/v2/agents/me',_0x5cc878[_0xecbe('0x1b')])})[_0xecbe('0x28')](function(_0x54bebf){logger[_0xecbe('0x1d')](_0xecbe('0x27'));return _0x54bebf;});}}function getEndUser(_0x71d4c2,_0x48d289,_0x81f839){logger[_0xecbe('0x1d')](_0xecbe('0x29'),_0x81f839);return request({'uri':util[_0xecbe('0xc')](_0xecbe('0x2a'),_0x71d4c2['remoteUri']),'qs':{'phone':_0x81f839}})[_0xecbe('0x28')](function(_0x1bd0c6){if(_0x1bd0c6['length']){logger[_0xecbe('0x1d')](_0xecbe('0x2b'));return _[_0xecbe('0x23')](_0x1bd0c6,{'phone':_0x81f839});}else{logger[_0xecbe('0x1d')](_0xecbe('0x2c'));return request({'uri':util[_0xecbe('0xc')](_0xecbe('0x2a'),_0x71d4c2['remoteUri']),'method':'POST','body':{'name':_0x48d289,'phone':_0x81f839}})[_0xecbe('0x28')](function(_0x3b4704){logger[_0xecbe('0x1d')](_0xecbe('0x2d'));return _0x3b4704;});}});}function getAuth(_0x3f850c){return util[_0xecbe('0xc')](_0xecbe('0x2e'),new Buffer(_0x3f850c['apiKey']+':X')[_0xecbe('0x2f')]('base64'));}function request(_0x40ff36){logger[_0xecbe('0x30')](_0xecbe('0x31'),JSON['stringify'](_0x40ff36));return rp(_[_0xecbe('0x32')](_0x40ff36,{'method':_0xecbe('0x33'),'headers':headers,'json':!![]}));}function getTags(_0x173630,_0x1063a4){var _0x5b4bec=[];if(_0x173630&&_0x173630['length']>0x0){_0x5b4bec=_[_0xecbe('0x34')](_0x173630,_0x1063a4);}return _0x5b4bec;}function getCustomFields(_0x3b3e68,_0x1b1631){var _0x212db1=[];var _0x2cfc09={'custom_fields':[]};if(_0x3b3e68['length']>0x0){_[_0xecbe('0x35')](_0x3b3e68,function(_0x3db034){if(_[_0xecbe('0x36')]([_0xecbe('0x37'),_0xecbe('0x38')],_0x3db034['type'])&&_0x3db034['nameField']&&!_0x3db034[_0xecbe('0x39')]){_0x2cfc09[_0x3db034[_0xecbe('0x3a')][_0xecbe('0x3b')]()]=_0x3db034[_0xecbe('0x3c')]['toString']();}else if(_[_0xecbe('0x36')](['string','picklist'],_0x3db034[_0xecbe('0x3d')])&&_0x3db034[_0xecbe('0x3e')]&&_0x3db034[_0xecbe('0x39')]){_0x2cfc09[_0xecbe('0x18')]['push']({'id':_0x3db034[_0xecbe('0x3e')],'value':_0x3db034['content'][_0xecbe('0x2f')]()});}else if(_0x3db034[_0xecbe('0x3d')]===_0xecbe('0x3f')&&_0x3db034['variableName']&&_0x3db034[_0xecbe('0x3e')]&&_0x3db034[_0xecbe('0x39')]){_0x1b1631[_0x3db034['variableName']]&&_0x2cfc09[_0xecbe('0x18')][_0xecbe('0x40')]({'id':_0x3db034[_0xecbe('0x3e')],'value':_0x1b1631[_0x3db034[_0xecbe('0x41')]][_0xecbe('0x2f')]()});}else if(_0x3db034[_0xecbe('0x3d')]===_0xecbe('0x42')&&_0x3db034[_0xecbe('0x43')]&&_0x3db034['Variable'][_0xecbe('0x14')]&&_0x3db034['idField']&&_0x3db034[_0xecbe('0x39')]){_0x1b1631[_0x3db034[_0xecbe('0x43')][_0xecbe('0x14')][_0xecbe('0x3b')]()]&&_0x2cfc09[_0xecbe('0x18')][_0xecbe('0x40')]({'id':_0x3db034['idField'],'value':_0x1b1631[_0x3db034['Variable'][_0xecbe('0x14')][_0xecbe('0x3b')]()][_0xecbe('0x2f')]()});}});}return _0x2cfc09;}exports[_0xecbe('0x44')]=function(_0x353502,_0x373074,_0x20110b,_0x7b545,_0x34832a,_0x393291){var _0x4abd16,_0x452345;_0x393291[_0xecbe('0x1b')]=intUtil[_0xecbe('0x45')](_0x393291[_0xecbe('0x1b')]);_0x393291[_0xecbe('0x46')]=intUtil[_0xecbe('0x45')](_0x393291[_0xecbe('0x46')]);if(_0x34832a&&_0x34832a[_0xecbe('0x47')]){logger[_0xecbe('0x1d')]('[QUEUE]',_0xecbe('0x48'));_0x373074[_0xecbe('0x49')]=util[_0xecbe('0xc')](_0xecbe('0x4a'),_0x393291['serverUrl'],_0x373074[_0xecbe('0x4b')],md5(_0x373074['uniqueid']));}else{_0x373074[_0xecbe('0x49')]='';}headers[_0xecbe('0x4c')]=getAuth(_0x393291);return getUser(_0x393291,_0x7b545['email'])[_0xecbe('0x28')](function(_0x16ea4b){_0x4abd16=_0x16ea4b;logger[_0xecbe('0x1d')](_0xecbe('0x4d'),_0x4abd16['id']);return getEndUser(_0x393291,_0x373074[_0xecbe('0xe')],_0x373074[_0xecbe('0xf')]);})[_0xecbe('0x28')](function(_0x28768a){_0x452345=_0x28768a;logger[_0xecbe('0x1d')](_0xecbe('0x4e'),_0x452345['id']);return getTicket(_0x393291,_0x4abd16,_0x452345,_0x20110b,_0x373074);})[_0xecbe('0x28')](function(_0x16bb9c){if(_0x16bb9c&&_0x16bb9c['id']){logger[_0xecbe('0x1d')]('Ticket\x20created!');logger[_0xecbe('0x1d')](_0xecbe('0x4f'),_0x16bb9c['id']);logger[_0xecbe('0x1d')](_0xecbe('0x50'),_0xecbe('0x51'));emit(util[_0xecbe('0xc')](_0xecbe('0x52'),_0x7b545[_0xecbe('0x14')]),_0xecbe('0x53'),{'uri':util[_0xecbe('0xc')](_0xecbe('0x54'),_0x393291[_0xecbe('0x1b')],_0x16bb9c['id'])});}})[_0xecbe('0x55')](function(_0x669621){logger[_0xecbe('0x56')](_0xecbe('0x50'),JSON['stringify'](_0x669621));});};exports[_0xecbe('0x57')]=function(_0x229d8f,_0x404fe5,_0x46cc01,_0x1a1358,_0x2f9e29,_0x206068,_0x515378){var _0x46a4f2,_0x394dcf;_0x206068[_0xecbe('0x1b')]=intUtil[_0xecbe('0x45')](_0x206068['remoteUri']);_0x206068['serverUrl']=intUtil['stripTrailingSlash'](_0x206068[_0xecbe('0x46')]);if(_0x515378&&_0x515378['recordingFormat']&&_0x515378[_0xecbe('0x58')]!==_0xecbe('0x59')){logger[_0xecbe('0x1d')](_0xecbe('0x5a'),_0xecbe('0x48'));_0x404fe5['recordingURL']=util[_0xecbe('0xc')](_0xecbe('0x4a'),_0x206068[_0xecbe('0x46')],_0x404fe5[_0xecbe('0x4b')],md5(_0x404fe5[_0xecbe('0x4b')]));}headers['Authorization']=getAuth(_0x206068);return getUser(_0x206068,_0x1a1358[_0xecbe('0x24')])[_0xecbe('0x28')](function(_0x5a51be){_0x46a4f2=_0x5a51be;logger[_0xecbe('0x1d')]('The\x20User\x20ID\x20is:',_0x46a4f2['id']);return getEndUser(_0x206068,_0x404fe5[_0xecbe('0x5b')],_0x404fe5[_0xecbe('0x5c')]);})[_0xecbe('0x28')](function(_0x1ea72f){_0x394dcf=_0x1ea72f;logger[_0xecbe('0x1d')]('The\x20Enduser\x20ID\x20is:',_0x394dcf['id']);return getTicket(_0x206068,_0x46a4f2,_0x394dcf,_0x46cc01,_0x404fe5);})[_0xecbe('0x28')](function(_0x2e9f09){if(_0x2e9f09&&_0x2e9f09['id']){logger[_0xecbe('0x1d')]('Ticket\x20created!');logger[_0xecbe('0x1d')](_0xecbe('0x4f'),_0x2e9f09['id']);logger['info'](_0xecbe('0x5a'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xecbe('0xc')]('user:%s',_0x1a1358[_0xecbe('0x14')]),_0xecbe('0x53'),{'uri':util[_0xecbe('0xc')](_0xecbe('0x54'),_0x206068[_0xecbe('0x1b')],_0x2e9f09['id'])});}})[_0xecbe('0x55')](function(_0x3802ce){logger[_0xecbe('0x56')](_0xecbe('0x5a'),JSON[_0xecbe('0x5d')](_0x3802ce));});};exports['unmanaged']=function(_0x60bd24,_0x48614f,_0x5b92de,_0x1501d1,_0xd5d51d,_0x3c46a6){var _0x3ed28f,_0x33afe2;_0x3c46a6[_0xecbe('0x1b')]=intUtil[_0xecbe('0x45')](_0x3c46a6[_0xecbe('0x1b')]);_0x3c46a6[_0xecbe('0x46')]=intUtil[_0xecbe('0x45')](_0x3c46a6[_0xecbe('0x46')]);if(_0xd5d51d&&_0xd5d51d['monitor_format']){logger[_0xecbe('0x1d')]('['+_0x48614f['lastevent'][_0xecbe('0x5e')]()+']',_0xecbe('0x48'));_0x48614f[_0xecbe('0x49')]=util[_0xecbe('0xc')](_0xecbe('0x4a'),_0x3c46a6['serverUrl'],_0x48614f[_0xecbe('0x4b')],md5(_0x48614f[_0xecbe('0x4b')]));}else{_0x48614f[_0xecbe('0x49')]='';}headers[_0xecbe('0x4c')]=getAuth(_0x3c46a6);return getUser(_0x3c46a6,'')[_0xecbe('0x28')](function(_0x2ccdd3){_0x3ed28f=_0x2ccdd3;logger[_0xecbe('0x1d')]('The\x20User\x20ID\x20is:',_0x3ed28f['id']);return getEndUser(_0x3c46a6,_0x48614f[_0xecbe('0xe')],_0x48614f['calleridnum']);})[_0xecbe('0x28')](function(_0x7cdacc){_0x33afe2=_0x7cdacc;logger[_0xecbe('0x1d')](_0xecbe('0x4e'),_0x33afe2['id']);return getTicket(_0x3c46a6,_0x3ed28f,_0x33afe2,_0x5b92de,_0x48614f);})[_0xecbe('0x28')](function(_0x28a3ce){if(_0x28a3ce){logger['info'](_0xecbe('0x1e'));logger[_0xecbe('0x1d')]('The\x20Ticket\x20ID\x20is:',_0x28a3ce['id']);}})[_0xecbe('0x55')](function(_0x44e619){logger[_0xecbe('0x56')]('['+_0x48614f[_0xecbe('0x5f')]['toUpperCase']()+']',JSON[_0xecbe('0x5d')](_0x44e619));});};
\ No newline at end of file