-
Notifications
You must be signed in to change notification settings - Fork 586
feat(calendar): implement rsvp shortcut #151
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,90 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package calendar | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/larksuite/cli/internal/output" | ||
| "github.com/larksuite/cli/internal/validate" | ||
| "github.com/larksuite/cli/shortcuts/common" | ||
| ) | ||
|
|
||
| var CalendarRsvp = common.Shortcut{ | ||
| Service: "calendar", | ||
| Command: "+rsvp", | ||
| Description: "Reply to a calendar event (accept/decline/tentative)", | ||
| Risk: "write", | ||
| Scopes: []string{"calendar:calendar.event:reply"}, | ||
| AuthTypes: []string{"user", "bot"}, | ||
| HasFormat: false, | ||
| Flags: []common.Flag{ | ||
| {Name: "calendar-id", Desc: "calendar ID (default: primary)"}, | ||
| {Name: "event-id", Desc: "event ID", Required: true}, | ||
| {Name: "rsvp-status", Desc: "reply status", Required: true, Enum: []string{"accept", "decline", "tentative"}}, | ||
| }, | ||
| DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { | ||
| calendarId := strings.TrimSpace(runtime.Str("calendar-id")) | ||
| d := common.NewDryRunAPI() | ||
| switch calendarId { | ||
| case "": | ||
| d.Desc("(calendar-id omitted) Will use primary calendar") | ||
| calendarId = "<primary>" | ||
| case "primary": | ||
| calendarId = "<primary>" | ||
| } | ||
| eventId := strings.TrimSpace(runtime.Str("event-id")) | ||
| status := strings.TrimSpace(runtime.Str("rsvp-status")) | ||
|
|
||
| return d. | ||
| POST("/open-apis/calendar/v4/calendars/:calendar_id/events/:event_id/reply"). | ||
| Body(map[string]interface{}{"rsvp_status": status}). | ||
| Set("calendar_id", calendarId). | ||
| Set("event_id", eventId) | ||
| }, | ||
| Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { | ||
| for _, flag := range []string{"calendar-id", "event-id", "rsvp-status"} { | ||
| if val := strings.TrimSpace(runtime.Str(flag)); val != "" { | ||
| if err := common.RejectDangerousChars("--"+flag, val); err != nil { | ||
| return output.ErrValidation(err.Error()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| eventId := strings.TrimSpace(runtime.Str("event-id")) | ||
| if eventId == "" { | ||
| return output.ErrValidation("event-id cannot be empty") | ||
| } | ||
| return nil | ||
| }, | ||
| Execute: func(ctx context.Context, runtime *common.RuntimeContext) error { | ||
| calendarId := strings.TrimSpace(runtime.Str("calendar-id")) | ||
| if calendarId == "" { | ||
| calendarId = PrimaryCalendarIDStr | ||
| } | ||
| eventId := strings.TrimSpace(runtime.Str("event-id")) | ||
| status := strings.TrimSpace(runtime.Str("rsvp-status")) | ||
|
|
||
| _, err := runtime.DoAPIJSON("POST", | ||
| fmt.Sprintf("/open-apis/calendar/v4/calendars/%s/events/%s/reply", | ||
| validate.EncodePathSegment(calendarId), | ||
| validate.EncodePathSegment(eventId)), | ||
| nil, | ||
| map[string]interface{}{ | ||
| "rsvp_status": status, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| runtime.Out(map[string]interface{}{ | ||
| "calendar_id": calendarId, | ||
| "event_id": eventId, | ||
| "rsvp_status": status, | ||
| }, nil) | ||
| return nil | ||
| }, | ||
| } | ||
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
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
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
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,42 @@ | ||
| # calendar +rsvp | ||
|
|
||
| > **前置条件:** 先阅读 [`../lark-shared/SKILL.md`](../../lark-shared/SKILL.md) 了解认证、全局参数和安全规则。 | ||
|
|
||
| 回复指定的日程,更新当前用户的 RSVP 状态(接受、拒绝或待定)。 | ||
|
|
||
| 需要的scopes: ["calendar:calendar.event:reply"] | ||
|
|
||
| ## 命令 | ||
|
|
||
| ```bash | ||
| # 回复日程为接受 (使用主日历) | ||
| lark-cli calendar +rsvp --event-id evt_xxx --rsvp-status accept | ||
|
|
||
| # 回复日程为拒绝 | ||
| lark-cli calendar +rsvp --event-id evt_xxx --rsvp-status decline | ||
|
|
||
| # 回复日程为待定 | ||
| lark-cli calendar +rsvp --event-id evt_xxx --rsvp-status tentative | ||
|
|
||
| # 指定其他日历下的日程 | ||
| lark-cli calendar +rsvp --calendar-id cal_xxx --event-id evt_xxx --rsvp-status accept | ||
| ``` | ||
|
|
||
| ## 参数 | ||
|
|
||
| | 参数 | 必填 | 说明 | | ||
| |------|------|------| | ||
| | `--event-id <id>` | **是** | 日程 ID | | ||
| | `--rsvp-status <status>` | **是** | 回复状态,可选值:`accept` (接受), `decline` (拒绝), `tentative` (待定) | | ||
| | `--calendar-id <id>` | 否 | 日历 ID(省略则使用主日历) | | ||
| | `--dry-run` | 否 | 预览 API 调用,不执行 | | ||
|
|
||
| ## 提示 | ||
|
|
||
| - 只能回复你被邀请的日程。 | ||
| - 调用前通常需要通过 `+agenda` 等命令获取到具体的 `event-id`。 | ||
|
|
||
| ## 参考 | ||
|
|
||
| - [lark-calendar](../SKILL.md) -- 日历全部命令 | ||
| - [lark-shared](../../lark-shared/SKILL.md) -- 认证和全局参数 |
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.