UPDATE: FIX SESSIONID
parent
6e99954b46
commit
23c3d833bc
|
@ -11,7 +11,8 @@ public class ApiProxyController : ControllerBase
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -481,16 +481,30 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
try {
|
||||
let sessionData = localStorage.getItem(STORAGE_KEY);
|
||||
let data;
|
||||
|
||||
let sessionId = null;
|
||||
if (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 {
|
||||
sessionId = localStorage.getItem('n8n-chat/sessionId');
|
||||
if (!sessionId) {
|
||||
sessionId = generateSessionId();
|
||||
localStorage.setItem('n8n-chat/sessionId', sessionId);
|
||||
}
|
||||
data = {
|
||||
timestamp: new Date().getTime(),
|
||||
sessionId: sessionId,
|
||||
messages: []
|
||||
};
|
||||
}
|
||||
|
||||
data.messages.push({ type, content });
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
||||
} catch (error) {
|
||||
|
@ -564,6 +578,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
const data = JSON.parse(sessionData);
|
||||
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) {
|
||||
console.error('Error retrieving sessionId:', error);
|
||||
}
|
||||
|
@ -574,10 +593,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
message: message
|
||||
})
|
||||
message: message,
|
||||
sessionId: sessionId
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
return response.json().catch(() => response.text());
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue