gateway_env.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. """Telegram env -> gateway config bridge (``PlatformEntry.env_overrides``)."""
  2. from gateway.config import GatewayConfig, Platform, PlatformConfig
  3. from gateway.platform_env import EnvCred, csv_list, getenv, home_step, reply_mode_step
  4. def _fallback_ips(config: GatewayConfig) -> None:
  5. if ips := getenv("TELEGRAM_FALLBACK_IPS"):
  6. config.platforms.setdefault(Platform.TELEGRAM, PlatformConfig()).extra["fallback_ips"] = csv_list(ips)
  7. ENV_ENABLE_CREDENTIALS = ("TELEGRAM_BOT_TOKEN",)
  8. # Order matters: the reply mode / fallback IPs may create the entry the home channel then attaches to.
  9. ENV_OVERRIDES = (
  10. EnvCred(Platform.TELEGRAM, ("TELEGRAM_BOT_TOKEN",), token="TELEGRAM_BOT_TOKEN"),
  11. reply_mode_step(Platform.TELEGRAM, "TELEGRAM_REPLY_TO_MODE"),
  12. _fallback_ips,
  13. home_step(Platform.TELEGRAM, "TELEGRAM_HOME_CHANNEL"),
  14. )
  15. # Authorization env names (``PlatformEntry`` fields). Core reads them from this file when the
  16. # live entry lacks them: a user plugin overriding this platform, safe mode, the plugin disabled.
  17. AUTHZ = {
  18. "allowed_users_env": "TELEGRAM_ALLOWED_USERS",
  19. "allow_all_env": "TELEGRAM_ALLOW_ALL_USERS",
  20. "allow_bots_env": "TELEGRAM_ALLOW_BOTS",
  21. "group_allowed_chats_env": "TELEGRAM_GROUP_ALLOWED_CHATS",
  22. "allowlist_suppresses_pairing": True,
  23. }