api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverAPI

func DiscoverAPI() (string, error)

DiscoverAPI attempts to auto-discover the Beeper Desktop API URL

func IsAuthError added in v0.4.0

func IsAuthError(err error) bool

IsAuthError returns true if the error is an authentication error

func IsNetworkError added in v0.4.0

func IsNetworkError(err error) bool

IsNetworkError returns true if the error is a network error

func IsNotFoundError added in v0.4.0

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a not found error

Types

type APIError added in v0.4.0

type APIError struct {
	// Message is the human-readable error message
	Message string `json:"message"`
	// Code is the error code (e.g., "auth_required", "chat_not_found")
	Code string `json:"code,omitempty"`
	// Category is the error category for hint generation
	Category ErrorCategory `json:"category"`
	// StatusCode is the HTTP status code
	StatusCode int `json:"status_code,omitempty"`
	// Operation is the operation that failed (e.g., "list_chats", "send_message")
	Operation string `json:"operation,omitempty"`
	// Hint is an actionable suggestion for resolving the error
	Hint string `json:"hint,omitempty"`
	// Underlying is the underlying error (not serialized to JSON)
	Underlying error `json:"-"`
}

APIError represents a structured error from the API

func NewAPIError added in v0.4.0

func NewAPIError(message string, category ErrorCategory) *APIError

NewAPIError creates a new APIError with the given parameters

func NewAPIErrorFromStatus added in v0.4.0

func NewAPIErrorFromStatus(statusCode int, body []byte, operation string) *APIError

NewAPIErrorFromStatus creates an APIError from an HTTP status code and response body

func WrapConfigError added in v0.4.0

func WrapConfigError(err error, message string) *APIError

WrapConfigError wraps a configuration error with appropriate context

func WrapNetworkError added in v0.4.0

func WrapNetworkError(err error, operation string) *APIError

WrapNetworkError wraps a network error with appropriate context

func (*APIError) Error added in v0.4.0

func (e *APIError) Error() string

Error implements the error interface

func (*APIError) ToJSON added in v0.4.0

func (e *APIError) ToJSON() string

ToJSON returns the error as a JSON string

func (*APIError) Unwrap added in v0.4.0

func (e *APIError) Unwrap() error

Unwrap returns the underlying error

func (*APIError) WithHint added in v0.4.0

func (e *APIError) WithHint(hint string) *APIError

WithHint sets the hint field and returns the error

func (*APIError) WithOperation added in v0.4.0

func (e *APIError) WithOperation(op string) *APIError

WithOperation sets the operation field and returns the error

type Chat

type Chat struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	Type        string `json:"type"`
	Network     string `json:"network"`
	UnreadCount int    `json:"unreadCount"`
	IsMuted     bool   `json:"isMuted"`
	IsArchived  bool   `json:"isArchived"`
	IsPinned    bool   `json:"isPinned"`
	// Store participants as raw JSON since it's a complex nested object
	Participants map[string]interface{} `json:"participants"`
}

Chat represents a Beeper chat/conversation Using a simplified structure that works with JSON unmarshaling

type ChatsResponse

type ChatsResponse struct {
	Items   []Chat `json:"items"`
	HasMore bool   `json:"hasMore"`
}

Chat represents a Beeper chat/conversation ChatsResponse represents the API response for listing chats

type Client

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

Client handles communication with Beeper Desktop API

func NewClient

func NewClient(baseURL string) *Client

NewClient creates a new API client

func (*Client) GetBaseURL added in v0.4.0

func (c *Client) GetBaseURL() string

GetBaseURL returns the base URL of the API

func (*Client) GetChat

func (c *Client) GetChat(chatID string) (*Chat, error)

GetChat retrieves a specific chat by ID

func (*Client) GetDesktopVersion added in v0.4.0

func (c *Client) GetDesktopVersion() string

GetDesktopVersion returns the cached Beeper Desktop version from the last API response

func (*Client) HasAuthToken added in v0.4.0

func (c *Client) HasAuthToken() bool

HasAuthToken returns true if an auth token is set

func (*Client) ListChats

func (c *Client) ListChats() ([]Chat, error)

ListChats retrieves all chats

func (*Client) ListMessages

func (c *Client) ListMessages(chatID string, limit int) ([]Message, error)

ListMessages retrieves messages from a chat

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the API is reachable

func (*Client) SearchMessages

func (c *Client) SearchMessages(query string, limit int) ([]Message, error)

SearchMessages searches for messages across all chats

func (*Client) SendMessage

func (c *Client) SendMessage(chatID, message string) (string, error)

SendMessage sends a message to a chat and returns the message ID

func (*Client) SetAuthToken

func (c *Client) SetAuthToken(token string)

SetAuthToken sets the Bearer authentication token

type ErrorCategory added in v0.4.0

type ErrorCategory string

ErrorCategory represents the type of error for categorization

const (
	// CategoryAuth indicates authentication/authorization errors
	CategoryAuth ErrorCategory = "auth"
	// CategoryConfig indicates configuration errors
	CategoryConfig ErrorCategory = "config"
	// CategoryPermission indicates permission/scope errors
	CategoryPermission ErrorCategory = "permission"
	// CategoryNotFound indicates resource not found errors
	CategoryNotFound ErrorCategory = "not_found"
	// CategoryNetwork indicates network/connectivity errors
	CategoryNetwork ErrorCategory = "network"
	// CategoryValidation indicates input validation errors
	CategoryValidation ErrorCategory = "validation"
	// CategoryServer indicates server-side errors
	CategoryServer ErrorCategory = "server"
	// CategoryUnknown indicates unknown/uncategorized errors
	CategoryUnknown ErrorCategory = "unknown"
)

type Message

type Message struct {
	ID        string `json:"id"`
	ChatID    string `json:"chatID"`
	Sender    string `json:"senderName"`
	Text      string `json:"text"`
	Timestamp string `json:"timestamp"` // ISO 8601 timestamp string
	IsSender  bool   `json:"isSender"`
}

Message represents a Beeper message

type MessagesResponse

type MessagesResponse struct {
	Items   []Message `json:"items"`
	HasMore bool      `json:"hasMore"`
}

MessagesResponse represents the API response for listing messages

type SearchResponse

type SearchResponse struct {
	Items []Message `json:"items"`
}

SearchResponse represents the API response for searching messages

type SendMessageRequest

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

SendMessageRequest represents a message send request

type SendMessageResponse

type SendMessageResponse struct {
	ID string `json:"id"`
}

SendMessageResponse represents the API response after sending a message

Jump to

Keyboard shortcuts

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