@openclaw/msteams 2026.3.12 → 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 +161 -9
- 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 +174 -437
- 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 +148 -14
- 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 +258 -0
- package/src/graph-upload.ts +87 -8
- 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 +522 -45
- 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 +477 -174
- 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 +301 -106
- 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 +34 -40
- 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 -101
- 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,289 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../attachments.js", () => ({
|
|
4
|
+
downloadMSTeamsAttachments: vi.fn(async () => []),
|
|
5
|
+
downloadMSTeamsGraphMedia: vi.fn(async () => ({ media: [] })),
|
|
6
|
+
downloadMSTeamsBotFrameworkAttachments: vi.fn(async () => ({ media: [], attachmentCount: 0 })),
|
|
7
|
+
buildMSTeamsGraphMessageUrls: vi.fn(() => [
|
|
8
|
+
"https://graph.microsoft.com/v1.0/chats/c/messages/m",
|
|
9
|
+
]),
|
|
10
|
+
extractMSTeamsHtmlAttachmentIds: vi.fn(() => ["att-0", "att-1"]),
|
|
11
|
+
isBotFrameworkPersonalChatId: vi.fn((id: string | null | undefined) => {
|
|
12
|
+
if (typeof id !== "string") {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return id.startsWith("a:") || id.startsWith("8:orgid:");
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
buildMSTeamsGraphMessageUrls,
|
|
21
|
+
downloadMSTeamsAttachments,
|
|
22
|
+
downloadMSTeamsBotFrameworkAttachments,
|
|
23
|
+
downloadMSTeamsGraphMedia,
|
|
24
|
+
extractMSTeamsHtmlAttachmentIds,
|
|
25
|
+
} from "../attachments.js";
|
|
26
|
+
import { resolveMSTeamsInboundMedia } from "./inbound-media.js";
|
|
27
|
+
|
|
28
|
+
const baseParams = {
|
|
29
|
+
maxBytes: 1024 * 1024,
|
|
30
|
+
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
31
|
+
conversationType: "personal",
|
|
32
|
+
conversationId: "19:user_bot@unq.gbl.spaces",
|
|
33
|
+
activity: { id: "msg-1", replyToId: undefined, channelData: {} },
|
|
34
|
+
log: { debug: vi.fn() },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("resolveMSTeamsInboundMedia graph fallback trigger", () => {
|
|
38
|
+
it("triggers Graph fallback when HTML contains <attachment> tags", async () => {
|
|
39
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
40
|
+
vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce(["att-0"]);
|
|
41
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({
|
|
42
|
+
media: [{ path: "/tmp/img.png", contentType: "image/png", placeholder: "[image]" }],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await resolveMSTeamsInboundMedia({
|
|
46
|
+
...baseParams,
|
|
47
|
+
attachments: [
|
|
48
|
+
{
|
|
49
|
+
contentType: "text/html",
|
|
50
|
+
content: '<div>A file <attachment id="att-0"></attachment></div>',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(buildMSTeamsGraphMessageUrls).toHaveBeenCalled();
|
|
56
|
+
expect(downloadMSTeamsGraphMedia).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does NOT trigger Graph fallback for mention-only HTML (no <attachment> tags)", async () => {
|
|
60
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
61
|
+
// Mention cards include `<at>` markers but no `<attachment id="...">`,
|
|
62
|
+
// so the extractor returns an empty ID list. The fallback must skip.
|
|
63
|
+
vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
|
|
64
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
65
|
+
vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
|
|
66
|
+
|
|
67
|
+
await resolveMSTeamsInboundMedia({
|
|
68
|
+
...baseParams,
|
|
69
|
+
attachments: [
|
|
70
|
+
{
|
|
71
|
+
contentType: "text/html",
|
|
72
|
+
content: '<div><at id="0">Bot</at> hello there</div>',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
78
|
+
expect(buildMSTeamsGraphMessageUrls).not.toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("does NOT trigger Graph fallback when no attachments are text/html", async () => {
|
|
82
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
83
|
+
// No HTML attachments at all → extractor returns [].
|
|
84
|
+
vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
|
|
85
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
86
|
+
vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
|
|
87
|
+
|
|
88
|
+
await resolveMSTeamsInboundMedia({
|
|
89
|
+
...baseParams,
|
|
90
|
+
attachments: [
|
|
91
|
+
{ contentType: "image/png", contentUrl: "https://example.com/img.png" },
|
|
92
|
+
{ contentType: "application/pdf", contentUrl: "https://example.com/doc.pdf" },
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("does NOT trigger Graph fallback when direct download succeeds", async () => {
|
|
100
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([
|
|
101
|
+
{ path: "/tmp/img.png", contentType: "image/png", placeholder: "[image]" },
|
|
102
|
+
]);
|
|
103
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
104
|
+
|
|
105
|
+
await resolveMSTeamsInboundMedia({
|
|
106
|
+
...baseParams,
|
|
107
|
+
attachments: [
|
|
108
|
+
{
|
|
109
|
+
contentType: "text/html",
|
|
110
|
+
content: '<div><attachment id="att-0"></attachment></div>',
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("forwards log through to downloadMSTeamsGraphMedia for diagnostics", async () => {
|
|
119
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
120
|
+
vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce(["att-0"]);
|
|
121
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
122
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({ media: [] });
|
|
123
|
+
const log = { debug: vi.fn() };
|
|
124
|
+
|
|
125
|
+
await resolveMSTeamsInboundMedia({
|
|
126
|
+
...baseParams,
|
|
127
|
+
log,
|
|
128
|
+
attachments: [
|
|
129
|
+
{
|
|
130
|
+
contentType: "text/html",
|
|
131
|
+
content: '<div><attachment id="att-0"></attachment></div>',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const call = vi.mocked(downloadMSTeamsGraphMedia).mock.calls[0]?.[0];
|
|
137
|
+
// The monitor handler's logger is forwarded so graph.ts can report
|
|
138
|
+
// message fetch failures instead of swallowing them (#51749).
|
|
139
|
+
expect(call?.logger).toBe(log);
|
|
140
|
+
expect(log.debug).toHaveBeenCalledWith(
|
|
141
|
+
"graph media fetch empty",
|
|
142
|
+
expect.objectContaining({ attachmentIdCount: 1 }),
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("resolveMSTeamsInboundMedia bot framework DM routing", () => {
|
|
148
|
+
const dmParams = {
|
|
149
|
+
...baseParams,
|
|
150
|
+
conversationType: "personal",
|
|
151
|
+
conversationId: "a:1dRsHCobZ1AxURzY05Dc",
|
|
152
|
+
serviceUrl: "https://smba.trafficmanager.net/amer/",
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
it("routes 'a:' conversation IDs through the Bot Framework attachment endpoint", async () => {
|
|
156
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
157
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
|
|
158
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockResolvedValue({
|
|
159
|
+
media: [
|
|
160
|
+
{
|
|
161
|
+
path: "/tmp/report.pdf",
|
|
162
|
+
contentType: "application/pdf",
|
|
163
|
+
placeholder: "<media:document>",
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
attachmentCount: 1,
|
|
167
|
+
});
|
|
168
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
169
|
+
|
|
170
|
+
const mediaList = await resolveMSTeamsInboundMedia({
|
|
171
|
+
...dmParams,
|
|
172
|
+
attachments: [
|
|
173
|
+
{
|
|
174
|
+
contentType: "text/html",
|
|
175
|
+
content: '<div>A file <attachment id="att-0"></attachment></div>',
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
expect(downloadMSTeamsBotFrameworkAttachments).toHaveBeenCalledTimes(1);
|
|
181
|
+
const call = vi.mocked(downloadMSTeamsBotFrameworkAttachments).mock.calls[0]?.[0];
|
|
182
|
+
expect(call?.serviceUrl).toBe(dmParams.serviceUrl);
|
|
183
|
+
expect(call?.attachmentIds).toEqual(["att-0", "att-1"]);
|
|
184
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
185
|
+
expect(mediaList).toHaveLength(1);
|
|
186
|
+
expect(mediaList[0].path).toBe("/tmp/report.pdf");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("skips the Graph fallback entirely for 'a:' conversation IDs", async () => {
|
|
190
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
191
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
|
|
192
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockResolvedValue({
|
|
193
|
+
media: [],
|
|
194
|
+
attachmentCount: 1,
|
|
195
|
+
});
|
|
196
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
197
|
+
vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
|
|
198
|
+
|
|
199
|
+
await resolveMSTeamsInboundMedia({
|
|
200
|
+
...dmParams,
|
|
201
|
+
attachments: [
|
|
202
|
+
{
|
|
203
|
+
contentType: "text/html",
|
|
204
|
+
content: '<div><attachment id="att-0"></attachment></div>',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(downloadMSTeamsBotFrameworkAttachments).toHaveBeenCalled();
|
|
210
|
+
expect(buildMSTeamsGraphMessageUrls).not.toHaveBeenCalled();
|
|
211
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("does NOT call the Bot Framework endpoint for Graph-compatible '19:' IDs", async () => {
|
|
215
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
216
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
|
|
217
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({ media: [] });
|
|
218
|
+
|
|
219
|
+
await resolveMSTeamsInboundMedia({
|
|
220
|
+
...baseParams,
|
|
221
|
+
conversationId: "19:abc@thread.tacv2",
|
|
222
|
+
serviceUrl: "https://smba.trafficmanager.net/amer/",
|
|
223
|
+
attachments: [
|
|
224
|
+
{
|
|
225
|
+
contentType: "text/html",
|
|
226
|
+
content: '<div><attachment id="att-0"></attachment></div>',
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
|
|
232
|
+
expect(downloadMSTeamsGraphMedia).toHaveBeenCalled();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("skips BF DM attachment fetch entirely when HTML has no <attachment> tags", async () => {
|
|
236
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
237
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
|
|
238
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
239
|
+
// Mention-only HTML (no `<attachment id="...">` tag) → extractor
|
|
240
|
+
// returns []. The fallback skips both the Bot Framework and Graph
|
|
241
|
+
// paths so we do not emit spurious 404 diagnostics (#58617).
|
|
242
|
+
vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
|
|
243
|
+
|
|
244
|
+
await resolveMSTeamsInboundMedia({
|
|
245
|
+
...dmParams,
|
|
246
|
+
attachments: [
|
|
247
|
+
{
|
|
248
|
+
contentType: "text/html",
|
|
249
|
+
content: '<div><at id="0">Bot</at> hello</div>',
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
|
|
255
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("logs when serviceUrl is missing for a BF DM with HTML content", async () => {
|
|
259
|
+
vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
|
|
260
|
+
vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
|
|
261
|
+
vi.mocked(downloadMSTeamsGraphMedia).mockClear();
|
|
262
|
+
vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
|
|
263
|
+
const log = { debug: vi.fn() };
|
|
264
|
+
|
|
265
|
+
await resolveMSTeamsInboundMedia({
|
|
266
|
+
...baseParams,
|
|
267
|
+
log,
|
|
268
|
+
conversationType: "personal",
|
|
269
|
+
conversationId: "a:bf-dm-id",
|
|
270
|
+
attachments: [
|
|
271
|
+
{
|
|
272
|
+
contentType: "text/html",
|
|
273
|
+
content: '<div><attachment id="att-0"></attachment></div>',
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
|
|
279
|
+
// Graph fallback is also skipped because the ID is 'a:'
|
|
280
|
+
expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
|
|
281
|
+
expect(log.debug).toHaveBeenCalledWith(
|
|
282
|
+
"bot framework attachment skipped (missing serviceUrl)",
|
|
283
|
+
expect.objectContaining({
|
|
284
|
+
conversationType: "personal",
|
|
285
|
+
conversationId: "a:bf-dm-id",
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildMSTeamsGraphMessageUrls,
|
|
3
3
|
downloadMSTeamsAttachments,
|
|
4
|
+
downloadMSTeamsBotFrameworkAttachments,
|
|
4
5
|
downloadMSTeamsGraphMedia,
|
|
6
|
+
extractMSTeamsHtmlAttachmentIds,
|
|
7
|
+
isBotFrameworkPersonalChatId,
|
|
5
8
|
type MSTeamsAccessTokenProvider,
|
|
6
9
|
type MSTeamsAttachmentLike,
|
|
7
10
|
type MSTeamsHtmlAttachmentSummary,
|
|
@@ -11,6 +14,8 @@ import type { MSTeamsTurnContext } from "../sdk-types.js";
|
|
|
11
14
|
|
|
12
15
|
type MSTeamsLogger = {
|
|
13
16
|
debug?: (message: string, meta?: Record<string, unknown>) => void;
|
|
17
|
+
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
18
|
+
error?: (message: string, meta?: Record<string, unknown>) => void;
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
export async function resolveMSTeamsInboundMedia(params: {
|
|
@@ -23,6 +28,7 @@ export async function resolveMSTeamsInboundMedia(params: {
|
|
|
23
28
|
conversationType: string;
|
|
24
29
|
conversationId: string;
|
|
25
30
|
conversationMessageId?: string;
|
|
31
|
+
serviceUrl?: string;
|
|
26
32
|
activity: Pick<MSTeamsTurnContext["activity"], "id" | "replyToId" | "channelData">;
|
|
27
33
|
log: MSTeamsLogger;
|
|
28
34
|
/** When true, embeds original filename in stored path for later extraction. */
|
|
@@ -37,6 +43,7 @@ export async function resolveMSTeamsInboundMedia(params: {
|
|
|
37
43
|
conversationType,
|
|
38
44
|
conversationId,
|
|
39
45
|
conversationMessageId,
|
|
46
|
+
serviceUrl,
|
|
40
47
|
activity,
|
|
41
48
|
log,
|
|
42
49
|
preserveFilenames,
|
|
@@ -49,14 +56,54 @@ export async function resolveMSTeamsInboundMedia(params: {
|
|
|
49
56
|
allowHosts,
|
|
50
57
|
authAllowHosts: params.authAllowHosts,
|
|
51
58
|
preserveFilenames,
|
|
59
|
+
logger: log,
|
|
52
60
|
});
|
|
53
61
|
|
|
54
62
|
if (mediaList.length === 0) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
// Gate the Graph/Bot Framework media fallback on the presence of real
|
|
64
|
+
// `<attachment id="...">` tags inside any `text/html` attachment. Teams
|
|
65
|
+
// delivers @mention cards and other chrome as `text/html` attachments
|
|
66
|
+
// too, so keying off contentType alone produces spurious 404 diagnostics
|
|
67
|
+
// for every mention-only message and masks real file attachments (#58617).
|
|
68
|
+
const attachmentIds = extractMSTeamsHtmlAttachmentIds(attachments);
|
|
69
|
+
const hasHtmlFileAttachment = attachmentIds.length > 0;
|
|
58
70
|
|
|
59
|
-
|
|
71
|
+
// Personal DMs with the bot use Bot Framework conversation IDs (`a:...`
|
|
72
|
+
// or `8:orgid:...`) which Graph's `/chats/{id}` endpoint rejects with
|
|
73
|
+
// "Invalid ThreadId". Fetch media via the Bot Framework v3 attachments
|
|
74
|
+
// endpoint instead, which speaks the same identifier space.
|
|
75
|
+
if (hasHtmlFileAttachment && isBotFrameworkPersonalChatId(conversationId)) {
|
|
76
|
+
if (!serviceUrl) {
|
|
77
|
+
log.debug?.("bot framework attachment skipped (missing serviceUrl)", {
|
|
78
|
+
conversationType,
|
|
79
|
+
conversationId,
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
const bfMedia = await downloadMSTeamsBotFrameworkAttachments({
|
|
83
|
+
serviceUrl,
|
|
84
|
+
attachmentIds,
|
|
85
|
+
tokenProvider,
|
|
86
|
+
maxBytes,
|
|
87
|
+
allowHosts,
|
|
88
|
+
authAllowHosts: params.authAllowHosts,
|
|
89
|
+
preserveFilenames,
|
|
90
|
+
});
|
|
91
|
+
if (bfMedia.media.length > 0) {
|
|
92
|
+
mediaList = bfMedia.media;
|
|
93
|
+
} else {
|
|
94
|
+
log.debug?.("bot framework attachments fetch empty", {
|
|
95
|
+
conversationType,
|
|
96
|
+
attachmentCount: bfMedia.attachmentCount ?? attachmentIds.length,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
hasHtmlFileAttachment &&
|
|
104
|
+
mediaList.length === 0 &&
|
|
105
|
+
!isBotFrameworkPersonalChatId(conversationId)
|
|
106
|
+
) {
|
|
60
107
|
const messageUrls = buildMSTeamsGraphMessageUrls({
|
|
61
108
|
conversationType,
|
|
62
109
|
conversationId,
|
|
@@ -89,6 +136,8 @@ export async function resolveMSTeamsInboundMedia(params: {
|
|
|
89
136
|
allowHosts,
|
|
90
137
|
authAllowHosts: params.authAllowHosts,
|
|
91
138
|
preserveFilenames,
|
|
139
|
+
log,
|
|
140
|
+
logger: log,
|
|
92
141
|
});
|
|
93
142
|
attempts.push({
|
|
94
143
|
url: messageUrl,
|
|
@@ -107,7 +156,10 @@ export async function resolveMSTeamsInboundMedia(params: {
|
|
|
107
156
|
}
|
|
108
157
|
}
|
|
109
158
|
if (mediaList.length === 0) {
|
|
110
|
-
log.debug?.("graph media fetch empty", {
|
|
159
|
+
log.debug?.("graph media fetch empty", {
|
|
160
|
+
attempts,
|
|
161
|
+
attachmentIdCount: attachmentIds.length,
|
|
162
|
+
});
|
|
111
163
|
}
|
|
112
164
|
}
|
|
113
165
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const runtimeApiMockState = vi.hoisted(() => ({
|
|
4
|
+
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
|
5
|
+
queuedFinal: false,
|
|
6
|
+
counts: {},
|
|
7
|
+
capturedCtxPayload: params.ctxPayload,
|
|
8
|
+
})),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
export function getRuntimeApiMockState() {
|
|
12
|
+
return runtimeApiMockState;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
vi.mock("openclaw/plugin-sdk/inbound-reply-dispatch", () => {
|
|
16
|
+
return {
|
|
17
|
+
dispatchReplyFromConfigWithSettledDispatcher:
|
|
18
|
+
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
vi.mock("../reply-dispatcher.js", () => ({
|
|
23
|
+
createMSTeamsReplyDispatcher: () => ({
|
|
24
|
+
dispatcher: {},
|
|
25
|
+
replyOptions: {},
|
|
26
|
+
markDispatchIdle: vi.fn(),
|
|
27
|
+
}),
|
|
28
|
+
}));
|