Built motion from commit (unavailable).|2.5.11
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index e29eb84..8751219 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9aea=['\x20Error\x20running\x20Zendesk\x20integration','lodash','md5','ioredis','./util','../../../../config/logger','zendesk','redis','defaults','socket.io-emitter','emit','application/json','Creating\x20new\x20ticket...','%s/tickets.json','remoteUri','POST','merge','Tags','name','getString','Subjects','Descriptions','Fields','info','Ticket\x20created!','ticket','Getting\x20agent\x20with\x20email','format','count','Agent\x20found!','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','filter','first','Enduser\x20found!','%s/users.json','end-user','Caller\x20-\x20%s','password','%s:%s','username','token','%s/token:%s','Basic\x20%s','toString','base64','debug','[HTTP]','stringify','GET','map','type','nameField','toLowerCase','string','idField','customField','custom_fields','content','variable','variableName','push','customVariable','Variable','queue','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Authorization','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/agent/tickets/%s','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','inspect','outbound','stripTrailingSlash','recordingFormat','none','[OUTBOUND]','uniqueid','email','destcalleridname','destcalleridnum','The\x20Ticket\x20ID\x20is:','integrationTab','Displaying\x20ticket\x20to\x20agent...','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','unmanaged','lastevent','toUpperCase'];(function(_0x4ee9f4,_0x128afa){var _0x3cb6e8=function(_0x11629f){while(--_0x11629f){_0x4ee9f4['push'](_0x4ee9f4['shift']());}};_0x3cb6e8(++_0x128afa);}(_0x9aea,0xdd));var _0xa9ae=function(_0x5a921a,_0x4239f9){_0x5a921a=_0x5a921a-0x0;var _0x7ba25=_0x9aea[_0x5a921a];return _0x7ba25;};'use strict';var _=require(_0xa9ae('0x0'));var rp=require('request-promise');var md5=require(_0xa9ae('0x1'));var util=require('util');var Redis=require(_0xa9ae('0x2'));var intUtil=require(_0xa9ae('0x3'));var config=require('../../../../config/environment');var logger=require(_0xa9ae('0x4'))(_0xa9ae('0x5'));config[_0xa9ae('0x6')]=_[_0xa9ae('0x7')](config[_0xa9ae('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0xa9ae('0x8'))(new Redis(config[_0xa9ae('0x6')]));function emit(_0x1e57c4,_0x53e52c,_0x1f2e4b){io['to'](_0x1e57c4)[_0xa9ae('0x9')](_0x53e52c,_0x1f2e4b);}var headers={'Content-Type':_0xa9ae('0xa'),'Accept':_0xa9ae('0xa')};function getTicket(_0x1882dc,_0x2d1188,_0x1816c2,_0x337dfb,_0x2f238f){logger['info'](_0xa9ae('0xb'));return request({'uri':util['format'](_0xa9ae('0xc'),_0x1882dc[_0xa9ae('0xd')]),'method':_0xa9ae('0xe'),'body':{'ticket':_[_0xa9ae('0xf')]({'requester_id':_0x1816c2['id'],'submitter_id':_0x2d1188?_0x2d1188['id']:undefined,'assignee_id':_0x2d1188?_0x2d1188['id']:undefined,'tags':getTags(_0x337dfb[_0xa9ae('0x10')],_0xa9ae('0x11')),'subject':intUtil[_0xa9ae('0x12')](_0x337dfb[_0xa9ae('0x13')],_0x2f238f,'\x20'),'description':intUtil['getString'](_0x337dfb[_0xa9ae('0x14')],_0x2f238f,'\x0a'),'comment':{'public':![],'body':intUtil[_0xa9ae('0x12')](_0x337dfb[_0xa9ae('0x14')],_0x2f238f,'\x0a')}},getCustomFields(_0x337dfb[_0xa9ae('0x15')],_0x2f238f))}})['then'](function(_0x28ce2d){logger[_0xa9ae('0x16')](_0xa9ae('0x17'));return _0x28ce2d[_0xa9ae('0x18')];});}function getUser(_0x77b0a4,_0xddb095){if(intUtil['validateEmail'](_0xddb095)){logger[_0xa9ae('0x16')](_0xa9ae('0x19'),_0xddb095);return request({'uri':util[_0xa9ae('0x1a')]('%s/search.json',_0x77b0a4['remoteUri']),'qs':{'query':util[_0xa9ae('0x1a')]('type:user\x20role:agent\x20email:%s',_0xddb095)}})['then'](function(_0x18911b){if(_0x18911b[_0xa9ae('0x1b')]){logger[_0xa9ae('0x16')](_0xa9ae('0x1c'));return _['find'](_0x18911b[_0xa9ae('0x1d')],{'email':_0xddb095,'role':_0xa9ae('0x1e')});}else{logger[_0xa9ae('0x16')](_0xa9ae('0x1f'));return request({'uri':util[_0xa9ae('0x1a')](_0xa9ae('0x20'),_0x77b0a4[_0xa9ae('0xd')])})['then'](function(_0xc021cf){logger['info']('Admin\x20account\x20selected.');return _0xc021cf['user'];});}});}else{logger['info'](_0xa9ae('0x1f'));return request({'uri':util['format'](_0xa9ae('0x20'),_0x77b0a4['remoteUri'])})[_0xa9ae('0x21')](function(_0x38eaeb){logger[_0xa9ae('0x16')](_0xa9ae('0x22'));return _0x38eaeb[_0xa9ae('0x23')];});}}function getEndUser(_0x3f3f97,_0x23c1ec,_0x5e82f1){logger[_0xa9ae('0x16')](_0xa9ae('0x24'),_0x5e82f1);return request({'uri':util[_0xa9ae('0x1a')](_0xa9ae('0x25'),_0x3f3f97[_0xa9ae('0xd')]),'qs':{'query':util[_0xa9ae('0x1a')](_0xa9ae('0x26'),_0x5e82f1)}})['then'](function(_0x489e88){var _0x2f1a9f;if(_0x489e88[_0xa9ae('0x1d')][_0xa9ae('0x27')]){_0x489e88[_0xa9ae('0x1d')]=_[_0xa9ae('0x28')](_0x489e88['results'],{'suspended':![],'role':'end-user'});if(_0x489e88[_0xa9ae('0x1d')][_0xa9ae('0x27')]){_0x2f1a9f=_[_0xa9ae('0x29')](_0x489e88[_0xa9ae('0x1d')]);}}if(_0x2f1a9f){logger[_0xa9ae('0x16')](_0xa9ae('0x2a'));return _0x2f1a9f;}else{logger['info']('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util[_0xa9ae('0x1a')](_0xa9ae('0x2b'),_0x3f3f97[_0xa9ae('0xd')]),'method':_0xa9ae('0xe'),'body':{'user':{'role':_0xa9ae('0x2c'),'name':util[_0xa9ae('0x1a')](_0xa9ae('0x2d'),_0x23c1ec||_0x5e82f1),'phone':_0x5e82f1}}})[_0xa9ae('0x21')](function(_0x5c4f79){logger[_0xa9ae('0x16')]('Enduser\x20created.');return _0x5c4f79[_0xa9ae('0x23')];});}});}function getAuth(_0x107ef8){var _0x3a701b;if(_0x107ef8['authType']===_0xa9ae('0x2e')){_0x3a701b=util[_0xa9ae('0x1a')](_0xa9ae('0x2f'),_0x107ef8[_0xa9ae('0x30')],_0x107ef8[_0xa9ae('0x2e')]);}else if(_0x107ef8['authType']===_0xa9ae('0x31')){_0x3a701b=util[_0xa9ae('0x1a')](_0xa9ae('0x32'),_0x107ef8['username'],_0x107ef8['token']);}return util[_0xa9ae('0x1a')](_0xa9ae('0x33'),new Buffer(_0x3a701b)[_0xa9ae('0x34')](_0xa9ae('0x35')));}function request(_0x484f67){logger[_0xa9ae('0x36')](_0xa9ae('0x37'),JSON[_0xa9ae('0x38')](_0x484f67));return rp(_[_0xa9ae('0x7')](_0x484f67,{'method':_0xa9ae('0x39'),'headers':headers,'json':!![]}));}function getTags(_0x4eafaf,_0x6ca134){var _0x4b890e=[];if(_0x4eafaf&&_0x4eafaf[_0xa9ae('0x27')]>0x0){_0x4b890e=_[_0xa9ae('0x3a')](_0x4eafaf,_0x6ca134);}return _0x4b890e;}function getCustomFields(_0xc0db08,_0x57fc9d){var _0x15a8b4=[];var _0x1ffcab={'custom_fields':[]};if(_0xc0db08[_0xa9ae('0x27')]>0x0){_['forEach'](_0xc0db08,function(_0x2e0d90){if(_0x2e0d90[_0xa9ae('0x3b')]==='string'&&_0x2e0d90[_0xa9ae('0x3c')]&&!_0x2e0d90['customField']){_0x1ffcab[_0x2e0d90[_0xa9ae('0x3c')][_0xa9ae('0x3d')]()]=_0x2e0d90['content'][_0xa9ae('0x34')]();}else if(_0x2e0d90[_0xa9ae('0x3b')]===_0xa9ae('0x3e')&&_0x2e0d90[_0xa9ae('0x3f')]&&_0x2e0d90[_0xa9ae('0x40')]){_0x1ffcab[_0xa9ae('0x41')]['push']({'id':_0x2e0d90[_0xa9ae('0x3f')],'value':_0x2e0d90[_0xa9ae('0x42')]['toString']()});}else if(_0x2e0d90['type']===_0xa9ae('0x43')&&_0x2e0d90[_0xa9ae('0x44')]&&_0x2e0d90[_0xa9ae('0x3f')]&&_0x2e0d90[_0xa9ae('0x40')]){_0x57fc9d[_0x2e0d90['variableName']]&&_0x1ffcab[_0xa9ae('0x41')][_0xa9ae('0x45')]({'id':_0x2e0d90[_0xa9ae('0x3f')],'value':_0x57fc9d[_0x2e0d90[_0xa9ae('0x44')]][_0xa9ae('0x34')]()});}else if(_0x2e0d90[_0xa9ae('0x3b')]===_0xa9ae('0x46')&&_0x2e0d90['Variable']&&_0x2e0d90[_0xa9ae('0x47')][_0xa9ae('0x11')]&&_0x2e0d90['idField']&&_0x2e0d90[_0xa9ae('0x40')]){_0x57fc9d[_0x2e0d90['Variable'][_0xa9ae('0x11')][_0xa9ae('0x3d')]()]&&_0x1ffcab[_0xa9ae('0x41')][_0xa9ae('0x45')]({'id':_0x2e0d90[_0xa9ae('0x3f')],'value':_0x57fc9d[_0x2e0d90[_0xa9ae('0x47')][_0xa9ae('0x11')]['toLowerCase']()][_0xa9ae('0x34')]()});}});}return _0x1ffcab;}exports[_0xa9ae('0x48')]=function(_0x5cc0e3,_0x40f77d,_0x373a21,_0x238797,_0x275b3a,_0x6f6cde){var _0x76502d,_0x571cb4;_0x6f6cde[_0xa9ae('0xd')]=intUtil['stripTrailingSlash'](_0x6f6cde[_0xa9ae('0xd')]);_0x6f6cde[_0xa9ae('0x49')]=intUtil['stripTrailingSlash'](_0x6f6cde['serverUrl']);if(_0x275b3a&&_0x275b3a[_0xa9ae('0x4a')]){logger[_0xa9ae('0x16')](_0xa9ae('0x4b'),_0xa9ae('0x4c'));_0x40f77d[_0xa9ae('0x4d')]=util[_0xa9ae('0x1a')](_0xa9ae('0x4e'),_0x6f6cde[_0xa9ae('0x49')],_0x40f77d['uniqueid'],md5(_0x40f77d['uniqueid']));}else{_0x40f77d[_0xa9ae('0x4d')]='';}headers[_0xa9ae('0x4f')]=getAuth(_0x6f6cde);return getUser(_0x6f6cde,_0x238797['email'])[_0xa9ae('0x21')](function(_0x38f24c){_0x76502d=_0x38f24c;logger[_0xa9ae('0x16')](_0xa9ae('0x50'),_0x76502d['id']);return getEndUser(_0x6f6cde,_0x40f77d[_0xa9ae('0x51')],_0x40f77d[_0xa9ae('0x52')]);})[_0xa9ae('0x21')](function(_0x2f74bb){_0x571cb4=_0x2f74bb;logger['info'](_0xa9ae('0x53'),_0x571cb4['id']);return getTicket(_0x6f6cde,_0x76502d,_0x571cb4,_0x373a21,_0x40f77d);})[_0xa9ae('0x21')](function(_0x5ea18d){if(_0x5ea18d){logger[_0xa9ae('0x16')]('The\x20Ticket\x20ID\x20is:',_0x5ea18d['id']);switch(_0x6f6cde['type']){case'integrationTab':logger[_0xa9ae('0x16')](_0xa9ae('0x4b'),'Displaying\x20ticket\x20to\x20agent...');return request({'uri':util['format']('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x6f6cde[_0xa9ae('0xd')],_0x76502d['id'],_0x5ea18d['id']),'method':'POST'});case _0xa9ae('0x54'):logger[_0xa9ae('0x16')]('[QUEUE]',_0xa9ae('0x55'));emit(util['format'](_0xa9ae('0x56'),_0x238797[_0xa9ae('0x11')]),_0xa9ae('0x57'),{'uri':util[_0xa9ae('0x1a')](_0xa9ae('0x58'),_0x6f6cde[_0xa9ae('0xd')],_0x5ea18d['id'])});break;default:logger[_0xa9ae('0x59')](_0xa9ae('0x4b'),_0xa9ae('0x5a'));}}})[_0xa9ae('0x5b')](function(_0x22ab67){logger[_0xa9ae('0x59')]('[QUEUE]\x20Error\x20running\x20Zendesk\x20integration',util[_0xa9ae('0x5c')](_0x22ab67,{'showHidden':!![],'depth':null}));});};exports[_0xa9ae('0x5d')]=function(_0x24087a,_0x205c90,_0x7dae60,_0x59de12,_0x4fe9e7,_0x1d5607,_0x4612f1){var _0x4f1219,_0x521c8c;_0x1d5607[_0xa9ae('0xd')]=intUtil['stripTrailingSlash'](_0x1d5607[_0xa9ae('0xd')]);_0x1d5607[_0xa9ae('0x49')]=intUtil[_0xa9ae('0x5e')](_0x1d5607['serverUrl']);if(_0x4612f1&&_0x4612f1[_0xa9ae('0x5f')]&&_0x4612f1['recordingFormat']!==_0xa9ae('0x60')){logger['info'](_0xa9ae('0x61'),_0xa9ae('0x4c'));_0x205c90[_0xa9ae('0x4d')]=util[_0xa9ae('0x1a')](_0xa9ae('0x4e'),_0x1d5607[_0xa9ae('0x49')],_0x205c90['uniqueid'],md5(_0x205c90[_0xa9ae('0x62')]));}headers[_0xa9ae('0x4f')]=getAuth(_0x1d5607);return getUser(_0x1d5607,_0x59de12[_0xa9ae('0x63')])[_0xa9ae('0x21')](function(_0x5842e5){_0x4f1219=_0x5842e5;logger[_0xa9ae('0x16')](_0xa9ae('0x50'),_0x4f1219['id']);return getEndUser(_0x1d5607,_0x205c90[_0xa9ae('0x64')],_0x205c90[_0xa9ae('0x65')]);})[_0xa9ae('0x21')](function(_0x1f563a){_0x521c8c=_0x1f563a;logger[_0xa9ae('0x16')](_0xa9ae('0x53'),_0x521c8c['id']);return getTicket(_0x1d5607,_0x4f1219,_0x521c8c,_0x7dae60,_0x205c90);})[_0xa9ae('0x21')](function(_0x28756d){if(_0x28756d){logger['info'](_0xa9ae('0x66'),_0x28756d['id']);switch(_0x1d5607[_0xa9ae('0x3b')]){case _0xa9ae('0x67'):logger[_0xa9ae('0x16')]('[OUTBOUND]',_0xa9ae('0x68'));return request({'uri':util[_0xa9ae('0x1a')]('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x1d5607[_0xa9ae('0xd')],_0x4f1219['id'],_0x28756d['id']),'method':_0xa9ae('0xe')});case _0xa9ae('0x54'):logger['info']('[OUTBOUND]',_0xa9ae('0x55'));emit(util[_0xa9ae('0x1a')]('user:%s',_0x59de12['name']),_0xa9ae('0x57'),{'uri':util[_0xa9ae('0x1a')](_0xa9ae('0x58'),_0x1d5607['remoteUri'],_0x28756d['id'])});break;default:logger[_0xa9ae('0x59')](_0xa9ae('0x61'),_0xa9ae('0x5a'));}}})[_0xa9ae('0x5b')](function(_0x52127b){logger[_0xa9ae('0x59')](_0xa9ae('0x69'),util[_0xa9ae('0x5c')](_0x52127b,{'showHidden':!![],'depth':null}));});};exports[_0xa9ae('0x6a')]=function(_0x110405,_0x53445e,_0x4acac8,_0x296708,_0x1a632a,_0x2317ec){var _0x505cc6,_0x296609;_0x2317ec[_0xa9ae('0xd')]=intUtil[_0xa9ae('0x5e')](_0x2317ec['remoteUri']);_0x2317ec['serverUrl']=intUtil[_0xa9ae('0x5e')](_0x2317ec['serverUrl']);if(_0x1a632a&&_0x1a632a[_0xa9ae('0x4a')]){logger[_0xa9ae('0x16')]('['+_0x53445e[_0xa9ae('0x6b')][_0xa9ae('0x6c')]()+']',_0xa9ae('0x4c'));_0x53445e[_0xa9ae('0x4d')]=util[_0xa9ae('0x1a')](_0xa9ae('0x4e'),_0x2317ec[_0xa9ae('0x49')],_0x53445e[_0xa9ae('0x62')],md5(_0x53445e['uniqueid']));}else{_0x53445e[_0xa9ae('0x4d')]='';}headers['Authorization']=getAuth(_0x2317ec);return getUser(_0x2317ec)[_0xa9ae('0x21')](function(_0x3bca8f){_0x505cc6=_0x3bca8f;logger[_0xa9ae('0x16')](_0xa9ae('0x50'),_0x505cc6['id']);return getEndUser(_0x2317ec,_0x53445e[_0xa9ae('0x51')],_0x53445e['calleridnum']);})[_0xa9ae('0x21')](function(_0x2e9c2e){_0x296609=_0x2e9c2e;logger[_0xa9ae('0x16')](_0xa9ae('0x53'),_0x296609['id']);return getTicket(_0x2317ec,_0x505cc6,_0x296609,_0x4acac8,_0x53445e);})[_0xa9ae('0x21')](function(_0x5c02d3){if(_0x5c02d3){logger[_0xa9ae('0x16')](_0xa9ae('0x66'),_0x5c02d3['id']);}})[_0xa9ae('0x5b')](function(_0x1fad1c){logger[_0xa9ae('0x59')]('['+_0x53445e['lastevent']['toUpperCase']()+']'+_0xa9ae('0x6d'),util[_0xa9ae('0x5c')](_0x1fad1c,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xfc60=['Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','Admin\x20account\x20selected.','user','type:user\x20role:end-user\x20phone:%s','length','first','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','end-user','Caller\x20-\x20%s','authType','%s:%s','username','password','%s/token:%s','Basic\x20%s','toString','debug','[HTTP]','GET','forEach','type','nameField','toLowerCase','content','string','idField','customField','custom_fields','push','variable','variableName','Variable','queue','stripTrailingSlash','serverUrl','monitor_format','Recording\x20is\x20enabled!','recordingURL','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','email','The\x20User\x20ID\x20is:','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','[QUEUE]','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','replace','/api/v2','error','Zendesk\x20account\x20type\x20not\x20recognized','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','recordingFormat','[OUTBOUND]','destcalleridname','destcalleridnum','integrationTab','Displaying\x20ticket\x20to\x20agent...','%s/agent/tickets/%s','catch','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','inspect','unmanaged','calleridname','toUpperCase','\x20Error\x20running\x20Zendesk\x20integration','lodash','request-promise','util','ioredis','./util','../../../../config/logger','zendesk','defaults','redis','localhost','socket.io-emitter','emit','application/json','info','Creating\x20new\x20ticket...','format','%s/tickets.json','POST','name','getString','Subjects','Descriptions','Fields','then','Ticket\x20created!','validateEmail','Getting\x20agent\x20with\x20email','%s/search.json','remoteUri','count','Agent\x20found!','find','results'];(function(_0x1efe03,_0x55b566){var _0x30060c=function(_0x2fc6a6){while(--_0x2fc6a6){_0x1efe03['push'](_0x1efe03['shift']());}};_0x30060c(++_0x55b566);}(_0xfc60,0xb3));var _0x0fc6=function(_0x4e5b7c,_0x291c10){_0x4e5b7c=_0x4e5b7c-0x0;var _0x2c89af=_0xfc60[_0x4e5b7c];return _0x2c89af;};'use strict';var _=require(_0x0fc6('0x0'));var rp=require(_0x0fc6('0x1'));var md5=require('md5');var util=require(_0x0fc6('0x2'));var Redis=require(_0x0fc6('0x3'));var intUtil=require(_0x0fc6('0x4'));var config=require('../../../../config/environment');var logger=require(_0x0fc6('0x5'))(_0x0fc6('0x6'));config['redis']=_[_0x0fc6('0x7')](config[_0x0fc6('0x8')],{'host':_0x0fc6('0x9'),'port':0x18eb});var io=require(_0x0fc6('0xa'))(new Redis(config['redis']));function emit(_0x5e4bb7,_0x12db30,_0x292ee9){io['to'](_0x5e4bb7)[_0x0fc6('0xb')](_0x12db30,_0x292ee9);}var headers={'Content-Type':_0x0fc6('0xc'),'Accept':'application/json'};function getTicket(_0x3768f9,_0x60ef83,_0x2dccf1,_0x53e321,_0x18696c){logger[_0x0fc6('0xd')](_0x0fc6('0xe'));return request({'uri':util[_0x0fc6('0xf')](_0x0fc6('0x10'),_0x3768f9['remoteUri']),'method':_0x0fc6('0x11'),'body':{'ticket':_['merge']({'requester_id':_0x2dccf1['id'],'submitter_id':_0x60ef83?_0x60ef83['id']:undefined,'assignee_id':_0x60ef83?_0x60ef83['id']:undefined,'tags':getTags(_0x53e321['Tags'],_0x0fc6('0x12')),'subject':intUtil[_0x0fc6('0x13')](_0x53e321[_0x0fc6('0x14')],_0x18696c,'\x20'),'description':intUtil[_0x0fc6('0x13')](_0x53e321[_0x0fc6('0x15')],_0x18696c,'\x0a'),'comment':{'public':![],'body':intUtil[_0x0fc6('0x13')](_0x53e321['Descriptions'],_0x18696c,'\x0a')}},getCustomFields(_0x53e321[_0x0fc6('0x16')],_0x18696c))}})[_0x0fc6('0x17')](function(_0x12ee6d){logger[_0x0fc6('0xd')](_0x0fc6('0x18'));return _0x12ee6d['ticket'];});}function getUser(_0x1cf7fc,_0x15e2fb){if(intUtil[_0x0fc6('0x19')](_0x15e2fb)){logger['info'](_0x0fc6('0x1a'),_0x15e2fb);return request({'uri':util['format'](_0x0fc6('0x1b'),_0x1cf7fc[_0x0fc6('0x1c')]),'qs':{'query':util[_0x0fc6('0xf')]('type:user\x20role:agent\x20email:%s',_0x15e2fb)}})[_0x0fc6('0x17')](function(_0x36f029){if(_0x36f029[_0x0fc6('0x1d')]){logger[_0x0fc6('0xd')](_0x0fc6('0x1e'));return _[_0x0fc6('0x1f')](_0x36f029[_0x0fc6('0x20')],{'email':_0x15e2fb,'role':'agent'});}else{logger['info'](_0x0fc6('0x21'));return request({'uri':util[_0x0fc6('0xf')](_0x0fc6('0x22'),_0x1cf7fc['remoteUri'])})[_0x0fc6('0x17')](function(_0x1a6bbe){logger['info'](_0x0fc6('0x23'));return _0x1a6bbe[_0x0fc6('0x24')];});}});}else{logger[_0x0fc6('0xd')](_0x0fc6('0x21'));return request({'uri':util['format']('%s/users/me.json',_0x1cf7fc[_0x0fc6('0x1c')])})[_0x0fc6('0x17')](function(_0x26662d){logger['info']('Admin\x20account\x20selected.');return _0x26662d[_0x0fc6('0x24')];});}}function getEndUser(_0x349b0b,_0x3476be,_0xbb8b47){logger[_0x0fc6('0xd')]('Searching\x20enduser\x20with\x20phone',_0xbb8b47);return request({'uri':util['format'](_0x0fc6('0x1b'),_0x349b0b[_0x0fc6('0x1c')]),'qs':{'query':util[_0x0fc6('0xf')](_0x0fc6('0x25'),_0xbb8b47)}})[_0x0fc6('0x17')](function(_0x3517ee){var _0x5f4f8c;if(_0x3517ee[_0x0fc6('0x20')][_0x0fc6('0x26')]){_0x3517ee['results']=_['filter'](_0x3517ee['results'],{'suspended':![],'role':'end-user'});if(_0x3517ee['results'][_0x0fc6('0x26')]){_0x5f4f8c=_[_0x0fc6('0x27')](_0x3517ee[_0x0fc6('0x20')]);}}if(_0x5f4f8c){logger[_0x0fc6('0xd')](_0x0fc6('0x28'));return _0x5f4f8c;}else{logger['info'](_0x0fc6('0x29'));return request({'uri':util[_0x0fc6('0xf')](_0x0fc6('0x2a'),_0x349b0b['remoteUri']),'method':_0x0fc6('0x11'),'body':{'user':{'role':_0x0fc6('0x2b'),'name':util['format'](_0x0fc6('0x2c'),_0x3476be||_0xbb8b47),'phone':_0xbb8b47}}})['then'](function(_0x1a1376){logger[_0x0fc6('0xd')]('Enduser\x20created.');return _0x1a1376[_0x0fc6('0x24')];});}});}function getAuth(_0x2146d6){var _0x53be41;if(_0x2146d6[_0x0fc6('0x2d')]==='password'){_0x53be41=util[_0x0fc6('0xf')](_0x0fc6('0x2e'),_0x2146d6[_0x0fc6('0x2f')],_0x2146d6[_0x0fc6('0x30')]);}else if(_0x2146d6[_0x0fc6('0x2d')]==='token'){_0x53be41=util[_0x0fc6('0xf')](_0x0fc6('0x31'),_0x2146d6['username'],_0x2146d6['token']);}return util[_0x0fc6('0xf')](_0x0fc6('0x32'),new Buffer(_0x53be41)[_0x0fc6('0x33')]('base64'));}function request(_0x4bb4fb){logger[_0x0fc6('0x34')](_0x0fc6('0x35'),JSON['stringify'](_0x4bb4fb));return rp(_[_0x0fc6('0x7')](_0x4bb4fb,{'method':_0x0fc6('0x36'),'headers':headers,'json':!![]}));}function getTags(_0x23f736,_0x545e9f){var _0x3129be=[];if(_0x23f736&&_0x23f736[_0x0fc6('0x26')]>0x0){_0x3129be=_['map'](_0x23f736,_0x545e9f);}return _0x3129be;}function getCustomFields(_0x5186e6,_0x4b5f30){var _0x5e87f7=[];var _0xb1c059={'custom_fields':[]};if(_0x5186e6['length']>0x0){_[_0x0fc6('0x37')](_0x5186e6,function(_0x207103){if(_0x207103[_0x0fc6('0x38')]==='string'&&_0x207103[_0x0fc6('0x39')]&&!_0x207103['customField']){_0xb1c059[_0x207103[_0x0fc6('0x39')][_0x0fc6('0x3a')]()]=_0x207103[_0x0fc6('0x3b')]['toString']();}else if(_0x207103['type']===_0x0fc6('0x3c')&&_0x207103[_0x0fc6('0x3d')]&&_0x207103[_0x0fc6('0x3e')]){_0xb1c059[_0x0fc6('0x3f')][_0x0fc6('0x40')]({'id':_0x207103[_0x0fc6('0x3d')],'value':_0x207103[_0x0fc6('0x3b')][_0x0fc6('0x33')]()});}else if(_0x207103['type']===_0x0fc6('0x41')&&_0x207103['variableName']&&_0x207103['idField']&&_0x207103[_0x0fc6('0x3e')]){_0x4b5f30[_0x207103[_0x0fc6('0x42')]]&&_0xb1c059[_0x0fc6('0x3f')][_0x0fc6('0x40')]({'id':_0x207103[_0x0fc6('0x3d')],'value':_0x4b5f30[_0x207103['variableName']]['toString']()});}else if(_0x207103[_0x0fc6('0x38')]==='customVariable'&&_0x207103[_0x0fc6('0x43')]&&_0x207103['Variable']['name']&&_0x207103[_0x0fc6('0x3d')]&&_0x207103[_0x0fc6('0x3e')]){_0x4b5f30[_0x207103[_0x0fc6('0x43')][_0x0fc6('0x12')][_0x0fc6('0x3a')]()]&&_0xb1c059['custom_fields'][_0x0fc6('0x40')]({'id':_0x207103[_0x0fc6('0x3d')],'value':_0x4b5f30[_0x207103[_0x0fc6('0x43')][_0x0fc6('0x12')][_0x0fc6('0x3a')]()]['toString']()});}});}return _0xb1c059;}exports[_0x0fc6('0x44')]=function(_0x73a7b0,_0x4222dc,_0x79384d,_0xd19de5,_0x237a56,_0x5e7e79){var _0x2da81e,_0x2746b8;_0x5e7e79[_0x0fc6('0x1c')]=intUtil[_0x0fc6('0x45')](_0x5e7e79['remoteUri']);_0x5e7e79[_0x0fc6('0x46')]=intUtil[_0x0fc6('0x45')](_0x5e7e79[_0x0fc6('0x46')]);if(_0x237a56&&_0x237a56[_0x0fc6('0x47')]){logger['info']('[QUEUE]',_0x0fc6('0x48'));_0x4222dc[_0x0fc6('0x49')]=util[_0x0fc6('0xf')](_0x0fc6('0x4a'),_0x5e7e79[_0x0fc6('0x46')],_0x4222dc[_0x0fc6('0x4b')],md5(_0x4222dc[_0x0fc6('0x4b')]));}else{_0x4222dc[_0x0fc6('0x49')]='';}headers[_0x0fc6('0x4c')]=getAuth(_0x5e7e79);return getUser(_0x5e7e79,_0xd19de5[_0x0fc6('0x4d')])['then'](function(_0xc20e7){_0x2da81e=_0xc20e7;logger[_0x0fc6('0xd')](_0x0fc6('0x4e'),_0x2da81e['id']);return getEndUser(_0x5e7e79,_0x4222dc['calleridname'],_0x4222dc[_0x0fc6('0x4f')]);})['then'](function(_0x42f526){_0x2746b8=_0x42f526;logger[_0x0fc6('0xd')](_0x0fc6('0x50'),_0x2746b8['id']);return getTicket(_0x5e7e79,_0x2da81e,_0x2746b8,_0x79384d,_0x4222dc);})[_0x0fc6('0x17')](function(_0x571ed6){if(_0x571ed6){logger[_0x0fc6('0xd')](_0x0fc6('0x51'),_0x571ed6['id']);switch(_0x5e7e79[_0x0fc6('0x38')]){case'integrationTab':logger[_0x0fc6('0xd')](_0x0fc6('0x52'),'Displaying\x20ticket\x20to\x20agent...');return request({'uri':util[_0x0fc6('0xf')](_0x0fc6('0x53'),_0x5e7e79[_0x0fc6('0x1c')],_0x2da81e['id'],_0x571ed6['id']),'method':'POST'});case _0x0fc6('0x54'):logger[_0x0fc6('0xd')](_0x0fc6('0x52'),_0x0fc6('0x55'));emit(util[_0x0fc6('0xf')]('user:%s',_0xd19de5[_0x0fc6('0x12')]),_0x0fc6('0x56'),{'uri':util[_0x0fc6('0xf')]('%s/agent/tickets/%s',_0x5e7e79['remoteUri'][_0x0fc6('0x57')](_0x0fc6('0x58'),''),_0x571ed6['id'])});break;default:logger[_0x0fc6('0x59')](_0x0fc6('0x52'),_0x0fc6('0x5a'));}}})['catch'](function(_0x3122aa){logger[_0x0fc6('0x59')](_0x0fc6('0x5b'),util['inspect'](_0x3122aa,{'showHidden':!![],'depth':null}));});};exports['outbound']=function(_0x471654,_0x4f1d56,_0x483cb5,_0x11c2de,_0x385315,_0x5d20b8,_0x2f82c6){var _0x391142,_0x50c64;_0x5d20b8['remoteUri']=intUtil[_0x0fc6('0x45')](_0x5d20b8[_0x0fc6('0x1c')]);_0x5d20b8[_0x0fc6('0x46')]=intUtil[_0x0fc6('0x45')](_0x5d20b8['serverUrl']);if(_0x2f82c6&&_0x2f82c6[_0x0fc6('0x5c')]&&_0x2f82c6[_0x0fc6('0x5c')]!=='none'){logger[_0x0fc6('0xd')](_0x0fc6('0x5d'),_0x0fc6('0x48'));_0x4f1d56[_0x0fc6('0x49')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x5d20b8[_0x0fc6('0x46')],_0x4f1d56[_0x0fc6('0x4b')],md5(_0x4f1d56[_0x0fc6('0x4b')]));}headers[_0x0fc6('0x4c')]=getAuth(_0x5d20b8);return getUser(_0x5d20b8,_0x11c2de['email'])[_0x0fc6('0x17')](function(_0x1fe327){_0x391142=_0x1fe327;logger[_0x0fc6('0xd')](_0x0fc6('0x4e'),_0x391142['id']);return getEndUser(_0x5d20b8,_0x4f1d56[_0x0fc6('0x5e')],_0x4f1d56[_0x0fc6('0x5f')]);})['then'](function(_0x52c2af){_0x50c64=_0x52c2af;logger[_0x0fc6('0xd')](_0x0fc6('0x50'),_0x50c64['id']);return getTicket(_0x5d20b8,_0x391142,_0x50c64,_0x483cb5,_0x4f1d56);})['then'](function(_0x3ba43f){if(_0x3ba43f){logger[_0x0fc6('0xd')](_0x0fc6('0x51'),_0x3ba43f['id']);switch(_0x5d20b8['type']){case _0x0fc6('0x60'):logger[_0x0fc6('0xd')](_0x0fc6('0x5d'),_0x0fc6('0x61'));return request({'uri':util[_0x0fc6('0xf')](_0x0fc6('0x53'),_0x5d20b8['remoteUri'],_0x391142['id'],_0x3ba43f['id']),'method':'POST'});case _0x0fc6('0x54'):logger[_0x0fc6('0xd')](_0x0fc6('0x5d'),_0x0fc6('0x55'));emit(util[_0x0fc6('0xf')]('user:%s',_0x11c2de[_0x0fc6('0x12')]),_0x0fc6('0x56'),{'uri':util['format'](_0x0fc6('0x62'),_0x5d20b8[_0x0fc6('0x1c')][_0x0fc6('0x57')](_0x0fc6('0x58'),''),_0x3ba43f['id'])});break;default:logger[_0x0fc6('0x59')](_0x0fc6('0x5d'),_0x0fc6('0x5a'));}}})[_0x0fc6('0x63')](function(_0x508f66){logger[_0x0fc6('0x59')](_0x0fc6('0x64'),util[_0x0fc6('0x65')](_0x508f66,{'showHidden':!![],'depth':null}));});};exports[_0x0fc6('0x66')]=function(_0x410f37,_0x84e299,_0x1d6d83,_0x2cf1bb,_0x516432,_0x14983e){var _0x36d6ea,_0x5ece02;_0x14983e[_0x0fc6('0x1c')]=intUtil['stripTrailingSlash'](_0x14983e[_0x0fc6('0x1c')]);_0x14983e['serverUrl']=intUtil['stripTrailingSlash'](_0x14983e[_0x0fc6('0x46')]);if(_0x516432&&_0x516432[_0x0fc6('0x47')]){logger[_0x0fc6('0xd')]('['+_0x84e299['lastevent']['toUpperCase']()+']',_0x0fc6('0x48'));_0x84e299[_0x0fc6('0x49')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x14983e['serverUrl'],_0x84e299[_0x0fc6('0x4b')],md5(_0x84e299[_0x0fc6('0x4b')]));}else{_0x84e299['recordingURL']='';}headers[_0x0fc6('0x4c')]=getAuth(_0x14983e);return getUser(_0x14983e)[_0x0fc6('0x17')](function(_0x1a03f5){_0x36d6ea=_0x1a03f5;logger[_0x0fc6('0xd')](_0x0fc6('0x4e'),_0x36d6ea['id']);return getEndUser(_0x14983e,_0x84e299[_0x0fc6('0x67')],_0x84e299[_0x0fc6('0x4f')]);})[_0x0fc6('0x17')](function(_0x152663){_0x5ece02=_0x152663;logger[_0x0fc6('0xd')]('The\x20Enduser\x20ID\x20is:',_0x5ece02['id']);return getTicket(_0x14983e,_0x36d6ea,_0x5ece02,_0x1d6d83,_0x84e299);})['then'](function(_0x566300){if(_0x566300){logger['info'](_0x0fc6('0x51'),_0x566300['id']);}})[_0x0fc6('0x63')](function(_0x6d261a){logger[_0x0fc6('0x59')]('['+_0x84e299['lastevent'][_0x0fc6('0x68')]()+']'+_0x0fc6('0x69'),util[_0x0fc6('0x65')](_0x6d261a,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file