Add new WebSocket message types and event handlers to CachiBot's real-time streaming system. Use this skill when adding new real-time events, live updates, or bidirectional WebSocket communication — e.g., "add live progress events", "stream file upload status", "add approval request events".
Add new WebSocket message types and event handlers to CachiBot's real-time streaming system. Use this skill when adding new real-time events, live updates, or bidirectional WebSocket communication — e.g., "add live progress events", "stream file upload status", "add approval request events".
metadata
{"author":"cachibot","version":"1.0"}
CachiBot WebSocket Event Creation
Add new real-time WebSocket events spanning the backend server, frontend hook, and store integration.
In the relevant handler (e.g., websocket.py or a service), send the event:
from cachibot.api.websocket import manager
# Send to a specific clientawait manager.send(client_id, WSMessage.your_event(
item_id="abc",
status="completed",
data={"result": "..."},
))
# Or broadcast to all clients of a botawait manager.broadcast(bot_id, WSMessage.your_event(...))
Sending from run_agent() in websocket.py
If the event is triggered during agent execution, add it to the streaming loop:
// Import store actionsimport { useYourStore } from'../stores/your-store'// Inside the message handler switch:case'your_event': {
const payload = msg.payloadasYourEventPayload// Update store with the event data
useYourStore.getState().handleYourEvent(payload)
break
}
Step 5: Frontend — Send from Client (if bidirectional)
Add a send method to the WebSocket client or expose through the hook:
// In api/websocket.ts — add to WebSocketClient class:sendYourRequest(data: YourRequestPayload): void {
this.send('your_request', data)
}
// In hooks/useWebSocket.ts — expose in the hook return:const sendYourRequest = useCallback((data: YourRequestPayload) => {
wsClient.sendYourRequest(data)
}, [])
return { ..., sendYourRequest }
Step 6: Frontend — Store Integration
Add handling in the relevant Zustand store:
// In your store:interfaceYourState {
// ... existing state ...handleYourEvent: (payload: YourEventPayload) =>void
}
exportconst useYourStore = create<YourState>()(
(set) => ({
// ... existing state ...handleYourEvent: (payload) =>set((state) => {
// Update state based on the eventreturn {
items: state.items.map((item) =>
item.id === payload.item_id
? { ...item, status: payload.status }
: item
),
}
}),
})
)