Telegram Bots als eigenständige Entität mit eigener Page
- Neue Tabelle 'telegram_bots' (bot_id, name, bot_token, webhook_secret, is_public)
- Automatische Migration bestehender Session-Telegram-Configs in telegram_bots
- Sessions verweisen via telegram_bot_id auf Bot (mehrere Sessions pro Bot möglich)
- Webhook-URL: /api/telegram/webhook/{botId} statt {sessionId}
- Eigene Telegram-Bot-Page (wie Agent/Cronjob/Session) statt Modal
- Bot-Page: Name, Token, Secret, Webhook-Verwaltung (registrieren/status/entfernen), Löschen
- Dashboard: Telegram Bots Section mit Cards (Name, maskierter Token, Session-Count)
- Session-Page: Bot-Picker (wie Agent-Picker) statt Token-Input, Chat-ID readonly + Unlink-Button
- Public-Flag: Bot kann von anderen Usern in ihren Sessions ausgewählt werden
- Vereinfacht: 1 Session = max. 1 Telegram Chat, allowed_chat_ids entfällt
- /start zeigt Chat-ID an, /unlink entfernt (Unlink nur über Web-UI)
- Nachrichten-Routing: Bot + Chat-ID → Session Lookup
This commit is contained in:
1 parent
3b7bdb7a20
commit
ec73ccd71e
13 files changed
+907
-371
No files matched your search
+68
-15
@@ -284,29 +284,61 @@ async function apiChangePassword(currentPassword, newPassword) {
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
// ── Telegram API (pro Session) ──
|
||||
// ── Telegram Bot API ──
|
||||
|
||||
async function apiSessionTelegramGet(sessionId) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram`);
|
||||
if (!resp.ok) return { configured: false };
|
||||
async function apiGetTelegramBots() {
|
||||
const resp = await fetch('/api/telegram/bots');
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiSessionTelegramSave(sessionId, botToken, webhookSecret, allowedChatIds) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram`, {
|
||||
method: 'PUT',
|
||||
async function apiGetTelegramBot(botId) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}`);
|
||||
if (!resp.ok) return null;
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiCreateTelegramBot(name, botToken) {
|
||||
const resp = await fetch('/api/telegram/bots', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ botToken, webhookSecret, allowedChatIds })
|
||||
body: JSON.stringify({ name, botToken })
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json().catch(() => ({}));
|
||||
throw new Error(err.error || 'Telegram-Config speichern fehlgeschlagen');
|
||||
throw new Error(err.error || 'Bot erstellen fehlgeschlagen');
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiSessionTelegramRegisterWebhook(sessionId, baseUrl) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram/register-webhook`, {
|
||||
async function apiGetAvailableTelegramBots() {
|
||||
const resp = await fetch('/api/telegram/bots/available');
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiUpdateTelegramBot(botId, name, botToken, isPublic) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, botToken, isPublic })
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json().catch(() => ({}));
|
||||
throw new Error(err.error || 'Bot speichern fehlgeschlagen');
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiDeleteTelegramBot(botId) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}`, { method: 'DELETE' });
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json().catch(() => ({}));
|
||||
throw new Error(err.error || 'Bot löschen fehlgeschlagen');
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiTelegramBotRegisterWebhook(botId, baseUrl) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}/register-webhook`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ baseUrl })
|
||||
@@ -315,18 +347,39 @@ async function apiSessionTelegramRegisterWebhook(sessionId, baseUrl) {
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiSessionTelegramWebhookInfo(sessionId) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram/webhook-info`);
|
||||
async function apiTelegramBotWebhookInfo(botId) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}/webhook-info`);
|
||||
if (!resp.ok) throw new Error('Webhook-Info fehlgeschlagen');
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiSessionTelegramDeleteWebhook(sessionId) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram/webhook`, { method: 'DELETE' });
|
||||
async function apiTelegramBotDeleteWebhook(botId) {
|
||||
const resp = await fetch(`/api/telegram/bots/${botId}/webhook`, { method: 'DELETE' });
|
||||
if (!resp.ok) throw new Error('Webhook-Löschung fehlgeschlagen');
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
// ── Session Telegram Config ──
|
||||
|
||||
async function apiSessionTelegramGet(sessionId) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram`);
|
||||
if (!resp.ok) return { configured: false };
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiSessionTelegramSave(sessionId, telegramBotId, chatId) {
|
||||
const resp = await fetch(`/api/sessions/${sessionId}/telegram`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ telegramBotId, chatId })
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json().catch(() => ({}));
|
||||
throw new Error(err.error || 'Telegram-Config speichern fehlgeschlagen');
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
async function apiGetSettings() {
|
||||
const resp = await fetch('/api/settings');
|
||||
if (!resp.ok) return {};
|
||||
|
||||
Reference in new issue
Block a user