platform_config.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. Chatto Platform Config
  3. """
  4. from dataclasses import dataclass
  5. import os
  6. from typing import Optional
  7. import utils
  8. @dataclass
  9. class ChattoConfig:
  10. """
  11. Chatto Platform Config
  12. Some constants and getting from environment/config.yaml
  13. """
  14. _token: Optional[str] = None
  15. _PLATFORM: str = "CHATTO"
  16. def __init__(self, extra: dict = {}):
  17. self._base_url = os.getenv("CHATTO_BASE_URL", "").strip() # todo: add config.yaml support
  18. self._token = os.getenv("CHATTO_TOKEN", "").strip() # todo: add config.yaml support
  19. self._login = os.getenv("CHATTO_LOGIN", "").strip() # todo: add config.yaml support
  20. self._password = os.getenv("CHATTO_PASSWORD", "").strip() # todo: add config.yaml support
  21. self._raw_channels = os.getenv("CHATTO_CHANNELS", "").strip() # todo: add config.yaml support
  22. if self._raw_channels:
  23. self._channel_ids = [c.strip() for c in self._raw_channels.split(",") if c.strip()]
  24. elif isinstance(extra.get("channels"), list):
  25. self._channel_ids = [str(c) for c in extra["channels"]]
  26. else:
  27. self._channel_ids = []
  28. self._home_channel = (
  29. os.getenv("CHATTO_HOME_CHANNEL", "").strip()
  30. or str(extra.get("home_channel", "")).strip()
  31. )
  32. self._require_mention = os.getenv("CHATTO_REQUIRE_MENTION", "").strip().lower()
  33. if self._require_mention:
  34. self._require_mention = self._require_mention in ("true", "1", "yes")
  35. else:
  36. self._require_mention = bool(extra.get("require_mention", True))
  37. # free_response_channels: room IDs where the bot responds without being mentioned via "@botname"
  38. _free_response = os.getenv("CHATTO_FREE_RESPONSE_CHANNELS", "").strip()
  39. if _free_response:
  40. self._free_response_channels = set(c.strip() for c in _free_response.split(",") if c.strip())
  41. else:
  42. self._free_response_channels = set(
  43. str(c) for c in extra.get("free_response_channels", []) if str(c).strip()
  44. )
  45. # Auto-thread: by default, Chatto creates a thread for replies to room
  46. # messages (not DMs, not already in a thread). This keeps conversations
  47. # organized in the room. Can be disabled via extra.auto_thread=false.
  48. self._auto_thread = utils.is_truthy_value(os.getenv("CHATTO_AUTO_THREAD", "").strip().lower()) # todo: add config.yaml support