package ws import ( "encoding/json" "homestead/homestead_gateway/util/cache" "homestead/homestead_gateway/util/queue" "log/slog" "time" "github.com/gorilla/websocket" ) type WebsocketGateway struct { port int apiKey string bodySizeBytes int64 upgrader websocket.Upgrader cache *cache.Cache queue *queue.Queue[GatewayMessageOut] bot *websocket.Conn conns *cache.ConnectionCache logger *slog.Logger closeFn func() error } type User struct { ID string `json:"id"` Name string `json:"name"` } type Destination struct { ID string `json:"channel_id,omitempty"` } type GatewayMessageIn struct { Type string ID string `json:"id"` // where am I from (channel_id or server_id) MsgID string `json:"msg_id"` // msg id Destination Destination `json:"destination,omitempty"` // where do I wanna go (channel_id or empty if from Bot) Author User `json:"author"` // who sent the message Content string `json:"content"` // message content Meta map[string]interface{} `json:"meta,omitempty"` // additional metadata Ts time.Time `json:"ts,omitempty"` // timestamp ReceivedAt time.Time `json:"-"` // ReceivedAt is populated by gateway (not from mod) } type GatewayMessageOut struct { Type string `json:"type"` // "mod"|"bot" ID string `json:"channel_id,omitempty"` // message.Destination.ID Author User `json:"author"` Content string `json:"content"` Meta map[string]interface{} `json:"meta,omitempty"` Ts time.Time `json:"ts,omitempty"` ReceivedAt time.Time `json:"received_at"` ForwardedAt time.Time `json:"forwarded_at"` } type GatewayAck struct { Status string `json:"status"` Type string `json:"type"` } type Handshake struct { Type string `json:"type"` // "mod" or "bot" Data json.RawMessage `json:"data"` } type ModHandshake struct { ServerID string `json:"server_id"` } type BotHandshake struct { BotID string `json:"bot_id"` }