apisdk

package module
v0.0.0-...-88b8dca Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

api-sdk/message.go

Index

Constants

View Source
const (
	KeySize   = 32 // 256-bit key
	NonceSize = 24 // NaCl secretbox nonce size
)
View Source
const (
	NotificationRoomInvite = "room_invite"
	NotificationError      = "notification.error"
)
View Source
const (
	MemberJoined = "member.joined"
	MemberLeft   = "member.left"
	MemberList   = "member.list"

	MessageReceived = "message.received"
	MessageDeleted  = "message.deleted"
	MessageUpdated  = "message.updated"

	ErrorEvent          = "error"
	AuthenticationError = "error.auth"
	JoinFailed          = "error.join"
	RateLimited         = "error.rate_limited"
	Kicked              = "error.kicked"

	RoomDeleted = "room.deleted"
	RoomUpdated = "room.updated"
)

Variables

View Source
var (
	ErrInvalidKey        = errors.New("invalid key size")
	ErrInvalidCiphertext = errors.New("invalid ciphertext")
	ErrDecryptionFailed  = errors.New("decryption failed")
)
View Source
var (
	ErrMissingIDParameter       = errors.New("missing required id parameter")
	ErrMissingJoinCodeParameter = errors.New("missing required join code parameter")
	ErrMissingUsername          = errors.New("missing required username parameter")
)

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func Decrypt

func Decrypt(ciphertextB64 string, keyBytes []byte) (string, error)

func DecryptWithKeyB64

func DecryptWithKeyB64(ciphertextB64, keyB64 string) (string, error)

DecryptWithKeyB64 decrypts using a base64-encoded key

func DefaultClientOptions

func DefaultClientOptions() []option.RequestOption

func Encrypt

func Encrypt(plaintext string, keyBytes []byte) (string, error)

func EncryptWithKeyB64

func EncryptWithKeyB64(plaintext, keyB64 string) (string, error)

EncryptWithKeyB64 encrypts using a base64-encoded key

func F

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func GenerateKey

func GenerateKey() ([]byte, error)

func GenerateKeyBase64

func GenerateKeyBase64() (string, error)

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type AIEnhanceRequest

type AIEnhanceRequest struct {
	Message string `json:"message"`
	Style   string `json:"style"` // professional, casual, concise, friendly, formal
	Tone    string `json:"tone"`  // confident, polite, neutral, enthusiastic
}

func (*AIEnhanceRequest) MarshalJSON

func (r *AIEnhanceRequest) MarshalJSON() ([]byte, error)

type AIEnhanceResponse

type AIEnhanceResponse struct {
	Original     string   `json:"original"`
	Enhanced     string   `json:"enhanced"`
	Style        string   `json:"style"`
	Tone         string   `json:"tone"`
	Improvements []string `json:"improvements"`
	Cached       bool     `json:"cached"`
}

func (*AIEnhanceResponse) UnmarshalJSON

func (r *AIEnhanceResponse) UnmarshalJSON(data []byte) error

type AIService

type AIService struct {
	Options []option.RequestOption
}

func NewAIService

func NewAIService(opts ...option.RequestOption) *AIService

func (*AIService) Enhance

func (*AIService) HealthCheck

func (s *AIService) HealthCheck(ctx context.Context, opts ...option.RequestOption) (bool, error)

type BootPayload

type BootPayload struct {
	Username string `json:"username"`
	Reason   string `json:"reason"`
}

type Client

type Client struct {
	Options []option.RequestOption
	Room    *RoomService
	Message *MessageService
	Health  *HealthService
	AI      *AIService
	File    *FileService
}

func NewClient

func NewClient(opts ...option.RequestOption) *Client

func (*Client) ConnectNotificationWebSocket

func (c *Client) ConnectNotificationWebSocket(
	ctx context.Context,
	opts ...option.RequestOption,
) (*NotificationWebSocket, error)

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, method, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, params, res any, opts ...option.RequestOption) error

type Error

type Error = apierror.Error

type ErrorPayload

type ErrorPayload struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
	Retry   bool   `json:"retry,omitempty"`
}

type FileResponse

type FileResponse struct {
	ID        string    `json:"id"`
	Filename  string    `json:"filename"`
	MimeType  string    `json:"mime_type"`
	Size      int64     `json:"size"`
	URL       string    `json:"url"`
	CreatedAt time.Time `json:"created_at"`
	Uploader  struct {
		ID       string `json:"id"`
		Username string `json:"username"`
	} `json:"uploader"`
}

func (*FileResponse) UnmarshalJSON

func (r *FileResponse) UnmarshalJSON(data []byte) error

type FileService

type FileService struct {
	Options []option.RequestOption
}

func NewFileService

func NewFileService(opts ...option.RequestOption) *FileService

func (*FileService) Upload

func (s *FileService) Upload(ctx context.Context, roomID, filePath, userID string, opts ...option.RequestOption) (*FileResponse, error)

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
	Time   string `json:"time"`
}

func (*HealthResponse) UnmarshalJSON

