Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index d705d2d..5082573 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x910f=['destcalleridname','The\x20Ticket\x20ID\x20is:','Displaying\x20ticket\x20to\x20agent...','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','toUpperCase','The\x20User\x20ID\x20is:','calleridname','\x20Error\x20running\x20Zendesk\x20integration','lodash','md5','util','./util','../../../../config/environment','../../../../config/logger','redis','localhost','socket.io-emitter','application/json','info','format','%s/tickets.json','remoteUri','POST','merge','Tags','name','getString','Subjects','Descriptions','then','Ticket\x20created!','ticket','validateEmail','Getting\x20agent\x20with\x20email','%s/search.json','type:user\x20role:agent\x20email:%s','Agent\x20found!','results','agent','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','user','Searching\x20enduser\x20with\x20phone','type:user\x20role:end-user\x20phone:%s','length','filter','end-user','first','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Enduser\x20created.','authType','%s:%s','username','password','token','%s/token:%s','Basic\x20%s','base64','[HTTP]','stringify','defaults','map','forEach','includes','string','picklist','type','nameField','customField','toLowerCase','content','custom_fields','push','idField','toString','variableName','customVariable','Variable','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','uniqueid','Authorization','email','calleridnum','The\x20Enduser\x20ID\x20is:','integrationTab','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','user:%s','trigger:browser:url','%s/agent/tickets/%s','replace','/api/v2','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','inspect','recordingFormat','none','[OUTBOUND]','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s'];(function(_0x548ee0,_0x4817f2){var _0x434d96=function(_0x141527){while(--_0x141527){_0x548ee0['push'](_0x548ee0['shift']());}};_0x434d96(++_0x4817f2);}(_0x910f,0x74));var _0xf910=function(_0x28d6b9,_0xbe9964){_0x28d6b9=_0x28d6b9-0x0;var _0x1e2bee=_0x910f[_0x28d6b9];return _0x1e2bee;};'use strict';var _=require(_0xf910('0x0'));var rp=require('request-promise');var md5=require(_0xf910('0x1'));var util=require(_0xf910('0x2'));var Redis=require('ioredis');var intUtil=require(_0xf910('0x3'));var config=require(_0xf910('0x4'));var logger=require(_0xf910('0x5'))('zendesk');config[_0xf910('0x6')]=_['defaults'](config[_0xf910('0x6')],{'host':_0xf910('0x7'),'port':0x18eb});var io=require(_0xf910('0x8'))(new Redis(config[_0xf910('0x6')]));function emit(_0x5e7f61,_0x3664f8,_0x5e909a){io['to'](_0x5e7f61)['emit'](_0x3664f8,_0x5e909a);}var headers={'Content-Type':_0xf910('0x9'),'Accept':_0xf910('0x9')};function getTicket(_0x1fcfe2,_0x3ebc5d,_0x3f7736,_0x10f395,_0x23c2ea){logger[_0xf910('0xa')]('Creating\x20new\x20ticket...');return request({'uri':util[_0xf910('0xb')](_0xf910('0xc'),_0x1fcfe2[_0xf910('0xd')]),'method':_0xf910('0xe'),'body':{'ticket':_[_0xf910('0xf')]({'requester_id':_0x3f7736['id'],'submitter_id':_0x3ebc5d?_0x3ebc5d['id']:undefined,'assignee_id':_0x3ebc5d?_0x3ebc5d['id']:undefined,'tags':getTags(_0x10f395[_0xf910('0x10')],_0xf910('0x11')),'subject':intUtil[_0xf910('0x12')](_0x10f395[_0xf910('0x13')],_0x23c2ea,'\x20'),'description':intUtil['getString'](_0x10f395[_0xf910('0x14')],_0x23c2ea,'\x0a'),'comment':{'public':![],'body':intUtil[_0xf910('0x12')](_0x10f395[_0xf910('0x14')],_0x23c2ea,'\x0a')}},getCustomFields(_0x10f395['Fields'],_0x23c2ea))}})[_0xf910('0x15')](function(_0x267ad9){logger[_0xf910('0xa')](_0xf910('0x16'));return _0x267ad9[_0xf910('0x17')];});}function getUser(_0x3b53d6,_0x4d0166){if(intUtil[_0xf910('0x18')](_0x4d0166)){logger[_0xf910('0xa')](_0xf910('0x19'),_0x4d0166);return request({'uri':util['format'](_0xf910('0x1a'),_0x3b53d6[_0xf910('0xd')]),'qs':{'query':util[_0xf910('0xb')](_0xf910('0x1b'),_0x4d0166)}})['then'](function(_0x25c45d){if(_0x25c45d['count']){logger['info'](_0xf910('0x1c'));return _['find'](_0x25c45d[_0xf910('0x1d')],{'email':_0x4d0166,'role':_0xf910('0x1e')});}else{logger[_0xf910('0xa')](_0xf910('0x1f'));return request({'uri':util[_0xf910('0xb')](_0xf910('0x20'),_0x3b53d6['remoteUri'])})[_0xf910('0x15')](function(_0x3fa4d6){logger['info']('Admin\x20account\x20selected.');return _0x3fa4d6['user'];});}});}else{logger[_0xf910('0xa')](_0xf910('0x1f'));return request({'uri':util[_0xf910('0xb')](_0xf910('0x20'),_0x3b53d6[_0xf910('0xd')])})['then'](function(_0x1c6f31){logger[_0xf910('0xa')]('Admin\x20account\x20selected.');return _0x1c6f31[_0xf910('0x21')];});}}function getEndUser(_0x335b7c,_0x417b9c,_0x463ed8){logger[_0xf910('0xa')](_0xf910('0x22'),_0x463ed8);return request({'uri':util[_0xf910('0xb')](_0xf910('0x1a'),_0x335b7c[_0xf910('0xd')]),'qs':{'query':util['format'](_0xf910('0x23'),_0x463ed8)}})[_0xf910('0x15')](function(_0x4bd739){var _0x280fb8;if(_0x4bd739[_0xf910('0x1d')][_0xf910('0x24')]){_0x4bd739[_0xf910('0x1d')]=_[_0xf910('0x25')](_0x4bd739[_0xf910('0x1d')],{'suspended':![],'role':_0xf910('0x26')});if(_0x4bd739[_0xf910('0x1d')][_0xf910('0x24')]){_0x280fb8=_[_0xf910('0x27')](_0x4bd739[_0xf910('0x1d')]);}}if(_0x280fb8){logger[_0xf910('0xa')]('Enduser\x20found!');return _0x280fb8;}else{logger[_0xf910('0xa')](_0xf910('0x28'));return request({'uri':util['format']('%s/users.json',_0x335b7c[_0xf910('0xd')]),'method':_0xf910('0xe'),'body':{'user':{'role':_0xf910('0x26'),'name':util['format']('Caller\x20-\x20%s',_0x417b9c||_0x463ed8),'phone':_0x463ed8}}})[_0xf910('0x15')](function(_0x49d1){logger[_0xf910('0xa')](_0xf910('0x29'));return _0x49d1[_0xf910('0x21')];});}});}function getAuth(_0x246a30){var _0x491859;if(_0x246a30[_0xf910('0x2a')]==='password'){_0x491859=util[_0xf910('0xb')](_0xf910('0x2b'),_0x246a30[_0xf910('0x2c')],_0x246a30[_0xf910('0x2d')]);}else if(_0x246a30[_0xf910('0x2a')]===_0xf910('0x2e')){_0x491859=util['format'](_0xf910('0x2f'),_0x246a30['username'],_0x246a30[_0xf910('0x2e')]);}return util[_0xf910('0xb')](_0xf910('0x30'),new Buffer(_0x491859)['toString'](_0xf910('0x31')));}function request(_0x2bfcf1){logger['debug'](_0xf910('0x32'),JSON[_0xf910('0x33')](_0x2bfcf1));return rp(_[_0xf910('0x34')](_0x2bfcf1,{'method':'GET','headers':headers,'json':!![]}));}function getTags(_0x472453,_0x2a8ded){var _0x4b0e35=[];if(_0x472453&&_0x472453[_0xf910('0x24')]>0x0){_0x4b0e35=_[_0xf910('0x35')](_0x472453,_0x2a8ded);}return _0x4b0e35;}function getCustomFields(_0xe187cf,_0x629350){var _0x3e7735=[];var _0x38f958={'custom_fields':[]};if(_0xe187cf['length']>0x0){_[_0xf910('0x36')](_0xe187cf,function(_0x25ec15){if(_[_0xf910('0x37')]([_0xf910('0x38'),_0xf910('0x39')],_0x25ec15[_0xf910('0x3a')])&&_0x25ec15[_0xf910('0x3b')]&&!_0x25ec15[_0xf910('0x3c')]){_0x38f958[_0x25ec15[_0xf910('0x3b')][_0xf910('0x3d')]()]=_0x25ec15[_0xf910('0x3e')]['toString']();}else if(_[_0xf910('0x37')]([_0xf910('0x38'),_0xf910('0x39')],_0x25ec15[_0xf910('0x3a')])&&_0x25ec15['idField']&&_0x25ec15[_0xf910('0x3c')]){_0x38f958[_0xf910('0x3f')][_0xf910('0x40')]({'id':_0x25ec15[_0xf910('0x41')],'value':_0x25ec15['content'][_0xf910('0x42')]()});}else if(_0x25ec15[_0xf910('0x3a')]==='variable'&&_0x25ec15[_0xf910('0x43')]&&_0x25ec15[_0xf910('0x41')]&&_0x25ec15['customField']){_0x629350[_0x25ec15[_0xf910('0x43')]]&&_0x38f958[_0xf910('0x3f')][_0xf910('0x40')]({'id':_0x25ec15[_0xf910('0x41')],'value':_0x629350[_0x25ec15['variableName']][_0xf910('0x42')]()});}else if(_0x25ec15[_0xf910('0x3a')]===_0xf910('0x44')&&_0x25ec15['Variable']&&_0x25ec15[_0xf910('0x45')][_0xf910('0x11')]&&_0x25ec15[_0xf910('0x41')]&&_0x25ec15[_0xf910('0x3c')]){_0x629350[_0x25ec15[_0xf910('0x45')][_0xf910('0x11')][_0xf910('0x3d')]()]&&_0x38f958[_0xf910('0x3f')][_0xf910('0x40')]({'id':_0x25ec15['idField'],'value':_0x629350[_0x25ec15['Variable'][_0xf910('0x11')]['toLowerCase']()][_0xf910('0x42')]()});}});}return _0x38f958;}exports[_0xf910('0x46')]=function(_0x4cf406,_0x380ca8,_0x168c2b,_0x5988bc,_0x435847,_0x15c3b2){var _0x1f42aa,_0x4f96a7;_0x15c3b2[_0xf910('0xd')]=intUtil[_0xf910('0x47')](_0x15c3b2[_0xf910('0xd')]);_0x15c3b2[_0xf910('0x48')]=intUtil[_0xf910('0x47')](_0x15c3b2[_0xf910('0x48')]);if(_0x435847&&_0x435847[_0xf910('0x49')]){logger['info'](_0xf910('0x4a'),_0xf910('0x4b'));_0x380ca8[_0xf910('0x4c')]=util[_0xf910('0xb')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x15c3b2['serverUrl'],_0x380ca8[_0xf910('0x4d')],md5(_0x380ca8[_0xf910('0x4d')]));}else{_0x380ca8['recordingURL']='';}headers[_0xf910('0x4e')]=getAuth(_0x15c3b2);return getUser(_0x15c3b2,_0x5988bc[_0xf910('0x4f')])[_0xf910('0x15')](function(_0x586bfb){_0x1f42aa=_0x586bfb;logger['info']('The\x20User\x20ID\x20is:',_0x1f42aa['id']);return getEndUser(_0x15c3b2,_0x380ca8['calleridname'],_0x380ca8[_0xf910('0x50')]);})[_0xf910('0x15')](function(_0x2977bd){_0x4f96a7=_0x2977bd;logger[_0xf910('0xa')](_0xf910('0x51'),_0x4f96a7['id']);return getTicket(_0x15c3b2,_0x1f42aa,_0x4f96a7,_0x168c2b,_0x380ca8);})['then'](function(_0x70c946){if(_0x70c946){logger['info']('The\x20Ticket\x20ID\x20is:',_0x70c946['id']);switch(_0x15c3b2[_0xf910('0x3a')]){case _0xf910('0x52'):logger['info'](_0xf910('0x4a'),'Displaying\x20ticket\x20to\x20agent...');return request({'uri':util[_0xf910('0xb')](_0xf910('0x53'),_0x15c3b2[_0xf910('0xd')],_0x1f42aa['id'],_0x70c946['id']),'method':_0xf910('0xe')});case _0xf910('0x54'):logger[_0xf910('0xa')]('[QUEUE]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0xf910('0xb')](_0xf910('0x55'),_0x5988bc['name']),_0xf910('0x56'),{'uri':util['format'](_0xf910('0x57'),_0x15c3b2[_0xf910('0xd')][_0xf910('0x58')](_0xf910('0x59'),''),_0x70c946['id'])});break;default:logger[_0xf910('0x5a')](_0xf910('0x4a'),_0xf910('0x5b'));}}})[_0xf910('0x5c')](function(_0x470f34){logger['error']('[QUEUE]\x20Error\x20running\x20Zendesk\x20integration',util[_0xf910('0x5d')](_0x470f34,{'showHidden':!![],'depth':null}));});};exports['outbound']=function(_0x229542,_0x2bd50c,_0xb1d71c,_0x41d549,_0x54a1f6,_0x295062,_0x511a1f){var _0x59f8d6,_0x5a77cc;_0x295062[_0xf910('0xd')]=intUtil['stripTrailingSlash'](_0x295062['remoteUri']);_0x295062[_0xf910('0x48')]=intUtil[_0xf910('0x47')](_0x295062[_0xf910('0x48')]);if(_0x511a1f&&_0x511a1f[_0xf910('0x5e')]&&_0x511a1f['recordingFormat']!==_0xf910('0x5f')){logger['info'](_0xf910('0x60'),_0xf910('0x4b'));_0x2bd50c[_0xf910('0x4c')]=util[_0xf910('0xb')](_0xf910('0x61'),_0x295062[_0xf910('0x48')],_0x2bd50c['uniqueid'],md5(_0x2bd50c[_0xf910('0x4d')]));}headers[_0xf910('0x4e')]=getAuth(_0x295062);return getUser(_0x295062,_0x41d549[_0xf910('0x4f')])[_0xf910('0x15')](function(_0x277b80){_0x59f8d6=_0x277b80;logger[_0xf910('0xa')]('The\x20User\x20ID\x20is:',_0x59f8d6['id']);return getEndUser(_0x295062,_0x2bd50c[_0xf910('0x62')],_0x2bd50c['destcalleridnum']);})['then'](function(_0x4986c2){_0x5a77cc=_0x4986c2;logger['info'](_0xf910('0x51'),_0x5a77cc['id']);return getTicket(_0x295062,_0x59f8d6,_0x5a77cc,_0xb1d71c,_0x2bd50c);})['then'](function(_0x3e2a51){if(_0x3e2a51){logger['info'](_0xf910('0x63'),_0x3e2a51['id']);switch(_0x295062[_0xf910('0x3a')]){case _0xf910('0x52'):logger[_0xf910('0xa')](_0xf910('0x60'),_0xf910('0x64'));return request({'uri':util[_0xf910('0xb')](_0xf910('0x53'),_0x295062[_0xf910('0xd')],_0x59f8d6['id'],_0x3e2a51['id']),'method':'POST'});case _0xf910('0x54'):logger[_0xf910('0xa')](_0xf910('0x60'),_0xf910('0x65'));emit(util[_0xf910('0xb')](_0xf910('0x55'),_0x41d549[_0xf910('0x11')]),'trigger:browser:url',{'uri':util['format'](_0xf910('0x57'),_0x295062[_0xf910('0xd')]['replace']('/api/v2',''),_0x3e2a51['id'])});break;default:logger['error'](_0xf910('0x60'),_0xf910('0x5b'));}}})['catch'](function(_0x52d1e5){logger[_0xf910('0x5a')](_0xf910('0x66'),util[_0xf910('0x5d')](_0x52d1e5,{'showHidden':!![],'depth':null}));});};exports['unmanaged']=function(_0x470944,_0x1ff360,_0x16ffee,_0x52db2a,_0x4fbf7b,_0x3a9c89){var _0x7c96cc,_0x2e7ff6;_0x3a9c89[_0xf910('0xd')]=intUtil[_0xf910('0x47')](_0x3a9c89[_0xf910('0xd')]);_0x3a9c89['serverUrl']=intUtil[_0xf910('0x47')](_0x3a9c89[_0xf910('0x48')]);if(_0x4fbf7b&&_0x4fbf7b[_0xf910('0x49')]){logger[_0xf910('0xa')]('['+_0x1ff360['lastevent'][_0xf910('0x67')]()+']',_0xf910('0x4b'));_0x1ff360[_0xf910('0x4c')]=util['format'](_0xf910('0x61'),_0x3a9c89[_0xf910('0x48')],_0x1ff360[_0xf910('0x4d')],md5(_0x1ff360[_0xf910('0x4d')]));}else{_0x1ff360[_0xf910('0x4c')]='';}headers[_0xf910('0x4e')]=getAuth(_0x3a9c89);return getUser(_0x3a9c89)[_0xf910('0x15')](function(_0x39463d){_0x7c96cc=_0x39463d;logger[_0xf910('0xa')](_0xf910('0x68'),_0x7c96cc['id']);return getEndUser(_0x3a9c89,_0x1ff360[_0xf910('0x69')],_0x1ff360['calleridnum']);})[_0xf910('0x15')](function(_0xc83801){_0x2e7ff6=_0xc83801;logger['info'](_0xf910('0x51'),_0x2e7ff6['id']);return getTicket(_0x3a9c89,_0x7c96cc,_0x2e7ff6,_0x16ffee,_0x1ff360);})[_0xf910('0x15')](function(_0x41e14e){if(_0x41e14e){logger['info']('The\x20Ticket\x20ID\x20is:',_0x41e14e['id']);}})[_0xf910('0x5c')](function(_0x12c31e){logger[_0xf910('0x5a')]('['+_0x1ff360['lastevent']['toUpperCase']()+']'+_0xf910('0x6a'),util[_0xf910('0x5d')](_0x12c31e,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x1b58=['picklist','type','nameField','customField','toLowerCase','idField','push','content','variableName','custom_fields','customVariable','Variable','name','queue','stripTrailingSlash','serverUrl','monitor_format','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','email','The\x20User\x20ID\x20is:','calleridname','The\x20Enduser\x20ID\x20is:','integrationTab','[QUEUE]','Displaying\x20ticket\x20to\x20agent...','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','/api/v2','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','inspect','outbound','recordingFormat','Recording\x20is\x20enabled!','destcalleridname','destcalleridnum','The\x20Ticket\x20ID\x20is:','[OUTBOUND]','%s/channels/voice/agents/%d/tickets/%d/display.json','%s/agent/tickets/%s','replace','toUpperCase','calleridnum','lastevent','\x20Error\x20running\x20Zendesk\x20integration','request-promise','md5','ioredis','../../../../config/environment','redis','defaults','localhost','socket.io-emitter','application/json','info','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!','%s/users/me.json','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','results','filter','end-user','length','first','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','Caller\x20-\x20%s','Enduser\x20created.','%s:%s','username','password','token','%s/token:%s','Basic\x20%s','toString','base64','debug','stringify','GET','map','forEach','includes','string'];(function(_0x3216ed,_0x1b78ae){var _0x1f7305=function(_0x5b4522){while(--_0x5b4522){_0x3216ed['push'](_0x3216ed['shift']());}};_0x1f7305(++_0x1b78ae);}(_0x1b58,0x9f));var _0x81b5=function(_0x5750fa,_0x57c0df){_0x5750fa=_0x5750fa-0x0;var _0x2aeb4e=_0x1b58[_0x5750fa];return _0x2aeb4e;};'use strict';var _=require('lodash');var rp=require(_0x81b5('0x0'));var md5=require(_0x81b5('0x1'));var util=require('util');var Redis=require(_0x81b5('0x2'));var intUtil=require('./util');var config=require(_0x81b5('0x3'));var logger=require('../../../../config/logger')('zendesk');config[_0x81b5('0x4')]=_[_0x81b5('0x5')](config[_0x81b5('0x4')],{'host':_0x81b5('0x6'),'port':0x18eb});var io=require(_0x81b5('0x7'))(new Redis(config[_0x81b5('0x4')]));function emit(_0x4edfc5,_0xfc6eb4,_0x4ce18a){io['to'](_0x4edfc5)['emit'](_0xfc6eb4,_0x4ce18a);}var headers={'Content-Type':'application/json','Accept':_0x81b5('0x8')};function getTicket(_0x5c8c9a,_0x10df74,_0x40bc65,_0x5769dd,_0x377d7c){logger[_0x81b5('0x9')]('Creating\x20new\x20ticket...');return request({'uri':util[_0x81b5('0xa')](_0x81b5('0xb'),_0x5c8c9a[_0x81b5('0xc')]),'method':_0x81b5('0xd'),'body':{'ticket':_[_0x81b5('0xe')]({'requester_id':_0x40bc65['id'],'submitter_id':_0x10df74?_0x10df74['id']:undefined,'assignee_id':_0x10df74?_0x10df74['id']:undefined,'tags':getTags(_0x5769dd[_0x81b5('0xf')],'name'),'subject':intUtil[_0x81b5('0x10')](_0x5769dd[_0x81b5('0x11')],_0x377d7c,'\x20'),'description':intUtil[_0x81b5('0x10')](_0x5769dd[_0x81b5('0x12')],_0x377d7c,'\x0a'),'comment':{'public':![],'body':intUtil[_0x81b5('0x10')](_0x5769dd[_0x81b5('0x12')],_0x377d7c,'\x0a')}},getCustomFields(_0x5769dd[_0x81b5('0x13')],_0x377d7c))}})[_0x81b5('0x14')](function(_0x5a6277){logger[_0x81b5('0x9')](_0x81b5('0x15'));return _0x5a6277[_0x81b5('0x16')];});}function getUser(_0x1385c7,_0x3de0c9){if(intUtil[_0x81b5('0x17')](_0x3de0c9)){logger[_0x81b5('0x9')](_0x81b5('0x18'),_0x3de0c9);return request({'uri':util[_0x81b5('0xa')](_0x81b5('0x19'),_0x1385c7[_0x81b5('0xc')]),'qs':{'query':util['format']('type:user\x20role:agent\x20email:%s',_0x3de0c9)}})[_0x81b5('0x14')](function(_0x5982df){if(_0x5982df[_0x81b5('0x1a')]){logger['info'](_0x81b5('0x1b'));return _[_0x81b5('0x1c')](_0x5982df['results'],{'email':_0x3de0c9,'role':_0x81b5('0x1d')});}else{logger[_0x81b5('0x9')](_0x81b5('0x1e'));return request({'uri':util[_0x81b5('0xa')](_0x81b5('0x1f'),_0x1385c7[_0x81b5('0xc')])})[_0x81b5('0x14')](function(_0x3e1867){logger[_0x81b5('0x9')](_0x81b5('0x20'));return _0x3e1867[_0x81b5('0x21')];});}});}else{logger['info']('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0x81b5('0xa')](_0x81b5('0x1f'),_0x1385c7[_0x81b5('0xc')])})[_0x81b5('0x14')](function(_0x2c4c7e){logger[_0x81b5('0x9')](_0x81b5('0x20'));return _0x2c4c7e[_0x81b5('0x21')];});}}function getEndUser(_0x5e2542,_0x37b63a,_0x504fa8){logger['info'](_0x81b5('0x22'),_0x504fa8);return request({'uri':util[_0x81b5('0xa')]('%s/search.json',_0x5e2542[_0x81b5('0xc')]),'qs':{'query':util[_0x81b5('0xa')]('type:user\x20role:end-user\x20phone:%s',_0x504fa8)}})[_0x81b5('0x14')](function(_0x556516){var _0x3cf47;if(_0x556516[_0x81b5('0x23')]['length']){_0x556516[_0x81b5('0x23')]=_[_0x81b5('0x24')](_0x556516['results'],{'suspended':![],'role':_0x81b5('0x25')});if(_0x556516[_0x81b5('0x23')][_0x81b5('0x26')]){_0x3cf47=_[_0x81b5('0x27')](_0x556516[_0x81b5('0x23')]);}}if(_0x3cf47){logger[_0x81b5('0x9')]('Enduser\x20found!');return _0x3cf47;}else{logger[_0x81b5('0x9')](_0x81b5('0x28'));return request({'uri':util['format'](_0x81b5('0x29'),_0x5e2542[_0x81b5('0xc')]),'method':'POST','body':{'user':{'role':_0x81b5('0x25'),'name':util['format'](_0x81b5('0x2a'),_0x37b63a||_0x504fa8),'phone':_0x504fa8}}})[_0x81b5('0x14')](function(_0x2ab31d){logger[_0x81b5('0x9')](_0x81b5('0x2b'));return _0x2ab31d['user'];});}});}function getAuth(_0x1813f6){var _0x36bf90;if(_0x1813f6['authType']==='password'){_0x36bf90=util['format'](_0x81b5('0x2c'),_0x1813f6[_0x81b5('0x2d')],_0x1813f6[_0x81b5('0x2e')]);}else if(_0x1813f6['authType']===_0x81b5('0x2f')){_0x36bf90=util[_0x81b5('0xa')](_0x81b5('0x30'),_0x1813f6[_0x81b5('0x2d')],_0x1813f6[_0x81b5('0x2f')]);}return util['format'](_0x81b5('0x31'),new Buffer(_0x36bf90)[_0x81b5('0x32')](_0x81b5('0x33')));}function request(_0xf651f8){logger[_0x81b5('0x34')]('[HTTP]',JSON[_0x81b5('0x35')](_0xf651f8));return rp(_[_0x81b5('0x5')](_0xf651f8,{'method':_0x81b5('0x36'),'headers':headers,'json':!![]}));}function getTags(_0xca8f87,_0x28777a){var _0x4d83e4=[];if(_0xca8f87&&_0xca8f87[_0x81b5('0x26')]>0x0){_0x4d83e4=_[_0x81b5('0x37')](_0xca8f87,_0x28777a);}return _0x4d83e4;}function getCustomFields(_0x216cc9,_0x2db378){var _0xa7cbc2=[];var _0x24bb89={'custom_fields':[]};if(_0x216cc9[_0x81b5('0x26')]>0x0){_[_0x81b5('0x38')](_0x216cc9,function(_0x41f17d){if(_[_0x81b5('0x39')]([_0x81b5('0x3a'),_0x81b5('0x3b')],_0x41f17d[_0x81b5('0x3c')])&&_0x41f17d[_0x81b5('0x3d')]&&!_0x41f17d[_0x81b5('0x3e')]){_0x24bb89[_0x41f17d[_0x81b5('0x3d')][_0x81b5('0x3f')]()]=_0x41f17d['content'][_0x81b5('0x32')]();}else if(_[_0x81b5('0x39')](['string',_0x81b5('0x3b')],_0x41f17d['type'])&&_0x41f17d[_0x81b5('0x40')]&&_0x41f17d[_0x81b5('0x3e')]){_0x24bb89['custom_fields'][_0x81b5('0x41')]({'id':_0x41f17d['idField'],'value':_0x41f17d[_0x81b5('0x42')][_0x81b5('0x32')]()});}else if(_0x41f17d[_0x81b5('0x3c')]==='variable'&&_0x41f17d['variableName']&&_0x41f17d[_0x81b5('0x40')]&&_0x41f17d['customField']){_0x2db378[_0x41f17d[_0x81b5('0x43')]]&&_0x24bb89[_0x81b5('0x44')][_0x81b5('0x41')]({'id':_0x41f17d[_0x81b5('0x40')],'value':_0x2db378[_0x41f17d[_0x81b5('0x43')]][_0x81b5('0x32')]()});}else if(_0x41f17d[_0x81b5('0x3c')]===_0x81b5('0x45')&&_0x41f17d[_0x81b5('0x46')]&&_0x41f17d[_0x81b5('0x46')]['name']&&_0x41f17d['idField']&&_0x41f17d[_0x81b5('0x3e')]){_0x2db378[_0x41f17d[_0x81b5('0x46')][_0x81b5('0x47')][_0x81b5('0x3f')]()]&&_0x24bb89[_0x81b5('0x44')][_0x81b5('0x41')]({'id':_0x41f17d[_0x81b5('0x40')],'value':_0x2db378[_0x41f17d[_0x81b5('0x46')][_0x81b5('0x47')][_0x81b5('0x3f')]()][_0x81b5('0x32')]()});}});}return _0x24bb89;}exports[_0x81b5('0x48')]=function(_0x27dbd2,_0x2795c9,_0x3f4c34,_0x237525,_0x2ed138,_0x491ec0){var _0x4f46c2,_0x139de2;_0x491ec0['remoteUri']=intUtil[_0x81b5('0x49')](_0x491ec0['remoteUri']);_0x491ec0[_0x81b5('0x4a')]=intUtil[_0x81b5('0x49')](_0x491ec0[_0x81b5('0x4a')]);if(_0x2ed138&&_0x2ed138[_0x81b5('0x4b')]){logger[_0x81b5('0x9')]('[QUEUE]','Recording\x20is\x20enabled!');_0x2795c9[_0x81b5('0x4c')]=util[_0x81b5('0xa')](_0x81b5('0x4d'),_0x491ec0['serverUrl'],_0x2795c9[_0x81b5('0x4e')],md5(_0x2795c9[_0x81b5('0x4e')]));}else{_0x2795c9[_0x81b5('0x4c')]='';}headers[_0x81b5('0x4f')]=getAuth(_0x491ec0);return getUser(_0x491ec0,_0x237525[_0x81b5('0x50')])['then'](function(_0x2da034){_0x4f46c2=_0x2da034;logger[_0x81b5('0x9')](_0x81b5('0x51'),_0x4f46c2['id']);return getEndUser(_0x491ec0,_0x2795c9[_0x81b5('0x52')],_0x2795c9['calleridnum']);})['then'](function(_0x5b5331){_0x139de2=_0x5b5331;logger[_0x81b5('0x9')](_0x81b5('0x53'),_0x139de2['id']);return getTicket(_0x491ec0,_0x4f46c2,_0x139de2,_0x3f4c34,_0x2795c9);})[_0x81b5('0x14')](function(_0x321c1b){if(_0x321c1b){logger['info']('The\x20Ticket\x20ID\x20is:',_0x321c1b['id']);switch(_0x491ec0['type']){case _0x81b5('0x54'):logger[_0x81b5('0x9')](_0x81b5('0x55'),_0x81b5('0x56'));return request({'uri':util[_0x81b5('0xa')]('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x491ec0['remoteUri'],_0x4f46c2['id'],_0x321c1b['id']),'method':'POST'});case _0x81b5('0x57'):logger['info']('[QUEUE]',_0x81b5('0x58'));emit(util['format']('user:%s',_0x237525['name']),_0x81b5('0x59'),{'uri':util[_0x81b5('0xa')]('%s/agent/tickets/%s',_0x491ec0[_0x81b5('0xc')]['replace'](_0x81b5('0x5a'),''),_0x321c1b['id'])});break;default:logger[_0x81b5('0x5b')](_0x81b5('0x55'),_0x81b5('0x5c'));}}})[_0x81b5('0x5d')](function(_0x3d2c8f){logger['error']('[QUEUE]\x20Error\x20running\x20Zendesk\x20integration',util[_0x81b5('0x5e')](_0x3d2c8f,{'showHidden':!![],'depth':null}));});};exports[_0x81b5('0x5f')]=function(_0x53f175,_0x451df7,_0x5725ab,_0x46ca91,_0x330000,_0x3b09d4,_0x5ef622){var _0xada1cb,_0x517325;_0x3b09d4[_0x81b5('0xc')]=intUtil[_0x81b5('0x49')](_0x3b09d4[_0x81b5('0xc')]);_0x3b09d4[_0x81b5('0x4a')]=intUtil[_0x81b5('0x49')](_0x3b09d4['serverUrl']);if(_0x5ef622&&_0x5ef622['recordingFormat']&&_0x5ef622[_0x81b5('0x60')]!=='none'){logger[_0x81b5('0x9')]('[OUTBOUND]',_0x81b5('0x61'));_0x451df7[_0x81b5('0x4c')]=util[_0x81b5('0xa')](_0x81b5('0x4d'),_0x3b09d4['serverUrl'],_0x451df7['uniqueid'],md5(_0x451df7[_0x81b5('0x4e')]));}headers[_0x81b5('0x4f')]=getAuth(_0x3b09d4);return getUser(_0x3b09d4,_0x46ca91[_0x81b5('0x50')])[_0x81b5('0x14')](function(_0x5a9586){_0xada1cb=_0x5a9586;logger['info'](_0x81b5('0x51'),_0xada1cb['id']);return getEndUser(_0x3b09d4,_0x451df7[_0x81b5('0x62')],_0x451df7[_0x81b5('0x63')]);})[_0x81b5('0x14')](function(_0xbd87ae){_0x517325=_0xbd87ae;logger[_0x81b5('0x9')](_0x81b5('0x53'),_0x517325['id']);return getTicket(_0x3b09d4,_0xada1cb,_0x517325,_0x5725ab,_0x451df7);})['then'](function(_0x3c2285){if(_0x3c2285){logger[_0x81b5('0x9')](_0x81b5('0x64'),_0x3c2285['id']);switch(_0x3b09d4[_0x81b5('0x3c')]){case _0x81b5('0x54'):logger[_0x81b5('0x9')](_0x81b5('0x65'),_0x81b5('0x56'));return request({'uri':util['format'](_0x81b5('0x66'),_0x3b09d4[_0x81b5('0xc')],_0xada1cb['id'],_0x3c2285['id']),'method':_0x81b5('0xd')});case _0x81b5('0x57'):logger[_0x81b5('0x9')](_0x81b5('0x65'),_0x81b5('0x58'));emit(util['format']('user:%s',_0x46ca91[_0x81b5('0x47')]),_0x81b5('0x59'),{'uri':util[_0x81b5('0xa')](_0x81b5('0x67'),_0x3b09d4[_0x81b5('0xc')][_0x81b5('0x68')]('/api/v2',''),_0x3c2285['id'])});break;default:logger[_0x81b5('0x5b')](_0x81b5('0x65'),_0x81b5('0x5c'));}}})[_0x81b5('0x5d')](function(_0x3909c8){logger['error']('[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration',util[_0x81b5('0x5e')](_0x3909c8,{'showHidden':!![],'depth':null}));});};exports['unmanaged']=function(_0x57d61c,_0x5c364e,_0x1a9a9c,_0x53de0b,_0x5e0454,_0x34b51d){var _0xf0db4d,_0x1cb002;_0x34b51d[_0x81b5('0xc')]=intUtil[_0x81b5('0x49')](_0x34b51d['remoteUri']);_0x34b51d[_0x81b5('0x4a')]=intUtil['stripTrailingSlash'](_0x34b51d[_0x81b5('0x4a')]);if(_0x5e0454&&_0x5e0454[_0x81b5('0x4b')]){logger[_0x81b5('0x9')]('['+_0x5c364e['lastevent'][_0x81b5('0x69')]()+']',_0x81b5('0x61'));_0x5c364e['recordingURL']=util[_0x81b5('0xa')](_0x81b5('0x4d'),_0x34b51d[_0x81b5('0x4a')],_0x5c364e[_0x81b5('0x4e')],md5(_0x5c364e['uniqueid']));}else{_0x5c364e['recordingURL']='';}headers['Authorization']=getAuth(_0x34b51d);return getUser(_0x34b51d)[_0x81b5('0x14')](function(_0x3b662c){_0xf0db4d=_0x3b662c;logger[_0x81b5('0x9')](_0x81b5('0x51'),_0xf0db4d['id']);return getEndUser(_0x34b51d,_0x5c364e['calleridname'],_0x5c364e[_0x81b5('0x6a')]);})[_0x81b5('0x14')](function(_0x3e25d6){_0x1cb002=_0x3e25d6;logger[_0x81b5('0x9')]('The\x20Enduser\x20ID\x20is:',_0x1cb002['id']);return getTicket(_0x34b51d,_0xf0db4d,_0x1cb002,_0x1a9a9c,_0x5c364e);})['then'](function(_0x23a746){if(_0x23a746){logger[_0x81b5('0x9')]('The\x20Ticket\x20ID\x20is:',_0x23a746['id']);}})[_0x81b5('0x5d')](function(_0x106880){logger['error']('['+_0x5c364e[_0x81b5('0x6b')][_0x81b5('0x69')]()+']'+_0x81b5('0x6c'),util[_0x81b5('0x5e')](_0x106880,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file