Hoy vamos a crear un canal de Telegram para recibir mensajes. Útil para recibir notificaciones, alertas,… de forma automatizada o bajo demanda.

    Para empezar, hay que crear un canal con el bot @BotFather e introducir el nombre del canal y su respectivo usuario.

    Haremos dichas acciones con las siguientes opciones de ejemplo: /newbot > changeofhabit > changeofhabit_bot

    Ahora tendremos el canal creado t.me/changeofhabit_bot y al final del mensaje anterior, recibiremos un token (HTTP API)

    Para obtener el chatID, localizaremos el campo id del JSON al acceder a la URL siguiente en la que tendremos que añadir el token anterior. El formato de la URL debe ser la siguiente: https://api.telegram.org/botXXX:XXX/getUpdates

    Ahora crearemos un script muy básico para el envío de mensajes al canal:

    #!/bin/bash
    
    apiToken='6052810916:AAHhWaRs7nwINlAsl1LuHMowwgR_Kv6tolQ'
    chatId='148304351'
    
    curl -s -X POST https://api.telegram.org/bot$apiToken/sendMessage -d text="hello from $(hostname -f)!" -d chat_id=$chatId --output /dev/null

    y el resultado:

    Links informativos:

    One Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *