api

package
v0.2.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL     = "http://localhost:23373"
	DefaultHTTPTimeout = 30 * time.Second

	// MaxRateLimitRetries is the maximum number of retries on 429 responses.
	MaxRateLimitRetries = 3

	// RateLimitBaseDelay is the initial delay for rate limit exponential backoff.
	RateLimitBaseDelay = 1 * time.Second

	// Max5xxRetries is the maximum retries for server errors on idempotent requests.
	Max5xxRetries = 1

	// ServerErrorRetryDelay is the delay before retrying on 5xx errors.
	ServerErrorRetryDelay = 1 * time.Second

	// CircuitBreakerThreshold is consecutive 5xx errors to open circuit.
	CircuitBreakerThreshold = 5

	// CircuitBreakerResetTime is how long before trying again.
	CircuitBreakerResetTime = 30 * time.Second
)

Variables

This section is empty.

Functions

func DecodeJSON added in v0.1.7

func DecodeJSON(resp *http.Response, out any) error

func IsEventStreamDisconnect added in v0.2.18

func IsEventStreamDisconnect(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func ParseError

func ParseError(resp *http.Response) error

func ParseErrorWithContext

func ParseErrorWithContext(resp *http.Response, context string) error

ParseErrorWithContext returns user-friendly error from HTTP response

func UserFriendlyError

func UserFriendlyError(err error) error

UserFriendlyError wraps an error with a user-friendly message

Types

type APIError

type APIError struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code"`
	Message    string `json:"message"`
}

func (*APIError) Error

func (e *APIError) Error() string

type Account

type Account struct {
	ID      string       `json:"accountID"`
	Network string       `json:"network"`
	User    *AccountUser `json:"user,omitempty"`
}

Account represents a connected chat network

type AccountUser added in v0.1.4

type AccountUser struct {
	ID          string `json:"id"`
	FullName    string `json:"fullName,omitempty"`
	Email       string `json:"email,omitempty"`
	PhoneNumber string `json:"phoneNumber,omitempty"`
	Username    string `json:"username,omitempty"`
	DisplayText string `json:"displayText,omitempty"`
	ImgURL      string `json:"imgURL,omitempty"`
	IsSelf      bool   `json:"isSelf"`
}

AccountUser represents the user info for an account

type Attachment added in v0.1.6

type Attachment struct {
	Type        string         `json:"type,omitempty"`
	Duration    int            `json:"duration,omitempty"`
	FileName    string         `json:"fileName,omitempty"`
	FileSize    int            `json:"fileSize,omitempty"`
	IsGif       bool           `json:"isGif,omitempty"`
	IsSticker   bool           `json:"isSticker,omitempty"`
	IsVoiceNote bool           `json:"isVoiceNote,omitempty"`
	MimeType    string         `json:"mimeType,omitempty"`
	PosterImg   string         `json:"posterImg,omitempty"`
	Size        AttachmentSize `json:"size,omitempty"`
	SrcURL      string         `json:"srcURL,omitempty"`
}

type AttachmentSize added in v0.1.6

type AttachmentSize struct {
	Width  int `json:"width,omitempty"`
	Height int `json:"height,omitempty"`
}

type Chat

type Chat struct {
	ID                     string           `json:"id"`
	LocalChatID            string           `json:"localChatID,omitempty"`
	AccountID              string           `json:"accountID"`
	Network                string           `json:"network,omitempty"`
	Title                  string           `json:"title"`
	Description            string           `json:"description,omitempty"`
	Type                   string           `json:"type"` // "dm", "single", or "group"
	UnreadCount            int              `json:"unreadCount"`
	IsUnread               bool             `json:"isUnread,omitempty"`
	IsMuted                bool             `json:"isMuted"`
	IsArchived             bool             `json:"isArchived"`
	IsPinned               bool             `json:"isPinned"`
	LastActivity           time.Time        `json:"lastActivity"`
	Preview                *MessagePreview  `json:"preview,omitempty"`
	Participants           *ParticipantList `json:"participants,omitempty"`
	LastReadMessageSortKey FlexibleString   `json:"lastReadMessageSortKey,omitempty"`
	ReminderAt             *time.Time       `json:"reminderAt,omitempty"`
}

