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:
Meleki committed 2026-03-08 19:27:05 +01:00
1 parent 3b7bdb7a20
commit ec73ccd71e
13 files changed
+907 -371

No files matched your search

+62 -14
View File
@@ -83,6 +83,13 @@
</div>
<div class="card-grid" id="cronjobCards"></div>
</section>
<section>
<div class="section-header">
<h2><i class="fa fa-paper-plane"></i> Telegram Bots</h2>
<button id="newTelegramBotBtn" class="section-add-btn"><i class="fa fa-plus"></i> Neuer Bot</button>
</div>
<div class="card-grid" id="telegramBotCards"></div>
</section>
<section id="sharedLinksSection" hidden>
<div class="section-header">
<h2>Geteilte Links</h2>
@@ -143,21 +150,18 @@
<label>Benutzerdefinierte Befehle</label>
<div class="custom-commands" id="customCommandsList"></div>
<button type="button" id="addCommandBtn" class="add-cmd-btn">+ Befehl hinzufügen</button>
<label><i class="fa fa-paper-plane"></i> <b>Telegram Bot</b></label>
<span>Erstelle einen Bot via <a href="https://t.me/BotFather" target="_blank">@BotFather</a></span>
<label>Bot-Token</label>
<input type="text" id="sessionTelegramToken" placeholder="123456:ABC-DEF..." autocomplete="off">
<label>Webhook-Secret</label>
<input type="text" id="sessionTelegramSecret" readonly style="opacity: var(--semi-transparent); ">
<label>Erlaubte Chat-IDs</label>
<input type="text" id="sessionTelegramAllowed" placeholder="Kommagetrennt, z.B. 123456,789012">
<small class="form-hint">Der verknüpfte Owner ist automatisch erlaubt. Weitere Chat-IDs hier eintragen.</small>
<label>Status</label>
<div id="sessionTelegramStatusBox" class="telegram-status-box">Kein Status verfügbar</div>
<div class="telegram-actions">
<button type="button" id="sessionTelegramRegisterBtn" hidden>Webhook registrieren</button>
<button type="button" id="sessionTelegramDeleteBtn" class="danger-btn" hidden>Webhook entfernen</button>
<label><i class="fa fa-paper-plane"></i> <b>Telegram</b></label>
<label>Telegram Bot</label>
<div id="telegramBotSelectCard" class="agent-select-card">
<div class="agent-select-empty"><i class="fa fa-paper-plane"></i> Kein Bot zugewiesen</div>
</div>
<input type="hidden" id="telegramBotSelect" value="">
<label>Chat-ID</label>
<div class="input-with-btn">
<input type="text" id="sessionTelegramChatId" placeholder="Wird automatisch bei /start gesetzt" autocomplete="off" readonly>
<button type="button" id="sessionTelegramUnlink" class="icon-btn danger-btn" title="Verknüpfung lösen"><i class="fa fa-chain-broken"></i></button>
</div>
<small class="form-hint">Wird automatisch gesetzt wenn jemand /start an den Bot sendet.</small>
</div>
</div>
<div class="form-actions">
@@ -306,6 +310,49 @@
</div>
</template>
<template id="tpl-telegram-bot">
<div class="page form-page">
<header>
<button class="back-btn icon-btn" data-page="dashboard"><i class="fa fa-arrow-left"></i></button>
<h1 id="telegramBotPageTitle">Neuer Telegram Bot</h1>
</header>
<div class="page-content">
<div class="form">
<label>Name</label>
<input type="text" id="tgBotName" placeholder="z.B. Mein Hauptbot">
<label>Bot-Token</label>
<input type="text" id="tgBotToken" placeholder="123456:ABC-DEF..." autocomplete="off">
<small class="form-hint">Erstelle einen Bot via <a href="https://t.me/BotFather" target="_blank">@BotFather</a></small>
<label class="checkbox-label">
<input type="checkbox" id="tgBotPublic">
<span>Public – andere User können diesen Bot in ihren Sessions verwenden</span>
</label>
<div id="tgBotSecretRow" hidden>
<label>Webhook-Secret</label>
<div class="input-with-btn">
<input type="text" id="tgBotSecret" readonly>
<button type="button" id="tgBotCopySecret" class="icon-btn" title="Kopieren"><i class="fa fa-clipboard"></i></button>
</div>
</div>
<div id="tgBotWebhookSection" hidden>
<label><i class="fa fa-plug"></i> <b>Webhook</b></label>
<div id="tgBotWebhookStatus" class="form-status-box"></div>
<div class="form-actions-inline">
<button type="button" id="tgBotWebhookRegister" class="positive-btn"><i class="fa fa-plug"></i> Registrieren</button>
<button type="button" id="tgBotWebhookInfo"><i class="fa fa-info-circle"></i> Status prüfen</button>
<button type="button" id="tgBotWebhookDelete" class="danger-btn"><i class="fa fa-unlink"></i> Entfernen</button>
</div>
</div>
<div class="form-actions">
<button id="tgBotSaveBtn">Speichern</button>
<button id="tgBotCancelBtn">Abbrechen</button>
<button id="tgBotDeleteBtn" class="danger-btn" hidden>Löschen</button>
</div>
</div>
</div>
</div>
</template>
<template id="tpl-chat">
<div class="page chat-page">
<header>
@@ -575,6 +622,7 @@
<script src="js/avatar-editor.js"></script>
<script src="js/pages/dashboard.js"></script>
<script src="js/pages/cronjob-page.js"></script>
<script src="js/pages/telegram-bot-page.js"></script>
<script src="js/pages/agent-page.js"></script>
<script src="js/pages/session-page.js"></script>
<script src="js/pages/chat-page.js"></script>