@openclaw/feishu 2026.5.2 → 2026.5.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts-Ba3-WP1z.js +423 -0
- package/dist/api.js +2280 -0
- package/dist/app-registration-B8qc1MCM.js +184 -0
- package/dist/audio-preflight.runtime-BPlzkO3l.js +7 -0
- package/dist/card-interaction-BfRLgvw_.js +96 -0
- package/dist/channel-CSD_Jt8I.js +1668 -0
- package/dist/channel-entry.js +22 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-DYsXcD36.js +700 -0
- package/dist/client-DBVoQL5w.js +157 -0
- package/dist/contract-api.js +9 -0
- package/dist/conversation-id-DWS3Ep2A.js +139 -0
- package/dist/directory.static-f3EeoRJd.js +44 -0
- package/dist/drive-C5eJLJr7.js +883 -0
- package/dist/index.js +68 -0
- package/dist/monitor-CT189QfR.js +60 -0
- package/dist/monitor.account-dJV2jO8C.js +4990 -0
- package/dist/monitor.state-DYM02ipp.js +100 -0
- package/dist/policy-D6c-wMPl.js +118 -0
- package/dist/probe-BNzzU_uR.js +149 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/runtime-CG0DuRCy.js +8 -0
- package/dist/runtime-api.js +14 -0
- package/dist/secret-contract-Dm4Z_zQN.js +119 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-DqJdocrN.js +11 -0
- package/dist/security-audit-shared-ByuMx9cJ.js +38 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-DowxxbpH.js +1218 -0
- package/dist/session-conversation-B4nrW-vo.js +27 -0
- package/dist/session-key-api.js +2 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/subagent-hooks-C3UhPVLV.js +227 -0
- package/dist/subagent-hooks-api.js +23 -0
- package/dist/targets-JMFJRKSe.js +48 -0
- package/dist/thread-bindings-BmS6TLes.js +222 -0
- package/package.json +15 -6
- package/api.ts +0 -31
- package/channel-entry.ts +0 -20
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -16
- package/index.ts +0 -82
- package/runtime-api.ts +0 -55
- package/secret-contract-api.ts +0 -5
- package/security-contract-api.ts +0 -1
- package/session-key-api.ts +0 -1
- package/setup-api.ts +0 -3
- package/setup-entry.test.ts +0 -14
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -459
- package/src/accounts.ts +0 -326
- package/src/app-registration.ts +0 -331
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -25
- package/src/async.test.ts +0 -35
- package/src/async.ts +0 -104
- package/src/audio-preflight.runtime.ts +0 -9
- package/src/bitable.test.ts +0 -131
- package/src/bitable.ts +0 -762
- package/src/bot-content.ts +0 -474
- package/src/bot-group-name.test.ts +0 -108
- package/src/bot-runtime-api.ts +0 -12
- package/src/bot-sender-name.ts +0 -125
- package/src/bot.broadcast.test.ts +0 -463
- package/src/bot.card-action.test.ts +0 -577
- package/src/bot.checkBotMentioned.test.ts +0 -265
- package/src/bot.helpers.test.ts +0 -118
- package/src/bot.stripBotMention.test.ts +0 -126
- package/src/bot.test.ts +0 -3040
- package/src/bot.ts +0 -1559
- package/src/card-action.ts +0 -447
- package/src/card-interaction.test.ts +0 -129
- package/src/card-interaction.ts +0 -159
- package/src/card-test-helpers.ts +0 -47
- package/src/card-ux-approval.ts +0 -65
- package/src/card-ux-launcher.test.ts +0 -99
- package/src/card-ux-launcher.ts +0 -121
- package/src/card-ux-shared.ts +0 -33
- package/src/channel-runtime-api.ts +0 -16
- package/src/channel.runtime.ts +0 -47
- package/src/channel.test.ts +0 -959
- package/src/channel.ts +0 -1313
- package/src/chat-schema.ts +0 -25
- package/src/chat.test.ts +0 -196
- package/src/chat.ts +0 -188
- package/src/client.test.ts +0 -433
- package/src/client.ts +0 -290
- package/src/comment-dispatcher-runtime-api.ts +0 -6
- package/src/comment-dispatcher.test.ts +0 -169
- package/src/comment-dispatcher.ts +0 -107
- package/src/comment-handler-runtime-api.ts +0 -3
- package/src/comment-handler.test.ts +0 -486
- package/src/comment-handler.ts +0 -309
- package/src/comment-reaction.test.ts +0 -166
- package/src/comment-reaction.ts +0 -259
- package/src/comment-shared.test.ts +0 -182
- package/src/comment-shared.ts +0 -406
- package/src/comment-target.ts +0 -44
- package/src/config-schema.test.ts +0 -309
- package/src/config-schema.ts +0 -333
- package/src/conversation-id.test.ts +0 -18
- package/src/conversation-id.ts +0 -199
- package/src/dedup-runtime-api.ts +0 -1
- package/src/dedup.ts +0 -141
- package/src/directory.static.ts +0 -61
- package/src/directory.test.ts +0 -136
- package/src/directory.ts +0 -124
- package/src/doc-schema.ts +0 -182
- package/src/docx-batch-insert.test.ts +0 -91
- package/src/docx-batch-insert.ts +0 -223
- package/src/docx-color-text.ts +0 -154
- package/src/docx-table-ops.test.ts +0 -53
- package/src/docx-table-ops.ts +0 -316
- package/src/docx-types.ts +0 -38
- package/src/docx.account-selection.test.ts +0 -79
- package/src/docx.test.ts +0 -685
- package/src/docx.ts +0 -1616
- package/src/drive-schema.ts +0 -92
- package/src/drive.test.ts +0 -1219
- package/src/drive.ts +0 -829
- package/src/dynamic-agent.ts +0 -137
- package/src/event-types.ts +0 -45
- package/src/external-keys.test.ts +0 -20
- package/src/external-keys.ts +0 -19
- package/src/lifecycle.test-support.ts +0 -220
- package/src/media.test.ts +0 -900
- package/src/media.ts +0 -861
- package/src/mention-target.types.ts +0 -5
- package/src/mention.ts +0 -114
- package/src/message-action-contract.ts +0 -13
- package/src/monitor-state-runtime-api.ts +0 -7
- package/src/monitor-transport-runtime-api.ts +0 -7
- package/src/monitor.account.ts +0 -468
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
- package/src/monitor.bot-identity.ts +0 -86
- package/src/monitor.bot-menu-handler.ts +0 -165
- package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
- package/src/monitor.bot-menu.test.ts +0 -178
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
- package/src/monitor.card-action.lifecycle.test-support.ts +0 -373
- package/src/monitor.cleanup.test.ts +0 -376
- package/src/monitor.comment-notice-handler.ts +0 -105
- package/src/monitor.comment.test.ts +0 -937
- package/src/monitor.comment.ts +0 -1386
- package/src/monitor.lifecycle.test.ts +0 -4
- package/src/monitor.message-handler.ts +0 -339
- package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
- package/src/monitor.reaction.test.ts +0 -713
- package/src/monitor.startup.test.ts +0 -192
- package/src/monitor.startup.ts +0 -74
- package/src/monitor.state.defaults.test.ts +0 -46
- package/src/monitor.state.ts +0 -170
- package/src/monitor.synthetic-error.ts +0 -18
- package/src/monitor.test-mocks.ts +0 -45
- package/src/monitor.transport.ts +0 -424
- package/src/monitor.ts +0 -100
- package/src/monitor.webhook-e2e.test.ts +0 -272
- package/src/monitor.webhook-security.test.ts +0 -264
- package/src/monitor.webhook.test-helpers.ts +0 -116
- package/src/outbound-runtime-api.ts +0 -1
- package/src/outbound.test.ts +0 -935
- package/src/outbound.ts +0 -718
- package/src/perm-schema.ts +0 -52
- package/src/perm.ts +0 -170
- package/src/pins.ts +0 -108
- package/src/policy.test.ts +0 -334
- package/src/policy.ts +0 -236
- package/src/post.test.ts +0 -105
- package/src/post.ts +0 -275
- package/src/probe.test.ts +0 -275
- package/src/probe.ts +0 -166
- package/src/processing-claims.ts +0 -59
- package/src/qr-terminal.ts +0 -1
- package/src/reactions.ts +0 -123
- package/src/reasoning-preview.test.ts +0 -59
- package/src/reasoning-preview.ts +0 -20
- package/src/reply-dispatcher-runtime-api.ts +0 -7
- package/src/reply-dispatcher.test.ts +0 -1144
- package/src/reply-dispatcher.ts +0 -650
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -145
- package/src/secret-input.ts +0 -1
- package/src/security-audit-shared.ts +0 -69
- package/src/security-audit.test.ts +0 -61
- package/src/security-audit.ts +0 -1
- package/src/send-result.ts +0 -29
- package/src/send-target.test.ts +0 -80
- package/src/send-target.ts +0 -35
- package/src/send.reply-fallback.test.ts +0 -292
- package/src/send.test.ts +0 -550
- package/src/send.ts +0 -800
- package/src/sequential-key.test.ts +0 -72
- package/src/sequential-key.ts +0 -28
- package/src/sequential-queue.test.ts +0 -92
- package/src/sequential-queue.ts +0 -16
- package/src/session-conversation.ts +0 -42
- package/src/session-route.ts +0 -48
- package/src/setup-core.ts +0 -51
- package/src/setup-surface.test.ts +0 -174
- package/src/setup-surface.ts +0 -581
- package/src/streaming-card.test.ts +0 -190
- package/src/streaming-card.ts +0 -490
- package/src/subagent-hooks.test.ts +0 -603
- package/src/subagent-hooks.ts +0 -397
- package/src/targets.ts +0 -97
- package/src/test-support/lifecycle-test-support.ts +0 -453
- package/src/thread-bindings.test.ts +0 -143
- package/src/thread-bindings.ts +0 -330
- package/src/tool-account-routing.test.ts +0 -187
- package/src/tool-account.test.ts +0 -44
- package/src/tool-account.ts +0 -93
- package/src/tool-factory-test-harness.ts +0 -79
- package/src/tool-result.test.ts +0 -32
- package/src/tool-result.ts +0 -16
- package/src/tools-config.test.ts +0 -21
- package/src/tools-config.ts +0 -22
- package/src/types.ts +0 -104
- package/src/typing.test.ts +0 -144
- package/src/typing.ts +0 -214
- package/src/wiki-schema.ts +0 -55
- package/src/wiki.ts +0 -227
- package/subagent-hooks-api.ts +0 -31
- package/tsconfig.json +0 -16
package/src/chat-schema.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Type, type Static } from "typebox";
|
|
2
|
-
|
|
3
|
-
const CHAT_ACTION_VALUES = ["members", "info", "member_info"] as const;
|
|
4
|
-
const MEMBER_ID_TYPE_VALUES = ["open_id", "user_id", "union_id"] as const;
|
|
5
|
-
|
|
6
|
-
export const FeishuChatSchema = Type.Object({
|
|
7
|
-
action: Type.Unsafe<(typeof CHAT_ACTION_VALUES)[number]>({
|
|
8
|
-
type: "string",
|
|
9
|
-
enum: [...CHAT_ACTION_VALUES],
|
|
10
|
-
description: "Action to run: members | info | member_info",
|
|
11
|
-
}),
|
|
12
|
-
chat_id: Type.Optional(Type.String({ description: "Chat ID (from URL or event payload)" })),
|
|
13
|
-
member_id: Type.Optional(Type.String({ description: "Member ID for member_info lookups" })),
|
|
14
|
-
page_size: Type.Optional(Type.Number({ description: "Page size (1-100, default 50)" })),
|
|
15
|
-
page_token: Type.Optional(Type.String({ description: "Pagination token" })),
|
|
16
|
-
member_id_type: Type.Optional(
|
|
17
|
-
Type.Unsafe<(typeof MEMBER_ID_TYPE_VALUES)[number]>({
|
|
18
|
-
type: "string",
|
|
19
|
-
enum: [...MEMBER_ID_TYPE_VALUES],
|
|
20
|
-
description: "Member ID type (default: open_id)",
|
|
21
|
-
}),
|
|
22
|
-
),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export type FeishuChatParams = Static<typeof FeishuChatSchema>;
|
package/src/chat.test.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
|
2
|
-
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { OpenClawPluginApi, PluginRuntime } from "../runtime-api.js";
|
|
4
|
-
|
|
5
|
-
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
|
6
|
-
const chatGetMock = vi.hoisted(() => vi.fn());
|
|
7
|
-
const chatMembersGetMock = vi.hoisted(() => vi.fn());
|
|
8
|
-
const contactUserGetMock = vi.hoisted(() => vi.fn());
|
|
9
|
-
|
|
10
|
-
vi.mock("./client.js", () => ({
|
|
11
|
-
createFeishuClient: createFeishuClientMock,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
let registerFeishuChatTools: typeof import("./chat.js").registerFeishuChatTools;
|
|
15
|
-
|
|
16
|
-
function createFeishuToolRuntime(): PluginRuntime {
|
|
17
|
-
return {} as PluginRuntime;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe("registerFeishuChatTools", () => {
|
|
21
|
-
function createChatToolApi(params: {
|
|
22
|
-
config: OpenClawPluginApi["config"];
|
|
23
|
-
registerTool: OpenClawPluginApi["registerTool"];
|
|
24
|
-
}): OpenClawPluginApi {
|
|
25
|
-
return createTestPluginApi({
|
|
26
|
-
id: "feishu-test",
|
|
27
|
-
name: "Feishu Test",
|
|
28
|
-
source: "local",
|
|
29
|
-
config: params.config,
|
|
30
|
-
runtime: createFeishuToolRuntime(),
|
|
31
|
-
logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
32
|
-
registerTool: params.registerTool,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
beforeAll(async () => {
|
|
37
|
-
({ registerFeishuChatTools } = await import("./chat.js"));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
vi.clearAllMocks();
|
|
42
|
-
createFeishuClientMock.mockReturnValue({
|
|
43
|
-
im: {
|
|
44
|
-
chat: { get: chatGetMock },
|
|
45
|
-
chatMembers: { get: chatMembersGetMock },
|
|
46
|
-
},
|
|
47
|
-
contact: {
|
|
48
|
-
user: { get: contactUserGetMock },
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("registers feishu_chat and handles info/members actions", async () => {
|
|
54
|
-
const registerTool = vi.fn();
|
|
55
|
-
registerFeishuChatTools(
|
|
56
|
-
createChatToolApi({
|
|
57
|
-
config: {
|
|
58
|
-
channels: {
|
|
59
|
-
feishu: {
|
|
60
|
-
enabled: true,
|
|
61
|
-
appId: "app_id",
|
|
62
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
63
|
-
tools: { chat: true },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
registerTool,
|
|
68
|
-
}),
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
expect(registerTool).toHaveBeenCalledTimes(1);
|
|
72
|
-
const tool = registerTool.mock.calls[0]?.[0];
|
|
73
|
-
expect(tool?.name).toBe("feishu_chat");
|
|
74
|
-
|
|
75
|
-
chatGetMock.mockResolvedValueOnce({
|
|
76
|
-
code: 0,
|
|
77
|
-
data: { name: "group name", user_count: 3 },
|
|
78
|
-
});
|
|
79
|
-
const infoResult = await tool.execute("tc_1", { action: "info", chat_id: "oc_1" });
|
|
80
|
-
expect(infoResult.details).toEqual(
|
|
81
|
-
expect.objectContaining({ chat_id: "oc_1", name: "group name", user_count: 3 }),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
chatMembersGetMock.mockResolvedValueOnce({
|
|
85
|
-
code: 0,
|
|
86
|
-
data: {
|
|
87
|
-
has_more: false,
|
|
88
|
-
page_token: "",
|
|
89
|
-
items: [{ member_id: "ou_1", name: "member1", member_id_type: "open_id" }],
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
const membersResult = await tool.execute("tc_2", { action: "members", chat_id: "oc_1" });
|
|
93
|
-
expect(membersResult.details).toEqual(
|
|
94
|
-
expect.objectContaining({
|
|
95
|
-
chat_id: "oc_1",
|
|
96
|
-
members: [expect.objectContaining({ member_id: "ou_1", name: "member1" })],
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
contactUserGetMock.mockResolvedValueOnce({
|
|
101
|
-
code: 0,
|
|
102
|
-
data: {
|
|
103
|
-
user: {
|
|
104
|
-
open_id: "ou_1",
|
|
105
|
-
name: "member1",
|
|
106
|
-
email: "member1@example.com",
|
|
107
|
-
department_ids: ["od_1"],
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
const memberInfoResult = await tool.execute("tc_3", {
|
|
112
|
-
action: "member_info",
|
|
113
|
-
member_id: "ou_1",
|
|
114
|
-
});
|
|
115
|
-
expect(memberInfoResult.details).toEqual(
|
|
116
|
-
expect.objectContaining({
|
|
117
|
-
member_id: "ou_1",
|
|
118
|
-
open_id: "ou_1",
|
|
119
|
-
name: "member1",
|
|
120
|
-
email: "member1@example.com",
|
|
121
|
-
department_ids: ["od_1"],
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("skips registration when chat tool is disabled", () => {
|
|
127
|
-
const registerTool = vi.fn();
|
|
128
|
-
registerFeishuChatTools(
|
|
129
|
-
createChatToolApi({
|
|
130
|
-
config: {
|
|
131
|
-
channels: {
|
|
132
|
-
feishu: {
|
|
133
|
-
enabled: true,
|
|
134
|
-
appId: "app_id",
|
|
135
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
136
|
-
tools: { chat: false },
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
registerTool,
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
expect(registerTool).not.toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("preserves Feishu diagnostics from rejected member lookups", async () => {
|
|
147
|
-
const registerTool = vi.fn();
|
|
148
|
-
registerFeishuChatTools(
|
|
149
|
-
createChatToolApi({
|
|
150
|
-
config: {
|
|
151
|
-
channels: {
|
|
152
|
-
feishu: {
|
|
153
|
-
enabled: true,
|
|
154
|
-
appId: "app_id",
|
|
155
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
156
|
-
tools: { chat: true },
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
registerTool,
|
|
161
|
-
}),
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const tool = registerTool.mock.calls[0]?.[0];
|
|
165
|
-
contactUserGetMock.mockRejectedValueOnce(
|
|
166
|
-
Object.assign(new Error("Request failed with status code 400"), {
|
|
167
|
-
response: {
|
|
168
|
-
status: 400,
|
|
169
|
-
data: {
|
|
170
|
-
code: 99992360,
|
|
171
|
-
msg: "The request you send is not a valid {user_id} or not exists",
|
|
172
|
-
error: {
|
|
173
|
-
log_id: "20260429124800CHAT",
|
|
174
|
-
troubleshooter: "https://open.feishu.cn/search?log_id=20260429124800CHAT",
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
}),
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const result = await tool.execute("tc_4", {
|
|
182
|
-
action: "member_info",
|
|
183
|
-
member_id: "ou_1",
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(result.details.error).toContain('"http_status":400');
|
|
187
|
-
expect(result.details.error).toContain('"feishu_code":99992360');
|
|
188
|
-
expect(result.details.error).toContain(
|
|
189
|
-
'"feishu_msg":"The request you send is not a valid {user_id} or not exists"',
|
|
190
|
-
);
|
|
191
|
-
expect(result.details.error).toContain('"feishu_log_id":"20260429124800CHAT"');
|
|
192
|
-
expect(result.details.error).toContain(
|
|
193
|
-
'"feishu_troubleshooter":"https://open.feishu.cn/search?log_id=20260429124800CHAT"',
|
|
194
|
-
);
|
|
195
|
-
});
|
|
196
|
-
});
|
package/src/chat.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
2
|
-
import type { OpenClawPluginApi } from "../runtime-api.js";
|
|
3
|
-
import { listEnabledFeishuAccounts } from "./accounts.js";
|
|
4
|
-
import { FeishuChatSchema, type FeishuChatParams } from "./chat-schema.js";
|
|
5
|
-
import { createFeishuClient } from "./client.js";
|
|
6
|
-
import { formatFeishuApiError } from "./comment-shared.js";
|
|
7
|
-
import { resolveToolsConfig } from "./tools-config.js";
|
|
8
|
-
|
|
9
|
-
function json(data: unknown) {
|
|
10
|
-
return {
|
|
11
|
-
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
12
|
-
details: data,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function getChatInfo(client: Lark.Client, chatId: string) {
|
|
17
|
-
const res = await client.im.chat.get({ path: { chat_id: chatId } });
|
|
18
|
-
if (res.code !== 0) {
|
|
19
|
-
throw new Error(res.msg);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const chat = res.data;
|
|
23
|
-
return {
|
|
24
|
-
chat_id: chatId,
|
|
25
|
-
name: chat?.name,
|
|
26
|
-
description: chat?.description,
|
|
27
|
-
owner_id: chat?.owner_id,
|
|
28
|
-
tenant_key: chat?.tenant_key,
|
|
29
|
-
user_count: chat?.user_count,
|
|
30
|
-
chat_mode: chat?.chat_mode,
|
|
31
|
-
chat_type: chat?.chat_type,
|
|
32
|
-
join_message_visibility: chat?.join_message_visibility,
|
|
33
|
-
leave_message_visibility: chat?.leave_message_visibility,
|
|
34
|
-
membership_approval: chat?.membership_approval,
|
|
35
|
-
moderation_permission: chat?.moderation_permission,
|
|
36
|
-
avatar: chat?.avatar,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function getChatMembers(
|
|
41
|
-
client: Lark.Client,
|
|
42
|
-
chatId: string,
|
|
43
|
-
pageSize?: number,
|
|
44
|
-
pageToken?: string,
|
|
45
|
-
memberIdType?: "open_id" | "user_id" | "union_id",
|
|
46
|
-
) {
|
|
47
|
-
const page_size = pageSize ? Math.max(1, Math.min(100, pageSize)) : 50;
|
|
48
|
-
const res = await client.im.chatMembers.get({
|
|
49
|
-
path: { chat_id: chatId },
|
|
50
|
-
params: {
|
|
51
|
-
page_size,
|
|
52
|
-
page_token: pageToken,
|
|
53
|
-
member_id_type: memberIdType ?? "open_id",
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (res.code !== 0) {
|
|
58
|
-
throw new Error(res.msg);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
chat_id: chatId,
|
|
63
|
-
has_more: res.data?.has_more,
|
|
64
|
-
page_token: res.data?.page_token,
|
|
65
|
-
members:
|
|
66
|
-
res.data?.items?.map((item) => ({
|
|
67
|
-
member_id: item.member_id,
|
|
68
|
-
name: item.name,
|
|
69
|
-
tenant_key: item.tenant_key,
|
|
70
|
-
member_id_type: item.member_id_type,
|
|
71
|
-
})) ?? [],
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function getFeishuMemberInfo(
|
|
76
|
-
client: Lark.Client,
|
|
77
|
-
memberId: string,
|
|
78
|
-
memberIdType: "open_id" | "user_id" | "union_id" = "open_id",
|
|
79
|
-
) {
|
|
80
|
-
const res = await client.contact.user.get({
|
|
81
|
-
path: { user_id: memberId },
|
|
82
|
-
params: {
|
|
83
|
-
user_id_type: memberIdType,
|
|
84
|
-
department_id_type: "open_department_id",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (res.code !== 0) {
|
|
89
|
-
throw new Error(res.msg);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const user = res.data?.user;
|
|
93
|
-
return {
|
|
94
|
-
member_id: memberId,
|
|
95
|
-
member_id_type: memberIdType,
|
|
96
|
-
open_id: user?.open_id,
|
|
97
|
-
user_id: user?.user_id,
|
|
98
|
-
union_id: user?.union_id,
|
|
99
|
-
name: user?.name,
|
|
100
|
-
en_name: user?.en_name,
|
|
101
|
-
nickname: user?.nickname,
|
|
102
|
-
email: user?.email,
|
|
103
|
-
enterprise_email: user?.enterprise_email,
|
|
104
|
-
mobile: user?.mobile,
|
|
105
|
-
mobile_visible: user?.mobile_visible,
|
|
106
|
-
status: user?.status,
|
|
107
|
-
avatar: user?.avatar,
|
|
108
|
-
department_ids: user?.department_ids,
|
|
109
|
-
department_path: user?.department_path,
|
|
110
|
-
leader_user_id: user?.leader_user_id,
|
|
111
|
-
city: user?.city,
|
|
112
|
-
country: user?.country,
|
|
113
|
-
work_station: user?.work_station,
|
|
114
|
-
join_time: user?.join_time,
|
|
115
|
-
is_tenant_manager: user?.is_tenant_manager,
|
|
116
|
-
employee_no: user?.employee_no,
|
|
117
|
-
employee_type: user?.employee_type,
|
|
118
|
-
description: user?.description,
|
|
119
|
-
job_title: user?.job_title,
|
|
120
|
-
geo: user?.geo,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function registerFeishuChatTools(api: OpenClawPluginApi) {
|
|
125
|
-
if (!api.config) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const accounts = listEnabledFeishuAccounts(api.config);
|
|
130
|
-
if (accounts.length === 0) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const firstAccount = accounts[0];
|
|
135
|
-
const toolsCfg = resolveToolsConfig(firstAccount.config.tools);
|
|
136
|
-
if (!toolsCfg.chat) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const getClient = () => createFeishuClient(firstAccount);
|
|
141
|
-
|
|
142
|
-
api.registerTool(
|
|
143
|
-
{
|
|
144
|
-
name: "feishu_chat",
|
|
145
|
-
label: "Feishu Chat",
|
|
146
|
-
description: "Feishu chat operations. Actions: members, info, member_info",
|
|
147
|
-
parameters: FeishuChatSchema,
|
|
148
|
-
async execute(_toolCallId, params) {
|
|
149
|
-
const p = params as FeishuChatParams;
|
|
150
|
-
try {
|
|
151
|
-
const client = getClient();
|
|
152
|
-
switch (p.action) {
|
|
153
|
-
case "members":
|
|
154
|
-
if (!p.chat_id) {
|
|
155
|
-
return json({ error: "chat_id is required for action members" });
|
|
156
|
-
}
|
|
157
|
-
return json(
|
|
158
|
-
await getChatMembers(
|
|
159
|
-
client,
|
|
160
|
-
p.chat_id,
|
|
161
|
-
p.page_size,
|
|
162
|
-
p.page_token,
|
|
163
|
-
p.member_id_type,
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
case "info":
|
|
167
|
-
if (!p.chat_id) {
|
|
168
|
-
return json({ error: "chat_id is required for action info" });
|
|
169
|
-
}
|
|
170
|
-
return json(await getChatInfo(client, p.chat_id));
|
|
171
|
-
case "member_info":
|
|
172
|
-
if (!p.member_id) {
|
|
173
|
-
return json({ error: "member_id is required for action member_info" });
|
|
174
|
-
}
|
|
175
|
-
return json(
|
|
176
|
-
await getFeishuMemberInfo(client, p.member_id, p.member_id_type ?? "open_id"),
|
|
177
|
-
);
|
|
178
|
-
default:
|
|
179
|
-
return json({ error: `Unknown action: ${String(p.action)}` });
|
|
180
|
-
}
|
|
181
|
-
} catch (err) {
|
|
182
|
-
return json({ error: formatFeishuApiError(err, { includeNestedErrorLogId: true }) });
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
{ name: "feishu_chat" },
|
|
187
|
-
);
|
|
188
|
-
}
|