-
Notifications
You must be signed in to change notification settings - Fork 667
feat(lark-im): support UAT for forward and add threads.forward #689
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
YangJunzhou-01
merged 1 commit into
larksuite:main
from
chenxingtong-bytedance:feat/support_uat_forward_msg
May 11, 2026
+196
−5
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
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,184 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package im | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| clie2e "github.com/larksuite/cli/tests/cli_e2e" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestIM_MessageForwardWorkflowAsUser(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
| t.Cleanup(cancel) | ||
|
|
||
| clie2e.SkipWithoutUserToken(t) | ||
|
|
||
| suffix := clie2e.GenerateSuffix() | ||
| messageText := "im-forward-msg-" + suffix | ||
| replyText := "im-forward-reply-" + suffix | ||
|
|
||
| selfOpenID := getSelfOpenID(t, ctx) | ||
| chatID, messageID := sendDirectMessageToUser(t, ctx, selfOpenID, messageText, "bot") | ||
|
|
||
|
chenxingtong-bytedance marked this conversation as resolved.
|
||
| t.Run("forward message with api command as user", func(t *testing.T) { | ||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{"im", "messages", "forward"}, | ||
| DefaultAs: "user", | ||
| Params: map[string]any{ | ||
| "message_id": messageID, | ||
| "receive_id_type": "chat_id", | ||
| "uuid": "msg-forward-" + suffix, | ||
| }, | ||
| Data: map[string]any{ | ||
| "receive_id": chatID, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| skipIfMissingIMForwardPermission(t, result) | ||
| result.AssertExitCode(t, 0) | ||
| result.AssertStdoutStatus(t, 0) | ||
|
|
||
| forwardedID := gjson.Get(result.Stdout, "data.message_id").String() | ||
| require.NotEmpty(t, forwardedID, "stdout:\n%s", result.Stdout) | ||
| require.NotEqual(t, messageID, forwardedID, "stdout:\n%s", result.Stdout) | ||
| require.Equal(t, chatID, gjson.Get(result.Stdout, "data.chat_id").String(), "stdout:\n%s", result.Stdout) | ||
| }) | ||
|
|
||
| var threadID string | ||
| t.Run("create thread fixture as bot", func(t *testing.T) { | ||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{"im", "+messages-reply", | ||
| "--message-id", messageID, | ||
| "--text", replyText, | ||
| "--reply-in-thread", | ||
| }, | ||
| DefaultAs: "bot", | ||
| }) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 0) | ||
| result.AssertStdoutStatus(t, true) | ||
|
|
||
| threadID = findThreadIDForMessage(t, ctx, chatID, messageID, "bot") | ||
| }) | ||
|
|
||
| t.Run("forward thread with api command as user", func(t *testing.T) { | ||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{"im", "threads", "forward"}, | ||
| DefaultAs: "user", | ||
| Params: map[string]any{ | ||
| "thread_id": threadID, | ||
| "receive_id_type": "chat_id", | ||
| "uuid": "thread-forward-" + suffix, | ||
| }, | ||
| Data: map[string]any{ | ||
| "receive_id": chatID, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| skipIfMissingIMForwardPermission(t, result) | ||
| result.AssertExitCode(t, 0) | ||
| result.AssertStdoutStatus(t, 0) | ||
|
|
||
| forwardedID := gjson.Get(result.Stdout, "data.message_id").String() | ||
| require.NotEmpty(t, forwardedID, "stdout:\n%s", result.Stdout) | ||
| require.Equal(t, chatID, gjson.Get(result.Stdout, "data.chat_id").String(), "stdout:\n%s", result.Stdout) | ||
| require.Equal(t, "merge_forward", gjson.Get(result.Stdout, "data.msg_type").String(), "stdout:\n%s", result.Stdout) | ||
| }) | ||
| } | ||
|
chenxingtong-bytedance marked this conversation as resolved.
|
||
|
|
||
| func findThreadIDForMessage(t *testing.T, ctx context.Context, chatID string, messageID string, defaultAs string) string { | ||
| t.Helper() | ||
|
|
||
| listResult, err := clie2e.RunCmdWithRetry(ctx, clie2e.Request{ | ||
| Args: []string{ | ||
| "im", "+chat-messages-list", | ||
| "--chat-id", chatID, | ||
| "--start", time.Now().UTC().Add(-10 * time.Minute).Format(time.RFC3339), | ||
| "--end", time.Now().UTC().Add(10 * time.Minute).Format(time.RFC3339), | ||
| }, | ||
| DefaultAs: defaultAs, | ||
| }, clie2e.RetryOptions{ | ||
| ShouldRetry: func(result *clie2e.Result) bool { | ||
| if result == nil || result.ExitCode != 0 { | ||
| return true | ||
| } | ||
| for _, item := range gjson.Get(result.Stdout, "data.messages").Array() { | ||
| if item.Get("message_id").String() == messageID && item.Get("thread_id").String() != "" { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| listResult.AssertExitCode(t, 0) | ||
| listResult.AssertStdoutStatus(t, true) | ||
|
|
||
| for _, item := range gjson.Get(listResult.Stdout, "data.messages").Array() { | ||
| if item.Get("message_id").String() == messageID { | ||
| threadID := item.Get("thread_id").String() | ||
| require.NotEmpty(t, threadID, "expected thread_id for message %s in stdout:\n%s", messageID, listResult.Stdout) | ||
| return threadID | ||
| } | ||
| } | ||
|
|
||
| t.Fatalf("expected message %s in stdout:\n%s", messageID, listResult.Stdout) | ||
| return "" | ||
| } | ||
|
|
||
| func getSelfOpenID(t *testing.T, ctx context.Context) string { | ||
| t.Helper() | ||
|
|
||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{"contact", "+get-user"}, | ||
| DefaultAs: "user", | ||
| }) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 0) | ||
| result.AssertStdoutStatus(t, true) | ||
|
|
||
| openID := gjson.Get(result.Stdout, "data.user.open_id").String() | ||
| require.NotEmpty(t, openID, "stdout:\n%s", result.Stdout) | ||
| return openID | ||
| } | ||
|
|
||
| func sendDirectMessageToUser(t *testing.T, ctx context.Context, userOpenID string, text string, defaultAs string) (string, string) { | ||
| t.Helper() | ||
|
|
||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{"im", "+messages-send", | ||
| "--user-id", userOpenID, | ||
| "--text", text, | ||
| }, | ||
| DefaultAs: defaultAs, | ||
| }) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 0) | ||
| result.AssertStdoutStatus(t, true) | ||
|
|
||
| chatID := gjson.Get(result.Stdout, "data.chat_id").String() | ||
| messageID := gjson.Get(result.Stdout, "data.message_id").String() | ||
| require.NotEmpty(t, chatID, "stdout:\n%s", result.Stdout) | ||
| require.NotEmpty(t, messageID, "stdout:\n%s", result.Stdout) | ||
| return chatID, messageID | ||
| } | ||
|
|
||
| func skipIfMissingIMForwardPermission(t *testing.T, result *clie2e.Result) { | ||
| t.Helper() | ||
| if result == nil || result.ExitCode == 0 { | ||
| return | ||
| } | ||
| stderrLower := strings.ToLower(result.Stderr) | ||
| if strings.Contains(stderrLower, "permission denied") || | ||
| strings.Contains(stderrLower, "230027") || | ||
| strings.Contains(stderrLower, "missing_scope") { | ||
| t.Skipf("skip UAT forward workflow due to missing IM forward permissions: %s", result.Stderr) | ||
| } | ||
| } | ||
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.