Skip to content

Commit 281ddfe

Browse files
authored
Merge pull request #7 from Spchdt/new-actions
Add echo.py
2 parents 41d85ac + a7d3131 commit 281ddfe

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/actions/client/echo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import asyncio
2+
from typing import TYPE_CHECKING, Any
3+
4+
from src.actions.base import ClientActionHandler, register_client_action
5+
from src.schema.frames import ClientFrame
6+
7+
if TYPE_CHECKING:
8+
from src.engine.connection_context import ConnectionContext
9+
10+
11+
@register_client_action("ECHO")
12+
class EchoActionHandler(ClientActionHandler):
13+
"""Example client action for testing."""
14+
15+
action_type = "ECHO"
16+
context_template = "Client sent an echo message."
17+
18+
def to_context_str(self, payload: dict[str, Any]) -> str:
19+
message = payload.get("message", "")
20+
return f"[EVENT:ECHO] Client sent an echo message: {message}"
21+
22+
async def execute(
23+
self,
24+
frame: ClientFrame,
25+
_ctx: "ConnectionContext",
26+
content_queue: asyncio.Queue[dict[str, Any]],
27+
) -> None:
28+
context_str = self.to_context_str(frame.payload)
29+
await content_queue.put({"type": "text", "text": context_str})

0 commit comments

Comments
 (0)