@openclaw/msteams 2026.5.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.
- package/dist/api.js +3 -0
- package/dist/channel-D7hdreTh.js +984 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BC1ruIfN.js +573 -0
- package/dist/config-schema-B8QezH6t.js +15 -0
- package/dist/contract-api.js +2 -0
- package/dist/graph-users-9uQJepqr.js +1354 -0
- package/dist/index.js +22 -0
- package/dist/oauth-BWJyilR1.js +114 -0
- package/dist/oauth.token-xxpoLWy5.js +115 -0
- package/dist/policy-DTnU2GR7.js +142 -0
- package/dist/probe-D_H8yFps.js +2194 -0
- package/dist/resolve-allowlist-D41JSziq.js +219 -0
- package/dist/runtime-api-DV1iVMn1.js +28 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-BuoEXmPS.js +35 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +64 -0
- package/dist/setup-surface-BLkFQYIQ.js +313 -0
- package/dist/src-CFp1QpFd.js +4064 -0
- package/dist/test-api.js +2 -0
- package/package.json +14 -6
- package/api.ts +0 -3
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -2
- package/config-api.ts +0 -4
- package/contract-api.ts +0 -4
- package/index.ts +0 -20
- package/runtime-api.ts +0 -73
- package/secret-contract-api.ts +0 -5
- package/setup-entry.ts +0 -13
- package/setup-plugin-api.ts +0 -3
- package/src/ai-entity.ts +0 -7
- package/src/approval-auth.ts +0 -44
- package/src/attachments/bot-framework.test.ts +0 -461
- package/src/attachments/bot-framework.ts +0 -362
- package/src/attachments/download.ts +0 -311
- package/src/attachments/graph.test.ts +0 -416
- package/src/attachments/graph.ts +0 -484
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -137
- package/src/attachments/remote-media.ts +0 -112
- package/src/attachments/shared.test.ts +0 -530
- package/src/attachments/shared.ts +0 -626
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -342
- package/src/attachments.helpers.test.ts +0 -246
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -687
- package/src/attachments.ts +0 -18
- package/src/block-streaming-config.test.ts +0 -61
- package/src/channel-api.ts +0 -1
- package/src/channel.actions.test.ts +0 -742
- package/src/channel.directory.test.ts +0 -200
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -128
- package/src/channel.ts +0 -1136
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -12
- package/src/conversation-store-fs.test.ts +0 -74
- package/src/conversation-store-fs.ts +0 -149
- package/src/conversation-store-helpers.test.ts +0 -202
- package/src/conversation-store-helpers.ts +0 -105
- package/src/conversation-store-memory.ts +0 -51
- package/src/conversation-store.shared.test.ts +0 -225
- package/src/conversation-store.ts +0 -71
- package/src/directory-live.test.ts +0 -156
- package/src/directory-live.ts +0 -111
- package/src/doctor.ts +0 -27
- package/src/errors.test.ts +0 -133
- package/src/errors.ts +0 -246
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -114
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -283
- package/src/file-consent-helpers.test.ts +0 -326
- package/src/file-consent-helpers.ts +0 -126
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -363
- package/src/file-consent.ts +0 -287
- package/src/graph-chat.ts +0 -55
- package/src/graph-group-management.test.ts +0 -318
- package/src/graph-group-management.ts +0 -168
- package/src/graph-members.test.ts +0 -89
- package/src/graph-members.ts +0 -48
- package/src/graph-messages.actions.test.ts +0 -243
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -213
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -215
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -246
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -258
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -516
- package/src/graph.ts +0 -293
- package/src/inbound.test.ts +0 -221
- package/src/inbound.ts +0 -148
- package/src/index.ts +0 -4
- package/src/media-helpers.test.ts +0 -202
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -244
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -865
- package/src/messenger.ts +0 -605
- package/src/monitor-handler/access.ts +0 -125
- package/src/monitor-handler/inbound-media.test.ts +0 -289
- package/src/monitor-handler/inbound-media.ts +0 -180
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
- package/src/monitor-handler/message-handler.authz.test.ts +0 -669
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -100
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
- package/src/monitor-handler/message-handler.ts +0 -1000
- package/src/monitor-handler/reaction-handler.test.ts +0 -267
- package/src/monitor-handler/reaction-handler.ts +0 -210
- package/src/monitor-handler/thread-session.ts +0 -17
- package/src/monitor-handler.adaptive-card.test.ts +0 -162
- package/src/monitor-handler.feedback-authz.test.ts +0 -314
- package/src/monitor-handler.file-consent.test.ts +0 -423
- package/src/monitor-handler.sso.test.ts +0 -563
- package/src/monitor-handler.test-helpers.ts +0 -180
- package/src/monitor-handler.ts +0 -534
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -278
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -442
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -305
- package/src/oauth.token.ts +0 -158
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -130
- package/src/outbound.ts +0 -71
- package/src/pending-uploads-fs.test.ts +0 -246
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -173
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -240
- package/src/policy.ts +0 -262
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -160
- package/src/polls.ts +0 -323
- package/src/presentation.ts +0 -68
- package/src/probe.test.ts +0 -77
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -437
- package/src/reply-dispatcher.ts +0 -346
- package/src/reply-stream-controller.test.ts +0 -235
- package/src/reply-stream-controller.ts +0 -147
- package/src/resolve-allowlist.test.ts +0 -250
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -9
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -666
- package/src/sdk.ts +0 -884
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.ts +0 -231
- package/src/send.test.ts +0 -493
- package/src/send.ts +0 -637
- package/src/sent-message-cache.test.ts +0 -15
- package/src/sent-message-cache.ts +0 -56
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -160
- package/src/setup-surface.test.ts +0 -202
- package/src/setup-surface.ts +0 -320
- package/src/sso-token-store.test.ts +0 -72
- package/src/sso-token-store.ts +0 -166
- package/src/sso.ts +0 -300
- package/src/storage.ts +0 -25
- package/src/store-fs.ts +0 -44
- package/src/streaming-message.test.ts +0 -262
- package/src/streaming-message.ts +0 -297
- package/src/test-runtime.ts +0 -16
- package/src/thread-parent-context.test.ts +0 -224
- package/src/thread-parent-context.ts +0 -159
- package/src/token-response.ts +0 -11
- package/src/token.test.ts +0 -259
- package/src/token.ts +0 -195
- package/src/user-agent.test.ts +0 -86
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -81
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_ACCOUNT_ID,
|
|
4
|
-
createChannelPairingController,
|
|
5
|
-
evaluateSenderGroupAccessForPolicy,
|
|
6
|
-
isDangerousNameMatchingEnabled,
|
|
7
|
-
readStoreAllowFromForDmPolicy,
|
|
8
|
-
resolveDefaultGroupPolicy,
|
|
9
|
-
resolveDmGroupAccessWithLists,
|
|
10
|
-
resolveEffectiveAllowFromLists,
|
|
11
|
-
resolveSenderScopedGroupPolicy,
|
|
12
|
-
type OpenClawConfig,
|
|
13
|
-
} from "../../runtime-api.js";
|
|
14
|
-
import { normalizeMSTeamsConversationId } from "../inbound.js";
|
|
15
|
-
import { resolveMSTeamsAllowlistMatch, resolveMSTeamsRouteConfig } from "../policy.js";
|
|
16
|
-
import { getMSTeamsRuntime } from "../runtime.js";
|
|
17
|
-
import type { MSTeamsTurnContext } from "../sdk-types.js";
|
|
18
|
-
|
|
19
|
-
export async function resolveMSTeamsSenderAccess(params: {
|
|
20
|
-
cfg: OpenClawConfig;
|
|
21
|
-
activity: MSTeamsTurnContext["activity"];
|
|
22
|
-
}) {
|
|
23
|
-
const activity = params.activity;
|
|
24
|
-
const msteamsCfg = params.cfg.channels?.msteams;
|
|
25
|
-
const conversationId = normalizeMSTeamsConversationId(activity.conversation?.id ?? "unknown");
|
|
26
|
-
const convType = normalizeOptionalLowercaseString(activity.conversation?.conversationType);
|
|
27
|
-
const isDirectMessage = convType === "personal" || (!convType && !activity.conversation?.isGroup);
|
|
28
|
-
const senderId = activity.from?.aadObjectId ?? activity.from?.id ?? "unknown";
|
|
29
|
-
const senderName = activity.from?.name ?? activity.from?.id ?? senderId;
|
|
30
|
-
|
|
31
|
-
const core = getMSTeamsRuntime();
|
|
32
|
-
const pairing = createChannelPairingController({
|
|
33
|
-
core,
|
|
34
|
-
channel: "msteams",
|
|
35
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
36
|
-
});
|
|
37
|
-
const dmPolicy = msteamsCfg?.dmPolicy ?? "pairing";
|
|
38
|
-
const storedAllowFrom = await readStoreAllowFromForDmPolicy({
|
|
39
|
-
provider: "msteams",
|
|
40
|
-
accountId: pairing.accountId,
|
|
41
|
-
dmPolicy,
|
|
42
|
-
readStore: pairing.readStoreForDmPolicy,
|
|
43
|
-
});
|
|
44
|
-
const configuredDmAllowFrom = msteamsCfg?.allowFrom ?? [];
|
|
45
|
-
const groupAllowFrom = msteamsCfg?.groupAllowFrom;
|
|
46
|
-
const resolvedAllowFromLists = resolveEffectiveAllowFromLists({
|
|
47
|
-
allowFrom: configuredDmAllowFrom,
|
|
48
|
-
groupAllowFrom,
|
|
49
|
-
storeAllowFrom: storedAllowFrom,
|
|
50
|
-
dmPolicy,
|
|
51
|
-
});
|
|
52
|
-
const defaultGroupPolicy = resolveDefaultGroupPolicy(params.cfg);
|
|
53
|
-
const groupPolicy =
|
|
54
|
-
!isDirectMessage && msteamsCfg
|
|
55
|
-
? (msteamsCfg.groupPolicy ?? defaultGroupPolicy ?? "allowlist")
|
|
56
|
-
: "disabled";
|
|
57
|
-
const effectiveGroupAllowFrom = resolvedAllowFromLists.effectiveGroupAllowFrom;
|
|
58
|
-
const allowNameMatching = isDangerousNameMatchingEnabled(msteamsCfg);
|
|
59
|
-
const channelGate = resolveMSTeamsRouteConfig({
|
|
60
|
-
cfg: msteamsCfg,
|
|
61
|
-
teamId: activity.channelData?.team?.id,
|
|
62
|
-
teamName: activity.channelData?.team?.name,
|
|
63
|
-
conversationId,
|
|
64
|
-
channelName: activity.channelData?.channel?.name,
|
|
65
|
-
allowNameMatching,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// When a route-level (team/channel) allowlist is configured but the sender allowlist is
|
|
69
|
-
// empty, resolveSenderScopedGroupPolicy would otherwise downgrade the policy to "open",
|
|
70
|
-
// allowing any sender. To close this bypass (GHSA-g7cr-9h7q-4qxq), treat an empty sender
|
|
71
|
-
// allowlist as deny-all whenever the route allowlist is active.
|
|
72
|
-
const senderGroupPolicy =
|
|
73
|
-
channelGate.allowlistConfigured && effectiveGroupAllowFrom.length === 0
|
|
74
|
-
? groupPolicy
|
|
75
|
-
: resolveSenderScopedGroupPolicy({
|
|
76
|
-
groupPolicy,
|
|
77
|
-
groupAllowFrom: effectiveGroupAllowFrom,
|
|
78
|
-
});
|
|
79
|
-
const access = resolveDmGroupAccessWithLists({
|
|
80
|
-
isGroup: !isDirectMessage,
|
|
81
|
-
dmPolicy,
|
|
82
|
-
groupPolicy: senderGroupPolicy,
|
|
83
|
-
allowFrom: configuredDmAllowFrom,
|
|
84
|
-
groupAllowFrom,
|
|
85
|
-
storeAllowFrom: storedAllowFrom,
|
|
86
|
-
groupAllowFromFallbackToAllowFrom: false,
|
|
87
|
-
isSenderAllowed: (allowFrom) =>
|
|
88
|
-
resolveMSTeamsAllowlistMatch({
|
|
89
|
-
allowFrom,
|
|
90
|
-
senderId,
|
|
91
|
-
senderName,
|
|
92
|
-
allowNameMatching,
|
|
93
|
-
}).allowed,
|
|
94
|
-
});
|
|
95
|
-
const senderGroupAccess = evaluateSenderGroupAccessForPolicy({
|
|
96
|
-
groupPolicy,
|
|
97
|
-
groupAllowFrom: effectiveGroupAllowFrom,
|
|
98
|
-
senderId,
|
|
99
|
-
isSenderAllowed: (_senderId, allowFrom) =>
|
|
100
|
-
resolveMSTeamsAllowlistMatch({
|
|
101
|
-
allowFrom,
|
|
102
|
-
senderId,
|
|
103
|
-
senderName,
|
|
104
|
-
allowNameMatching,
|
|
105
|
-
}).allowed,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
msteamsCfg,
|
|
110
|
-
pairing,
|
|
111
|
-
isDirectMessage,
|
|
112
|
-
conversationId,
|
|
113
|
-
senderId,
|
|
114
|
-
senderName,
|
|
115
|
-
dmPolicy,
|
|
116
|
-
channelGate,
|
|
117
|
-
access,
|
|
118
|
-
senderGroupAccess,
|
|
119
|
-
configuredDmAllowFrom,
|
|
120
|
-
effectiveDmAllowFrom: access.effectiveAllowFrom,
|
|
121
|
-
effectiveGroupAllowFrom,
|
|
122
|
-
allowNameMatching,
|
|
123
|
-
groupPolicy,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
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,180 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildMSTeamsGraphMessageUrls,
|
|
3
|
-
downloadMSTeamsAttachments,
|
|
4
|
-
downloadMSTeamsBotFrameworkAttachments,
|
|
5
|
-
downloadMSTeamsGraphMedia,
|
|
6
|
-
extractMSTeamsHtmlAttachmentIds,
|
|
7
|
-
isBotFrameworkPersonalChatId,
|
|
8
|
-
type MSTeamsAccessTokenProvider,
|
|
9
|
-
type MSTeamsAttachmentLike,
|
|
10
|
-
type MSTeamsHtmlAttachmentSummary,
|
|
11
|
-
type MSTeamsInboundMedia,
|
|
12
|
-
} from "../attachments.js";
|
|
13
|
-
import type { MSTeamsTurnContext } from "../sdk-types.js";
|
|
14
|
-
|
|
15
|
-
type MSTeamsLogger = {
|
|
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;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export async function resolveMSTeamsInboundMedia(params: {
|
|
22
|
-
attachments: MSTeamsAttachmentLike[];
|
|
23
|
-
htmlSummary?: MSTeamsHtmlAttachmentSummary;
|
|
24
|
-
maxBytes: number;
|
|
25
|
-
allowHosts?: string[];
|
|
26
|
-
authAllowHosts?: string[];
|
|
27
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
28
|
-
conversationType: string;
|
|
29
|
-
conversationId: string;
|
|
30
|
-
conversationMessageId?: string;
|
|
31
|
-
serviceUrl?: string;
|
|
32
|
-
activity: Pick<MSTeamsTurnContext["activity"], "id" | "replyToId" | "channelData">;
|
|
33
|
-
log: MSTeamsLogger;
|
|
34
|
-
/** When true, embeds original filename in stored path for later extraction. */
|
|
35
|
-
preserveFilenames?: boolean;
|
|
36
|
-
}): Promise<MSTeamsInboundMedia[]> {
|
|
37
|
-
const {
|
|
38
|
-
attachments,
|
|
39
|
-
htmlSummary,
|
|
40
|
-
maxBytes,
|
|
41
|
-
tokenProvider,
|
|
42
|
-
allowHosts,
|
|
43
|
-
conversationType,
|
|
44
|
-
conversationId,
|
|
45
|
-
conversationMessageId,
|
|
46
|
-
serviceUrl,
|
|
47
|
-
activity,
|
|
48
|
-
log,
|
|
49
|
-
preserveFilenames,
|
|
50
|
-
} = params;
|
|
51
|
-
|
|
52
|
-
let mediaList = await downloadMSTeamsAttachments({
|
|
53
|
-
attachments,
|
|
54
|
-
maxBytes,
|
|
55
|
-
tokenProvider,
|
|
56
|
-
allowHosts,
|
|
57
|
-
authAllowHosts: params.authAllowHosts,
|
|
58
|
-
preserveFilenames,
|
|
59
|
-
logger: log,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (mediaList.length === 0) {
|
|
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;
|
|
70
|
-
|
|
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
|
-
) {
|
|
107
|
-
const messageUrls = buildMSTeamsGraphMessageUrls({
|
|
108
|
-
conversationType,
|
|
109
|
-
conversationId,
|
|
110
|
-
messageId: activity.id ?? undefined,
|
|
111
|
-
replyToId: activity.replyToId ?? undefined,
|
|
112
|
-
conversationMessageId,
|
|
113
|
-
channelData: activity.channelData,
|
|
114
|
-
});
|
|
115
|
-
if (messageUrls.length === 0) {
|
|
116
|
-
log.debug?.("graph message url unavailable", {
|
|
117
|
-
conversationType,
|
|
118
|
-
hasChannelData: Boolean(activity.channelData),
|
|
119
|
-
messageId: activity.id ?? undefined,
|
|
120
|
-
replyToId: activity.replyToId ?? undefined,
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
const attempts: Array<{
|
|
124
|
-
url: string;
|
|
125
|
-
hostedStatus?: number;
|
|
126
|
-
attachmentStatus?: number;
|
|
127
|
-
hostedCount?: number;
|
|
128
|
-
attachmentCount?: number;
|
|
129
|
-
tokenError?: boolean;
|
|
130
|
-
}> = [];
|
|
131
|
-
for (const messageUrl of messageUrls) {
|
|
132
|
-
const graphMedia = await downloadMSTeamsGraphMedia({
|
|
133
|
-
messageUrl,
|
|
134
|
-
tokenProvider,
|
|
135
|
-
maxBytes,
|
|
136
|
-
allowHosts,
|
|
137
|
-
authAllowHosts: params.authAllowHosts,
|
|
138
|
-
preserveFilenames,
|
|
139
|
-
log,
|
|
140
|
-
logger: log,
|
|
141
|
-
});
|
|
142
|
-
attempts.push({
|
|
143
|
-
url: messageUrl,
|
|
144
|
-
hostedStatus: graphMedia.hostedStatus,
|
|
145
|
-
attachmentStatus: graphMedia.attachmentStatus,
|
|
146
|
-
hostedCount: graphMedia.hostedCount,
|
|
147
|
-
attachmentCount: graphMedia.attachmentCount,
|
|
148
|
-
tokenError: graphMedia.tokenError,
|
|
149
|
-
});
|
|
150
|
-
if (graphMedia.media.length > 0) {
|
|
151
|
-
mediaList = graphMedia.media;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
if (graphMedia.tokenError) {
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (mediaList.length === 0) {
|
|
159
|
-
log.debug?.("graph media fetch empty", {
|
|
160
|
-
attempts,
|
|
161
|
-
attachmentIdCount: attachmentIds.length,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (mediaList.length > 0) {
|
|
169
|
-
log.debug?.("downloaded attachments", { count: mediaList.length });
|
|
170
|
-
} else if (htmlSummary?.imgTags) {
|
|
171
|
-
log.debug?.("inline images detected but none downloaded", {
|
|
172
|
-
imgTags: htmlSummary.imgTags,
|
|
173
|
-
srcHosts: htmlSummary.srcHosts,
|
|
174
|
-
dataImages: htmlSummary.dataImages,
|
|
175
|
-
cidImages: htmlSummary.cidImages,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return mediaList;
|
|
180
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}));
|