Documentation
¶
Index ¶
- Constants
- func IsFormatError(err error) bool
- func IsReplyTargetGone(err error) bool
- func IsRetryable(err error) bool
- type BatchConfig
- type BatchedDispatch
- type BotAddedEvent
- type BotIdentity
- type BotIdentityCacheConfig
- type CardActionContext
- type CardActionEvent
- type CardActionOperator
- type CardActionPayload
- type Channel
- type ChannelConfig
- type ChannelOption
- type CommentEvent
- type FeishuChannelError
- type FeishuChannelErrorCode
- type MediaKind
- type Mention
- type NormalizedMessage
- type OperatorInfo
- type OutboundConfig
- type PolicyConfig
- type PolicyDecision
- type ReactionEvent
- type RejectEvent
- type RejectReason
- type Resource
- type SafetyConfig
- type SendInput
- type SendResult
- type StreamController
- type UploadInput
- type UploadResult
Constants ¶
const ( DefaultStaleWindow = 30 * time.Minute DefaultLockTTL = 5 * time.Minute )
Default configuration constants.
Variables ¶
This section is empty.
Functions ¶
func IsFormatError ¶
func IsReplyTargetGone ¶
func IsRetryable ¶
Types ¶
type BatchConfig ¶
type BatchConfig struct {
DelayMs time.Duration
LongThresholdChars int
LongDelayMs time.Duration
MaxMessages int
MaxChars int
}
BatchConfig configures the ChatPipeline batching behavior.
func DefaultBatchConfig ¶
func DefaultBatchConfig() BatchConfig
DefaultBatchConfig returns the default batching configuration.
type BatchedDispatch ¶
type BatchedDispatch struct {
Message *NormalizedMessage
SourceIDs []string
}
BatchedDispatch represents a flushed batch of messages.
type BotAddedEvent ¶
type BotAddedEvent struct {
EventID string `json:"event_id"`
ChatID string `json:"chat_id"`
ChatName string `json:"chat_name"`
UserID string `json:"user_id"` // User who added the bot
CreateTimeMs int64 `json:"create_time_ms"`
RawEvent interface{} `json:"raw_event"`
}
BotAddedEvent represents an event when the bot is added to a chat.
type BotIdentity ¶
BotIdentity represents the resolved identity of the bot
type BotIdentityCacheConfig ¶
BotIdentityCacheConfig controls how bot identity is cached and refreshed.
type CardActionContext ¶
type CardActionEvent ¶
type CardActionEvent struct {
EventID string `json:"event_id"`
MessageID string `json:"message_id"`
ChatID string `json:"chat_id"`
Token string `json:"token,omitempty"`
Host string `json:"host,omitempty"`
DeliveryType string `json:"delivery_type,omitempty"`
Operator CardActionOperator `json:"operator"`
Action CardActionPayload `json:"action"`
Context CardActionContext `json:"context"`
RawEvent interface{} `json:"raw_event"`
}
CardActionEvent represents an interactive card action callback.
type CardActionOperator ¶
type CardActionPayload ¶
type CardActionPayload struct {
Value map[string]interface{} `json:"value,omitempty"`
Tag string `json:"tag,omitempty"`
Option string `json:"option,omitempty"`
Timezone string `json:"timezone,omitempty"`
Name string `json:"name,omitempty"`
FormValue map[string]interface{} `json:"form_value,omitempty"`
InputValue string `json:"input_value,omitempty"`
Options []string `json:"options,omitempty"`
Checked bool `json:"checked,omitempty"`
}
type Channel ¶
type Channel interface {
Send(ctx context.Context, input *SendInput) (*SendResult, error)
OnMessage(handler func(ctx context.Context, msg *NormalizedMessage) error)
OnReaction(handler func(ctx context.Context, event *ReactionEvent) error)
OnComment(handler func(ctx context.Context, event *CommentEvent) error)
OnBotAdded(handler func(ctx context.Context, event *BotAddedEvent) error)
OnCardAction(handler func(ctx context.Context, event *CardActionEvent) error)
OnReject(handler func(ctx context.Context, event *RejectEvent) error)
// Media download
DownloadFile(ctx context.Context, fileKey string, mediaType string) ([]byte, error)
// Lifecycle hooks
OnReady(handler func())
OnError(handler func(err error))
OnReconnecting(handler func())
OnReconnected(handler func())
OnDisconnected(handler func())
// Lifecycle
Start(ctx context.Context) error
Stream(ctx context.Context, input *SendInput) (StreamController, error)
UpdatePolicy(cfg PolicyConfig)
GetPolicy() PolicyConfig
// Fetch Bot Identity
GetBotIdentity(ctx context.Context) *BotIdentity
// Lifecycle
Stop(ctx context.Context) error
}
Channel is the core interface for the channel feature, providing high-level abstractions for message receiving, sending, and streaming.
type ChannelConfig ¶
type ChannelConfig struct {
Safety SafetyConfig
Policy PolicyConfig
Outbound OutboundConfig
BotIdentityCache BotIdentityCacheConfig
}
ChannelConfig is the consolidated configuration for the channel.
func DefaultChannelConfig ¶
func DefaultChannelConfig() ChannelConfig
DefaultChannelConfig returns a default ChannelConfig to be used when no options are provided.
type ChannelOption ¶
type ChannelOption func(*ChannelConfig)
ChannelOption is a function that modifies the ChannelConfig.
func WithBotIdentityCacheConfig ¶
func WithBotIdentityCacheConfig(cfg BotIdentityCacheConfig) ChannelOption
WithBotIdentityCacheConfig sets the bot identity cache configuration.
func WithOutboundConfig ¶
func WithOutboundConfig(cfg OutboundConfig) ChannelOption
WithOutboundConfig sets the outbound configuration.
func WithPolicyConfig ¶
func WithPolicyConfig(cfg PolicyConfig) ChannelOption
WithPolicyConfig sets the policy configuration.
func WithSafetyConfig ¶
func WithSafetyConfig(cfg SafetyConfig) ChannelOption
WithSafetyConfig sets the safety configuration.
type CommentEvent ¶
type CommentEvent struct {
EventID string `json:"event_id"`
CommentID string `json:"comment_id"`
FileToken string `json:"file_token"`
FileType string `json:"file_type"`
Operator OperatorInfo `json:"operator"`
ReplyID string `json:"reply_id"`
MentionedBot bool `json:"mentioned_bot"`
Timestamp int64 `json:"timestamp"`
RawEvent interface{} `json:"raw_event"`
}
CommentEvent represents a comment/reply on a drive document.
type FeishuChannelError ¶
type FeishuChannelError struct {
Code FeishuChannelErrorCode
Message string
Cause error
Context map[string]interface{}
}
func ClassifyError ¶
func ClassifyError(err error, ctx ...map[string]interface{}) *FeishuChannelError
ClassifyError classifies a raw error into a FeishuChannelError with a stable code.
func (*FeishuChannelError) Error ¶
func (e *FeishuChannelError) Error() string
func (*FeishuChannelError) Unwrap ¶
func (e *FeishuChannelError) Unwrap() error
type FeishuChannelErrorCode ¶
type FeishuChannelErrorCode string
const ( ErrCodeTargetRevoked FeishuChannelErrorCode = "target_revoked" ErrCodePermissionDenied FeishuChannelErrorCode = "permission_denied" ErrCodeFormatError FeishuChannelErrorCode = "format_error" ErrCodeRateLimited FeishuChannelErrorCode = "rate_limited" ErrCodeSSRFBlocked FeishuChannelErrorCode = "ssrf_blocked" ErrCodeSendTimeout FeishuChannelErrorCode = "send_timeout" ErrCodeUnknown FeishuChannelErrorCode = "unknown" )
type Mention ¶
type Mention struct {
Key string `json:"key"`
UserID string `json:"user_id"` // UserID if available
OpenID string `json:"open_id"` // OpenID if available
Name string `json:"name"`
IsBot bool `json:"is_bot"`
}
Mention represents a user mention in a message.
type NormalizedMessage ¶
type NormalizedMessage struct {
EventID string `json:"event_id"` // Original event ID for tracing/debugging
MessageID string `json:"message_id"`
ChatID string `json:"chat_id"`
ChatType string `json:"chat_type"` // "group" or "p2p"
UserID string `json:"user_id"`
Content string `json:"content"` // Standard text content
RawContentType string `json:"raw_content_type"` // Original message type from Lark API
Mentions []Mention `json:"mentions"` // Mentions in the message
MentionAll bool `json:"mention_all"`
MentionedBot bool `json:"mentioned_bot"`
Resources []Resource `json:"resources"` // Images, files, etc.
CreateTimeMs int64 `json:"create_time_ms"`
RawEvent interface{} `json:"raw_event"` // Original event data
}
NormalizedMessage represents a standardized message event extracted from various underlying message types, making it easier to handle common use cases.
type OperatorInfo ¶
type OperatorInfo struct {
OpenID string `json:"open_id"`
UserID string `json:"user_id,omitempty"`
UnionID string `json:"union_id,omitempty"`
}
OperatorInfo represents the user who triggered the event.
type OutboundConfig ¶
type OutboundConfig struct {
TextChunkLimit int
StreamThrottleMs time.Duration
StreamThrottleChars int
Retry struct {
MaxAttempts int
BaseDelayMs time.Duration
}
}
OutboundConfig holds outbound sending behavior configurations.
type PolicyConfig ¶
type PolicyConfig struct {
GroupAllowlist []string
RequireMention *bool
RespondToMentionAll *bool
DMMode string // "open", "disabled", "allowlist"
DMAllowlist []string
}
PolicyConfig configures the PolicyGate.
type PolicyDecision ¶
type PolicyDecision struct {
Allowed bool
Reason RejectReason
}
PolicyDecision represents the result of evaluating a message against policies.
type ReactionEvent ¶
type ReactionEvent struct {
EventID string `json:"event_id"`
MessageID string `json:"message_id"`
ReactionType string `json:"reaction_type"` // e.g. "SMILE"
OperatorType string `json:"operator_type,omitempty"`
UserID string `json:"user_id"`
Action string `json:"action"` // "add" or "remove"
CreateTimeMs int64 `json:"create_time_ms"`
RawEvent interface{} `json:"raw_event"`
}
ReactionEvent represents a reaction added or removed from a message.
type RejectEvent ¶
type RejectEvent struct {
MessageID string `json:"message_id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Reason string `json:"reason"`
}
RejectEvent represents a message rejected by safety policies.
type RejectReason ¶
type RejectReason string
RejectReason defines why a message was rejected by the policy gate.
const ( RejectReasonGroupNotAllowed RejectReason = "group_not_allowed" RejectReasonNoMention RejectReason = "no_mention" RejectReasonMentionAll RejectReason = "mention_all_blocked" RejectReasonDMDisabled RejectReason = "dm_disabled" RejectReasonSenderNotAllowed RejectReason = "sender_not_allowed" )
type Resource ¶
type Resource struct {
Type string `json:"type"` // "image", "file", "audio", "video", "sticker", etc.
FileKey string `json:"file_key"` // The file key used in Lark API
FileName string `json:"file_name,omitempty"`
DurationMs *int `json:"duration_ms,omitempty"`
CoverImageKey string `json:"cover_image_key,omitempty"`
}
Resource represents an attached file, image, audio, video, sticker, etc.
type SafetyConfig ¶
type SafetyConfig struct {
Dedup struct {
MaxEntries int
SweepIntervalMs time.Duration
}
Batch BatchConfig
StaleMessageWindowMs time.Duration
}
SafetyConfig holds safety and performance pipeline configurations.
type SendInput ¶
type SendInput struct {
ReceiveID string `json:"receive_id,omitempty"` // High priority, auto-detected
ChatID string `json:"chat_id,omitempty"` // Fallback
UserID string `json:"user_id,omitempty"` // Fallback
MsgType string `json:"msg_type,omitempty"` // text, post, image, file, interactive, etc.
ReplyMessageID string `json:"reply_message_id,omitempty"`
// Message contents
Text string `json:"text,omitempty"`
Markdown string `json:"markdown,omitempty"`
Title string `json:"title,omitempty"` // Used as Post title if Markdown is set
ImageKey string `json:"image_key,omitempty"`
FileKey string `json:"file_key,omitempty"`
AudioKey string `json:"audio_key,omitempty"`
VideoKey string `json:"video_key,omitempty"`
Card string `json:"card,omitempty"` // Stringified JSON of the card
Post string `json:"post,omitempty"` // Stringified JSON of the post
StickerFileKey string `json:"sticker_file_key,omitempty"`
// Local file paths (Uploader will automatically upload them before sending)
ImagePath string `json:"image_path,omitempty"`
FilePath string `json:"file_path,omitempty"`
// Media configuration for uploading
Media *UploadInput `json:"media,omitempty"`
// Mentions represents user mentions to be prepended to the message
Mentions []Mention `json:"mentions,omitempty"`
}
SendInput represents the structured parameters for sending a message.
type SendResult ¶
type SendResult struct {
MessageID string `json:"message_id"`
ChunkIDs []string `json:"chunk_ids,omitempty"` // For messages split into multiple chunks
ChatID string `json:"chat_id,omitempty"`
Error error `json:"error,omitempty"`
}
SendResult represents the result of sending a message.
type StreamController ¶
type StreamController interface {
// Append adds text to the end of the streaming message.
Append(ctx context.Context, text string) error
// UpdateCard updates the message with a new card.
UpdateCard(ctx context.Context, card string) error
// Flush forces any pending text to be sent immediately.
Flush(ctx context.Context) error
// Close completes the stream. No further updates can be made.
Close(ctx context.Context) error
}
StreamController provides methods to control a streaming message.