Built motion from commit b58257bb.|2.5.37
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index 700aa51..f8f59f6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8b1f=['/api/v2','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','unmanaged','lastevent','Authorization','calleridname','toUpperCase','\x20Error\x20running\x20Zendesk\x20integration','lodash','md5','util','ioredis','../../../../config/logger','zendesk','defaults','redis','localhost','emit','application/json','info','Creating\x20new\x20ticket...','format','remoteUri','POST','merge','Tags','name','getString','Subjects','Descriptions','Fields','then','Ticket\x20created!','ticket','Getting\x20agent\x20with\x20email','%s/search.json','type:user\x20role:agent\x20email:%s','count','Agent\x20found!','agent','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','results','length','filter','first','Enduser\x20found!','end-user','Caller\x20-\x20%s','authType','password','%s:%s','username','%s/token:%s','token','Basic\x20%s','debug','GET','map','forEach','includes','string','picklist','type','nameField','customField','toLowerCase','content','toString','idField','push','variable','variableName','custom_fields','Variable','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','The\x20User\x20ID\x20is:','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','[QUEUE]','Displaying\x20ticket\x20to\x20agent...','%s/channels/voice/agents/%d/tickets/%d/display.json','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/agent/tickets/%s','replace','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','inspect','outbound','recordingFormat','[OUTBOUND]','uniqueid','email','destcalleridname','newTab'];(function(_0x33dae5,_0x3bdb4e){var _0x3a4873=function(_0x524d78){while(--_0x524d78){_0x33dae5['push'](_0x33dae5['shift']());}};_0x3a4873(++_0x3bdb4e);}(_0x8b1f,0xe2));var _0xf8b1=function(_0x404f0e,_0x2c62a7){_0x404f0e=_0x404f0e-0x0;var _0x4709d8=_0x8b1f[_0x404f0e];return _0x4709d8;};'use strict';var _=require(_0xf8b1('0x0'));var rp=require('request-promise');var md5=require(_0xf8b1('0x1'));var util=require(_0xf8b1('0x2'));var Redis=require(_0xf8b1('0x3'));var intUtil=require('./util');var config=require('../../../../config/environment');var logger=require(_0xf8b1('0x4'))(_0xf8b1('0x5'));config['redis']=_[_0xf8b1('0x6')](config[_0xf8b1('0x7')],{'host':_0xf8b1('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xf8b1('0x7')]));function emit(_0x7d6ae6,_0x57ba9e,_0x36e011){io['to'](_0x7d6ae6)[_0xf8b1('0x9')](_0x57ba9e,_0x36e011);}var headers={'Content-Type':_0xf8b1('0xa'),'Accept':_0xf8b1('0xa')};function getTicket(_0x3e27ca,_0x3e8d49,_0x29a58a,_0x438b5a,_0x5970ad){logger[_0xf8b1('0xb')](_0xf8b1('0xc'));return request({'uri':util[_0xf8b1('0xd')]('%s/tickets.json',_0x3e27ca[_0xf8b1('0xe')]),'method':_0xf8b1('0xf'),'body':{'ticket':_[_0xf8b1('0x10')]({'requester_id':_0x29a58a['id'],'submitter_id':_0x3e8d49?_0x3e8d49['id']:undefined,'assignee_id':_0x3e8d49?_0x3e8d49['id']:undefined,'tags':getTags(_0x438b5a[_0xf8b1('0x11')],_0xf8b1('0x12')),'subject':intUtil[_0xf8b1('0x13')](_0x438b5a[_0xf8b1('0x14')],_0x5970ad,'\x20'),'description':intUtil[_0xf8b1('0x13')](_0x438b5a[_0xf8b1('0x15')],_0x5970ad,'\x0a'),'comment':{'public':![],'body':intUtil[_0xf8b1('0x13')](_0x438b5a['Descriptions'],_0x5970ad,'\x0a')}},getCustomFields(_0x438b5a[_0xf8b1('0x16')],_0x5970ad))}})[_0xf8b1('0x17')](function(_0x2c6416){logger[_0xf8b1('0xb')](_0xf8b1('0x18'));return _0x2c6416[_0xf8b1('0x19')];});}function getUser(_0x4716db,_0x49a38a){if(intUtil['validateEmail'](_0x49a38a)){logger[_0xf8b1('0xb')](_0xf8b1('0x1a'),_0x49a38a);return request({'uri':util[_0xf8b1('0xd')](_0xf8b1('0x1b'),_0x4716db[_0xf8b1('0xe')]),'qs':{'query':util[_0xf8b1('0xd')](_0xf8b1('0x1c'),_0x49a38a)}})[_0xf8b1('0x17')](function(_0x37249e){if(_0x37249e[_0xf8b1('0x1d')]){logger[_0xf8b1('0xb')](_0xf8b1('0x1e'));return _['find'](_0x37249e['results'],{'email':_0x49a38a,'role':_0xf8b1('0x1f')});}else{logger[_0xf8b1('0xb')](_0xf8b1('0x20'));return request({'uri':util['format'](_0xf8b1('0x21'),_0x4716db[_0xf8b1('0xe')])})[_0xf8b1('0x17')](function(_0x3a3269){logger['info'](_0xf8b1('0x22'));return _0x3a3269[_0xf8b1('0x23')];});}});}else{logger[_0xf8b1('0xb')](_0xf8b1('0x20'));return request({'uri':util[_0xf8b1('0xd')](_0xf8b1('0x21'),_0x4716db[_0xf8b1('0xe')])})[_0xf8b1('0x17')](function(_0x4be414){logger[_0xf8b1('0xb')](_0xf8b1('0x22'));return _0x4be414['user'];});}}function getEndUser(_0x268b98,_0x493b3c,_0x1cc057){logger[_0xf8b1('0xb')](_0xf8b1('0x24'),_0x1cc057);return request({'uri':util[_0xf8b1('0xd')](_0xf8b1('0x1b'),_0x268b98[_0xf8b1('0xe')]),'qs':{'query':util[_0xf8b1('0xd')]('type:user\x20role:end-user\x20phone:%s',_0x1cc057)}})[_0xf8b1('0x17')](function(_0x5e8098){var _0x5472e7;if(_0x5e8098[_0xf8b1('0x25')][_0xf8b1('0x26')]){_0x5e8098[_0xf8b1('0x25')]=_[_0xf8b1('0x27')](_0x5e8098['results'],{'suspended':![],'role':'end-user'});if(_0x5e8098[_0xf8b1('0x25')][_0xf8b1('0x26')]){_0x5472e7=_[_0xf8b1('0x28')](_0x5e8098[_0xf8b1('0x25')]);}}if(_0x5472e7){logger[_0xf8b1('0xb')](_0xf8b1('0x29'));return _0x5472e7;}else{logger[_0xf8b1('0xb')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util[_0xf8b1('0xd')]('%s/users.json',_0x268b98[_0xf8b1('0xe')]),'method':_0xf8b1('0xf'),'body':{'user':{'role':_0xf8b1('0x2a'),'name':util[_0xf8b1('0xd')](_0xf8b1('0x2b'),_0x493b3c||_0x1cc057),'phone':_0x1cc057}}})[_0xf8b1('0x17')](function(_0x54dd47){logger[_0xf8b1('0xb')]('Enduser\x20created.');return _0x54dd47['user'];});}});}function getAuth(_0x2d1a53){var _0x2babf1;if(_0x2d1a53[_0xf8b1('0x2c')]===_0xf8b1('0x2d')){_0x2babf1=util[_0xf8b1('0xd')](_0xf8b1('0x2e'),_0x2d1a53[_0xf8b1('0x2f')],_0x2d1a53['password']);}else if(_0x2d1a53[_0xf8b1('0x2c')]==='token'){_0x2babf1=util[_0xf8b1('0xd')](_0xf8b1('0x30'),_0x2d1a53[_0xf8b1('0x2f')],_0x2d1a53[_0xf8b1('0x31')]);}return util[_0xf8b1('0xd')](_0xf8b1('0x32'),new Buffer(_0x2babf1)['toString']('base64'));}function request(_0x31d9fc){logger[_0xf8b1('0x33')]('[HTTP]',JSON['stringify'](_0x31d9fc));return rp(_[_0xf8b1('0x6')](_0x31d9fc,{'method':_0xf8b1('0x34'),'headers':headers,'json':!![]}));}function getTags(_0x488017,_0x19d7ef){var _0x3f586b=[];if(_0x488017&&_0x488017[_0xf8b1('0x26')]>0x0){_0x3f586b=_[_0xf8b1('0x35')](_0x488017,_0x19d7ef);}return _0x3f586b;}function getCustomFields(_0x3e41e4,_0xeb2a0e){var _0x7c2772=[];var _0x45ff95={'custom_fields':[]};if(_0x3e41e4[_0xf8b1('0x26')]>0x0){_[_0xf8b1('0x36')](_0x3e41e4,function(_0x4bb12b){if(_[_0xf8b1('0x37')]([_0xf8b1('0x38'),_0xf8b1('0x39')],_0x4bb12b[_0xf8b1('0x3a')])&&_0x4bb12b[_0xf8b1('0x3b')]&&!_0x4bb12b[_0xf8b1('0x3c')]){_0x45ff95[_0x4bb12b['nameField'][_0xf8b1('0x3d')]()]=_0x4bb12b[_0xf8b1('0x3e')][_0xf8b1('0x3f')]();}else if(_['includes']([_0xf8b1('0x38'),'picklist'],_0x4bb12b['type'])&&_0x4bb12b[_0xf8b1('0x40')]&&_0x4bb12b[_0xf8b1('0x3c')]){_0x45ff95['custom_fields'][_0xf8b1('0x41')]({'id':_0x4bb12b['idField'],'value':_0x4bb12b['content'][_0xf8b1('0x3f')]()});}else if(_0x4bb12b[_0xf8b1('0x3a')]===_0xf8b1('0x42')&&_0x4bb12b['variableName']&&_0x4bb12b[_0xf8b1('0x40')]&&_0x4bb12b[_0xf8b1('0x3c')]){_0xeb2a0e[_0x4bb12b[_0xf8b1('0x43')]]&&_0x45ff95[_0xf8b1('0x44')][_0xf8b1('0x41')]({'id':_0x4bb12b[_0xf8b1('0x40')],'value':_0xeb2a0e[_0x4bb12b[_0xf8b1('0x43')]][_0xf8b1('0x3f')]()});}else if(_0x4bb12b['type']==='customVariable'&&_0x4bb12b[_0xf8b1('0x45')]&&_0x4bb12b[_0xf8b1('0x45')]['name']&&_0x4bb12b[_0xf8b1('0x40')]&&_0x4bb12b['customField']){_0xeb2a0e[_0x4bb12b[_0xf8b1('0x45')]['name'][_0xf8b1('0x3d')]()]&&_0x45ff95['custom_fields'][_0xf8b1('0x41')]({'id':_0x4bb12b[_0xf8b1('0x40')],'value':_0xeb2a0e[_0x4bb12b[_0xf8b1('0x45')][_0xf8b1('0x12')][_0xf8b1('0x3d')]()][_0xf8b1('0x3f')]()});}});}return _0x45ff95;}exports['queue']=function(_0x3b611e,_0x1be402,_0xfdd8e9,_0x594720,_0x5f14ab,_0x27bc0c){var _0x2d86e2,_0x5e4b40;_0x27bc0c[_0xf8b1('0xe')]=intUtil[_0xf8b1('0x46')](_0x27bc0c[_0xf8b1('0xe')]);_0x27bc0c[_0xf8b1('0x47')]=intUtil[_0xf8b1('0x46')](_0x27bc0c[_0xf8b1('0x47')]);if(_0x5f14ab&&_0x5f14ab[_0xf8b1('0x48')]){logger[_0xf8b1('0xb')]('[QUEUE]',_0xf8b1('0x49'));_0x1be402[_0xf8b1('0x4a')]=util[_0xf8b1('0xd')](_0xf8b1('0x4b'),_0x27bc0c[_0xf8b1('0x47')],_0x1be402['uniqueid'],md5(_0x1be402['uniqueid']));}else{_0x1be402[_0xf8b1('0x4a')]='';}headers['Authorization']=getAuth(_0x27bc0c);return getUser(_0x27bc0c,_0x594720['email'])[_0xf8b1('0x17')](function(_0x21050a){_0x2d86e2=_0x21050a;logger['info'](_0xf8b1('0x4c'),_0x2d86e2['id']);return getEndUser(_0x27bc0c,_0x1be402['calleridname'],_0x1be402[_0xf8b1('0x4d')]);})['then'](function(_0x366c3f){_0x5e4b40=_0x366c3f;logger[_0xf8b1('0xb')](_0xf8b1('0x4e'),_0x5e4b40['id']);return getTicket(_0x27bc0c,_0x2d86e2,_0x5e4b40,_0xfdd8e9,_0x1be402);})[_0xf8b1('0x17')](function(_0x229e1d){if(_0x229e1d){logger[_0xf8b1('0xb')](_0xf8b1('0x4f'),_0x229e1d['id']);switch(_0x27bc0c['type']){case _0xf8b1('0x50'):logger[_0xf8b1('0xb')](_0xf8b1('0x51'),_0xf8b1('0x52'));return request({'uri':util['format'](_0xf8b1('0x53'),_0x27bc0c[_0xf8b1('0xe')],_0x2d86e2['id'],_0x229e1d['id']),'method':'POST'});case'newTab':logger[_0xf8b1('0xb')]('[QUEUE]',_0xf8b1('0x54'));emit(util['format'](_0xf8b1('0x55'),_0x594720[_0xf8b1('0x12')]),_0xf8b1('0x56'),{'uri':util[_0xf8b1('0xd')](_0xf8b1('0x57'),_0x27bc0c['remoteUri'][_0xf8b1('0x58')]('/api/v2',''),_0x229e1d['id'])});break;default:logger[_0xf8b1('0x59')](_0xf8b1('0x51'),_0xf8b1('0x5a'));}}})[_0xf8b1('0x5b')](function(_0x13b159){logger[_0xf8b1('0x59')](_0xf8b1('0x5c'),util[_0xf8b1('0x5d')](_0x13b159,{'showHidden':!![],'depth':null}));});};exports[_0xf8b1('0x5e')]=function(_0x1a81c7,_0x3ececc,_0x52ae6f,_0x4a8057,_0x4f6f50,_0x1d0be9,_0x4af155){var _0x2b9c92,_0x20440c;_0x1d0be9[_0xf8b1('0xe')]=intUtil['stripTrailingSlash'](_0x1d0be9[_0xf8b1('0xe')]);_0x1d0be9[_0xf8b1('0x47')]=intUtil[_0xf8b1('0x46')](_0x1d0be9[_0xf8b1('0x47')]);if(_0x4af155&&_0x4af155[_0xf8b1('0x5f')]&&_0x4af155[_0xf8b1('0x5f')]!=='none'){logger[_0xf8b1('0xb')](_0xf8b1('0x60'),_0xf8b1('0x49'));_0x3ececc[_0xf8b1('0x4a')]=util[_0xf8b1('0xd')](_0xf8b1('0x4b'),_0x1d0be9['serverUrl'],_0x3ececc[_0xf8b1('0x61')],md5(_0x3ececc['uniqueid']));}headers['Authorization']=getAuth(_0x1d0be9);return getUser(_0x1d0be9,_0x4a8057[_0xf8b1('0x62')])[_0xf8b1('0x17')](function(_0x46eb06){_0x2b9c92=_0x46eb06;logger['info'](_0xf8b1('0x4c'),_0x2b9c92['id']);return getEndUser(_0x1d0be9,_0x3ececc[_0xf8b1('0x63')],_0x3ececc['destcalleridnum']);})[_0xf8b1('0x17')](function(_0x47cfad){_0x20440c=_0x47cfad;logger[_0xf8b1('0xb')](_0xf8b1('0x4e'),_0x20440c['id']);return getTicket(_0x1d0be9,_0x2b9c92,_0x20440c,_0x52ae6f,_0x3ececc);})['then'](function(_0x4d79fa){if(_0x4d79fa){logger[_0xf8b1('0xb')](_0xf8b1('0x4f'),_0x4d79fa['id']);switch(_0x1d0be9[_0xf8b1('0x3a')]){case _0xf8b1('0x50'):logger['info'](_0xf8b1('0x60'),_0xf8b1('0x52'));return request({'uri':util[_0xf8b1('0xd')](_0xf8b1('0x53'),_0x1d0be9[_0xf8b1('0xe')],_0x2b9c92['id'],_0x4d79fa['id']),'method':_0xf8b1('0xf')});case _0xf8b1('0x64'):logger[_0xf8b1('0xb')](_0xf8b1('0x60'),_0xf8b1('0x54'));emit(util[_0xf8b1('0xd')]('user:%s',_0x4a8057['name']),_0xf8b1('0x56'),{'uri':util['format'](_0xf8b1('0x57'),_0x1d0be9[_0xf8b1('0xe')][_0xf8b1('0x58')](_0xf8b1('0x65'),''),_0x4d79fa['id'])});break;default:logger[_0xf8b1('0x59')]('[OUTBOUND]',_0xf8b1('0x5a'));}}})[_0xf8b1('0x5b')](function(_0x1b93aa){logger[_0xf8b1('0x59')](_0xf8b1('0x66'),util['inspect'](_0x1b93aa,{'showHidden':!![],'depth':null}));});};exports[_0xf8b1('0x67')]=function(_0x124130,_0x1a2b78,_0x5a41c9,_0x3f0a87,_0x245e24,_0x488d1f){var _0x31735f,_0x157059;_0x488d1f[_0xf8b1('0xe')]=intUtil['stripTrailingSlash'](_0x488d1f['remoteUri']);_0x488d1f[_0xf8b1('0x47')]=intUtil['stripTrailingSlash'](_0x488d1f[_0xf8b1('0x47')]);if(_0x245e24&&_0x245e24[_0xf8b1('0x48')]){logger['info']('['+_0x1a2b78[_0xf8b1('0x68')]['toUpperCase']()+']',_0xf8b1('0x49'));_0x1a2b78[_0xf8b1('0x4a')]=util[_0xf8b1('0xd')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x488d1f[_0xf8b1('0x47')],_0x1a2b78[_0xf8b1('0x61')],md5(_0x1a2b78['uniqueid']));}else{_0x1a2b78[_0xf8b1('0x4a')]='';}headers[_0xf8b1('0x69')]=getAuth(_0x488d1f);return getUser(_0x488d1f)['then'](function(_0x1eae11){_0x31735f=_0x1eae11;logger[_0xf8b1('0xb')](_0xf8b1('0x4c'),_0x31735f['id']);return getEndUser(_0x488d1f,_0x1a2b78[_0xf8b1('0x6a')],_0x1a2b78[_0xf8b1('0x4d')]);})['then'](function(_0x29731f){_0x157059=_0x29731f;logger[_0xf8b1('0xb')](_0xf8b1('0x4e'),_0x157059['id']);return getTicket(_0x488d1f,_0x31735f,_0x157059,_0x5a41c9,_0x1a2b78);})[_0xf8b1('0x17')](function(_0x2756f0){if(_0x2756f0){logger[_0xf8b1('0xb')](_0xf8b1('0x4f'),_0x2756f0['id']);}})[_0xf8b1('0x5b')](function(_0x5563f5){logger[_0xf8b1('0x59')]('['+_0x1a2b78[_0xf8b1('0x68')][_0xf8b1('0x6b')]()+']'+_0xf8b1('0x6c'),util[_0xf8b1('0x5d')](_0x5563f5,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x97f7=['stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','trigger:browser:url','replace','error','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','%s/agent/tickets/%s','Zendesk\x20account\x20type\x20not\x20recognized','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','inspect','lastevent','toUpperCase','\x20Error\x20running\x20Zendesk\x20integration','lodash','request-promise','md5','util','ioredis','./util','../../../../config/environment','../../../../config/logger','defaults','socket.io-emitter','redis','application/json','info','Creating\x20new\x20ticket...','%s/tickets.json','remoteUri','merge','name','getString','Subjects','Descriptions','Ticket\x20created!','ticket','validateEmail','Getting\x20agent\x20with\x20email','format','count','Agent\x20found!','find','results','agent','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','then','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','%s/search.json','type:user\x20role:end-user\x20phone:%s','length','end-user','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','POST','Caller\x20-\x20%s','Enduser\x20created.','password','%s:%s','username','authType','token','%s/token:%s','Basic\x20%s','base64','[HTTP]','map','forEach','includes','string','picklist','type','nameField','customField','content','idField','custom_fields','push','toString','variable','variableName','customVariable','Variable','toLowerCase','queue'];(function(_0x1656d4,_0x5c0706){var _0x116a28=function(_0x71c2d6){while(--_0x71c2d6){_0x1656d4['push'](_0x1656d4['shift']());}};_0x116a28(++_0x5c0706);}(_0x97f7,0x98));var _0x797f=function(_0x599f41,_0x4db732){_0x599f41=_0x599f41-0x0;var _0x2e4d58=_0x97f7[_0x599f41];return _0x2e4d58;};'use strict';var _=require(_0x797f('0x0'));var rp=require(_0x797f('0x1'));var md5=require(_0x797f('0x2'));var util=require(_0x797f('0x3'));var Redis=require(_0x797f('0x4'));var intUtil=require(_0x797f('0x5'));var config=require(_0x797f('0x6'));var logger=require(_0x797f('0x7'))('zendesk');config['redis']=_[_0x797f('0x8')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x797f('0x9'))(new Redis(config[_0x797f('0xa')]));function emit(_0x1da408,_0x1460bc,_0x19ee87){io['to'](_0x1da408)['emit'](_0x1460bc,_0x19ee87);}var headers={'Content-Type':_0x797f('0xb'),'Accept':_0x797f('0xb')};function getTicket(_0x407b26,_0x3e4e73,_0x18fe43,_0x4b96ff,_0x4fe4e9){logger[_0x797f('0xc')](_0x797f('0xd'));return request({'uri':util['format'](_0x797f('0xe'),_0x407b26[_0x797f('0xf')]),'method':'POST','body':{'ticket':_[_0x797f('0x10')]({'requester_id':_0x18fe43['id'],'submitter_id':_0x3e4e73?_0x3e4e73['id']:undefined,'assignee_id':_0x3e4e73?_0x3e4e73['id']:undefined,'tags':getTags(_0x4b96ff['Tags'],_0x797f('0x11')),'subject':intUtil[_0x797f('0x12')](_0x4b96ff[_0x797f('0x13')],_0x4fe4e9,'\x20'),'description':intUtil[_0x797f('0x12')](_0x4b96ff[_0x797f('0x14')],_0x4fe4e9,'\x0a'),'comment':{'public':![],'body':intUtil['getString'](_0x4b96ff[_0x797f('0x14')],_0x4fe4e9,'\x0a')}},getCustomFields(_0x4b96ff['Fields'],_0x4fe4e9))}})['then'](function(_0x3209fc){logger[_0x797f('0xc')](_0x797f('0x15'));return _0x3209fc[_0x797f('0x16')];});}function getUser(_0x4c200e,_0x43a971){if(intUtil[_0x797f('0x17')](_0x43a971)){logger[_0x797f('0xc')](_0x797f('0x18'),_0x43a971);return request({'uri':util['format']('%s/search.json',_0x4c200e['remoteUri']),'qs':{'query':util[_0x797f('0x19')]('type:user\x20role:agent\x20email:%s',_0x43a971)}})['then'](function(_0x3cf137){if(_0x3cf137[_0x797f('0x1a')]){logger[_0x797f('0xc')](_0x797f('0x1b'));return _[_0x797f('0x1c')](_0x3cf137[_0x797f('0x1d')],{'email':_0x43a971,'role':_0x797f('0x1e')});}else{logger[_0x797f('0xc')](_0x797f('0x1f'));return request({'uri':util[_0x797f('0x19')](_0x797f('0x20'),_0x4c200e['remoteUri'])})[_0x797f('0x21')](function(_0x5b4877){logger['info'](_0x797f('0x22'));return _0x5b4877[_0x797f('0x23')];});}});}else{logger[_0x797f('0xc')](_0x797f('0x1f'));return request({'uri':util['format'](_0x797f('0x20'),_0x4c200e[_0x797f('0xf')])})[_0x797f('0x21')](function(_0x1c8236){logger[_0x797f('0xc')](_0x797f('0x22'));return _0x1c8236[_0x797f('0x23')];});}}function getEndUser(_0x328536,_0x120861,_0x52e929){logger['info'](_0x797f('0x24'),_0x52e929);return request({'uri':util[_0x797f('0x19')](_0x797f('0x25'),_0x328536['remoteUri']),'qs':{'query':util[_0x797f('0x19')](_0x797f('0x26'),_0x52e929)}})[_0x797f('0x21')](function(_0x5d12a2){var _0xdddf;if(_0x5d12a2[_0x797f('0x1d')][_0x797f('0x27')]){_0x5d12a2['results']=_['filter'](_0x5d12a2[_0x797f('0x1d')],{'suspended':![],'role':_0x797f('0x28')});if(_0x5d12a2[_0x797f('0x1d')]['length']){_0xdddf=_['first'](_0x5d12a2['results']);}}if(_0xdddf){logger['info']('Enduser\x20found!');return _0xdddf;}else{logger['info'](_0x797f('0x29'));return request({'uri':util[_0x797f('0x19')](_0x797f('0x2a'),_0x328536['remoteUri']),'method':_0x797f('0x2b'),'body':{'user':{'role':_0x797f('0x28'),'name':util[_0x797f('0x19')](_0x797f('0x2c'),_0x120861||_0x52e929),'phone':_0x52e929}}})[_0x797f('0x21')](function(_0x106405){logger[_0x797f('0xc')](_0x797f('0x2d'));return _0x106405['user'];});}});}function getAuth(_0x3e4211){var _0x31cc6c;if(_0x3e4211['authType']===_0x797f('0x2e')){_0x31cc6c=util[_0x797f('0x19')](_0x797f('0x2f'),_0x3e4211[_0x797f('0x30')],_0x3e4211[_0x797f('0x2e')]);}else if(_0x3e4211[_0x797f('0x31')]===_0x797f('0x32')){_0x31cc6c=util['format'](_0x797f('0x33'),_0x3e4211[_0x797f('0x30')],_0x3e4211[_0x797f('0x32')]);}return util['format'](_0x797f('0x34'),new Buffer(_0x31cc6c)['toString'](_0x797f('0x35')));}function request(_0x58e5e3){logger['debug'](_0x797f('0x36'),JSON['stringify'](_0x58e5e3));return rp(_[_0x797f('0x8')](_0x58e5e3,{'method':'GET','headers':headers,'json':!![]}));}function getTags(_0x5ce34f,_0x258789){var _0x3d08dd=[];if(_0x5ce34f&&_0x5ce34f[_0x797f('0x27')]>0x0){_0x3d08dd=_[_0x797f('0x37')](_0x5ce34f,_0x258789);}return _0x3d08dd;}function getCustomFields(_0x4a9f06,_0x3ad652){var _0x28bdef=[];var _0x2e0737={'custom_fields':[]};if(_0x4a9f06[_0x797f('0x27')]>0x0){_[_0x797f('0x38')](_0x4a9f06,function(_0x553354){if(_[_0x797f('0x39')]([_0x797f('0x3a'),_0x797f('0x3b')],_0x553354[_0x797f('0x3c')])&&_0x553354[_0x797f('0x3d')]&&!_0x553354[_0x797f('0x3e')]){_0x2e0737[_0x553354[_0x797f('0x3d')]['toLowerCase']()]=_0x553354[_0x797f('0x3f')]['toString']();}else if(_[_0x797f('0x39')](['string',_0x797f('0x3b')],_0x553354[_0x797f('0x3c')])&&_0x553354[_0x797f('0x40')]&&_0x553354[_0x797f('0x3e')]){_0x2e0737[_0x797f('0x41')][_0x797f('0x42')]({'id':_0x553354['idField'],'value':_0x553354['content'][_0x797f('0x43')]()});}else if(_0x553354[_0x797f('0x3c')]===_0x797f('0x44')&&_0x553354[_0x797f('0x45')]&&_0x553354['idField']&&_0x553354['customField']){_0x3ad652[_0x553354['variableName']]&&_0x2e0737[_0x797f('0x41')][_0x797f('0x42')]({'id':_0x553354[_0x797f('0x40')],'value':_0x3ad652[_0x553354[_0x797f('0x45')]][_0x797f('0x43')]()});}else if(_0x553354['type']===_0x797f('0x46')&&_0x553354['Variable']&&_0x553354[_0x797f('0x47')][_0x797f('0x11')]&&_0x553354[_0x797f('0x40')]&&_0x553354[_0x797f('0x3e')]){_0x3ad652[_0x553354[_0x797f('0x47')]['name'][_0x797f('0x48')]()]&&_0x2e0737[_0x797f('0x41')]['push']({'id':_0x553354[_0x797f('0x40')],'value':_0x3ad652[_0x553354[_0x797f('0x47')][_0x797f('0x11')][_0x797f('0x48')]()][_0x797f('0x43')]()});}});}return _0x2e0737;}exports[_0x797f('0x49')]=function(_0x5e5f9a,_0x55e87c,_0x4d9448,_0x26943d,_0x46cb2c,_0x1b1930){var _0x466cc2,_0x501366;_0x1b1930[_0x797f('0xf')]=intUtil[_0x797f('0x4a')](_0x1b1930[_0x797f('0xf')]);_0x1b1930[_0x797f('0x4b')]=intUtil[_0x797f('0x4a')](_0x1b1930['serverUrl']);if(_0x46cb2c&&_0x46cb2c[_0x797f('0x4c')]){logger[_0x797f('0xc')](_0x797f('0x4d'),_0x797f('0x4e'));_0x55e87c[_0x797f('0x4f')]=util[_0x797f('0x19')](_0x797f('0x50'),_0x1b1930[_0x797f('0x4b')],_0x55e87c[_0x797f('0x51')],md5(_0x55e87c[_0x797f('0x51')]));}else{_0x55e87c[_0x797f('0x4f')]='';}headers[_0x797f('0x52')]=getAuth(_0x1b1930);return getUser(_0x1b1930,_0x26943d[_0x797f('0x53')])[_0x797f('0x21')](function(_0x4f6e5f){_0x466cc2=_0x4f6e5f;logger[_0x797f('0xc')](_0x797f('0x54'),_0x466cc2['id']);return getEndUser(_0x1b1930,_0x55e87c[_0x797f('0x55')],_0x55e87c[_0x797f('0x56')]);})[_0x797f('0x21')](function(_0x190053){_0x501366=_0x190053;logger[_0x797f('0xc')](_0x797f('0x57'),_0x501366['id']);return getTicket(_0x1b1930,_0x466cc2,_0x501366,_0x4d9448,_0x55e87c);})[_0x797f('0x21')](function(_0x18b8e8){if(_0x18b8e8){logger[_0x797f('0xc')](_0x797f('0x58'),_0x18b8e8['id']);switch(_0x1b1930[_0x797f('0x3c')]){case _0x797f('0x59'):logger[_0x797f('0xc')](_0x797f('0x4d'),_0x797f('0x5a'));return request({'uri':util[_0x797f('0x19')](_0x797f('0x5b'),_0x1b1930['remoteUri'],_0x466cc2['id'],_0x18b8e8['id']),'method':_0x797f('0x2b')});case _0x797f('0x5c'):logger[_0x797f('0xc')](_0x797f('0x4d'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x797f('0x19')]('user:%s',_0x26943d[_0x797f('0x11')]),_0x797f('0x5d'),{'uri':util[_0x797f('0x19')]('%s/agent/tickets/%s',_0x1b1930[_0x797f('0xf')][_0x797f('0x5e')]('/api/v2',''),_0x18b8e8['id'])});break;default:logger[_0x797f('0x5f')](_0x797f('0x4d'),'Zendesk\x20account\x20type\x20not\x20recognized');}}})[_0x797f('0x60')](function(_0x5ab7b7){logger['error'](_0x797f('0x61'),util['inspect'](_0x5ab7b7,{'showHidden':!![],'depth':null}));});};exports[_0x797f('0x62')]=function(_0x35b1e8,_0x142445,_0x25edef,_0x406f70,_0x3d79e0,_0x1474d3,_0x46faa4){var _0x3e4942,_0x30083b;_0x1474d3['remoteUri']=intUtil[_0x797f('0x4a')](_0x1474d3['remoteUri']);_0x1474d3[_0x797f('0x4b')]=intUtil[_0x797f('0x4a')](_0x1474d3[_0x797f('0x4b')]);if(_0x46faa4&&_0x46faa4['recordingFormat']&&_0x46faa4[_0x797f('0x63')]!==_0x797f('0x64')){logger['info'](_0x797f('0x65'),_0x797f('0x4e'));_0x142445[_0x797f('0x4f')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x1474d3[_0x797f('0x4b')],_0x142445[_0x797f('0x51')],md5(_0x142445[_0x797f('0x51')]));}headers[_0x797f('0x52')]=getAuth(_0x1474d3);return getUser(_0x1474d3,_0x406f70[_0x797f('0x53')])[_0x797f('0x21')](function(_0x43904f){_0x3e4942=_0x43904f;logger[_0x797f('0xc')](_0x797f('0x54'),_0x3e4942['id']);return getEndUser(_0x1474d3,_0x142445[_0x797f('0x66')],_0x142445[_0x797f('0x67')]);})['then'](function(_0x477c67){_0x30083b=_0x477c67;logger['info']('The\x20Enduser\x20ID\x20is:',_0x30083b['id']);return getTicket(_0x1474d3,_0x3e4942,_0x30083b,_0x25edef,_0x142445);})[_0x797f('0x21')](function(_0x35e8c8){if(_0x35e8c8){logger[_0x797f('0xc')]('The\x20Ticket\x20ID\x20is:',_0x35e8c8['id']);switch(_0x1474d3[_0x797f('0x3c')]){case _0x797f('0x59'):logger[_0x797f('0xc')](_0x797f('0x65'),_0x797f('0x5a'));return request({'uri':util[_0x797f('0x19')](_0x797f('0x5b'),_0x1474d3[_0x797f('0xf')],_0x3e4942['id'],_0x35e8c8['id']),'method':_0x797f('0x2b')});case _0x797f('0x5c'):logger['info']('[OUTBOUND]',_0x797f('0x68'));emit(util[_0x797f('0x19')](_0x797f('0x69'),_0x406f70[_0x797f('0x11')]),_0x797f('0x5d'),{'uri':util['format'](_0x797f('0x6a'),_0x1474d3[_0x797f('0xf')][_0x797f('0x5e')]('/api/v2',''),_0x35e8c8['id'])});break;default:logger[_0x797f('0x5f')](_0x797f('0x65'),_0x797f('0x6b'));}}})[_0x797f('0x60')](function(_0x30de6f){logger[_0x797f('0x5f')](_0x797f('0x6c'),util[_0x797f('0x6d')](_0x30de6f,{'showHidden':!![],'depth':null}));});};exports['unmanaged']=function(_0x49a491,_0x33a639,_0x5d8d71,_0x472c15,_0x3494c4,_0x17bcb6){var _0x1b3fe9,_0x26cea7;_0x17bcb6[_0x797f('0xf')]=intUtil[_0x797f('0x4a')](_0x17bcb6[_0x797f('0xf')]);_0x17bcb6[_0x797f('0x4b')]=intUtil[_0x797f('0x4a')](_0x17bcb6['serverUrl']);if(_0x3494c4&&_0x3494c4[_0x797f('0x4c')]){logger[_0x797f('0xc')]('['+_0x33a639[_0x797f('0x6e')][_0x797f('0x6f')]()+']',_0x797f('0x4e'));_0x33a639[_0x797f('0x4f')]=util[_0x797f('0x19')](_0x797f('0x50'),_0x17bcb6[_0x797f('0x4b')],_0x33a639[_0x797f('0x51')],md5(_0x33a639['uniqueid']));}else{_0x33a639[_0x797f('0x4f')]='';}headers['Authorization']=getAuth(_0x17bcb6);return getUser(_0x17bcb6)[_0x797f('0x21')](function(_0x222c00){_0x1b3fe9=_0x222c00;logger['info'](_0x797f('0x54'),_0x1b3fe9['id']);return getEndUser(_0x17bcb6,_0x33a639[_0x797f('0x55')],_0x33a639[_0x797f('0x56')]);})[_0x797f('0x21')](function(_0x239123){_0x26cea7=_0x239123;logger[_0x797f('0xc')](_0x797f('0x57'),_0x26cea7['id']);return getTicket(_0x17bcb6,_0x1b3fe9,_0x26cea7,_0x5d8d71,_0x33a639);})[_0x797f('0x21')](function(_0x49fd1e){if(_0x49fd1e){logger[_0x797f('0xc')](_0x797f('0x58'),_0x49fd1e['id']);}})[_0x797f('0x60')](function(_0x5c1fb7){logger[_0x797f('0x5f')]('['+_0x33a639[_0x797f('0x6e')][_0x797f('0x6f')]()+']'+_0x797f('0x70'),util[_0x797f('0x6d')](_0x5c1fb7,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file