Files
summer/bot.py
T
chrispi 934efc996e
Deploy Summer to Server / deploy (push) Successful in 3s
boty nochmal angepasst
2026-10-17 04:10:54 +02:00

41 lines
1.2 KiB
Python

import os
import logging
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler
load_dotenv()
TOKEN = os.getenv("BOT_TOKEN")
CHAT_ID = os.getenv("ADMIN_CHAT_ID")
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO
)
async def post_init(application):
if CHAT_ID:
try:
await application.bot.send_message(
chat_id=CHAT_ID,
text="Das Deployment war erfolgreich. Ich bin zurück!"
)
except Exception as e:
print(f"Konnte Start-Nachricht nicht senden: {e}")
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_name = update.effective_user.first_name
await update.message.reply_text(f"Hallo {user_name} Dein Telegram Bot läuft über Gitea")
if __name__ == "__main__":
if not TOKEN:
print("Fehler: Kein BOT_TOKEN in der .env gefunden")
exit(1)
app = ApplicationBuilder().token(TOKEN).post_init(post_init).build()
app.add_handler(CommandHandler("start", start))
print("Bot wird gestartet und wartet auf Nachrichten!")
app.run_polling()