Built motion from commit (unavailable).|2.1.0
[motion2.git] / server / services / ami / trigger / integration / zendesk.js
index 97f883c..855a341 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xacd2=['trigger:browser:url','Zendesk\x20account\x20type\x20not\x20recognized','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','abandoned','[ABANDONED]','[ABANDONED]\x20Error\x20running\x20Zendesk\x20integration','lodash','request-promise','util','ioredis','../../../../config/environment','../../../../config/logger','zendesk','redis','defaults','localhost','socket.io-emitter','emit','application/json','info','Creating\x20new\x20ticket...','format','%s/tickets.json','remoteUri','POST','merge','name','Subjects','getString','Descriptions','Fields','ticket','Getting\x20agent\x20with\x20email','%s/search.json','type:user\x20role:agent\x20email:%s','then','count','Agent\x20found!','find','results','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\x20found!','Caller\x20-\x20%s','Enduser\x20created.','authType','password','%s:%s','username','%s/token:%s','token','Basic\x20%s','toString','debug','[HTTP]','stringify','GET','map','type','string','nameField','toLowerCase','content','idField','customField','custom_fields','push','variable','variableName','customVariable','Variable','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]','Displaying\x20ticket\x20to\x20agent...','%s/channels/voice/agents/%d/tickets/%d/display.json','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','%s/agent/tickets/%s','error','catch','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','inspect','outbound','recordingFormat','none','[OUTBOUND]','destcalleridname','destcalleridnum'];(function(_0x5d8e0a,_0x5b865c){var _0x393dc8=function(_0x49e2ca){while(--_0x49e2ca){_0x5d8e0a['push'](_0x5d8e0a['shift']());}};_0x393dc8(++_0x5b865c);}(_0xacd2,0xde));var _0x2acd=function(_0x4dcb4e,_0x51c91c){_0x4dcb4e=_0x4dcb4e-0x0;var _0x62da44=_0xacd2[_0x4dcb4e];return _0x62da44;};'use strict';var _=require(_0x2acd('0x0'));var rp=require(_0x2acd('0x1'));var md5=require('md5');var util=require(_0x2acd('0x2'));var Redis=require(_0x2acd('0x3'));var intUtil=require('./util');var config=require(_0x2acd('0x4'));var logger=require(_0x2acd('0x5'))(_0x2acd('0x6'));config[_0x2acd('0x7')]=_[_0x2acd('0x8')](config[_0x2acd('0x7')],{'host':_0x2acd('0x9'),'port':0x18eb});var io=require(_0x2acd('0xa'))(new Redis(config[_0x2acd('0x7')]));function emit(_0x465e7b,_0x5a4cfc,_0x3f4e41){io['to'](_0x465e7b)[_0x2acd('0xb')](_0x5a4cfc,_0x3f4e41);}var headers={'Content-Type':_0x2acd('0xc'),'Accept':_0x2acd('0xc')};function getTicket(_0x43a833,_0x29f531,_0x26f2cf,_0xe5e70b,_0x629d99){logger[_0x2acd('0xd')](_0x2acd('0xe'));return request({'uri':util[_0x2acd('0xf')](_0x2acd('0x10'),_0x43a833[_0x2acd('0x11')]),'method':_0x2acd('0x12'),'body':{'ticket':_[_0x2acd('0x13')]({'requester_id':_0x26f2cf['id'],'submitter_id':_0x29f531?_0x29f531['id']:undefined,'assignee_id':_0x29f531?_0x29f531['id']:undefined,'tags':getTags(_0xe5e70b['Tags'],_0x2acd('0x14')),'subject':intUtil['getString'](_0xe5e70b[_0x2acd('0x15')],_0x629d99,'\x20'),'description':intUtil[_0x2acd('0x16')](_0xe5e70b[_0x2acd('0x17')],_0x629d99,'\x0a'),'comment':{'public':![],'body':intUtil[_0x2acd('0x16')](_0xe5e70b[_0x2acd('0x17')],_0x629d99,'\x0a')}},getCustomFields(_0xe5e70b[_0x2acd('0x18')],_0x629d99))}})['then'](function(_0x25cb7f){logger[_0x2acd('0xd')]('Ticket\x20created!');return _0x25cb7f[_0x2acd('0x19')];});}function getUser(_0x226103,_0xb9fd59){logger[_0x2acd('0xd')](_0x2acd('0x1a'),_0xb9fd59);return request({'uri':util[_0x2acd('0xf')](_0x2acd('0x1b'),_0x226103['remoteUri']),'qs':{'query':util['format'](_0x2acd('0x1c'),_0xb9fd59)}})[_0x2acd('0x1d')](function(_0x569834){if(_0x569834[_0x2acd('0x1e')]){logger[_0x2acd('0xd')](_0x2acd('0x1f'));return _[_0x2acd('0x20')](_0x569834[_0x2acd('0x21')],{'email':_0xb9fd59,'role':'agent'});}else{logger[_0x2acd('0xd')](_0x2acd('0x22'));return request({'uri':util[_0x2acd('0xf')](_0x2acd('0x23'),_0x226103[_0x2acd('0x11')])})['then'](function(_0x1e719c){logger[_0x2acd('0xd')]('Admin\x20account\x20selected.');return _0x1e719c[_0x2acd('0x24')];});}});}function getEndUser(_0xfca052,_0x537504,_0x16f81d){logger[_0x2acd('0xd')](_0x2acd('0x25'),_0x16f81d);return request({'uri':util['format']('%s/search.json',_0xfca052['remoteUri']),'qs':{'query':util[_0x2acd('0xf')](_0x2acd('0x26'),_0x16f81d)}})['then'](function(_0x3d82e5){var _0x1c4d42;if(_0x3d82e5[_0x2acd('0x21')][_0x2acd('0x27')]){_0x3d82e5['results']=_[_0x2acd('0x28')](_0x3d82e5[_0x2acd('0x21')],{'suspended':![],'role':_0x2acd('0x29')});if(_0x3d82e5[_0x2acd('0x21')][_0x2acd('0x27')]){_0x1c4d42=_[_0x2acd('0x2a')](_0x3d82e5[_0x2acd('0x21')]);}}if(_0x1c4d42){logger['info'](_0x2acd('0x2b'));return _0x1c4d42;}else{logger['info']('Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!');return request({'uri':util[_0x2acd('0xf')]('%s/users.json',_0xfca052[_0x2acd('0x11')]),'method':'POST','body':{'user':{'role':_0x2acd('0x29'),'name':util[_0x2acd('0xf')](_0x2acd('0x2c'),_0x537504||_0x16f81d),'phone':_0x16f81d}}})[_0x2acd('0x1d')](function(_0x2290fe){logger[_0x2acd('0xd')](_0x2acd('0x2d'));return _0x2290fe[_0x2acd('0x24')];});}});}function getAuth(_0x16381a){var _0x59390b;if(_0x16381a[_0x2acd('0x2e')]===_0x2acd('0x2f')){_0x59390b=util[_0x2acd('0xf')](_0x2acd('0x30'),_0x16381a[_0x2acd('0x31')],_0x16381a['password']);}else if(_0x16381a[_0x2acd('0x2e')]==='token'){_0x59390b=util[_0x2acd('0xf')](_0x2acd('0x32'),_0x16381a[_0x2acd('0x31')],_0x16381a[_0x2acd('0x33')]);}return util['format'](_0x2acd('0x34'),new Buffer(_0x59390b)[_0x2acd('0x35')]('base64'));}function request(_0x36b055){logger[_0x2acd('0x36')](_0x2acd('0x37'),JSON[_0x2acd('0x38')](_0x36b055));return rp(_[_0x2acd('0x8')](_0x36b055,{'method':_0x2acd('0x39'),'headers':headers,'json':!![]}));}function getTags(_0x216bac,_0x22c357){var _0x43d2a8=[];if(_0x216bac&&_0x216bac[_0x2acd('0x27')]>0x0){_0x43d2a8=_[_0x2acd('0x3a')](_0x216bac,_0x22c357);}return _0x43d2a8;}function getCustomFields(_0x5743d1,_0x305865){var _0x18fe77=[];var _0x343d49={'custom_fields':[]};if(_0x5743d1['length']>0x0){_['forEach'](_0x5743d1,function(_0x57cd4d){if(_0x57cd4d[_0x2acd('0x3b')]===_0x2acd('0x3c')&&_0x57cd4d[_0x2acd('0x3d')]&&!_0x57cd4d['customField']){_0x343d49[_0x57cd4d['nameField'][_0x2acd('0x3e')]()]=_0x57cd4d[_0x2acd('0x3f')][_0x2acd('0x35')]();}else if(_0x57cd4d['type']==='string'&&_0x57cd4d[_0x2acd('0x40')]&&_0x57cd4d[_0x2acd('0x41')]){_0x343d49[_0x2acd('0x42')][_0x2acd('0x43')]({'id':_0x57cd4d[_0x2acd('0x40')],'value':_0x57cd4d[_0x2acd('0x3f')]['toString']()});}else if(_0x57cd4d[_0x2acd('0x3b')]===_0x2acd('0x44')&&_0x57cd4d[_0x2acd('0x45')]&&_0x57cd4d[_0x2acd('0x40')]&&_0x57cd4d[_0x2acd('0x41')]){_0x305865[_0x57cd4d[_0x2acd('0x45')]]&&_0x343d49[_0x2acd('0x42')][_0x2acd('0x43')]({'id':_0x57cd4d[_0x2acd('0x40')],'value':_0x305865[_0x57cd4d[_0x2acd('0x45')]][_0x2acd('0x35')]()});}else if(_0x57cd4d[_0x2acd('0x3b')]===_0x2acd('0x46')&&_0x57cd4d[_0x2acd('0x47')]&&_0x57cd4d[_0x2acd('0x47')]['name']&&_0x57cd4d[_0x2acd('0x40')]&&_0x57cd4d[_0x2acd('0x41')]){_0x305865[_0x57cd4d[_0x2acd('0x47')][_0x2acd('0x14')][_0x2acd('0x3e')]()]&&_0x343d49['custom_fields']['push']({'id':_0x57cd4d[_0x2acd('0x40')],'value':_0x305865[_0x57cd4d['Variable'][_0x2acd('0x14')][_0x2acd('0x3e')]()][_0x2acd('0x35')]()});}});}return _0x343d49;}exports['queue']=function(_0x57a075,_0x207cf4,_0x566f86,_0x2b9cfe,_0x141fd7,_0x2c4bb4){var _0x1684b8,_0x557967;_0x2c4bb4['remoteUri']=intUtil[_0x2acd('0x48')](_0x2c4bb4[_0x2acd('0x11')]);_0x2c4bb4[_0x2acd('0x49')]=intUtil[_0x2acd('0x48')](_0x2c4bb4[_0x2acd('0x49')]);if(_0x141fd7&&_0x141fd7[_0x2acd('0x4a')]){logger[_0x2acd('0xd')]('[QUEUE]',_0x2acd('0x4b'));_0x207cf4[_0x2acd('0x4c')]=util[_0x2acd('0xf')](_0x2acd('0x4d'),_0x2c4bb4[_0x2acd('0x49')],_0x207cf4[_0x2acd('0x4e')],md5(_0x207cf4['uniqueid']));}else{_0x207cf4[_0x2acd('0x4c')]='';}headers[_0x2acd('0x4f')]=getAuth(_0x2c4bb4);return getUser(_0x2c4bb4,_0x2b9cfe[_0x2acd('0x50')])[_0x2acd('0x1d')](function(_0x17838f){_0x1684b8=_0x17838f;logger['info'](_0x2acd('0x51'),_0x1684b8['id']);return getEndUser(_0x2c4bb4,_0x207cf4['calleridname'],_0x207cf4[_0x2acd('0x52')]);})[_0x2acd('0x1d')](function(_0x3d6ec6){_0x557967=_0x3d6ec6;logger[_0x2acd('0xd')](_0x2acd('0x53'),_0x557967['id']);return getTicket(_0x2c4bb4,_0x1684b8,_0x557967,_0x566f86,_0x207cf4);})[_0x2acd('0x1d')](function(_0x131bba){if(_0x131bba){logger['info'](_0x2acd('0x54'),_0x131bba['id']);switch(_0x2c4bb4[_0x2acd('0x3b')]){case'integrationTab':logger[_0x2acd('0xd')](_0x2acd('0x55'),_0x2acd('0x56'));return request({'uri':util[_0x2acd('0xf')](_0x2acd('0x57'),_0x2c4bb4['remoteUri'],_0x1684b8['id'],_0x131bba['id']),'method':_0x2acd('0x12')});case _0x2acd('0x58'):logger[_0x2acd('0xd')](_0x2acd('0x55'),_0x2acd('0x59'));emit(util[_0x2acd('0xf')](_0x2acd('0x5a'),_0x2b9cfe['name']),'trigger:browser:url',{'uri':util['format'](_0x2acd('0x5b'),_0x2c4bb4[_0x2acd('0x11')],_0x131bba['id'])});break;default:logger[_0x2acd('0x5c')](_0x2acd('0x55'),'Zendesk\x20account\x20type\x20not\x20recognized');}}})[_0x2acd('0x5d')](function(_0x1893a1){logger[_0x2acd('0x5c')](_0x2acd('0x5e'),util[_0x2acd('0x5f')](_0x1893a1,{'showHidden':!![],'depth':null}));});};exports[_0x2acd('0x60')]=function(_0xf97579,_0x26c367,_0x33e081,_0x2b42e4,_0x1cac78,_0x12c66d,_0x599540){var _0x108ad6,_0x102a59;_0x12c66d[_0x2acd('0x11')]=intUtil[_0x2acd('0x48')](_0x12c66d[_0x2acd('0x11')]);_0x12c66d['serverUrl']=intUtil['stripTrailingSlash'](_0x12c66d[_0x2acd('0x49')]);if(_0x599540&&_0x599540[_0x2acd('0x61')]&&_0x599540[_0x2acd('0x61')]!==_0x2acd('0x62')){logger['info'](_0x2acd('0x63'),_0x2acd('0x4b'));_0x26c367['recordingURL']=util[_0x2acd('0xf')](_0x2acd('0x4d'),_0x12c66d['serverUrl'],_0x26c367[_0x2acd('0x4e')],md5(_0x26c367[_0x2acd('0x4e')]));}headers[_0x2acd('0x4f')]=getAuth(_0x12c66d);return getUser(_0x12c66d,_0x2b42e4[_0x2acd('0x50')])[_0x2acd('0x1d')](function(_0x2d6114){_0x108ad6=_0x2d6114;logger[_0x2acd('0xd')]('The\x20User\x20ID\x20is:',_0x108ad6['id']);return getEndUser(_0x12c66d,_0x26c367[_0x2acd('0x64')],_0x26c367[_0x2acd('0x65')]);})[_0x2acd('0x1d')](function(_0x50d449){_0x102a59=_0x50d449;logger[_0x2acd('0xd')]('The\x20Enduser\x20ID\x20is:',_0x102a59['id']);return getTicket(_0x12c66d,_0x108ad6,_0x102a59,_0x33e081,_0x26c367);})[_0x2acd('0x1d')](function(_0x2c1537){if(_0x2c1537){logger[_0x2acd('0xd')]('The\x20Ticket\x20ID\x20is:',_0x2c1537['id']);switch(_0x12c66d['type']){case'integrationTab':logger[_0x2acd('0xd')](_0x2acd('0x63'),'Displaying\x20ticket\x20to\x20agent...');return request({'uri':util['format'](_0x2acd('0x57'),_0x12c66d[_0x2acd('0x11')],_0x108ad6['id'],_0x2c1537['id']),'method':'POST'});case _0x2acd('0x58'):logger[_0x2acd('0xd')](_0x2acd('0x63'),_0x2acd('0x59'));emit(util[_0x2acd('0xf')]('user:%s',_0x2b42e4[_0x2acd('0x14')]),_0x2acd('0x66'),{'uri':util[_0x2acd('0xf')](_0x2acd('0x5b'),_0x12c66d[_0x2acd('0x11')],_0x2c1537['id'])});break;default:logger[_0x2acd('0x5c')](_0x2acd('0x63'),_0x2acd('0x67'));}}})[_0x2acd('0x5d')](function(_0x5077c6){logger[_0x2acd('0x5c')](_0x2acd('0x68'),util['inspect'](_0x5077c6,{'showHidden':!![],'depth':null}));});};exports[_0x2acd('0x69')]=function(_0x1d60ce,_0x27cb46,_0x40a787,_0x24d62c,_0x28a1fd,_0x2e5f5a){var _0x35dce3,_0x2989d5;_0x2e5f5a[_0x2acd('0x11')]=intUtil[_0x2acd('0x48')](_0x2e5f5a['remoteUri']);_0x2e5f5a[_0x2acd('0x49')]=intUtil[_0x2acd('0x48')](_0x2e5f5a[_0x2acd('0x49')]);if(_0x28a1fd&&_0x28a1fd['monitor_format']){logger['info'](_0x2acd('0x6a'),'Recording\x20is\x20enabled!');_0x27cb46['recordingURL']=util[_0x2acd('0xf')](_0x2acd('0x4d'),_0x2e5f5a[_0x2acd('0x49')],_0x27cb46[_0x2acd('0x4e')],md5(_0x27cb46[_0x2acd('0x4e')]));}else{_0x27cb46[_0x2acd('0x4c')]='';}headers[_0x2acd('0x4f')]=getAuth(_0x2e5f5a);return getUser(_0x2e5f5a)[_0x2acd('0x1d')](function(_0x1df5bf){_0x35dce3=_0x1df5bf;logger[_0x2acd('0xd')](_0x2acd('0x51'),_0x35dce3['id']);return getEndUser(_0x2e5f5a,_0x27cb46['calleridname'],_0x27cb46['calleridnum']);})[_0x2acd('0x1d')](function(_0x2a405a){_0x2989d5=_0x2a405a;logger[_0x2acd('0xd')](_0x2acd('0x53'),_0x2989d5['id']);return getTicket(_0x2e5f5a,_0x35dce3,_0x2989d5,_0x40a787,_0x27cb46);})[_0x2acd('0x1d')](function(_0x100af9){if(_0x100af9){logger[_0x2acd('0xd')]('The\x20Ticket\x20ID\x20is:',_0x100af9['id']);}})[_0x2acd('0x5d')](function(_0x2c5cc3){logger[_0x2acd('0x5c')](_0x2acd('0x6b'),util[_0x2acd('0x5f')](_0x2c5cc3,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file
+var _0x9c15=['agent','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','%s/users/me.json','then','Admin\x20account\x20selected.','user','Searching\x20enduser\x20with\x20phone','length','filter','end-user','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','Enduser\x20created.','authType','username','password','token','%s/token:%s','Basic\x20%s','toString','base64','debug','stringify','GET','map','forEach','string','nameField','toLowerCase','content','type','idField','variable','variableName','customField','custom_fields','push','customVariable','Variable','name','queue','stripTrailingSlash','serverUrl','monitor_format','[QUEUE]','Recording\x20is\x20enabled!','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','uniqueid','Authorization','email','The\x20User\x20ID\x20is:','calleridname','The\x20Ticket\x20ID\x20is:','Displaying\x20ticket\x20to\x20agent...','newTab','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','user:%s','trigger:browser:url','%s/agent/tickets/%s','Zendesk\x20account\x20type\x20not\x20recognized','catch','error','[QUEUE]\x20Error\x20running\x20Zendesk\x20integration','inspect','outbound','recordingFormat','recordingURL','destcalleridname','integrationTab','[OUTBOUND]','%s/channels/voice/agents/%d/tickets/%d/display.json','[OUTBOUND]\x20Error\x20running\x20Zendesk\x20integration','The\x20Enduser\x20ID\x20is:','[ABANDONED]\x20Error\x20running\x20Zendesk\x20integration','lodash','request-promise','md5','util','ioredis','./util','../../../../config/environment','../../../../config/logger','zendesk','redis','defaults','localhost','socket.io-emitter','emit','application/json','info','Creating\x20new\x20ticket...','format','remoteUri','POST','Tags','getString','Descriptions','Fields','Ticket\x20created!','ticket','%s/search.json','type:user\x20role:agent\x20email:%s','count','find','results'];(function(_0x3d76aa,_0x53d9a9){var _0x45f536=function(_0x488975){while(--_0x488975){_0x3d76aa['push'](_0x3d76aa['shift']());}};_0x45f536(++_0x53d9a9);}(_0x9c15,0x1e9));var _0x59c1=function(_0x13d07a,_0x41efc3){_0x13d07a=_0x13d07a-0x0;var _0x5ee0ee=_0x9c15[_0x13d07a];return _0x5ee0ee;};'use strict';var _=require(_0x59c1('0x0'));var rp=require(_0x59c1('0x1'));var md5=require(_0x59c1('0x2'));var util=require(_0x59c1('0x3'));var Redis=require(_0x59c1('0x4'));var intUtil=require(_0x59c1('0x5'));var config=require(_0x59c1('0x6'));var logger=require(_0x59c1('0x7'))(_0x59c1('0x8'));config[_0x59c1('0x9')]=_[_0x59c1('0xa')](config[_0x59c1('0x9')],{'host':_0x59c1('0xb'),'port':0x18eb});var io=require(_0x59c1('0xc'))(new Redis(config[_0x59c1('0x9')]));function emit(_0x479407,_0x47b3d7,_0x578bcf){io['to'](_0x479407)[_0x59c1('0xd')](_0x47b3d7,_0x578bcf);}var headers={'Content-Type':_0x59c1('0xe'),'Accept':_0x59c1('0xe')};function getTicket(_0xe9ffef,_0x32b9c9,_0x26e40e,_0xe4d925,_0x27182a){logger[_0x59c1('0xf')](_0x59c1('0x10'));return request({'uri':util[_0x59c1('0x11')]('%s/tickets.json',_0xe9ffef[_0x59c1('0x12')]),'method':_0x59c1('0x13'),'body':{'ticket':_['merge']({'requester_id':_0x26e40e['id'],'submitter_id':_0x32b9c9?_0x32b9c9['id']:undefined,'assignee_id':_0x32b9c9?_0x32b9c9['id']:undefined,'tags':getTags(_0xe4d925[_0x59c1('0x14')],'name'),'subject':intUtil[_0x59c1('0x15')](_0xe4d925['Subjects'],_0x27182a,'\x20'),'description':intUtil[_0x59c1('0x15')](_0xe4d925[_0x59c1('0x16')],_0x27182a,'\x0a'),'comment':{'public':![],'body':intUtil[_0x59c1('0x15')](_0xe4d925[_0x59c1('0x16')],_0x27182a,'\x0a')}},getCustomFields(_0xe4d925[_0x59c1('0x17')],_0x27182a))}})['then'](function(_0x2c76a2){logger['info'](_0x59c1('0x18'));return _0x2c76a2[_0x59c1('0x19')];});}function getUser(_0x56ba22,_0x3728c5){logger[_0x59c1('0xf')]('Getting\x20agent\x20with\x20email',_0x3728c5);return request({'uri':util[_0x59c1('0x11')](_0x59c1('0x1a'),_0x56ba22[_0x59c1('0x12')]),'qs':{'query':util[_0x59c1('0x11')](_0x59c1('0x1b'),_0x3728c5)}})['then'](function(_0x5e70c4){if(_0x5e70c4[_0x59c1('0x1c')]){logger['info']('Agent\x20found!');return _[_0x59c1('0x1d')](_0x5e70c4[_0x59c1('0x1e')],{'email':_0x3728c5,'role':_0x59c1('0x1f')});}else{logger[_0x59c1('0xf')](_0x59c1('0x20'));return request({'uri':util[_0x59c1('0x11')](_0x59c1('0x21'),_0x56ba22['remoteUri'])})[_0x59c1('0x22')](function(_0x1689b4){logger[_0x59c1('0xf')](_0x59c1('0x23'));return _0x1689b4[_0x59c1('0x24')];});}});}function getEndUser(_0x59ef8b,_0x2cfd45,_0x2a3f34){logger['info'](_0x59c1('0x25'),_0x2a3f34);return request({'uri':util[_0x59c1('0x11')](_0x59c1('0x1a'),_0x59ef8b[_0x59c1('0x12')]),'qs':{'query':util[_0x59c1('0x11')]('type:user\x20role:end-user\x20phone:%s',_0x2a3f34)}})[_0x59c1('0x22')](function(_0x5e7e2b){var _0x370464;if(_0x5e7e2b[_0x59c1('0x1e')][_0x59c1('0x26')]){_0x5e7e2b[_0x59c1('0x1e')]=_[_0x59c1('0x27')](_0x5e7e2b[_0x59c1('0x1e')],{'suspended':![],'role':_0x59c1('0x28')});if(_0x5e7e2b[_0x59c1('0x1e')][_0x59c1('0x26')]){_0x370464=_['first'](_0x5e7e2b['results']);}}if(_0x370464){logger[_0x59c1('0xf')]('Enduser\x20found!');return _0x370464;}else{logger[_0x59c1('0xf')](_0x59c1('0x29'));return request({'uri':util[_0x59c1('0x11')]('%s/users.json',_0x59ef8b[_0x59c1('0x12')]),'method':'POST','body':{'user':{'role':_0x59c1('0x28'),'name':util[_0x59c1('0x11')]('Caller\x20-\x20%s',_0x2cfd45||_0x2a3f34),'phone':_0x2a3f34}}})[_0x59c1('0x22')](function(_0x1b2e7c){logger[_0x59c1('0xf')](_0x59c1('0x2a'));return _0x1b2e7c[_0x59c1('0x24')];});}});}function getAuth(_0x159418){var _0x4ed6a0;if(_0x159418[_0x59c1('0x2b')]==='password'){_0x4ed6a0=util[_0x59c1('0x11')]('%s:%s',_0x159418[_0x59c1('0x2c')],_0x159418[_0x59c1('0x2d')]);}else if(_0x159418['authType']===_0x59c1('0x2e')){_0x4ed6a0=util[_0x59c1('0x11')](_0x59c1('0x2f'),_0x159418[_0x59c1('0x2c')],_0x159418[_0x59c1('0x2e')]);}return util['format'](_0x59c1('0x30'),new Buffer(_0x4ed6a0)[_0x59c1('0x31')](_0x59c1('0x32')));}function request(_0x50d3e2){logger[_0x59c1('0x33')]('[HTTP]',JSON[_0x59c1('0x34')](_0x50d3e2));return rp(_[_0x59c1('0xa')](_0x50d3e2,{'method':_0x59c1('0x35'),'headers':headers,'json':!![]}));}function getTags(_0x1bd5e7,_0x3d20b1){var _0x1db064=[];if(_0x1bd5e7&&_0x1bd5e7[_0x59c1('0x26')]>0x0){_0x1db064=_[_0x59c1('0x36')](_0x1bd5e7,_0x3d20b1);}return _0x1db064;}function getCustomFields(_0x4dbace,_0x2fe79b){var _0xfc51d7=[];var _0x430fbe={'custom_fields':[]};if(_0x4dbace[_0x59c1('0x26')]>0x0){_[_0x59c1('0x37')](_0x4dbace,function(_0x556db8){if(_0x556db8['type']===_0x59c1('0x38')&&_0x556db8[_0x59c1('0x39')]&&!_0x556db8['customField']){_0x430fbe[_0x556db8[_0x59c1('0x39')][_0x59c1('0x3a')]()]=_0x556db8[_0x59c1('0x3b')][_0x59c1('0x31')]();}else if(_0x556db8[_0x59c1('0x3c')]===_0x59c1('0x38')&&_0x556db8[_0x59c1('0x3d')]&&_0x556db8['customField']){_0x430fbe['custom_fields']['push']({'id':_0x556db8[_0x59c1('0x3d')],'value':_0x556db8[_0x59c1('0x3b')]['toString']()});}else if(_0x556db8['type']===_0x59c1('0x3e')&&_0x556db8[_0x59c1('0x3f')]&&_0x556db8[_0x59c1('0x3d')]&&_0x556db8[_0x59c1('0x40')]){_0x2fe79b[_0x556db8['variableName']]&&_0x430fbe[_0x59c1('0x41')][_0x59c1('0x42')]({'id':_0x556db8[_0x59c1('0x3d')],'value':_0x2fe79b[_0x556db8[_0x59c1('0x3f')]][_0x59c1('0x31')]()});}else if(_0x556db8[_0x59c1('0x3c')]===_0x59c1('0x43')&&_0x556db8['Variable']&&_0x556db8[_0x59c1('0x44')][_0x59c1('0x45')]&&_0x556db8[_0x59c1('0x3d')]&&_0x556db8[_0x59c1('0x40')]){_0x2fe79b[_0x556db8['Variable']['name'][_0x59c1('0x3a')]()]&&_0x430fbe[_0x59c1('0x41')][_0x59c1('0x42')]({'id':_0x556db8[_0x59c1('0x3d')],'value':_0x2fe79b[_0x556db8[_0x59c1('0x44')][_0x59c1('0x45')]['toLowerCase']()][_0x59c1('0x31')]()});}});}return _0x430fbe;}exports[_0x59c1('0x46')]=function(_0x3ed0d9,_0x53d0b4,_0x3a9518,_0x5e3494,_0x14b973,_0x423135){var _0x1f65b2,_0x1c72cb;_0x423135[_0x59c1('0x12')]=intUtil[_0x59c1('0x47')](_0x423135[_0x59c1('0x12')]);_0x423135[_0x59c1('0x48')]=intUtil[_0x59c1('0x47')](_0x423135['serverUrl']);if(_0x14b973&&_0x14b973[_0x59c1('0x49')]){logger['info'](_0x59c1('0x4a'),_0x59c1('0x4b'));_0x53d0b4['recordingURL']=util[_0x59c1('0x11')](_0x59c1('0x4c'),_0x423135[_0x59c1('0x48')],_0x53d0b4[_0x59c1('0x4d')],md5(_0x53d0b4[_0x59c1('0x4d')]));}else{_0x53d0b4['recordingURL']='';}headers[_0x59c1('0x4e')]=getAuth(_0x423135);return getUser(_0x423135,_0x5e3494[_0x59c1('0x4f')])[_0x59c1('0x22')](function(_0x425efc){_0x1f65b2=_0x425efc;logger[_0x59c1('0xf')](_0x59c1('0x50'),_0x1f65b2['id']);return getEndUser(_0x423135,_0x53d0b4[_0x59c1('0x51')],_0x53d0b4['calleridnum']);})['then'](function(_0xe01e28){_0x1c72cb=_0xe01e28;logger[_0x59c1('0xf')]('The\x20Enduser\x20ID\x20is:',_0x1c72cb['id']);return getTicket(_0x423135,_0x1f65b2,_0x1c72cb,_0x3a9518,_0x53d0b4);})[_0x59c1('0x22')](function(_0x4b5536){if(_0x4b5536){logger[_0x59c1('0xf')](_0x59c1('0x52'),_0x4b5536['id']);switch(_0x423135['type']){case'integrationTab':logger[_0x59c1('0xf')](_0x59c1('0x4a'),_0x59c1('0x53'));return request({'uri':util[_0x59c1('0x11')]('%s/channels/voice/agents/%d/tickets/%d/display.json',_0x423135['remoteUri'],_0x1f65b2['id'],_0x4b5536['id']),'method':_0x59c1('0x13')});case _0x59c1('0x54'):logger[_0x59c1('0xf')](_0x59c1('0x4a'),_0x59c1('0x55'));emit(util[_0x59c1('0x11')](_0x59c1('0x56'),_0x5e3494[_0x59c1('0x45')]),_0x59c1('0x57'),{'uri':util['format'](_0x59c1('0x58'),_0x423135[_0x59c1('0x12')],_0x4b5536['id'])});break;default:logger['error'](_0x59c1('0x4a'),_0x59c1('0x59'));}}})[_0x59c1('0x5a')](function(_0xb9c3c5){logger[_0x59c1('0x5b')](_0x59c1('0x5c'),util[_0x59c1('0x5d')](_0xb9c3c5,{'showHidden':!![],'depth':null}));});};exports[_0x59c1('0x5e')]=function(_0x12f016,_0x582982,_0x36e435,_0x528e9d,_0x364c57,_0x53df45,_0x5af639){var _0x1b0295,_0x34e019;_0x53df45[_0x59c1('0x12')]=intUtil[_0x59c1('0x47')](_0x53df45['remoteUri']);_0x53df45[_0x59c1('0x48')]=intUtil['stripTrailingSlash'](_0x53df45['serverUrl']);if(_0x5af639&&_0x5af639[_0x59c1('0x5f')]&&_0x5af639['recordingFormat']!=='none'){logger['info']('[OUTBOUND]',_0x59c1('0x4b'));_0x582982[_0x59c1('0x60')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x53df45['serverUrl'],_0x582982[_0x59c1('0x4d')],md5(_0x582982[_0x59c1('0x4d')]));}headers[_0x59c1('0x4e')]=getAuth(_0x53df45);return getUser(_0x53df45,_0x528e9d[_0x59c1('0x4f')])[_0x59c1('0x22')](function(_0xd71754){_0x1b0295=_0xd71754;logger[_0x59c1('0xf')]('The\x20User\x20ID\x20is:',_0x1b0295['id']);return getEndUser(_0x53df45,_0x582982[_0x59c1('0x61')],_0x582982['destcalleridnum']);})[_0x59c1('0x22')](function(_0x43f1a1){_0x34e019=_0x43f1a1;logger[_0x59c1('0xf')]('The\x20Enduser\x20ID\x20is:',_0x34e019['id']);return getTicket(_0x53df45,_0x1b0295,_0x34e019,_0x36e435,_0x582982);})[_0x59c1('0x22')](function(_0x46a1ac){if(_0x46a1ac){logger['info'](_0x59c1('0x52'),_0x46a1ac['id']);switch(_0x53df45['type']){case _0x59c1('0x62'):logger[_0x59c1('0xf')](_0x59c1('0x63'),_0x59c1('0x53'));return request({'uri':util[_0x59c1('0x11')](_0x59c1('0x64'),_0x53df45[_0x59c1('0x12')],_0x1b0295['id'],_0x46a1ac['id']),'method':_0x59c1('0x13')});case _0x59c1('0x54'):logger[_0x59c1('0xf')](_0x59c1('0x63'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...');emit(util[_0x59c1('0x11')](_0x59c1('0x56'),_0x528e9d[_0x59c1('0x45')]),_0x59c1('0x57'),{'uri':util[_0x59c1('0x11')](_0x59c1('0x58'),_0x53df45[_0x59c1('0x12')],_0x46a1ac['id'])});break;default:logger[_0x59c1('0x5b')]('[OUTBOUND]',_0x59c1('0x59'));}}})[_0x59c1('0x5a')](function(_0x2784d1){logger[_0x59c1('0x5b')](_0x59c1('0x65'),util[_0x59c1('0x5d')](_0x2784d1,{'showHidden':!![],'depth':null}));});};exports['abandoned']=function(_0x17aa38,_0x54fecc,_0x398e12,_0x261666,_0x14d551,_0x34e037){var _0x43b2c9,_0x35e817;_0x34e037[_0x59c1('0x12')]=intUtil[_0x59c1('0x47')](_0x34e037['remoteUri']);_0x34e037[_0x59c1('0x48')]=intUtil[_0x59c1('0x47')](_0x34e037[_0x59c1('0x48')]);if(_0x14d551&&_0x14d551['monitor_format']){logger['info']('[ABANDONED]',_0x59c1('0x4b'));_0x54fecc['recordingURL']=util[_0x59c1('0x11')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x34e037['serverUrl'],_0x54fecc[_0x59c1('0x4d')],md5(_0x54fecc[_0x59c1('0x4d')]));}else{_0x54fecc['recordingURL']='';}headers[_0x59c1('0x4e')]=getAuth(_0x34e037);return getUser(_0x34e037)[_0x59c1('0x22')](function(_0x2ca2d8){_0x43b2c9=_0x2ca2d8;logger[_0x59c1('0xf')](_0x59c1('0x50'),_0x43b2c9['id']);return getEndUser(_0x34e037,_0x54fecc[_0x59c1('0x51')],_0x54fecc['calleridnum']);})[_0x59c1('0x22')](function(_0x55fc2f){_0x35e817=_0x55fc2f;logger['info'](_0x59c1('0x66'),_0x35e817['id']);return getTicket(_0x34e037,_0x43b2c9,_0x35e817,_0x398e12,_0x54fecc);})[_0x59c1('0x22')](function(_0x1e72e6){if(_0x1e72e6){logger[_0x59c1('0xf')](_0x59c1('0x52'),_0x1e72e6['id']);}})['catch'](function(_0x5c6571){logger[_0x59c1('0x5b')](_0x59c1('0x67'),util['inspect'](_0x5c6571,{'showHidden':!![],'depth':null}));});};
\ No newline at end of file