Documentation
¶
Overview ¶
api-sdk/message.go
Index ¶
- Constants
- Variables
- func Bool(value bool) param.Field[bool]
- func Decrypt(ciphertextB64 string, keyBytes []byte) (string, error)
- func DecryptWithKeyB64(ciphertextB64, keyB64 string) (string, error)
- func DefaultClientOptions() []option.RequestOption
- func Encrypt(plaintext string, keyBytes []byte) (string, error)
- func EncryptWithKeyB64(plaintext, keyB64 string) (string, error)
- func F[T any](value T) param.Field[T]
- func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]
- func Float(value float64) param.Field[float64]
- func GenerateKey() ([]byte, error)
- func GenerateKeyBase64() (string, error)
- func Int(value int64) param.Field[int64]
- func Null[T any]() param.Field[T]
- func Raw[T any](value any) param.Field[T]
- func String(value string) param.Field[string]
- type AIEnhanceRequest
- type AIEnhanceResponse
- type AIService
- type BootPayload
- type Client
- func (c *Client) ConnectNotificationWebSocket(ctx context.Context, opts ...option.RequestOption) (*NotificationWebSocket, error)
- func (c *Client) Delete(ctx context.Context, path string, params, res any, ...) error
- func (c *Client) Execute(ctx context.Context, method, path string, params, res any, ...) error
- func (c *Client) Get(ctx context.Context, path string, params, res any, ...) error
- func (c *Client) Post(ctx context.Context, path string, params, res any, ...) error
- func (c *Client) Put(ctx context.Context, path string, params, res any, ...) error
- type Error
- type ErrorPayload
- type FileResponse
- type FileService
- type HealthResponse
- type HealthService
- type JoinByCodeParams
- type JoinRoomParams
- type MemberListPayload
- type MemberPayload
- type MembershipResponse
- type MessageCountResponse
- type MessageDeletedPayload
- type MessageDeletedResponse
- type MessageListAfterParams
- type MessageListParams
- type MessagePayload
- type MessageResponse
- type MessageService
- func (m *MessageService) Count(ctx context.Context, roomID string, opts ...option.RequestOption) (*MessageCountResponse, error)
- func (m *MessageService) Delete(ctx context.Context, roomID, messageID string, opts ...option.RequestOption) (*MessageDeletedResponse, error)
- func (m *MessageService) List(ctx context.Context, roomID string, query MessageListParams, ...) (*MessagesResponse, error)
- func (m *MessageService) ListAfter(ctx context.Context, roomID string, query MessageListAfterParams, ...) (*MessagesResponse, error)
- func (m *MessageService) Send(ctx context.Context, roomID string, body SendMessageParams, ...) (*MessageResponse, error)
- func (m *MessageService) SetEncryptionKey(key string)
- func (m *MessageService) Update(ctx context.Context, roomID, messageID string, body UpdateMessageParams, ...) (*MessageUpdatedResponse, error)
- type MessageUpdatedResponse
- type MessagesResponse
- type NotificationWSMessage
- type NotificationWebSocket
- type RoomCreateParams
- type RoomDeletedPayload
- type RoomResponse
- type RoomService
- func (r *RoomService) CheckMembership(ctx context.Context, id string, opts ...option.RequestOption) (*MembershipResponse, error)
- func (r *RoomService) ConnectWebSocket(ctx context.Context, roomID string, opts ...option.RequestOption) (*RoomWebSocket, error)
- func (r *RoomService) Create(ctx context.Context, body RoomCreateParams, opts ...option.RequestOption) (*RoomResponse, error)
- func (r *RoomService) Delete(ctx context.Context, id string, opts ...option.RequestOption) error
- func (r *RoomService) GenerateNewJoinCode(ctx context.Context, id string, opts ...option.RequestOption) error
- func (r *RoomService) Get(ctx context.Context, id string, opts ...option.RequestOption) (*RoomResponse, error)
- func (r *RoomService) GetByJoinCode(ctx context.Context, body JoinByCodeParams, opts ...option.RequestOption) (*RoomResponse, error)
- func (r *RoomService) Join(ctx context.Context, id string, body JoinRoomParams, ...) (*SuccessResponse, error)
- func (r *RoomService) KickMember(ctx context.Context, roomID, userID string, opts ...option.RequestOption) (*SuccessResponse, error)
- func (r *RoomService) Leave(ctx context.Context, id string, opts ...option.RequestOption) (*SuccessResponse, error)
- type RoomWebSocket
- type SendMessageParams
- type SuccessResponse
- type UpdateMessageParams
- type UserResponse
- type WSMessage
Constants ¶
const ( KeySize = 32 // 256-bit key NonceSize = 24 // NaCl secretbox nonce size )
const ( NotificationRoomInvite = "room_invite" NotificationError = "notification.error" )
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 ¶
Functions ¶
func DecryptWithKeyB64 ¶
DecryptWithKeyB64 decrypts using a base64-encoded key
func DefaultClientOptions ¶
func DefaultClientOptions() []option.RequestOption
func EncryptWithKeyB64 ¶
EncryptWithKeyB64 encrypts using a base64-encoded key
func F ¶
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 GenerateKey ¶
func GenerateKeyBase64 ¶
func Int ¶
Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.
func Raw ¶
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).
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 (s *AIService) Enhance(ctx context.Context, body AIEnhanceRequest, opts ...option.RequestOption) (*AIEnhanceResponse, error)
func (*AIService) HealthCheck ¶
type BootPayload ¶
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)
type ErrorPayload ¶
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 ¶
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 ¶
func (h *HealthService) Get(ctx context.Context, opts ...option.RequestOption) (*HealthResponse, error)
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 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 ¶
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 MessageListParams ¶
type MessageListParams struct {
Limit int64 // Optional, defaults to 50 on server
}
type MessagePayload ¶
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 (m *MessageService) Count(ctx context.Context, roomID string, opts ...option.RequestOption) (*MessageCountResponse, error)
func (*MessageService) Delete ¶
func (m *MessageService) Delete(ctx context.Context, roomID, messageID string, opts ...option.RequestOption) (*MessageDeletedResponse, error)
func (*MessageService) List ¶
func (m *MessageService) List(ctx context.Context, roomID string, query MessageListParams, opts ...option.RequestOption) (*MessagesResponse, error)
List retrieves and decrypts messages from a room
func (*MessageService) ListAfter ¶
func (m *MessageService) ListAfter(ctx context.Context, roomID string, query MessageListAfterParams, opts ...option.RequestOption) (*MessagesResponse, error)
ListAfter retrieves and decrypts messages after a specific timestamp
func (*MessageService) Send ¶
func (m *MessageService) Send(ctx context.Context, roomID string, body SendMessageParams, opts ...option.RequestOption) (*MessageResponse, error)
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 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 ¶
func (r *RoomService) Create(ctx context.Context, body RoomCreateParams, opts ...option.RequestOption) (*RoomResponse, error)
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 ¶
func (r *RoomService) Join(ctx context.Context, id string, body JoinRoomParams, opts ...option.RequestOption) (*SuccessResponse, error)
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) 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)