RU Open Web

Type to search client APIs, Bot API methods, and guides.

Build Your Own Client — WebSocket API & RPC
Build Your Own Client WebSocket API & RPC

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

typeKey fields in dataBehavior
pingreq_id optionalKeepalive check returning pong
client_stateApp foreground/background metadataGuides push notification suppression
active_chatchat_id (0 when closed)Suppresses notifications for open conversation
typingchat_id, actiontyping, record_voice, record_round, uploading_photo, uploading_video, uploading_file, uploading_audio, choosing_sticker, stop
emoji_interactionchat_id, message_id, emojiBroadcasts synchronized fullscreen emoji tap animations
send_messagechat_id, content, local_id, file_url, message_type, topic_id, is_round, is_view_once, ttl_seconds, send_as_anonymousIdempotent message creation; returns result.message (or { deduplicated: true, message })
read_history / mark_readchat_id, max_idAdvances High-Water Mark inbox pointer and returns unread count
callback_queryBot inline button payloadTriggers bot callback and returns answer alert/URL
call.*Call IDs, tracks, SDP/ICE payloadscall.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 typeTrigger
new_message, message_edited, message_deleted, message_burnedMessage created, edited, deleted, or self-destruct/view-once expired
message_read, unread_count_updated, unread_badges_updated, message_listenedHigh-Water Mark read state, unread counters, or voice/round listened state changed
message_reaction_updated, message_pinned, message_unpinned, message_views_updated, post_comments_updatedReactions, 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_updatedDialog, group, topic, archive, or theme state changed
member_joined, member_updated, join_requests_updated, scheduled_messages_updatedGroup/channel membership or scheduled post queue updated
draft_updated, typing, emoji_interaction, screenshot_takenCross-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_deletedPresence, profile, avatar, or contact changes
session_terminated, app_update_availableActive session revoked or newer app release published