refactor: telegram config via pos config telegram; fix listener pipe + entertainment bugs
- Drop sender 'config'/'config set' subcommand — redundant with 'pos config telegram' (same POS_CONFIG registry: masked token input/display, chat-id validation, chmod 600); sender/listener error hints now point there. - Listener: load_map now uses a \x1f delimiter, so mapped /commands containing '|' are no longer truncated at the first pipe. - entertainment send: forward extra plugin args (previously dropped); pass '--' before the message so leading '-' plugin output isn't parsed as an option. - write_config_key/cfg_write: replace unescaped sed writes with grep-v+append so values with &, |, \ round-trip safely. - sync_systemd: daemon-reload after removing timer units. - config-ui: 'digits' validation accepts negative group/supergroup chat ids.
This commit is contained in:
@@ -59,7 +59,7 @@ Linux_post_install/
|
||||
│ ├── pos # Main dispatcher — smart arg matching to pos-* scripts
|
||||
<!-- GEN:START tree -->
|
||||
│ ├── pos-communication-telegram-listener # Telegram bot listener: map /command → bash, run them on chat messages
|
||||
│ ├── pos-communication-telegram-sender # Send Telegram messages/files/links/stickers via Bot API (send, test, config set)
|
||||
│ ├── pos-communication-telegram-sender # Send Telegram messages/files/links/stickers via Bot API (send, test)
|
||||
│ ├── pos-config # Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry)
|
||||
│ ├── pos-docker-compose # Docker Compose service manager (ls/up/down/restart/logs/update/config)
|
||||
│ ├── pos-docker-health # One-glance container health dashboard (exits 1 if unhealthy)
|
||||
@@ -251,7 +251,7 @@ All non-interactive `pos` commands log output to `~/.local/share/linux_post_inst
|
||||
|----------|---------|--------|-------------|
|
||||
<!-- GEN:START dispatch -->
|
||||
| communication | telegram-listener | `pos-communication-telegram-listener` | Telegram bot listener: map /command → bash, run them on chat messages |
|
||||
| communication | telegram-sender | `pos-communication-telegram-sender` | Send Telegram messages/files/links/stickers via Bot API (send, test, config set) |
|
||||
| communication | telegram-sender | `pos-communication-telegram-sender` | Send Telegram messages/files/links/stickers via Bot API (send, test) |
|
||||
| | config | `pos-config` | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) |
|
||||
| docker | compose | `pos-docker-compose` | Docker Compose service manager (ls/up/down/restart/logs/update/config) |
|
||||
| docker | health | `pos-docker-health` | One-glance container health dashboard (exits 1 if unhealthy) |
|
||||
@@ -553,8 +553,8 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:`
|
||||
| `features/autostart.sh` | 14 | Boot-time feature (moved from `bin/`, flag-gated service) |
|
||||
<!-- GEN:START filetable -->
|
||||
| `bin/pos` | 270 | CLI dispatcher with smart arg matching + logging + category help |
|
||||
| `bin/pos-communication-telegram-listener` | 508 | Telegram bot listener: map /command → bash, run them on chat messages |
|
||||
| `bin/pos-communication-telegram-sender` | 270 | Send Telegram messages/files/links/stickers via Bot API (send, test, config set) |
|
||||
| `bin/pos-communication-telegram-listener` | 509 | Telegram bot listener: map /command → bash, run them on chat messages |
|
||||
| `bin/pos-communication-telegram-sender` | 220 | Send Telegram messages/files/links/stickers via Bot API (send, test) |
|
||||
| `bin/pos-config` | 80 | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) |
|
||||
| `bin/pos-docker-compose` | 366 | Docker Compose service manager (ls/up/down/restart/logs/update/config) |
|
||||
| `bin/pos-docker-health` | 110 | One-glance container health dashboard (exits 1 if unhealthy) |
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ PACKAGES=(
|
||||
Two kinds of config, don't mix them up:
|
||||
|
||||
- **Machine defaults shipped by the installer:** place the file in `config/` and add copy logic to `postinstall.sh`. If it contains secrets, add to `.gitignore` and document in `DOC/`.
|
||||
- **Runtime tool config set by the user:** `~/.config/linux_post_install/<tool>.env` with `chmod 600`. Load it with env-var precedence (flags > environment > file). Patterns: `pos-docker-compose` (`compose.env`), `pos-communication-telegram-sender` (`telegram.env`, token masked in `config` output), and the shared ones below. Never store tokens in the repo.
|
||||
- **Runtime tool config set by the user:** `~/.config/linux_post_install/<tool>.env` with `chmod 600`. Load it with env-var precedence (flags > environment > file). Patterns: `pos-docker-compose` (`compose.env`), `pos-communication-telegram-sender` (`telegram.env`, edited via `pos config telegram` — token masked), and the shared ones below. Never store tokens in the repo.
|
||||
- `system.env` — shared "system" settings loaded by `pos-system-*` tools via `load_system_env()` in `lib/common.sh` (currently `BACKUP_SERVICE_ROOTS`, `HEALTH_BACKUP_MAX_AGE_DAYS`). Env already exported wins over the file.
|
||||
- `notify.env` — alerting platform selection (`NOTIFY_PLATFORM=telegram,matrix`), read by `lib/notify.sh`.
|
||||
|
||||
|
||||
+2
-3
@@ -33,15 +33,14 @@ templates (without overwriting an existing file):
|
||||
|
||||
| File | Used by | Keys |
|
||||
|------|---------|------|
|
||||
| `telegram.env` | `pos communication telegram`, everything that alerts | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
|
||||
| `telegram.env` | `pos communication telegram sender` / `listener`, everything that alerts | `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
|
||||
| `notify.env` | `lib/notify.sh` (all alerting) | `NOTIFY_PLATFORM` (e.g. `telegram,matrix`) |
|
||||
| `system.env` | `pos system health`, `pos system backup` | `BACKUP_SERVICE_ROOTS`, `HEALTH_BACKUP_MAX_AGE_DAYS` |
|
||||
| `compose.env` | `pos docker compose` | `TS_AUTHKEY`, `TZ`, `DNS_SERVER`, `SERVICES_BASE` |
|
||||
| `entertainment.env` | `pos entertainment *` | plugin keys (`WEATHER_LAT`…), `ENABLED` |
|
||||
|
||||
```bash
|
||||
pos communication telegram sender config set TELEGRAM_BOT_TOKEN=123:ABC
|
||||
pos communication telegram sender config set TELEGRAM_CHAT_ID=98765
|
||||
pos config telegram # set TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID
|
||||
pos entertainment config set WEATHER_LAT=36.51 WEATHER_LON=40.75
|
||||
```
|
||||
|
||||
|
||||
+2
-5
@@ -208,13 +208,10 @@ Subcommands that need input prompt interactively when args are omitted.
|
||||
| `pos communication telegram sender send "text" --parse-mode <mode>` | Send with Telegram formatting; `<mode>` is `plain` (default), `markdown`, or `html` (passed as `parse_mode` to the API — also applies to captions). Markdown/HTML use raw Telegram syntax — unescaped characters may be rejected by the API (400) |
|
||||
| `pos communication telegram sender send … --token <t> --chat-id <id>` | One-shot override of token/chat ID |
|
||||
| `pos communication telegram sender test` | Sends a canned test message using the current config |
|
||||
| `pos communication telegram sender config` | Shows current config (bot token masked) |
|
||||
| `pos communication telegram sender config set TELEGRAM_BOT_TOKEN=...` | Saves a bot token (600 perms) |
|
||||
| `pos communication telegram sender config set TELEGRAM_CHAT_ID=...` | Saves the target chat ID |
|
||||
|
||||
`send` option validation: `--caption` is only valid with media types (file/photo/video/audio/voice/animation), `--no-preview` only with `--type message`/`link`, and `--type` only accepts `message|file|link|sticker|photo|video|audio|voice|animation`. An explicit `--type` always overrides auto-detection.
|
||||
|
||||
The bot token is a secret — it is stored only in `~/.config/linux_post_install/telegram.env` and never in the repo. Requires network access to `api.telegram.org`.
|
||||
The bot token is a secret — it is stored only in `~/.config/linux_post_install/telegram.env` and never in the repo. Edit `TELEGRAM_BOT_TOKEN` / `TELEGRAM_CHAT_ID` interactively with `pos config telegram` (masked input + display). Requires network access to `api.telegram.org`.
|
||||
|
||||
`pos communication telegram listener` in detail:
|
||||
|
||||
@@ -241,7 +238,7 @@ Map entries may carry an optional **description** shown in the bot's `/` menu: `
|
||||
| `pos entertainment send` | List available plugins + usage |
|
||||
| `pos entertainment send <plugin> [--print] [--markdown] [args…]` | Run the plugin, send its output to Telegram (silent) |
|
||||
| `pos entertainment send <plugin> --print` | Print the output locally; do not send |
|
||||
| `pos entertainment send <plugin> --markdown` | Send with `--parse-mode markdown` (via `pos communication telegram`) |
|
||||
| `pos entertainment send <plugin> --markdown` | Send with `--parse-mode markdown` (via `pos communication telegram sender`) |
|
||||
| `pos entertainment config` | Show the config file (`~/.config/linux_post_install/entertainment.env`) |
|
||||
| `pos entertainment config set KEY=VALUE…` | Set keys (any UPPER_SNAKE key; warns if no installed plugin uses it) and re-sync the schedule |
|
||||
| `pos entertainment enable <plugin> [interval]` | Add plugin to `ENABLED` + schedule it as a systemd user timer |
|
||||
|
||||
@@ -19,14 +19,15 @@ health digests, backup alerts, firewall changes — and can be used directly.
|
||||
### One-time setup
|
||||
|
||||
```bash
|
||||
pos communication telegram sender config set TELEGRAM_BOT_TOKEN=123456:ABC...
|
||||
pos communication telegram sender config set TELEGRAM_CHAT_ID=987654321
|
||||
pos communication telegram sender config
|
||||
pos config telegram
|
||||
# edit TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID (masked input), then test:
|
||||
pos communication telegram sender test
|
||||
# config lives in ~/.config/linux_post_install/telegram.env (chmod 600)
|
||||
```
|
||||
|
||||
The bot token comes from @BotFather, the chat ID from @userinfobot (or by
|
||||
starting a chat and reading it). `sender config` shows the configured chat id.
|
||||
starting a chat and reading it). `pos config telegram` shows the current values
|
||||
(token masked).
|
||||
|
||||
### Send
|
||||
|
||||
@@ -47,7 +48,7 @@ pos communication telegram sender send /path/to/report.pdf # auto-detects
|
||||
- **On-call file drop:** `pos communication telegram sender send ~/log/nginx-error.log`
|
||||
|
||||
**Troubleshooting:**
|
||||
- "Not configured (no token or chat id)" → run `sender config set` for both values.
|
||||
- "Not configured (no token or chat id)" → run `pos config telegram` and set both values.
|
||||
- Send succeeds but nothing arrives → the chat must have started the bot
|
||||
(press `Start` / send `/start` once).
|
||||
- **Markdown silently empty** → Telegram uses its own MarkdownV2; unmatched
|
||||
|
||||
Reference in New Issue
Block a user