Cómo crear un bot de Telegram

INTRODUCCIÓN

En este post voy a explicar cómo hacer funcionar un robot de ejemplo para Telegram.

Voy a seguir todos los pasos necesarios para poner a funcionar un bot de ejemplo.

Aquí encontramos el ejemplo , así como muchos otros en otros lenguajes como PHP, Python, etc.

El proceso es muy sencillo.

GESTIÓN DEL BOT CON BOTFATHER

Abrimos el cliente de Telegram y en la lupa para buscar, ponemos: botfather.

Le escribimos /help:

They call me the Botfather, I can help you create and set up Telegram bots. Please read this manual before we begin: https://core.telegram.org/bots

You can control me by sending these commands:

/newbot – create a new bot

/token – generate authorization token

/revoke – revoke bot access token

/setname – change a bot’s name

/setdescription – change bot description

/setabouttext – change bot about info

/setuserpic – change bot profile photo

/setinline – change inline settings

/setinlinegeo – toggle inline location requests

/setinlinefeedback – change inline feedback settings

/setcommands – change bot commands list

/setjoingroups – can your bot be added to groups?

/setprivacy – what messages does your bot see in groups?

/deletebot – delete a bot

/cancel – cancel the current operation

Estos son todos los comandos disponibles a la hora de gestionar tu(s) bot(s).

Pero el que nos interesa es /newbot y /token.

CREANDO UN NUEVO BOT CON BOTFATHER

  1. Le escribimos /newbot.
  2. Nos preguntará qué nombre queremos para nuestro bot, y debemos elegir uno acabado en “bot“, por ejemplo DevoxyzBot.
  3. Una vez acertemos con un nombre que no esté registrado, nos enviará un mensaje con el token, que lo necesitaremos para hacer funcionar el robot con Telegram.

BotFather nos debe haber dado un token, nos servirá para el siguiente paso.

CONSIGUIENDO EL CÓDIGO FUENTE DEL BOT Y LANZÁNDOLO

  1. Git clone.
  2. Cd DemoBot.
  3. Git clone.
  4. Npm install.
  5. Edita el fichero package.json y rellena la variable token con el valor que te dio BotFather.
  6. Npm run tg.

Deberías ver lo siguiente:

demo_bot@0.0.1 tg /Users/aberope/robots/Telegram/DemoBot

token=’XXXXXXXXX:AXHXbXCX7XLX6XuXYXGXYXYXeXYXWX_XDXY’ node telegram_bot.js

PROBANDO EL BOT

Tenemos 2 opciones:

  1. Buscar el bot por su nombre en el cliente de Telegram.
  2. Usar el enlace que nos dio BotFather para hablar directamente con él.

Una vez encontrado, mantenemos una conversación con él, como la siguiente:

Espero que os haya gustado, esto es todo de momento.

Tecnologia
Cómo crear un bot multi-equipo para Slack Devopensource y Redsys

Comments