- ${statusText}
+
+ ${s.name ? `${s.name} (${s.phone || 'unknown'})` : `Phone: ${s.phone || "unknown"}`}
+
+
+
+ ${statusText}
+
+
@@ -621,6 +628,42 @@
list.appendChild(card);
});
+
+ list.querySelectorAll(".deleteSessionBtn").forEach(btn => {
+ btn.addEventListener("click", () => {
+ const phone = btn.dataset.phone;
+ const id = btn.dataset.id;
+ if (id && phone && phone !== 'unknown') {
+ deleteSession(id, phone);
+ }
+ });
+ });
+ }
+
+ async function deleteSession(id, phone) {
+ if (!confirm(`Delete session for ${phone} and all its chat history?`)) return;
+
+ const { error: historyError } = await supabaseClient
+ .from('n8n_chat_histories')
+ .delete()
+ .eq('session_id', id);
+
+ if (historyError) {
+ alert('Error deleting chat history: ' + historyError.message);
+ return;
+ }
+
+ const { error: sessionError } = await supabaseClient
+ .from('sessions')
+ .delete()
+ .eq('id', id);
+
+ if (sessionError) {
+ alert('Error deleting session: ' + sessionError.message);
+ return;
+ }
+
+ await loadSessions();
}
// =============================