fix(telegram,core): first message seeds the branch, registered commands, no ellipses, html drafts

This commit is contained in:
hh
2026-08-28 18:25:46 +02:00
parent b0f280b3ca
commit 3995741cd5
5 changed files with 111 additions and 78 deletions
@@ -15,7 +15,9 @@ import time
import zlib
from typing import TYPE_CHECKING
from aiogram.exceptions import TelegramAPIError
from aiogram.exceptions import TelegramAPIError, TelegramBadRequest
from beaver_gateway.frontends.telegram.render import to_html
if TYPE_CHECKING:
from aiogram import Bot
@@ -37,7 +39,7 @@ class Draft:
thread_id: int | None,
turn_id: str,
interval: float = 0.7,
status: str = "⏳ думаю",
status: str = "⏳ думаю",
) -> None:
self._bot = bot
self._chat_id = chat_id
@@ -82,20 +84,27 @@ class Draft:
async def _push(self) -> None:
self._dirty = False
self._last_sent = time.monotonic()
text = self._render()
try:
await self._bot.send_message_draft(
chat_id=self._chat_id,
draft_id=self._draft_id,
message_thread_id=self._thread_id,
text=self._render(),
parse_mode=None,
)
try:
await self._send(to_html(text), "HTML")
except TelegramBadRequest:
await self._send(text, None)
except TelegramAPIError as exc:
self._broken = True
_log.warning(
"draft to %s/%s stopped: %s", self._chat_id, self._thread_id, exc
)
async def _send(self, text: str, parse_mode: str | None) -> None:
await self._bot.send_message_draft(
chat_id=self._chat_id,
draft_id=self._draft_id,
message_thread_id=self._thread_id,
text=text,
parse_mode=parse_mode,
)
def _render(self) -> str:
tail = self.text[-_TAIL:]
return f"{self.status}\n\n{tail}" if tail.strip() else self.status