31 lines
890 B
Python
31 lines
890 B
Python
"""Messaging tool — channel-adapter-backed send_message for the agent."""
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from channels.adapter import ChannelAdapter
|
|
|
|
# Injected by main.py before each invocation
|
|
_adapter: 'ChannelAdapter | None' = None
|
|
_message_sent: bool = False
|
|
|
|
|
|
def set_adapter(adapter: 'ChannelAdapter') -> None:
|
|
global _adapter, _message_sent
|
|
_adapter = adapter
|
|
_message_sent = False # reset on each new invocation
|
|
|
|
|
|
def was_sent() -> bool:
|
|
"""Returns True if send() was called during this invocation."""
|
|
return _message_sent
|
|
|
|
|
|
def send(text: str) -> str:
|
|
"""Send a message to the user via the active channel adapter."""
|
|
global _message_sent
|
|
if _adapter is None:
|
|
return 'No channel adapter configured.'
|
|
msg_id = _adapter.send(text)
|
|
_message_sent = True
|
|
return f"Sent (id={msg_id})" if msg_id else 'Sent'
|