📖
📈 Intermédiaire
Python : créer un bot Telegram en 20 minutes (sans serveur)
1 min de lecture
1,650 vues
09 May 2026
? Créer un bot Telegram avec Python en 20 minutes
Un bot Telegram peut envoyer des notifications, répondre aux messages, surveiller des prix... et vous pouvez le créer sans serveur.
pip install python-telegram-bot
? Étape 1 — Obtenir un token
1
Ouvrir Telegram
Cherchez @BotFather
Cherchez @BotFather
2
Créer
Envoyez /newbot → choisissez un nom → recevez votre TOKEN
Envoyez /newbot → choisissez un nom → recevez votre TOKEN
? Bot basique
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
TOKEN = "VOTRE_TOKEN_ICI"
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Bonjour ! Je suis votre bot ?")
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(f"Vous avez dit : {{update.message.text}}")
app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(MessageHandler(filters.TEXT, echo))
app.run_polling()
print("Bot démarré !")
? Lancez le script, ouvrez Telegram, cherchez votre bot et tapez /start !
? Envoyer des notifications automatiques
import requests
TOKEN = "VOTRE_TOKEN"
CHAT_ID = "VOTRE_CHAT_ID" # Obtenez-le via @userinfobot
def notifier(message):
url = f"https://api.telegram.org/bot{{TOKEN}}/sendMessage"
requests.post(url, json={{"chat_id": CHAT_ID, "text": message}})
notifier("? Prix Bitcoin sous 60 000 $ !")
Combinez ce bot avec le script de surveillance de prix vu dans le tutoriel précédent pour des alertes automatiques.