feat: Permanente Tastatur mit 6 Schnellzugriff-Buttons

This commit is contained in:
Auto-Sync 2026-03-08 14:31:19 +01:00
parent 80dd6ae34c
commit 8d9e2bbbba

View file

@ -7,7 +7,7 @@ import os
sys.path.insert(0, os.path.dirname(__file__)) sys.path.insert(0, os.path.dirname(__file__))
from telegram import BotCommand, Update from telegram import BotCommand, Update, ReplyKeyboardMarkup, KeyboardButton
from telegram.ext import ( from telegram.ext import (
Application, CommandHandler, MessageHandler, filters, ContextTypes, Application, CommandHandler, MessageHandler, filters, ContextTypes,
) )
@ -25,6 +25,25 @@ BOT_COMMANDS = [
BotCommand("start", "Hilfe anzeigen"), BotCommand("start", "Hilfe anzeigen"),
] ]
KEYBOARD = ReplyKeyboardMarkup(
[
[KeyboardButton("📊 Status"), KeyboardButton("❌ Fehler"), KeyboardButton("📰 Feeds")],
[KeyboardButton("📋 Report"), KeyboardButton("🔧 Check"), KeyboardButton("🔇 Stille")],
],
resize_keyboard=True,
is_persistent=True,
)
BUTTON_MAP = {
"📊 Status": "status",
"❌ Fehler": "errors",
"📰 Feeds": "feeds",
"📋 Report": "report",
"🔧 Check": "check",
"🔇 Stille": "silence",
}
import context import context
import requests as _req import requests as _req
import llm import llm
@ -70,7 +89,8 @@ async def cmd_start(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
"/report — Tagesbericht\n" "/report — Tagesbericht\n"
"/check — Monitoring-Check\n" "/check — Monitoring-Check\n"
"/feeds — Feed-Status & Artikel\n\n" "/feeds — Feed-Status & Artikel\n\n"
"Oder einfach eine Frage stellen!" "Oder einfach eine Frage stellen!",
reply_markup=KEYBOARD,
) )
@ -234,18 +254,32 @@ async def cmd_feeds(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(f"Fehler: {e}") await update.message.reply_text(f"Fehler: {e}")
async def handle_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE): async def handle_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
"""Freitext-Fragen → Kontext sammeln → LLM → Antwort.""" """Button-Presses und Freitext-Fragen verarbeiten."""
if not _authorized(update): if not _authorized(update):
return return
question = update.message.text text = update.message.text
if not question: if not text:
return return
cmd = BUTTON_MAP.get(text)
if cmd == "status":
return await cmd_status(update, ctx)
elif cmd == "errors":
return await cmd_errors(update, ctx)
elif cmd == "feeds":
return await cmd_feeds(update, ctx)
elif cmd == "report":
return await cmd_report(update, ctx)
elif cmd == "check":
return await cmd_check(update, ctx)
elif cmd == "silence":
return await cmd_silence(update, ctx)
await update.message.reply_text("🤔 Denke nach...") await update.message.reply_text("🤔 Denke nach...")
try: try:
data = context.gather_context_for_question(question) data = context.gather_context_for_question(text)
answer = llm.ask(question, data) answer = llm.ask(text, data)
await update.message.reply_text(answer[:4000]) await update.message.reply_text(answer[:4000], reply_markup=KEYBOARD)
except Exception as e: except Exception as e:
log.exception("Fehler bei Freitext") log.exception("Fehler bei Freitext")
await update.message.reply_text(f"Fehler: {e}") await update.message.reply_text(f"Fehler: {e}")