Documentation
¶
Index ¶
- Constants
- Variables
- type Attachment
- type CallSession
- type Channel
- type Client
- func (c *Client) AuthToken(ctx context.Context, token, deviceID string) error
- func (c *Client) Call(ctx context.Context, calleeExternalID int64, forceRelay bool) (*CallSession, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) CreateGroup(ctx context.Context, name string, memberIDs []int64) (*Packet, error)
- func (c *Client) DeleteMessage(ctx context.Context, chatID int64, messageIDs []string, forMe bool) error
- func (c *Client) EditMessage(ctx context.Context, chatID int64, messageID string, text string, ...) error
- func (c *Client) Errors() <-chan error
- func (c *Client) FindUserByPhone(ctx context.Context, phone string) (*User, error)
- func (c *Client) GetGroupMembers(ctx context.Context, groupID int64) (*Packet, error)
- func (c *Client) GetHistory(ctx context.Context, chatID int64, count int) (*Packet, error)
- func (c *Client) InvokeMethod(ctx context.Context, opcode int, payload any) (*Packet, error)
- func (c *Client) JoinGroup(ctx context.Context, groupID int64) error
- func (c *Client) LeaveGroup(ctx context.Context, groupID int64) error
- func (c *Client) Packets() <-chan *Packet
- func (c *Client) PinMessage(ctx context.Context, chatID int64, messageID string, notify bool) error
- func (c *Client) ResolveByLink(ctx context.Context, link string) (*Packet, error)
- func (c *Client) ResolveChannel(ctx context.Context, channelID int64) (*Packet, error)
- func (c *Client) ResolveUsers(ctx context.Context, userIDs []int64) (*Packet, error)
- func (c *Client) SendMessage(ctx context.Context, chatID int64, text string, opts ...SendMessageOpts) (*Packet, error)
- func (c *Client) SetProfile(ctx context.Context, opts ProfileOpts) error
- func (c *Client) SetSettings(ctx context.Context, opts SettingsOpts) error
- func (c *Client) StartQRAuth(ctx context.Context) (string, error)
- func (c *Client) SubscribeChat(ctx context.Context, chatID int64) (*Packet, error)
- func (c *Client) UploadFile(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
- func (c *Client) UploadPhoto(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
- func (c *Client) UploadVideo(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
- func (c *Client) WaitForCall(ctx context.Context, forceRelay bool) (*CallSession, error)
- func (c *Client) WaitQRAuth(ctx context.Context) (*QRAuth, error)
- type Group
- type Message
- type MessageEvent
- type Option
- type Packet
- type ProfileOpts
- type QRAuth
- type SendMessageOpts
- type SettingsOpts
- type User
Constants ¶
const ( CallsAPIURL = "https://calls.okcdn.ru/fb.do" CallsAppKey = "CNHIJPLGDIHBABABA" CallsClientType = "SDK_JS" CallsClientVersion = "1.1" CallsProtocolVersion = "5" CallsCapabilities = "603F" CallsDeviceType = "browser" CallsPlatform = "WEB" CallsClientTypeSignaling = "ONE_ME" )
Call API constants
const ( WSURL = "wss://ws-api.oneme.ru/websocket" RPCVersion = 11 AppVersion = "26.2.2" DefaultUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" DefaultOrigin = "https://web.max.ru" )
const ( OpcodeKeepalive = 1 OpcodeHello = 6 OpcodeChangeProfile = 16 OpcodeSendCode = 17 OpcodeSignIn = 18 OpcodeLoginByToken = 19 OpcodeSetSettings = 22 OpcodeResolveUsers = 32 OpcodeAddContact = 34 OpcodeAddContactByPhone = 41 OpcodeResolveChannel = 48 OpcodeGetHistory = 49 OpcodePinMessage = 55 OpcodeJoinChannel = 57 OpcodeGetMembers = 59 OpcodeSendMessage = 64 OpcodePrepareAttach = 65 OpcodeDeleteMessage = 66 OpcodeEditMessage = 67 OpcodeSubscribeChat = 75 OpcodeGroupOps = 77 OpcodeFastStartCall = 78 OpcodePhotoUploadURL = 80 OpcodeVideoUploadURL = 82 OpcodeVideoDownloadURL = 83 OpcodeFileUploadURL = 87 OpcodeFileDownloadURL = 88 OpcodeResolveByLink = 89 OpcodeMessageEvent = 128 OpcodeUploadComplete = 136 OpcodeIncomingCall = 137 OpcodeCallToken = 158 OpcodeReactMessage = 178 OpcodeGetReactions = 181 OpcodeGetQR = 288 OpcodeGetQRStatus = 289 OpcodeLoginByQR = 291 )
Opcodes for the MAX protocol.
Variables ¶
var ( ErrDisconnected = errors.New("maxclient: disconnected") ErrReconnecting = errors.New("maxclient: reconnecting") ErrReconnected = errors.New("maxclient: reconnected") ErrAuthRequired = errors.New("maxclient: authentication required") ErrQRExpired = errors.New("maxclient: QR code expired") ErrNotConnected = errors.New("maxclient: not connected") )
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
Type string `json:"_type"`
PhotoToken string `json:"photoToken,omitempty"`
VideoID json.Number `json:"videoId,omitempty"`
FileID json.Number `json:"fileId,omitempty"`
Token string `json:"token,omitempty"`
}
Attachment represents a media attachment in a message. VideoID and FileID use json.Number so they serialize as numbers (server requirement).
type CallSession ¶ added in v0.3.0
type CallSession struct {
// contains filtered or unexported fields
}
CallSession represents an established call with a bidirectional data stream.
func (*CallSession) Close ¶ added in v0.3.0
func (s *CallSession) Close() error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a MAX messenger API client.
func (*Client) AuthToken ¶
AuthToken authenticates using a previously obtained token and device ID. Sends hello -> login_by_token -> starts keepalive.
func (*Client) Call ¶ added in v0.3.0
func (c *Client) Call(ctx context.Context, calleeExternalID int64, forceRelay bool) (*CallSession, error)
Call initiates a call to the given user and returns a CallSession with a bidirectional data stream over ICE. calleeExternalID is the callee's externalId in OneMe (obtain via FindUserByPhone — it's the User.ExternalID field). forceRelay=true restricts to TURN-only candidates (no P2P).
func (*Client) Close ¶
Close gracefully shuts down the client. This is terminal — the client cannot be reused after Close.
func (*Client) Connect ¶
Connect establishes a WebSocket connection to the MAX server. Does not authenticate — call AuthToken or StartQRAuth/WaitQRAuth after connecting.
func (*Client) CreateGroup ¶
CreateGroup creates a new group chat with the given name and member IDs.
func (*Client) DeleteMessage ¶
func (c *Client) DeleteMessage(ctx context.Context, chatID int64, messageIDs []string, forMe bool) error
DeleteMessage deletes messages from a chat.
func (*Client) EditMessage ¶
func (c *Client) EditMessage(ctx context.Context, chatID int64, messageID string, text string, attaches ...Attachment) error
EditMessage edits a message in a chat. Optional attaches can be provided.
func (*Client) Errors ¶
Errors returns a channel of connection errors and status notifications. Status notifications include ErrReconnecting and ErrReconnected.
func (*Client) FindUserByPhone ¶ added in v0.2.0
FindUserByPhone looks up a user by phone number. Calls addContactByPhone to get the user's externalId (contact.id), then resolves the chatID from chat participants via ResolveChannel.
func (*Client) GetGroupMembers ¶
GetGroupMembers retrieves the member list of a group.
func (*Client) GetHistory ¶
GetHistory retrieves chat message history.
func (*Client) InvokeMethod ¶
InvokeMethod sends a request and waits for the matching response. If auto-reconnect is in progress, blocks until reconnection completes (respecting ctx).
func (*Client) LeaveGroup ¶
LeaveGroup leaves a group chat.
func (*Client) PinMessage ¶
PinMessage pins a message in a chat.
func (*Client) ResolveByLink ¶
ResolveByLink resolves a channel or group by its invite link.
func (*Client) ResolveChannel ¶
ResolveChannel resolves a channel by its ID.
func (*Client) ResolveUsers ¶
ResolveUsers resolves users by their IDs.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, chatID int64, text string, opts ...SendMessageOpts) (*Packet, error)
SendMessage sends a text message to a chat.
func (*Client) SetProfile ¶
func (c *Client) SetProfile(ctx context.Context, opts ProfileOpts) error
SetProfile updates the current user's profile fields. Only non-nil fields are sent.
func (*Client) SetSettings ¶
func (c *Client) SetSettings(ctx context.Context, opts SettingsOpts) error
SetSettings updates the current user's settings.
func (*Client) StartQRAuth ¶
StartQRAuth begins QR-code authentication. Sends hello -> requests QR code (opcode 288) -> stores trackId internally -> returns the QR link. Consumer should display the link as a QR code, then call WaitQRAuth.
func (*Client) SubscribeChat ¶ added in v0.2.1
SubscribeChat subscribes to events for the given chat ID. Without subscribing, the WebSocket does not receive message events for a chat.
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
UploadFile uploads a file and waits for server-side processing completion (opcode 136).
func (*Client) UploadPhoto ¶
func (c *Client) UploadPhoto(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
UploadPhoto uploads a photo and returns an Attachment for use in SendMessage.
func (*Client) UploadVideo ¶
func (c *Client) UploadVideo(ctx context.Context, filename string, data io.Reader) (*Attachment, error)
UploadVideo uploads a video and waits for server-side processing completion (opcode 136).
func (*Client) WaitForCall ¶ added in v0.3.0
WaitForCall blocks until an incoming call arrives and establishes the ICE connection. Returns a CallSession with a bidirectional data stream.
type Message ¶
type Message struct {
ID string `json:"id"`
ChatID int64 `json:"chatId,omitempty"`
Text string `json:"text"`
Status string `json:"status,omitempty"`
Sender int64 `json:"sender,omitempty"`
}
Message represents a chat message.
type MessageEvent ¶
MessageEvent is the payload of opcode 128 packets.
func ParseMessageEvent ¶
func ParseMessageEvent(p *Packet) (*MessageEvent, error)
ParseMessageEvent extracts a MessageEvent from a Packet with opcode 128.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAutoReconnect ¶
WithAutoReconnect enables automatic reconnection on disconnect.
func WithHTTPClient ¶ added in v0.3.0
WithHTTPClient sets a custom HTTP client for file uploads.
func WithPacketBufferSize ¶
WithPacketBufferSize sets the buffer size for the Packets channel. Panics if n < 0.
func WithReconnectBackoff ¶
WithReconnectBackoff sets the min and max backoff durations for reconnection.
func WithUserAgent ¶
WithUserAgent sets a custom User-Agent header.
type Packet ¶
type Packet struct {
Ver int `json:"ver"`
Cmd int `json:"cmd"`
Seq int `json:"seq"`
Opcode int `json:"opcode"`
Payload json.RawMessage `json:"payload"`
}
Packet is the wire-level MAX protocol message.
type ProfileOpts ¶
ProfileOpts contains optional parameters for SetProfile.
type SendMessageOpts ¶
type SendMessageOpts struct {
ReplyTo string // empty = no reply
Attaches []Attachment
}
SendMessageOpts contains optional parameters for SendMessage.
type SettingsOpts ¶
SettingsOpts contains optional parameters for SetSettings.