from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

class TelegramBot:

    #Token du bot Telegram
    TOKEN = '7150777483:AAHBJ86IBcb7KDM8vDong3ONCCYyw28a2FI'

    # Constructeur : initialise le bot Telegram
    def __init__(self):
        self.application = Application.builder().token(TelegramBot.TOKEN).build()
        self._add_handlers()

    # Ajouter les gestionnaires de commandes /start et /chatid
    def _add_handlers(self):
        self.application.add_handler(CommandHandler('start', self.start))
        self.application.add_handler(CommandHandler('chatid', self.chatid))

    # ENvoi une message de bienvenue à l'utilisateur quand il clic sur "start"
    async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
        await update.message.reply_text('Hello! Utilisez /chatid pour obtenir votre identifiant de chat.')

    # Récupère et affiche le chat ID de l'utilisateur
    async def chatid(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
        chat_id = update.message.chat_id
        await update.message.reply_text(f"Votre identifiant de chat est {chat_id}")
        print(chat_id)

    # Démarre le bot
    def run(self):
        self.application.run_polling()