Files
simplex-chat/apps/simplex-support-bot-light/src/support_bot_light/context.py
T
sh 68916aa90a feat: add simplex-support-bot-light (#7378)
* feat: add simplex-support-bot-light

* feat: package simplex-support-bot-light for docker

* docs: document simplex-support-bot-light

* fix: make a missing config actionable and bounded

* docs: note the attached compose Ctrl+C behaviour

* refactor: use the library for startup and custom data

* refactor: drop the display-name workaround

* style: shorten the startup comment

* build: build the core and the library into the image

* docs: correct where the image type rule comes from

* fix: log what the core said a command got wrong

* build: run the container as the operator's uid

* docs: keep the container uid in .env

* docs: tighten the README
2026-08-17 09:12:47 +01:00

37 lines
1.1 KiB
Python

"""Everything the handlers need, resolved once at startup."""
from __future__ import annotations
import logging
from dataclasses import dataclass, field
from simplex_chat import ChatApi, ChatError
from .config import Config
log = logging.getLogger(__name__)
@dataclass(slots=True)
class BotContext:
"""API handle plus the ids and config resolved during startup."""
api: ChatApi
user_id: int
roster_group_id: int
config: Config
# Business chats repaired by the startup pass, so the queued event for the
# same chat does not report the customer a second time.
repaired: set[int] = field(default_factory=set)
async def post_to_roster(self, text: str) -> None:
"""Send a message to the roster group.
Never raises: this is the operator's visibility channel, and a failure
to report an event must not also discard the event that caused it.
"""
try:
await self.api.api_send_text_message(["group", self.roster_group_id], text)
except ChatError:
log.warning("could not post to the roster group: %s", text, exc_info=True)