Inicio > Cursos > Bots & Automatizacion > Crear un bot de Telegram
Bots & AutomatizacionBots de TelegramLección 3 de 7

Crear un bot de Telegram

Telegram tiene una de las APIs de bots mas faciles del mundo. Habla con @BotFather para crear tu bot y obtener el token en 1 minuto.

from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters

async def start(update: Update, context):
    await update.message.reply_text(
        "Hola! Soy tu bot de Duobi 🤖\n"
        "Comandos:\n"
        "/quote - Cita random de programacion\n"
        "/joke - Chiste de programador"
    )

async def quote(update: Update, context):
    quotes = [
        "Talk is cheap. Show me the code. - Linus Torvalds",
        "First, solve the problem. Then, write the code. - John Johnson",
        "Code is like humor. When you have to explain it, its bad. - Cory House",
    ]
    import random
    await update.message.reply_text(random.choice(quotes))

app = Application.builder().token("TU_TOKEN").build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("quote", quote))
app.run_polling()
← Bot de moderacion y comandos avanzadosAutomatizar tareas repetitivas →

Practica esta lección

Resuelve los ejercicios del curso de Bots & Automatizacion en la app, gratis y con corrección automática.

Empezar a practicar