Skip to content

Commit 7d8bde5

Browse files
author
Anatoliy Bezgubenko
committed
Initial commit
0 parents  commit 7d8bde5

File tree

929 files changed

+294684
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

929 files changed

+294684
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db-data
2+
main

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
.env
3+
playground
4+
db-data
5+
main

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: go
2+
3+
go:
4+
- 1.12.x
5+
- 1.13.x
6+
- 1.14.x
7+
- 1.15.x
8+
9+
env:
10+
- GO111MODULE=on
11+
12+
script:
13+
- go build -mod vendor main.go

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.15.2 as builder
2+
WORKDIR /build
3+
COPY . .
4+
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix cgo -o bot main.go
5+
6+
FROM alpine:latest
7+
RUN apk update && apk --no-cache add ca-certificates
8+
WORKDIR /root
9+
COPY --from=builder /build/bot .
10+
CMD ["./bot"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Anatoliy Bezgubenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: mqtg-bot

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# mqtg-bot
2+
3+
[![Build Status](https://travis-ci.com/xDWart/mqtg-bot.svg?branch=master)](https://travis-ci.com/xDWart/mqtg-bot)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/xDWart/mqtg-bot)](https://goreportcard.com/report/github.com/xDWart/mqtg-bot)
5+
[![Version](https://img.shields.io/github/go-mod/go-version/xDWart/mqtg-bot)](go.mod)
6+
[![License](https://img.shields.io/github/license/xDWart/mqtg-bot)](LICENSE)
7+
8+
![Gopher Bot](https://github.com/xDWart/mqtg-bot/raw/master/assets/kdpv.jpg)
9+
10+
## Introduction
11+
12+
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.
13+
14+
![Edit buttons menu](https://github.com/xDWart/mqtg-bot/raw/master/assets/edit_buttons_menu.jpg)
15+
16+
![Temp and Humidity](https://github.com/xDWart/mqtg-bot/raw/master/assets/temp_and_humidity.jpg)
17+
18+
![Take a picture](https://github.com/xDWart/mqtg-bot/raw/master/assets/take_a_picture.jpg)
19+
20+
## Features
21+
22+
- [x] Connecting to MQTT broker
23+
- [x] tcp / ssl / ws / wss
24+
- [x] Subscribing to a topic:
25+
- [x] Selectable QoS/Retained
26+
- [x] Text/Image data types
27+
- [x] Pre/post value displaying text
28+
- [x] Storing data into DB
29+
- [ ] Data storage management
30+
- [ ] Publish action on receiving
31+
- [ ] Parse data from message by regexp
32+
- [ ] Voice data type
33+
- [x] Publishing to a topic:
34+
- [x] Selectable QoS/Retained
35+
- [x] Text/Image data types
36+
- [ ] Voice data type
37+
- [x] Customized users buttons menu:
38+
- [x] Folders
39+
- [x] Single-value buttons
40+
- [x] Toggle buttons
41+
- [x] Multi-value buttons
42+
- [x] Print last subscription value
43+
- [x] Draw charts
44+
- [ ] Your great idea ([create a proposal in issues](https://github.com/xDWart/mqtg-bot/issues/new/choose))
45+
46+
## Usage
47+
48+
You can run the bot on your Raspberry Pi home server or free Heroku dyno.
49+
50+
Clone this repository:
51+
```sh
52+
git clone https://github.com/xDWart/mqtg-bot
53+
```
54+
55+
Message [@BotFather](https://telegram.me/BotFather) `/newbot` command to create a bot and get its HTTP API access token.
56+
57+
#### Required environment variables
58+
59+
- `TELEGRAM_BOT_TOKEN` (HTTP API access token)
60+
- `DATABASE_URL` **or** `POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`
61+
62+
Notes:
63+
1. `DATABASE_URL` must have the following format: `postgres://user:password@host:port/db`
64+
1. You can create the `.env` file in the root of the project and insert your key/value environment variable pairs in the following format of `KEY=VALUE`
65+
66+
#### Local running
67+
68+
If you don't have Postgres, the easiest way to get it is to run it under Docker:
69+
70+
```sh
71+
docker run --name some-postgres -e POSTGRES_PASSWORD=... -p 5432:5432 -d postgres
72+
```
73+
74+
You can run mqtg-bot with environment variables:
75+
76+
```sh
77+
TELEGRAM_BOT_TOKEN=... POSTGRES_PASSWORD=... go run main.go
78+
```
79+
80+
or if you've already created the `.env` file:
81+
82+
```sh
83+
go run main.go
84+
```
85+
86+
#### Running in Docker container
87+
88+
```sh
89+
docker run -e TELEGRAM_BOT_TOKEN=... -e DATABASE_URL=... --network=host owart/mqtg-bot
90+
```
91+
92+
#### Running both mqtg-bot and Postgres with Docker Compose
93+
94+
Create a `.env` file in the root of the project and insert your key/value environment variable pairs in the following format of `KEY=VALUE`.
95+
96+
```sh
97+
TELEGRAM_BOT_TOKEN=*BOT_ACCESS_TOKEN*
98+
POSTGRES_PASSWORD=password
99+
```
100+
101+
Run docker-compose:
102+
103+
```sh
104+
docker-compose up --build
105+
```
106+
107+
#### Heroku running
108+
109+
You will need Heroku CLI
110+
111+
```sh
112+
# login into Heroku
113+
heroku login
114+
115+
# create a new app
116+
heroku create
117+
118+
# add your new app into git remotes
119+
heroku git:remote -a *YOUR_APP_NAME*
120+
121+
# add TELEGRAM_BOT_TOKEN environment
122+
heroku config:set TELEGRAM_BOT_TOKEN=*BOT_ACCESS_TOKEN*
123+
124+
# attach Postgres add-on
125+
heroku addons:create heroku-postgresql:hobby-dev
126+
127+
# push master branch to Heroku
128+
git push heroku master
129+
130+
# scale up your app
131+
heroku ps:scale worker=1
132+
```
133+
134+
Then just message `/start` to your bot and follow the instructions to configure it.
135+
136+
## Try bot
137+
138+
[@mqtg_bot](https://telegram.me/mqtg_bot)
139+
Message `/start` to him and configure connection to your MQTT broker.
140+
141+
## Contribution
142+
143+
- Do you have an idea to improve mqtg-bot? -> [Create an issue](https://github.com/xDWart/mqtg-bot/issues/new/choose).
144+
- Have you discovered a bug? -> [Create an issue](https://github.com/xDWart/mqtg-bot/issues/new/choose).
145+
- Have you already coded something for mqtg-bot? -> [Create a pull request](https://github.com/xDWart/mqtg-bot/compare).
146+
147+
## Licence
148+
149+
- mqtg-bot is licensed under the MIT License.
150+
- See [LICENSE](LICENSE) for the full license text.
151+
- Copyright (c) Anatoliy Bezgubenko

ToDo.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ToDo
2+
1. Unit Tests!!!
3+
1. Show last topic inline keyboard button for publish
4+
1. Add names for subscriptions and show them on chart legends instead topic
5+
1. Add chart button params to configure:
6+
- min value for Y axis (autoscale by default)
7+
- user datetime format for X axis
8+
1. Editable subscription stored data
9+
- Subscriptions -> /topic -> Stored data (count) ->
10+
- Print stored data
11+
- Clear older than month (count)
12+
- Clear older than week (count)
13+
- Clear all stored data (count)
14+
- Back
15+
1. Configurable user timezone

assets/edit_buttons_menu.jpg

114 KB
Loading

assets/kdpv.jpg

136 KB
Loading

0 commit comments

Comments
 (0)