HKUDS/nanobot · error · ValueError

webhook_secret_token must be 1-256 characters using only…

Error message

webhook_secret_token must be 1-256 characters using only A-Z, a-z, 0-9, _ and -

What it means

Format validation in validate_webhook_config: webhook_secret_token after stripping is either empty, longer than 256 characters, or contains characters outside A-Z, a-z, 0-9, '_', '-'. Telegram restricts the secret header to this alphabet and length range.

Solutions

  1. Use a hex/base64url-style token of only letters, digits, underscore, and hyphen (e.g. output of 'openssl rand -hex 32')
  2. Trim the token to 1-256 characters and remove whitespace/special symbols
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nanobot/channels/telegram/runtime.py:453 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26). Data as JSON: /api/errors/4850fb89eb9a03cf. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/channels/telegram/runtime.py:453

            raise ValueError('webhook_path must start with "/"')
        return value

    @model_validator(mode="after")
    def validate_webhook_config(self) -> "TelegramConfig":
        if self.mode != "webhook":
            return self

        url = self.webhook_url.strip()
        if not url:
            raise ValueError("webhook_url is required when Telegram mode is webhook")
        parsed = urlparse(url)
        if parsed.scheme != "https" or not parsed.netloc:
            raise ValueError("webhook_url must be a public HTTPS URL")
        secret = self.webhook_secret_token.strip()
        if not secret:
            raise ValueError("webhook_secret_token is required when Telegram mode is webhook")
        if len(secret) > 256 or re.match(r"^[A-Za-z0-9_-]+$", secret) is None:
            raise ValueError(
                "webhook_secret_token must be 1-256 characters using only A-Z, a-z, 0-9, _ and -"
            )
        return self


class TelegramChannel(BaseChannel):
    """
    Telegram channel using long polling or webhook mode.

    Long polling is the default. Webhook mode requires a public HTTPS URL and a
    Telegram secret token.
    """

    name = "telegram"
    display_name = "Telegram"

    # Commands registered with Telegram's command menu
    BOT_COMMANDS: list[BotCommand] = [

View on GitHub (pinned to 42f37dc4c0)