| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """
- Chatto Platform Config
- """
- from dataclasses import dataclass
- import os
- from typing import Optional
- import utils
- @dataclass
- class ChattoConfig:
- """
- Chatto Platform Config
- Some constants and getting from environment/config.yaml
- """
- _token: Optional[str] = None
- _PLATFORM: str = "CHATTO"
- def __init__(self, extra: dict = {}):
- self._base_url = os.getenv("CHATTO_BASE_URL", "").strip() # todo: add config.yaml support
- self._token = os.getenv("CHATTO_TOKEN", "").strip() # todo: add config.yaml support
- self._login = os.getenv("CHATTO_LOGIN", "").strip() # todo: add config.yaml support
- self._password = os.getenv("CHATTO_PASSWORD", "").strip() # todo: add config.yaml support
- self._raw_channels = os.getenv("CHATTO_CHANNELS", "").strip() # todo: add config.yaml support
- if self._raw_channels:
- self._channel_ids = [c.strip() for c in self._raw_channels.split(",") if c.strip()]
- elif isinstance(extra.get("channels"), list):
- self._channel_ids = [str(c) for c in extra["channels"]]
- else:
- self._channel_ids = []
- self._home_channel = (
- os.getenv("CHATTO_HOME_CHANNEL", "").strip()
- or str(extra.get("home_channel", "")).strip()
- )
- self._require_mention = os.getenv("CHATTO_REQUIRE_MENTION", "").strip().lower()
- if self._require_mention:
- self._require_mention = self._require_mention in ("true", "1", "yes")
- else:
- self._require_mention = bool(extra.get("require_mention", True))
- # free_response_channels: room IDs where the bot responds without being mentioned via "@botname"
- _free_response = os.getenv("CHATTO_FREE_RESPONSE_CHANNELS", "").strip()
- if _free_response:
- self._free_response_channels = set(c.strip() for c in _free_response.split(",") if c.strip())
- else:
- self._free_response_channels = set(
- str(c) for c in extra.get("free_response_channels", []) if str(c).strip()
- )
- # Auto-thread: by default, Chatto creates a thread for replies to room
- # messages (not DMs, not already in a thread). This keeps conversations
- # organized in the room. Can be disabled via extra.auto_thread=false.
- self._auto_thread = utils.is_truthy_value(os.getenv("CHATTO_AUTO_THREAD", "").strip().lower()) # todo: add config.yaml support
|