xDWart/mqtg-bot
MQTT Client Telegram Bot
Featured achievements
The project's latest awards
#1 Repository of the month
#1 Repository of the month
#1 Repository of the month
mqtg-bot

Articles
- Development of the Open-Source Telegram Bot for MQTT IoT (En, DZone.com)
- (Не)очередной MQTT-телеграм-бот для IoT (Ru, Habr)
- Разработка NoCode решения для интернета вещей (Ru, YouTube)
Introduction
mqtg-bot is an easy-to-configure for your needs MQTT client Telegram bot. Without programming knowledge you can configure the bot to send various commands (turn on the light, open the garage door, etc.) or request any information (the temperature in the house, the state of the heating system, etc.) or receive frames from security camera. In general the functionality of this solution is very rich.



Features
- Connecting to MQTT broker
- tcp / ssl / ws / wss
- Supported databases
- Postgres
- SQLite
- Subscribing to a topic:
- Selectable QoS/Retained
- Text/Image data types
- Pre/post value displaying text
- Storing data into DB
- Parse data by JsonPath expressions
- Data storage management
- Publish action on receiving
- Voice data type
- Publishing to a topic:
- Selectable QoS/Retained
- Text/Image data types
- Voice data type
- Customized users buttons menu:
- Folders
- Single-value buttons
- Toggle buttons
- Multi-value buttons
- Print last subscription value
- Draw charts
- Your great idea (create a proposal in issues)
Usage
You can run the bot on your Raspberry Pi home server or free Heroku dyno.
Clone this repository:
git clone https://github.com/xDWart/mqtg-bot
Message @BotFather /newbot command to create a bot and get his HTTP API access token.
Environment variables
TELEGRAM_BOT_TOKEN- bot HTTP API access token, requiredDATABASE_URL- Postgres connection string in the following format:postgres://user:password@host:port/dbSQLITE_PATH- path to SQLite databaseMQTT_CLIENT_ID- Client ID to be used. Required for VerneMQ.
Notes:
- Only
TELEGRAM_BOT_TOKENenv is required - If
DATABASE_URLenv is omitted, or a Postgres connection error occurred, SQLite will be used - If
SQLITE_PATHenv is omitted,mqtg.dbwill be used by default as a SQLite database - You can create the
.envfile in the root of the project and insert your key/value environment variable pairs in the following format ofKEY=VALUE
Local running
You can run mqtg-bot with environment variables:
TELEGRAM_BOT_TOKEN=... go run main.go
or if you've already created the .env file:
go run main.go
Running in Docker container
docker run -e TELEGRAM_BOT_TOKEN=... -e DATABASE_URL=... --network=host owart/mqtg-bot
Heroku running
You will need Heroku CLI
# login into Heroku
heroku login
# create a new app
heroku create *YOUR_APP_NAME*
# add your new app into git remotes
heroku git:remote -a *YOUR_APP_NAME*
# add TELEGRAM_BOT_TOKEN environment
heroku config:set TELEGRAM_BOT_TOKEN=*BOT_ACCESS_TOKEN*
# set version of Go
heroku config:set GOVERSION=go1.15
# attach Postgres add-on
heroku addons:create heroku-postgresql:hobby-dev
# push master branch to Heroku
git push heroku master
# scale up your app
heroku ps:scale worker=1
Then just message /start to your bot and follow the instructions to configure it.
Contribution
- Do you have an idea to improve mqtg-bot? -> Create an issue.
- Have you discovered a bug? -> Create an issue.
- Have you already coded something for mqtg-bot? -> Create a pull request.
Licence
- mqtg-bot is licensed under the MIT License.
- See LICENSE for the full license text.
- Copyright (c) Anatoliy Bezgubenko
Similar Projects
Discover other similar projects and AI models.
Get up and running with Inkling, Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
All-in-one IoT Platform - Device management, data collection, processing and visualization.
JetLinks 基于Java,Spring Boot ,WebFlux,Netty,Vert.x,Reactor等开发, 是一个全响应式的企业级物联网平台。支持统一物模型管理,多种设备,多种厂家,统一管理。统一设备连接管理,多协议适配(TCP,MQTT,UDP,CoAP,HTTP等),屏蔽网络编程复杂性,灵活接入不同厂家不同协议等设备。实时数据处理,设备告警,消息通知,数据转发。地理位置,数据可视化等。能帮助你快速建立物联网相关业务系统。
A Powerful and All-in-One MQTT 5.0 client toolbox for Desktop, CLI and WebSocket.
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.