feat(channel): add mention_only option for Telegram groups

Adds mention_only config option to Telegram channel, allowing the bot
to only respond to messages that @-mention the bot in group chats.
Direct messages are always processed regardless of this setting.

Behavior:
- When mention_only = true: Bot only responds to group messages containing @botname
- When mention_only = false (default): Bot responds to all allowed messages
- DM/private chats always work regardless of mention_only setting

Implementation:
- Fetch and cache bot username from Telegram API on startup
- Check for @botname mention in group messages
- Strip mention from message content before processing

Config example:
[channels.telegram]
bot_token = "your_token"
mention_only = true

Changes:
- src/config/schema.rs: Add mention_only to TelegramConfig
- src/channels/telegram.rs: Implement mention_only logic + 6 new tests
- src/channels/mod.rs: Update factory calls
- src/cron/scheduler.rs: Update constructor call
- src/onboard/wizard.rs: Update wizard config
- src/daemon/mod.rs: Update test config
- src/integrations/registry.rs: Update test config
- TESTING_TELEGRAM.md: Add mention_only test section
- CHANGELOG.md: Document feature

Risk: medium
Backward compatible: Yes (default: false)
This commit is contained in:
ZeroClaw Contributor 2026-02-18 12:57:38 +03:00 committed by Chummy
parent 3b75c6cc42
commit c0a80ad656
10 changed files with 264 additions and 54 deletions

View file

@ -101,7 +101,22 @@ After running automated tests, perform these manual checks:
- Verify: No "Too Many Requests" errors
- Verify: Responses have delays
5. **Error logging**
5. **Mention-only mode (group chats)**
```toml
# Edit ~/.zeroclaw/config.toml
[channels.telegram]
mention_only = true
```
- Add bot to a group chat
- Send message without @botname mention
- Verify: Bot does not respond
- Send message with @botname mention
- Verify: Bot responds and mention is stripped
- DM/private chat should always work regardless of mention_only
6. **Error logging**
```bash
RUST_LOG=debug zeroclaw channel start
@ -225,7 +240,7 @@ Expected values after all fixes:
| Message split overhead | <50ms | Check logs for timing |
| Memory usage | <10MB | `ps aux \| grep zeroclaw` |
| Binary size | ~3-4MB | `ls -lh target/release/zeroclaw` |
| Unit test coverage | 24/24 pass | `cargo test telegram --lib` |
| Unit test coverage | 61/61 pass | `cargo test telegram --lib` |
## 🐛 Debugging Failed Tests