This is a simple notification service (not a daemon) that sends notifications to Telegram at the end of a running command.
The service reads its configuration from the NOTIFY_CONFIG environment variable. If the variable is not set, the service stops and does not execute any commands. The command's output is redirected to stdout.
The configuration must include:
chat_id: CHAT_ID
tg_bot_token: TG_BOT_TOKEN
instance: YOUR_INSTANCE
thread_id: THREAD_ID
where:
chat_idis the ID of the chat where the message will be sent.tg_bot_tokenis the Telegram bot token.instanceis the instance where the service is running.thread_idis the thread ID in a Telegram group. It can be set to-1, meaning there is no thread.
IMPORTANT:
- If sending to a forum chat, the
chat_idin the configuration must start with-100followed by the chat ID. - If sending to a group chat, the
chat_idin the configuration should match the Telegram chat ID.
To run it on bare metal, first compile the binary:
go mod download
go build -o tgnotifyThen run it with:
./tgnotify ping google.comYou can also run it using Docker Compose:
docker compose up -dBefore doing that, make sure to specify the command you want to run in your docker-compose.yml file:
command: ["ping", "google.com"]