Telegram: Auto-Link bei /start und normalen Nachrichten

Wenn eine Telegram-Nachricht von einem nicht verknüpften Chat eingeht:
- Sucht nach Sessions mit diesem Bot, die noch keine Chat-ID haben
- Genau 1 unverknüpfte Session → automatisch zuweisen + Bestätigung
- 0 oder mehrere → Chat-ID anzeigen, manuell im Web-UI zuweisen

Neue DB-Methode: FindUnlinkedSessionsForBot(botId)
This commit is contained in:
Meleki committed 2026-03-08 23:00:13 +01:00
1 parent bed4b1687e
commit 4f847bd33d
2 files changed
+47 -8

No files matched your search

+9 -3
View File
@@ -1332,11 +1332,17 @@ public class DatabaseService
{
using var conn = CreateConnection();
var chatIdStr = chatId.ToString();
// Erst exakte Chat-ID-Verknüpfung suchen
var session = await conn.QuerySingleOrDefaultAsync<SessionRecord>(
return await conn.QuerySingleOrDefaultAsync<SessionRecord>(
"SELECT * FROM sessions WHERE telegram_bot_id = @botId AND telegram_chat_id = @chatIdStr AND is_deleted = 0",
new { botId, chatIdStr });
return session;
}
public async Task<IEnumerable<SessionRecord>> FindUnlinkedSessionsForBot(string botId)
{
using var conn = CreateConnection();
return await conn.QueryAsync<SessionRecord>(
"SELECT * FROM sessions WHERE telegram_bot_id = @botId AND (telegram_chat_id IS NULL OR telegram_chat_id = '') AND is_deleted = 0",
new { botId });
}
public async Task<IEnumerable<SessionRecord>> GetUserSessions(string userId)