Built motion from commit aab208717af8d15f4fa224cdb6a202877019af9b. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / desk.js
index be1d1e7..f4bc88c 100644 (file)
@@ -1 +1 @@
-const a1136_0x5528=['getString','Enduser\x20found!','The\x20User\x20ID\x20is:','Basic\x20%s','Recording\x20is\x20enabled!','map','phone','then','work','./util','error','lodash','name','%s/users/me','Descriptions','user','Displaying\x20ticket\x20to\x20agent...','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','request-promise-native','merge','application/json','monitor_format','outbound','Fields','find','token','%s/customers/search','toUpperCase','%s/agent/tickets/%s','[QUEUE]','[OUTBOUND]','integrationTab','unmanaged','base64','debug','Tags','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','remoteUri','/api/v2/users/%d','util','md5','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','xCALLY','validateEmail','%s/customers','recordingURL','stripTrailingSlash','from','customField','content','uniqueid','new','type','variable','defaults','%s/token:%s','lastevent','../../../../config/logger','info','catch','user:%s','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','string','Getting\x20agent\x20with\x20email','Authorization','serverUrl','basic','authType','custom_fields','Ticket\x20created!','The\x20Ticket\x20ID\x20is:','format','%s/users','variableName','trigger:browser:url','queue','username','customVariable','Desk\x20account\x20type\x20not\x20recognized','toString','The\x20Enduser\x20ID\x20is:','newTab','Searching\x20enduser\x20with\x20phone','[HTTP]','Motion','trigger:desk:display','Variable','nameField','recordingFormat','_embedded','length','email','calleridname','toLowerCase','desk','forEach','POST','priority','calleridnum','stringify','../../../../rediscache','idField','Subjects'];(function(_0x3c45e6,_0x552874){const _0x3180c9=function(_0x240e15){while(--_0x240e15){_0x3c45e6['push'](_0x3c45e6['shift']());}};_0x3180c9(++_0x552874);}(a1136_0x5528,0x11c));const a1136_0x3180=function(_0x3c45e6,_0x552874){_0x3c45e6=_0x3c45e6-0x0;let _0x3180c9=a1136_0x5528[_0x3c45e6];return _0x3180c9;};const _0x5320ac=a1136_0x3180;'use strict';const _=require(_0x5320ac('0x24')),rp=require(_0x5320ac('0x2b')),md5=require(_0x5320ac('0x41')),util=require(_0x5320ac('0x40')),intUtil=require(_0x5320ac('0x22')),logger=require(_0x5320ac('0x52'))(_0x5320ac('0x10')),{getSocket}=require(_0x5320ac('0x16')),io=getSocket();function emit(_0x240e15,_0x452d94,_0x57aa1c){io['to'](_0x240e15)['emit'](_0x452d94,_0x57aa1c);}const headers={'Content-Type':_0x5320ac('0x2d'),'Accept':'application/json'};function getUser(_0x43d723,_0x144802){const _0xff9617=_0x5320ac;return intUtil[_0xff9617('0x44')](_0x144802)===!![]?(logger[_0xff9617('0x53')](_0xff9617('0x58'),_0x144802),request({'uri':util[_0xff9617('0x60')](_0xff9617('0x61'),_0x43d723['remoteUri'])})[_0xff9617('0x20')](function(_0x2f5cf5){const _0x51c854=_0xff9617;if(_0x2f5cf5['total_entries'])return _[_0x51c854('0x31')](_0x2f5cf5[_0x51c854('0xb')]['entries'],{'email':_0x144802});})[_0xff9617('0x20')](function(_0x231346){const _0x473a28=_0xff9617;return _0x231346?(logger[_0x473a28('0x53')]('Agent\x20found!'),_0x231346):(logger[_0x473a28('0x53')](_0x473a28('0x56')),request({'uri':util[_0x473a28('0x60')](_0x473a28('0x26'),_0x43d723['remoteUri'])}));})):(logger[_0xff9617('0x53')]('Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!'),request({'uri':util['format'](_0xff9617('0x26'),_0x43d723['remoteUri'])}));}function request(_0x514185){const _0x34e434=_0x5320ac;return logger[_0x34e434('0x3b')](_0x34e434('0x5'),JSON[_0x34e434('0x15')](_0x514185)),rp(_[_0x34e434('0x4f')](_0x514185,{'method':'GET','headers':headers,'json':!![]}));}function getAuth(_0x1e05de){const _0x29d7dc=_0x5320ac;let _0x2a5e9a;if(_0x1e05de['authType']===_0x29d7dc('0x5b'))_0x2a5e9a=util[_0x29d7dc('0x60')]('%s:%s',_0x1e05de[_0x29d7dc('0x65')],_0x1e05de['password']);else _0x1e05de[_0x29d7dc('0x5c')]===_0x29d7dc('0x32')&&(_0x2a5e9a=util[_0x29d7dc('0x60')](_0x29d7dc('0x50'),_0x1e05de[_0x29d7dc('0x65')],_0x1e05de[_0x29d7dc('0x32')]));return util[_0x29d7dc('0x60')](_0x29d7dc('0x1c'),Buffer[_0x29d7dc('0x48')](_0x2a5e9a)[_0x29d7dc('0x1')](_0x29d7dc('0x3a')));}function getEndUser(_0x146f8b,_0x166fce,_0x56257e){const _0x4154bd=_0x5320ac;return logger[_0x4154bd('0x53')](_0x4154bd('0x4'),_0x56257e),request({'uri':util[_0x4154bd('0x60')](_0x4154bd('0x33'),_0x146f8b['remoteUri']),'qs':{'phone':_0x56257e}})['then'](function(_0x427fb1){const _0x53636e=_0x4154bd;return _0x427fb1['total_entries']?(logger[_0x53636e('0x53')](_0x53636e('0x1a')),_0x427fb1['_embedded']['entries'][0x0]):(logger[_0x53636e('0x53')](_0x53636e('0x3d')),request({'uri':util[_0x53636e('0x60')](_0x53636e('0x45'),_0x146f8b[_0x53636e('0x3e')]),'method':_0x53636e('0x12'),'body':{'first_name':_0x166fce,'title':_0x166fce,'phone_numbers':[{'type':_0x53636e('0x21'),'value':_0x56257e}]}}));});}function getTags(_0x572211,_0x5c4d60){const _0x2c3e8a=_0x5320ac;let _0x303a94=[];return _0x572211&&_0x572211[_0x2c3e8a('0xc')]>0x0&&(_0x303a94=_[_0x2c3e8a('0x1e')](_0x572211,_0x5c4d60)),_0x303a94;}function getCustomFields(_0x17cc5,_0x72c0a){const _0xef01e4=_0x5320ac,_0x2b5feb={'custom_fields':{}};return _0x17cc5[_0xef01e4('0xc')]>0x0&&_[_0xef01e4('0x11')](_0x17cc5,function(_0x52dbfd){const _0x382d13=_0xef01e4;if(_0x52dbfd[_0x382d13('0x4d')]===_0x382d13('0x57')&&_0x52dbfd[_0x382d13('0x9')]&&!_0x52dbfd[_0x382d13('0x49')])_0x2b5feb[_0x52dbfd[_0x382d13('0x9')][_0x382d13('0xf')]()]=_0x52dbfd[_0x382d13('0x4a')][_0x382d13('0x1')]();else{if(_0x52dbfd[_0x382d13('0x4d')]===_0x382d13('0x57')&&_0x52dbfd[_0x382d13('0x17')]&&_0x52dbfd['customField'])_0x2b5feb[_0x382d13('0x5d')][_0x52dbfd[_0x382d13('0x17')]]=_0x52dbfd[_0x382d13('0x4a')][_0x382d13('0x1')]();else{if(_0x52dbfd['type']===_0x382d13('0x4e')&&_0x52dbfd[_0x382d13('0x62')]&&_0x52dbfd[_0x382d13('0x17')]&&_0x52dbfd[_0x382d13('0x49')])_0x72c0a[_0x52dbfd[_0x382d13('0x62')]]&&(_0x2b5feb['custom_fields'][_0x52dbfd[_0x382d13('0x17')]]=_0x72c0a[_0x52dbfd['variableName']]['toString']());else _0x52dbfd['type']===_0x382d13('0x66')&&_0x52dbfd[_0x382d13('0x8')]&&_0x52dbfd['Variable']['name']&&_0x52dbfd['idField']&&_0x52dbfd[_0x382d13('0x49')]&&(_0x72c0a[_0x52dbfd['Variable'][_0x382d13('0x25')][_0x382d13('0xf')]()]&&(_0x2b5feb[_0x382d13('0x5d')][_0x52dbfd['idField']]=_0x72c0a[_0x52dbfd[_0x382d13('0x8')][_0x382d13('0x25')][_0x382d13('0xf')]()][_0x382d13('0x1')]()));}}}),_0x2b5feb[_0xef01e4('0x13')]&&(_0x2b5feb[_0xef01e4('0x13')]=Number(_0x2b5feb[_0xef01e4('0x13')])),_0x2b5feb;}function getTicket(_0xa273ce,_0x186f8c,_0x32319c,_0x3aa938,_0x51b226){const _0xb3d444=_0x5320ac;logger[_0xb3d444('0x53')]('Creating\x20new\x20ticket...');const _0x5fe26c=_[_0xb3d444('0x2c')]({'subject':intUtil[_0xb3d444('0x19')](_0x3aa938[_0xb3d444('0x18')],_0x51b226,'\x20'),'type':_0xb3d444('0x1f'),'status':_0xb3d444('0x4c'),'labels':[_0xb3d444('0x43'),_0xb3d444('0x6'),'CTI']['concat'](getTags(_0x3aa938[_0xb3d444('0x3c')],_0xb3d444('0x25'))),'description':intUtil['getString'](_0x3aa938[_0xb3d444('0x27')],_0x51b226,'\x0a'),'_links':{'assigned_user':{'href':util[_0xb3d444('0x60')](_0xb3d444('0x3f'),_0x186f8c['id']),'class':_0xb3d444('0x28')}},'message':{'direction':'in','body':intUtil[_0xb3d444('0x19')](_0x3aa938[_0xb3d444('0x27')],_0x51b226,'\x0a')}},getCustomFields(_0x3aa938[_0xb3d444('0x30')],_0x51b226));return request({'uri':util[_0xb3d444('0x60')]('%s/customers/%d/cases',_0xa273ce[_0xb3d444('0x3e')],_0x32319c['id']),'method':_0xb3d444('0x12'),'body':_0x5fe26c});}exports[_0x5320ac('0x64')]=function(_0x4e7b92,_0x2c4b6b,_0x462176,_0x237e4a,_0x4afc3c,_0x3aca5d){const _0x5282a8=_0x5320ac;let _0xde1710,_0x47fd5b;return _0x3aca5d[_0x5282a8('0x3e')]=intUtil[_0x5282a8('0x47')](_0x3aca5d[_0x5282a8('0x3e')]),_0x3aca5d['serverUrl']=intUtil[_0x5282a8('0x47')](_0x3aca5d[_0x5282a8('0x5a')]),_0x4afc3c&&_0x4afc3c[_0x5282a8('0x2e')]?(logger['info'](_0x5282a8('0x36'),_0x5282a8('0x1d')),_0x2c4b6b[_0x5282a8('0x46')]=util[_0x5282a8('0x60')](_0x5282a8('0x42'),_0x3aca5d[_0x5282a8('0x5a')],_0x2c4b6b[_0x5282a8('0x4b')],md5(_0x2c4b6b[_0x5282a8('0x4b')]))):_0x2c4b6b[_0x5282a8('0x46')]='',headers['Authorization']=getAuth(_0x3aca5d),getUser(_0x3aca5d,_0x237e4a[_0x5282a8('0xd')])[_0x5282a8('0x20')](function(_0x59a411){const _0x31bc0f=_0x5282a8;return _0xde1710=_0x59a411,logger[_0x31bc0f('0x53')](_0x31bc0f('0x1b'),_0xde1710['id']),getEndUser(_0x3aca5d,_0x2c4b6b[_0x31bc0f('0xe')],_0x2c4b6b[_0x31bc0f('0x14')]);})[_0x5282a8('0x20')](function(_0x72f185){const _0x36900d=_0x5282a8;return _0x47fd5b=_0x72f185,logger[_0x36900d('0x53')](_0x36900d('0x2'),_0x47fd5b['id']),getTicket(_0x3aca5d,_0xde1710,_0x47fd5b,_0x462176,_0x2c4b6b);})[_0x5282a8('0x20')](function(_0xbc7dd4){const _0x868685=_0x5282a8;if(_0xbc7dd4){logger[_0x868685('0x53')](_0x868685('0x5e')),logger['info'](_0x868685('0x5f'),_0xbc7dd4['id']);switch(_0x3aca5d[_0x868685('0x4d')]){case'integrationTab':logger[_0x868685('0x53')]('[QUEUE]',_0x868685('0x29')),emit(util[_0x868685('0x60')](_0x868685('0x55'),_0x237e4a[_0x868685('0x25')]),_0x868685('0x7'),{'recordId':_0xbc7dd4['id']});break;case _0x868685('0x3'):logger['info'](_0x868685('0x36'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x868685('0x60')](_0x868685('0x55'),_0x237e4a[_0x868685('0x25')]),_0x868685('0x63'),{'uri':util[_0x868685('0x60')]('https://xcally.desk.com/web/agent/case/%d',_0xbc7dd4['id'])});break;default:logger['error'](_0x868685('0x36'),_0x868685('0x0'));}}})[_0x5282a8('0x54')](function(_0x2b5db6){const _0x1dbfa7=_0x5282a8;console[_0x1dbfa7('0x23')](_0x2b5db6),logger[_0x1dbfa7('0x23')](_0x1dbfa7('0x36'),JSON['stringify'](_0x2b5db6));});},exports[_0x5320ac('0x2f')]=function(_0x221664,_0x35c267,_0x50c16d,_0x5f55e4,_0x25b015,_0x3e06c2,_0x551e88){const _0x3e3ddd=_0x5320ac;let _0x34186b,_0x4d91bb;return _0x3e06c2[_0x3e3ddd('0x3e')]=intUtil[_0x3e3ddd('0x47')](_0x3e06c2['remoteUri']),_0x3e06c2[_0x3e3ddd('0x5a')]=intUtil[_0x3e3ddd('0x47')](_0x3e06c2['serverUrl']),_0x551e88&&_0x551e88[_0x3e3ddd('0xa')]&&_0x551e88[_0x3e3ddd('0xa')]!=='none'&&(logger[_0x3e3ddd('0x53')](_0x3e3ddd('0x37'),_0x3e3ddd('0x1d')),_0x35c267[_0x3e3ddd('0x46')]=util['format'](_0x3e3ddd('0x42'),_0x3e06c2['serverUrl'],_0x35c267[_0x3e3ddd('0x4b')],md5(_0x35c267[_0x3e3ddd('0x4b')]))),headers['Authorization']=getAuth(_0x3e06c2),getUser(_0x3e06c2,_0x5f55e4[_0x3e3ddd('0xd')])[_0x3e3ddd('0x20')](function(_0x3aa8f0){const _0x3344c4=_0x3e3ddd;return _0x34186b=_0x3aa8f0,logger[_0x3344c4('0x53')](_0x3344c4('0x1b'),_0x34186b['id']),getEndUser(_0x3e06c2,_0x35c267['destcalleridname'],_0x35c267['destcalleridnum']);})[_0x3e3ddd('0x20')](function(_0x5f1bf7){const _0x45ce55=_0x3e3ddd;return _0x4d91bb=_0x5f1bf7,logger[_0x45ce55('0x53')](_0x45ce55('0x2'),_0x4d91bb['id']),getTicket(_0x3e06c2,_0x34186b,_0x4d91bb,_0x50c16d,_0x35c267);})[_0x3e3ddd('0x20')](function(_0x18ffa1){const _0x512f67=_0x3e3ddd;if(_0x18ffa1){logger[_0x512f67('0x53')](_0x512f67('0x5e')),logger['info']('The\x20Ticket\x20ID\x20is:',_0x18ffa1['id']);switch(_0x3e06c2['type']){case _0x512f67('0x38'):logger[_0x512f67('0x53')](_0x512f67('0x36'),_0x512f67('0x29')),emit(util[_0x512f67('0x60')](_0x512f67('0x55'),_0x5f55e4[_0x512f67('0x25')]),_0x512f67('0x7'),{'recordId':_0x18ffa1['id']});break;case _0x512f67('0x3'):logger['info']('[QUEUE]',_0x512f67('0x2a')),emit(util[_0x512f67('0x60')](_0x512f67('0x55'),_0x5f55e4['name']),'trigger:browser:url',{'uri':util[_0x512f67('0x60')](_0x512f67('0x35'),_0x3e06c2['remoteUri'],_0x18ffa1['id'])});break;default:logger['error']('[OUTBOUND]','Desk\x20account\x20type\x20not\x20recognized');}}})['catch'](function(_0x49659c){const _0x3cda59=_0x3e3ddd;logger[_0x3cda59('0x23')]('[OUTBOUND]',JSON[_0x3cda59('0x15')](_0x49659c));});},exports[_0x5320ac('0x39')]=function(_0x4683fa,_0x1d011e,_0x264753,_0x39a30c,_0x7692a3,_0x318ba2){const _0x5d4df7=_0x5320ac;let _0x24ab6f,_0x51969e;return _0x318ba2[_0x5d4df7('0x3e')]=intUtil[_0x5d4df7('0x47')](_0x318ba2['remoteUri']),_0x318ba2[_0x5d4df7('0x5a')]=intUtil['stripTrailingSlash'](_0x318ba2[_0x5d4df7('0x5a')]),_0x7692a3&&_0x7692a3[_0x5d4df7('0x2e')]?(logger[_0x5d4df7('0x53')]('['+_0x1d011e[_0x5d4df7('0x51')][_0x5d4df7('0x34')]()+']','Recording\x20is\x20enabled!'),_0x1d011e[_0x5d4df7('0x46')]=util['format'](_0x5d4df7('0x42'),_0x318ba2[_0x5d4df7('0x5a')],_0x1d011e[_0x5d4df7('0x4b')],md5(_0x1d011e['uniqueid']))):_0x1d011e['recordingURL']='',headers[_0x5d4df7('0x59')]=getAuth(_0x318ba2),getUser(_0x318ba2)[_0x5d4df7('0x20')](function(_0x2c5c26){const _0x4ae976=_0x5d4df7;return _0x24ab6f=_0x2c5c26,logger[_0x4ae976('0x53')](_0x4ae976('0x1b'),_0x24ab6f['id']),getEndUser(_0x318ba2,_0x1d011e[_0x4ae976('0xe')],_0x1d011e[_0x4ae976('0x14')]);})['then'](function(_0x390e67){const _0x318d01=_0x5d4df7;return _0x51969e=_0x390e67,logger[_0x318d01('0x53')](_0x318d01('0x2'),_0x51969e['id']),getTicket(_0x318ba2,_0x24ab6f,_0x51969e,_0x264753,_0x1d011e);})['then'](function(_0x5c3ca5){const _0x54f8ad=_0x5d4df7;_0x5c3ca5&&(logger[_0x54f8ad('0x53')](_0x54f8ad('0x5e')),logger[_0x54f8ad('0x53')]('The\x20Ticket\x20ID\x20is:',_0x5c3ca5['id']));})[_0x5d4df7('0x54')](function(_0xdca577){const _0x1c1557=_0x5d4df7;logger[_0x1c1557('0x23')]('['+_0x1d011e[_0x1c1557('0x51')]['toUpperCase']()+']',JSON['stringify'](_0xdca577));});};
\ No newline at end of file
+const a1136_0x1f04=['password','application/json','nameField','emit','%s/agent/tickets/%s','idField','error','Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!','token','desk','%s/customers/%d/cases','base64','Motion','Creating\x20new\x20ticket...','from','username','../../../../config/logger','length','serverUrl','variableName','%s/users','stripTrailingSlash','Agent\x20found!','The\x20Ticket\x20ID\x20is:','stringify','The\x20Enduser\x20ID\x20is:','none','calleridname','uniqueid','getString','customVariable','trigger:browser:url','CTI','calleridnum','merge','new','email','forEach','https://xcally.desk.com/web/agent/case/%d','recordingFormat','destcalleridnum','catch','xCALLY','info','priority','then','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','user','content','./util','integrationTab','variable','[HTTP]','work','Displaying\x20ticket\x20to\x20agent...','lastevent','debug','customField','POST','newTab','entries','%s/customers/search','unmanaged','queue','[OUTBOUND]','trigger:desk:display','_embedded','concat','toString','toUpperCase','Descriptions','Authorization','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','Recording\x20is\x20enabled!','destcalleridname','Fields','string','basic','The\x20User\x20ID\x20is:','custom_fields','Searching\x20enduser\x20with\x20phone','authType','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','total_entries','lodash','monitor_format','recordingURL','%s/token:%s','/api/v2/users/%d','[QUEUE]','Getting\x20agent\x20with\x20email','Basic\x20%s','GET','user:%s','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...','Desk\x20account\x20type\x20not\x20recognized','request-promise-native','type','Tags','util','find','name','format','phone','Variable','remoteUri','Ticket\x20created!','map'];(function(_0x1862c4,_0x1f0475){const _0x1560d8=function(_0x150580){while(--_0x150580){_0x1862c4['push'](_0x1862c4['shift']());}};_0x1560d8(++_0x1f0475);}(a1136_0x1f04,0x88));const a1136_0x1560=function(_0x1862c4,_0x1f0475){_0x1862c4=_0x1862c4-0x0;let _0x1560d8=a1136_0x1f04[_0x1862c4];return _0x1560d8;};const _0x355e9e=a1136_0x1560;'use strict';const _=require(_0x355e9e('0x38')),rp=require(_0x355e9e('0x44')),md5=require('md5'),util=require(_0x355e9e('0x47')),intUtil=require(_0x355e9e('0x15')),logger=require(_0x355e9e('0x60'))(_0x355e9e('0x59')),{getSocket}=require('../../../../rediscache'),io=getSocket();function emit(_0x150580,_0x3ad00e,_0x5e2049){const _0x9d45f1=_0x355e9e;io['to'](_0x150580)[_0x9d45f1('0x53')](_0x3ad00e,_0x5e2049);}const headers={'Content-Type':'application/json','Accept':_0x355e9e('0x51')};function getUser(_0x2facdc,_0x27579c){const _0x546c2d=_0x355e9e;return intUtil['validateEmail'](_0x27579c)===!![]?(logger[_0x546c2d('0xf')](_0x546c2d('0x3e'),_0x27579c),request({'uri':util[_0x546c2d('0x4a')](_0x546c2d('0x64'),_0x2facdc[_0x546c2d('0x4d')])})[_0x546c2d('0x11')](function(_0x3c51d1){const _0x474839=_0x546c2d;if(_0x3c51d1[_0x474839('0x37')])return _[_0x474839('0x48')](_0x3c51d1[_0x474839('0x26')][_0x474839('0x20')],{'email':_0x27579c});})[_0x546c2d('0x11')](function(_0x308fc9){const _0x58ba2c=_0x546c2d;return _0x308fc9?(logger['info'](_0x58ba2c('0x66')),_0x308fc9):(logger[_0x58ba2c('0xf')](_0x58ba2c('0x12')),request({'uri':util[_0x58ba2c('0x4a')]('%s/users/me',_0x2facdc[_0x58ba2c('0x4d')])}));})):(logger[_0x546c2d('0xf')](_0x546c2d('0x57')),request({'uri':util[_0x546c2d('0x4a')]('%s/users/me',_0x2facdc[_0x546c2d('0x4d')])}));}function request(_0x172b78){const _0x3673e6=_0x355e9e;return logger[_0x3673e6('0x1c')](_0x3673e6('0x18'),JSON[_0x3673e6('0x68')](_0x172b78)),rp(_['defaults'](_0x172b78,{'method':_0x3673e6('0x40'),'headers':headers,'json':!![]}));}function getAuth(_0xeeb305){const _0x1bdfa8=_0x355e9e;let _0x34ef1d;if(_0xeeb305[_0x1bdfa8('0x35')]===_0x1bdfa8('0x31'))_0x34ef1d=util[_0x1bdfa8('0x4a')]('%s:%s',_0xeeb305[_0x1bdfa8('0x5f')],_0xeeb305[_0x1bdfa8('0x50')]);else _0xeeb305[_0x1bdfa8('0x35')]===_0x1bdfa8('0x58')&&(_0x34ef1d=util[_0x1bdfa8('0x4a')](_0x1bdfa8('0x3b'),_0xeeb305[_0x1bdfa8('0x5f')],_0xeeb305['token']));return util['format'](_0x1bdfa8('0x3f'),Buffer[_0x1bdfa8('0x5e')](_0x34ef1d)[_0x1bdfa8('0x28')](_0x1bdfa8('0x5b')));}function getEndUser(_0x5245fc,_0x15f7ef,_0x11f04e){const _0x49610e=_0x355e9e;return logger[_0x49610e('0xf')](_0x49610e('0x34'),_0x11f04e),request({'uri':util[_0x49610e('0x4a')](_0x49610e('0x21'),_0x5245fc[_0x49610e('0x4d')]),'qs':{'phone':_0x11f04e}})[_0x49610e('0x11')](function(_0x926c60){const _0x56d475=_0x49610e;return _0x926c60['total_entries']?(logger[_0x56d475('0xf')]('Enduser\x20found!'),_0x926c60[_0x56d475('0x26')][_0x56d475('0x20')][0x0]):(logger[_0x56d475('0xf')](_0x56d475('0x36')),request({'uri':util[_0x56d475('0x4a')]('%s/customers',_0x5245fc['remoteUri']),'method':'POST','body':{'first_name':_0x15f7ef,'title':_0x15f7ef,'phone_numbers':[{'type':_0x56d475('0x19'),'value':_0x11f04e}]}}));});}function getTags(_0x5371a1,_0x1a5ab5){const _0x5c52c6=_0x355e9e;let _0x231cad=[];return _0x5371a1&&_0x5371a1[_0x5c52c6('0x61')]>0x0&&(_0x231cad=_[_0x5c52c6('0x4f')](_0x5371a1,_0x1a5ab5)),_0x231cad;}function getCustomFields(_0x14c56c,_0x22b288){const _0x22d0bb=_0x355e9e,_0xfe2f95={'custom_fields':{}};return _0x14c56c['length']>0x0&&_[_0x22d0bb('0x9')](_0x14c56c,function(_0x573a35){const _0x41dfab=_0x22d0bb;if(_0x573a35['type']==='string'&&_0x573a35[_0x41dfab('0x52')]&&!_0x573a35[_0x41dfab('0x1d')])_0xfe2f95[_0x573a35['nameField']['toLowerCase']()]=_0x573a35[_0x41dfab('0x14')][_0x41dfab('0x28')]();else{if(_0x573a35[_0x41dfab('0x45')]===_0x41dfab('0x30')&&_0x573a35['idField']&&_0x573a35[_0x41dfab('0x1d')])_0xfe2f95[_0x41dfab('0x33')][_0x573a35['idField']]=_0x573a35['content'][_0x41dfab('0x28')]();else{if(_0x573a35[_0x41dfab('0x45')]===_0x41dfab('0x17')&&_0x573a35[_0x41dfab('0x63')]&&_0x573a35[_0x41dfab('0x55')]&&_0x573a35['customField'])_0x22b288[_0x573a35[_0x41dfab('0x63')]]&&(_0xfe2f95[_0x41dfab('0x33')][_0x573a35[_0x41dfab('0x55')]]=_0x22b288[_0x573a35[_0x41dfab('0x63')]][_0x41dfab('0x28')]());else _0x573a35[_0x41dfab('0x45')]===_0x41dfab('0x2')&&_0x573a35['Variable']&&_0x573a35[_0x41dfab('0x4c')][_0x41dfab('0x49')]&&_0x573a35[_0x41dfab('0x55')]&&_0x573a35[_0x41dfab('0x1d')]&&(_0x22b288[_0x573a35[_0x41dfab('0x4c')][_0x41dfab('0x49')]['toLowerCase']()]&&(_0xfe2f95['custom_fields'][_0x573a35[_0x41dfab('0x55')]]=_0x22b288[_0x573a35[_0x41dfab('0x4c')]['name']['toLowerCase']()]['toString']()));}}}),_0xfe2f95[_0x22d0bb('0x10')]&&(_0xfe2f95[_0x22d0bb('0x10')]=Number(_0xfe2f95[_0x22d0bb('0x10')])),_0xfe2f95;}function getTicket(_0x248d99,_0x3e7f22,_0x422379,_0x41a1c9,_0x406394){const _0x5318f9=_0x355e9e;logger[_0x5318f9('0xf')](_0x5318f9('0x5d'));const _0x2a7074=_[_0x5318f9('0x6')]({'subject':intUtil[_0x5318f9('0x1')](_0x41a1c9['Subjects'],_0x406394,'\x20'),'type':_0x5318f9('0x4b'),'status':_0x5318f9('0x7'),'labels':[_0x5318f9('0xe'),_0x5318f9('0x5c'),_0x5318f9('0x4')][_0x5318f9('0x27')](getTags(_0x41a1c9[_0x5318f9('0x46')],_0x5318f9('0x49'))),'description':intUtil[_0x5318f9('0x1')](_0x41a1c9[_0x5318f9('0x2a')],_0x406394,'\x0a'),'_links':{'assigned_user':{'href':util[_0x5318f9('0x4a')](_0x5318f9('0x3c'),_0x3e7f22['id']),'class':_0x5318f9('0x13')}},'message':{'direction':'in','body':intUtil[_0x5318f9('0x1')](_0x41a1c9[_0x5318f9('0x2a')],_0x406394,'\x0a')}},getCustomFields(_0x41a1c9[_0x5318f9('0x2f')],_0x406394));return request({'uri':util[_0x5318f9('0x4a')](_0x5318f9('0x5a'),_0x248d99[_0x5318f9('0x4d')],_0x422379['id']),'method':_0x5318f9('0x1e'),'body':_0x2a7074});}exports[_0x355e9e('0x23')]=function(_0x305a2b,_0xb44b9f,_0x483f8c,_0x4e15c8,_0x3c46dc,_0x8d8c25){const _0x495f7f=_0x355e9e;let _0x48f70d,_0x49e65d;return _0x8d8c25[_0x495f7f('0x4d')]=intUtil[_0x495f7f('0x65')](_0x8d8c25[_0x495f7f('0x4d')]),_0x8d8c25[_0x495f7f('0x62')]=intUtil[_0x495f7f('0x65')](_0x8d8c25[_0x495f7f('0x62')]),_0x3c46dc&&_0x3c46dc[_0x495f7f('0x39')]?(logger[_0x495f7f('0xf')](_0x495f7f('0x3d'),_0x495f7f('0x2d')),_0xb44b9f[_0x495f7f('0x3a')]=util['format'](_0x495f7f('0x2c'),_0x8d8c25[_0x495f7f('0x62')],_0xb44b9f[_0x495f7f('0x0')],md5(_0xb44b9f[_0x495f7f('0x0')]))):_0xb44b9f[_0x495f7f('0x3a')]='',headers[_0x495f7f('0x2b')]=getAuth(_0x8d8c25),getUser(_0x8d8c25,_0x4e15c8['email'])[_0x495f7f('0x11')](function(_0x3e0362){const _0x3089ec=_0x495f7f;return _0x48f70d=_0x3e0362,logger[_0x3089ec('0xf')](_0x3089ec('0x32'),_0x48f70d['id']),getEndUser(_0x8d8c25,_0xb44b9f[_0x3089ec('0x6b')],_0xb44b9f[_0x3089ec('0x5')]);})[_0x495f7f('0x11')](function(_0x143f24){const _0x518a78=_0x495f7f;return _0x49e65d=_0x143f24,logger[_0x518a78('0xf')](_0x518a78('0x69'),_0x49e65d['id']),getTicket(_0x8d8c25,_0x48f70d,_0x49e65d,_0x483f8c,_0xb44b9f);})[_0x495f7f('0x11')](function(_0x276a00){const _0x282e00=_0x495f7f;if(_0x276a00){logger['info'](_0x282e00('0x4e')),logger[_0x282e00('0xf')]('The\x20Ticket\x20ID\x20is:',_0x276a00['id']);switch(_0x8d8c25[_0x282e00('0x45')]){case _0x282e00('0x16'):logger['info'](_0x282e00('0x3d'),_0x282e00('0x1a')),emit(util[_0x282e00('0x4a')]('user:%s',_0x4e15c8['name']),_0x282e00('0x25'),{'recordId':_0x276a00['id']});break;case _0x282e00('0x1f'):logger[_0x282e00('0xf')](_0x282e00('0x3d'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x282e00('0x4a')](_0x282e00('0x41'),_0x4e15c8[_0x282e00('0x49')]),_0x282e00('0x3'),{'uri':util[_0x282e00('0x4a')](_0x282e00('0xa'),_0x276a00['id'])});break;default:logger[_0x282e00('0x56')](_0x282e00('0x3d'),'Desk\x20account\x20type\x20not\x20recognized');}}})[_0x495f7f('0xd')](function(_0x4631b3){const _0x11561e=_0x495f7f;console[_0x11561e('0x56')](_0x4631b3),logger[_0x11561e('0x56')](_0x11561e('0x3d'),JSON[_0x11561e('0x68')](_0x4631b3));});},exports['outbound']=function(_0x39242b,_0x1412d4,_0x2ef5f6,_0x31ad88,_0x5c2068,_0x47ac41,_0x437957){const _0xb59f8c=_0x355e9e;let _0xf68d03,_0x148e8d;return _0x47ac41[_0xb59f8c('0x4d')]=intUtil['stripTrailingSlash'](_0x47ac41[_0xb59f8c('0x4d')]),_0x47ac41[_0xb59f8c('0x62')]=intUtil[_0xb59f8c('0x65')](_0x47ac41['serverUrl']),_0x437957&&_0x437957[_0xb59f8c('0xb')]&&_0x437957[_0xb59f8c('0xb')]!==_0xb59f8c('0x6a')&&(logger[_0xb59f8c('0xf')]('[OUTBOUND]',_0xb59f8c('0x2d')),_0x1412d4[_0xb59f8c('0x3a')]=util[_0xb59f8c('0x4a')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x47ac41[_0xb59f8c('0x62')],_0x1412d4[_0xb59f8c('0x0')],md5(_0x1412d4[_0xb59f8c('0x0')]))),headers[_0xb59f8c('0x2b')]=getAuth(_0x47ac41),getUser(_0x47ac41,_0x31ad88[_0xb59f8c('0x8')])[_0xb59f8c('0x11')](function(_0x129da9){const _0x3dcc75=_0xb59f8c;return _0xf68d03=_0x129da9,logger[_0x3dcc75('0xf')](_0x3dcc75('0x32'),_0xf68d03['id']),getEndUser(_0x47ac41,_0x1412d4[_0x3dcc75('0x2e')],_0x1412d4[_0x3dcc75('0xc')]);})['then'](function(_0x3e4e9d){const _0x5413af=_0xb59f8c;return _0x148e8d=_0x3e4e9d,logger['info'](_0x5413af('0x69'),_0x148e8d['id']),getTicket(_0x47ac41,_0xf68d03,_0x148e8d,_0x2ef5f6,_0x1412d4);})[_0xb59f8c('0x11')](function(_0x298cd3){const _0x4c2a4b=_0xb59f8c;if(_0x298cd3){logger[_0x4c2a4b('0xf')](_0x4c2a4b('0x4e')),logger[_0x4c2a4b('0xf')](_0x4c2a4b('0x67'),_0x298cd3['id']);switch(_0x47ac41['type']){case _0x4c2a4b('0x16'):logger[_0x4c2a4b('0xf')](_0x4c2a4b('0x3d'),'Displaying\x20ticket\x20to\x20agent...'),emit(util[_0x4c2a4b('0x4a')]('user:%s',_0x31ad88[_0x4c2a4b('0x49')]),_0x4c2a4b('0x25'),{'recordId':_0x298cd3['id']});break;case _0x4c2a4b('0x1f'):logger['info'](_0x4c2a4b('0x3d'),_0x4c2a4b('0x42')),emit(util[_0x4c2a4b('0x4a')](_0x4c2a4b('0x41'),_0x31ad88[_0x4c2a4b('0x49')]),_0x4c2a4b('0x3'),{'uri':util[_0x4c2a4b('0x4a')](_0x4c2a4b('0x54'),_0x47ac41['remoteUri'],_0x298cd3['id'])});break;default:logger['error']('[OUTBOUND]',_0x4c2a4b('0x43'));}}})[_0xb59f8c('0xd')](function(_0x1d11df){const _0x5c3ee6=_0xb59f8c;logger[_0x5c3ee6('0x56')](_0x5c3ee6('0x24'),JSON[_0x5c3ee6('0x68')](_0x1d11df));});},exports[_0x355e9e('0x22')]=function(_0x11092a,_0x42cf8a,_0x9a5f27,_0x1cb813,_0x239ae5,_0x135b12){const _0x548e8a=_0x355e9e;let _0x2610af,_0x2543d4;return _0x135b12['remoteUri']=intUtil[_0x548e8a('0x65')](_0x135b12[_0x548e8a('0x4d')]),_0x135b12[_0x548e8a('0x62')]=intUtil[_0x548e8a('0x65')](_0x135b12[_0x548e8a('0x62')]),_0x239ae5&&_0x239ae5[_0x548e8a('0x39')]?(logger[_0x548e8a('0xf')]('['+_0x42cf8a[_0x548e8a('0x1b')][_0x548e8a('0x29')]()+']',_0x548e8a('0x2d')),_0x42cf8a[_0x548e8a('0x3a')]=util['format']('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x135b12[_0x548e8a('0x62')],_0x42cf8a['uniqueid'],md5(_0x42cf8a[_0x548e8a('0x0')]))):_0x42cf8a['recordingURL']='',headers[_0x548e8a('0x2b')]=getAuth(_0x135b12),getUser(_0x135b12)[_0x548e8a('0x11')](function(_0xd01129){const _0x54dd69=_0x548e8a;return _0x2610af=_0xd01129,logger[_0x54dd69('0xf')](_0x54dd69('0x32'),_0x2610af['id']),getEndUser(_0x135b12,_0x42cf8a[_0x54dd69('0x6b')],_0x42cf8a[_0x54dd69('0x5')]);})[_0x548e8a('0x11')](function(_0x4edf83){const _0x1422ab=_0x548e8a;return _0x2543d4=_0x4edf83,logger[_0x1422ab('0xf')](_0x1422ab('0x69'),_0x2543d4['id']),getTicket(_0x135b12,_0x2610af,_0x2543d4,_0x9a5f27,_0x42cf8a);})['then'](function(_0x4c65d1){const _0x1b3aa7=_0x548e8a;_0x4c65d1&&(logger[_0x1b3aa7('0xf')](_0x1b3aa7('0x4e')),logger[_0x1b3aa7('0xf')](_0x1b3aa7('0x67'),_0x4c65d1['id']));})[_0x548e8a('0xd')](function(_0x59042c){const _0x1003ba=_0x548e8a;logger[_0x1003ba('0x56')]('['+_0x42cf8a['lastevent']['toUpperCase']()+']',JSON[_0x1003ba('0x68')](_0x59042c));});};
\ No newline at end of file