-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(feishu): add random reaction emoji config #1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
9f017d0
92a0db4
109a382
b15cff1
6aa1d02
08d668c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "math/rand" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
|
|
@@ -195,25 +196,38 @@ func (c *FeishuChannel) SendPlaceholder(ctx context.Context, chatID string) (str | |
| } | ||
|
|
||
| // ReactToMessage implements channels.ReactionCapable. | ||
| // Adds an "Pin" reaction 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) { | ||
| // Get emoji list from config | ||
| emojiList := c.config.RandomReactionEmoji | ||
| if len(emojiList) == 0 { | ||
| // Default to "Pin" if no config | ||
| emojiList = []string{"Pin"} | ||
| } | ||
| logger.Info(fmt.Sprintf("[MABEN] c.config.RandomReactionEmoji, %v", c.config.RandomReactionEmoji)) | ||
|
|
||
| // Randomly choose one from the list | ||
| chosenEmoji := emojiList[rand.Intn(len(emojiList))] | ||
|
||
|
|
||
| req := larkim.NewCreateMessageReactionReqBuilder(). | ||
| MessageId(messageID). | ||
| Body(larkim.NewCreateMessageReactionReqBodyBuilder(). | ||
| ReactionType(larkim.NewEmojiBuilder().EmojiType("Pin").Build()). | ||
| ReactionType(larkim.NewEmojiBuilder().EmojiType(chosenEmoji).Build()). | ||
| Build()). | ||
| Build() | ||
|
|
||
| resp, err := c.client.Im.V1.MessageReaction.Create(ctx, req) | ||
| if err != nil { | ||
| logger.ErrorCF("feishu", "Failed to add reaction", map[string]any{ | ||
| "emoji": chosenEmoji, | ||
| "message_id": messageID, | ||
| "error": err.Error(), | ||
| }) | ||
| return func() {}, fmt.Errorf("feishu react: %w", err) | ||
| } | ||
| if !resp.Success() { | ||
| logger.ErrorCF("feishu", "Reaction API error", map[string]any{ | ||
| "emoji": chosenEmoji, | ||
| "message_id": messageID, | ||
| "code": resp.Code, | ||
| "msg": resp.Msg, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this log a debug log? Perhaps it needs to be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i will fix that