@openclaw/msteams 2026.5.2-beta.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
package/src/send.ts
DELETED
|
@@ -1,637 +0,0 @@
|
|
|
1
|
-
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
|
|
2
|
-
import { convertMarkdownTables } from "openclaw/plugin-sdk/text-runtime";
|
|
3
|
-
import { loadOutboundMediaFromUrl, type OpenClawConfig } from "../runtime-api.js";
|
|
4
|
-
import {
|
|
5
|
-
classifyMSTeamsSendError,
|
|
6
|
-
formatMSTeamsSendErrorHint,
|
|
7
|
-
formatUnknownError,
|
|
8
|
-
} from "./errors.js";
|
|
9
|
-
import { prepareFileConsentActivityFs, requiresFileConsent } from "./file-consent-helpers.js";
|
|
10
|
-
import { buildTeamsFileInfoCard } from "./graph-chat.js";
|
|
11
|
-
import {
|
|
12
|
-
getDriveItemProperties,
|
|
13
|
-
uploadAndShareOneDrive,
|
|
14
|
-
uploadAndShareSharePoint,
|
|
15
|
-
} from "./graph-upload.js";
|
|
16
|
-
import { extractFilename, extractMessageId } from "./media-helpers.js";
|
|
17
|
-
import { buildConversationReference, sendMSTeamsMessages } from "./messenger.js";
|
|
18
|
-
import { setPendingUploadActivityIdFs } from "./pending-uploads-fs.js";
|
|
19
|
-
import { setPendingUploadActivityId } from "./pending-uploads.js";
|
|
20
|
-
import { buildMSTeamsPollCard } from "./polls.js";
|
|
21
|
-
import { resolveMSTeamsSendContext, type MSTeamsProactiveContext } from "./send-context.js";
|
|
22
|
-
|
|
23
|
-
type SendMSTeamsMessageParams = {
|
|
24
|
-
/** Full config (for credentials) */
|
|
25
|
-
cfg: OpenClawConfig;
|
|
26
|
-
/** Conversation ID or user ID to send to */
|
|
27
|
-
to: string;
|
|
28
|
-
/** Message text */
|
|
29
|
-
text: string;
|
|
30
|
-
/** Optional media URL */
|
|
31
|
-
mediaUrl?: string;
|
|
32
|
-
/** Optional filename override for uploaded media/files */
|
|
33
|
-
filename?: string;
|
|
34
|
-
mediaLocalRoots?: readonly string[];
|
|
35
|
-
mediaReadFile?: (filePath: string) => Promise<Buffer>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
type SendMSTeamsMessageResult = {
|
|
39
|
-
messageId: string;
|
|
40
|
-
conversationId: string;
|
|
41
|
-
/** If a FileConsentCard was sent instead of the file, this contains the upload ID */
|
|
42
|
-
pendingUploadId?: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** Threshold for large files that require FileConsentCard flow in personal chats */
|
|
46
|
-
const FILE_CONSENT_THRESHOLD_BYTES = 4 * 1024 * 1024; // 4MB
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* MSTeams-specific media size limit (100MB).
|
|
50
|
-
* Higher than the default because OneDrive upload handles large files well.
|
|
51
|
-
*/
|
|
52
|
-
const MSTEAMS_MAX_MEDIA_BYTES = 100 * 1024 * 1024;
|
|
53
|
-
|
|
54
|
-
type SendMSTeamsPollParams = {
|
|
55
|
-
/** Full config (for credentials) */
|
|
56
|
-
cfg: OpenClawConfig;
|
|
57
|
-
/** Conversation ID or user ID to send to */
|
|
58
|
-
to: string;
|
|
59
|
-
/** Poll question */
|
|
60
|
-
question: string;
|
|
61
|
-
/** Poll options */
|
|
62
|
-
options: string[];
|
|
63
|
-
/** Max selections (defaults to 1) */
|
|
64
|
-
maxSelections?: number;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
type SendMSTeamsPollResult = {
|
|
68
|
-
pollId: string;
|
|
69
|
-
messageId: string;
|
|
70
|
-
conversationId: string;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
type SendMSTeamsCardParams = {
|
|
74
|
-
/** Full config (for credentials) */
|
|
75
|
-
cfg: OpenClawConfig;
|
|
76
|
-
/** Conversation ID or user ID to send to */
|
|
77
|
-
to: string;
|
|
78
|
-
/** Adaptive Card JSON object */
|
|
79
|
-
card: Record<string, unknown>;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
type SendMSTeamsCardResult = {
|
|
83
|
-
messageId: string;
|
|
84
|
-
conversationId: string;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Send a message to a Teams conversation or user.
|
|
89
|
-
*
|
|
90
|
-
* Uses the stored ConversationReference from previous interactions.
|
|
91
|
-
* The bot must have received at least one message from the conversation
|
|
92
|
-
* before proactive messaging works.
|
|
93
|
-
*
|
|
94
|
-
* File handling by conversation type:
|
|
95
|
-
* - Personal (1:1) chats: small images (<4MB) use base64, large files and non-images use FileConsentCard
|
|
96
|
-
* - Group chats / channels: files are uploaded to OneDrive and shared via link
|
|
97
|
-
*/
|
|
98
|
-
export async function sendMessageMSTeams(
|
|
99
|
-
params: SendMSTeamsMessageParams,
|
|
100
|
-
): Promise<SendMSTeamsMessageResult> {
|
|
101
|
-
const { cfg, to, text, mediaUrl, filename, mediaLocalRoots, mediaReadFile } = params;
|
|
102
|
-
const tableMode = resolveMarkdownTableMode({
|
|
103
|
-
cfg,
|
|
104
|
-
channel: "msteams",
|
|
105
|
-
});
|
|
106
|
-
const messageText = convertMarkdownTables(text ?? "", tableMode);
|
|
107
|
-
const ctx = await resolveMSTeamsSendContext({ cfg, to });
|
|
108
|
-
const {
|
|
109
|
-
adapter,
|
|
110
|
-
appId,
|
|
111
|
-
conversationId,
|
|
112
|
-
ref,
|
|
113
|
-
log,
|
|
114
|
-
conversationType,
|
|
115
|
-
tokenProvider,
|
|
116
|
-
sharePointSiteId,
|
|
117
|
-
} = ctx;
|
|
118
|
-
|
|
119
|
-
log.debug?.("sending proactive message", {
|
|
120
|
-
conversationId,
|
|
121
|
-
conversationType,
|
|
122
|
-
textLength: messageText.length,
|
|
123
|
-
hasMedia: Boolean(mediaUrl),
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Handle media if present
|
|
127
|
-
if (mediaUrl) {
|
|
128
|
-
const mediaMaxBytes = ctx.mediaMaxBytes ?? MSTEAMS_MAX_MEDIA_BYTES;
|
|
129
|
-
const media = await loadOutboundMediaFromUrl(mediaUrl, {
|
|
130
|
-
maxBytes: mediaMaxBytes,
|
|
131
|
-
mediaLocalRoots,
|
|
132
|
-
mediaReadFile,
|
|
133
|
-
});
|
|
134
|
-
const isLargeFile = media.buffer.length >= FILE_CONSENT_THRESHOLD_BYTES;
|
|
135
|
-
const isImage = media.contentType?.startsWith("image/") ?? false;
|
|
136
|
-
const fallbackFileName = await extractFilename(mediaUrl);
|
|
137
|
-
const fileName = filename?.trim() || media.fileName || fallbackFileName;
|
|
138
|
-
|
|
139
|
-
log.debug?.("processing media", {
|
|
140
|
-
fileName,
|
|
141
|
-
contentType: media.contentType,
|
|
142
|
-
size: media.buffer.length,
|
|
143
|
-
isLargeFile,
|
|
144
|
-
isImage,
|
|
145
|
-
conversationType,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Personal chats: base64 only works for images; use FileConsentCard for large files or non-images
|
|
149
|
-
if (
|
|
150
|
-
requiresFileConsent({
|
|
151
|
-
conversationType,
|
|
152
|
-
contentType: media.contentType,
|
|
153
|
-
bufferSize: media.buffer.length,
|
|
154
|
-
thresholdBytes: FILE_CONSENT_THRESHOLD_BYTES,
|
|
155
|
-
})
|
|
156
|
-
) {
|
|
157
|
-
// Proactive CLI sends run in a different process from the gateway's
|
|
158
|
-
// monitor that receives the fileConsent/invoke callback. Use the FS-
|
|
159
|
-
// backed helper so the invoke handler can find the pending upload when
|
|
160
|
-
// the user clicks "Allow".
|
|
161
|
-
const { activity, uploadId } = await prepareFileConsentActivityFs({
|
|
162
|
-
media: { buffer: media.buffer, filename: fileName, contentType: media.contentType },
|
|
163
|
-
conversationId,
|
|
164
|
-
description: messageText || undefined,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
log.debug?.("sending file consent card", { uploadId, fileName, size: media.buffer.length });
|
|
168
|
-
|
|
169
|
-
const messageId = await sendProactiveActivity({
|
|
170
|
-
adapter,
|
|
171
|
-
appId,
|
|
172
|
-
ref,
|
|
173
|
-
activity,
|
|
174
|
-
errorPrefix: "msteams consent card send",
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Store the activity ID so the accept handler can replace the consent
|
|
178
|
-
// card in-place. Mirror it into the FS store too because the invoke
|
|
179
|
-
// callback may be delivered to a different process than the CLI send.
|
|
180
|
-
setPendingUploadActivityId(uploadId, messageId);
|
|
181
|
-
await setPendingUploadActivityIdFs(uploadId, messageId);
|
|
182
|
-
|
|
183
|
-
log.info("sent file consent card", { conversationId, messageId, uploadId });
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
messageId,
|
|
187
|
-
conversationId,
|
|
188
|
-
pendingUploadId: uploadId,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Personal chat with small image: use base64 (only works for images)
|
|
193
|
-
if (conversationType === "personal") {
|
|
194
|
-
// Small image in personal chat: use base64 (only works for images)
|
|
195
|
-
const base64 = media.buffer.toString("base64");
|
|
196
|
-
const finalMediaUrl = `data:${media.contentType};base64,${base64}`;
|
|
197
|
-
|
|
198
|
-
return sendTextWithMedia(ctx, messageText, finalMediaUrl);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (isImage && !sharePointSiteId) {
|
|
202
|
-
// Group chat/channel without SharePoint: send image inline (avoids OneDrive failures)
|
|
203
|
-
const base64 = media.buffer.toString("base64");
|
|
204
|
-
const finalMediaUrl = `data:${media.contentType};base64,${base64}`;
|
|
205
|
-
return sendTextWithMedia(ctx, messageText, finalMediaUrl);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Group chat or channel: upload to SharePoint (if siteId configured) or OneDrive
|
|
209
|
-
try {
|
|
210
|
-
if (sharePointSiteId) {
|
|
211
|
-
// Use SharePoint upload + Graph API for native file card
|
|
212
|
-
log.debug?.("uploading to SharePoint for native file card", {
|
|
213
|
-
fileName,
|
|
214
|
-
conversationType,
|
|
215
|
-
siteId: sharePointSiteId,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
const uploaded = await uploadAndShareSharePoint({
|
|
219
|
-
buffer: media.buffer,
|
|
220
|
-
filename: fileName,
|
|
221
|
-
contentType: media.contentType,
|
|
222
|
-
tokenProvider,
|
|
223
|
-
siteId: sharePointSiteId,
|
|
224
|
-
// Use the Graph-native chat ID (19:xxx format) — the Bot Framework conversationId
|
|
225
|
-
// for personal DMs uses a different format that Graph API rejects.
|
|
226
|
-
chatId: ctx.graphChatId ?? conversationId,
|
|
227
|
-
usePerUserSharing: conversationType === "groupChat",
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
log.debug?.("SharePoint upload complete", {
|
|
231
|
-
itemId: uploaded.itemId,
|
|
232
|
-
shareUrl: uploaded.shareUrl,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// Get driveItem properties needed for native file card
|
|
236
|
-
const driveItem = await getDriveItemProperties({
|
|
237
|
-
siteId: sharePointSiteId,
|
|
238
|
-
itemId: uploaded.itemId,
|
|
239
|
-
tokenProvider,
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
log.debug?.("driveItem properties retrieved", {
|
|
243
|
-
eTag: driveItem.eTag,
|
|
244
|
-
webDavUrl: driveItem.webDavUrl,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// Build native Teams file card attachment and send via Bot Framework
|
|
248
|
-
const fileCardAttachment = buildTeamsFileInfoCard(driveItem);
|
|
249
|
-
const activity = {
|
|
250
|
-
type: "message",
|
|
251
|
-
text: messageText || undefined,
|
|
252
|
-
attachments: [fileCardAttachment],
|
|
253
|
-
};
|
|
254
|
-
const messageId = await sendProactiveActivityRaw({
|
|
255
|
-
adapter,
|
|
256
|
-
appId,
|
|
257
|
-
ref,
|
|
258
|
-
activity,
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
log.info("sent native file card", {
|
|
262
|
-
conversationId,
|
|
263
|
-
messageId,
|
|
264
|
-
fileName: driveItem.name,
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
return { messageId, conversationId };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Fallback: no SharePoint site configured, use OneDrive with markdown link
|
|
271
|
-
log.debug?.("uploading to OneDrive (no SharePoint site configured)", {
|
|
272
|
-
fileName,
|
|
273
|
-
conversationType,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
const uploaded = await uploadAndShareOneDrive({
|
|
277
|
-
buffer: media.buffer,
|
|
278
|
-
filename: fileName,
|
|
279
|
-
contentType: media.contentType,
|
|
280
|
-
tokenProvider,
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
log.debug?.("OneDrive upload complete", {
|
|
284
|
-
itemId: uploaded.itemId,
|
|
285
|
-
shareUrl: uploaded.shareUrl,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// Send message with file link (Bot Framework doesn't support "reference" attachment type for sending)
|
|
289
|
-
const fileLink = `📎 [${uploaded.name}](${uploaded.shareUrl})`;
|
|
290
|
-
const activity = {
|
|
291
|
-
type: "message",
|
|
292
|
-
text: messageText ? `${messageText}\n\n${fileLink}` : fileLink,
|
|
293
|
-
};
|
|
294
|
-
const messageId = await sendProactiveActivityRaw({
|
|
295
|
-
adapter,
|
|
296
|
-
appId,
|
|
297
|
-
ref,
|
|
298
|
-
activity,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
log.info("sent message with OneDrive file link", {
|
|
302
|
-
conversationId,
|
|
303
|
-
messageId,
|
|
304
|
-
shareUrl: uploaded.shareUrl,
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
return { messageId, conversationId };
|
|
308
|
-
} catch (err) {
|
|
309
|
-
const classification = classifyMSTeamsSendError(err);
|
|
310
|
-
const hint = formatMSTeamsSendErrorHint(classification);
|
|
311
|
-
const status = classification.statusCode ? ` (HTTP ${classification.statusCode})` : "";
|
|
312
|
-
throw new Error(
|
|
313
|
-
`msteams file send failed${status}: ${formatUnknownError(err)}${hint ? ` (${hint})` : ""}`,
|
|
314
|
-
{ cause: err },
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// No media: send text only
|
|
320
|
-
return sendTextWithMedia(ctx, messageText, undefined);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Send a text message with optional base64 media URL.
|
|
325
|
-
*/
|
|
326
|
-
async function sendTextWithMedia(
|
|
327
|
-
ctx: MSTeamsProactiveContext,
|
|
328
|
-
text: string,
|
|
329
|
-
mediaUrl: string | undefined,
|
|
330
|
-
): Promise<SendMSTeamsMessageResult> {
|
|
331
|
-
const {
|
|
332
|
-
adapter,
|
|
333
|
-
appId,
|
|
334
|
-
conversationId,
|
|
335
|
-
ref,
|
|
336
|
-
log,
|
|
337
|
-
tokenProvider,
|
|
338
|
-
sharePointSiteId,
|
|
339
|
-
mediaMaxBytes,
|
|
340
|
-
} = ctx;
|
|
341
|
-
|
|
342
|
-
let messageIds: string[];
|
|
343
|
-
try {
|
|
344
|
-
messageIds = await sendMSTeamsMessages({
|
|
345
|
-
replyStyle: "top-level",
|
|
346
|
-
adapter,
|
|
347
|
-
appId,
|
|
348
|
-
conversationRef: ref,
|
|
349
|
-
messages: [{ text: text || undefined, mediaUrl }],
|
|
350
|
-
retry: {},
|
|
351
|
-
onRetry: (event) => {
|
|
352
|
-
log.debug?.("retrying send", { conversationId, ...event });
|
|
353
|
-
},
|
|
354
|
-
tokenProvider,
|
|
355
|
-
sharePointSiteId,
|
|
356
|
-
mediaMaxBytes,
|
|
357
|
-
});
|
|
358
|
-
} catch (err) {
|
|
359
|
-
const classification = classifyMSTeamsSendError(err);
|
|
360
|
-
const hint = formatMSTeamsSendErrorHint(classification);
|
|
361
|
-
const status = classification.statusCode ? ` (HTTP ${classification.statusCode})` : "";
|
|
362
|
-
throw new Error(
|
|
363
|
-
`msteams send failed${status}: ${formatUnknownError(err)}${hint ? ` (${hint})` : ""}`,
|
|
364
|
-
{ cause: err },
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const messageId = messageIds[0] ?? "unknown";
|
|
369
|
-
log.info("sent proactive message", { conversationId, messageId });
|
|
370
|
-
|
|
371
|
-
return {
|
|
372
|
-
messageId,
|
|
373
|
-
conversationId,
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
type ProactiveActivityParams = {
|
|
378
|
-
adapter: MSTeamsProactiveContext["adapter"];
|
|
379
|
-
appId: string;
|
|
380
|
-
ref: MSTeamsProactiveContext["ref"];
|
|
381
|
-
activity: Record<string, unknown>;
|
|
382
|
-
errorPrefix: string;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
type ProactiveActivityRawParams = Omit<ProactiveActivityParams, "errorPrefix">;
|
|
386
|
-
|
|
387
|
-
async function sendProactiveActivityRaw({
|
|
388
|
-
adapter,
|
|
389
|
-
appId,
|
|
390
|
-
ref,
|
|
391
|
-
activity,
|
|
392
|
-
}: ProactiveActivityRawParams): Promise<string> {
|
|
393
|
-
const baseRef = buildConversationReference(ref);
|
|
394
|
-
const proactiveRef = {
|
|
395
|
-
...baseRef,
|
|
396
|
-
activityId: undefined,
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
let messageId = "unknown";
|
|
400
|
-
await adapter.continueConversation(appId, proactiveRef, async (ctx) => {
|
|
401
|
-
const response = await ctx.sendActivity(activity);
|
|
402
|
-
messageId = extractMessageId(response) ?? "unknown";
|
|
403
|
-
});
|
|
404
|
-
return messageId;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
async function sendProactiveActivity({
|
|
408
|
-
adapter,
|
|
409
|
-
appId,
|
|
410
|
-
ref,
|
|
411
|
-
activity,
|
|
412
|
-
errorPrefix,
|
|
413
|
-
}: ProactiveActivityParams): Promise<string> {
|
|
414
|
-
try {
|
|
415
|
-
return await sendProactiveActivityRaw({
|
|
416
|
-
adapter,
|
|
417
|
-
appId,
|
|
418
|
-
ref,
|
|
419
|
-
activity,
|
|
420
|
-
});
|
|
421
|
-
} catch (err) {
|
|
422
|
-
const classification = classifyMSTeamsSendError(err);
|
|
423
|
-
const hint = formatMSTeamsSendErrorHint(classification);
|
|
424
|
-
const status = classification.statusCode ? ` (HTTP ${classification.statusCode})` : "";
|
|
425
|
-
throw new Error(
|
|
426
|
-
`${errorPrefix} failed${status}: ${formatUnknownError(err)}${hint ? ` (${hint})` : ""}`,
|
|
427
|
-
{ cause: err },
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Send a poll (Adaptive Card) to a Teams conversation or user.
|
|
434
|
-
*/
|
|
435
|
-
export async function sendPollMSTeams(
|
|
436
|
-
params: SendMSTeamsPollParams,
|
|
437
|
-
): Promise<SendMSTeamsPollResult> {
|
|
438
|
-
const { cfg, to, question, options, maxSelections } = params;
|
|
439
|
-
const { adapter, appId, conversationId, ref, log } = await resolveMSTeamsSendContext({
|
|
440
|
-
cfg,
|
|
441
|
-
to,
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
const pollCard = buildMSTeamsPollCard({
|
|
445
|
-
question,
|
|
446
|
-
options,
|
|
447
|
-
maxSelections,
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
log.debug?.("sending poll", {
|
|
451
|
-
conversationId,
|
|
452
|
-
pollId: pollCard.pollId,
|
|
453
|
-
optionCount: pollCard.options.length,
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
const activity = {
|
|
457
|
-
type: "message",
|
|
458
|
-
attachments: [
|
|
459
|
-
{
|
|
460
|
-
contentType: "application/vnd.microsoft.card.adaptive",
|
|
461
|
-
content: pollCard.card,
|
|
462
|
-
},
|
|
463
|
-
],
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
// Send poll via proactive conversation (Adaptive Cards require direct activity send)
|
|
467
|
-
const messageId = await sendProactiveActivity({
|
|
468
|
-
adapter,
|
|
469
|
-
appId,
|
|
470
|
-
ref,
|
|
471
|
-
activity,
|
|
472
|
-
errorPrefix: "msteams poll send",
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
log.info("sent poll", { conversationId, pollId: pollCard.pollId, messageId });
|
|
476
|
-
|
|
477
|
-
return {
|
|
478
|
-
pollId: pollCard.pollId,
|
|
479
|
-
messageId,
|
|
480
|
-
conversationId,
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Send an arbitrary Adaptive Card to a Teams conversation or user.
|
|
486
|
-
*/
|
|
487
|
-
export async function sendAdaptiveCardMSTeams(
|
|
488
|
-
params: SendMSTeamsCardParams,
|
|
489
|
-
): Promise<SendMSTeamsCardResult> {
|
|
490
|
-
const { cfg, to, card } = params;
|
|
491
|
-
const { adapter, appId, conversationId, ref, log } = await resolveMSTeamsSendContext({
|
|
492
|
-
cfg,
|
|
493
|
-
to,
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
log.debug?.("sending adaptive card", {
|
|
497
|
-
conversationId,
|
|
498
|
-
cardType: card.type,
|
|
499
|
-
cardVersion: card.version,
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
const activity = {
|
|
503
|
-
type: "message",
|
|
504
|
-
attachments: [
|
|
505
|
-
{
|
|
506
|
-
contentType: "application/vnd.microsoft.card.adaptive",
|
|
507
|
-
content: card,
|
|
508
|
-
},
|
|
509
|
-
],
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
// Send card via proactive conversation
|
|
513
|
-
const messageId = await sendProactiveActivity({
|
|
514
|
-
adapter,
|
|
515
|
-
appId,
|
|
516
|
-
ref,
|
|
517
|
-
activity,
|
|
518
|
-
errorPrefix: "msteams card send",
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
log.info("sent adaptive card", { conversationId, messageId });
|
|
522
|
-
|
|
523
|
-
return {
|
|
524
|
-
messageId,
|
|
525
|
-
conversationId,
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
type EditMSTeamsMessageParams = {
|
|
530
|
-
/** Full config (for credentials) */
|
|
531
|
-
cfg: OpenClawConfig;
|
|
532
|
-
/** Conversation ID or user ID */
|
|
533
|
-
to: string;
|
|
534
|
-
/** Activity ID of the message to edit */
|
|
535
|
-
activityId: string;
|
|
536
|
-
/** New message text */
|
|
537
|
-
text: string;
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
type EditMSTeamsMessageResult = {
|
|
541
|
-
conversationId: string;
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
type DeleteMSTeamsMessageParams = {
|
|
545
|
-
/** Full config (for credentials) */
|
|
546
|
-
cfg: OpenClawConfig;
|
|
547
|
-
/** Conversation ID or user ID */
|
|
548
|
-
to: string;
|
|
549
|
-
/** Activity ID of the message to delete */
|
|
550
|
-
activityId: string;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
type DeleteMSTeamsMessageResult = {
|
|
554
|
-
conversationId: string;
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Edit (update) a previously sent message in a Teams conversation.
|
|
559
|
-
*
|
|
560
|
-
* Uses the Bot Framework `continueConversation` → `updateActivity` flow
|
|
561
|
-
* for proactive edits outside of the original turn context.
|
|
562
|
-
*/
|
|
563
|
-
export async function editMessageMSTeams(
|
|
564
|
-
params: EditMSTeamsMessageParams,
|
|
565
|
-
): Promise<EditMSTeamsMessageResult> {
|
|
566
|
-
const { cfg, to, activityId, text } = params;
|
|
567
|
-
const { adapter, appId, conversationId, ref, log } = await resolveMSTeamsSendContext({
|
|
568
|
-
cfg,
|
|
569
|
-
to,
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
log.debug?.("editing proactive message", { conversationId, activityId, textLength: text.length });
|
|
573
|
-
|
|
574
|
-
const baseRef = buildConversationReference(ref);
|
|
575
|
-
const proactiveRef = { ...baseRef, activityId: undefined };
|
|
576
|
-
|
|
577
|
-
try {
|
|
578
|
-
await adapter.continueConversation(appId, proactiveRef, async (ctx) => {
|
|
579
|
-
await ctx.updateActivity({
|
|
580
|
-
type: "message",
|
|
581
|
-
id: activityId,
|
|
582
|
-
text,
|
|
583
|
-
});
|
|
584
|
-
});
|
|
585
|
-
} catch (err) {
|
|
586
|
-
const classification = classifyMSTeamsSendError(err);
|
|
587
|
-
const hint = formatMSTeamsSendErrorHint(classification);
|
|
588
|
-
const status = classification.statusCode ? ` (HTTP ${classification.statusCode})` : "";
|
|
589
|
-
throw new Error(
|
|
590
|
-
`msteams edit failed${status}: ${formatUnknownError(err)}${hint ? ` (${hint})` : ""}`,
|
|
591
|
-
{ cause: err },
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
log.info("edited proactive message", { conversationId, activityId });
|
|
596
|
-
|
|
597
|
-
return { conversationId };
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Delete a previously sent message in a Teams conversation.
|
|
602
|
-
*
|
|
603
|
-
* Uses the Bot Framework `continueConversation` → `deleteActivity` flow
|
|
604
|
-
* for proactive deletes outside of the original turn context.
|
|
605
|
-
*/
|
|
606
|
-
export async function deleteMessageMSTeams(
|
|
607
|
-
params: DeleteMSTeamsMessageParams,
|
|
608
|
-
): Promise<DeleteMSTeamsMessageResult> {
|
|
609
|
-
const { cfg, to, activityId } = params;
|
|
610
|
-
const { adapter, appId, conversationId, ref, log } = await resolveMSTeamsSendContext({
|
|
611
|
-
cfg,
|
|
612
|
-
to,
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
log.debug?.("deleting proactive message", { conversationId, activityId });
|
|
616
|
-
|
|
617
|
-
const baseRef = buildConversationReference(ref);
|
|
618
|
-
const proactiveRef = { ...baseRef, activityId: undefined };
|
|
619
|
-
|
|
620
|
-
try {
|
|
621
|
-
await adapter.continueConversation(appId, proactiveRef, async (ctx) => {
|
|
622
|
-
await ctx.deleteActivity(activityId);
|
|
623
|
-
});
|
|
624
|
-
} catch (err) {
|
|
625
|
-
const classification = classifyMSTeamsSendError(err);
|
|
626
|
-
const hint = formatMSTeamsSendErrorHint(classification);
|
|
627
|
-
const status = classification.statusCode ? ` (HTTP ${classification.statusCode})` : "";
|
|
628
|
-
throw new Error(
|
|
629
|
-
`msteams delete failed${status}: ${formatUnknownError(err)}${hint ? ` (${hint})` : ""}`,
|
|
630
|
-
{ cause: err },
|
|
631
|
-
);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
log.info("deleted proactive message", { conversationId, activityId });
|
|
635
|
-
|
|
636
|
-
return { conversationId };
|
|
637
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
clearMSTeamsSentMessageCache,
|
|
4
|
-
recordMSTeamsSentMessage,
|
|
5
|
-
wasMSTeamsMessageSent,
|
|
6
|
-
} from "./sent-message-cache.js";
|
|
7
|
-
|
|
8
|
-
describe("msteams sent message cache", () => {
|
|
9
|
-
it("records and resolves sent message ids", () => {
|
|
10
|
-
clearMSTeamsSentMessageCache();
|
|
11
|
-
recordMSTeamsSentMessage("conv-1", "msg-1");
|
|
12
|
-
expect(wasMSTeamsMessageSent("conv-1", "msg-1")).toBe(true);
|
|
13
|
-
expect(wasMSTeamsMessageSent("conv-1", "msg-2")).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
2
|
-
const MSTEAMS_SENT_MESSAGES_KEY = Symbol.for("openclaw.msteamsSentMessages");
|
|
3
|
-
|
|
4
|
-
let sentMessageCache: Map<string, Map<string, number>> | undefined;
|
|
5
|
-
|
|
6
|
-
function getSentMessageCache(): Map<string, Map<string, number>> {
|
|
7
|
-
if (!sentMessageCache) {
|
|
8
|
-
const globalStore = globalThis as Record<PropertyKey, unknown>;
|
|
9
|
-
sentMessageCache =
|
|
10
|
-
(globalStore[MSTEAMS_SENT_MESSAGES_KEY] as Map<string, Map<string, number>> | undefined) ??
|
|
11
|
-
new Map<string, Map<string, number>>();
|
|
12
|
-
globalStore[MSTEAMS_SENT_MESSAGES_KEY] = sentMessageCache;
|
|
13
|
-
}
|
|
14
|
-
return sentMessageCache;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function cleanupExpired(scopeKey: string, entry: Map<string, number>, now: number): void {
|
|
18
|
-
for (const [id, timestamp] of entry) {
|
|
19
|
-
if (now - timestamp > TTL_MS) {
|
|
20
|
-
entry.delete(id);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (entry.size === 0) {
|
|
24
|
-
getSentMessageCache().delete(scopeKey);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function recordMSTeamsSentMessage(conversationId: string, messageId: string): void {
|
|
29
|
-
if (!conversationId || !messageId) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const now = Date.now();
|
|
33
|
-
const store = getSentMessageCache();
|
|
34
|
-
let entry = store.get(conversationId);
|
|
35
|
-
if (!entry) {
|
|
36
|
-
entry = new Map<string, number>();
|
|
37
|
-
store.set(conversationId, entry);
|
|
38
|
-
}
|
|
39
|
-
entry.set(messageId, now);
|
|
40
|
-
if (entry.size > 200) {
|
|
41
|
-
cleanupExpired(conversationId, entry, now);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function wasMSTeamsMessageSent(conversationId: string, messageId: string): boolean {
|
|
46
|
-
const entry = getSentMessageCache().get(conversationId);
|
|
47
|
-
if (!entry) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
cleanupExpired(conversationId, entry, Date.now());
|
|
51
|
-
return entry.has(messageId);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function clearMSTeamsSentMessageCache(): void {
|
|
55
|
-
getSentMessageCache().clear();
|
|
56
|
-
}
|