func (r *HealthResponse) UnmarshalJSON(data []byte) error

type HealthService

type HealthService struct {
	Options []option.RequestOption
}

func NewHealthService

func NewHealthService(opts ...option.RequestOption) *HealthService

func (*HealthService) Get

Get retrieves the health status of the API

type JoinByCodeParams

type JoinByCodeParams struct {
	JoinCode string `json:"join_code"` // 6-character join code
	Username string `json:"username,omitempty"`
}

func (*JoinByCodeParams) MarshalJSON

func (r *JoinByCodeParams) MarshalJSON() ([]byte, error)

type JoinRoomParams

type JoinRoomParams struct {
	Username string `json:"username,omitempty"`
}

func (*JoinRoomParams) MarshalJSON

func (r *JoinRoomParams) MarshalJSON() ([]byte, error)

type MemberListPayload

type MemberListPayload struct {
	Members []MemberPayload `json:"members"`
}

type MemberPayload

type MemberPayload struct {
	UserID   string `json:"userId"`
	Username string `json:"username"`
	JoinedAt string `json:"joinedAt,omitempty"`
}

type MembershipResponse

type MembershipResponse struct {
	IsMember bool   `json:"is_member"`
	RoomID   string `json:"room_id"`
	UserID   string `json:"user_id,omitempty"`
}

func (*MembershipResponse) UnmarshalJSON

func (r *MembershipResponse) UnmarshalJSON(data []byte) error

type MessageCountResponse

type MessageCountResponse struct {
	RoomID string `json:"room_id"`
	Count  int64  `json:"count"`
}

func (*MessageCountResponse) UnmarshalJSON

func (r *MessageCountResponse) UnmarshalJSON(data []byte) error

type MessageDeletedPayload

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

type MessageDeletedResponse

type MessageDeletedResponse struct {
	Success   bool   `json:"success"`
	MessageID string `json:"message_id"`
}

func (*MessageDeletedResponse) UnmarshalJSON

func (r *MessageDeletedResponse) UnmarshalJSON(data []byte) error

type MessageListAfterParams

type MessageListAfterParams struct {
	Timestamp time.Time
	Limit     int64 // Optional, defaults to 100 on server
}

type MessageListParams

type MessageListParams struct {
	Limit int64 // Optional, defaults to 50 on server
}

type MessagePayload

type MessagePayload struct {
	ID        string `json:"id"`
	Content   string `json:"content"`
	UserID    string `json:"userId"`
	Username  string `json:"username"`
	Timestamp string `json:"timestamp"`
}

type MessageResponse

type MessageResponse struct {
	ID        string    `json:"id"`
	RoomID    string    `json:"room_id"`
	UserID    string    `json:"user_id"`
	Username  string    `json:"username"`
	Content   string    `json:"content"`
	Encrypted bool      `json:"encrypted"`
	CreatedAt time.Time `json:"created_at"`
}

func (*MessageResponse) UnmarshalJSON

func (r *MessageResponse) UnmarshalJSON(data []byte) error

type MessageService

type MessageService struct {
	Options []option.RequestOption
	// contains filtered or unexported fields
}

func NewMessageService

func NewMessageService(opts ...option.RequestOption) *MessageService

func (*MessageService) Count

func (*MessageService) Delete

func (m *MessageService) Delete(ctx context.Context, roomID, messageID string, opts ...option.RequestOption) (*MessageDeletedResponse, error)

func (*MessageService) List

List retrieves and decrypts messages from a room

func (*MessageService) ListAfter

ListAfter retrieves and decrypts messages after a specific timestamp

func (*MessageService) Send

Send encrypts and sends a message to a room

func (*MessageService) SetEncryptionKey

func (m *MessageService) SetEncryptionKey(key string)

SetEncryptionKey sets the room's encryption key for automatic encrypt/decrypt

func (*MessageService) Update

func (m *MessageService) Update(ctx context.Context, roomID, messageID string, body UpdateMessageParams, opts ...option.RequestOption) (*MessageUpdatedResponse, error)

Update encrypts and updates a message

type MessageUpdatedResponse

type MessageUpdatedResponse struct {
	Success   bool   `json:"success"`
	MessageID string `json:"message_id"`
	Content   string `json:"content"`
	Encrypted bool   `json:"encrypted"`
}

func (*MessageUpdatedResponse) UnmarshalJSON

func (r *MessageUpdatedResponse) UnmarshalJSON(data []byte) error

type MessagesResponse

type MessagesResponse struct {
	Messages []MessageResponse `json:"messages"`
	Count    int               `json:"count"`
	RoomID   string            `json:"room_id"`
}

func (*MessagesResponse) UnmarshalJSON

func (r *MessagesResponse) UnmarshalJSON(data []byte) error

type NotificationWSMessage

type NotificationWSMessage struct {
	Type   string         `json:"type"`
	UserID string         `json:"userId"`
	Data   map[string]any `json:"data"`
}

type NotificationWebSocket

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

func (*NotificationWebSocket) Close

func (ws *NotificationWebSocket) Close() error

func (*NotificationWebSocket) Listen

