zjor / mqtt2telegram

Provides secured REST API for sending messages to Telegram. Uses MQTT under the hood.
10 stars 1 forks source link

MQTT 2 Telegram

logo

@Mqtt2TelegramBot bot allows you to add notification in your project in minutes with almost no coding. Within the bot you subscribe to a topic of your choice. The topic name reflects the type of the event of your interest (e.g. IoT sensor reading, CI/CD pipeline status, any regular job you need to report status of). After you subscribe to the topic by issuing a command /sub topic the bot generates a private API for you and returns a command you can use to start sending messages to yourself immediately.

Features

Implementation details

The bot uses MQTT under the hood, when you subscribe to a topic it subscribes to ${chatId}/${topic} in MQTT thus allowing users to have their own set of topics. It is possible to fork the repo and deploy it with your own MQTT broker, in this case you will be able to send notifications directly to MQTT.

This is how you can send messages directly to MQTT given you have your own deployment:

Text message

mqtt pub -h ${MQTT_HOST} -p 8883 -s -u ${MQTT_USER} --password ${MQTT_PASSWORD} -t "${chatId}/${topic}" -m 'Hello world'

Image

mqtt pub -h ${MQTT_HOST} -p 8883 -s -u ${MQTT_USER} --password ${MQTT_PASSWORD} -t "${chatId}/${topic}" -m:file ~/tmp/img.jpeg -ct 'image:img.jpeg'

Stack

REST API Authentication

Basic authorization of telegramId:secret

Libraries