Chat represents a conversation

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, token string, opts ...ClientOption) *Client

func (*Client) BaseURL added in v0.2.18

func (c *Client) BaseURL() string

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)

func (*Client) DeleteJSON added in v0.2.18

func (c *Client) DeleteJSON(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

func (*Client) OpenEventStream added in v0.2.18

func (c *Client) OpenEventStream(ctx context.Context) (*EventStream, error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) PostMultipart added in v0.2.14

func (c *Client) PostMultipart(ctx context.Context, path, fieldName, fileName string, file io.Reader, fields map[string]string) (*http.Response, error)

PostMultipart sends a multipart/form-data POST request with a file and optional fields. It bypasses Do() to avoid the hardcoded Content-Type: application/json header.

func (*Client) Put added in v0.2.14

func (c *Client) Put(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) RetrieveInfo added in v0.2.18

func (c *Client) RetrieveInfo(ctx context.Context) (InfoResponse, error)

type ClientOption

type ClientOption func(*Client)

func WithDebug

func WithDebug(debug bool) ClientOption

func WithDebugWriter added in v0.1.7

func WithDebugWriter(w io.Writer) ClientOption

type Contact added in v0.2.14

type Contact struct {
	ID            string `json:"id"`
	Username      string `json:"username,omitempty"`
	PhoneNumber   string `json:"phoneNumber,omitempty"`
	Email         string `json:"email,omitempty"`
	FullName      string `json:"fullName,omitempty"`
	ImgURL        string `json:"imgURL,omitempty"`
	CannotMessage bool   `json:"cannotMessage,omitempty"`
	IsSelf        bool   `json:"isSelf,omitempty"`
}

type CreateChatRequest added in v0.2.14

type CreateChatRequest struct {
	AccountID      string   `json:"accountID"`
	Type           string   `json:"type"`
	ParticipantIDs []string `json:"participantIDs"`
	Title          string   `json:"title,omitempty"`
	MessageText    string   `json:"messageText,omitempty"`
}

CreateChatRequest for creating a new chat

type CreateChatResponse added in v0.2.14

type CreateChatResponse struct {
	ChatID string `json:"chatID"`
}

type DownloadAssetRequest added in v0.2.14

type DownloadAssetRequest struct {
	URL string `json:"url"`
}

type DownloadAssetResponse added in v0.2.14

type DownloadAssetResponse struct {
	SrcURL string `json:"srcURL,omitempty"`
	Error  string `json:"error,omitempty"`
}

type EditMessageRequest added in v0.2.14

type EditMessageRequest struct {
	Text string `json:"text"`
}

type EditMessageResponse added in v0.2.14

type EditMessageResponse struct {
	ChatID    string `json:"chatID"`
	MessageID string `json:"messageID"`
	Success   bool   `json:"success"`
}

type EventEnvelope added in v0.2.18

type EventEnvelope struct {
	Type      string            `json:"type"`
	RequestID string            `json:"requestID,omitempty"`
	Version   int               `json:"version,omitempty"`
	ChatIDs   []string          `json:"chatIDs,omitempty"`
	Code      string            `json:"code,omitempty"`
	Message   string            `json:"message,omitempty"`
	Seq       int64             `json:"seq,omitempty"`
	TS        int64             `json:"ts,omitempty"`
	ChatID    string            `json:"chatID,omitempty"`
	IDs       []string          `json:"ids,omitempty"`
	Entries   []json.RawMessage `json:"entries,omitempty"`
}

func (EventEnvelope) IsControl added in v0.2.18

func (e EventEnvelope) IsControl() bool

func (EventEnvelope) Timestamp added in v0.2.18

func (e EventEnvelope) Timestamp() time.Time

type EventStream added in v0.2.18

type EventStream struct {
	// contains filtered or unexported fields
}

func (*EventStream) Close added in v0.2.18

func (s *EventStream) Close() error

func (*EventStream) Next added in v0.2.18

func (s *EventStream) Next(ctx context.Context) (EventEnvelope, error)

func (*EventStream) SetSubscriptions added in v0.2.18

func (s *EventStream) SetSubscriptions(ctx context.Context, chatIDs []string, requestID string) error

type FlexibleEmoji added in v0.2.0

type FlexibleEmoji string

FlexibleEmoji is a type that can unmarshal from string, bool, or null JSON values The Beeper API sometimes returns bool for emoji fields (e.g., false when no custom emoji)

func (FlexibleEmoji) String added in v0.2.0

func (fe FlexibleEmoji) String() string

String returns the string value

func (*FlexibleEmoji) UnmarshalJSON added in v0.2.0

func (fe *FlexibleEmoji) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling to handle string, bool, and null types

type FlexibleString added in v0.1.8

type FlexibleString string

FlexibleString is a type that can unmarshal from both string and number JSON values

func (FlexibleString) String added in v0.1.8

func (fs FlexibleString) String() string

String returns the string value

func (*FlexibleString) UnmarshalJSON added in v0.1.8

func (fs *FlexibleString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling to handle both string and number types

type FocusRequest

type FocusRequest struct {
	ChatID              string `json:"chatID,omitempty"`
	MessageID           string `json:"messageID,omitempty"`
	DraftText           string `json:"draftText,omitempty"`
	DraftAttachmentPath string `json:"draftAttachmentPath,omitempty"`
}

FocusRequest for focusing Beeper window

type InfoApp added in v0.2.18

type InfoApp struct {
	BundleID string `json:"bundle_id"`
	Name     string `json:"name"`
	Version  string `json:"version"`
}

type InfoEndpoints added in v0.2.18

type InfoEndpoints struct {
	MCP      string `json:"mcp"`
	Spec     string `json:"spec"`
	WSEvents string `json:"ws_events"`
}

type InfoPlatform added in v0.2.18

type InfoPlatform struct {
	Arch    string `json:"arch"`
	OS      string `json:"os"`
	Release string `json:"release,omitempty"`
}

type InfoResponse added in v0.2.18

type InfoResponse struct {
	App       InfoApp       `json:"app"`
	Endpoints InfoEndpoints `json:"endpoints"`
	Platform  InfoPlatform  `json:"platform"`
	Server    InfoServer    `json:"server"`
}

type InfoServer added in v0.2.18

type InfoServer struct {
	BaseURL      string `json:"base_url"`
	Hostname     string `json:"hostname"`
	MCPEnabled   bool   `json:"mcp_enabled"`
	Port         int    `json:"port"`
	RemoteAccess bool   `json:"remote_access"`
	Status       string `json:"status"`
}

type ListChatsResponse

type ListChatsResponse struct {
	Items        []Chat `json:"items"`
	Total        int    `json:"total"`
	HasMore      bool   `json:"hasMore"`
	Cursor       string `json:"cursor,omitempty"`
	NewestCursor string `json:"newestCursor,omitempty"`
	OldestCursor string `json:"oldestCursor,omitempty"`
}

type ListMessagesResponse

type ListMessagesResponse struct {
	Items   []Message `json:"items"`
	HasMore bool      `json:"hasMore"`
	Cursor  string    `json:"cursor,omitempty"`
}

type Message

type Message struct {
	SortKey         FlexibleString `json:"sortKey,omitempty"`
	ID              string         `json:"id"`
	ChatID          string         `json:"chatID"`
	AccountID       string         `json:"accountID"`
	SenderID        string         `json:"senderID"`
	Sender          string         `json:"sender"`
	SenderName      string         `json:"senderName,omitempty"`
	Text            string         `json:"text"`
	Timestamp       time.Time      `json:"timestamp"`
	IsMe            bool           `json:"isMe"`
	IsSender        bool           `json:"isSender,omitempty"`
	IsUnread        bool           `json:"isUnread,omitempty"`
	Attachments     []Attachment   `json:"attachments"`
	Reactions       []Reaction     `json:"reactions"`
	LinkedMessageID string         `json:"linkedMessageID,omitempty"`
	ReplyTo         *Message       `json:"replyTo,omitempty"`
}

Message represents a chat message

type MessagePreview

type MessagePreview struct {
	Text      string    `json:"text"`
	Sender    string    `json:"sender,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

MessagePreview is the preview shown in chat list

type Participant

type Participant struct {
	ID          string `json:"id"`
	FullName    string `json:"fullName"`
	Username    string `json:"username,omitempty"`
	PhoneNumber string `json:"phoneNumber,omitempty"`
	ImgURL      string `json:"imgURL,omitempty"`
	IsSelf      bool   `json:"isSelf"`
	IsAdmin     bool   `json:"isAdmin"`
	IsVerified  bool   `json:"isVerified"`
}

type ParticipantList

type ParticipantList struct {
	Items []Participant `json:"items"`
}

ParticipantList wraps the participants array

type Reaction added in v0.1.6

type Reaction struct {
	ID            string        `json:"id,omitempty"`
	ParticipantID string        `json:"participantID,omitempty"`
	ReactionKey   string        `json:"reactionKey,omitempty"`
	Emoji         FlexibleEmoji `json:"emoji,omitempty"`
	ImgURL        string        `json:"imgURL,omitempty"`
}

type ReactionRequest added in v0.1.6

type ReactionRequest struct {
	ReactionKey string `json:"reactionKey"`
}

ReactionRequest for adding a reaction

type ReminderRequest

type ReminderRequest struct {
	Reminder                 ReminderTime `json:"reminder"`
	DismissOnIncomingMessage bool         `json:"dismissOnIncomingMessage,omitempty"`
}

ReminderRequest for setting a reminder

type ReminderTime

type ReminderTime struct {
	RemindAtMs int64 `json:"remindAtMs"`
}

ReminderTime represents the time format expected by Beeper API

func NewReminderTime

func NewReminderTime(t time.Time) ReminderTime

NewReminderTime creates a ReminderTime from a time.Time

type SearchContactsResponse added in v0.2.14

type SearchContactsResponse struct {
	Items []Contact `json:"items"`
}

type SearchMessagesResponse

type SearchMessagesResponse struct {
	Messages []Message       `json:"messages"`
	Chats    map[string]Chat `json:"chats"`
	HasMore  bool            `json:"hasMore"`
	Cursor   string          `json:"cursor,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	Chats    []Chat    `json:"chats"`
	Messages []Message `json:"messages"`
	HasMore  bool      `json:"hasMore"`
}

SearchResponse for unified search

type SendMessageAttachment added in v0.2.14

type SendMessageAttachment struct {
	UploadID string          `json:"uploadID"`
	MimeType string          `json:"mimeType,omitempty"`
	FileName string          `json:"fileName,omitempty"`
	Size     *AttachmentSize `json:"size,omitempty"`
	Duration int             `json:"duration,omitempty"`
	Type     string          `json:"type,omitempty"`
}

type SendMessageRequest

type SendMessageRequest struct {
	Text             string                 `json:"text,omitempty"`
	ReplyToMessageID string                 `json:"replyToMessageID,omitempty"`
	Attachment       *SendMessageAttachment `json:"attachment,omitempty"`
}

SendMessageRequest for sending a message

type SendMessageResponse

type SendMessageResponse struct {
	ChatID           string `json:"chatID"`
	PendingMessageID string `json:"pendingMessageID"`
}

type SubscriptionSetRequest added in v0.2.18

type SubscriptionSetRequest struct {
	Type      string   `json:"type"`
	RequestID string   `json:"requestID,omitempty"`
	ChatIDs   []string `json:"chatIDs"`
}

type UploadAssetBase64Request added in v0.2.14

type UploadAssetBase64Request struct {
	Content  string `json:"content"`
	FileName string `json:"fileName,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
}

type UploadAssetResponse added in v0.2.14

type UploadAssetResponse struct {
	UploadID string `json:"uploadID,omitempty"`
	SrcURL   string `json:"srcURL,omitempty"`
	FileName string `json:"fileName,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
	FileSize int    `json:"fileSize,omitempty"`
	Width    int    `json:"width,omitempty"`
	Height   int    `json:"height,omitempty"`
	Duration int    `json:"duration,omitempty"`
	Error    string `json:"error,omitempty"`
}

type ValidationError

type ValidationError struct {
	Code     string   `json:"code"`
	Expected string   `json:"expected,omitempty"`
	Received string   `json:"received,omitempty"`
	Path     []string `json:"path,omitempty"`
	Message  string   `json:"message"`
}

ValidationError represents a single validation error from the API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL