@openclaw/msteams 2026.5.2-beta.2 → 2026.5.3-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.
Files changed (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,742 +0,0 @@
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
- });