feat(channel): KOOK 渠道适配器 + 框架兼容增强(wsutil/httpclient)
- plugins/channels/kook: config/adapter/gateway/websocket/send/message/errors — 实现 PlatformAdapter 13方法 - WS 有状态网关: 取gateway地址→连WS→信令0/1/2/3/4/6 + 30s心跳/6s超时 + resume(拼接sn/session_id) + 指数退避重连 - 收事件: 信令0 → UnifiedMessage(word注 channel_type/type/target_id/extra.author→字段) - 发消息: /message/create(频道) + /direct-message/create(私聊,修正正确端点,非user-chat) + Bearer鉴权 - 注册 channels.go + CHANNELS_JSON 多账号 + channelbridge.configured 加 kook(bot_token非空才连) - 框架增强: internal/channel/adapter/wsutil(连接管理/心跳/重连/resume骨架,复用gorilla,KOOK用上) + httpclient(Bearer+envelope归一,KOOK用) - 全仓 go build/vet/test 绿, 零新依赖(复用餐gorilla), 未动telegram/qq/weixin/webhook契约 - §4.6 隔离/黑白名单/第三方边界未破坏 注: KOOK WS/WH 双模式待补(ReceiveMode), 实测需主人提供 CHANNEL_KOOK_TOKEN
This commit is contained in:
1 parent
eab6b63eb0
commit
764d592859
24 files changed
+2800
-2
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package kook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// gatewayResult is the "data" payload of GET /gateway/index.
|
||||
type gatewayResult struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// fetchGatewayURL retrieves the gateway WebSocket address from the KOOK REST
|
||||
// API. compress=0 requests uncompressed delivery so every server->client frame is
|
||||
// plain JSON text, matching wsutil's reader.
|
||||
func (a *Adapter) fetchGatewayURL(ctx context.Context) (string, error) {
|
||||
data, err := a.http.GetJSON(ctx, gatewayPath, url.Values{"compress": {"0"}})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("kook: fetch gateway: %w", err)
|
||||
}
|
||||
var res gatewayResult
|
||||
if err := json.Unmarshal(data, &res); err != nil {
|
||||
return "", fmt.Errorf("kook: decode gateway result: %w", err)
|
||||
}
|
||||
if res.URL == "" {
|
||||
return "", fmt.Errorf("kook: gateway url empty: %w", ErrBadResponse)
|
||||
}
|
||||
return res.URL, nil
|
||||
}
|
||||
Reference in new issue
Block a user