Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index ebbaff5..823d0af 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf118=['integrationTab','[QUEUE]','Displaying\x20ticket\x20to\x20agent...','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/agent/tickets/%s','replace','/api/v2','error','Zendesk\x20account\x20type\x20not\x20recognized','catch','inspect','outbound','recordingFormat','none','[OUTBOUND]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Authorization','%s/channels/voice/agents/%d/tickets/%d/display.json','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','unmanaged','lastevent','toUpperCase','lodash','md5','util','ioredis','./util','../../../../config/environment','zendesk','redis','socket.io-emitter','application/json','info','Creating\x20new\x20ticket...','%s/tickets.json','remoteUri','Tags','name','getString','Descriptions','Fields','then','ticket','validateEmail','Getting\x20agent\x20with\x20email','format','%s/search.json','count','Agent\x20found!','find','results','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','type:user\x20role:end-user\x20phone:%s','end-user','Enduser\x20found!','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/users.json','POST','authType','password','%s:%s','token','%s/token:%s','username','Basic\x20%s','toString','base64','[HTTP]','stringify','GET','length','map','forEach','string','type','nameField','customField','toLowerCase','picklist','push','idField','variable','variableName','customVariable','Variable','queue','stripTrailingSlash','serverUrl','monitor_format','recordingURL','uniqueid','email','The\x20User\x20ID\x20is:','calleridname','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:'];(function(_0x4145ce,_0x3956f0){var _0x2d7580=function(_0x4fc0dc){while(--_0x4fc0dc){_0x4145ce['push'](_0x4145ce['shift']());}};_0x2d7580(++_0x3956f0);}(_0xf118,0x155));var _0x8f11=function(_0x5538d5,_0x190032){_0x5538d5=_0x5538d5-0x0;var _0x323b1a=_0xf118[_0x5538d5];return _0x323b1a;};'use strict';var _=require(_0x8f11('0x0'));var rp=require('request-promise');var md5=require(_0x8f11('0x1'));var util=require(_0x8f11('0x2'));var Redis=require(_0x8f11('0x3'));var intUtil=require(_0x8f11('0x4'));var config=require(_0x8f11('0x5'));var logger=require('../../../../config/logger')(_0x8f11('0x6'));config[_0x8f11('0x7')]=_['defaults'](config[_0x8f11('0x7')],{'host':'localhost','port':0x18eb});var io=require(_0x8f11('0x8'))(new Redis(config[_0x8f11('0x7')]));function emit(_0x3a7262,_0x29922c,_0x325342){io['to'](_0x3a7262)['emit'](_0x29922c,_0x325342);}var headers={'Content-Type':_0x8f11('0x9'),'Accept':_0x8f11('0x9')};function getTicket(_0x5d7ca3,_0x39bc58,_0x4f1187,_0x2085b4,_0x28c6d6){logger[_0x8f11('0xa')](_0x8f11('0xb'));return request({'uri':util['format'](_0x8f11('0xc'),_0x5d7ca3[_0x8f11('0xd')]),'method':'POST','body':{'ticket':_['merge']({'requester_id':_0x4f1187['id'],'submitter_id':_0x39bc58?_0x39bc58['id']:undefined,'assignee_id':_0x39bc58?_0x39bc58['id']:undefined,'tags':getTags(_0x2085b4[_0x8f11('0xe')],_0x8f11('0xf')),'subject':intUtil[_0x8f11('0x10')](_0x2085b4['Subjects'],_0x28c6d6,'\x20'),'description':intUtil[_0x8f11('0x10')](_0x2085b4[_0x8f11('0x11')],_0x28c6d6,'\x0a'),'comment':{'public':![],'body':intUtil[_0x8f11('0x10')](_0x2085b4[_0x8f11('0x11')],_0x28c6d6,'\x0a')}},getCustomFields(_0x2085b4[_0x8f11('0x12')],_0x28c6d6))}})[_0x8f11('0x13')](function(_0x2666cb){logger[_0x8f11('0xa')]('Ticket\x20created!');return _0x2666cb[_0x8f11('0x14')];});}function getUser(_0x10ffd5,_0x56c1b0){if(intUtil[_0x8f11('0x15')](_0x56c1b0)){logger[_0x8f11('0xa')](_0x8f11('0x16'),_0x56c1b0);return request({'uri':util[_0x8f11('0x17')](_0x8f11('0x18'),_0x10ffd5[_0x8f11('0xd')]),'qs':{'query':util[_0x8f11('0x17')]('type:user\x20role:agent\x20email:%s',_0x56c1b0)}})[_0x8f11('0x13')](function(_0x121b96){if(_0x121b96[_0x8f11('0x19')]){logger[_0x8f11('0xa')](_0x8f11('0x1a'));return _[_0x8f11('0x1b')](_0x121b96[_0x8f11('0x1c')],{'email':_0x56c1b0,'role':'agent'});}else{logger[_0x8f11('0xa')](_0x8f11('0x1d'));return request({'uri':util['format'](_0x8f11('0x1e'),_0x10ffd5[_0x8f11('0xd')])})[_0x8f11('0x13')](function(_0x41e1a0){logger[_0x8f11('0xa')](_0x8f11('0x1f'));return _0x41e1a0[_0x8f11('0x20')];});}});}else{logger[_0x8f11('0xa')](_0x8f11('0x1d'));return request({'uri':util[_0x8f11('0x17')](_0x8f11('0x1e'),_0x10ffd5[_0x8f11('0xd')])})['then'](function(_0x395ab3){logger[_0x8f11('0xa')](_0x8f11('0x1f'));return _0x395ab3['user'];});}}function getEndUser(_0x297bb0,_0x9f5cad,_0x5cc422){logger[_0x8f11('0xa')](_0x8f11('0x21'),_0x5cc422);return request({'uri':util['format'](_0x8f11('0x18'),_0x297bb0[_0x8f11('0xd')]),'qs':{'query':util[_0x8f11('0x17')](_0x8f11('0x22'),_0x5cc422)}})[_0x8f11('0x13')](function(_0x25fe3d){var _0x13fb5c;if(_0x25fe3d[_0x8f11('0x1c')]['length']){_0x25fe3d[_0x8f11('0x1c')]=_['filter'](_0x25fe3d[_0x8f11('0x1c')],{'suspended':![],'role':_0x8f11('0x23')});if(_0x25fe3d['results']['length']){_0x13fb5c=_['first'](_0x25fe3d[_0x8f11('0x1c')]);}}if(_0x13fb5c){logger[_0x8f11('0xa')](_0x8f11('0x24'));return _0x13fb5c;}else{logger[_0x8f11('0xa')](_0x8f11('0x25'));return request({'uri':util[_0x8f11('0x17')](_0x8f11('0x26'),_0x297bb0[_0x8f11('0xd')]),'method':_0x8f11('0x27'),'body':{'user':{'role':'end-user','name':util[_0x8f11('0x17')]('Caller\x20-\x20%s',_0x9f5cad||_0x5cc422),'phone':_0x5cc422}}})[_0x8f11('0x13')](function(_0x53e34c){logger[_0x8f11('0xa')]('Enduser\x20created.');return _0x53e34c['user'];});}});}function getAuth(_0xba04b3){var _0x2cb1c9;if(_0xba04b3[_0x8f11('0x28')]===_0x8f11('0x29')){_0x2cb1c9=util[_0x8f11('0x17')](_0x8f11('0x2a'),_0xba04b3['username'],_0xba04b3[_0x8f11('0x29')]);}else if(_0xba04b3[_0x8f11('0x28')]===_0x8f11('0x2b')){_0x2cb1c9=util[_0x8f11('0x17')](_0x8f11('0x2c'),_0xba04b3[_0x8f11('0x2d')],_0xba04b3['token']);}return util[_0x8f11('0x17')](_0x8f11('0x2e'),new Buffer(_0x2cb1c9)[_0x8f11('0x2f')](_0x8f11('0x30')));}function request(_0x4ecdce){logger['debug'](_0x8f11('0x31'),JSON[_0x8f11('0x32')](_0x4ecdce));return rp(_['defaults'](_0x4ecdce,{'method':_0x8f11('0x33'),'headers':headers,'json':!![]}));}function getTags(_0x1ace5e,_0x3b91d5){var _0x53893e=[];if(_0x1ace5e&&_0x1ace5e[_0x8f11('0x34')]>0x0){_0x53893e=_[_0x8f11('0x35')](_0x1ace5e,_0x3b91d5);}return _0x53893e;}function getCustomFields(_0x5874bf,_0x28e5f4){var _0xe1b2c0=[];var _0x5381f4={'custom_fields':[]};if(_0x5874bf[_0x8f11('0x34')]>0x0){_[_0x8f11('0x36')](_0x5874bf,function(_0x7d80f3){if(_['includes']([_0x8f11('0x37'),'picklist'],_0x7d80f3[_0x8f11('0x38')])&&_0x7d80f3[_0x8f11('0x39')]&&!_0x7d80f3[_0x8f11('0x3a')]){_0x5381f4[_0x7d80f3[_0x8f11('0x39')][_0x8f11('0x3b')]()]=_0x7d80f3['content'][_0x8f11('0x2f')]();}else if(_['includes']([_0x8f11('0x37'),_0x8f11('0x3c')],_0x7d80f3[_0x8f11('0x38')])&&_0x7d80f3['idField']&&_0x7d80f3[_0x8f11('0x3a')]){_0x5381f4['custom_fields'][_0x8f11('0x3d')]({'id':_0x7d80f3[_0x8f11('0x3e')],'value':_0x7d80f3['content'][_0x8f11('0x2f')]()});}else if(_0x7d80f3[_0x8f11('0x38')]===_0x8f11('0x3f')&&_0x7d80f3[_0x8f11('0x40')]&&_0x7d80f3[_0x8f11('0x3e')]&&_0x7d80f3[_0x8f11('0x3a')]){_0x28e5f4[_0x7d80f3[_0x8f11('0x40')]]&&_0x5381f4['custom_fields'][_0x8f11('0x3d')]({'id':_0x7d80f3[_0x8f11('0x3e')],'value':_0x28e5f4[_0x7d80f3[_0x8f11('0x40')]][_0x8f11('0x2f')]()});}else if(_0x7d80f3[_0x8f11('0x38')]===_0x8f11('0x41')&&_0x7d80f3[_0x8f11('0x42')]&&_0x7d80f3[_0x8f11('0x42')]['name']&&_0x7d80f3[_0x8f11('0x3e')]&&_0x7d80f3['customField']){_0x28e5f4[_0x7d80f3[_0x8f11('0x42')][_0x8f11('0xf')][_0x8f11('0x3b')]()]&&_0x5381f4['custom_fields'][_0x8f11('0x3d')]({'id':_0x7d80f3[_0x8f11('0x3e')],'value':_0x28e5f4[_0x7d80f3[_0x8f11('0x42')]['name'][_0x8f11('0x3b')]()][_0x8f11('0x2f')]()});}});}return _0x5381f4;}exports[_0x8f11('0x43')]=function(_0x528b15,_0x466ec6,_0x3be31e,_0x393095,_0x29183f,_0x538ca9){var _0x4df791,_0x22f3e3;_0x538ca9[_0x8f11('0xd')]=intUtil[_0x8f11('0x44')](_0x538ca9[_0x8f11('0xd')]);_0x538ca9[_0x8f11('0x45')]=intUtil['stripTrailingSlash'](_0x538ca9[_0x8f11('0x45')]);if(_0x29183f&&_0x29183f[_0x8f11('0x46')]){logger[_0x8f11('0xa')]('[QUEUE]','Recording\x20is\x20enabled!');_0x466ec6[_0x8f11('0x47')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x538ca9[_0x8f11('0x45')],_0x466ec6[_0x8f11('0x48')],md5(_0x466ec6[_0x8f11('0x48')]));}else{_0x466ec6[_0x8f11('0x47')]='';}headers['Authorization']=getAuth(_0x538ca9);return getUser(_0x538ca9,_0x393095[_0x8f11('0x49')])[_0x8f11('0x13')](function(_0x4a67e8){_0x4df791=_0x4a67e8;logger[_0x8f11('0xa')](_0x8f11('0x4a'),_0x4df791['id']);return getEndUser(_0x538ca9,_0x466ec6[_0x8f11('0x4b')],_0x466ec6[_0x8f11('0x4c')]);})['then'](function(_0x5a6f54){_0x22f3e3=_0x5a6f54;logger[_0x8f11('0xa')](_0x8f11('0x4d'),_0x22f3e3['id']);return getTicket(_0x538ca9,_0x4df791,_0x22f3e3,_0x3be31e,_0x466ec6);})[_0x8f11('0x13')](function(_0x49b9d9){if(_0x49b9d9){logger[_0x8f11('0xa')](_0x8f11('0x4e'),_0x49b9d9['id']);switch(_0x538ca9[_0x8f11('0x38')]){case _0x8f11('0x4f'):logger[_0x8f11('0xa')](_0x8f11('0x50'),_0x8f11('0x51'));return request({'uri':util[_0x8f11('0x17')]('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x538ca9[_0x8f11('0xd')],_0x4df791['id'],_0x49b9d9['id']),'method':_0x8f11('0x27')});case _0x8f11('0x52'):logger['info'](_0x8f11('0x50'),_0x8f11('0x53'));emit(util[_0x8f11('0x17')](_0x8f11('0x54'),_0x393095[_0x8f11('0xf')]),_0x8f11('0x55'),{'uri':util[_0x8f11('0x17')](_0x8f11('0x56'),_0x538ca9[_0x8f11('0xd')][_0x8f11('0x57')](_0x8f11('0x58'),''),_0x49b9d9['id'])});break;default:logger[_0x8f11('0x59')](_0x8f11('0x50'),_0x8f11('0x5a'));}}})[_0x8f11('0x5b')](function(_0x13c932){logger[_0x8f11('0x59')]('[QUEUE]\x20Error\x20running\x20Zendesk\x20integration',util[_0x8f11('0x5c')](_0x13c932,{'showHidden':!![],'depth':null}));});};exports[_0x8f11('0x5d')]=function(_0x544765,_0x4dca46,_0xfb5cbd,_0x4472c5,_0x15d629,_0x195f9b,_0x348833){var _0x47c3a0,_0x573aac;_0x195f9b[_0x8f11('0xd')]=intUtil[_0x8f11('0x44')](_0x195f9b[_0x8f11('0xd')]);_0x195f9b[_0x8f11('0x45')]=intUtil['stripTrailingSlash'](_0x195f9b[_0x8f11('0x45')]);if(_0x348833&&_0x348833[_0x8f11('0x5e')]&&_0x348833[_0x8f11('0x5e')]!==_0x8f11('0x5f')){logger['info'](_0x8f11('0x60'),_0x8f11('0x61'));_0x4dca46['recordingURL']=util[_0x8f11('0x17')](_0x8f11('0x62'),_0x195f9b[_0x8f11('0x45')],_0x4dca46[_0x8f11('0x48')],md5(_0x4dca46[_0x8f11('0x48')]));}headers[_0x8f11('0x63')]=getAuth(_0x195f9b);return getUser(_0x195f9b,_0x4472c5[_0x8f11('0x49')])[_0x8f11('0x13')](function(_0x3d911f){_0x47c3a0=_0x3d911f;logger[_0x8f11('0xa')](_0x8f11('0x4a'),_0x47c3a0['id']);return getEndUser(_0x195f9b,_0x4dca46['destcalleridname'],_0x4dca46['destcalleridnum']);})[_0x8f11('0x13')](function(_0x1485c0){_0x573aac=_0x1485c0;logger[_0x8f11('0xa')](_0x8f11('0x4d'),_0x573aac['id']);return getTicket(_0x195f9b,_0x47c3a0,_0x573aac,_0xfb5cbd,_0x4dca46);})[_0x8f11('0x13')](function(_0xd7e379){if(_0xd7e379){logger[_0x8f11('0xa')](_0x8f11('0x4e'),_0xd7e379['id']);switch(_0x195f9b['type']){case'integrationTab':logger[_0x8f11('0xa')](_0x8f11('0x60'),_0x8f11('0x51'));return request({'uri':util['format'](_0x8f11('0x64'),_0x195f9b[_0x8f11('0xd')],_0x47c3a0['id'],_0xd7e379['id']),'method':_0x8f11('0x27')});case'newTab':logger[_0x8f11('0xa')]('[OUTBOUND]',_0x8f11('0x53'));emit(util['format'](_0x8f11('0x54'),_0x4472c5[_0x8f11('0xf')]),_0x8f11('0x55'),{'uri':util[_0x8f11('0x17')]('%s/agent/tickets/%s',_0x195f9b[_0x8f11('0xd')][_0x8f11('0x57')]('/api/v2',''),_0xd7e379['id'])});break;default:logger[_0x8f11('0x59')](_0x8f11('0x60'),_0x8f11('0x5a'));}}})['catch'](function(_0x19449e){logger[_0x8f11('0x59')](_0x8f11('0x65'),util[_0x8f11('0x5c')](_0x19449e,{'showHidden':!![],'depth':null}));});};exports[_0x8f11('0x66')]=function(_0x1b5235,_0x3ec4a9,_0x190ad2,_0x4e23de,_0x1729aa,_0x12953a){var _0x2d8b97,_0x263b40;_0x12953a[_0x8f11('0xd')]=intUtil[_0x8f11('0x44')](_0x12953a[_0x8f11('0xd')]);_0x12953a[_0x8f11('0x45')]=intUtil[_0x8f11('0x44')](_0x12953a['serverUrl']);if(_0x1729aa&&_0x1729aa[_0x8f11('0x46')]){logger[_0x8f11('0xa')]('['+_0x3ec4a9[_0x8f11('0x67')][_0x8f11('0x68')]()+']','Recording\x20is\x20enabled!');_0x3ec4a9[_0x8f11('0x47')]=util[_0x8f11('0x17')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x12953a[_0x8f11('0x45')],_0x3ec4a9[_0x8f11('0x48')],md5(_0x3ec4a9['uniqueid']));}else{_0x3ec4a9[_0x8f11('0x47')]='';}headers[_0x8f11('0x63')]=getAuth(_0x12953a);return getUser(_0x12953a)['then'](function(_0xd89819){_0x2d8b97=_0xd89819;logger['info'](_0x8f11('0x4a'),_0x2d8b97['id']);return getEndUser(_0x12953a,_0x3ec4a9['calleridname'],_0x3ec4a9['calleridnum']);})[_0x8f11('0x13')](function(_0x3c0833){_0x263b40=_0x3c0833;logger[_0x8f11('0xa')](_0x8f11('0x4d'),_0x263b40['id']);return getTicket(_0x12953a,_0x2d8b97,_0x263b40,_0x190ad2,_0x3ec4a9);})[_0x8f11('0x13')](function(_0x327556){if(_0x327556){logger[_0x8f11('0xa')](_0x8f11('0x4e'),_0x327556['id']);}})[_0x8f11('0x5b')](function(_0x1baf3a){logger[_0x8f11('0x59')]('['+_0x3ec4a9['lastevent']['toUpperCase']()+']'+'\x20Error\x20running\x20Zendesk\x20integration',util[_0x8f11('0x5c')](_0x1baf3a,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0xdd37=['variableName','custom_fields','customVariable','Variable','queue','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:','calleridnum','The\x20Enduser\x20ID\x20is:','The\x20Ticket\x20ID\x20is:','Displaying\x20ticket\x20to\x20agent...','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','trigger:browser:url','/api/v2','error','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','outbound','recordingFormat','none','destcalleridnum','integrationTab','[OUTBOUND]','user:%s','%s/agent/tickets/%s','replace','Zendesk\x20account\x20type\x20not\x20recognized','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','inspect','unmanaged','toUpperCase','calleridname','lastevent','\x20Error\x20running\x20Zendesk\x20integration','lodash','request-promise','md5','util','ioredis','./util','../../../../config/logger','zendesk','defaults','redis','localhost','socket.io-emitter','emit','application/json','info','Creating\x20new\x20ticket...','format','%s/tickets.json','POST','merge','Tags','name','getString','Subjects','Descriptions','Fields','then','Ticket\x20created!','ticket','validateEmail','Getting\x20agent\x20with\x20email','remoteUri','type:user\x20role:agent\x20email:%s','count','Agent\x20found!','find','results','agent','%s/users/me.json','Admin\x20account\x20selected.','Searching\x20enduser\x20with\x20phone','type:user\x20role:end-user\x20phone:%s','length','end-user','first','Enduser\x20found!','%s/users.json','Caller\x20-\x20%s','user','authType','password','%s:%s','token','%s/token:%s','Basic\x20%s','base64','debug','[HTTP]','stringify','GET','map','forEach','includes','string','picklist','type','nameField','customField','toLowerCase','content','toString','idField','push','variable'];(function(_0x162780,_0x47f2e2){var _0x1ea2dc=function(_0x123898){while(--_0x123898){_0x162780['push'](_0x162780['shift']());}};_0x1ea2dc(++_0x47f2e2);}(_0xdd37,0xa4));var _0x7dd3=function(_0x2b4411,_0x2625ed){_0x2b4411=_0x2b4411-0x0;var _0x8e41ef=_0xdd37[_0x2b4411];return _0x8e41ef;};'use strict';var _=require(_0x7dd3('0x0'));var rp=require(_0x7dd3('0x1'));var md5=require(_0x7dd3('0x2'));var util=require(_0x7dd3('0x3'));var Redis=require(_0x7dd3('0x4'));var intUtil=require(_0x7dd3('0x5'));var config=require('../../../../config/environment');var logger=require(_0x7dd3('0x6'))(_0x7dd3('0x7'));config['redis']=_[_0x7dd3('0x8')](config[_0x7dd3('0x9')],{'host':_0x7dd3('0xa'),'port':0x18eb});var io=require(_0x7dd3('0xb'))(new Redis(config[_0x7dd3('0x9')]));function emit(_0x456408,_0x163b2e,_0x4aa4f6){io['to'](_0x456408)[_0x7dd3('0xc')](_0x163b2e,_0x4aa4f6);}var headers={'Content-Type':_0x7dd3('0xd'),'Accept':'application/json'};function getTicket(_0x44a32a,_0x1bcc2d,_0x392f1c,_0x4aa6ba,_0x3aa3d8){logger[_0x7dd3('0xe')](_0x7dd3('0xf'));return request({'uri':util[_0x7dd3('0x10')](_0x7dd3('0x11'),_0x44a32a['remoteUri']),'method':_0x7dd3('0x12'),'body':{'ticket':_[_0x7dd3('0x13')]({'requester_id':_0x392f1c['id'],'submitter_id':_0x1bcc2d?_0x1bcc2d['id']:undefined,'assignee_id':_0x1bcc2d?_0x1bcc2d['id']:undefined,'tags':getTags(_0x4aa6ba[_0x7dd3('0x14')],_0x7dd3('0x15')),'subject':intUtil[_0x7dd3('0x16')](_0x4aa6ba[_0x7dd3('0x17')],_0x3aa3d8,'\x20'),'description':intUtil[_0x7dd3('0x16')](_0x4aa6ba[_0x7dd3('0x18')],_0x3aa3d8,'\x0a'),'comment':{'public':![],'body':intUtil[_0x7dd3('0x16')](_0x4aa6ba[_0x7dd3('0x18')],_0x3aa3d8,'\x0a')}},getCustomFields(_0x4aa6ba[_0x7dd3('0x19')],_0x3aa3d8))}})[_0x7dd3('0x1a')](function(_0x337fa3){logger[_0x7dd3('0xe')](_0x7dd3('0x1b'));return _0x337fa3[_0x7dd3('0x1c')];});}function getUser(_0x5f1063,_0x2bf05e){if(intUtil[_0x7dd3('0x1d')](_0x2bf05e)){logger[_0x7dd3('0xe')](_0x7dd3('0x1e'),_0x2bf05e);return request({'uri':util['format']('%s/search.json',_0x5f1063[_0x7dd3('0x1f')]),'qs':{'query':util[_0x7dd3('0x10')](_0x7dd3('0x20'),_0x2bf05e)}})['then'](function(_0x2a7309){if(_0x2a7309[_0x7dd3('0x21')]){logger[_0x7dd3('0xe')](_0x7dd3('0x22'));return _[_0x7dd3('0x23')](_0x2a7309[_0x7dd3('0x24')],{'email':_0x2bf05e,'role':_0x7dd3('0x25')});}else{logger[_0x7dd3('0xe')]('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0x7dd3('0x10')](_0x7dd3('0x26'),_0x5f1063['remoteUri'])})[_0x7dd3('0x1a')](function(_0x44f61f){logger[_0x7dd3('0xe')](_0x7dd3('0x27'));return _0x44f61f['user'];});}});}else{logger['info']('Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!');return request({'uri':util[_0x7dd3('0x10')](_0x7dd3('0x26'),_0x5f1063['remoteUri'])})[_0x7dd3('0x1a')](function(_0x4b94c2){logger[_0x7dd3('0xe')](_0x7dd3('0x27'));return _0x4b94c2['user'];});}}function getEndUser(_0x327138,_0x155716,_0x2242f4){logger[_0x7dd3('0xe')](_0x7dd3('0x28'),_0x2242f4);return request({'uri':util[_0x7dd3('0x10')]('%s/search.json',_0x327138[_0x7dd3('0x1f')]),'qs':{'query':util['format'](_0x7dd3('0x29'),_0x2242f4)}})['then'](function(_0x10d9a0){var _0x4d58db;if(_0x10d9a0[_0x7dd3('0x24')][_0x7dd3('0x2a')]){_0x10d9a0[_0x7dd3('0x24')]=_['filter'](_0x10d9a0[_0x7dd3('0x24')],{'suspended':![],'role':_0x7dd3('0x2b')});if(_0x10d9a0['results']['length']){_0x4d58db=_[_0x7dd3('0x2c')](_0x10d9a0[_0x7dd3('0x24')]);}}if(_0x4d58db){logger[_0x7dd3('0xe')](_0x7dd3('0x2d'));return _0x4d58db;}else{logger[_0x7dd3('0xe')]('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util['format'](_0x7dd3('0x2e'),_0x327138[_0x7dd3('0x1f')]),'method':_0x7dd3('0x12'),'body':{'user':{'role':_0x7dd3('0x2b'),'name':util[_0x7dd3('0x10')](_0x7dd3('0x2f'),_0x155716||_0x2242f4),'phone':_0x2242f4}}})[_0x7dd3('0x1a')](function(_0x10886a){logger[_0x7dd3('0xe')]('Enduser\x20created.');return _0x10886a[_0x7dd3('0x30')];});}});}function getAuth(_0xa58ad1){var _0x1ad09b;if(_0xa58ad1[_0x7dd3('0x31')]===_0x7dd3('0x32')){_0x1ad09b=util[_0x7dd3('0x10')](_0x7dd3('0x33'),_0xa58ad1['username'],_0xa58ad1['password']);}else if(_0xa58ad1['authType']===_0x7dd3('0x34')){_0x1ad09b=util[_0x7dd3('0x10')](_0x7dd3('0x35'),_0xa58ad1['username'],_0xa58ad1[_0x7dd3('0x34')]);}return util[_0x7dd3('0x10')](_0x7dd3('0x36'),new Buffer(_0x1ad09b)['toString'](_0x7dd3('0x37')));}function request(_0x344f60){logger[_0x7dd3('0x38')](_0x7dd3('0x39'),JSON[_0x7dd3('0x3a')](_0x344f60));return rp(_['defaults'](_0x344f60,{'method':_0x7dd3('0x3b'),'headers':headers,'json':!![]}));}function getTags(_0x156f8d,_0x22f492){var _0xc4a637=[];if(_0x156f8d&&_0x156f8d[_0x7dd3('0x2a')]>0x0){_0xc4a637=_[_0x7dd3('0x3c')](_0x156f8d,_0x22f492);}return _0xc4a637;}function getCustomFields(_0x1d6ebe,_0x248c9d){var _0x4f6c52=[];var _0x9cae93={'custom_fields':[]};if(_0x1d6ebe[_0x7dd3('0x2a')]>0x0){_[_0x7dd3('0x3d')](_0x1d6ebe,function(_0x2240b2){if(_[_0x7dd3('0x3e')]([_0x7dd3('0x3f'),_0x7dd3('0x40')],_0x2240b2[_0x7dd3('0x41')])&&_0x2240b2[_0x7dd3('0x42')]&&!_0x2240b2[_0x7dd3('0x43')]){_0x9cae93[_0x2240b2[_0x7dd3('0x42')][_0x7dd3('0x44')]()]=_0x2240b2[_0x7dd3('0x45')][_0x7dd3('0x46')]();}else if(_[_0x7dd3('0x3e')]([_0x7dd3('0x3f'),_0x7dd3('0x40')],_0x2240b2[_0x7dd3('0x41')])&&_0x2240b2[_0x7dd3('0x47')]&&_0x2240b2['customField']){_0x9cae93['custom_fields'][_0x7dd3('0x48')]({'id':_0x2240b2[_0x7dd3('0x47')],'value':_0x2240b2[_0x7dd3('0x45')][_0x7dd3('0x46')]()});}else if(_0x2240b2[_0x7dd3('0x41')]===_0x7dd3('0x49')&&_0x2240b2['variableName']&&_0x2240b2[_0x7dd3('0x47')]&&_0x2240b2['customField']){_0x248c9d[_0x2240b2[_0x7dd3('0x4a')]]&&_0x9cae93[_0x7dd3('0x4b')][_0x7dd3('0x48')]({'id':_0x2240b2[_0x7dd3('0x47')],'value':_0x248c9d[_0x2240b2[_0x7dd3('0x4a')]][_0x7dd3('0x46')]()});}else if(_0x2240b2[_0x7dd3('0x41')]===_0x7dd3('0x4c')&&_0x2240b2['Variable']&&_0x2240b2['Variable']['name']&&_0x2240b2[_0x7dd3('0x47')]&&_0x2240b2['customField']){_0x248c9d[_0x2240b2[_0x7dd3('0x4d')][_0x7dd3('0x15')][_0x7dd3('0x44')]()]&&_0x9cae93[_0x7dd3('0x4b')][_0x7dd3('0x48')]({'id':_0x2240b2['idField'],'value':_0x248c9d[_0x2240b2[_0x7dd3('0x4d')][_0x7dd3('0x15')]['toLowerCase']()][_0x7dd3('0x46')]()});}});}return _0x9cae93;}exports[_0x7dd3('0x4e')]=function(_0x2b9889,_0x2907a3,_0x1a4233,_0x303426,_0x121f54,_0x2e5d1e){var _0x2049f1,_0x2e5f17;_0x2e5d1e[_0x7dd3('0x1f')]=intUtil[_0x7dd3('0x4f')](_0x2e5d1e[_0x7dd3('0x1f')]);_0x2e5d1e[_0x7dd3('0x50')]=intUtil[_0x7dd3('0x4f')](_0x2e5d1e[_0x7dd3('0x50')]);if(_0x121f54&&_0x121f54[_0x7dd3('0x51')]){logger[_0x7dd3('0xe')](_0x7dd3('0x52'),_0x7dd3('0x53'));_0x2907a3[_0x7dd3('0x54')]=util[_0x7dd3('0x10')](_0x7dd3('0x55'),_0x2e5d1e[_0x7dd3('0x50')],_0x2907a3[_0x7dd3('0x56')],md5(_0x2907a3[_0x7dd3('0x56')]));}else{_0x2907a3[_0x7dd3('0x54')]='';}headers[_0x7dd3('0x57')]=getAuth(_0x2e5d1e);return getUser(_0x2e5d1e,_0x303426[_0x7dd3('0x58')])[_0x7dd3('0x1a')](function(_0x2fb26f){_0x2049f1=_0x2fb26f;logger[_0x7dd3('0xe')](_0x7dd3('0x59'),_0x2049f1['id']);return getEndUser(_0x2e5d1e,_0x2907a3['calleridname'],_0x2907a3[_0x7dd3('0x5a')]);})['then'](function(_0x55d332){_0x2e5f17=_0x55d332;logger['info'](_0x7dd3('0x5b'),_0x2e5f17['id']);return getTicket(_0x2e5d1e,_0x2049f1,_0x2e5f17,_0x1a4233,_0x2907a3);})[_0x7dd3('0x1a')](function(_0x30138b){if(_0x30138b){logger['info'](_0x7dd3('0x5c'),_0x30138b['id']);switch(_0x2e5d1e['type']){case'integrationTab':logger['info'](_0x7dd3('0x52'),_0x7dd3('0x5d'));return request({'uri':util[_0x7dd3('0x10')](_0x7dd3('0x5e'),_0x2e5d1e[_0x7dd3('0x1f')],_0x2049f1['id'],_0x30138b['id']),'method':'POST'});case _0x7dd3('0x5f'):logger['info'](_0x7dd3('0x52'),_0x7dd3('0x60'));emit(util[_0x7dd3('0x10')]('user:%s',_0x303426['name']),_0x7dd3('0x61'),{'uri':util[_0x7dd3('0x10')]('%s/agent/tickets/%s',_0x2e5d1e[_0x7dd3('0x1f')]['replace'](_0x7dd3('0x62'),''),_0x30138b['id'])});break;default:logger[_0x7dd3('0x63')](_0x7dd3('0x52'),'Zendesk\x20account\x20type\x20not\x20recognized');}}})[_0x7dd3('0x64')](function(_0x303fb9){logger['error'](_0x7dd3('0x65'),util['inspect'](_0x303fb9,{'showHidden':!![],'depth':null}));});};exports[_0x7dd3('0x66')]=function(_0x2b8508,_0x1364da,_0x4d4c99,_0x269719,_0x375f52,_0x53dd67,_0x2e3504){var _0x5e2047,_0x2e775b;_0x53dd67[_0x7dd3('0x1f')]=intUtil[_0x7dd3('0x4f')](_0x53dd67[_0x7dd3('0x1f')]);_0x53dd67[_0x7dd3('0x50')]=intUtil[_0x7dd3('0x4f')](_0x53dd67['serverUrl']);if(_0x2e3504&&_0x2e3504['recordingFormat']&&_0x2e3504[_0x7dd3('0x67')]!==_0x7dd3('0x68')){logger[_0x7dd3('0xe')]('[OUTBOUND]','Recording\x20is\x20enabled!');_0x1364da[_0x7dd3('0x54')]=util[_0x7dd3('0x10')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x53dd67[_0x7dd3('0x50')],_0x1364da[_0x7dd3('0x56')],md5(_0x1364da[_0x7dd3('0x56')]));}headers[_0x7dd3('0x57')]=getAuth(_0x53dd67);return getUser(_0x53dd67,_0x269719[_0x7dd3('0x58')])[_0x7dd3('0x1a')](function(_0x54fdaa){_0x5e2047=_0x54fdaa;logger[_0x7dd3('0xe')]('The\x20User\x20ID\x20is:',_0x5e2047['id']);return getEndUser(_0x53dd67,_0x1364da['destcalleridname'],_0x1364da[_0x7dd3('0x69')]);})[_0x7dd3('0x1a')](function(_0x5c4bae){_0x2e775b=_0x5c4bae;logger[_0x7dd3('0xe')](_0x7dd3('0x5b'),_0x2e775b['id']);return getTicket(_0x53dd67,_0x5e2047,_0x2e775b,_0x4d4c99,_0x1364da);})['then'](function(_0x4ceb95){if(_0x4ceb95){logger[_0x7dd3('0xe')](_0x7dd3('0x5c'),_0x4ceb95['id']);switch(_0x53dd67['type']){case _0x7dd3('0x6a'):logger[_0x7dd3('0xe')](_0x7dd3('0x6b'),_0x7dd3('0x5d'));return request({'uri':util['format'](_0x7dd3('0x5e'),_0x53dd67[_0x7dd3('0x1f')],_0x5e2047['id'],_0x4ceb95['id']),'method':_0x7dd3('0x12')});case _0x7dd3('0x5f'):logger[_0x7dd3('0xe')](_0x7dd3('0x6b'),_0x7dd3('0x60'));emit(util[_0x7dd3('0x10')](_0x7dd3('0x6c'),_0x269719['name']),'trigger:browser:url',{'uri':util['format'](_0x7dd3('0x6d'),_0x53dd67[_0x7dd3('0x1f')][_0x7dd3('0x6e')](_0x7dd3('0x62'),''),_0x4ceb95['id'])});break;default:logger[_0x7dd3('0x63')](_0x7dd3('0x6b'),_0x7dd3('0x6f'));}}})['catch'](function(_0x434138){logger['error'](_0x7dd3('0x70'),util[_0x7dd3('0x71')](_0x434138,{'showHidden':!![],'depth':null}));});};exports[_0x7dd3('0x72')]=function(_0x454394,_0x2ec866,_0xf40795,_0x408cdd,_0x1a22cc,_0x5b691b){var _0x3910a5,_0x4d13eb;_0x5b691b[_0x7dd3('0x1f')]=intUtil[_0x7dd3('0x4f')](_0x5b691b['remoteUri']);_0x5b691b[_0x7dd3('0x50')]=intUtil[_0x7dd3('0x4f')](_0x5b691b[_0x7dd3('0x50')]);if(_0x1a22cc&&_0x1a22cc[_0x7dd3('0x51')]){logger['info']('['+_0x2ec866['lastevent'][_0x7dd3('0x73')]()+']',_0x7dd3('0x53'));_0x2ec866[_0x7dd3('0x54')]=util['format'](_0x7dd3('0x55'),_0x5b691b[_0x7dd3('0x50')],_0x2ec866[_0x7dd3('0x56')],md5(_0x2ec866[_0x7dd3('0x56')]));}else{_0x2ec866['recordingURL']='';}headers[_0x7dd3('0x57')]=getAuth(_0x5b691b);return getUser(_0x5b691b)['then'](function(_0x1e4d29){_0x3910a5=_0x1e4d29;logger['info'](_0x7dd3('0x59'),_0x3910a5['id']);return getEndUser(_0x5b691b,_0x2ec866[_0x7dd3('0x74')],_0x2ec866['calleridnum']);})[_0x7dd3('0x1a')](function(_0x65efd){_0x4d13eb=_0x65efd;logger[_0x7dd3('0xe')](_0x7dd3('0x5b'),_0x4d13eb['id']);return getTicket(_0x5b691b,_0x3910a5,_0x4d13eb,_0xf40795,_0x2ec866);})[_0x7dd3('0x1a')](function(_0xb31b62){if(_0xb31b62){logger['info'](_0x7dd3('0x5c'),_0xb31b62['id']);}})[_0x7dd3('0x64')](function(_0x4ec84e){logger[_0x7dd3('0x63')]('['+_0x2ec866[_0x7dd3('0x75')][_0x7dd3('0x73')]()+']'+_0x7dd3('0x76'),util[_0x7dd3('0x71')](_0x4ec84e,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file