@openclaw/msteams 2026.5.2 → 2026.5.3-beta.2
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
package/src/graph-thread.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { fetchGraphJson, type GraphResponse } from "./graph.js";
|
|
2
|
-
|
|
3
|
-
export type GraphThreadMessage = {
|
|
4
|
-
id?: string;
|
|
5
|
-
from?: {
|
|
6
|
-
user?: { displayName?: string; id?: string };
|
|
7
|
-
application?: { displayName?: string; id?: string };
|
|
8
|
-
};
|
|
9
|
-
body?: { content?: string; contentType?: string };
|
|
10
|
-
createdDateTime?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// TTL cache for team ID -> group GUID mapping.
|
|
14
|
-
const teamGroupIdCache = new Map<string, { groupId: string; expiresAt: number }>();
|
|
15
|
-
const CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Strip HTML tags from Teams message content, preserving @mention display names.
|
|
19
|
-
* Teams wraps mentions in <at>Name</at> tags.
|
|
20
|
-
*/
|
|
21
|
-
export function stripHtmlFromTeamsMessage(html: string): string {
|
|
22
|
-
// Preserve mention display names by replacing <at>Name</at> with @Name.
|
|
23
|
-
let text = html.replace(/<at[^>]*>(.*?)<\/at>/gi, "@$1");
|
|
24
|
-
// Strip remaining HTML tags.
|
|
25
|
-
text = text.replace(/<[^>]*>/g, " ");
|
|
26
|
-
// Decode common HTML entities.
|
|
27
|
-
text = text
|
|
28
|
-
.replace(/&/g, "&")
|
|
29
|
-
.replace(/</g, "<")
|
|
30
|
-
.replace(/>/g, ">")
|
|
31
|
-
.replace(/"/g, '"')
|
|
32
|
-
.replace(/'/g, "'")
|
|
33
|
-
.replace(/ /g, " ");
|
|
34
|
-
// Normalize whitespace.
|
|
35
|
-
return text.replace(/\s+/g, " ").trim();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Resolve the Azure AD group GUID for a Teams conversation team ID.
|
|
40
|
-
* Results are cached with a TTL to avoid repeated Graph API calls.
|
|
41
|
-
*/
|
|
42
|
-
export async function resolveTeamGroupId(
|
|
43
|
-
token: string,
|
|
44
|
-
conversationTeamId: string,
|
|
45
|
-
): Promise<string> {
|
|
46
|
-
const cached = teamGroupIdCache.get(conversationTeamId);
|
|
47
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
48
|
-
return cached.groupId;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// The team ID in channelData is typically the group ID itself for standard teams.
|
|
52
|
-
// Validate by fetching /teams/{id} and returning the confirmed id.
|
|
53
|
-
// Requires Team.ReadBasic.All permission; fall back to raw ID if missing.
|
|
54
|
-
try {
|
|
55
|
-
const path = `/teams/${encodeURIComponent(conversationTeamId)}?$select=id`;
|
|
56
|
-
const team = await fetchGraphJson<{ id?: string }>({ token, path });
|
|
57
|
-
const groupId = team.id ?? conversationTeamId;
|
|
58
|
-
|
|
59
|
-
// Only cache when the Graph lookup succeeds — caching a fallback raw ID
|
|
60
|
-
// can cause silent failures for the entire TTL if the ID is not a valid
|
|
61
|
-
// Graph team GUID (e.g. Bot Framework conversation key).
|
|
62
|
-
teamGroupIdCache.set(conversationTeamId, {
|
|
63
|
-
groupId,
|
|
64
|
-
expiresAt: Date.now() + CACHE_TTL_MS,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return groupId;
|
|
68
|
-
} catch {
|
|
69
|
-
// Fallback to raw team ID without caching so subsequent calls retry the
|
|
70
|
-
// Graph lookup instead of using a potentially invalid cached value.
|
|
71
|
-
return conversationTeamId;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Fetch a single channel message (the parent/root of a thread).
|
|
77
|
-
* Returns undefined on error so callers can degrade gracefully.
|
|
78
|
-
*/
|
|
79
|
-
export async function fetchChannelMessage(
|
|
80
|
-
token: string,
|
|
81
|
-
groupId: string,
|
|
82
|
-
channelId: string,
|
|
83
|
-
messageId: string,
|
|
84
|
-
): Promise<GraphThreadMessage | undefined> {
|
|
85
|
-
const path = `/teams/${encodeURIComponent(groupId)}/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(messageId)}?$select=id,from,body,createdDateTime`;
|
|
86
|
-
try {
|
|
87
|
-
return await fetchGraphJson<GraphThreadMessage>({ token, path });
|
|
88
|
-
} catch {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Fetch thread replies for a channel message, ordered chronologically.
|
|
95
|
-
*
|
|
96
|
-
* **Limitation:** The Graph API replies endpoint (`/messages/{id}/replies`) does not
|
|
97
|
-
* support `$orderby`, so results are always returned in ascending (oldest-first) order.
|
|
98
|
-
* Combined with the `$top` cap of 50, this means only the **oldest 50 replies** are
|
|
99
|
-
* returned for long threads — newer replies are silently omitted. There is currently no
|
|
100
|
-
* Graph API workaround for this; pagination via `@odata.nextLink` can retrieve more
|
|
101
|
-
* replies but still in ascending order only.
|
|
102
|
-
*/
|
|
103
|
-
export async function fetchThreadReplies(
|
|
104
|
-
token: string,
|
|
105
|
-
groupId: string,
|
|
106
|
-
channelId: string,
|
|
107
|
-
messageId: string,
|
|
108
|
-
limit = 50,
|
|
109
|
-
): Promise<GraphThreadMessage[]> {
|
|
110
|
-
const top = Math.min(Math.max(limit, 1), 50);
|
|
111
|
-
// NOTE: Graph replies endpoint returns oldest-first and does not support $orderby.
|
|
112
|
-
// For threads with >50 replies, only the oldest 50 are returned. The most recent
|
|
113
|
-
// replies (often the most relevant context) may be truncated.
|
|
114
|
-
const path = `/teams/${encodeURIComponent(groupId)}/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(messageId)}/replies?$top=${top}&$select=id,from,body,createdDateTime`;
|
|
115
|
-
const res = await fetchGraphJson<GraphResponse<GraphThreadMessage>>({ token, path });
|
|
116
|
-
return res.value ?? [];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Format thread messages into a context string for the agent.
|
|
121
|
-
* Skips the current message (by id) and blank messages.
|
|
122
|
-
*/
|
|
123
|
-
export function formatThreadContext(
|
|
124
|
-
messages: GraphThreadMessage[],
|
|
125
|
-
currentMessageId?: string,
|
|
126
|
-
): string {
|
|
127
|
-
const lines: string[] = [];
|
|
128
|
-
for (const msg of messages) {
|
|
129
|
-
if (msg.id && msg.id === currentMessageId) {
|
|
130
|
-
continue;
|
|
131
|
-
} // Skip the triggering message.
|
|
132
|
-
const sender = msg.from?.user?.displayName ?? msg.from?.application?.displayName ?? "unknown";
|
|
133
|
-
const contentType = msg.body?.contentType ?? "text";
|
|
134
|
-
const rawContent = msg.body?.content ?? "";
|
|
135
|
-
const content =
|
|
136
|
-
contentType === "html" ? stripHtmlFromTeamsMessage(rawContent) : rawContent.trim();
|
|
137
|
-
if (!content) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
lines.push(`${sender}: ${content}`);
|
|
141
|
-
}
|
|
142
|
-
return lines.join("\n");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Exported for testing only.
|
|
146
|
-
export { teamGroupIdCache as _teamGroupIdCacheForTest };
|
package/src/graph-upload.test.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { buildTeamsFileInfoCard } from "./graph-chat.js";
|
|
4
|
-
import { resolveGraphChatId, uploadToOneDrive, uploadToSharePoint } from "./graph-upload.js";
|
|
5
|
-
|
|
6
|
-
describe("graph upload helpers", () => {
|
|
7
|
-
const tokenProvider = {
|
|
8
|
-
getAccessToken: vi.fn(async () => "graph-token"),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
it("uploads to OneDrive with the personal drive path", async () => {
|
|
12
|
-
const fetchFn = vi.fn(
|
|
13
|
-
async () =>
|
|
14
|
-
new Response(
|
|
15
|
-
JSON.stringify({ id: "item-1", webUrl: "https://example.com/1", name: "a.txt" }),
|
|
16
|
-
{
|
|
17
|
-
status: 200,
|
|
18
|
-
headers: { "content-type": "application/json" },
|
|
19
|
-
},
|
|
20
|
-
),
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const result = await uploadToOneDrive({
|
|
24
|
-
buffer: Buffer.from("hello"),
|
|
25
|
-
filename: "a.txt",
|
|
26
|
-
tokenProvider,
|
|
27
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
expect(fetchFn).toHaveBeenCalledWith(
|
|
31
|
-
"https://graph.microsoft.com/v1.0/me/drive/root:/OpenClawShared/a.txt:/content",
|
|
32
|
-
expect.objectContaining({
|
|
33
|
-
method: "PUT",
|
|
34
|
-
headers: expect.objectContaining({
|
|
35
|
-
Authorization: "Bearer graph-token",
|
|
36
|
-
"Content-Type": "application/octet-stream",
|
|
37
|
-
"User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
|
|
38
|
-
}),
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
expect(result).toEqual({
|
|
42
|
-
id: "item-1",
|
|
43
|
-
webUrl: "https://example.com/1",
|
|
44
|
-
name: "a.txt",
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("uploads to SharePoint with the site drive path", async () => {
|
|
49
|
-
const fetchFn = vi.fn(
|
|
50
|
-
async () =>
|
|
51
|
-
new Response(
|
|
52
|
-
JSON.stringify({ id: "item-2", webUrl: "https://example.com/2", name: "b.txt" }),
|
|
53
|
-
{
|
|
54
|
-
status: 200,
|
|
55
|
-
headers: { "content-type": "application/json" },
|
|
56
|
-
},
|
|
57
|
-
),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const result = await uploadToSharePoint({
|
|
61
|
-
buffer: Buffer.from("world"),
|
|
62
|
-
filename: "b.txt",
|
|
63
|
-
siteId: "site-123",
|
|
64
|
-
tokenProvider,
|
|
65
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(fetchFn).toHaveBeenCalledWith(
|
|
69
|
-
"https://graph.microsoft.com/v1.0/sites/site-123/drive/root:/OpenClawShared/b.txt:/content",
|
|
70
|
-
expect.objectContaining({
|
|
71
|
-
method: "PUT",
|
|
72
|
-
headers: expect.objectContaining({
|
|
73
|
-
Authorization: "Bearer graph-token",
|
|
74
|
-
"Content-Type": "application/octet-stream",
|
|
75
|
-
"User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
|
|
76
|
-
}),
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
expect(result).toEqual({
|
|
80
|
-
id: "item-2",
|
|
81
|
-
webUrl: "https://example.com/2",
|
|
82
|
-
name: "b.txt",
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("rejects upload responses missing required fields", async () => {
|
|
87
|
-
const fetchFn = vi.fn(
|
|
88
|
-
async () =>
|
|
89
|
-
new Response(JSON.stringify({ id: "item-3" }), {
|
|
90
|
-
status: 200,
|
|
91
|
-
headers: { "content-type": "application/json" },
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
await expect(
|
|
96
|
-
uploadToSharePoint({
|
|
97
|
-
buffer: Buffer.from("world"),
|
|
98
|
-
filename: "bad.txt",
|
|
99
|
-
siteId: "site-123",
|
|
100
|
-
tokenProvider,
|
|
101
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
102
|
-
}),
|
|
103
|
-
).rejects.toThrow("SharePoint upload response missing required fields");
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("resolveGraphChatId", () => {
|
|
108
|
-
const tokenProvider = {
|
|
109
|
-
getAccessToken: vi.fn(async () => "graph-token"),
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
it("returns the ID directly when it already starts with 19:", async () => {
|
|
113
|
-
const fetchFn = vi.fn();
|
|
114
|
-
const result = await resolveGraphChatId({
|
|
115
|
-
botFrameworkConversationId: "19:abc123@thread.tacv2",
|
|
116
|
-
tokenProvider,
|
|
117
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
118
|
-
});
|
|
119
|
-
// Should short-circuit without making any API call
|
|
120
|
-
expect(fetchFn).not.toHaveBeenCalled();
|
|
121
|
-
expect(result).toBe("19:abc123@thread.tacv2");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("resolves personal DM chat ID via Graph API using user AAD object ID", async () => {
|
|
125
|
-
const fetchFn = vi.fn(
|
|
126
|
-
async () =>
|
|
127
|
-
new Response(JSON.stringify({ value: [{ id: "19:dm-chat-id@unq.gbl.spaces" }] }), {
|
|
128
|
-
status: 200,
|
|
129
|
-
headers: { "content-type": "application/json" },
|
|
130
|
-
}),
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const result = await resolveGraphChatId({
|
|
134
|
-
botFrameworkConversationId: "a:1abc_bot_framework_dm_id",
|
|
135
|
-
userAadObjectId: "user-aad-object-id-123",
|
|
136
|
-
tokenProvider,
|
|
137
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
expect(fetchFn).toHaveBeenCalledWith(
|
|
141
|
-
expect.stringContaining("/me/chats"),
|
|
142
|
-
expect.objectContaining({
|
|
143
|
-
headers: expect.objectContaining({
|
|
144
|
-
Authorization: "Bearer graph-token",
|
|
145
|
-
"User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
|
|
146
|
-
}),
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
const firstCall = fetchFn.mock.calls[0];
|
|
150
|
-
if (!firstCall) {
|
|
151
|
-
throw new Error("expected Graph chat lookup request");
|
|
152
|
-
}
|
|
153
|
-
const [callUrlRaw] = firstCall as unknown as [string, RequestInit?];
|
|
154
|
-
const callUrl = new URL(callUrlRaw);
|
|
155
|
-
expect(callUrl.origin).toBe("https://graph.microsoft.com");
|
|
156
|
-
expect(callUrl.pathname).toBe("/v1.0/me/chats");
|
|
157
|
-
expect(callUrl.searchParams.get("$filter")).toBe(
|
|
158
|
-
"chatType eq 'oneOnOne' and members/any(m:m/microsoft.graph.aadUserConversationMember/userId eq 'user-aad-object-id-123')",
|
|
159
|
-
);
|
|
160
|
-
expect(callUrl.searchParams.get("$select")).toBe("id");
|
|
161
|
-
expect(result).toBe("19:dm-chat-id@unq.gbl.spaces");
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("resolves personal DM chat ID without user AAD object ID (lists all 1:1 chats)", async () => {
|
|
165
|
-
const fetchFn = vi.fn(
|
|
166
|
-
async () =>
|
|
167
|
-
new Response(JSON.stringify({ value: [{ id: "19:fallback-chat@unq.gbl.spaces" }] }), {
|
|
168
|
-
status: 200,
|
|
169
|
-
headers: { "content-type": "application/json" },
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const result = await resolveGraphChatId({
|
|
174
|
-
botFrameworkConversationId: "8:orgid:user-object-id",
|
|
175
|
-
tokenProvider,
|
|
176
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
expect(fetchFn).toHaveBeenCalledOnce();
|
|
180
|
-
expect(result).toBe("19:fallback-chat@unq.gbl.spaces");
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("returns null when Graph API returns no chats", async () => {
|
|
184
|
-
const fetchFn = vi.fn(
|
|
185
|
-
async () =>
|
|
186
|
-
new Response(JSON.stringify({ value: [] }), {
|
|
187
|
-
status: 200,
|
|
188
|
-
headers: { "content-type": "application/json" },
|
|
189
|
-
}),
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const result = await resolveGraphChatId({
|
|
193
|
-
botFrameworkConversationId: "a:1unknown_dm",
|
|
194
|
-
userAadObjectId: "some-user",
|
|
195
|
-
tokenProvider,
|
|
196
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
expect(result).toBeNull();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("returns null when Graph API call fails", async () => {
|
|
203
|
-
const fetchFn = vi.fn(
|
|
204
|
-
async () =>
|
|
205
|
-
new Response("Unauthorized", {
|
|
206
|
-
status: 401,
|
|
207
|
-
headers: { "content-type": "text/plain" },
|
|
208
|
-
}),
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
const result = await resolveGraphChatId({
|
|
212
|
-
botFrameworkConversationId: "a:1some_dm_id",
|
|
213
|
-
userAadObjectId: "some-user",
|
|
214
|
-
tokenProvider,
|
|
215
|
-
fetchFn: withFetchPreconnect(fetchFn),
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(result).toBeNull();
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe("buildTeamsFileInfoCard", () => {
|
|
223
|
-
it("extracts a unique id from quoted etags and lowercases file extensions", () => {
|
|
224
|
-
expect(
|
|
225
|
-
buildTeamsFileInfoCard({
|
|
226
|
-
eTag: '"{ABC-123},42"',
|
|
227
|
-
name: "Quarterly.Report.PDF",
|
|
228
|
-
webDavUrl: "https://sharepoint.example.com/file.pdf",
|
|
229
|
-
}),
|
|
230
|
-
).toEqual({
|
|
231
|
-
contentType: "application/vnd.microsoft.teams.card.file.info",
|
|
232
|
-
contentUrl: "https://sharepoint.example.com/file.pdf",
|
|
233
|
-
name: "Quarterly.Report.PDF",
|
|
234
|
-
content: {
|
|
235
|
-
uniqueId: "ABC-123",
|
|
236
|
-
fileType: "pdf",
|
|
237
|
-
},
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("keeps the raw etag when no version suffix exists and handles extensionless files", () => {
|
|
242
|
-
expect(
|
|
243
|
-
buildTeamsFileInfoCard({
|
|
244
|
-
eTag: "plain-etag",
|
|
245
|
-
name: "README",
|
|
246
|
-
webDavUrl: "https://sharepoint.example.com/readme",
|
|
247
|
-
}),
|
|
248
|
-
).toEqual({
|
|
249
|
-
contentType: "application/vnd.microsoft.teams.card.file.info",
|
|
250
|
-
contentUrl: "https://sharepoint.example.com/readme",
|
|
251
|
-
name: "README",
|
|
252
|
-
content: {
|
|
253
|
-
uniqueId: "plain-etag",
|
|
254
|
-
fileType: "",
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|