Feat v0.5.2 chat surface (#32)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #32.
This commit is contained in:
39
packages/chat/script.star
Normal file
39
packages/chat/script.star
Normal file
@@ -0,0 +1,39 @@
|
||||
# Chat Surface — Starlark Backend (v0.1.0)
|
||||
#
|
||||
# Thin surface layer on top of chat-core library.
|
||||
# Only handles typing indicator broadcast — all CRUD is
|
||||
# delegated to chat-core's own API routes.
|
||||
#
|
||||
# Modules: json, realtime
|
||||
|
||||
def _resp(status, data):
|
||||
return {"status": status, "body": json.encode(data), "headers": {"Content-Type": "application/json"}}
|
||||
|
||||
|
||||
def on_request(req):
|
||||
path = req["path"]
|
||||
method = req["method"]
|
||||
user_id = req.get("user_id", "")
|
||||
|
||||
# POST /typing/:conversation_id — broadcast typing indicator
|
||||
if method == "POST" and path.startswith("/typing/"):
|
||||
cid = path[len("/typing/"):]
|
||||
if not cid:
|
||||
return _resp(400, {"error": "conversation_id required"})
|
||||
|
||||
body = json.decode(req.get("body", "{}"))
|
||||
display_name = str(body.get("display_name", ""))
|
||||
|
||||
realtime.publish(
|
||||
"conversation:" + cid,
|
||||
"typing",
|
||||
{
|
||||
"participant_id": user_id,
|
||||
"display_name": display_name,
|
||||
"conversation_id": cid,
|
||||
},
|
||||
)
|
||||
|
||||
return _resp(200, {"ok": True})
|
||||
|
||||
return _resp(404, {"error": "not found"})
|
||||
Reference in New Issue
Block a user