@openclaw/msteams 2026.1.29
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/CHANGELOG.md +56 -0
- package/index.ts +18 -0
- package/openclaw.plugin.json +11 -0
- package/package.json +36 -0
- package/src/attachments/download.ts +206 -0
- package/src/attachments/graph.ts +319 -0
- package/src/attachments/html.ts +76 -0
- package/src/attachments/payload.ts +22 -0
- package/src/attachments/shared.ts +235 -0
- package/src/attachments/types.ts +37 -0
- package/src/attachments.test.ts +424 -0
- package/src/attachments.ts +18 -0
- package/src/channel.directory.test.ts +46 -0
- package/src/channel.ts +436 -0
- package/src/conversation-store-fs.test.ts +89 -0
- package/src/conversation-store-fs.ts +155 -0
- package/src/conversation-store-memory.ts +45 -0
- package/src/conversation-store.ts +41 -0
- package/src/directory-live.ts +179 -0
- package/src/errors.test.ts +46 -0
- package/src/errors.ts +158 -0
- package/src/file-consent-helpers.test.ts +234 -0
- package/src/file-consent-helpers.ts +73 -0
- package/src/file-consent.ts +122 -0
- package/src/graph-chat.ts +52 -0
- package/src/graph-upload.ts +445 -0
- package/src/inbound.test.ts +67 -0
- package/src/inbound.ts +38 -0
- package/src/index.ts +4 -0
- package/src/media-helpers.test.ts +186 -0
- package/src/media-helpers.ts +77 -0
- package/src/messenger.test.ts +245 -0
- package/src/messenger.ts +460 -0
- package/src/monitor-handler/inbound-media.ts +123 -0
- package/src/monitor-handler/message-handler.ts +629 -0
- package/src/monitor-handler.ts +166 -0
- package/src/monitor-types.ts +5 -0
- package/src/monitor.ts +290 -0
- package/src/onboarding.ts +432 -0
- package/src/outbound.ts +47 -0
- package/src/pending-uploads.ts +87 -0
- package/src/policy.test.ts +210 -0
- package/src/policy.ts +247 -0
- package/src/polls-store-memory.ts +30 -0
- package/src/polls-store.test.ts +40 -0
- package/src/polls.test.ts +73 -0
- package/src/polls.ts +300 -0
- package/src/probe.test.ts +57 -0
- package/src/probe.ts +99 -0
- package/src/reply-dispatcher.ts +128 -0
- package/src/resolve-allowlist.ts +277 -0
- package/src/runtime.ts +14 -0
- package/src/sdk-types.ts +19 -0
- package/src/sdk.ts +33 -0
- package/src/send-context.ts +156 -0
- package/src/send.ts +489 -0
- package/src/sent-message-cache.test.ts +16 -0
- package/src/sent-message-cache.ts +41 -0
- package/src/storage.ts +22 -0
- package/src/store-fs.ts +80 -0
- package/src/token.ts +19 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type { PluginRuntime } from "openclaw/plugin-sdk";
|
|
4
|
+
import { setMSTeamsRuntime } from "./runtime.js";
|
|
5
|
+
|
|
6
|
+
const detectMimeMock = vi.fn(async () => "image/png");
|
|
7
|
+
const saveMediaBufferMock = vi.fn(async () => ({
|
|
8
|
+
path: "/tmp/saved.png",
|
|
9
|
+
contentType: "image/png",
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const runtimeStub = {
|
|
13
|
+
media: {
|
|
14
|
+
detectMime: (...args: unknown[]) => detectMimeMock(...args),
|
|
15
|
+
},
|
|
16
|
+
channel: {
|
|
17
|
+
media: {
|
|
18
|
+
saveMediaBuffer: (...args: unknown[]) => saveMediaBufferMock(...args),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
} as unknown as PluginRuntime;
|
|
22
|
+
|
|
23
|
+
describe("msteams attachments", () => {
|
|
24
|
+
const load = async () => {
|
|
25
|
+
return await import("./attachments.js");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
detectMimeMock.mockClear();
|
|
30
|
+
saveMediaBufferMock.mockClear();
|
|
31
|
+
setMSTeamsRuntime(runtimeStub);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("buildMSTeamsAttachmentPlaceholder", () => {
|
|
35
|
+
it("returns empty string when no attachments", async () => {
|
|
36
|
+
const { buildMSTeamsAttachmentPlaceholder } = await load();
|
|
37
|
+
expect(buildMSTeamsAttachmentPlaceholder(undefined)).toBe("");
|
|
38
|
+
expect(buildMSTeamsAttachmentPlaceholder([])).toBe("");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns image placeholder for image attachments", async () => {
|
|
42
|
+
const { buildMSTeamsAttachmentPlaceholder } = await load();
|
|
43
|
+
expect(
|
|
44
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
45
|
+
{ contentType: "image/png", contentUrl: "https://x/img.png" },
|
|
46
|
+
]),
|
|
47
|
+
).toBe("<media:image>");
|
|
48
|
+
expect(
|
|
49
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
50
|
+
{ contentType: "image/png", contentUrl: "https://x/1.png" },
|
|
51
|
+
{ contentType: "image/jpeg", contentUrl: "https://x/2.jpg" },
|
|
52
|
+
]),
|
|
53
|
+
).toBe("<media:image> (2 images)");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("treats Teams file.download.info image attachments as images", async () => {
|
|
57
|
+
const { buildMSTeamsAttachmentPlaceholder } = await load();
|
|
58
|
+
expect(
|
|
59
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
60
|
+
{
|
|
61
|
+
contentType: "application/vnd.microsoft.teams.file.download.info",
|
|
62
|
+
content: { downloadUrl: "https://x/dl", fileType: "png" },
|
|
63
|
+
},
|
|
64
|
+
]),
|
|
65
|
+
).toBe("<media:image>");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("returns document placeholder for non-image attachments", async () => {
|
|
69
|
+
const { buildMSTeamsAttachmentPlaceholder } = await load();
|
|
70
|
+
expect(
|
|
71
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
72
|
+
{ contentType: "application/pdf", contentUrl: "https://x/x.pdf" },
|
|
73
|
+
]),
|
|
74
|
+
).toBe("<media:document>");
|
|
75
|
+
expect(
|
|
76
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
77
|
+
{ contentType: "application/pdf", contentUrl: "https://x/1.pdf" },
|
|
78
|
+
{ contentType: "application/pdf", contentUrl: "https://x/2.pdf" },
|
|
79
|
+
]),
|
|
80
|
+
).toBe("<media:document> (2 files)");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("counts inline images in text/html attachments", async () => {
|
|
84
|
+
const { buildMSTeamsAttachmentPlaceholder } = await load();
|
|
85
|
+
expect(
|
|
86
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
87
|
+
{
|
|
88
|
+
contentType: "text/html",
|
|
89
|
+
content: '<p>hi</p><img src="https://x/a.png" />',
|
|
90
|
+
},
|
|
91
|
+
]),
|
|
92
|
+
).toBe("<media:image>");
|
|
93
|
+
expect(
|
|
94
|
+
buildMSTeamsAttachmentPlaceholder([
|
|
95
|
+
{
|
|
96
|
+
contentType: "text/html",
|
|
97
|
+
content: '<img src="https://x/a.png" /><img src="https://x/b.png" />',
|
|
98
|
+
},
|
|
99
|
+
]),
|
|
100
|
+
).toBe("<media:image> (2 images)");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("downloadMSTeamsAttachments", () => {
|
|
105
|
+
it("downloads and stores image contentUrl attachments", async () => {
|
|
106
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
107
|
+
const fetchMock = vi.fn(async () => {
|
|
108
|
+
return new Response(Buffer.from("png"), {
|
|
109
|
+
status: 200,
|
|
110
|
+
headers: { "content-type": "image/png" },
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const media = await downloadMSTeamsAttachments({
|
|
115
|
+
attachments: [{ contentType: "image/png", contentUrl: "https://x/img" }],
|
|
116
|
+
maxBytes: 1024 * 1024,
|
|
117
|
+
allowHosts: ["x"],
|
|
118
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(fetchMock).toHaveBeenCalledWith("https://x/img");
|
|
122
|
+
expect(saveMediaBufferMock).toHaveBeenCalled();
|
|
123
|
+
expect(media).toHaveLength(1);
|
|
124
|
+
expect(media[0]?.path).toBe("/tmp/saved.png");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("supports Teams file.download.info downloadUrl attachments", async () => {
|
|
128
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
129
|
+
const fetchMock = vi.fn(async () => {
|
|
130
|
+
return new Response(Buffer.from("png"), {
|
|
131
|
+
status: 200,
|
|
132
|
+
headers: { "content-type": "image/png" },
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const media = await downloadMSTeamsAttachments({
|
|
137
|
+
attachments: [
|
|
138
|
+
{
|
|
139
|
+
contentType: "application/vnd.microsoft.teams.file.download.info",
|
|
140
|
+
content: { downloadUrl: "https://x/dl", fileType: "png" },
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
maxBytes: 1024 * 1024,
|
|
144
|
+
allowHosts: ["x"],
|
|
145
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(fetchMock).toHaveBeenCalledWith("https://x/dl");
|
|
149
|
+
expect(media).toHaveLength(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("downloads non-image file attachments (PDF)", async () => {
|
|
153
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
154
|
+
const fetchMock = vi.fn(async () => {
|
|
155
|
+
return new Response(Buffer.from("pdf"), {
|
|
156
|
+
status: 200,
|
|
157
|
+
headers: { "content-type": "application/pdf" },
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
detectMimeMock.mockResolvedValueOnce("application/pdf");
|
|
161
|
+
saveMediaBufferMock.mockResolvedValueOnce({
|
|
162
|
+
path: "/tmp/saved.pdf",
|
|
163
|
+
contentType: "application/pdf",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const media = await downloadMSTeamsAttachments({
|
|
167
|
+
attachments: [{ contentType: "application/pdf", contentUrl: "https://x/doc.pdf" }],
|
|
168
|
+
maxBytes: 1024 * 1024,
|
|
169
|
+
allowHosts: ["x"],
|
|
170
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(fetchMock).toHaveBeenCalledWith("https://x/doc.pdf");
|
|
174
|
+
expect(media).toHaveLength(1);
|
|
175
|
+
expect(media[0]?.path).toBe("/tmp/saved.pdf");
|
|
176
|
+
expect(media[0]?.placeholder).toBe("<media:document>");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("downloads inline image URLs from html attachments", async () => {
|
|
180
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
181
|
+
const fetchMock = vi.fn(async () => {
|
|
182
|
+
return new Response(Buffer.from("png"), {
|
|
183
|
+
status: 200,
|
|
184
|
+
headers: { "content-type": "image/png" },
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const media = await downloadMSTeamsAttachments({
|
|
189
|
+
attachments: [
|
|
190
|
+
{
|
|
191
|
+
contentType: "text/html",
|
|
192
|
+
content: '<img src="https://x/inline.png" />',
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
maxBytes: 1024 * 1024,
|
|
196
|
+
allowHosts: ["x"],
|
|
197
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
expect(media).toHaveLength(1);
|
|
201
|
+
expect(fetchMock).toHaveBeenCalledWith("https://x/inline.png");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("stores inline data:image base64 payloads", async () => {
|
|
205
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
206
|
+
const base64 = Buffer.from("png").toString("base64");
|
|
207
|
+
const media = await downloadMSTeamsAttachments({
|
|
208
|
+
attachments: [
|
|
209
|
+
{
|
|
210
|
+
contentType: "text/html",
|
|
211
|
+
content: `<img src="data:image/png;base64,${base64}" />`,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
maxBytes: 1024 * 1024,
|
|
215
|
+
allowHosts: ["x"],
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(media).toHaveLength(1);
|
|
219
|
+
expect(saveMediaBufferMock).toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("retries with auth when the first request is unauthorized", async () => {
|
|
223
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
224
|
+
const fetchMock = vi.fn(async (_url: string, opts?: RequestInit) => {
|
|
225
|
+
const hasAuth = Boolean(
|
|
226
|
+
opts &&
|
|
227
|
+
typeof opts === "object" &&
|
|
228
|
+
"headers" in opts &&
|
|
229
|
+
(opts.headers as Record<string, string>)?.Authorization,
|
|
230
|
+
);
|
|
231
|
+
if (!hasAuth) {
|
|
232
|
+
return new Response("unauthorized", { status: 401 });
|
|
233
|
+
}
|
|
234
|
+
return new Response(Buffer.from("png"), {
|
|
235
|
+
status: 200,
|
|
236
|
+
headers: { "content-type": "image/png" },
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const media = await downloadMSTeamsAttachments({
|
|
241
|
+
attachments: [{ contentType: "image/png", contentUrl: "https://x/img" }],
|
|
242
|
+
maxBytes: 1024 * 1024,
|
|
243
|
+
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
244
|
+
allowHosts: ["x"],
|
|
245
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
249
|
+
expect(media).toHaveLength(1);
|
|
250
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("skips urls outside the allowlist", async () => {
|
|
254
|
+
const { downloadMSTeamsAttachments } = await load();
|
|
255
|
+
const fetchMock = vi.fn();
|
|
256
|
+
const media = await downloadMSTeamsAttachments({
|
|
257
|
+
attachments: [{ contentType: "image/png", contentUrl: "https://evil.test/img" }],
|
|
258
|
+
maxBytes: 1024 * 1024,
|
|
259
|
+
allowHosts: ["graph.microsoft.com"],
|
|
260
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expect(media).toHaveLength(0);
|
|
264
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe("buildMSTeamsGraphMessageUrls", () => {
|
|
269
|
+
it("builds channel message urls", async () => {
|
|
270
|
+
const { buildMSTeamsGraphMessageUrls } = await load();
|
|
271
|
+
const urls = buildMSTeamsGraphMessageUrls({
|
|
272
|
+
conversationType: "channel",
|
|
273
|
+
conversationId: "19:thread@thread.tacv2",
|
|
274
|
+
messageId: "123",
|
|
275
|
+
channelData: { team: { id: "team-id" }, channel: { id: "chan-id" } },
|
|
276
|
+
});
|
|
277
|
+
expect(urls[0]).toContain("/teams/team-id/channels/chan-id/messages/123");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("builds channel reply urls when replyToId is present", async () => {
|
|
281
|
+
const { buildMSTeamsGraphMessageUrls } = await load();
|
|
282
|
+
const urls = buildMSTeamsGraphMessageUrls({
|
|
283
|
+
conversationType: "channel",
|
|
284
|
+
messageId: "reply-id",
|
|
285
|
+
replyToId: "root-id",
|
|
286
|
+
channelData: { team: { id: "team-id" }, channel: { id: "chan-id" } },
|
|
287
|
+
});
|
|
288
|
+
expect(urls[0]).toContain(
|
|
289
|
+
"/teams/team-id/channels/chan-id/messages/root-id/replies/reply-id",
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("builds chat message urls", async () => {
|
|
294
|
+
const { buildMSTeamsGraphMessageUrls } = await load();
|
|
295
|
+
const urls = buildMSTeamsGraphMessageUrls({
|
|
296
|
+
conversationType: "groupChat",
|
|
297
|
+
conversationId: "19:chat@thread.v2",
|
|
298
|
+
messageId: "456",
|
|
299
|
+
});
|
|
300
|
+
expect(urls[0]).toContain("/chats/19%3Achat%40thread.v2/messages/456");
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe("downloadMSTeamsGraphMedia", () => {
|
|
305
|
+
it("downloads hostedContents images", async () => {
|
|
306
|
+
const { downloadMSTeamsGraphMedia } = await load();
|
|
307
|
+
const base64 = Buffer.from("png").toString("base64");
|
|
308
|
+
const fetchMock = vi.fn(async (url: string) => {
|
|
309
|
+
if (url.endsWith("/hostedContents")) {
|
|
310
|
+
return new Response(
|
|
311
|
+
JSON.stringify({
|
|
312
|
+
value: [
|
|
313
|
+
{
|
|
314
|
+
id: "1",
|
|
315
|
+
contentType: "image/png",
|
|
316
|
+
contentBytes: base64,
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
}),
|
|
320
|
+
{ status: 200 },
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
if (url.endsWith("/attachments")) {
|
|
324
|
+
return new Response(JSON.stringify({ value: [] }), { status: 200 });
|
|
325
|
+
}
|
|
326
|
+
return new Response("not found", { status: 404 });
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const media = await downloadMSTeamsGraphMedia({
|
|
330
|
+
messageUrl: "https://graph.microsoft.com/v1.0/chats/19%3Achat/messages/123",
|
|
331
|
+
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
332
|
+
maxBytes: 1024 * 1024,
|
|
333
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(media.media).toHaveLength(1);
|
|
337
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
338
|
+
expect(saveMediaBufferMock).toHaveBeenCalled();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("merges SharePoint reference attachments with hosted content", async () => {
|
|
342
|
+
const { downloadMSTeamsGraphMedia } = await load();
|
|
343
|
+
const hostedBase64 = Buffer.from("png").toString("base64");
|
|
344
|
+
const shareUrl = "https://contoso.sharepoint.com/site/file";
|
|
345
|
+
const fetchMock = vi.fn(async (url: string) => {
|
|
346
|
+
if (url.endsWith("/hostedContents")) {
|
|
347
|
+
return new Response(
|
|
348
|
+
JSON.stringify({
|
|
349
|
+
value: [
|
|
350
|
+
{
|
|
351
|
+
id: "hosted-1",
|
|
352
|
+
contentType: "image/png",
|
|
353
|
+
contentBytes: hostedBase64,
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
}),
|
|
357
|
+
{ status: 200 },
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
if (url.endsWith("/attachments")) {
|
|
361
|
+
return new Response(
|
|
362
|
+
JSON.stringify({
|
|
363
|
+
value: [
|
|
364
|
+
{
|
|
365
|
+
id: "ref-1",
|
|
366
|
+
contentType: "reference",
|
|
367
|
+
contentUrl: shareUrl,
|
|
368
|
+
name: "report.pdf",
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
}),
|
|
372
|
+
{ status: 200 },
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
if (url.startsWith("https://graph.microsoft.com/v1.0/shares/")) {
|
|
376
|
+
return new Response(Buffer.from("pdf"), {
|
|
377
|
+
status: 200,
|
|
378
|
+
headers: { "content-type": "application/pdf" },
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
if (url.endsWith("/messages/123")) {
|
|
382
|
+
return new Response(
|
|
383
|
+
JSON.stringify({
|
|
384
|
+
attachments: [
|
|
385
|
+
{
|
|
386
|
+
id: "ref-1",
|
|
387
|
+
contentType: "reference",
|
|
388
|
+
contentUrl: shareUrl,
|
|
389
|
+
name: "report.pdf",
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
}),
|
|
393
|
+
{ status: 200 },
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return new Response("not found", { status: 404 });
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const media = await downloadMSTeamsGraphMedia({
|
|
400
|
+
messageUrl: "https://graph.microsoft.com/v1.0/chats/19%3Achat/messages/123",
|
|
401
|
+
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
402
|
+
maxBytes: 1024 * 1024,
|
|
403
|
+
fetchFn: fetchMock as unknown as typeof fetch,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
expect(media.media).toHaveLength(2);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
describe("buildMSTeamsMediaPayload", () => {
|
|
411
|
+
it("returns single and multi-file fields", async () => {
|
|
412
|
+
const { buildMSTeamsMediaPayload } = await load();
|
|
413
|
+
const payload = buildMSTeamsMediaPayload([
|
|
414
|
+
{ path: "/tmp/a.png", contentType: "image/png" },
|
|
415
|
+
{ path: "/tmp/b.png", contentType: "image/png" },
|
|
416
|
+
]);
|
|
417
|
+
expect(payload.MediaPath).toBe("/tmp/a.png");
|
|
418
|
+
expect(payload.MediaUrl).toBe("/tmp/a.png");
|
|
419
|
+
expect(payload.MediaPaths).toEqual(["/tmp/a.png", "/tmp/b.png"]);
|
|
420
|
+
expect(payload.MediaUrls).toEqual(["/tmp/a.png", "/tmp/b.png"]);
|
|
421
|
+
expect(payload.MediaTypes).toEqual(["image/png", "image/png"]);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
downloadMSTeamsAttachments,
|
|
3
|
+
/** @deprecated Use `downloadMSTeamsAttachments` instead. */
|
|
4
|
+
downloadMSTeamsImageAttachments,
|
|
5
|
+
} from "./attachments/download.js";
|
|
6
|
+
export { buildMSTeamsGraphMessageUrls, downloadMSTeamsGraphMedia } from "./attachments/graph.js";
|
|
7
|
+
export {
|
|
8
|
+
buildMSTeamsAttachmentPlaceholder,
|
|
9
|
+
summarizeMSTeamsHtmlAttachments,
|
|
10
|
+
} from "./attachments/html.js";
|
|
11
|
+
export { buildMSTeamsMediaPayload } from "./attachments/payload.js";
|
|
12
|
+
export type {
|
|
13
|
+
MSTeamsAccessTokenProvider,
|
|
14
|
+
MSTeamsAttachmentLike,
|
|
15
|
+
MSTeamsGraphMediaResult,
|
|
16
|
+
MSTeamsHtmlAttachmentSummary,
|
|
17
|
+
MSTeamsInboundMedia,
|
|
18
|
+
} from "./attachments/types.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
4
|
+
|
|
5
|
+
import { msteamsPlugin } from "./channel.js";
|
|
6
|
+
|
|
7
|
+
describe("msteams directory", () => {
|
|
8
|
+
it("lists peers and groups from config", async () => {
|
|
9
|
+
const cfg = {
|
|
10
|
+
channels: {
|
|
11
|
+
msteams: {
|
|
12
|
+
allowFrom: ["alice", "user:Bob"],
|
|
13
|
+
dms: { carol: {}, bob: {} },
|
|
14
|
+
teams: {
|
|
15
|
+
team1: {
|
|
16
|
+
channels: {
|
|
17
|
+
"conversation:chan1": {},
|
|
18
|
+
chan2: {},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
} as unknown as OpenClawConfig;
|
|
25
|
+
|
|
26
|
+
expect(msteamsPlugin.directory).toBeTruthy();
|
|
27
|
+
expect(msteamsPlugin.directory?.listPeers).toBeTruthy();
|
|
28
|
+
expect(msteamsPlugin.directory?.listGroups).toBeTruthy();
|
|
29
|
+
|
|
30
|
+
await expect(msteamsPlugin.directory!.listPeers({ cfg, query: undefined, limit: undefined })).resolves.toEqual(
|
|
31
|
+
expect.arrayContaining([
|
|
32
|
+
{ kind: "user", id: "user:alice" },
|
|
33
|
+
{ kind: "user", id: "user:Bob" },
|
|
34
|
+
{ kind: "user", id: "user:carol" },
|
|
35
|
+
{ kind: "user", id: "user:bob" },
|
|
36
|
+
]),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await expect(msteamsPlugin.directory!.listGroups({ cfg, query: undefined, limit: undefined })).resolves.toEqual(
|
|
40
|
+
expect.arrayContaining([
|
|
41
|
+
{ kind: "group", id: "conversation:chan1" },
|
|
42
|
+
{ kind: "group", id: "conversation:chan2" },
|
|
43
|
+
]),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
});
|