feat: Permanente Tastatur mit 6 Schnellzugriff-Buttons
This commit is contained in:
parent
80dd6ae34c
commit
8d9e2bbbba
1 changed files with 42 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ import os
|
|||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from telegram import BotCommand, Update
|
||||
from telegram import BotCommand, Update, ReplyKeyboardMarkup, KeyboardButton
|
||||
from telegram.ext import (
|
||||
Application, CommandHandler, MessageHandler, filters, ContextTypes,
|
||||
)
|
||||
|
|
@ -25,6 +25,25 @@ BOT_COMMANDS = [
|
|||
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 requests as _req
|
||||
import llm
|
||||
|
|
@ -70,7 +89,8 @@ async def cmd_start(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
|
|||
"/report — Tagesbericht\n"
|
||||
"/check — Monitoring-Check\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}")
|
||||
|
||||
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):
|
||||
return
|
||||
question = update.message.text
|
||||
if not question:
|
||||
text = update.message.text
|
||||
if not text:
|
||||
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...")
|
||||
try:
|
||||
data = context.gather_context_for_question(question)
|
||||
answer = llm.ask(question, data)
|
||||
await update.message.reply_text(answer[:4000])
|
||||
data = context.gather_context_for_question(text)
|
||||
answer = llm.ask(text, data)
|
||||
await update.message.reply_text(answer[:4000], reply_markup=KEYBOARD)
|
||||
except Exception as e:
|
||||
log.exception("Fehler bei Freitext")
|
||||
await update.message.reply_text(f"Fehler: {e}")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue