-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(feishu): enhance channel with markdown cards, media, mentions, and editing #1000
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c9fb681
feat(feishu): enhance channel with markdown cards, media, mentions, a…
alexhoshina 0bee9d7
fix(feishu): resolve lint issues
alexhoshina 42eb6ea
fix(feishu): address review findings
alexhoshina 595de78
fix(feishu): remove dead fetchBotOpenID stub and fix misleading comment
alexhoshina fa1cb9c
fix(feishu): address PR #1000 review comments from @xiaket
alexhoshina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ) | ||
|
|
||
| // 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 { | ||
alexhoshina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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+`) | ||
alexhoshina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 || ppc64constraint here (or split SDK-dependent helpers into a *_64.go file and provide a *_32.go stub).