65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
import logging
|
|
import os
|
|
import asyncio
|
|
from dotenv import load_dotenv
|
|
from telegram import Update
|
|
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
|
|
|
# Chargement du token
|
|
load_dotenv()
|
|
API_TOKEN = os.getenv("API_TOKEN")
|
|
|
|
# Configuration du logging
|
|
logging.basicConfig(
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
level=logging.INFO
|
|
)
|
|
|
|
async def get_info(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
"""Affiche toutes les informations disponibles lors de la réception d'un message"""
|
|
user = update.effective_user
|
|
chat = update.effective_chat
|
|
msg = update.effective_message
|
|
|
|
print("\n" + "="*40)
|
|
print("🎯 NOUVELLE INTERACTION DÉTECTÉE")
|
|
print("="*40)
|
|
|
|
if user:
|
|
print(f"👤 UTILISATEUR (Auteur) :")
|
|
print(f" - ID : {user.id}")
|
|
print(f" - Nom : {user.full_name}")
|
|
print(f" - Username : @{user.username if user.username else 'N/A'}")
|
|
print(f" - Est un Bot : {user.is_bot}")
|
|
else:
|
|
print("👤 UTILISATEUR : Non disponible (Post de canal anonyme)")
|
|
|
|
print(f"\n💬 CONTEXTE DU CHAT :")
|
|
print(f" - Chat ID : {chat.id}")
|
|
print(f" - Titre : {chat.title if chat.title else 'Conversation Privée'}")
|
|
print(f" - Type : {chat.type}")
|
|
|
|
print(f"\n📝 MESSAGE :")
|
|
print(f" - Contenu : {msg.text if msg.text else '[Média/Autre]'}")
|
|
print("="*40 + "\n")
|
|
|
|
# On répond à l'utilisateur pour confirmer
|
|
if msg:
|
|
await msg.reply_text(f"✅ Infos reçues !\nTon ID : {user.id if user else 'N/A'}\nChat ID : {chat.id}")
|
|
|
|
if __name__ == '__main__':
|
|
if not API_TOKEN:
|
|
print("❌ Erreur : API_TOKEN non trouvé dans le .env")
|
|
exit(1)
|
|
|
|
# Création de l'application de test
|
|
application = ApplicationBuilder().token(API_TOKEN).build()
|
|
|
|
# On écoute absolument TOUT (messages, posts de canaux, etc.)
|
|
application.add_handler(MessageHandler(filters.ALL, get_info))
|
|
|
|
print("🚀 SCRIPT DE TEST DÉMARRÉ")
|
|
print("👉 Envoie un message au bot pour voir tes informations s'afficher ici...")
|
|
|
|
application.run_polling()
|