add telegram handling script für anmeldung
parent
9d850d8b15
commit
946090ed54
@ -0,0 +1,52 @@
|
||||
import os
|
||||
import logging
|
||||
from flask import Flask, request, jsonify
|
||||
#from win10toast import ToastNotifier
|
||||
import asyncio
|
||||
import subprocess
|
||||
import signal
|
||||
import psutil
|
||||
import telegram
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters
|
||||
import telegram.error
|
||||
|
||||
logging.basicConfig(filename='osiris_telegram.log', level=logging.DEBUG, format='%(asctime)s %(message)s')
|
||||
|
||||
####
|
||||
# Telegramm Functions
|
||||
####
|
||||
|
||||
# Telegram bot token
|
||||
TELEGRAM_BOT_TOKEN = '6984289827:AAHNUM4F_U6233oa75nX5jXyQY6vC0NlZvw'
|
||||
|
||||
# File to store subscriber chat IDs
|
||||
SUBSCRIBERS_FILE = 'telegramm_subscribers.txt'
|
||||
|
||||
async def start_bot(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
chat_id = update.message.chat_id
|
||||
save_subscriber(chat_id)
|
||||
await context.bot.send_message(chat_id=update.effective_chat.id, text="Sie wurden angemeldet für Nachrichten vom nuc_morroc.")
|
||||
|
||||
def load_subscribers():
|
||||
"""Load subscriber chat IDs from the file."""
|
||||
if os.path.exists(SUBSCRIBERS_FILE):
|
||||
with open(SUBSCRIBERS_FILE, 'r') as file:
|
||||
return [line.strip() for line in file.readlines()]
|
||||
return []
|
||||
|
||||
def save_subscriber(chat_id):
|
||||
"""Save a new subscriber chat ID to the file."""
|
||||
with open(SUBSCRIBERS_FILE, 'a') as file:
|
||||
file.write(f"{chat_id}\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.info("Starte Telegram-Bot")
|
||||
|
||||
telegramm_app = ApplicationBuilder().token(TELEGRAM_BOT_TOKEN).build()
|
||||
|
||||
start_handler = CommandHandler('start', start_bot)
|
||||
telegramm_app.add_handler(start_handler)
|
||||
|
||||
telegramm_app.run_polling()
|
||||
|
Loading…
Reference in New Issue