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
_botorBot, 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_CHAT_ID env variable)
- 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_ENABLEDenv var 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 showand some other native calls, so you have to installiproute2andfpingon Linux machine where chatbot is running. See Dockerfile - This feature does not work on Windows
- To enable/disable host notifications, run the
/featurescommand 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_CHAT_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
Enabledcheckbox on the Command editing page - In the Telegram client these commands will be available as a reply markup
- Modify
WAKE_ON_LAN_BROADCAST_IPenv var 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 Enabledcheckbox - To wake up a host, run
/wolin the Telegram client and select the one you want
- Set
OPENWEATHER_ENABLEDenv variable totrue - Generate you API key on https://home.openweathermap.org/api_keys page
- Set the API key above as
OPENWEATHER_APPIDenv variable - Add places where you want to know the weather on http://127.0.0.1:9988/weather page
- Don't add
city IDwithlat & lonin 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
/weathercommand 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 bootJarin 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 chown -R $USER:$USER /var/telegram
sudo chmod 755 /var/telegram
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
.envfile (with all necessary props) next to the jar file
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
- Set your password as SSL_KEY_STORE_PASSWORD* property and change other props if necessary
- Add
thb-keystore.p12to theTrusted Root Certification Authorities certificatestore (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
sonarqubetask
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-springboot-longpolling-starter


