fix(feishu): skip empty random_reaction_emoji entries

Feishu returns 231001 when emoji_type is empty. Config slices like
["", "Pin"] could randomly select an empty string; filter and
trim entries and fall back to Pin when none remain.

Made-with: Cursor
This commit is contained in:
imalasong 2026-03-28 23:36:49 +08:00
parent 27f638e909
commit 43095543ab

View file

@ -245,15 +245,18 @@ func (c *FeishuChannel) SendPlaceholder(ctx context.Context, chatID string) (str
// ReactToMessage implements channels.ReactionCapable. // ReactToMessage implements channels.ReactionCapable.
// Adds a reaction (randomly chosen from config) and returns an undo function to remove it. // Adds a reaction (randomly chosen from config) and returns an undo function to remove it.
func (c *FeishuChannel) ReactToMessage(ctx context.Context, chatID, messageID string) (func(), error) { func (c *FeishuChannel) ReactToMessage(ctx context.Context, chatID, messageID string) (func(), error) {
// Get emoji list from config // Get emoji list from config (Feishu emoji_type keys, e.g. Pin, THUMBSUP).
emojiList := c.config.RandomReactionEmoji // Ignore empty entries so a list like ["", "Pin"] does not randomly pick "" (API 231001).
var chosenEmoji string var candidates []string
if len(emojiList) == 0 { for _, e := range c.config.RandomReactionEmoji {
// Default to "Pin" if no config e = strings.TrimSpace(e)
chosenEmoji = "Pin" if e != "" {
} else { candidates = append(candidates, e)
idx := rand.Intn(len(emojiList)) }
chosenEmoji = emojiList[idx] }
chosenEmoji := "Pin"
if len(candidates) > 0 {
chosenEmoji = candidates[rand.Intn(len(candidates))]
} }
req := larkim.NewCreateMessageReactionReqBuilder(). req := larkim.NewCreateMessageReactionReqBuilder().