func (ws *NotificationWebSocket) Listen(ctx context.Context) error

func (*NotificationWebSocket) SetErrorHandler

func (ws *NotificationWebSocket) SetErrorHandler(handler func(error))

func (*NotificationWebSocket) SetMessageHandler

func (ws *NotificationWebSocket) SetMessageHandler(handler func(NotificationWSMessage))

type RoomCreateParams

type RoomCreateParams struct {
	ExpiryHours int `json:"expiry_hours"` // 1 to 168 hours (1 hour to 7 days)
}

Request/Response types

func (*RoomCreateParams) MarshalJSON

func (r *RoomCreateParams) MarshalJSON() ([]byte, error)

type RoomDeletedPayload

type RoomDeletedPayload struct {
	RoomID string `json:"roomid"`
}

type RoomResponse

type RoomResponse struct {
	ID            string         `json:"id"`
	JoinCode      string         `json:"join_code"`
	QRCodeURL     string         `json:"qr_code_url"`
	Owner         UserResponse   `json:"owner"`
	CreatedAt     time.Time      `json:"created_at"`
	ExpiresAt     time.Time      `json:"expires_at"`
	Members       []UserResponse `json:"members"`
	CurrentUser   UserResponse   `json:"current_user"`
	EncryptionKey string         `json:"encryption_key"`
}

func (*RoomResponse) UnmarshalJSON

func (r *RoomResponse) UnmarshalJSON(data []byte) error

type RoomService

type RoomService struct {
	Options []option.RequestOption
}

func NewRoomService

func NewRoomService(opts ...option.RequestOption) *RoomService

func (*RoomService) CheckMembership

func (r *RoomService) CheckMembership(ctx context.Context, id string, opts ...option.RequestOption) (*MembershipResponse, error)

CheckMembership checks if the current user is a member of a room

func (*RoomService) ConnectWebSocket

func (r *RoomService) ConnectWebSocket(
	ctx context.Context,
	roomID string,
	opts ...option.RequestOption,
) (*RoomWebSocket, error)

func (*RoomService) Create

Create creates a new room with specified expiry hours

func (*RoomService) Delete

func (r *RoomService) Delete(ctx context.Context, id string, opts ...option.RequestOption) error

Delete deletes a room (only owner can delete)

func (*RoomService) GenerateNewJoinCode

func (r *RoomService) GenerateNewJoinCode(ctx context.Context, id string, opts ...option.RequestOption) error

Generates a new join code for the room

func (*RoomService) Get

func (r *RoomService) Get(ctx context.Context, id string, opts ...option.RequestOption) (*RoomResponse, error)

Get retrieves a room by ID

func (*RoomService) GetByJoinCode

func (r *RoomService) GetByJoinCode(ctx context.Context, body JoinByCodeParams, opts ...option.RequestOption) (*RoomResponse, error)

GetByJoinCode retrieves a room by join code and joins the user to it

func (*RoomService) Join

Join joins an existing room by room ID

func (*RoomService) KickMember

func (r *RoomService) KickMember(ctx context.Context, roomID, userID string, opts ...option.RequestOption) (*SuccessResponse, error)

KickMember kicks a member from the room (only owner can kick)

func (*RoomService) Leave

func (r *RoomService) Leave(ctx context.Context, id string, opts ...option.RequestOption) (*SuccessResponse, error)

Leave leaves a room

type RoomWebSocket

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

func (*RoomWebSocket) Close

func (ws *RoomWebSocket) Close() error

func (*RoomWebSocket) Listen

func (ws *RoomWebSocket) Listen(ctx context.Context) error

func (*RoomWebSocket) SendMessage

func (ws *RoomWebSocket) SendMessage(content string) error

func (*RoomWebSocket) SetErrorHandler

func (ws *RoomWebSocket) SetErrorHandler(handler func(error))

func (*RoomWebSocket) SetMessageHandler

func (ws *RoomWebSocket) SetMessageHandler(handler func(WSMessage))

type SendMessageParams

type SendMessageParams struct {
	Content   string `json:"content"`
	Encrypted bool   `json:"encrypted,omitempty"`
}

func (*SendMessageParams) MarshalJSON

func (r *SendMessageParams) MarshalJSON() ([]byte, error)

type SuccessResponse

type SuccessResponse struct {
	Message string         `json:"message"`
	Data    map[string]any `json:"data,omitempty"`
}

func (*SuccessResponse) UnmarshalJSON

func (r *SuccessResponse) UnmarshalJSON(data []byte) error

type UpdateMessageParams

type UpdateMessageParams struct {
	Content   string `json:"content"`
	Encrypted bool   `json:"encrypted,omitempty"`
}

func (*UpdateMessageParams) MarshalJSON

func (r *UpdateMessageParams) MarshalJSON() ([]byte, error)

type UserResponse

type UserResponse struct {
	ID       string `json:"id"`
	Username string `json:"username"`
}

type WSMessage

type WSMessage struct {
	Type   string `json:"type"`
	RoomID string `json:"roomId"`
	Data   any    `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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