Can be used for home automation on Raspberry Pi
- Monitor local network and notify about hosts appearances/disappearances via Telegram client
- Run commands on target machine from Telegram client
- Wake-up selected hosts via WOL technology sending magic packet using Telegram client
- Provide weather info for chosen places using OpenWeatherMap API via Telegram client
Application settings are stored in application.properties file
- Start a chat with @BotFather
- Use message /newbot
- Set unique bot name (ends with
_bot
orBot
, use it as telegram.bot-name) - Get token from the final message (and use it as telegram.token)
- Start conversation with bot
- Retrieve chat_id, call https://api.telegram.org/bot[YOUR_TOKEN]/getUpdates (and use it as telegram.bot-owner-id)
- Located by default on http://127.0.0.1:9988/
- Port setting:
server.port
- Port setting:
- Default users:
admin / 1234
,user / 1234
- Default credentials could be changed in settings:
default.admin.login / default.admin.password
,default.user.login / default.user.password
- Default credentials could be changed in settings:
- Password could be changed on http://127.0.0.1:9988/updatePassword page
- Set
network-monitor.enabled
totrue
- You can observe/add/edit hosts on http://127.0.0.1:9988/hosts page
- Hosts availability changes is on http://127.0.0.1:9988/hosts/time-log page
- Unfortunately, current implementation is based on
ip -j n show
and some other native calls, so you have to installiproute2
andfping
on Linux machine where chatbot is running. See Dockerfile - This feature does not work on Windows
- To enable/disable host notifications, run the
/features
command in the Telegram client and choose what you want
- Periodically calls a command (state.change.command) to check network changes
- Chatbot notifies about hosts appearances/disappearances telegram.bot-owner-id user
- You can add any initial commands that will be available to run in commands.properties file
- Besides, you can add/edit commands on http://127.0.0.1:9988/commands page
- To hide any command from the Telegram client, uncheck the
Enabled
checkbox on the Command editing page - In the Telegram client these commands will be available as a reply markup
- Modify
wakeOnLan.broadcast.ip
according to your network mask - To enable WOL for a host open http://127.0.0.1:9988/hosts page
- Choose a host and check
Wake On Lan Enabled
checkbox - To wake up a host, run
/wol
in the Telegram client and select the one you want
- Set
openweather.enabled
property totrue
- Generate you API key on https://home.openweathermap.org/api_keys page
- Set the API key above as
openweather.appid
property - Add places where you want to know the weather on http://127.0.0.1:9988/weather page
- Don't add
city ID
withlat & lon
in the same time, use them separately - City ID could be found in city.list.json.gz or city.list.min.json.gz
- Don't add
- After starting the app you can reach the Weather menu using
/weather
command via Telegram client - Please note that the free subscription includes: 60 calls/minute, 1 000 000 calls/month (Pricing)
- Useful links
/menu
- Main menu/features
- Features Setting (notification settings for now)/wol
- Wake On Lan hosts/weather
- Weather
-
Run
gradlew clean bootJar
in the project root folder -
Executable jar will be placed here:
build/libs/thb.jar
-
Copy the jar file to SOME_LINUX_FOLDER on Linux machine
-
Run on Linux machine:
sudo mkdir /var/telegram # create a folder for jar file
sudo cp /SOME_LINUX_FOLDER/thb.jar /var/telegram/thb.jar # copy jar to the folder
sudo ln -s /var/telegram/thb.jar /etc/init.d/thb # create symlink the jar to init.d
sudo chmod +x /var/telegram/thb.jar # make thb.jar executable
sudo systemctl daemon-reload # reload systemd manager configuration
sudo service thb start # start bot as a service
update-rc.d thb defaults # autostart
- When I'm using THB as a Linux service, I just put the properties files next to the jar file and also set the Telegram credentials into the application.properties without using env variables
The example below will be with a self-signed certificate on the local machine
- Create
thb-keystore.p12
keytool -genkeypair -alias thb -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore thb-keystore.p12 -validity 3650 -ext san=ip:127.0.0.1
- You will be asked to enter a password for the keystore
- Uncomment
server.ssl.*
properties - Set your password as server.ssl.key-store-password property and change other props if necessary
- Add
thb-keystore.p12
to theTrusted Root Certification Authorities certificate
store (Windows)
# Build the image
docker build -t thb-image .
# Create and start new container from the image
docker run -d -p 80:8080 --network=bridge --name=thb thb-image
# Start the container
docker start thb
# Stop the running container
docker stop thb
# Show information logged by a running container
docker logs -f thb
- Run SonarQube container
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
- Browse http://127.0.0.1:9000. Initial credentials:
admin / admin
- Change password
- Create project with name
thb
- Create project token
- Run
sonarqube
task
gradlew sonarqube -Dsonar.projectKey=thb -Dsonar.host.url=http://127.0.0.1:9000 -Dsonar.login=PROJECT_TOKEN
- open a session with @BotFather
- enter /setjoingroups
- enter the name of the bot
- enter Disable
- get private group chat_id, call https://api.telegram.org/bot$TOKEN/getUpdates
Kotlin, Spring (Boot/Security/WebFlux), Gradle, H2, Thymeleaf, Google Charts, telegrambots-spring-boot-starter