|
|
|
|
@ -14,6 +14,7 @@ class Nanobot: |
|
|
|
|
def __init__(self): |
|
|
|
|
self._ws = None |
|
|
|
|
self._chat_id = None |
|
|
|
|
self._lock = asyncio.Lock() |
|
|
|
|
|
|
|
|
|
async def __aenter__(self): |
|
|
|
|
await self.connect() |
|
|
|
|
@ -30,6 +31,7 @@ class Nanobot: |
|
|
|
|
main_logger.info("connected chat_id=%s", self._chat_id) |
|
|
|
|
|
|
|
|
|
async def chat(self, message: str, timeout: float = 60): |
|
|
|
|
async with self._lock: |
|
|
|
|
try: |
|
|
|
|
await self._ws.send(json.dumps({"content": message})) |
|
|
|
|
except websockets.ConnectionClosed: |
|
|
|
|
|