@openclaw/msteams 2026.3.13 → 2026.5.1-beta.1
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/api.ts +3 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +2 -0
- package/config-api.ts +4 -0
- package/contract-api.ts +4 -0
- package/index.ts +15 -12
- package/openclaw.plugin.json +553 -1
- package/package.json +46 -12
- package/runtime-api.ts +73 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/setup-plugin-api.ts +3 -0
- package/src/ai-entity.ts +7 -0
- package/src/approval-auth.ts +44 -0
- package/src/attachments/bot-framework.test.ts +461 -0
- package/src/attachments/bot-framework.ts +362 -0
- package/src/attachments/download.ts +63 -19
- package/src/attachments/graph.test.ts +416 -0
- package/src/attachments/graph.ts +163 -72
- package/src/attachments/html.ts +33 -1
- package/src/attachments/payload.ts +1 -1
- package/src/attachments/remote-media.test.ts +137 -0
- package/src/attachments/remote-media.ts +75 -8
- package/src/attachments/shared.test.ts +138 -1
- package/src/attachments/shared.ts +193 -26
- package/src/attachments/types.ts +10 -0
- package/src/attachments.graph.test.ts +342 -0
- package/src/attachments.helpers.test.ts +246 -0
- package/src/attachments.test-helpers.ts +17 -0
- package/src/attachments.test.ts +163 -418
- package/src/attachments.ts +5 -5
- package/src/block-streaming-config.test.ts +61 -0
- package/src/channel-api.ts +1 -0
- package/src/channel.actions.test.ts +742 -0
- package/src/channel.directory.test.ts +145 -4
- package/src/channel.runtime.ts +56 -0
- package/src/channel.setup.ts +77 -0
- package/src/channel.test.ts +128 -0
- package/src/channel.ts +1077 -395
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +12 -0
- package/src/conversation-store-fs.test.ts +4 -5
- package/src/conversation-store-fs.ts +35 -51
- package/src/conversation-store-helpers.test.ts +202 -0
- package/src/conversation-store-helpers.ts +105 -0
- package/src/conversation-store-memory.ts +27 -23
- package/src/conversation-store.shared.test.ts +225 -0
- package/src/conversation-store.ts +30 -0
- package/src/directory-live.test.ts +156 -0
- package/src/directory-live.ts +7 -4
- package/src/doctor.ts +27 -0
- package/src/errors.test.ts +64 -1
- package/src/errors.ts +50 -9
- package/src/feedback-reflection-prompt.ts +117 -0
- package/src/feedback-reflection-store.ts +114 -0
- package/src/feedback-reflection.test.ts +237 -0
- package/src/feedback-reflection.ts +283 -0
- package/src/file-consent-helpers.test.ts +83 -0
- package/src/file-consent-helpers.ts +64 -11
- package/src/file-consent-invoke.ts +150 -0
- package/src/file-consent.test.ts +363 -0
- package/src/file-consent.ts +165 -4
- package/src/graph-chat.ts +5 -3
- package/src/graph-group-management.test.ts +318 -0
- package/src/graph-group-management.ts +168 -0
- package/src/graph-members.test.ts +89 -0
- package/src/graph-members.ts +48 -0
- package/src/graph-messages.actions.test.ts +243 -0
- package/src/graph-messages.read.test.ts +391 -0
- package/src/graph-messages.search.test.ts +213 -0
- package/src/graph-messages.test-helpers.ts +50 -0
- package/src/graph-messages.ts +534 -0
- package/src/graph-teams.test.ts +215 -0
- package/src/graph-teams.ts +114 -0
- package/src/graph-thread.test.ts +246 -0
- package/src/graph-thread.ts +146 -0
- package/src/graph-upload.test.ts +161 -4
- package/src/graph-upload.ts +147 -56
- package/src/graph.test.ts +516 -0
- package/src/graph.ts +233 -21
- package/src/inbound.test.ts +156 -1
- package/src/inbound.ts +101 -1
- package/src/media-helpers.ts +1 -1
- package/src/mentions.test.ts +27 -18
- package/src/mentions.ts +2 -2
- package/src/messenger.test.ts +504 -23
- package/src/messenger.ts +133 -52
- package/src/monitor-handler/access.ts +125 -0
- package/src/monitor-handler/inbound-media.test.ts +289 -0
- package/src/monitor-handler/inbound-media.ts +57 -5
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
- package/src/monitor-handler/message-handler.authz.test.ts +588 -74
- package/src/monitor-handler/message-handler.dm-media.test.ts +54 -0
- package/src/monitor-handler/message-handler.test-support.ts +100 -0
- package/src/monitor-handler/message-handler.thread-parent.test.ts +223 -0
- package/src/monitor-handler/message-handler.thread-session.test.ts +77 -0
- package/src/monitor-handler/message-handler.ts +470 -164
- package/src/monitor-handler/reaction-handler.test.ts +267 -0
- package/src/monitor-handler/reaction-handler.ts +210 -0
- package/src/monitor-handler/thread-session.ts +17 -0
- package/src/monitor-handler.adaptive-card.test.ts +162 -0
- package/src/monitor-handler.feedback-authz.test.ts +314 -0
- package/src/monitor-handler.file-consent.test.ts +281 -79
- package/src/monitor-handler.sso.test.ts +563 -0
- package/src/monitor-handler.test-helpers.ts +180 -0
- package/src/monitor-handler.ts +459 -115
- package/src/monitor-handler.types.ts +27 -0
- package/src/monitor-types.ts +1 -0
- package/src/monitor.lifecycle.test.ts +74 -10
- package/src/monitor.test.ts +35 -1
- package/src/monitor.ts +143 -46
- package/src/oauth.flow.ts +77 -0
- package/src/oauth.shared.ts +37 -0
- package/src/oauth.test.ts +305 -0
- package/src/oauth.token.ts +158 -0
- package/src/oauth.ts +130 -0
- package/src/outbound.test.ts +10 -11
- package/src/outbound.ts +62 -44
- package/src/pending-uploads-fs.test.ts +246 -0
- package/src/pending-uploads-fs.ts +235 -0
- package/src/pending-uploads.test.ts +173 -0
- package/src/pending-uploads.ts +34 -2
- package/src/policy.test.ts +11 -5
- package/src/policy.ts +5 -5
- package/src/polls.test.ts +106 -5
- package/src/polls.ts +15 -7
- package/src/presentation.ts +68 -0
- package/src/probe.test.ts +27 -8
- package/src/probe.ts +43 -9
- package/src/reply-dispatcher.test.ts +437 -0
- package/src/reply-dispatcher.ts +259 -73
- package/src/reply-stream-controller.test.ts +235 -0
- package/src/reply-stream-controller.ts +147 -0
- package/src/resolve-allowlist.test.ts +105 -1
- package/src/resolve-allowlist.ts +112 -7
- package/src/runtime.ts +6 -3
- package/src/sdk-types.ts +43 -3
- package/src/sdk.test.ts +666 -0
- package/src/sdk.ts +867 -16
- package/src/secret-contract.ts +49 -0
- package/src/secret-input.ts +1 -1
- package/src/send-context.ts +76 -9
- package/src/send.test.ts +389 -5
- package/src/send.ts +140 -32
- package/src/sent-message-cache.ts +30 -18
- package/src/session-route.ts +40 -0
- package/src/setup-core.ts +160 -0
- package/src/setup-surface.test.ts +202 -0
- package/src/setup-surface.ts +320 -0
- package/src/sso-token-store.test.ts +72 -0
- package/src/sso-token-store.ts +166 -0
- package/src/sso.ts +300 -0
- package/src/storage.ts +1 -1
- package/src/store-fs.ts +2 -2
- package/src/streaming-message.test.ts +262 -0
- package/src/streaming-message.ts +297 -0
- package/src/test-runtime.ts +1 -1
- package/src/thread-parent-context.test.ts +224 -0
- package/src/thread-parent-context.ts +159 -0
- package/src/token.test.ts +237 -50
- package/src/token.ts +162 -7
- package/src/user-agent.test.ts +86 -0
- package/src/user-agent.ts +53 -0
- package/src/webhook-timeouts.ts +27 -0
- package/src/welcome-card.test.ts +81 -0
- package/src/welcome-card.ts +57 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
- package/CHANGELOG.md +0 -107
- package/src/file-lock.ts +0 -1
- package/src/graph-users.test.ts +0 -66
- package/src/onboarding.ts +0 -381
- package/src/polls-store.test.ts +0 -38
- package/src/revoked-context.test.ts +0 -39
- package/src/token-response.test.ts +0 -23
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { msteamsPlugin } from "./channel.js";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
editMessageMSTeamsMock,
|
|
7
|
+
deleteMessageMSTeamsMock,
|
|
8
|
+
getChannelInfoMSTeamsMock,
|
|
9
|
+
getMemberInfoMSTeamsMock,
|
|
10
|
+
getMessageMSTeamsMock,
|
|
11
|
+
listChannelsMSTeamsMock,
|
|
12
|
+
listReactionsMSTeamsMock,
|
|
13
|
+
pinMessageMSTeamsMock,
|
|
14
|
+
reactMessageMSTeamsMock,
|
|
15
|
+
searchMessagesMSTeamsMock,
|
|
16
|
+
sendAdaptiveCardMSTeamsMock,
|
|
17
|
+
sendMessageMSTeamsMock,
|
|
18
|
+
unpinMessageMSTeamsMock,
|
|
19
|
+
} = vi.hoisted(() => ({
|
|
20
|
+
editMessageMSTeamsMock: vi.fn(),
|
|
21
|
+
deleteMessageMSTeamsMock: vi.fn(),
|
|
22
|
+
getChannelInfoMSTeamsMock: vi.fn(),
|
|
23
|
+
getMemberInfoMSTeamsMock: vi.fn(),
|
|
24
|
+
getMessageMSTeamsMock: vi.fn(),
|
|
25
|
+
listChannelsMSTeamsMock: vi.fn(),
|
|
26
|
+
listReactionsMSTeamsMock: vi.fn(),
|
|
27
|
+
pinMessageMSTeamsMock: vi.fn(),
|
|
28
|
+
reactMessageMSTeamsMock: vi.fn(),
|
|
29
|
+
searchMessagesMSTeamsMock: vi.fn(),
|
|
30
|
+
sendAdaptiveCardMSTeamsMock: vi.fn(),
|
|
31
|
+
sendMessageMSTeamsMock: vi.fn(),
|
|
32
|
+
unpinMessageMSTeamsMock: vi.fn(),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
vi.mock("./channel.runtime.js", () => ({
|
|
36
|
+
msTeamsChannelRuntime: {
|
|
37
|
+
editMessageMSTeams: editMessageMSTeamsMock,
|
|
38
|
+
deleteMessageMSTeams: deleteMessageMSTeamsMock,
|
|
39
|
+
getChannelInfoMSTeams: getChannelInfoMSTeamsMock,
|
|
40
|
+
getMemberInfoMSTeams: getMemberInfoMSTeamsMock,
|
|
41
|
+
getMessageMSTeams: getMessageMSTeamsMock,
|
|
42
|
+
listChannelsMSTeams: listChannelsMSTeamsMock,
|
|
43
|
+
listReactionsMSTeams: listReactionsMSTeamsMock,
|
|
44
|
+
pinMessageMSTeams: pinMessageMSTeamsMock,
|
|
45
|
+
reactMessageMSTeams: reactMessageMSTeamsMock,
|
|
46
|
+
searchMessagesMSTeams: searchMessagesMSTeamsMock,
|
|
47
|
+
sendAdaptiveCardMSTeams: sendAdaptiveCardMSTeamsMock,
|
|
48
|
+
sendMessageMSTeams: sendMessageMSTeamsMock,
|
|
49
|
+
unpinMessageMSTeams: unpinMessageMSTeamsMock,
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
const actionMocks = [
|
|
54
|
+
editMessageMSTeamsMock,
|
|
55
|
+
deleteMessageMSTeamsMock,
|
|
56
|
+
getChannelInfoMSTeamsMock,
|
|
57
|
+
getMemberInfoMSTeamsMock,
|
|
58
|
+
getMessageMSTeamsMock,
|
|
59
|
+
listChannelsMSTeamsMock,
|
|
60
|
+
listReactionsMSTeamsMock,
|
|
61
|
+
pinMessageMSTeamsMock,
|
|
62
|
+
reactMessageMSTeamsMock,
|
|
63
|
+
searchMessagesMSTeamsMock,
|
|
64
|
+
sendAdaptiveCardMSTeamsMock,
|
|
65
|
+
sendMessageMSTeamsMock,
|
|
66
|
+
unpinMessageMSTeamsMock,
|
|
67
|
+
];
|
|
68
|
+
const currentChannelId = "conversation:19:ctx@thread.tacv2";
|
|
69
|
+
const reactChannelId = "conversation:19:react@thread.tacv2";
|
|
70
|
+
const targetChannelId = "conversation:19:target@thread.tacv2";
|
|
71
|
+
const editedConversationId = "19:edited@thread.tacv2";
|
|
72
|
+
const editedMessageId = "msg-edit-1";
|
|
73
|
+
const readMessage = { id: "msg-1", text: "hello" };
|
|
74
|
+
const reactionType = "like";
|
|
75
|
+
const updatedText = "updated text";
|
|
76
|
+
const reactionTypes = ["like", "heart", "laugh", "surprised", "sad", "angry"];
|
|
77
|
+
const deleteMissingTargetError = "Delete requires a target (to) and messageId.";
|
|
78
|
+
const reactionsMissingTargetError = "Reactions requires a target (to) and messageId.";
|
|
79
|
+
const presentationSendMissingTargetError = "Card send requires a target (to).";
|
|
80
|
+
const reactMissingEmojiError =
|
|
81
|
+
"React requires an emoji (reaction type). Valid types: like, heart, laugh, surprised, sad, angry.";
|
|
82
|
+
const reactMissingEmojiDetail = "React requires an emoji (reaction type).";
|
|
83
|
+
const searchMissingQueryError = "Search requires a target (to) and query.";
|
|
84
|
+
|
|
85
|
+
function padded(value: string) {
|
|
86
|
+
return ` ${value} `;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function msteamsActionDetails(action: string, details?: Record<string, unknown>) {
|
|
90
|
+
return {
|
|
91
|
+
channel: "msteams",
|
|
92
|
+
action,
|
|
93
|
+
...details,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function okMSTeamsActionDetails(action: string, details?: Record<string, unknown>) {
|
|
98
|
+
return msteamsActionDetails(action, { ok: true, ...details });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function requireMSTeamsHandleAction() {
|
|
102
|
+
const handleAction = msteamsPlugin.actions?.handleAction;
|
|
103
|
+
if (!handleAction) {
|
|
104
|
+
throw new Error("msteams actions.handleAction unavailable");
|
|
105
|
+
}
|
|
106
|
+
return handleAction;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function runAction(params: {
|
|
110
|
+
action: string;
|
|
111
|
+
cfg?: Record<string, unknown>;
|
|
112
|
+
params?: Record<string, unknown>;
|
|
113
|
+
toolContext?: Record<string, unknown>;
|
|
114
|
+
mediaLocalRoots?: readonly string[];
|
|
115
|
+
mediaReadFile?: (filePath: string) => Promise<Buffer>;
|
|
116
|
+
}) {
|
|
117
|
+
const handleAction = requireMSTeamsHandleAction();
|
|
118
|
+
return await handleAction({
|
|
119
|
+
channel: "msteams",
|
|
120
|
+
action: params.action,
|
|
121
|
+
cfg: params.cfg ?? {},
|
|
122
|
+
params: params.params ?? {},
|
|
123
|
+
mediaLocalRoots: params.mediaLocalRoots,
|
|
124
|
+
mediaReadFile: params.mediaReadFile,
|
|
125
|
+
toolContext: params.toolContext,
|
|
126
|
+
} as Parameters<ReturnType<typeof requireMSTeamsHandleAction>>[0]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function expectActionError(
|
|
130
|
+
params: Parameters<typeof runAction>[0],
|
|
131
|
+
expectedMessage: string,
|
|
132
|
+
expectedDetails?: Record<string, unknown>,
|
|
133
|
+
) {
|
|
134
|
+
await expect(runAction(params)).resolves.toEqual({
|
|
135
|
+
isError: true,
|
|
136
|
+
content: [{ type: "text", text: expectedMessage }],
|
|
137
|
+
details: expectedDetails ?? { error: expectedMessage },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function expectActionParamError(
|
|
142
|
+
action: Parameters<typeof runAction>[0]["action"],
|
|
143
|
+
params: Record<string, unknown>,
|
|
144
|
+
expectedMessage: string,
|
|
145
|
+
expectedDetails?: Record<string, unknown>,
|
|
146
|
+
) {
|
|
147
|
+
await expectActionError({ action, params }, expectedMessage, expectedDetails);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function expectActionSuccess(
|
|
151
|
+
result: Awaited<ReturnType<typeof runAction>>,
|
|
152
|
+
details: Record<string, unknown>,
|
|
153
|
+
contentDetails: Record<string, unknown> = details,
|
|
154
|
+
) {
|
|
155
|
+
expect(result).toEqual({
|
|
156
|
+
content: [
|
|
157
|
+
{
|
|
158
|
+
type: "text",
|
|
159
|
+
text: JSON.stringify(contentDetails),
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
details,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function expectActionRuntimeCall(
|
|
167
|
+
mockFn: ReturnType<typeof vi.fn>,
|
|
168
|
+
params: Record<string, unknown>,
|
|
169
|
+
) {
|
|
170
|
+
expect(mockFn).toHaveBeenCalledWith({
|
|
171
|
+
cfg: {},
|
|
172
|
+
...params,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function expectSuccessfulAction(params: {
|
|
177
|
+
mockFn: ReturnType<typeof vi.fn>;
|
|
178
|
+
mockResult: unknown;
|
|
179
|
+
action: Parameters<typeof runAction>[0]["action"];
|
|
180
|
+
actionParams?: Parameters<typeof runAction>[0]["params"];
|
|
181
|
+
toolContext?: Parameters<typeof runAction>[0]["toolContext"];
|
|
182
|
+
mediaLocalRoots?: Parameters<typeof runAction>[0]["mediaLocalRoots"];
|
|
183
|
+
mediaReadFile?: Parameters<typeof runAction>[0]["mediaReadFile"];
|
|
184
|
+
runtimeParams: Record<string, unknown>;
|
|
185
|
+
details: Record<string, unknown>;
|
|
186
|
+
contentDetails?: Record<string, unknown>;
|
|
187
|
+
}) {
|
|
188
|
+
params.mockFn.mockResolvedValue(params.mockResult);
|
|
189
|
+
const result = await runAction({
|
|
190
|
+
action: params.action,
|
|
191
|
+
params: params.actionParams,
|
|
192
|
+
mediaLocalRoots: params.mediaLocalRoots,
|
|
193
|
+
mediaReadFile: params.mediaReadFile,
|
|
194
|
+
toolContext: params.toolContext,
|
|
195
|
+
});
|
|
196
|
+
expectActionRuntimeCall(params.mockFn, params.runtimeParams);
|
|
197
|
+
expectActionSuccess(result, params.details, params.contentDetails);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
describe("msteamsPlugin message actions", () => {
|
|
201
|
+
beforeEach(() => {
|
|
202
|
+
for (const mockFn of actionMocks) {
|
|
203
|
+
mockFn.mockReset();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("falls back to toolContext.currentChannelId for read actions", async () => {
|
|
208
|
+
await expectSuccessfulAction({
|
|
209
|
+
mockFn: getMessageMSTeamsMock,
|
|
210
|
+
mockResult: readMessage,
|
|
211
|
+
action: "read",
|
|
212
|
+
actionParams: {
|
|
213
|
+
messageId: padded("msg-1"),
|
|
214
|
+
},
|
|
215
|
+
toolContext: {
|
|
216
|
+
currentChannelId: padded(currentChannelId),
|
|
217
|
+
},
|
|
218
|
+
runtimeParams: {
|
|
219
|
+
to: currentChannelId,
|
|
220
|
+
messageId: "msg-1",
|
|
221
|
+
},
|
|
222
|
+
details: okMSTeamsActionDetails("read", {
|
|
223
|
+
message: readMessage,
|
|
224
|
+
}),
|
|
225
|
+
contentDetails: {
|
|
226
|
+
ok: true,
|
|
227
|
+
channel: "msteams",
|
|
228
|
+
action: "read",
|
|
229
|
+
message: readMessage,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("advertises upload-file in the message tool surface", () => {
|
|
235
|
+
expect(
|
|
236
|
+
msteamsPlugin.actions?.describeMessageTool?.({
|
|
237
|
+
cfg: {
|
|
238
|
+
channels: {
|
|
239
|
+
msteams: {
|
|
240
|
+
appId: "app-id",
|
|
241
|
+
appPassword: "secret",
|
|
242
|
+
tenantId: "tenant-id",
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
} as OpenClawConfig,
|
|
246
|
+
})?.actions,
|
|
247
|
+
).toContain("upload-file");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("routes upload-file through sendMessageMSTeams with filename override", async () => {
|
|
251
|
+
const mediaReadFile = vi.fn(async () => Buffer.from("pdf"));
|
|
252
|
+
await expectSuccessfulAction({
|
|
253
|
+
mockFn: sendMessageMSTeamsMock,
|
|
254
|
+
mockResult: {
|
|
255
|
+
messageId: "msg-upload-1",
|
|
256
|
+
conversationId: "conv-upload-1",
|
|
257
|
+
},
|
|
258
|
+
action: "upload-file",
|
|
259
|
+
actionParams: {
|
|
260
|
+
target: padded(targetChannelId),
|
|
261
|
+
path: " /tmp/report.pdf ",
|
|
262
|
+
message: "Quarterly report",
|
|
263
|
+
filename: "Q1-report.pdf",
|
|
264
|
+
},
|
|
265
|
+
mediaLocalRoots: ["/tmp"],
|
|
266
|
+
mediaReadFile,
|
|
267
|
+
runtimeParams: {
|
|
268
|
+
to: targetChannelId,
|
|
269
|
+
text: "Quarterly report",
|
|
270
|
+
mediaUrl: " /tmp/report.pdf ",
|
|
271
|
+
filename: "Q1-report.pdf",
|
|
272
|
+
mediaLocalRoots: ["/tmp"],
|
|
273
|
+
mediaReadFile,
|
|
274
|
+
},
|
|
275
|
+
details: {
|
|
276
|
+
ok: true,
|
|
277
|
+
channel: "msteams",
|
|
278
|
+
messageId: "msg-upload-1",
|
|
279
|
+
},
|
|
280
|
+
contentDetails: {
|
|
281
|
+
ok: true,
|
|
282
|
+
channel: "msteams",
|
|
283
|
+
action: "upload-file",
|
|
284
|
+
messageId: "msg-upload-1",
|
|
285
|
+
conversationId: "conv-upload-1",
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("routes member-info through the Teams runtime", async () => {
|
|
291
|
+
await expectSuccessfulAction({
|
|
292
|
+
mockFn: getMemberInfoMSTeamsMock,
|
|
293
|
+
mockResult: { member: { id: "user-1" } },
|
|
294
|
+
action: "member-info",
|
|
295
|
+
actionParams: { userId: " user-1 " },
|
|
296
|
+
runtimeParams: { userId: "user-1" },
|
|
297
|
+
details: okMSTeamsActionDetails("member-info", {
|
|
298
|
+
member: { id: "user-1" },
|
|
299
|
+
}),
|
|
300
|
+
contentDetails: {
|
|
301
|
+
ok: true,
|
|
302
|
+
channel: "msteams",
|
|
303
|
+
action: "member-info",
|
|
304
|
+
member: { id: "user-1" },
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("routes channel-list through the Teams runtime", async () => {
|
|
310
|
+
await expectSuccessfulAction({
|
|
311
|
+
mockFn: listChannelsMSTeamsMock,
|
|
312
|
+
mockResult: { channels: [{ id: "channel-1" }] },
|
|
313
|
+
action: "channel-list",
|
|
314
|
+
actionParams: { teamId: " team-1 " },
|
|
315
|
+
runtimeParams: { teamId: "team-1" },
|
|
316
|
+
details: okMSTeamsActionDetails("channel-list", {
|
|
317
|
+
channels: [{ id: "channel-1" }],
|
|
318
|
+
}),
|
|
319
|
+
contentDetails: {
|
|
320
|
+
ok: true,
|
|
321
|
+
channel: "msteams",
|
|
322
|
+
action: "channel-list",
|
|
323
|
+
channels: [{ id: "channel-1" }],
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("routes channel-info through the Teams runtime", async () => {
|
|
329
|
+
await expectSuccessfulAction({
|
|
330
|
+
mockFn: getChannelInfoMSTeamsMock,
|
|
331
|
+
mockResult: { channel: { id: "channel-1" } },
|
|
332
|
+
action: "channel-info",
|
|
333
|
+
actionParams: {
|
|
334
|
+
teamId: " team-1 ",
|
|
335
|
+
channelId: " channel-1 ",
|
|
336
|
+
},
|
|
337
|
+
runtimeParams: {
|
|
338
|
+
teamId: "team-1",
|
|
339
|
+
channelId: "channel-1",
|
|
340
|
+
},
|
|
341
|
+
details: okMSTeamsActionDetails("channel-info", {
|
|
342
|
+
channelInfo: { id: "channel-1" },
|
|
343
|
+
}),
|
|
344
|
+
contentDetails: {
|
|
345
|
+
ok: true,
|
|
346
|
+
channel: "msteams",
|
|
347
|
+
action: "channel-info",
|
|
348
|
+
channelInfo: { id: "channel-1" },
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("accepts target as an alias for pin actions", async () => {
|
|
354
|
+
await expectSuccessfulAction({
|
|
355
|
+
mockFn: pinMessageMSTeamsMock,
|
|
356
|
+
mockResult: { ok: true, pinnedMessageId: "pin-1" },
|
|
357
|
+
action: "pin",
|
|
358
|
+
actionParams: {
|
|
359
|
+
target: padded(targetChannelId),
|
|
360
|
+
messageId: padded("msg-2"),
|
|
361
|
+
},
|
|
362
|
+
runtimeParams: {
|
|
363
|
+
to: targetChannelId,
|
|
364
|
+
messageId: "msg-2",
|
|
365
|
+
},
|
|
366
|
+
details: okMSTeamsActionDetails("pin", {
|
|
367
|
+
pinnedMessageId: "pin-1",
|
|
368
|
+
}),
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("falls back from content to message fields for edit actions", async () => {
|
|
373
|
+
await expectSuccessfulAction({
|
|
374
|
+
mockFn: editMessageMSTeamsMock,
|
|
375
|
+
mockResult: { conversationId: editedConversationId },
|
|
376
|
+
action: "edit",
|
|
377
|
+
actionParams: {
|
|
378
|
+
to: targetChannelId,
|
|
379
|
+
messageId: editedMessageId,
|
|
380
|
+
content: updatedText,
|
|
381
|
+
},
|
|
382
|
+
runtimeParams: {
|
|
383
|
+
to: targetChannelId,
|
|
384
|
+
activityId: editedMessageId,
|
|
385
|
+
text: updatedText,
|
|
386
|
+
},
|
|
387
|
+
details: {
|
|
388
|
+
ok: true,
|
|
389
|
+
channel: "msteams",
|
|
390
|
+
},
|
|
391
|
+
contentDetails: {
|
|
392
|
+
ok: true,
|
|
393
|
+
channel: "msteams",
|
|
394
|
+
conversationId: editedConversationId,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("falls back from pinnedMessageId to messageId for unpin actions", async () => {
|
|
400
|
+
await expectSuccessfulAction({
|
|
401
|
+
mockFn: unpinMessageMSTeamsMock,
|
|
402
|
+
mockResult: { ok: true },
|
|
403
|
+
action: "unpin",
|
|
404
|
+
actionParams: {
|
|
405
|
+
target: padded(targetChannelId),
|
|
406
|
+
messageId: padded("pin-2"),
|
|
407
|
+
},
|
|
408
|
+
runtimeParams: {
|
|
409
|
+
to: targetChannelId,
|
|
410
|
+
pinnedMessageId: "pin-2",
|
|
411
|
+
},
|
|
412
|
+
details: okMSTeamsActionDetails("unpin"),
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("uses explicit pinnedMessageId over messageId for unpin actions", async () => {
|
|
417
|
+
await expectSuccessfulAction({
|
|
418
|
+
mockFn: unpinMessageMSTeamsMock,
|
|
419
|
+
mockResult: { ok: true },
|
|
420
|
+
action: "unpin",
|
|
421
|
+
actionParams: {
|
|
422
|
+
target: padded(targetChannelId),
|
|
423
|
+
pinnedMessageId: padded("pinned-resource-99"),
|
|
424
|
+
messageId: padded("msg-99"),
|
|
425
|
+
},
|
|
426
|
+
runtimeParams: {
|
|
427
|
+
to: targetChannelId,
|
|
428
|
+
pinnedMessageId: "pinned-resource-99",
|
|
429
|
+
},
|
|
430
|
+
details: okMSTeamsActionDetails("unpin"),
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("returns an error when unpin is called without pinnedMessageId or messageId", async () => {
|
|
435
|
+
await expectActionParamError(
|
|
436
|
+
"unpin",
|
|
437
|
+
{ target: targetChannelId },
|
|
438
|
+
"Unpin requires a target (to) and pinnedMessageId.",
|
|
439
|
+
);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
it("exposes pinnedMessageId in the tool schema", () => {
|
|
443
|
+
const discovery = msteamsPlugin.actions?.describeMessageTool?.({
|
|
444
|
+
cfg: {
|
|
445
|
+
channels: {
|
|
446
|
+
msteams: {
|
|
447
|
+
appId: "app-id",
|
|
448
|
+
appPassword: "secret",
|
|
449
|
+
tenantId: "tenant-id",
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
} as OpenClawConfig,
|
|
453
|
+
});
|
|
454
|
+
const schema = discovery?.schema;
|
|
455
|
+
expect(schema).toBeTruthy();
|
|
456
|
+
const properties = Array.isArray(schema)
|
|
457
|
+
? schema[0]?.properties
|
|
458
|
+
: (schema as { properties: Record<string, unknown> })?.properties;
|
|
459
|
+
expect(properties).toHaveProperty("pinnedMessageId");
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("reuses currentChannelId fallback for react actions", async () => {
|
|
463
|
+
await expectSuccessfulAction({
|
|
464
|
+
mockFn: reactMessageMSTeamsMock,
|
|
465
|
+
mockResult: { ok: true },
|
|
466
|
+
action: "react",
|
|
467
|
+
actionParams: {
|
|
468
|
+
messageId: padded("msg-3"),
|
|
469
|
+
emoji: padded(reactionType),
|
|
470
|
+
},
|
|
471
|
+
toolContext: {
|
|
472
|
+
currentChannelId: padded(reactChannelId),
|
|
473
|
+
},
|
|
474
|
+
runtimeParams: {
|
|
475
|
+
to: reactChannelId,
|
|
476
|
+
messageId: "msg-3",
|
|
477
|
+
reactionType,
|
|
478
|
+
},
|
|
479
|
+
details: okMSTeamsActionDetails("react", {
|
|
480
|
+
reactionType,
|
|
481
|
+
}),
|
|
482
|
+
contentDetails: {
|
|
483
|
+
channel: "msteams",
|
|
484
|
+
action: "react",
|
|
485
|
+
reactionType,
|
|
486
|
+
ok: true,
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("shares the missing target and messageId validation across actions", async () => {
|
|
492
|
+
await expectActionParamError("delete", {}, deleteMissingTargetError);
|
|
493
|
+
|
|
494
|
+
await expectActionParamError("reactions", { to: targetChannelId }, reactionsMissingTargetError);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it("keeps presentation-card target validation shared", async () => {
|
|
498
|
+
await expectActionParamError(
|
|
499
|
+
"send",
|
|
500
|
+
{ presentation: { blocks: [{ type: "text", text: "hello" }] } },
|
|
501
|
+
presentationSendMissingTargetError,
|
|
502
|
+
);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("preserves message text when sending presentation cards", async () => {
|
|
506
|
+
await expectSuccessfulAction({
|
|
507
|
+
mockFn: sendAdaptiveCardMSTeamsMock,
|
|
508
|
+
mockResult: {
|
|
509
|
+
messageId: "msg-card-1",
|
|
510
|
+
conversationId: "conv-card-1",
|
|
511
|
+
},
|
|
512
|
+
action: "send",
|
|
513
|
+
actionParams: {
|
|
514
|
+
to: targetChannelId,
|
|
515
|
+
message: "Deploy finished",
|
|
516
|
+
presentation: {
|
|
517
|
+
blocks: [
|
|
518
|
+
{
|
|
519
|
+
type: "buttons",
|
|
520
|
+
buttons: [{ label: "Open", value: "open" }],
|
|
521
|
+
},
|
|
522
|
+
],
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
runtimeParams: {
|
|
526
|
+
to: targetChannelId,
|
|
527
|
+
card: {
|
|
528
|
+
type: "AdaptiveCard",
|
|
529
|
+
version: "1.4",
|
|
530
|
+
body: [{ type: "TextBlock", text: "Deploy finished", wrap: true }],
|
|
531
|
+
actions: [
|
|
532
|
+
{ type: "Action.Submit", title: "Open", data: { value: "open", label: "Open" } },
|
|
533
|
+
],
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
details: {
|
|
537
|
+
ok: true,
|
|
538
|
+
channel: "msteams",
|
|
539
|
+
messageId: "msg-card-1",
|
|
540
|
+
},
|
|
541
|
+
contentDetails: {
|
|
542
|
+
ok: true,
|
|
543
|
+
channel: "msteams",
|
|
544
|
+
messageId: "msg-card-1",
|
|
545
|
+
conversationId: "conv-card-1",
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("reports the allowed reaction types when emoji is missing", async () => {
|
|
551
|
+
await expectActionParamError(
|
|
552
|
+
"react",
|
|
553
|
+
{
|
|
554
|
+
to: targetChannelId,
|
|
555
|
+
messageId: "msg-4",
|
|
556
|
+
},
|
|
557
|
+
reactMissingEmojiError,
|
|
558
|
+
{
|
|
559
|
+
error: reactMissingEmojiDetail,
|
|
560
|
+
validTypes: reactionTypes,
|
|
561
|
+
},
|
|
562
|
+
);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("requires a non-empty search query after trimming", async () => {
|
|
566
|
+
await expectActionParamError(
|
|
567
|
+
"search",
|
|
568
|
+
{
|
|
569
|
+
to: targetChannelId,
|
|
570
|
+
query: " ",
|
|
571
|
+
},
|
|
572
|
+
searchMissingQueryError,
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it("routes channel fallback targets via teamId/channelId for react actions", async () => {
|
|
577
|
+
// When an action is invoked in a Teams channel context and `target` is
|
|
578
|
+
// omitted, the action handler falls back to `toolContext.currentChannelId`.
|
|
579
|
+
// For channel turns, buildToolContext populates that field with the
|
|
580
|
+
// compound `teamId/channelId` form (see buildToolContext below), so the
|
|
581
|
+
// runtime call must receive that compound form — NOT a bare
|
|
582
|
+
// `conversation:<id>` — so Graph API routes through
|
|
583
|
+
// `/teams/{teamId}/channels/{channelId}` rather than `/chats/{id}`.
|
|
584
|
+
const teamChannelTarget = "team-1/19:channel-abc@thread.tacv2";
|
|
585
|
+
await expectSuccessfulAction({
|
|
586
|
+
mockFn: reactMessageMSTeamsMock,
|
|
587
|
+
mockResult: { ok: true },
|
|
588
|
+
action: "react",
|
|
589
|
+
actionParams: {
|
|
590
|
+
messageId: "msg-channel-react",
|
|
591
|
+
emoji: reactionType,
|
|
592
|
+
},
|
|
593
|
+
toolContext: {
|
|
594
|
+
currentChannelId: "conversation:19:channel-abc@thread.tacv2",
|
|
595
|
+
currentGraphChannelId: teamChannelTarget,
|
|
596
|
+
},
|
|
597
|
+
runtimeParams: {
|
|
598
|
+
to: teamChannelTarget,
|
|
599
|
+
messageId: "msg-channel-react",
|
|
600
|
+
reactionType,
|
|
601
|
+
},
|
|
602
|
+
details: okMSTeamsActionDetails("react", {
|
|
603
|
+
reactionType,
|
|
604
|
+
}),
|
|
605
|
+
contentDetails: {
|
|
606
|
+
channel: "msteams",
|
|
607
|
+
action: "react",
|
|
608
|
+
reactionType,
|
|
609
|
+
ok: true,
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("preserves explicit teamId/channelId target over toolContext fallback", async () => {
|
|
615
|
+
// Even in a channel context with a compound currentChannelId, an
|
|
616
|
+
// explicit `target` param must take precedence.
|
|
617
|
+
const teamChannelTarget = "team-2/19:channel-def@thread.tacv2";
|
|
618
|
+
const explicitTarget = "team-explicit/19:other@thread.tacv2";
|
|
619
|
+
await expectSuccessfulAction({
|
|
620
|
+
mockFn: reactMessageMSTeamsMock,
|
|
621
|
+
mockResult: { ok: true },
|
|
622
|
+
action: "react",
|
|
623
|
+
actionParams: {
|
|
624
|
+
target: explicitTarget,
|
|
625
|
+
messageId: "msg-explicit",
|
|
626
|
+
emoji: reactionType,
|
|
627
|
+
},
|
|
628
|
+
toolContext: {
|
|
629
|
+
currentChannelId: teamChannelTarget,
|
|
630
|
+
currentGraphChannelId: teamChannelTarget,
|
|
631
|
+
},
|
|
632
|
+
runtimeParams: {
|
|
633
|
+
to: explicitTarget,
|
|
634
|
+
messageId: "msg-explicit",
|
|
635
|
+
reactionType,
|
|
636
|
+
},
|
|
637
|
+
details: okMSTeamsActionDetails("react", {
|
|
638
|
+
reactionType,
|
|
639
|
+
}),
|
|
640
|
+
contentDetails: {
|
|
641
|
+
channel: "msteams",
|
|
642
|
+
action: "react",
|
|
643
|
+
reactionType,
|
|
644
|
+
ok: true,
|
|
645
|
+
},
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it("keeps chat conversation fallback targets as-is for DM react actions", async () => {
|
|
650
|
+
// DM/group-chat turns continue to set currentChannelId to a
|
|
651
|
+
// `conversation:<id>` string (no `teamId/` prefix), which the runtime
|
|
652
|
+
// will resolve through `/chats/{id}`.
|
|
653
|
+
const dmFallback = "conversation:19:chat-dm@thread.skype";
|
|
654
|
+
await expectSuccessfulAction({
|
|
655
|
+
mockFn: reactMessageMSTeamsMock,
|
|
656
|
+
mockResult: { ok: true },
|
|
657
|
+
action: "react",
|
|
658
|
+
actionParams: {
|
|
659
|
+
messageId: "msg-dm-react",
|
|
660
|
+
emoji: reactionType,
|
|
661
|
+
},
|
|
662
|
+
toolContext: {
|
|
663
|
+
currentChannelId: dmFallback,
|
|
664
|
+
},
|
|
665
|
+
runtimeParams: {
|
|
666
|
+
to: dmFallback,
|
|
667
|
+
messageId: "msg-dm-react",
|
|
668
|
+
reactionType,
|
|
669
|
+
},
|
|
670
|
+
details: okMSTeamsActionDetails("react", {
|
|
671
|
+
reactionType,
|
|
672
|
+
}),
|
|
673
|
+
contentDetails: {
|
|
674
|
+
channel: "msteams",
|
|
675
|
+
action: "react",
|
|
676
|
+
reactionType,
|
|
677
|
+
ok: true,
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
describe("msteamsPlugin.threading.buildToolContext", () => {
|
|
684
|
+
function callBuildToolContext(context: {
|
|
685
|
+
To?: string;
|
|
686
|
+
NativeChannelId?: string;
|
|
687
|
+
ReplyToId?: string;
|
|
688
|
+
}) {
|
|
689
|
+
const build = msteamsPlugin.threading?.buildToolContext;
|
|
690
|
+
if (!build) {
|
|
691
|
+
throw new Error("msteams threading.buildToolContext unavailable");
|
|
692
|
+
}
|
|
693
|
+
return build({
|
|
694
|
+
cfg: {} as OpenClawConfig,
|
|
695
|
+
accountId: undefined,
|
|
696
|
+
context,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
it("uses NativeChannelId for channel turns so actions route via teamId/channelId", () => {
|
|
701
|
+
// Teams channel inbound messages carry the compound `teamId/channelId`
|
|
702
|
+
// on NativeChannelId. buildToolContext must prefer it over the bare
|
|
703
|
+
// `conversation:<id>` in To so action fallbacks route via
|
|
704
|
+
// `/teams/{teamId}/channels/{channelId}`.
|
|
705
|
+
const result = callBuildToolContext({
|
|
706
|
+
To: "conversation:19:channel-abc@thread.tacv2",
|
|
707
|
+
NativeChannelId: "team-1/19:channel-abc@thread.tacv2",
|
|
708
|
+
ReplyToId: "reply-1",
|
|
709
|
+
});
|
|
710
|
+
expect(result?.currentChannelId).toBe("conversation:19:channel-abc@thread.tacv2");
|
|
711
|
+
expect(result?.currentGraphChannelId).toBe("team-1/19:channel-abc@thread.tacv2");
|
|
712
|
+
expect(result?.currentThreadTs).toBe("reply-1");
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it("falls back to To for DM turns (no NativeChannelId)", () => {
|
|
716
|
+
const result = callBuildToolContext({
|
|
717
|
+
To: "user:aad-user-1",
|
|
718
|
+
});
|
|
719
|
+
expect(result?.currentChannelId).toBe("user:aad-user-1");
|
|
720
|
+
expect(result?.currentGraphChannelId).toBeUndefined();
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("falls back to To for group chat turns (no NativeChannelId)", () => {
|
|
724
|
+
const result = callBuildToolContext({
|
|
725
|
+
To: "conversation:19:groupchat@thread.v2",
|
|
726
|
+
});
|
|
727
|
+
expect(result?.currentChannelId).toBe("conversation:19:groupchat@thread.v2");
|
|
728
|
+
expect(result?.currentGraphChannelId).toBeUndefined();
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("ignores NativeChannelId that does not encode a teamId/channelId pair", () => {
|
|
732
|
+
// Safety: only compound forms (with "/") should preempt the To fallback.
|
|
733
|
+
// A bare native id without a team prefix must not accidentally route
|
|
734
|
+
// through channel Graph paths.
|
|
735
|
+
const result = callBuildToolContext({
|
|
736
|
+
To: "conversation:19:chat@thread.v2",
|
|
737
|
+
NativeChannelId: "19:chat@thread.v2",
|
|
738
|
+
});
|
|
739
|
+
expect(result?.currentChannelId).toBe("conversation:19:chat@thread.v2");
|
|
740
|
+
expect(result?.currentGraphChannelId).toBeUndefined();
|
|
741
|
+
});
|
|
742
|
+
});
|