UPDATE: FIX SESSIONID
parent
6e99954b46
commit
23c3d833bc
|
@ -11,7 +11,8 @@ public class ApiProxyController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
private const string N8nWebhookUrl = "http://10.50.50.61:5678/webhook/f2129606-7716-415b-a83b-b9c0e84b752f/chat";
|
// private const string N8nWebhookUrl = "http://10.50.50.61:5678/webhook/f2129606-7716-415b-a83b-b9c0e84b752f/chat";
|
||||||
|
private const string N8nWebhookUrl = "http://10.50.50.61:5678/webhook/chatbot";
|
||||||
|
|
||||||
public ApiProxyController(IHttpClientFactory httpClientFactory)
|
public ApiProxyController(IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
|
|
|
@ -481,16 +481,30 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
try {
|
try {
|
||||||
let sessionData = localStorage.getItem(STORAGE_KEY);
|
let sessionData = localStorage.getItem(STORAGE_KEY);
|
||||||
let data;
|
let data;
|
||||||
|
let sessionId = null;
|
||||||
if (sessionData) {
|
if (sessionData) {
|
||||||
data = JSON.parse(sessionData);
|
data = JSON.parse(sessionData);
|
||||||
|
|
||||||
|
if (!data.sessionId) {
|
||||||
|
sessionId = localStorage.getItem('n8n-chat/sessionId');
|
||||||
|
if (!sessionId) {
|
||||||
|
sessionId = generateSessionId();
|
||||||
|
localStorage.setItem('n8n-chat/sessionId', sessionId);
|
||||||
|
}
|
||||||
|
data.sessionId = sessionId;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
sessionId = localStorage.getItem('n8n-chat/sessionId');
|
||||||
|
if (!sessionId) {
|
||||||
|
sessionId = generateSessionId();
|
||||||
|
localStorage.setItem('n8n-chat/sessionId', sessionId);
|
||||||
|
}
|
||||||
data = {
|
data = {
|
||||||
timestamp: new Date().getTime(),
|
timestamp: new Date().getTime(),
|
||||||
|
sessionId: sessionId,
|
||||||
messages: []
|
messages: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
data.messages.push({ type, content });
|
data.messages.push({ type, content });
|
||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -564,6 +578,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
const data = JSON.parse(sessionData);
|
const data = JSON.parse(sessionData);
|
||||||
sessionId = data.sessionId;
|
sessionId = data.sessionId;
|
||||||
}
|
}
|
||||||
|
// Fallback: if still not found, try n8n-chat/sessionId
|
||||||
|
if (!sessionId) {
|
||||||
|
sessionId = localStorage.getItem('n8n-chat/sessionId');
|
||||||
|
}
|
||||||
|
console.log('Retrieved sessionId:', sessionId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error retrieving sessionId:', error);
|
console.error('Error retrieving sessionId:', error);
|
||||||
}
|
}
|
||||||
|
@ -574,9 +593,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
message: message
|
message: message,
|
||||||
})
|
|
||||||
sessionId: sessionId
|
sessionId: sessionId
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return response.json().catch(() => response.text());
|
return response.json().catch(() => response.text());
|
||||||
|
|
Loading…
Reference in New Issue