62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package adapter
|
|
|
|
// Capabilities declares what a concrete platform adapter supports, so the
|
|
// runtime can degrade gracefully and the channel layer can enforce limits.
|
|
type Capabilities struct {
|
|
// MaxMessageLength is the maximum message length the platform accepts.
|
|
// Zero means "derive a sensible default".
|
|
MaxMessageLength int
|
|
// Markdown reports whether the platform renders markdown in outgoing text.
|
|
Markdown bool
|
|
// Image reports whether the platform supports sending images.
|
|
Image bool
|
|
// Voice reports whether the platform supports sending voice/audio.
|
|
Voice bool
|
|
// Reaction reports whether the platform supports reactions.
|
|
Reaction bool
|
|
// TypingHint reports whether the platform supports typing indicators.
|
|
TypingHint bool
|
|
// RecommendBurstMax is the recommended maximum number of messages in one
|
|
// burst. Zero means "derive a sensible default".
|
|
RecommendBurstMax int
|
|
// Proactive reports whether the platform allows push without a recent
|
|
// inbound message (e.g. weixin-ilink has a 24h window; OneBot needs rate
|
|
// limiting). See design/08 section 3.
|
|
Proactive bool
|
|
}
|
|
|
|
const (
|
|
// defaultMaxMessageLength is used when an adapter declares no limit.
|
|
defaultMaxMessageLength = 4000
|
|
// defaultRecommendBurstMax avoids flooding a channel by default.
|
|
defaultRecommendBurstMax = 1
|
|
)
|
|
|
|
// Normalize fills zero-valued numeric fields with sensible defaults so a
|
|
// partially declared Capabilities is still usable. Boolean fields are left
|
|
// untouched because an unset bool already means "not supported".
|
|
func (c Capabilities) Normalize() Capabilities {
|
|
if c.MaxMessageLength <= 0 {
|
|
c.MaxMessageLength = defaultMaxMessageLength
|
|
}
|
|
if c.RecommendBurstMax <= 0 {
|
|
c.RecommendBurstMax = defaultRecommendBurstMax
|
|
}
|
|
return c
|
|
}
|
|
|
|
// DefaultCapabilities returns a conservative baseline for adapters that only
|
|
// speak plain text and basic images, leaving richer features off by default.
|
|
func DefaultCapabilities() Capabilities {
|
|
return Capabilities{
|
|
MaxMessageLength: defaultMaxMessageLength,
|
|
Markdown: true,
|
|
Image: true,
|
|
Voice: false,
|
|
Reaction: false,
|
|
TypingHint: false,
|
|
RecommendBurstMax: defaultRecommendBurstMax,
|
|
Proactive: false,
|
|
}
|
|
}
|