Cómo crear un Bot de Telegram?
Hola 👋 soy YOSS, en este post te enseñaré a crear un Bot de Telegram con Python usando la librería python-telegrama-bot. No necesitas conocimientos avanzados de Python ni de la API de Bots de Telegram, ya que la librería lo simplifica todo. Y bueno comenzamos.
Primero instalamos la librería usando pip(el gestor de paquetes de Python).
Vamos al terminar e ingresamos:
pip install python-telegram-bot
Esperamos a que se instale y listo 👌
Ahora vamos a crear un archivo bot.py donde pondremos el código del bot. Importamos las referencias.
Esto le dice Python que va a utilizar de la librería.
Ahora crearemos la función Main el esqueleto básico de nuestro bot
Aquí primero creamos la instancia del bot creando un objeto Updater con el parámetro TOKEN que es el nos da BotFather al crear un bot. Luego creamos el primer manejador que define que cuando lancemos el comando “/start” va a ejecutar la función start y por último ponemos el bot en espera de nuestros mensajes. Fuera de la función Main la mandamos a ejecutar ( main() ) para que todo esto surta efecto.
Ahora crearemos el diálogo de bienvenida de la siguiente forma:
Recuerda que puedes usar las comillas triples para crear textos multilínea.
Y ahora la función start que es lo que hará nuestro bot al ejecutar el comando /start
Aquí lo que estamos haciendo es decirle al bot que mandé un saludo "Hello", seguido del nombre del usuario que está utilizando nuestro bot y el mensaje que habíamos definido anteriormente. Y Listo 👌 con este código tan simple ya hemos creado un bot de telegram si quieres aprender a desplegarlo y ponerlo en funcionamiento sígueme para ver mi siguiente post si quieres probarlo solo introduce el TOKEN que te dió BotFather y ejecuta en el terminal
python bot.py
Ve a telegram, abre tu bot y manda "/start" y ve que pasa. Recuerda que puedes pasar por mi perfil de GitHub y ahí encontrarás el código de un bot que hize, es muy sencillo y te puede servir de ayuda. Sin más espero que te haya gustado 😊 el post.
✌️ CODE 4EVER ✌️
Ten articles before and after
Simple Telegram Bot using API’s. A Simple Telegram Bot which can respond… – Telegram Group
Making our First Telegram Bot [Part -2] – Telegram Group
Bots! What are they? Let’s make a Telegram Bot [Part -1] – Telegram Group
How I Create “Sembako Bot” using Google Cloud – Telegram Group
How to build a Telegram bot to show Chainlink price feeds – Telegram Group
Send APK automatically to Telegram using Dart/Flutter – Telegram Group
IntruderDet —An Intruder Detection Bot for my Appartment – Telegram Group
Телеграм бот для уведомлений об ордерах Binance – Telegram Group