WebSocket API & RPC
Bidirectional WebSocket stream (/api/ws), client RPC frame schema ({ type, req_id, data }), and real-time server events.
Connect to the bidirectional WebSocket endpoint using query parameters or headers:
wss://api.theaver.app/api/ws?token=<jwt_token>&device_id=<device_id>
Native clients may pass Authorization: Bearer <jwt_token> and X-Device-ID on the upgrade handshake (browsers can also supply the token via Sec-WebSocket-Protocol). Immediately after upgrading, the server pushes { "type": "connected", "user_id": "...", "timestamp": "..." }.
Client RPC frame format (Client → Server)
Client frames wrap method arguments inside a data object and carry an optional req_id correlation ID:
{
"type": "send_message",
"req_id": "req-101",
"data": {
"chat_id": 849201432,
"content": "Hello over WebSocket RPC",
"local_id": "client-uuid-991",
"reply_to_message_id": null
}
}
When req_id is set, the server replies with either { "type": "rpc_result", "req_id": "req-101", "ok": true, "result": { ... }, "timestamp": "..." } or { "type": "rpc_error", "req_id": "req-101", "ok": false, "error_code": 429, "error": "SLOWMODE_WAIT", "description": "...", "parameters": { "retry_after": 12 } }. Unknown type values return UNKNOWN_METHOD.
Supported client RPC methods
type | Key fields in data | Behavior |
|---|---|---|
ping | req_id optional | Keepalive check returning pong |
client_state | App foreground/background metadata | Guides push notification suppression |
active_chat | chat_id (0 when closed) | Suppresses notifications for open conversation |
typing | chat_id, action | typing, record_voice, record_round, uploading_photo, uploading_video, uploading_file, uploading_audio, choosing_sticker, stop |
emoji_interaction | chat_id, message_id, emoji | Broadcasts synchronized fullscreen emoji tap animations |
send_message | chat_id, content, local_id, file_url, message_type, topic_id, is_round, is_view_once, ttl_seconds, send_as_anonymous | Idempotent message creation; returns result.message (or { deduplicated: true, message }) |
read_history / mark_read | chat_id, max_id | Advances High-Water Mark inbox pointer and returns unread count |
callback_query | Bot inline button payload | Triggers bot callback and returns answer alert/URL |
call.* | Call IDs, tracks, SDP/ICE payloads | call.start, call.accept, call.decline, call.leave, call.transfer_device, call.update_state, call.stream.*, call.signal |
Server push events (Server → Client)
Every push event follows { "type": "<event_type>", ... } and also enters the per-user usn log for offline replay via /api/updates?since_usn=...:
Event type | Trigger |
|---|---|
new_message, message_edited, message_deleted, message_burned | Message created, edited, deleted, or self-destruct/view-once expired |
message_read, unread_count_updated, unread_badges_updated, message_listened | High-Water Mark read state, unread counters, or voice/round listened state changed |
message_reaction_updated, message_pinned, message_unpinned, message_views_updated, post_comments_updated | Reactions, pins, channel views, or discussion counters updated |
new_chat, chat_update, chat_deleted, chat_archive_updated, chat_settings_updated, chat_appearance_updated, chat_auto_delete_updated, chat_unread_marked, forum_topic_updated | Dialog, group, topic, archive, or theme state changed |
member_joined, member_updated, join_requests_updated, scheduled_messages_updated | Group/channel membership or scheduled post queue updated |
draft_updated, typing, emoji_interaction, screenshot_taken | Cross-device drafts, live typing/upload activity, emoji bursts, screenshot alerts |
user_online, user_offline, user_status, user_avatar_updated, user_appearance_updated, contact_updated, contact_deleted | Presence, profile, avatar, or contact changes |
session_terminated, app_update_available | Active session revoked or newer app release published |