Skip to content

Provides secured REST API for sending messages to Telegram. Uses MQTT under the hood.

Notifications You must be signed in to change notification settings

zjor/mqtt2telegram

Repository files navigation

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

  • allows managing subscriptions with commands /sub, /list, /unsub
  • generates private REST API for sending messages, e.g. /sub test will return
http -a ${chatId}:${secret} https://mqtt2telegram.projects.royz.cc/api/v1.0/send topic=test payload='<your message>'

where chatId is your telegram ID, secret is generated by the bot.

  • allows sending images as a payload
http -a ${chatId}:${secret} --multipart https://mqtt2telegram.projects.royz.cc/api/v1.0/sendImage topic=images image@image.jpeg

where image.jpeg is an image file located in the current directory.

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

  • guice
  • javalin
  • telegramBots
  • java mongo driver & atlas cloud

REST API Authentication

Basic authorization of telegramId:secret

Libraries

About

Provides secured REST API for sending messages to Telegram. Uses MQTT under the hood.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published