-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: support vc,minute event #1113
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 all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package minutes | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/larksuite/cli/internal/event" | ||
| "github.com/larksuite/cli/internal/validate" | ||
| ) | ||
|
|
||
| const ( | ||
| minutesDetailRetryDelay = 500 * time.Millisecond | ||
| minutesDetailMaxRetries = 2 | ||
| ) | ||
|
|
||
| // MinutesMinuteSourceOutput is the flattened minute source payload. | ||
| type MinutesMinuteSourceOutput struct { | ||
| SourceType string `json:"source_type,omitempty" desc:"Minute source type"` | ||
| SourceEntityID string `json:"source_entity_id,omitempty" desc:"Source entity ID"` | ||
| } | ||
|
|
||
| // MinutesMinuteGeneratedOutput is the flattened shape for minutes.minute.generated_v1. | ||
| type MinutesMinuteGeneratedOutput struct { | ||
| Type string `json:"type" desc:"Event type; always minutes.minute.generated_v1"` | ||
| EventID string `json:"event_id,omitempty" desc:"Globally unique event ID; safe for deduplication"` | ||
| Timestamp string `json:"timestamp,omitempty" desc:"Event delivery time (ms timestamp string); taken from header.create_time when present" kind:"timestamp_ms"` | ||
| MinuteToken string `json:"minute_token,omitempty" desc:"Minute token"` | ||
| Title string `json:"title,omitempty" desc:"Minute title"` | ||
| MinuteSource *MinutesMinuteSourceOutput `json:"minute_source,omitempty" desc:"Minute source metadata"` | ||
| } | ||
|
|
||
| func processMinutesMinuteGenerated(ctx context.Context, rt event.APIClient, raw *event.RawEvent, _ map[string]string) (json.RawMessage, error) { | ||
| var envelope struct { | ||
| Header struct { | ||
| EventID string `json:"event_id"` | ||
| EventType string `json:"event_type"` | ||
| CreateTime string `json:"create_time"` | ||
| } `json:"header"` | ||
| Event struct { | ||
| MinuteToken string `json:"minute_token"` | ||
| MinuteSource struct { | ||
| SourceType string `json:"source_type"` | ||
| SourceEntityID string `json:"source_entity_id"` | ||
| } `json:"minute_source"` | ||
| } `json:"event"` | ||
| } | ||
| if err := json.Unmarshal(raw.Payload, &envelope); err != nil { | ||
| return raw.Payload, nil //nolint:nilerr // passthrough on malformed payload so consumers still see the event | ||
| } | ||
|
|
||
| out := &MinutesMinuteGeneratedOutput{ | ||
| Type: envelope.Header.EventType, | ||
| EventID: envelope.Header.EventID, | ||
| Timestamp: envelope.Header.CreateTime, | ||
| MinuteToken: envelope.Event.MinuteToken, | ||
| } | ||
| if out.Type == "" { | ||
| out.Type = raw.EventType | ||
| } | ||
| if src := envelope.Event.MinuteSource; src.SourceType != "" || src.SourceEntityID != "" { | ||
| out.MinuteSource = &MinutesMinuteSourceOutput{ | ||
| SourceType: src.SourceType, | ||
| SourceEntityID: src.SourceEntityID, | ||
| } | ||
| } | ||
|
|
||
| if rt != nil && out.MinuteToken != "" { | ||
| fillMinutesMinuteGeneratedDetails(ctx, rt, out) | ||
| } | ||
|
|
||
| return json.Marshal(out) | ||
| } | ||
|
|
||
| func fillMinutesMinuteGeneratedDetails(ctx context.Context, rt event.APIClient, out *MinutesMinuteGeneratedOutput) { | ||
| if rt == nil || out == nil || out.MinuteToken == "" { | ||
| return | ||
| } | ||
|
|
||
| path := fmt.Sprintf(pathMinuteDetailFmt, validate.EncodePathSegment(out.MinuteToken)) | ||
|
|
||
| type minuteDetailResp struct { | ||
| Data struct { | ||
| Minute struct { | ||
| Title string `json:"title"` | ||
| } `json:"minute"` | ||
| } `json:"data"` | ||
| } | ||
|
|
||
| for attempt := 0; attempt <= minutesDetailMaxRetries; attempt++ { | ||
| if attempt > 0 { | ||
| time.Sleep(minutesDetailRetryDelay) | ||
| } | ||
|
|
||
| raw, err := rt.CallAPI(ctx, "GET", path, nil) | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| var resp minuteDetailResp | ||
| if err := json.Unmarshal(raw, &resp); err != nil { | ||
| continue | ||
| } | ||
|
|
||
| if resp.Data.Minute.Title == "" { | ||
| continue | ||
| } | ||
|
|
||
| out.Title = resp.Data.Minute.Title | ||
| return | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.