ryOS ryOS / Docs
GitHub Launch

Presence API

Endpoints for presence tracking, user search, and AI integration in chat rooms.

Overview

Presence tracking keeps track of which users are currently active in which rooms. The AI endpoint allows users to get AI-generated responses within chat rooms.

Endpoint Summary

MethodEndpointDescriptionAuth
POST/api/presence/switchSwitch rooms (presence tracking)Yes
GET/api/users?search=...Search usersNo
POST/api/ai/ryo-replyGenerate Ryo AI replyYes

Presence

Switch Rooms

Update presence when a user switches between rooms. This is used for real-time "who's online" functionality.

POST /api/presence/switch
Authorization: Bearer {token}
X-Username: alice
Content-Type: application/json

{
  "previousRoomId": "general",
  "nextRoomId": "random",
  "username": "alice"
}
Request Body:
FieldTypeRequiredDescription
previousRoomIdstringNoRoom the user is leaving (null if first room)
nextRoomIdstringNoRoom the user is entering (null if leaving all)
usernamestringYesUser's username
Response (200):
{
  "success": true
}
Use Cases:
  • User opens chat app → previousRoomId: null, nextRoomId: "general"
  • User switches rooms → previousRoomId: "general", nextRoomId: "random"
  • User closes chat app → previousRoomId: "random", nextRoomId: null

User Search

Search Users

Search for users by username prefix.

GET /api/users?search=ali
Query Parameters:
ParameterTypeRequiredDescription
searchstringYesUsername search string (minimum 2 chars; shorter queries return empty list)
Response (200):
{
  "users": [
    {
      "username": "alice",
      "lastActive": 1704067200000
    },
    {
      "username": "alicia",
      "lastActive": 1704000000000
    }
  ]
}

AI Integration

Ryo Reply

Generate an AI response from Ryo within a chat room. This is triggered when users mention @ryo in their messages.

POST /api/ai/ryo-reply
Authorization: Bearer {token}
X-Username: alice
Content-Type: application/json

{
  "roomId": "general",
  "prompt": "what's up?",
  "systemState": {
    "chatRoomContext": {
      "recentMessages": "alice: hey everyone\nbob: hi alice\nalice: @ryo what's up?",
      "mentionedMessage": "@ryo what's up?"
    }
  }
}
Request Body:
FieldTypeRequiredDescription
roomIdstringYesRoom where the mention occurred
promptstringYesThe user's message/question
systemState.chatRoomContext.recentMessagesstringNoRecent chat history
systemState.chatRoomContext.mentionedMessagestringNoMessage that mentioned @ryo
Response (201):
{
  "message": {
    "id": "msg_123",
    "roomId": "general",
    "username": "ryo",
    "content": "hey, what's up",
    "timestamp": 1704067320000
  }
}

Rate Limits

User TypeLimitWindow
Authenticated5 requests1 minute

AI Behavior

When mentioned in chat rooms, Ryo:

  • Considers recent chat context
  • Responds in a casual, friendly tone
  • Can answer questions, provide information, or just chat
  • Respects the room's conversation flow

Real-time Updates

Presence changes and AI replies trigger Pusher broadcasts to connected clients:

EventChannelPayload
room-updatedchats-public / chats-{username}{ room }
room-messageroom-{roomId}{ roomId, message }

Error Responses

StatusErrorDescription
400Invalid requestMissing or invalid parameters
401Authentication requiredToken missing (for AI reply)
403UnauthorizedOrigin not allowed
404Room not foundRoom ID doesn't exist
429Rate limit exceededToo many AI requests
500Failed to generate replyAI service error

Related