adding automatic KA lookup from ticket
This commit is contained in:
parent
10f64409bd
commit
09b26a57f1
@ -38,6 +38,26 @@ function App() {
|
||||
}
|
||||
}, [isLoggedIn, token]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleMessage = (event) => {
|
||||
if (event.data.type === 'navigate-to-ka') {
|
||||
const kaNumber = event.data.kaNumber;
|
||||
console.log('Navigating to KA:', kaNumber);
|
||||
|
||||
const article = articles.find(a => a.ka_number === kaNumber);
|
||||
if (article) {
|
||||
handleArticleClick(article);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleMessage);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', handleMessage);
|
||||
}
|
||||
}, [articles]);
|
||||
|
||||
const handleLoginSuccess = (user, authToken) => {
|
||||
setCurrentUser(user);
|
||||
setToken(authToken);
|
||||
|
||||
@ -7,7 +7,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
window.addEventListener('message', function(event) {
|
||||
console.log('Received message:', event.origin, event.data);
|
||||
|
||||
if (event.origin !== 'https://jvis.freshdesk.com') {
|
||||
if (event.origin !== 'https://kb.jv.com') {
|
||||
console.log('Ignoring message from wrong origin');
|
||||
return;
|
||||
}
|
||||
@ -22,6 +22,25 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
.then(function (client) {
|
||||
console.log('KB app initialized');
|
||||
|
||||
// Check if ticket already has a KA number and navigate to it
|
||||
client.data.get('ticket')
|
||||
.then(function(data) {
|
||||
const existingKA = data.ticket.custom_fields.cf_ka_number;
|
||||
console.log('Existing KA in ticket:', existingKA);
|
||||
|
||||
if (existingKA) {
|
||||
// Send message to KB iframe to navigate to this article
|
||||
const iframe = document.getElementById('kb-iframe');
|
||||
iframe.contentWindow.postMessage({
|
||||
type: 'navigate-to-ka',
|
||||
kaNumber: existingKA
|
||||
}, 'https://kb.jv.com');
|
||||
}
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error('Error reading ticket:', error);
|
||||
});
|
||||
|
||||
document.getElementById('insert-ka-btn').addEventListener('click', function() {
|
||||
console.log('Insert button clicked, currentKA:', currentKA);
|
||||
|
||||
@ -40,7 +59,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
.then(function(data) {
|
||||
return client.interface.trigger('showNotify', {
|
||||
type: 'success',
|
||||
message: 'KA# ' + currentKA + ' attached'
|
||||
message: currentKA + ' attached to ticket'
|
||||
});
|
||||
})
|
||||
.catch(function(error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user