// Package kook implements the built-in KOOK (KaiHeiLa) channel adapter for // Cyrene v2. KOOK is a stateful WebSocket-gateway channel: inbound events are // delivered over a gateway WebSocket (hello/heartbeat/event/resume signaling), // while outbound messages are sent over a bearer-authenticated REST API. // // The adapter conforms to internal/channel/adapter.PlatformAdapter, translating // native KOOK events into the normalized adapter.UnifiedMessage model and // delivering replies via /api/v3/message/create (channels) and // /api/v3/direct-message/create (private chat). Identity is carried as channel // actor metadata (author id + nickname) only — owner/member resolution is the // channel layer's job, never a prompt-text heuristic. // // The design authority is DevDocs/design/08-渠道接入.md §4 (kook) and §7 // (framework reusability). It depends on internal/channel/adapter (including the // shared wsutil and httpclient primitives), internal/logger, and the standard // library. The bot token is never logged. package kook import ( "strings" "time" ) // Defaults and knobs for the KOOK integration. const ( // defaultBaseURL is the KOOK REST API root. defaultBaseURL = "https://www.kookapp.cn/api/v3" // defaultHTTPTimeout bounds a single REST request. defaultHTTPTimeout = 30 * time.Second // gatewayPath is the gateway-address fetch endpoint relative to baseURL. gatewayPath = "/gateway/index" // maxMessageLen is KOOK's documented per-message content limit. maxMessageLen = 8000 // heartbeatInterval is how often the client sends a ping (KOOK: 30s). heartbeatInterval = 30 * time.Second // helloTimeout bounds the wait for the handshake (hello/resume ack). helloTimeout = 6 * time.Second ) // Config holds the settings required to reach the KOOK API. type Config struct { // BotToken is the secret bot token issued by the KOOK developer center. It is // surfaced through Config() but never written to logs. BotToken string `json:"bot_token"` // BaseURL is the KOOK REST API root; empty uses the production default. BaseURL string `json:"base_url"` } // Validate checks the configuration for values needed to connect. func (c Config) Validate() error { if strings.TrimSpace(c.BotToken) == "" { return ErrMissingToken } return nil }