websocket

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Type      string `json:"type"`      // "message", "ping"
	Content   string `json:"content"`   // message content
	Timestamp int64  `json:"timestamp"` // unix timestamp
}

ChatMessage represents a message sent from client to server

func (*ChatMessage) FromBytes

func (m *ChatMessage) FromBytes(data []byte) error

FromBytes parses JSON bytes to ChatMessage

func (*ChatMessage) IsValidMessageType

func (m *ChatMessage) IsValidMessageType() bool

IsValidMessageType checks if message type is valid

type ChatResponse

type ChatResponse struct {
	Type      string `json:"type"`                 // "message", "history", "status", "error", "pong", "trace"
	Content   string `json:"content"`              // message content
	User      *User  `json:"user,omitempty"`       // sender information
	Timestamp int64  `json:"timestamp"`            // unix timestamp
	MessageID string `json:"message_id,omitempty"` // unique message identifier
}

ChatResponse represents a message sent from server to client

func NewChatResponse

func NewChatResponse(msgType, content string) *ChatResponse

NewChatResponse creates a new ChatResponse with current timestamp

func NewErrorResponse

func NewErrorResponse(content string) *ChatResponse

NewErrorResponse creates an error response

func NewMessageResponse

func NewMessageResponse(content string, user *User) *ChatResponse

NewMessageResponse creates a chat message response

func NewPongResponse

func NewPongResponse() *ChatResponse

NewPongResponse creates a pong response

func NewStatusResponse

func NewStatusResponse(content string) *ChatResponse

NewStatusResponse creates a status response

func NewTraceResponse

func NewTraceResponse(content string, user *User) *ChatResponse

NewTraceResponse creates a trace message response

func (*ChatResponse) IsValidResponseType

func (r *ChatResponse) IsValidResponseType() bool

IsValidResponseType checks if response type is valid

func (*ChatResponse) ToBytes

func (r *ChatResponse) ToBytes() ([]byte, error)

ToBytes converts ChatResponse to JSON bytes

type User

type User struct {
	ID   string `json:"id"`   // user ID
	Name string `json:"name"` // display name
}

User represents user information in WebSocket messages

func UserFromSlackUser

func UserFromSlackUser(slackUser *slack.User) *User

UserFromSlackUser converts slack.User to websocket.User

Jump to

Keyboard shortcuts

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