mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-26 12:43:54 +00:00
feat(): telegram support stream edit interval
This commit is contained in:
parent
e21ba5f667
commit
af6c75141f
@ -166,6 +166,7 @@ def _markdown_to_telegram_html(text: str) -> str:
|
|||||||
|
|
||||||
_SEND_MAX_RETRIES = 3
|
_SEND_MAX_RETRIES = 3
|
||||||
_SEND_RETRY_BASE_DELAY = 0.5 # seconds, doubled each retry
|
_SEND_RETRY_BASE_DELAY = 0.5 # seconds, doubled each retry
|
||||||
|
_STREAM_EDIT_INTERVAL_DEFAULT = 0.6 # min seconds between edit_message_text calls
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -190,6 +191,7 @@ class TelegramConfig(Base):
|
|||||||
connection_pool_size: int = 32
|
connection_pool_size: int = 32
|
||||||
pool_timeout: float = 5.0
|
pool_timeout: float = 5.0
|
||||||
streaming: bool = True
|
streaming: bool = True
|
||||||
|
stream_edit_interval: float = Field(default=_STREAM_EDIT_INTERVAL_DEFAULT, ge=0.1)
|
||||||
|
|
||||||
|
|
||||||
class TelegramChannel(BaseChannel):
|
class TelegramChannel(BaseChannel):
|
||||||
@ -219,8 +221,6 @@ class TelegramChannel(BaseChannel):
|
|||||||
def default_config(cls) -> dict[str, Any]:
|
def default_config(cls) -> dict[str, Any]:
|
||||||
return TelegramConfig().model_dump(by_alias=True)
|
return TelegramConfig().model_dump(by_alias=True)
|
||||||
|
|
||||||
_STREAM_EDIT_INTERVAL = 0.6 # min seconds between edit_message_text calls
|
|
||||||
|
|
||||||
def __init__(self, config: Any, bus: MessageBus):
|
def __init__(self, config: Any, bus: MessageBus):
|
||||||
if isinstance(config, dict):
|
if isinstance(config, dict):
|
||||||
config = TelegramConfig.model_validate(config)
|
config = TelegramConfig.model_validate(config)
|
||||||
@ -619,7 +619,7 @@ class TelegramChannel(BaseChannel):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Stream initial send failed: {}", e)
|
logger.warning("Stream initial send failed: {}", e)
|
||||||
raise # Let ChannelManager handle retry
|
raise # Let ChannelManager handle retry
|
||||||
elif (now - buf.last_edit) >= self._STREAM_EDIT_INTERVAL:
|
elif (now - buf.last_edit) >= self.config.stream_edit_interval:
|
||||||
try:
|
try:
|
||||||
await self._call_with_retry(
|
await self._call_with_retry(
|
||||||
self._app.bot.edit_message_text,
|
self._app.bot.edit_message_text,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user