Documentation
¶
Index ¶
- Constants
- func DecodeJSON(resp *http.Response, out any) error
- func IsEventStreamDisconnect(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func ParseError(resp *http.Response) error
- func ParseErrorWithContext(resp *http.Response, context string) error
- func UserFriendlyError(err error) error
- type APIError
- type Account
- type AccountUser
- type Attachment
- type AttachmentSize
- type Chat
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) DeleteJSON(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) OpenEventStream(ctx context.Context) (*EventStream, error)
- func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) PostMultipart(ctx context.Context, path, fieldName, fileName string, file io.Reader, ...) (*http.Response, error)
- func (c *Client) Put(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) RetrieveInfo(ctx context.Context) (InfoResponse, error)
- type ClientOption
- type Contact
- type CreateChatRequest
- type CreateChatResponse
- type DownloadAssetRequest
- type DownloadAssetResponse
- type EditMessageRequest
- type EditMessageResponse
- type EventEnvelope
- type EventStream
- type FlexibleEmoji
- type FlexibleString
- type FocusRequest
- type InfoApp
- type InfoEndpoints
- type InfoPlatform
- type InfoResponse
- type InfoServer
- type ListChatsResponse
- type ListMessagesResponse
- type Message
- type MessagePreview
- type Participant
- type ParticipantList
- type Reaction
- type ReactionRequest
- type ReminderRequest
- type ReminderTime
- type SearchContactsResponse
- type SearchMessagesResponse
- type SearchResponse
- type SendMessageAttachment
- type SendMessageRequest
- type SendMessageResponse
- type SubscriptionSetRequest
- type UploadAssetBase64Request
- type UploadAssetResponse
- type ValidationError
Constants ¶
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 IsEventStreamDisconnect ¶ added in v0.2.18
func IsNotFound ¶
func IsUnauthorized ¶
func ParseError ¶
func ParseErrorWithContext ¶
ParseErrorWithContext returns user-friendly error from HTTP response
func UserFriendlyError ¶
UserFriendlyError wraps an error with a user-friendly message
Types ¶
type APIError ¶
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 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) DeleteJSON ¶ added in v0.2.18
func (*Client) OpenEventStream ¶ added in v0.2.18
func (c *Client) OpenEventStream(ctx context.Context) (*EventStream, 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) 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 EditMessageRequest ¶ added in v0.2.14
type EditMessageRequest struct {
Text string `json:"text"`
}
type EditMessageResponse ¶ added in v0.2.14
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
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 InfoEndpoints ¶ added in v0.2.18
type InfoPlatform ¶ added in v0.2.18
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 ListChatsResponse ¶
type ListMessagesResponse ¶
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 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 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 SubscriptionSetRequest ¶ added in v0.2.18
type UploadAssetBase64Request ¶ added in v0.2.14
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