45fac267fe
- PlatformConfig 新增 ID 字段 (8字节hex,创建时自动生成) - QQ adapter 新增 configID + ConfigID() 访问器 - ChannelInfo 新增 AdapterID + AdapterName - createSingleAdapter 接受 configID 参数 - 同一个平台类型的多个配置实例通过 ID 唯一区分 Co-Authored-By: Claude <noreply@anthropic.com>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package bridge
|
|
|
|
import "context"
|
|
|
|
// PlatformAdapter is the interface every platform adapter must implement.
|
|
type PlatformAdapter interface {
|
|
PlatformName() string
|
|
|
|
// Message conversion.
|
|
ToUnified(rawMessage interface{}) (*UnifiedMessage, error)
|
|
FromUnified(response *UnifiedResponse) ([]PlatformMessage, error)
|
|
|
|
// Capabilities.
|
|
Capabilities() PlatformCapabilities
|
|
|
|
// Connection management.
|
|
Connect(ctx context.Context) error
|
|
Disconnect(ctx context.Context) error
|
|
IsConnected() bool
|
|
HealthCheck() error
|
|
}
|
|
|
|
// ProactiveSender is an optional interface for adapters that can
|
|
// proactively send messages (e.g., OBv11 bot sending without prior request).
|
|
type ProactiveSender interface {
|
|
SendProactive(chatType string, userID, groupID int64, content string) error
|
|
}
|
|
|
|
// ChannelInfo describes a known chat channel (group or private).
|
|
type ChannelInfo struct {
|
|
Platform string `json:"platform"`
|
|
ChannelType string `json:"channel_type"` // "group", "private"
|
|
ChannelID string `json:"channel_id"`
|
|
ChannelName string `json:"channel_name,omitempty"`
|
|
AdapterID string `json:"adapter_id,omitempty"` // config ID of the adapter instance
|
|
AdapterName string `json:"adapter_name,omitempty"` // config name, e.g. "qq-main"
|
|
}
|
|
|
|
// ChannelLister is an optional interface for adapters that can enumerate
|
|
// their channels (groups and friends) from the platform API.
|
|
type ChannelLister interface {
|
|
ListChannels() []ChannelInfo
|
|
}
|
|
|
|
// MessageHandler receives unified messages from adapters for processing.
|
|
type MessageHandler func(msg *UnifiedMessage) (*UnifiedResponse, error)
|