@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-upload.ts
DELETED
|
@@ -1,531 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OneDrive/SharePoint upload utilities for MS Teams file sending.
|
|
3
|
-
*
|
|
4
|
-
* For group chats and channels, files are uploaded to SharePoint and shared via a link.
|
|
5
|
-
* This module provides utilities for:
|
|
6
|
-
* - Uploading files to OneDrive (personal scope - now deprecated for bot use)
|
|
7
|
-
* - Uploading files to SharePoint (group/channel scope)
|
|
8
|
-
* - Creating sharing links (organization-wide or per-user)
|
|
9
|
-
* - Getting chat members for per-user sharing
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { MSTeamsAccessTokenProvider } from "./attachments/types.js";
|
|
13
|
-
import { buildUserAgent } from "./user-agent.js";
|
|
14
|
-
|
|
15
|
-
const GRAPH_ROOT = "https://graph.microsoft.com/v1.0";
|
|
16
|
-
const GRAPH_BETA = "https://graph.microsoft.com/beta";
|
|
17
|
-
const GRAPH_SCOPE = "https://graph.microsoft.com";
|
|
18
|
-
|
|
19
|
-
interface OneDriveUploadResult {
|
|
20
|
-
id: string;
|
|
21
|
-
webUrl: string;
|
|
22
|
-
name: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Upload a file to the user's OneDrive root folder.
|
|
27
|
-
* For larger files, this uses the simple upload endpoint (up to 4MB).
|
|
28
|
-
*/
|
|
29
|
-
export async function uploadToOneDrive(params: {
|
|
30
|
-
buffer: Buffer;
|
|
31
|
-
filename: string;
|
|
32
|
-
contentType?: string;
|
|
33
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
34
|
-
fetchFn?: typeof fetch;
|
|
35
|
-
}): Promise<OneDriveUploadResult> {
|
|
36
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
37
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
38
|
-
|
|
39
|
-
// Use "OpenClawShared" folder to organize bot-uploaded files
|
|
40
|
-
const uploadPath = `/OpenClawShared/${encodeURIComponent(params.filename)}`;
|
|
41
|
-
|
|
42
|
-
const res = await fetchFn(`${GRAPH_ROOT}/me/drive/root:${uploadPath}:/content`, {
|
|
43
|
-
method: "PUT",
|
|
44
|
-
headers: {
|
|
45
|
-
"User-Agent": buildUserAgent(),
|
|
46
|
-
Authorization: `Bearer ${token}`,
|
|
47
|
-
"Content-Type": params.contentType ?? "application/octet-stream",
|
|
48
|
-
},
|
|
49
|
-
body: new Uint8Array(params.buffer),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (!res.ok) {
|
|
53
|
-
const body = await res.text().catch(() => "");
|
|
54
|
-
throw new Error(`OneDrive upload failed: ${res.status} ${res.statusText} - ${body}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const data = (await res.json()) as {
|
|
58
|
-
id?: string;
|
|
59
|
-
webUrl?: string;
|
|
60
|
-
name?: string;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
if (!data.id || !data.webUrl || !data.name) {
|
|
64
|
-
throw new Error("OneDrive upload response missing required fields");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
id: data.id,
|
|
69
|
-
webUrl: data.webUrl,
|
|
70
|
-
name: data.name,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface OneDriveSharingLink {
|
|
75
|
-
webUrl: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Create a sharing link for a OneDrive file.
|
|
80
|
-
* The link allows organization members to view the file.
|
|
81
|
-
*/
|
|
82
|
-
async function createSharingLink(params: {
|
|
83
|
-
itemId: string;
|
|
84
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
85
|
-
/** Sharing scope: "organization" (default) or "anonymous" */
|
|
86
|
-
scope?: "organization" | "anonymous";
|
|
87
|
-
fetchFn?: typeof fetch;
|
|
88
|
-
}): Promise<OneDriveSharingLink> {
|
|
89
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
90
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
91
|
-
|
|
92
|
-
const res = await fetchFn(`${GRAPH_ROOT}/me/drive/items/${params.itemId}/createLink`, {
|
|
93
|
-
method: "POST",
|
|
94
|
-
headers: {
|
|
95
|
-
"User-Agent": buildUserAgent(),
|
|
96
|
-
Authorization: `Bearer ${token}`,
|
|
97
|
-
"Content-Type": "application/json",
|
|
98
|
-
},
|
|
99
|
-
body: JSON.stringify({
|
|
100
|
-
type: "view",
|
|
101
|
-
scope: params.scope ?? "organization",
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (!res.ok) {
|
|
106
|
-
const body = await res.text().catch(() => "");
|
|
107
|
-
throw new Error(`Create sharing link failed: ${res.status} ${res.statusText} - ${body}`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const data = (await res.json()) as {
|
|
111
|
-
link?: { webUrl?: string };
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
if (!data.link?.webUrl) {
|
|
115
|
-
throw new Error("Create sharing link response missing webUrl");
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
webUrl: data.link.webUrl,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Upload a file to OneDrive and create a sharing link.
|
|
125
|
-
* Convenience function for the common case.
|
|
126
|
-
*/
|
|
127
|
-
export async function uploadAndShareOneDrive(params: {
|
|
128
|
-
buffer: Buffer;
|
|
129
|
-
filename: string;
|
|
130
|
-
contentType?: string;
|
|
131
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
132
|
-
scope?: "organization" | "anonymous";
|
|
133
|
-
fetchFn?: typeof fetch;
|
|
134
|
-
}): Promise<{
|
|
135
|
-
itemId: string;
|
|
136
|
-
webUrl: string;
|
|
137
|
-
shareUrl: string;
|
|
138
|
-
name: string;
|
|
139
|
-
}> {
|
|
140
|
-
const uploaded = await uploadToOneDrive({
|
|
141
|
-
buffer: params.buffer,
|
|
142
|
-
filename: params.filename,
|
|
143
|
-
contentType: params.contentType,
|
|
144
|
-
tokenProvider: params.tokenProvider,
|
|
145
|
-
fetchFn: params.fetchFn,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const shareLink = await createSharingLink({
|
|
149
|
-
itemId: uploaded.id,
|
|
150
|
-
tokenProvider: params.tokenProvider,
|
|
151
|
-
scope: params.scope,
|
|
152
|
-
fetchFn: params.fetchFn,
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
itemId: uploaded.id,
|
|
157
|
-
webUrl: uploaded.webUrl,
|
|
158
|
-
shareUrl: shareLink.webUrl,
|
|
159
|
-
name: uploaded.name,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ============================================================================
|
|
164
|
-
// SharePoint upload functions for group chats and channels
|
|
165
|
-
// ============================================================================
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Upload a file to a SharePoint site.
|
|
169
|
-
* This is used for group chats and channels where /me/drive doesn't work for bots.
|
|
170
|
-
*
|
|
171
|
-
* @param params.siteId - SharePoint site ID (e.g., "contoso.sharepoint.com,guid1,guid2")
|
|
172
|
-
*/
|
|
173
|
-
export async function uploadToSharePoint(params: {
|
|
174
|
-
buffer: Buffer;
|
|
175
|
-
filename: string;
|
|
176
|
-
contentType?: string;
|
|
177
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
178
|
-
siteId: string;
|
|
179
|
-
fetchFn?: typeof fetch;
|
|
180
|
-
}): Promise<OneDriveUploadResult> {
|
|
181
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
182
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
183
|
-
|
|
184
|
-
// Use "OpenClawShared" folder to organize bot-uploaded files
|
|
185
|
-
const uploadPath = `/OpenClawShared/${encodeURIComponent(params.filename)}`;
|
|
186
|
-
|
|
187
|
-
const res = await fetchFn(
|
|
188
|
-
`${GRAPH_ROOT}/sites/${params.siteId}/drive/root:${uploadPath}:/content`,
|
|
189
|
-
{
|
|
190
|
-
method: "PUT",
|
|
191
|
-
headers: {
|
|
192
|
-
"User-Agent": buildUserAgent(),
|
|
193
|
-
Authorization: `Bearer ${token}`,
|
|
194
|
-
"Content-Type": params.contentType ?? "application/octet-stream",
|
|
195
|
-
},
|
|
196
|
-
body: new Uint8Array(params.buffer),
|
|
197
|
-
},
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
if (!res.ok) {
|
|
201
|
-
const body = await res.text().catch(() => "");
|
|
202
|
-
throw new Error(`SharePoint upload failed: ${res.status} ${res.statusText} - ${body}`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const data = (await res.json()) as {
|
|
206
|
-
id?: string;
|
|
207
|
-
webUrl?: string;
|
|
208
|
-
name?: string;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
if (!data.id || !data.webUrl || !data.name) {
|
|
212
|
-
throw new Error("SharePoint upload response missing required fields");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
id: data.id,
|
|
217
|
-
webUrl: data.webUrl,
|
|
218
|
-
name: data.name,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
interface ChatMember {
|
|
223
|
-
aadObjectId: string;
|
|
224
|
-
displayName?: string;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Properties needed for native Teams file card attachments.
|
|
229
|
-
* The eTag is used as the attachment ID and webDavUrl as the contentUrl.
|
|
230
|
-
*/
|
|
231
|
-
export interface DriveItemProperties {
|
|
232
|
-
/** The eTag of the driveItem (used as attachment ID) */
|
|
233
|
-
eTag: string;
|
|
234
|
-
/** The WebDAV URL of the driveItem (used as contentUrl for reference attachment) */
|
|
235
|
-
webDavUrl: string;
|
|
236
|
-
/** The filename */
|
|
237
|
-
name: string;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Get driveItem properties needed for native Teams file card attachments.
|
|
242
|
-
* This fetches the eTag and webDavUrl which are required for "reference" type attachments.
|
|
243
|
-
*
|
|
244
|
-
* @param params.siteId - SharePoint site ID
|
|
245
|
-
* @param params.itemId - The driveItem ID (returned from upload)
|
|
246
|
-
*/
|
|
247
|
-
export async function getDriveItemProperties(params: {
|
|
248
|
-
siteId: string;
|
|
249
|
-
itemId: string;
|
|
250
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
251
|
-
fetchFn?: typeof fetch;
|
|
252
|
-
}): Promise<DriveItemProperties> {
|
|
253
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
254
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
255
|
-
|
|
256
|
-
const res = await fetchFn(
|
|
257
|
-
`${GRAPH_ROOT}/sites/${params.siteId}/drive/items/${params.itemId}?$select=eTag,webDavUrl,name`,
|
|
258
|
-
{ headers: { "User-Agent": buildUserAgent(), Authorization: `Bearer ${token}` } },
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
if (!res.ok) {
|
|
262
|
-
const body = await res.text().catch(() => "");
|
|
263
|
-
throw new Error(`Get driveItem properties failed: ${res.status} ${res.statusText} - ${body}`);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const data = (await res.json()) as {
|
|
267
|
-
eTag?: string;
|
|
268
|
-
webDavUrl?: string;
|
|
269
|
-
name?: string;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
if (!data.eTag || !data.webDavUrl || !data.name) {
|
|
273
|
-
throw new Error("DriveItem response missing required properties (eTag, webDavUrl, or name)");
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
eTag: data.eTag,
|
|
278
|
-
webDavUrl: data.webDavUrl,
|
|
279
|
-
name: data.name,
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Resolve the Graph API-native chat ID from a Bot Framework conversation ID.
|
|
285
|
-
*
|
|
286
|
-
* Bot Framework personal DM conversation IDs use formats like `a:1xxx@unq.gbl.spaces`
|
|
287
|
-
* or `8:orgid:xxx` that the Graph API does not accept. Graph API requires the
|
|
288
|
-
* `19:xxx@thread.tacv2` or `19:xxx@unq.gbl.spaces` format.
|
|
289
|
-
*
|
|
290
|
-
* This function looks up the matching Graph chat by querying the bot's chats filtered
|
|
291
|
-
* by the target user's AAD object ID.
|
|
292
|
-
*/
|
|
293
|
-
export async function resolveGraphChatId(params: {
|
|
294
|
-
/** Bot Framework conversation ID (may be in non-Graph format for personal DMs) */
|
|
295
|
-
botFrameworkConversationId: string;
|
|
296
|
-
/** AAD object ID of the user in the conversation (used for filtering chats) */
|
|
297
|
-
userAadObjectId?: string;
|
|
298
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
299
|
-
fetchFn?: typeof fetch;
|
|
300
|
-
}): Promise<string | null> {
|
|
301
|
-
const { botFrameworkConversationId, userAadObjectId, tokenProvider } = params;
|
|
302
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
303
|
-
|
|
304
|
-
// If the conversation ID already looks like a valid Graph chat ID, return it directly.
|
|
305
|
-
// Graph chat IDs start with "19:" — Bot Framework group chat IDs already use this format.
|
|
306
|
-
if (botFrameworkConversationId.startsWith("19:")) {
|
|
307
|
-
return botFrameworkConversationId;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// For personal DMs with non-Graph conversation IDs (e.g. `a:1xxx` or `8:orgid:xxx`),
|
|
311
|
-
// query the bot's chats to find the matching one.
|
|
312
|
-
const token = await tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
313
|
-
|
|
314
|
-
// Build filter: if we have the user's AAD object ID, narrow the search to 1:1 chats
|
|
315
|
-
// with that member. Otherwise, fall back to listing all 1:1 chats.
|
|
316
|
-
let path: string;
|
|
317
|
-
if (userAadObjectId) {
|
|
318
|
-
const encoded = encodeURIComponent(
|
|
319
|
-
`chatType eq 'oneOnOne' and members/any(m:m/microsoft.graph.aadUserConversationMember/userId eq '${userAadObjectId}')`,
|
|
320
|
-
);
|
|
321
|
-
path = `/me/chats?$filter=${encoded}&$select=id`;
|
|
322
|
-
} else {
|
|
323
|
-
// Fallback: list all 1:1 chats when no user ID is available.
|
|
324
|
-
// Only safe when the bot has exactly one 1:1 chat; returns null otherwise to
|
|
325
|
-
// avoid sending to the wrong person's chat.
|
|
326
|
-
path = `/me/chats?$filter=${encodeURIComponent("chatType eq 'oneOnOne'")}&$select=id`;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const res = await fetchFn(`${GRAPH_ROOT}${path}`, {
|
|
330
|
-
headers: { "User-Agent": buildUserAgent(), Authorization: `Bearer ${token}` },
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
if (!res.ok) {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const data = (await res.json()) as {
|
|
338
|
-
value?: Array<{ id?: string }>;
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const chats = data.value ?? [];
|
|
342
|
-
|
|
343
|
-
// When filtered by userAadObjectId, any non-empty result is the right 1:1 chat.
|
|
344
|
-
if (userAadObjectId && chats.length > 0 && chats[0]?.id) {
|
|
345
|
-
return chats[0].id;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Without a user ID we can only be certain when exactly one chat is returned;
|
|
349
|
-
// multiple results would be ambiguous and could route to the wrong person.
|
|
350
|
-
if (!userAadObjectId && chats.length === 1 && chats[0]?.id) {
|
|
351
|
-
return chats[0].id;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Get members of a Teams chat for per-user sharing.
|
|
359
|
-
* Used to create sharing links scoped to only the chat participants.
|
|
360
|
-
*/
|
|
361
|
-
async function getChatMembers(params: {
|
|
362
|
-
chatId: string;
|
|
363
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
364
|
-
fetchFn?: typeof fetch;
|
|
365
|
-
}): Promise<ChatMember[]> {
|
|
366
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
367
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
368
|
-
|
|
369
|
-
const res = await fetchFn(`${GRAPH_ROOT}/chats/${params.chatId}/members`, {
|
|
370
|
-
headers: { "User-Agent": buildUserAgent(), Authorization: `Bearer ${token}` },
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
if (!res.ok) {
|
|
374
|
-
const body = await res.text().catch(() => "");
|
|
375
|
-
throw new Error(`Get chat members failed: ${res.status} ${res.statusText} - ${body}`);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const data = (await res.json()) as {
|
|
379
|
-
value?: Array<{
|
|
380
|
-
userId?: string;
|
|
381
|
-
displayName?: string;
|
|
382
|
-
}>;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
return (data.value ?? [])
|
|
386
|
-
.map((m) => ({
|
|
387
|
-
aadObjectId: m.userId ?? "",
|
|
388
|
-
displayName: m.displayName,
|
|
389
|
-
}))
|
|
390
|
-
.filter((m) => m.aadObjectId);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Create a sharing link for a SharePoint drive item.
|
|
395
|
-
* For organization scope (default), uses v1.0 API.
|
|
396
|
-
* For per-user scope, uses beta API with recipients.
|
|
397
|
-
*/
|
|
398
|
-
async function createSharePointSharingLink(params: {
|
|
399
|
-
siteId: string;
|
|
400
|
-
itemId: string;
|
|
401
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
402
|
-
/** Sharing scope: "organization" (default) or "users" (per-user with recipients) */
|
|
403
|
-
scope?: "organization" | "users";
|
|
404
|
-
/** Required when scope is "users": AAD object IDs of recipients */
|
|
405
|
-
recipientObjectIds?: string[];
|
|
406
|
-
fetchFn?: typeof fetch;
|
|
407
|
-
}): Promise<OneDriveSharingLink> {
|
|
408
|
-
const fetchFn = params.fetchFn ?? fetch;
|
|
409
|
-
const token = await params.tokenProvider.getAccessToken(GRAPH_SCOPE);
|
|
410
|
-
const scope = params.scope ?? "organization";
|
|
411
|
-
|
|
412
|
-
// Per-user sharing requires beta API
|
|
413
|
-
const apiRoot = scope === "users" ? GRAPH_BETA : GRAPH_ROOT;
|
|
414
|
-
|
|
415
|
-
const body: Record<string, unknown> = {
|
|
416
|
-
type: "view",
|
|
417
|
-
scope: scope === "users" ? "users" : "organization",
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
// Add recipients for per-user sharing
|
|
421
|
-
if (scope === "users" && params.recipientObjectIds?.length) {
|
|
422
|
-
body.recipients = params.recipientObjectIds.map((id) => ({ objectId: id }));
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const res = await fetchFn(
|
|
426
|
-
`${apiRoot}/sites/${params.siteId}/drive/items/${params.itemId}/createLink`,
|
|
427
|
-
{
|
|
428
|
-
method: "POST",
|
|
429
|
-
headers: {
|
|
430
|
-
"User-Agent": buildUserAgent(),
|
|
431
|
-
Authorization: `Bearer ${token}`,
|
|
432
|
-
"Content-Type": "application/json",
|
|
433
|
-
},
|
|
434
|
-
body: JSON.stringify(body),
|
|
435
|
-
},
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
if (!res.ok) {
|
|
439
|
-
const respBody = await res.text().catch(() => "");
|
|
440
|
-
throw new Error(
|
|
441
|
-
`Create SharePoint sharing link failed: ${res.status} ${res.statusText} - ${respBody}`,
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const data = (await res.json()) as {
|
|
446
|
-
link?: { webUrl?: string };
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
if (!data.link?.webUrl) {
|
|
450
|
-
throw new Error("Create SharePoint sharing link response missing webUrl");
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return {
|
|
454
|
-
webUrl: data.link.webUrl,
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Upload a file to SharePoint and create a sharing link.
|
|
460
|
-
*
|
|
461
|
-
* For group chats, this creates a per-user sharing link scoped to chat members.
|
|
462
|
-
* For channels, this creates an organization-wide sharing link.
|
|
463
|
-
*
|
|
464
|
-
* @param params.siteId - SharePoint site ID
|
|
465
|
-
* @param params.chatId - Optional chat ID for per-user sharing (group chats)
|
|
466
|
-
* @param params.usePerUserSharing - Whether to use per-user sharing (requires beta API + Chat.Read.All)
|
|
467
|
-
*/
|
|
468
|
-
export async function uploadAndShareSharePoint(params: {
|
|
469
|
-
buffer: Buffer;
|
|
470
|
-
filename: string;
|
|
471
|
-
contentType?: string;
|
|
472
|
-
tokenProvider: MSTeamsAccessTokenProvider;
|
|
473
|
-
siteId: string;
|
|
474
|
-
chatId?: string;
|
|
475
|
-
usePerUserSharing?: boolean;
|
|
476
|
-
fetchFn?: typeof fetch;
|
|
477
|
-
}): Promise<{
|
|
478
|
-
itemId: string;
|
|
479
|
-
webUrl: string;
|
|
480
|
-
shareUrl: string;
|
|
481
|
-
name: string;
|
|
482
|
-
}> {
|
|
483
|
-
// 1. Upload file to SharePoint
|
|
484
|
-
const uploaded = await uploadToSharePoint({
|
|
485
|
-
buffer: params.buffer,
|
|
486
|
-
filename: params.filename,
|
|
487
|
-
contentType: params.contentType,
|
|
488
|
-
tokenProvider: params.tokenProvider,
|
|
489
|
-
siteId: params.siteId,
|
|
490
|
-
fetchFn: params.fetchFn,
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
// 2. Determine sharing scope
|
|
494
|
-
let scope: "organization" | "users" = "organization";
|
|
495
|
-
let recipientObjectIds: string[] | undefined;
|
|
496
|
-
|
|
497
|
-
if (params.usePerUserSharing && params.chatId) {
|
|
498
|
-
try {
|
|
499
|
-
const members = await getChatMembers({
|
|
500
|
-
chatId: params.chatId,
|
|
501
|
-
tokenProvider: params.tokenProvider,
|
|
502
|
-
fetchFn: params.fetchFn,
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
if (members.length > 0) {
|
|
506
|
-
scope = "users";
|
|
507
|
-
recipientObjectIds = members.map((m) => m.aadObjectId);
|
|
508
|
-
}
|
|
509
|
-
} catch {
|
|
510
|
-
// Fall back to organization scope if we can't get chat members
|
|
511
|
-
// (e.g., missing Chat.Read.All permission)
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// 3. Create sharing link
|
|
516
|
-
const shareLink = await createSharePointSharingLink({
|
|
517
|
-
siteId: params.siteId,
|
|
518
|
-
itemId: uploaded.id,
|
|
519
|
-
tokenProvider: params.tokenProvider,
|
|
520
|
-
scope,
|
|
521
|
-
recipientObjectIds,
|
|
522
|
-
fetchFn: params.fetchFn,
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
return {
|
|
526
|
-
itemId: uploaded.id,
|
|
527
|
-
webUrl: uploaded.webUrl,
|
|
528
|
-
shareUrl: shareLink.webUrl,
|
|
529
|
-
name: uploaded.name,
|
|
530
|
-
};
|
|
531
|
-
}
|
package/src/graph-users.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { escapeOData, fetchGraphJson, type GraphResponse, type GraphUser } from "./graph.js";
|
|
2
|
-
|
|
3
|
-
export async function searchGraphUsers(params: {
|
|
4
|
-
token: string;
|
|
5
|
-
query: string;
|
|
6
|
-
top?: number;
|
|
7
|
-
}): Promise<GraphUser[]> {
|
|
8
|
-
const query = params.query.trim();
|
|
9
|
-
if (!query) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (query.includes("@")) {
|
|
14
|
-
const escaped = escapeOData(query);
|
|
15
|
-
const filter = `(mail eq '${escaped}' or userPrincipalName eq '${escaped}')`;
|
|
16
|
-
const path = `/users?$filter=${encodeURIComponent(filter)}&$select=id,displayName,mail,userPrincipalName`;
|
|
17
|
-
const res = await fetchGraphJson<GraphResponse<GraphUser>>({ token: params.token, path });
|
|
18
|
-
return res.value ?? [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const top = typeof params.top === "number" && params.top > 0 ? params.top : 10;
|
|
22
|
-
const path = `/users?$search=${encodeURIComponent(`"displayName:${query}"`)}&$select=id,displayName,mail,userPrincipalName&$top=${top}`;
|
|
23
|
-
const res = await fetchGraphJson<GraphResponse<GraphUser>>({
|
|
24
|
-
token: params.token,
|
|
25
|
-
path,
|
|
26
|
-
headers: { ConsistencyLevel: "eventual" },
|
|
27
|
-
});
|
|
28
|
-
return res.value ?? [];
|
|
29
|
-
}
|