Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeActionValue(action, sessionID, messageID string) (string, error)
- type APIError
- type ActionValue
- type Adapter
- func (a *Adapter) GetAppToken() (string, error)
- func (a *Adapter) GetAppTokenWithContext(ctx context.Context) (string, error)
- func (a *Adapter) SendMessage(ctx context.Context, sessionID string, msg *base.ChatMessage) error
- func (a *Adapter) SetSender(fn func(ctx context.Context, sessionID string, msg *base.ChatMessage) error)
- type CardAction
- type CardBlock
- type CardBuilder
- func (b *CardBuilder) BuildAnswerCard(content string) (string, error)
- func (b *CardBuilder) BuildErrorCard(errorMsg string) (string, error)
- func (b *CardBuilder) BuildPermissionCard(title, description, riskLevel string) (string, error)
- func (b *CardBuilder) BuildSessionStatsCard(duration string, tokenUsage int, otherStats map[string]string) (string, error)
- func (b *CardBuilder) BuildThinkingCard(message string) (string, error)
- func (b *CardBuilder) BuildToolUseCard(toolName, toolInput string) (string, error)
- type CardConfig
- type CardElement
- type CardHeader
- type CardTemplate
- type Client
- func (c *Client) GetAppToken() (string, int, error)
- func (c *Client) GetAppTokenWithContext(ctx context.Context) (string, int, error)
- func (c *Client) SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
- func (c *Client) SendMessage(ctx context.Context, token, chatID, msgType string, content map[string]string) (string, error)
- func (c *Client) SendTextMessage(ctx context.Context, token, chatID, text string) (string, error)
- type CommandContent
- type CommandEvent
- type CommandEventData
- type CommandHandler
- type CommandHeader
- type Config
- type Event
- type EventData
- type EventHandler
- func (h *EventHandler) HandleURLVerification(w http.ResponseWriter, token string, eventType string) bool
- func (h *EventHandler) ProcessEvent(w http.ResponseWriter, r *http.Request, ...)
- func (h *EventHandler) WriteJSONResponse(w http.ResponseWriter, data interface{})
- func (h *EventHandler) WriteOKResponse(w http.ResponseWriter)
- type EventHeader
- type FeishuAPIClient
- type InteractiveAction
- type InteractiveEvent
- type InteractiveEventData
- type InteractiveHandler
- type InteractiveHeader
- type InteractiveMessage
- type InteractiveUser
- type Message
- type MessageContent
- type MessageData
- type RateLimiter
- type SendMessageRequest
- type SendMessageResponse
- type Text
- type TokenResponse
- type UserID
Constants ¶
const ( CardTemplateBlue = "blue" CardTemplateWathet = "wathet" CardTemplateGreen = "green" CardTemplateYellow = "yellow" CardTemplateOrange = "orange" CardTemplateRed = "red" Purple = "purple" Grey = "grey" )
Card colors (templates)
const ( TextTypePlainText = "plain_text" TextTypeLarkMD = "lark_md" )
Text types
const ( ElementDiv = "div" ElementNote = "note" ElementAlert = "alert" ElementAction = "action" ElementButton = "button" ElementMarkdown = "markdown" )
Element types
const ( ButtonTypeDefault = "default" ButtonTypePrimary = "primary" ButtonTypeDanger = "danger" )
Button types
Variables ¶
var ( ErrConfigMissingAppID = fmt.Errorf("feishu: app_id is required") ErrConfigMissingAppSecret = fmt.Errorf("feishu: app_secret is required") ErrConfigMissingVerificationToken = fmt.Errorf("feishu: verification_token is required") ErrConfigMissingEncryptKey = fmt.Errorf("feishu: encrypt_key is required") ErrInvalidSignature = fmt.Errorf("feishu: invalid signature") ErrInvalidChallenge = fmt.Errorf("feishu: invalid challenge") ErrEventParseFailed = fmt.Errorf("feishu: failed to parse event") ErrUnsupportedEventType = fmt.Errorf("feishu: unsupported event type") ErrTokenFetchFailed = fmt.Errorf("feishu: failed to fetch access token") ErrMessageSendFailed = fmt.Errorf("feishu: failed to send message") ErrMessageUpdateFailed = fmt.Errorf("feishu: failed to update message") ErrMessageDeleteFailed = fmt.Errorf("feishu: failed to delete message") )
Feishu adapter errors
Functions ¶
func EncodeActionValue ¶
EncodeActionValue encodes an action value for button callback
Types ¶
type ActionValue ¶
type ActionValue struct {
Action string `json:"action"`
SessionID string `json:"session_id"`
MessageID string `json:"message_id,omitempty"`
}
ActionValue represents the decoded action value from button click
func DecodeActionValue ¶
func DecodeActionValue(value string) (*ActionValue, error)
DecodeActionValue decodes an action value from button callback
type Adapter ¶
Adapter implements the Feishu (Lark) chat adapter
func NewAdapter ¶
NewAdapter creates a new Feishu adapter
func (*Adapter) GetAppToken ¶
GetAppToken gets or caches the app access token
func (*Adapter) GetAppTokenWithContext ¶
GetAppTokenWithContext gets or caches the app access token with context
func (*Adapter) SendMessage ¶
SendMessage sends a message to Feishu
type CardAction ¶
type CardAction struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Value interface{} `json:"value,omitempty"`
URL string `json:"url,omitempty"`
}
CardAction defines an interactive action (button, etc.)
type CardBlock ¶
type CardBlock struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Content string `json:"content,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Actions []CardAction `json:"actions,omitempty"`
}
CardBlock represents a card block
type CardBuilder ¶
type CardBuilder struct {
// contains filtered or unexported fields
}
CardBuilder builds Feishu interactive cards for HotPlex events
func NewCardBuilder ¶
func NewCardBuilder(sessionID string) *CardBuilder
NewCardBuilder creates a new card builder
func (*CardBuilder) BuildAnswerCard ¶
func (b *CardBuilder) BuildAnswerCard(content string) (string, error)
BuildAnswerCard builds an answer card with Markdown support Event: answer - Final answer with Markdown
func (*CardBuilder) BuildErrorCard ¶
func (b *CardBuilder) BuildErrorCard(errorMsg string) (string, error)
BuildErrorCard builds an error/warning card Event: error - Red alert box
func (*CardBuilder) BuildPermissionCard ¶
func (b *CardBuilder) BuildPermissionCard(title, description, riskLevel string) (string, error)
BuildPermissionCard builds a permission request card with Allow/Deny buttons Event: permission_request - Interactive card with buttons
func (*CardBuilder) BuildSessionStatsCard ¶
func (b *CardBuilder) BuildSessionStatsCard(duration string, tokenUsage int, otherStats map[string]string) (string, error)
BuildSessionStatsCard builds a session statistics card Event: session_stats - Gray note with stats
func (*CardBuilder) BuildThinkingCard ¶
func (b *CardBuilder) BuildThinkingCard(message string) (string, error)
BuildThinkingCard builds a thinking state card Event: thinking - Shows "🤔 Thinking..." with loading animation
func (*CardBuilder) BuildToolUseCard ¶
func (b *CardBuilder) BuildToolUseCard(toolName, toolInput string) (string, error)
BuildToolUseCard builds a tool execution card Event: tool_use - Shows "🛠️ Executing: Bash"
type CardConfig ¶
type CardConfig struct {
WideScreenMode bool `json:"wide_screen_mode,omitempty"`
EnableForward bool `json:"enable_forward,omitempty"`
}
CardConfig defines card configuration
type CardElement ¶
type CardElement struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Content string `json:"content,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Actions []CardAction `json:"actions,omitempty"`
}
CardElement represents a card element (markdown, note, alert, etc.)
type CardHeader ¶
type CardHeader struct {
Template string `json:"template,omitempty"`
Title *Text `json:"title,omitempty"`
}
CardHeader defines card header
type CardTemplate ¶
type CardTemplate struct {
Config *CardConfig `json:"config,omitempty"`
Header *CardHeader `json:"header,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Cards []CardBlock `json:"cards,omitempty"`
}
CardTemplate defines a Feishu interactive card template
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Feishu Open API
func (*Client) GetAppToken ¶
GetAppToken fetches a new app access token
func (*Client) GetAppTokenWithContext ¶
GetAppTokenWithContext fetches a new app access token with context
func (*Client) SendInteractiveMessage ¶
func (c *Client) SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
SendInteractiveMessage sends an interactive card message This is a placeholder for Phase 2 implementation
type CommandContent ¶
type CommandContent struct {
Text string `json:"text"`
}
CommandContent represents the command content
type CommandEvent ¶
type CommandEvent struct {
Header *CommandHeader `json:"header"`
Event *CommandEventData `json:"event"`
Token string `json:"token"`
}
CommandEvent represents a Feishu command event
type CommandEventData ¶
type CommandEventData struct {
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
OperatorID *UserID `json:"operator_id"`
Name string `json:"name"`
Content *CommandContent `json:"content"`
}
CommandEventData represents the command event data
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler handles Feishu bot commands (/reset, /dc)
func NewCommandHandler ¶
func NewCommandHandler(adapter *Adapter, registry *command.Registry) *CommandHandler
NewCommandHandler creates a new command handler
func (*CommandHandler) HandleCommand ¶
func (h *CommandHandler) HandleCommand(w http.ResponseWriter, r *http.Request)
HandleCommand handles incoming command events
type CommandHeader ¶
type CommandHeader struct {
EventID string `json:"event_id"`
EventType string `json:"event_type"`
CreateTime string `json:"create_time"`
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
}
CommandHeader represents the command event header
type Config ¶
type Config struct {
// App credentials
AppID string `json:"app_id" yaml:"app_id"`
AppSecret string `json:"app_secret" yaml:"app_secret"`
// Event subscription
VerificationToken string `json:"verification_token" yaml:"verification_token"`
EncryptKey string `json:"encrypt_key" yaml:"encrypt_key"`
// Server configuration
ServerAddr string `json:"server_addr" yaml:"server_addr"`
MaxMessageLen int `json:"max_message_len" yaml:"max_message_len"`
// System prompt
SystemPrompt string `json:"system_prompt" yaml:"system_prompt"`
}
Config holds Feishu (Lark) adapter configuration
type Event ¶
type Event struct {
Schema string `json:"schema"`
Header *EventHeader `json:"header"`
Event *EventData `json:"event"`
Token string `json:"token"`
Type string `json:"type"`
Challenge string `json:"challenge"`
}
Event represents a Feishu webhook event
type EventData ¶
type EventData struct {
Message *Message `json:"message"`
}
EventData contains the actual event payload
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
EventHandler provides common event handling logic (DRY principle)
func NewEventHandler ¶
func NewEventHandler(adapter *Adapter) *EventHandler
NewEventHandler creates a new event handler
func (*EventHandler) HandleURLVerification ¶
func (h *EventHandler) HandleURLVerification(w http.ResponseWriter, token string, eventType string) bool
HandleURLVerification handles URL verification for Feishu webhooks
func (*EventHandler) ProcessEvent ¶
func (h *EventHandler) ProcessEvent(w http.ResponseWriter, r *http.Request, parseFunc func([]byte) (interface{}, error), handleFunc func(interface{}) error)
ProcessEvent is a common event processing pipeline
func (*EventHandler) WriteJSONResponse ¶
func (h *EventHandler) WriteJSONResponse(w http.ResponseWriter, data interface{})
WriteJSONResponse writes a JSON response
func (*EventHandler) WriteOKResponse ¶
func (h *EventHandler) WriteOKResponse(w http.ResponseWriter)
WriteOKResponse writes a simple OK response
type EventHeader ¶
type EventHeader struct {
EventType string `json:"event_type"`
EventID string `json:"event_id"`
CreateTime int64 `json:"create_time"`
TenantKey string `json:"tenant_key"`
AppID string `json:"app_id"`
}
EventHeader contains event metadata
type FeishuAPIClient ¶
type FeishuAPIClient interface {
GetAppTokenWithContext(ctx context.Context) (string, int, error)
SendMessage(ctx context.Context, token, chatID, msgType string, content map[string]string) (string, error)
SendTextMessage(ctx context.Context, token, chatID, text string) (string, error)
SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
}
FeishuAPIClient defines the interface for Feishu API operations (SOLID: Dependency Inversion)
type InteractiveAction ¶
InteractiveAction represents the button action
type InteractiveEvent ¶
type InteractiveEvent struct {
Header *InteractiveHeader `json:"header"`
Event *InteractiveEventData `json:"event"`
Token string `json:"token"`
}
InteractiveEvent represents a Feishu interactive event
type InteractiveEventData ¶
type InteractiveEventData struct {
Message *InteractiveMessage `json:"message"`
User *InteractiveUser `json:"user"`
Action *InteractiveAction `json:"action"`
}
InteractiveEventData represents the event data
type InteractiveHandler ¶
type InteractiveHandler struct {
// contains filtered or unexported fields
}
InteractiveHandler handles Feishu interactive card callbacks
func NewInteractiveHandler ¶
func NewInteractiveHandler(adapter *Adapter) *InteractiveHandler
NewInteractiveHandler creates a new interactive handler
func (*InteractiveHandler) HandleInteractive ¶
func (h *InteractiveHandler) HandleInteractive(w http.ResponseWriter, r *http.Request)
HandleInteractive handles incoming interactive events
func (*InteractiveHandler) UpdatePermissionCard ¶
func (h *InteractiveHandler) UpdatePermissionCard(ctx context.Context, messageID, chatID, result string) error
UpdatePermissionCard updates a permission card with the result
type InteractiveHeader ¶
type InteractiveHeader struct {
EventID string `json:"event_id"`
EventType string `json:"event_type"`
CreateTime string `json:"create_time"`
Token string `json:"token"`
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
}
InteractiveHeader represents the event header
type InteractiveMessage ¶
type InteractiveMessage struct {
MessageID string `json:"message_id"`
ChatID string `json:"chat_id"`
MessageType string `json:"message_type"`
}
InteractiveMessage represents the message in the event
type InteractiveUser ¶
type InteractiveUser struct {
UserID string `json:"user_id"`
}
InteractiveUser represents the user who triggered the event
type Message ¶
type Message struct {
MessageID string `json:"message_id"`
UnionID string `json:"union_id"`
SenderID string `json:"sender_id"`
ChatID string `json:"chat_id"`
Content *MessageContent `json:"content"`
CreateTime int64 `json:"create_time"`
TenantKey string `json:"tenant_key"`
MessageType string `json:"message_type"`
}
Message represents a Feishu message
type MessageContent ¶
MessageContent represents message content
type MessageData ¶
type MessageData struct {
MessageID string `json:"message_id"`
}
MessageData represents message data in response
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements simple rate limiting for commands
func NewRateLimiter ¶
func NewRateLimiter(duration time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow(key string) bool
Allow checks if a request is allowed
type SendMessageRequest ¶
type SendMessageRequest struct {
ReceiveID string `json:"receive_id"`
MsgType string `json:"msg_type"`
Content string `json:"content"`
}
SendMessageRequest represents a message send request
type SendMessageResponse ¶
type SendMessageResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *MessageData `json:"data"`
}
SendMessageResponse represents a message send response