Built motion from commit c49361c37b5f784889c8087ac6e0e91b7e6b561a. Version 3.0.0...
[motion-next.git] / server / services / ami / trigger / integration / freshdesk.js
1 const a1137_0x1ae1=['customVariable','customField','[QUEUE]','Tags','queue','Enduser\x20not\x20found,\x20creating\x20a\x20new\x20enduser!','%s/helpdesk/tickets/%d','none','Authorization','The\x20User\x20ID\x20is:','Enduser\x20created.','%s/api/v2/agents/me','contact','custom_fields','calleridname','toLowerCase','push','string','forEach','md5','debug','%s/api/v2/agents','format','email','mapValues','serverUrl','destcalleridname','value','<br>','Searching\x20enduser\x20with\x20phone','Variable','name','Recording\x20is\x20enabled!','remoteUri','%s/api/v2/contacts','toString','request-promise-native','map','Invalid\x20email\x20format,\x20using\x20the\x20admin\x20account!','Agent\x20found!','freshdesk','Subjects','type','trigger:browser:url','stripTrailingSlash','Descriptions','[OUTBOUND]','The\x20Enduser\x20ID\x20is:','recordingURL','emit','getString','[HTTP]','Ticket\x20created!','idField','outbound','catch','recordingFormat','Creating\x20new\x20ticket...','from','./util','length','user:%s','../../../../rediscache','lastevent','Fields','defaults','variableName','keyBy','content','Basic\x20%s','validateEmail','calleridnum','find','Enduser\x20found!','util','POST','destcalleridnum','stringify','base64','toUpperCase','info','The\x20Ticket\x20ID\x20is:','error','nameField','monitor_format','application/json','Agent\x20not\x20found,\x20using\x20the\x20admin\x20account!','merge','then','%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s','../../../../config/logger','GET','uniqueid','Admin\x20account\x20selected.'];(function(_0x5bf51d,_0x1ae1d7){const _0x4ca7b5=function(_0x1ee5c1){while(--_0x1ee5c1){_0x5bf51d['push'](_0x5bf51d['shift']());}};_0x4ca7b5(++_0x1ae1d7);}(a1137_0x1ae1,0xcc));const a1137_0x4ca7=function(_0x5bf51d,_0x1ae1d7){_0x5bf51d=_0x5bf51d-0x0;let _0x4ca7b5=a1137_0x1ae1[_0x5bf51d];return _0x4ca7b5;};const _0x5ab2ce=a1137_0x4ca7;'use strict';const _=require('lodash'),rp=require(_0x5ab2ce('0x14')),md5=require(_0x5ab2ce('0x3')),util=require(_0x5ab2ce('0x3a')),intUtil=require(_0x5ab2ce('0x2b')),logger=require(_0x5ab2ce('0x4a'))(_0x5ab2ce('0x18')),{getSocket}=require(_0x5ab2ce('0x2e')),io=getSocket(),headers={'Content-Type':_0x5ab2ce('0x45'),'Accept':_0x5ab2ce('0x45')};function emit(_0x1ee5c1,_0x34e76d,_0x1b7ec8){const _0x2c0e8c=_0x5ab2ce;io['to'](_0x1ee5c1)[_0x2c0e8c('0x21')](_0x34e76d,_0x1b7ec8);}function getTicket(_0x220c69,_0x3c845c,_0x86edf7,_0x51c4ed,_0x2d6f5c){const _0x30d838=_0x5ab2ce;logger[_0x30d838('0x40')](_0x30d838('0x29'));const _0x330593=_[_0x30d838('0x47')]({'responder_id':_0x3c845c['id'],'requester_id':_0x86edf7['id'],'name':util['format']('Caller\x20-\x20%s',_0x2d6f5c['calleridname']),'phone':_0x2d6f5c[_0x30d838('0x37')],'source':0x3,'priority':0x1,'status':0x2,'subject':intUtil[_0x30d838('0x22')](_0x51c4ed[_0x30d838('0x19')],_0x2d6f5c,'\x20'),'description':intUtil['getString'](_0x51c4ed[_0x30d838('0x1d')],_0x2d6f5c,_0x30d838('0xc')),'tags':getTags(_0x51c4ed[_0x30d838('0x51')],'name')},getCustomFields(_0x51c4ed[_0x30d838('0x30')],_0x2d6f5c));return _0x330593[_0x30d838('0x5b')]=_[_0x30d838('0x8')](_[_0x30d838('0x33')](_0x330593[_0x30d838('0x5b')],'id'),_0x30d838('0xb')),request({'uri':util[_0x30d838('0x6')]('%s/api/v2/tickets',_0x220c69[_0x30d838('0x11')]),'method':_0x30d838('0x3b'),'body':_0x330593})['then'](function(_0x42d9b0){const _0x2943fb=_0x30d838;return logger['info'](_0x2943fb('0x24')),_0x42d9b0;});}function getUser(_0x3a332a,_0x2ca378){const _0x29ab89=_0x5ab2ce;return intUtil[_0x29ab89('0x36')](_0x2ca378)?request({'uri':util['format'](_0x29ab89('0x5'),_0x3a332a[_0x29ab89('0x11')]),'qs':{'email':_0x2ca378}})[_0x29ab89('0x48')](function(_0x3a633a){const _0x223e53=_0x29ab89;return _0x3a633a['length']?(logger[_0x223e53('0x40')](_0x223e53('0x17')),_[_0x223e53('0x38')](_0x3a633a,function(_0x57deb6){const _0x4ce1e4=_0x223e53;return _0x57deb6[_0x4ce1e4('0x5a')][_0x4ce1e4('0x7')]===_0x2ca378;})):(logger[_0x223e53('0x40')](_0x223e53('0x46')),request({'uri':util[_0x223e53('0x6')](_0x223e53('0x59'),_0x3a332a[_0x223e53('0x11')])})[_0x223e53('0x48')](function(_0x163c23){const _0x4f10eb=_0x223e53;return logger[_0x4f10eb('0x40')](_0x4f10eb('0x4d')),_0x163c23;}));}):(logger['info'](_0x29ab89('0x16')),request({'uri':util[_0x29ab89('0x6')](_0x29ab89('0x59'),_0x3a332a[_0x29ab89('0x11')])})['then'](function(_0x37c572){const _0xb241ed=_0x29ab89;return logger[_0xb241ed('0x40')](_0xb241ed('0x4d')),_0x37c572;}));}function getEndUser(_0x26eb13,_0x218d08,_0x253313){const _0x57b4be=_0x5ab2ce;return logger[_0x57b4be('0x40')](_0x57b4be('0xd'),_0x253313),request({'uri':util[_0x57b4be('0x6')](_0x57b4be('0x12'),_0x26eb13[_0x57b4be('0x11')]),'qs':{'phone':_0x253313}})['then'](function(_0x39dbdd){const _0x52672d=_0x57b4be;return _0x39dbdd['length']?(logger[_0x52672d('0x40')](_0x52672d('0x39')),_[_0x52672d('0x38')](_0x39dbdd,{'phone':_0x253313})):(logger[_0x52672d('0x40')](_0x52672d('0x53')),request({'uri':util[_0x52672d('0x6')](_0x52672d('0x12'),_0x26eb13[_0x52672d('0x11')]),'method':_0x52672d('0x3b'),'body':{'name':_0x218d08,'phone':_0x253313}})[_0x52672d('0x48')](function(_0x8f3a1e){const _0x3ec9ea=_0x52672d;return logger[_0x3ec9ea('0x40')](_0x3ec9ea('0x58')),_0x8f3a1e;}));});}function getAuth(_0x3832a6){const _0x5bfd90=_0x5ab2ce;return util[_0x5bfd90('0x6')](_0x5bfd90('0x35'),Buffer[_0x5bfd90('0x2a')](_0x3832a6['apiKey']+':X')[_0x5bfd90('0x13')](_0x5bfd90('0x3e')));}function request(_0x14e113){const _0x4f1e96=_0x5ab2ce;return logger[_0x4f1e96('0x4')](_0x4f1e96('0x23'),JSON[_0x4f1e96('0x3d')](_0x14e113)),rp(_[_0x4f1e96('0x31')](_0x14e113,{'method':_0x4f1e96('0x4b'),'headers':headers,'json':!![]}));}function getTags(_0x4ff3f2,_0x7d4924){const _0x480785=_0x5ab2ce;let _0x1bf18a=[];return _0x4ff3f2&&_0x4ff3f2[_0x480785('0x2c')]>0x0&&(_0x1bf18a=_[_0x480785('0x15')](_0x4ff3f2,_0x7d4924)),_0x1bf18a;}function getCustomFields(_0x318158,_0x1988b6){const _0x3f8f89=_0x5ab2ce,_0x1d7444={'custom_fields':[]};return _0x318158[_0x3f8f89('0x2c')]>0x0&&_[_0x3f8f89('0x2')](_0x318158,function(_0xbd8bc9){const _0x380535=_0x3f8f89;if(_0xbd8bc9[_0x380535('0x1a')]===_0x380535('0x1')&&_0xbd8bc9[_0x380535('0x43')]&&!_0xbd8bc9[_0x380535('0x4f')])_0x1d7444[_0xbd8bc9[_0x380535('0x43')][_0x380535('0x5d')]()]=_0xbd8bc9[_0x380535('0x34')][_0x380535('0x13')]();else{if(_0xbd8bc9[_0x380535('0x1a')]===_0x380535('0x1')&&_0xbd8bc9[_0x380535('0x25')]&&_0xbd8bc9[_0x380535('0x4f')])_0x1d7444['custom_fields'][_0x380535('0x0')]({'id':_0xbd8bc9[_0x380535('0x25')],'value':_0xbd8bc9[_0x380535('0x34')][_0x380535('0x13')]()});else{if(_0xbd8bc9[_0x380535('0x1a')]==='variable'&&_0xbd8bc9[_0x380535('0x32')]&&_0xbd8bc9[_0x380535('0x25')]&&_0xbd8bc9[_0x380535('0x4f')])_0x1988b6[_0xbd8bc9['variableName']]&&_0x1d7444['custom_fields'][_0x380535('0x0')]({'id':_0xbd8bc9[_0x380535('0x25')],'value':_0x1988b6[_0xbd8bc9[_0x380535('0x32')]][_0x380535('0x13')]()});else _0xbd8bc9['type']===_0x380535('0x4e')&&_0xbd8bc9['Variable']&&_0xbd8bc9[_0x380535('0xe')]['name']&&_0xbd8bc9['idField']&&_0xbd8bc9[_0x380535('0x4f')]&&(_0x1988b6[_0xbd8bc9['Variable'][_0x380535('0xf')][_0x380535('0x5d')]()]&&_0x1d7444[_0x380535('0x5b')][_0x380535('0x0')]({'id':_0xbd8bc9[_0x380535('0x25')],'value':_0x1988b6[_0xbd8bc9[_0x380535('0xe')][_0x380535('0xf')][_0x380535('0x5d')]()][_0x380535('0x13')]()}));}}}),_0x1d7444;}exports[_0x5ab2ce('0x52')]=function(_0x3e7d47,_0x2f889e,_0x371152,_0x15b5bf,_0x4d3267,_0x30f65d){const _0x515340=_0x5ab2ce;let _0x34fc7e,_0x3f4a6b;return _0x30f65d[_0x515340('0x11')]=intUtil[_0x515340('0x1c')](_0x30f65d[_0x515340('0x11')]),_0x30f65d[_0x515340('0x9')]=intUtil[_0x515340('0x1c')](_0x30f65d[_0x515340('0x9')]),_0x4d3267&&_0x4d3267[_0x515340('0x44')]?(logger[_0x515340('0x40')](_0x515340('0x50'),'Recording\x20is\x20enabled!'),_0x2f889e[_0x515340('0x20')]=util[_0x515340('0x6')](_0x515340('0x49'),_0x30f65d['serverUrl'],_0x2f889e['uniqueid'],md5(_0x2f889e['uniqueid']))):_0x2f889e[_0x515340('0x20')]='',headers[_0x515340('0x56')]=getAuth(_0x30f65d),getUser(_0x30f65d,_0x15b5bf[_0x515340('0x7')])[_0x515340('0x48')](function(_0x52a6f7){const _0x509644=_0x515340;return _0x34fc7e=_0x52a6f7,logger[_0x509644('0x40')](_0x509644('0x57'),_0x34fc7e['id']),getEndUser(_0x30f65d,_0x2f889e[_0x509644('0x5c')],_0x2f889e['calleridnum']);})[_0x515340('0x48')](function(_0x16377f){const _0x3ca838=_0x515340;return _0x3f4a6b=_0x16377f,logger[_0x3ca838('0x40')](_0x3ca838('0x1f'),_0x3f4a6b['id']),getTicket(_0x30f65d,_0x34fc7e,_0x3f4a6b,_0x371152,_0x2f889e);})[_0x515340('0x48')](function(_0x335e08){const _0x2f1be9=_0x515340;_0x335e08&&_0x335e08['id']&&(logger['info'](_0x2f1be9('0x24')),logger[_0x2f1be9('0x40')](_0x2f1be9('0x41'),_0x335e08['id']),logger[_0x2f1be9('0x40')](_0x2f1be9('0x50'),'Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x2f1be9('0x6')](_0x2f1be9('0x2d'),_0x15b5bf[_0x2f1be9('0xf')]),_0x2f1be9('0x1b'),{'uri':util[_0x2f1be9('0x6')](_0x2f1be9('0x54'),_0x30f65d['remoteUri'],_0x335e08['id'])}));})[_0x515340('0x27')](function(_0x45fdde){const _0xa18afe=_0x515340;logger['error'](_0xa18afe('0x50'),JSON[_0xa18afe('0x3d')](_0x45fdde));});},exports[_0x5ab2ce('0x26')]=function(_0x16b6d1,_0x4774c5,_0x1b37b0,_0x1b2698,_0x963165,_0x1d2b34,_0x8e6079){const _0x1783db=_0x5ab2ce;let _0x1484c9,_0x3a43bf;return _0x1d2b34[_0x1783db('0x11')]=intUtil[_0x1783db('0x1c')](_0x1d2b34['remoteUri']),_0x1d2b34[_0x1783db('0x9')]=intUtil['stripTrailingSlash'](_0x1d2b34['serverUrl']),_0x8e6079&&_0x8e6079[_0x1783db('0x28')]&&_0x8e6079[_0x1783db('0x28')]!==_0x1783db('0x55')&&(logger[_0x1783db('0x40')](_0x1783db('0x1e'),_0x1783db('0x10')),_0x4774c5[_0x1783db('0x20')]=util[_0x1783db('0x6')]('%s/api/voice/recordings/%s/downloads?type=uniqueid&token=%s',_0x1d2b34['serverUrl'],_0x4774c5[_0x1783db('0x4c')],md5(_0x4774c5[_0x1783db('0x4c')]))),headers[_0x1783db('0x56')]=getAuth(_0x1d2b34),getUser(_0x1d2b34,_0x1b2698[_0x1783db('0x7')])['then'](function(_0x1b45d7){const _0x42180d=_0x1783db;return _0x1484c9=_0x1b45d7,logger[_0x42180d('0x40')]('The\x20User\x20ID\x20is:',_0x1484c9['id']),getEndUser(_0x1d2b34,_0x4774c5[_0x42180d('0xa')],_0x4774c5[_0x42180d('0x3c')]);})[_0x1783db('0x48')](function(_0x5ce479){const _0xa12475=_0x1783db;return _0x3a43bf=_0x5ce479,logger[_0xa12475('0x40')]('The\x20Enduser\x20ID\x20is:',_0x3a43bf['id']),getTicket(_0x1d2b34,_0x1484c9,_0x3a43bf,_0x1b37b0,_0x4774c5);})[_0x1783db('0x48')](function(_0x404078){const _0x46c4d7=_0x1783db;_0x404078&&_0x404078['id']&&(logger[_0x46c4d7('0x40')](_0x46c4d7('0x24')),logger[_0x46c4d7('0x40')](_0x46c4d7('0x41'),_0x404078['id']),logger[_0x46c4d7('0x40')]('[OUTBOUND]','Displaying\x20ticket\x20to\x20agent\x20in\x20a\x20new\x20tab...'),emit(util[_0x46c4d7('0x6')](_0x46c4d7('0x2d'),_0x1b2698[_0x46c4d7('0xf')]),_0x46c4d7('0x1b'),{'uri':util[_0x46c4d7('0x6')]('%s/helpdesk/tickets/%d',_0x1d2b34[_0x46c4d7('0x11')],_0x404078['id'])}));})[_0x1783db('0x27')](function(_0x433da5){const _0x15037a=_0x1783db;logger[_0x15037a('0x42')](_0x15037a('0x1e'),JSON[_0x15037a('0x3d')](_0x433da5));});},exports['unmanaged']=function(_0x234bf0,_0x3a4c90,_0x248342,_0x43a1b6,_0x254a57,_0x104f7e){const _0x5ce7f1=_0x5ab2ce;let _0x2b055c,_0x1841e4;return _0x104f7e['remoteUri']=intUtil[_0x5ce7f1('0x1c')](_0x104f7e['remoteUri']),_0x104f7e[_0x5ce7f1('0x9')]=intUtil['stripTrailingSlash'](_0x104f7e['serverUrl']),_0x254a57&&_0x254a57[_0x5ce7f1('0x44')]?(logger['info']('['+_0x3a4c90[_0x5ce7f1('0x2f')][_0x5ce7f1('0x3f')]()+']',_0x5ce7f1('0x10')),_0x3a4c90[_0x5ce7f1('0x20')]=util[_0x5ce7f1('0x6')](_0x5ce7f1('0x49'),_0x104f7e[_0x5ce7f1('0x9')],_0x3a4c90[_0x5ce7f1('0x4c')],md5(_0x3a4c90['uniqueid']))):_0x3a4c90[_0x5ce7f1('0x20')]='',headers['Authorization']=getAuth(_0x104f7e),getUser(_0x104f7e,'')[_0x5ce7f1('0x48')](function(_0x2c04c4){const _0x1b7b54=_0x5ce7f1;return _0x2b055c=_0x2c04c4,logger[_0x1b7b54('0x40')](_0x1b7b54('0x57'),_0x2b055c['id']),getEndUser(_0x104f7e,_0x3a4c90['calleridname'],_0x3a4c90[_0x1b7b54('0x37')]);})[_0x5ce7f1('0x48')](function(_0x4c78ec){const _0x257156=_0x5ce7f1;return _0x1841e4=_0x4c78ec,logger[_0x257156('0x40')](_0x257156('0x1f'),_0x1841e4['id']),getTicket(_0x104f7e,_0x2b055c,_0x1841e4,_0x248342,_0x3a4c90);})[_0x5ce7f1('0x48')](function(_0x366672){const _0x9cb5e0=_0x5ce7f1;_0x366672&&(logger[_0x9cb5e0('0x40')](_0x9cb5e0('0x24')),logger['info'](_0x9cb5e0('0x41'),_0x366672['id']));})[_0x5ce7f1('0x27')](function(_0x5eae30){const _0x16fde3=_0x5ce7f1;logger[_0x16fde3('0x42')]('['+_0x3a4c90[_0x16fde3('0x2f')][_0x16fde3('0x3f')]()+']',JSON[_0x16fde3('0x3d')](_0x5eae30));});};