dashboard_card.py 1.2 KB

12345678910111213141516171819202122232425
  1. """Telegram's Channels-page card (Desktop + web dashboard): the PlatformEntry ``dashboard_*`` /
  2. ``docs_url`` fields register() spreads in. Kept apart from adapter.py, which is over its size cap."""
  3. import re
  4. # Write checks (kept in sync with ChannelsPage.tsx): reject credentials
  5. # pasted into the wrong field. Allowlists split like the adapter's parser (comma, strip, drop
  6. # empties) so a trailing comma the runtime accepts is not refused here.
  7. _BOT_TOKEN_RE = re.compile(r"\d+:[A-Za-z0-9_-]{30,}")
  8. _USER_ID_RE = re.compile(r"\d+")
  9. _ENV_VALUE_RULES = {
  10. "TELEGRAM_BOT_TOKEN": (
  11. _BOT_TOKEN_RE.fullmatch,
  12. "Telegram bot token must be the complete token from @BotFather, such as 123456789:ABC…"),
  13. "TELEGRAM_ALLOWED_USERS": (
  14. lambda v: all(_USER_ID_RE.fullmatch(u.strip()) for u in v.split(",") if u.strip()),
  15. "Telegram allowed users must be comma-separated numeric user IDs."),
  16. }
  17. DASHBOARD_CARD = dict(
  18. dashboard_description="Run Hermes from Telegram DMs, groups, and topics.",
  19. docs_url="https://core.telegram.org/bots/features#botfather",
  20. dashboard_env_vars=("TELEGRAM_BOT_TOKEN", "TELEGRAM_ALLOWED_USERS", "TELEGRAM_PROXY"),
  21. env_value_rules=_ENV_VALUE_RULES,
  22. )