Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions pkg/channels/feishu/common.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,92 @@
package feishu

import (
"encoding/json"
"regexp"
"strings"

larkim "github.com/larksuite/oapi-sdk-go/v3/service/im/v1"
)
Comment on lines 1 to +9
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/channels/feishu has a 32-bit stub (feishu_32.go) because the Feishu SDK isn’t supported on 32-bit, but this file is missing the same 64-bit-only build tag and imports the Feishu SDK (larkim). As-is, 32-bit builds will still try to compile this file and fail. Add the same //go:build amd64 || arm64 || riscv64 || mips64 || ppc64 constraint here (or split SDK-dependent helpers into a *_64.go file and provide a *_32.go stub).

Copilot uses AI. Check for mistakes.

// stringValue safely dereferences a *string pointer.
func stringValue(v *string) string {
if v == nil {
return ""
}
return *v
}

// buildMarkdownCard builds a Feishu Interactive Card JSON 2.0 string with markdown content.
// JSON 2.0 cards support full CommonMark standard markdown syntax.
func buildMarkdownCard(content string) (string, error) {
card := map[string]any{
"schema": "2.0",
"body": map[string]any{
"elements": []map[string]any{
{
"tag": "markdown",
"content": content,
},
},
},
}
data, err := json.Marshal(card)
if err != nil {
return "", err
}
return string(data), nil
}

// extractImageKey extracts the image_key from a Feishu image message content JSON.
// Format: {"image_key": "img_xxx"}
func extractImageKey(content string) string {
var payload struct {
ImageKey string `json:"image_key"`
}
if err := json.Unmarshal([]byte(content), &payload); err != nil {
return ""
}
return payload.ImageKey
}

// extractFileKey extracts the file_key from a Feishu file/audio message content JSON.
// Format: {"file_key": "file_xxx", "file_name": "...", ...}
func extractFileKey(content string) string {
var payload struct {
FileKey string `json:"file_key"`
}
if err := json.Unmarshal([]byte(content), &payload); err != nil {
return ""
}
return payload.FileKey
}

// extractFileName extracts the file_name from a Feishu file message content JSON.
func extractFileName(content string) string {
var payload struct {
FileName string `json:"file_name"`
}
if err := json.Unmarshal([]byte(content), &payload); err != nil {
return ""
}
return payload.FileName
}

// mentionPlaceholderRegex matches @_user_N placeholders inserted by Feishu for mentions.
var mentionPlaceholderRegex = regexp.MustCompile(`@_user_\d+`)

// stripMentionPlaceholders removes @_user_N placeholders from the text content.
// These are inserted by Feishu when users @mention someone in a message.
func stripMentionPlaceholders(content string, mentions []*larkim.MentionEvent) string {
if len(mentions) == 0 {
return content
}
for _, m := range mentions {
if m.Key != nil && *m.Key != "" {
content = strings.ReplaceAll(content, *m.Key, "")
}
}
// Also clean up any remaining @_user_N patterns
content = mentionPlaceholderRegex.ReplaceAllString(content, "")
return strings.TrimSpace(content)
}
28 changes: 25 additions & 3 deletions pkg/channels/feishu/feishu_32.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type FeishuChannel struct {
*channels.BaseChannel
}

var errUnsupported = errors.New("feishu channel is not supported on 32-bit architectures")

// NewFeishuChannel returns an error on 32-bit architectures where the Feishu SDK is not supported
func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (*FeishuChannel, error) {
return nil, errors.New(
Expand All @@ -25,15 +27,35 @@ func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (*FeishuChan

// Start is a stub method to satisfy the Channel interface
func (c *FeishuChannel) Start(ctx context.Context) error {
return nil
return errUnsupported
}

// Stop is a stub method to satisfy the Channel interface
func (c *FeishuChannel) Stop(ctx context.Context) error {
return nil
return errUnsupported
}

// Send is a stub method to satisfy the Channel interface
func (c *FeishuChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
return errors.New("feishu channel is not supported on 32-bit architectures")
return errUnsupported
}

// EditMessage is a stub method to satisfy MessageEditor
func (c *FeishuChannel) EditMessage(ctx context.Context, chatID, messageID, content string) error {
return errUnsupported
}

// SendPlaceholder is a stub method to satisfy PlaceholderCapable
func (c *FeishuChannel) SendPlaceholder(ctx context.Context, chatID string) (string, error) {
return "", errUnsupported
}

// ReactToMessage is a stub method to satisfy ReactionCapable
func (c *FeishuChannel) ReactToMessage(ctx context.Context, chatID, messageID string) (func(), error) {
return func() {}, errUnsupported
}

// SendMedia is a stub method to satisfy MediaSender
func (c *FeishuChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMessage) error {
return errUnsupported
}
Loading