Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index d3df33e..ec4313a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0e4b=['lodash','request-promise','md5','ioredis','redis','defaults','localhost','socket.io-emitter','application/json','info','Creating\x20new\x20ticket...','format','%s/tickets.json','remoteUri','POST','merge','Tags','getString','Subjects','Descriptions','Fields','then','Ticket\x20created!','ticket','validateEmail','Getting\x20agent\x20with\x20email','%s/search.json','count','Agent\x20found!','find','agent','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','type:user\x20role:end-user\x20phone:%s','results','length','filter','end-user','first','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','Caller\x20-\x20%s','Enduser\x20created.','authType','username','password','token','Basic\x20%s','toString','debug','[HTTP]','stringify','map','forEach','string','nameField','content','push','idField','variable','variableName','customField','custom_fields','type','customVariable','Variable','name','toLowerCase','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','recordingURL','Authorization','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','user:%s','/api/v2','Zendesk\x20account\x20type\x20not\x20recognized','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','inspect','recordingFormat','none','uniqueid','email','The\x20User\x20ID\x20is:','destcalleridname','destcalleridnum','[OUTBOUND]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','%s/agent/tickets/%s','replace','error','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','lastevent','toUpperCase','calleridname'];(function(_0xbca1b1,_0x33f0ce){var _0x4e1686=function(_0x58a80c){while(--_0x58a80c){_0xbca1b1['push'](_0xbca1b1['shift']());}};_0x4e1686(++_0x33f0ce);}(_0x0e4b,0xdc));var _0xb0e4=function(_0x9bf07f,_0x1914b4){_0x9bf07f=_0x9bf07f-0x0;var _0x543fb2=_0x0e4b[_0x9bf07f];return _0x543fb2;};'use strict';var _=require(_0xb0e4('0x0'));var rp=require(_0xb0e4('0x1'));var md5=require(_0xb0e4('0x2'));var util=require('util');var Redis=require(_0xb0e4('0x3'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require('../../../../config/logger')('zendesk');config[_0xb0e4('0x4')]=_[_0xb0e4('0x5')](config['redis'],{'host':_0xb0e4('0x6'),'port':0x18eb});var io=require(_0xb0e4('0x7'))(new Redis(config[_0xb0e4('0x4')]));function emit(_0x3dff2f,_0x35aa64,_0x57f45d){io['to'](_0x3dff2f)['emit'](_0x35aa64,_0x57f45d);}var headers={'Content-Type':_0xb0e4('0x8'),'Accept':_0xb0e4('0x8')};function getTicket(_0x1d6452,_0x23555b,_0x12a36a,_0x140b7e,_0x16940b){logger[_0xb0e4('0x9')](_0xb0e4('0xa'));return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0xc'),_0x1d6452[_0xb0e4('0xd')]),'method':_0xb0e4('0xe'),'body':{'ticket':_[_0xb0e4('0xf')]({'requester_id':_0x12a36a['id'],'submitter_id':_0x23555b?_0x23555b['id']:undefined,'assignee_id':_0x23555b?_0x23555b['id']:undefined,'tags':getTags(_0x140b7e[_0xb0e4('0x10')],'name'),'subject':intUtil[_0xb0e4('0x11')](_0x140b7e[_0xb0e4('0x12')],_0x16940b,'\x20'),'description':intUtil['getString'](_0x140b7e[_0xb0e4('0x13')],_0x16940b,'\x0a'),'comment':{'public':![],'body':intUtil[_0xb0e4('0x11')](_0x140b7e[_0xb0e4('0x13')],_0x16940b,'\x0a')}},getCustomFields(_0x140b7e[_0xb0e4('0x14')],_0x16940b))}})[_0xb0e4('0x15')](function(_0x57ba9d){logger['info'](_0xb0e4('0x16'));return _0x57ba9d[_0xb0e4('0x17')];});}function getUser(_0x5b219a,_0x152ceb){if(intUtil[_0xb0e4('0x18')](_0x152ceb)){logger[_0xb0e4('0x9')](_0xb0e4('0x19'),_0x152ceb);return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0x1a'),_0x5b219a['remoteUri']),'qs':{'query':util['format']('type:user\x20role:agent\x20email:%s',_0x152ceb)}})[_0xb0e4('0x15')](function(_0x41b3c1){if(_0x41b3c1[_0xb0e4('0x1b')]){logger[_0xb0e4('0x9')](_0xb0e4('0x1c'));return _[_0xb0e4('0x1d')](_0x41b3c1['results'],{'email':_0x152ceb,'role':_0xb0e4('0x1e')});}else{logger[_0xb0e4('0x9')](_0xb0e4('0x1f'));return request({'uri':util[_0xb0e4('0xb')]('%s/users/me.json',_0x5b219a[_0xb0e4('0xd')])})[_0xb0e4('0x15')](function(_0x52b55e){logger[_0xb0e4('0x9')](_0xb0e4('0x20'));return _0x52b55e[_0xb0e4('0x21')];});}});}else{logger['info'](_0xb0e4('0x1f'));return request({'uri':util['format']('%s/users/me.json',_0x5b219a[_0xb0e4('0xd')])})[_0xb0e4('0x15')](function(_0x139c84){logger[_0xb0e4('0x9')](_0xb0e4('0x20'));return _0x139c84[_0xb0e4('0x21')];});}}function getEndUser(_0x6665e,_0x50fe9e,_0x28ed88){logger['info'](_0xb0e4('0x22'),_0x28ed88);return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0x1a'),_0x6665e[_0xb0e4('0xd')]),'qs':{'query':util['format'](_0xb0e4('0x23'),_0x28ed88)}})[_0xb0e4('0x15')](function(_0x15d402){var _0x451008;if(_0x15d402[_0xb0e4('0x24')][_0xb0e4('0x25')]){_0x15d402[_0xb0e4('0x24')]=_[_0xb0e4('0x26')](_0x15d402['results'],{'suspended':![],'role':_0xb0e4('0x27')});if(_0x15d402['results'][_0xb0e4('0x25')]){_0x451008=_[_0xb0e4('0x28')](_0x15d402['results']);}}if(_0x451008){logger[_0xb0e4('0x9')](_0xb0e4('0x29'));return _0x451008;}else{logger[_0xb0e4('0x9')](_0xb0e4('0x2a'));return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0x2b'),_0x6665e['remoteUri']),'method':_0xb0e4('0xe'),'body':{'user':{'role':'end-user','name':util['format'](_0xb0e4('0x2c'),_0x50fe9e||_0x28ed88),'phone':_0x28ed88}}})['then'](function(_0xc51bcb){logger['info'](_0xb0e4('0x2d'));return _0xc51bcb['user'];});}});}function getAuth(_0x9d8544){var _0x12f6a6;if(_0x9d8544[_0xb0e4('0x2e')]==='password'){_0x12f6a6=util[_0xb0e4('0xb')]('%s:%s',_0x9d8544[_0xb0e4('0x2f')],_0x9d8544[_0xb0e4('0x30')]);}else if(_0x9d8544[_0xb0e4('0x2e')]===_0xb0e4('0x31')){_0x12f6a6=util[_0xb0e4('0xb')]('%s/token:%s',_0x9d8544[_0xb0e4('0x2f')],_0x9d8544['token']);}return util[_0xb0e4('0xb')](_0xb0e4('0x32'),new Buffer(_0x12f6a6)[_0xb0e4('0x33')]('base64'));}function request(_0x46ca20){logger[_0xb0e4('0x34')](_0xb0e4('0x35'),JSON[_0xb0e4('0x36')](_0x46ca20));return rp(_['defaults'](_0x46ca20,{'method':'GET','headers':headers,'json':!![]}));}function getTags(_0x4af7f6,_0x4dffd8){var _0x16812e=[];if(_0x4af7f6&&_0x4af7f6['length']>0x0){_0x16812e=_[_0xb0e4('0x37')](_0x4af7f6,_0x4dffd8);}return _0x16812e;}function getCustomFields(_0x49b45f,_0x2415ce){var _0x540536=[];var _0x5d4af8={'custom_fields':[]};if(_0x49b45f[_0xb0e4('0x25')]>0x0){_[_0xb0e4('0x38')](_0x49b45f,function(_0x270b6e){if(_0x270b6e['type']===_0xb0e4('0x39')&&_0x270b6e[_0xb0e4('0x3a')]&&!_0x270b6e['customField']){_0x5d4af8[_0x270b6e[_0xb0e4('0x3a')]['toLowerCase']()]=_0x270b6e[_0xb0e4('0x3b')][_0xb0e4('0x33')]();}else if(_0x270b6e['type']===_0xb0e4('0x39')&&_0x270b6e['idField']&&_0x270b6e['customField']){_0x5d4af8['custom_fields'][_0xb0e4('0x3c')]({'id':_0x270b6e[_0xb0e4('0x3d')],'value':_0x270b6e['content'][_0xb0e4('0x33')]()});}else if(_0x270b6e['type']===_0xb0e4('0x3e')&&_0x270b6e[_0xb0e4('0x3f')]&&_0x270b6e[_0xb0e4('0x3d')]&&_0x270b6e[_0xb0e4('0x40')]){_0x2415ce[_0x270b6e['variableName']]&&_0x5d4af8[_0xb0e4('0x41')][_0xb0e4('0x3c')]({'id':_0x270b6e[_0xb0e4('0x3d')],'value':_0x2415ce[_0x270b6e[_0xb0e4('0x3f')]][_0xb0e4('0x33')]()});}else if(_0x270b6e[_0xb0e4('0x42')]===_0xb0e4('0x43')&&_0x270b6e[_0xb0e4('0x44')]&&_0x270b6e[_0xb0e4('0x44')][_0xb0e4('0x45')]&&_0x270b6e[_0xb0e4('0x3d')]&&_0x270b6e[_0xb0e4('0x40')]){_0x2415ce[_0x270b6e[_0xb0e4('0x44')][_0xb0e4('0x45')][_0xb0e4('0x46')]()]&&_0x5d4af8[_0xb0e4('0x41')]['push']({'id':_0x270b6e[_0xb0e4('0x3d')],'value':_0x2415ce[_0x270b6e[_0xb0e4('0x44')][_0xb0e4('0x45')][_0xb0e4('0x46')]()]['toString']()});}});}return _0x5d4af8;}exports[_0xb0e4('0x47')]=function(_0x2ff73c,_0x56ff92,_0x28a484,_0x2c1c5c,_0x47107e,_0x40a365){var _0x48ad47,_0x2c9a89;_0x40a365[_0xb0e4('0xd')]=intUtil[_0xb0e4('0x48')](_0x40a365[_0xb0e4('0xd')]);_0x40a365[_0xb0e4('0x49')]=intUtil[_0xb0e4('0x48')](_0x40a365[_0xb0e4('0x49')]);if(_0x47107e&&_0x47107e[_0xb0e4('0x4a')]){logger[_0xb0e4('0x9')](_0xb0e4('0x4b'),_0xb0e4('0x4c'));_0x56ff92['recordingURL']=util[_0xb0e4('0xb')](_0xb0e4('0x4d'),_0x40a365['serverUrl'],_0x56ff92['uniqueid'],md5(_0x56ff92['uniqueid']));}else{_0x56ff92[_0xb0e4('0x4e')]='';}headers[_0xb0e4('0x4f')]=getAuth(_0x40a365);return getUser(_0x40a365,_0x2c1c5c['email'])['then'](function(_0x5e8a9a){_0x48ad47=_0x5e8a9a;logger['info']('The\x20User\x20ID\x20is:',_0x48ad47['id']);return getEndUser(_0x40a365,_0x56ff92['calleridname'],_0x56ff92[_0xb0e4('0x50')]);})['then'](function(_0x17c18c){_0x2c9a89=_0x17c18c;logger[_0xb0e4('0x9')](_0xb0e4('0x51'),_0x2c9a89['id']);return getTicket(_0x40a365,_0x48ad47,_0x2c9a89,_0x28a484,_0x56ff92);})[_0xb0e4('0x15')](function(_0x502d5e){if(_0x502d5e){logger[_0xb0e4('0x9')](_0xb0e4('0x52'),_0x502d5e['id']);switch(_0x40a365['type']){case _0xb0e4('0x53'):logger['info'](_0xb0e4('0x4b'),_0xb0e4('0x54'));return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0x55'),_0x40a365['remoteUri'],_0x48ad47['id'],_0x502d5e['id']),'method':_0xb0e4('0xe')});case _0xb0e4('0x56'):logger[_0xb0e4('0x9')](_0xb0e4('0x4b'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xb0e4('0xb')](_0xb0e4('0x57'),_0x2c1c5c[_0xb0e4('0x45')]),'trigger:browser:url',{'uri':util['format']('%s/agent/tickets/%s',_0x40a365['remoteUri']['replace'](_0xb0e4('0x58'),''),_0x502d5e['id'])});break;default:logger['error'](_0xb0e4('0x4b'),_0xb0e4('0x59'));}}})[_0xb0e4('0x5a')](function(_0x10b23b){logger['error'](_0xb0e4('0x5b'),util[_0xb0e4('0x5c')](_0x10b23b,{'showHidden':!![],'depth':null}));});};exports['outbound']=function(_0x3f9bd4,_0x54e8f2,_0x2a2b9d,_0x581366,_0xe3250d,_0x5aec54,_0x3ad23a){var _0x363b2f,_0x5bf6e1;_0x5aec54[_0xb0e4('0xd')]=intUtil[_0xb0e4('0x48')](_0x5aec54['remoteUri']);_0x5aec54['serverUrl']=intUtil[_0xb0e4('0x48')](_0x5aec54[_0xb0e4('0x49')]);if(_0x3ad23a&&_0x3ad23a[_0xb0e4('0x5d')]&&_0x3ad23a['recordingFormat']!==_0xb0e4('0x5e')){logger[_0xb0e4('0x9')]('[OUTBOUND]',_0xb0e4('0x4c'));_0x54e8f2[_0xb0e4('0x4e')]=util['format'](_0xb0e4('0x4d'),_0x5aec54[_0xb0e4('0x49')],_0x54e8f2[_0xb0e4('0x5f')],md5(_0x54e8f2['uniqueid']));}headers[_0xb0e4('0x4f')]=getAuth(_0x5aec54);return getUser(_0x5aec54,_0x581366[_0xb0e4('0x60')])[_0xb0e4('0x15')](function(_0x40c288){_0x363b2f=_0x40c288;logger['info'](_0xb0e4('0x61'),_0x363b2f['id']);return getEndUser(_0x5aec54,_0x54e8f2[_0xb0e4('0x62')],_0x54e8f2[_0xb0e4('0x63')]);})[_0xb0e4('0x15')](function(_0x32c5c5){_0x5bf6e1=_0x32c5c5;logger[_0xb0e4('0x9')](_0xb0e4('0x51'),_0x5bf6e1['id']);return getTicket(_0x5aec54,_0x363b2f,_0x5bf6e1,_0x2a2b9d,_0x54e8f2);})['then'](function(_0x58cae0){if(_0x58cae0){logger[_0xb0e4('0x9')](_0xb0e4('0x52'),_0x58cae0['id']);switch(_0x5aec54[_0xb0e4('0x42')]){case _0xb0e4('0x53'):logger[_0xb0e4('0x9')](_0xb0e4('0x64'),_0xb0e4('0x54'));return request({'uri':util[_0xb0e4('0xb')](_0xb0e4('0x55'),_0x5aec54[_0xb0e4('0xd')],_0x363b2f['id'],_0x58cae0['id']),'method':_0xb0e4('0xe')});case _0xb0e4('0x56'):logger[_0xb0e4('0x9')](_0xb0e4('0x64'),_0xb0e4('0x65'));emit(util[_0xb0e4('0xb')]('user:%s',_0x581366['name']),_0xb0e4('0x66'),{'uri':util[_0xb0e4('0xb')](_0xb0e4('0x67'),_0x5aec54[_0xb0e4('0xd')][_0xb0e4('0x68')]('/api/v2',''),_0x58cae0['id'])});break;default:logger['error'](_0xb0e4('0x64'),_0xb0e4('0x59'));}}})[_0xb0e4('0x5a')](function(_0x54f614){logger[_0xb0e4('0x69')](_0xb0e4('0x6a'),util['inspect'](_0x54f614,{'showHidden':!![],'depth':null}));});};exports['unmanaged']=function(_0x2c46de,_0x553f4d,_0x2400e0,_0x3ae187,_0x138b22,_0x44eb57){var _0x1bd223,_0x27e561;_0x44eb57[_0xb0e4('0xd')]=intUtil[_0xb0e4('0x48')](_0x44eb57[_0xb0e4('0xd')]);_0x44eb57[_0xb0e4('0x49')]=intUtil[_0xb0e4('0x48')](_0x44eb57['serverUrl']);if(_0x138b22&&_0x138b22[_0xb0e4('0x4a')]){logger[_0xb0e4('0x9')]('['+_0x553f4d[_0xb0e4('0x6b')][_0xb0e4('0x6c')]()+']',_0xb0e4('0x4c'));_0x553f4d[_0xb0e4('0x4e')]=util[_0xb0e4('0xb')](_0xb0e4('0x4d'),_0x44eb57['serverUrl'],_0x553f4d[_0xb0e4('0x5f')],md5(_0x553f4d[_0xb0e4('0x5f')]));}else{_0x553f4d[_0xb0e4('0x4e')]='';}headers[_0xb0e4('0x4f')]=getAuth(_0x44eb57);return getUser(_0x44eb57)[_0xb0e4('0x15')](function(_0x1172e3){_0x1bd223=_0x1172e3;logger[_0xb0e4('0x9')](_0xb0e4('0x61'),_0x1bd223['id']);return getEndUser(_0x44eb57,_0x553f4d[_0xb0e4('0x6d')],_0x553f4d['calleridnum']);})[_0xb0e4('0x15')](function(_0x5ad916){_0x27e561=_0x5ad916;logger[_0xb0e4('0x9')]('The\x20Enduser\x20ID\x20is:',_0x27e561['id']);return getTicket(_0x44eb57,_0x1bd223,_0x27e561,_0x2400e0,_0x553f4d);})['then'](function(_0x4d658b){if(_0x4d658b){logger[_0xb0e4('0x9')](_0xb0e4('0x52'),_0x4d658b['id']);}})[_0xb0e4('0x5a')](function(_0x282398){logger[_0xb0e4('0x69')]('['+_0x553f4d[_0xb0e4('0x6b')][_0xb0e4('0x6c')]()+']'+'\x20Error\x20running\x20Zendesk\x20integration',util[_0xb0e4('0x5c')](_0x282398,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x6462=['Ticket\x20created!','validateEmail','%s/search.json','type:user\x20role:agent\x20email:%s','count','find','Admin\x20account\x20selected.','user','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','Searching\x20enduser\x20with\x20phone','length','results','first','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','POST','Caller\x20-\x20%s','authType','%s:%s','username','password','token','Basic\x20%s','base64','debug','[HTTP]','GET','map','forEach','string','picklist','type','nameField','toLowerCase','content','toString','idField','custom_fields','push','variableName','customVariable','Variable','customField','stripTrailingSlash','serverUrl','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','%s/agent/tickets/%s','replace','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','recordingFormat','none','[OUTBOUND]','Authorization','email','destcalleridname','destcalleridnum','%s/channels/voice/agents/%d/tickets/%d/display.json','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','monitor_format','lastevent','toUpperCase','The\x20User\x20ID\x20is:','lodash','request-promise','md5','util','ioredis','../../../../config/environment','../../../../config/logger','redis','defaults','socket.io-emitter','emit','application/json','info','Creating\x20new\x20ticket...','format','%s/tickets.json','remoteUri','merge','Tags','name','getString','Subjects','Descriptions','Fields','then'];(function(_0xdea41a,_0x552987){var _0x15d0d8=function(_0x1e0d0b){while(--_0x1e0d0b){_0xdea41a['push'](_0xdea41a['shift']());}};_0x15d0d8(++_0x552987);}(_0x6462,0x187));var _0x2646=function(_0x44b517,_0x5d0ed5){_0x44b517=_0x44b517-0x0;var _0x82d9b5=_0x6462[_0x44b517];return _0x82d9b5;};'use strict';var _=require(_0x2646('0x0'));var rp=require(_0x2646('0x1'));var md5=require(_0x2646('0x2'));var util=require(_0x2646('0x3'));var Redis=require(_0x2646('0x4'));var intUtil=require('./util');var config=require(_0x2646('0x5'));var logger=require(_0x2646('0x6'))('zendesk');config[_0x2646('0x7')]=_[_0x2646('0x8')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x2646('0x9'))(new Redis(config[_0x2646('0x7')]));function emit(_0x4daf5f,_0x2b1d6a,_0x2ba22e){io['to'](_0x4daf5f)[_0x2646('0xa')](_0x2b1d6a,_0x2ba22e);}var headers={'Content-Type':_0x2646('0xb'),'Accept':_0x2646('0xb')};function getTicket(_0x194bdb,_0x225349,_0x1bd371,_0x17ad4c,_0x3a5daa){logger[_0x2646('0xc')](_0x2646('0xd'));return request({'uri':util[_0x2646('0xe')](_0x2646('0xf'),_0x194bdb[_0x2646('0x10')]),'method':'POST','body':{'ticket':_[_0x2646('0x11')]({'requester_id':_0x1bd371['id'],'submitter_id':_0x225349?_0x225349['id']:undefined,'assignee_id':_0x225349?_0x225349['id']:undefined,'tags':getTags(_0x17ad4c[_0x2646('0x12')],_0x2646('0x13')),'subject':intUtil[_0x2646('0x14')](_0x17ad4c[_0x2646('0x15')],_0x3a5daa,'\x20'),'description':intUtil[_0x2646('0x14')](_0x17ad4c['Descriptions'],_0x3a5daa,'\x0a'),'comment':{'public':![],'body':intUtil[_0x2646('0x14')](_0x17ad4c[_0x2646('0x16')],_0x3a5daa,'\x0a')}},getCustomFields(_0x17ad4c[_0x2646('0x17')],_0x3a5daa))}})[_0x2646('0x18')](function(_0x1a4cc9){logger[_0x2646('0xc')](_0x2646('0x19'));return _0x1a4cc9['ticket'];});}function getUser(_0x1b156e,_0x46ed17){if(intUtil[_0x2646('0x1a')](_0x46ed17)){logger[_0x2646('0xc')]('Getting\x20agent\x20with\x20email',_0x46ed17);return request({'uri':util['format'](_0x2646('0x1b'),_0x1b156e['remoteUri']),'qs':{'query':util[_0x2646('0xe')](_0x2646('0x1c'),_0x46ed17)}})[_0x2646('0x18')](function(_0x2f3240){if(_0x2f3240[_0x2646('0x1d')]){logger[_0x2646('0xc')]('Agent\x20found!');return _[_0x2646('0x1e')](_0x2f3240['results'],{'email':_0x46ed17,'role':'agent'});}else{logger[_0x2646('0xc')]('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0x2646('0xe')]('%s/users/me.json',_0x1b156e[_0x2646('0x10')])})[_0x2646('0x18')](function(_0x10ade2){logger[_0x2646('0xc')](_0x2646('0x1f'));return _0x10ade2[_0x2646('0x20')];});}});}else{logger['info'](_0x2646('0x21'));return request({'uri':util[_0x2646('0xe')](_0x2646('0x22'),_0x1b156e[_0x2646('0x10')])})[_0x2646('0x18')](function(_0x5533e3){logger['info'](_0x2646('0x1f'));return _0x5533e3['user'];});}}function getEndUser(_0x11609b,_0x268d0e,_0x3f384f){logger['info'](_0x2646('0x23'),_0x3f384f);return request({'uri':util[_0x2646('0xe')](_0x2646('0x1b'),_0x11609b[_0x2646('0x10')]),'qs':{'query':util[_0x2646('0xe')]('type:user\x20role:end-user\x20phone:%s',_0x3f384f)}})[_0x2646('0x18')](function(_0x2f2fb9){var _0x25b55a;if(_0x2f2fb9['results'][_0x2646('0x24')]){_0x2f2fb9[_0x2646('0x25')]=_['filter'](_0x2f2fb9[_0x2646('0x25')],{'suspended':![],'role':'end-user'});if(_0x2f2fb9['results']['length']){_0x25b55a=_[_0x2646('0x26')](_0x2f2fb9[_0x2646('0x25')]);}}if(_0x25b55a){logger['info'](_0x2646('0x27'));return _0x25b55a;}else{logger[_0x2646('0xc')](_0x2646('0x28'));return request({'uri':util[_0x2646('0xe')](_0x2646('0x29'),_0x11609b[_0x2646('0x10')]),'method':_0x2646('0x2a'),'body':{'user':{'role':'end-user','name':util[_0x2646('0xe')](_0x2646('0x2b'),_0x268d0e||_0x3f384f),'phone':_0x3f384f}}})[_0x2646('0x18')](function(_0x24c241){logger['info']('Enduser\x20created.');return _0x24c241[_0x2646('0x20')];});}});}function getAuth(_0x4aa577){var _0x4fc4fb;if(_0x4aa577[_0x2646('0x2c')]==='password'){_0x4fc4fb=util['format'](_0x2646('0x2d'),_0x4aa577[_0x2646('0x2e')],_0x4aa577[_0x2646('0x2f')]);}else if(_0x4aa577[_0x2646('0x2c')]===_0x2646('0x30')){_0x4fc4fb=util[_0x2646('0xe')]('%s/token:%s',_0x4aa577['username'],_0x4aa577[_0x2646('0x30')]);}return util[_0x2646('0xe')](_0x2646('0x31'),new Buffer(_0x4fc4fb)['toString'](_0x2646('0x32')));}function request(_0x482254){logger[_0x2646('0x33')](_0x2646('0x34'),JSON['stringify'](_0x482254));return rp(_[_0x2646('0x8')](_0x482254,{'method':_0x2646('0x35'),'headers':headers,'json':!![]}));}function getTags(_0x3cd45e,_0x4f5393){var _0x5a1625=[];if(_0x3cd45e&&_0x3cd45e[_0x2646('0x24')]>0x0){_0x5a1625=_[_0x2646('0x36')](_0x3cd45e,_0x4f5393);}return _0x5a1625;}function getCustomFields(_0xdf8d51,_0x4f633d){var _0x4877cc=[];var _0x196fa1={'custom_fields':[]};if(_0xdf8d51[_0x2646('0x24')]>0x0){_[_0x2646('0x37')](_0xdf8d51,function(_0x27aaf5){if(_['includes']([_0x2646('0x38'),_0x2646('0x39')],_0x27aaf5[_0x2646('0x3a')])&&_0x27aaf5['nameField']&&!_0x27aaf5['customField']){_0x196fa1[_0x27aaf5[_0x2646('0x3b')][_0x2646('0x3c')]()]=_0x27aaf5[_0x2646('0x3d')][_0x2646('0x3e')]();}else if(_['includes']([_0x2646('0x38'),_0x2646('0x39')],_0x27aaf5[_0x2646('0x3a')])&&_0x27aaf5[_0x2646('0x3f')]&&_0x27aaf5['customField']){_0x196fa1[_0x2646('0x40')][_0x2646('0x41')]({'id':_0x27aaf5[_0x2646('0x3f')],'value':_0x27aaf5['content']['toString']()});}else if(_0x27aaf5[_0x2646('0x3a')]==='variable'&&_0x27aaf5[_0x2646('0x42')]&&_0x27aaf5[_0x2646('0x3f')]&&_0x27aaf5['customField']){_0x4f633d[_0x27aaf5[_0x2646('0x42')]]&&_0x196fa1[_0x2646('0x40')]['push']({'id':_0x27aaf5[_0x2646('0x3f')],'value':_0x4f633d[_0x27aaf5[_0x2646('0x42')]]['toString']()});}else if(_0x27aaf5[_0x2646('0x3a')]===_0x2646('0x43')&&_0x27aaf5[_0x2646('0x44')]&&_0x27aaf5[_0x2646('0x44')]['name']&&_0x27aaf5['idField']&&_0x27aaf5[_0x2646('0x45')]){_0x4f633d[_0x27aaf5[_0x2646('0x44')][_0x2646('0x13')][_0x2646('0x3c')]()]&&_0x196fa1['custom_fields'][_0x2646('0x41')]({'id':_0x27aaf5[_0x2646('0x3f')],'value':_0x4f633d[_0x27aaf5[_0x2646('0x44')][_0x2646('0x13')]['toLowerCase']()][_0x2646('0x3e')]()});}});}return _0x196fa1;}exports['queue']=function(_0x3e3277,_0x19ecaf,_0x2a858e,_0xc61973,_0xfde522,_0x23d01d){var _0xee95ba,_0xb0e603;_0x23d01d['remoteUri']=intUtil[_0x2646('0x46')](_0x23d01d[_0x2646('0x10')]);_0x23d01d[_0x2646('0x47')]=intUtil[_0x2646('0x46')](_0x23d01d[_0x2646('0x47')]);if(_0xfde522&&_0xfde522['monitor_format']){logger[_0x2646('0xc')](_0x2646('0x48'),_0x2646('0x49'));_0x19ecaf[_0x2646('0x4a')]=util['format'](_0x2646('0x4b'),_0x23d01d[_0x2646('0x47')],_0x19ecaf[_0x2646('0x4c')],md5(_0x19ecaf['uniqueid']));}else{_0x19ecaf[_0x2646('0x4a')]='';}headers['Authorization']=getAuth(_0x23d01d);return getUser(_0x23d01d,_0xc61973['email'])[_0x2646('0x18')](function(_0x26a26a){_0xee95ba=_0x26a26a;logger['info']('The\x20User\x20ID\x20is:',_0xee95ba['id']);return getEndUser(_0x23d01d,_0x19ecaf['calleridname'],_0x19ecaf[_0x2646('0x4d')]);})['then'](function(_0x3719e9){_0xb0e603=_0x3719e9;logger[_0x2646('0xc')](_0x2646('0x4e'),_0xb0e603['id']);return getTicket(_0x23d01d,_0xee95ba,_0xb0e603,_0x2a858e,_0x19ecaf);})['then'](function(_0x4a8a8d){if(_0x4a8a8d){logger['info'](_0x2646('0x4f'),_0x4a8a8d['id']);switch(_0x23d01d[_0x2646('0x3a')]){case _0x2646('0x50'):logger[_0x2646('0xc')](_0x2646('0x48'),_0x2646('0x51'));return request({'uri':util[_0x2646('0xe')]('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x23d01d[_0x2646('0x10')],_0xee95ba['id'],_0x4a8a8d['id']),'method':_0x2646('0x2a')});case _0x2646('0x52'):logger[_0x2646('0xc')](_0x2646('0x48'),_0x2646('0x53'));emit(util['format'](_0x2646('0x54'),_0xc61973[_0x2646('0x13')]),'trigger:browser:url',{'uri':util[_0x2646('0xe')](_0x2646('0x55'),_0x23d01d[_0x2646('0x10')][_0x2646('0x56')]('/api/v2',''),_0x4a8a8d['id'])});break;default:logger[_0x2646('0x57')](_0x2646('0x48'),_0x2646('0x58'));}}})[_0x2646('0x59')](function(_0x55db8d){logger[_0x2646('0x57')](_0x2646('0x5a'),util['inspect'](_0x55db8d,{'showHidden':!![],'depth':null}));});};exports['outbound']=function(_0x132ecc,_0x11dd31,_0x5148fe,_0x5d4fa3,_0x207ffc,_0x44c053,_0x2e8ac9){var _0x5b26c6,_0x37e1b5;_0x44c053[_0x2646('0x10')]=intUtil[_0x2646('0x46')](_0x44c053[_0x2646('0x10')]);_0x44c053[_0x2646('0x47')]=intUtil['stripTrailingSlash'](_0x44c053['serverUrl']);if(_0x2e8ac9&&_0x2e8ac9[_0x2646('0x5b')]&&_0x2e8ac9[_0x2646('0x5b')]!==_0x2646('0x5c')){logger[_0x2646('0xc')](_0x2646('0x5d'),_0x2646('0x49'));_0x11dd31[_0x2646('0x4a')]=util[_0x2646('0xe')](_0x2646('0x4b'),_0x44c053[_0x2646('0x47')],_0x11dd31[_0x2646('0x4c')],md5(_0x11dd31[_0x2646('0x4c')]));}headers[_0x2646('0x5e')]=getAuth(_0x44c053);return getUser(_0x44c053,_0x5d4fa3[_0x2646('0x5f')])[_0x2646('0x18')](function(_0x4bf2a1){_0x5b26c6=_0x4bf2a1;logger[_0x2646('0xc')]('The\x20User\x20ID\x20is:',_0x5b26c6['id']);return getEndUser(_0x44c053,_0x11dd31[_0x2646('0x60')],_0x11dd31[_0x2646('0x61')]);})[_0x2646('0x18')](function(_0x43e31a){_0x37e1b5=_0x43e31a;logger[_0x2646('0xc')](_0x2646('0x4e'),_0x37e1b5['id']);return getTicket(_0x44c053,_0x5b26c6,_0x37e1b5,_0x5148fe,_0x11dd31);})['then'](function(_0x4b8cb9){if(_0x4b8cb9){logger['info'](_0x2646('0x4f'),_0x4b8cb9['id']);switch(_0x44c053['type']){case _0x2646('0x50'):logger[_0x2646('0xc')](_0x2646('0x5d'),_0x2646('0x51'));return request({'uri':util[_0x2646('0xe')](_0x2646('0x62'),_0x44c053['remoteUri'],_0x5b26c6['id'],_0x4b8cb9['id']),'method':_0x2646('0x2a')});case'newTab':logger['info']('[OUTBOUND]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x2646('0xe')](_0x2646('0x54'),_0x5d4fa3[_0x2646('0x13')]),'trigger:browser:url',{'uri':util['format'](_0x2646('0x55'),_0x44c053[_0x2646('0x10')][_0x2646('0x56')]('/api/v2',''),_0x4b8cb9['id'])});break;default:logger[_0x2646('0x57')](_0x2646('0x5d'),_0x2646('0x58'));}}})[_0x2646('0x59')](function(_0xfb0280){logger[_0x2646('0x57')](_0x2646('0x63'),util['inspect'](_0xfb0280,{'showHidden':!![],'depth':null}));});};exports['unmanaged']=function(_0x1bc147,_0x3aebdf,_0x58169b,_0x339957,_0x282edd,_0x2486fc){var _0x2a124e,_0x465674;_0x2486fc[_0x2646('0x10')]=intUtil[_0x2646('0x46')](_0x2486fc[_0x2646('0x10')]);_0x2486fc[_0x2646('0x47')]=intUtil[_0x2646('0x46')](_0x2486fc[_0x2646('0x47')]);if(_0x282edd&&_0x282edd[_0x2646('0x64')]){logger[_0x2646('0xc')]('['+_0x3aebdf[_0x2646('0x65')][_0x2646('0x66')]()+']',_0x2646('0x49'));_0x3aebdf['recordingURL']=util[_0x2646('0xe')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x2486fc[_0x2646('0x47')],_0x3aebdf[_0x2646('0x4c')],md5(_0x3aebdf[_0x2646('0x4c')]));}else{_0x3aebdf[_0x2646('0x4a')]='';}headers[_0x2646('0x5e')]=getAuth(_0x2486fc);return getUser(_0x2486fc)[_0x2646('0x18')](function(_0x27682d){_0x2a124e=_0x27682d;logger[_0x2646('0xc')](_0x2646('0x67'),_0x2a124e['id']);return getEndUser(_0x2486fc,_0x3aebdf['calleridname'],_0x3aebdf[_0x2646('0x4d')]);})[_0x2646('0x18')](function(_0x45bc4b){_0x465674=_0x45bc4b;logger['info']('The\x20Enduser\x20ID\x20is:',_0x465674['id']);return getTicket(_0x2486fc,_0x2a124e,_0x465674,_0x58169b,_0x3aebdf);})[_0x2646('0x18')](function(_0x305f90){if(_0x305f90){logger[_0x2646('0xc')](_0x2646('0x4f'),_0x305f90['id']);}})[_0x2646('0x59')](function(_0x1c27fb){logger[_0x2646('0x57')]('['+_0x3aebdf['lastevent'][_0x2646('0x66')]()+']'+'\x20Error\x20running\x20Zendesk\x20integration',util['inspect'](_0x1c27fb,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file