@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/monitor-handler.ts
DELETED
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
4
|
-
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
|
|
5
|
-
import { formatUnknownError } from "./errors.js";
|
|
6
|
-
import { buildFeedbackEvent, runFeedbackReflection } from "./feedback-reflection.js";
|
|
7
|
-
import { respondToMSTeamsFileConsentInvoke } from "./file-consent-invoke.js";
|
|
8
|
-
import { extractMSTeamsConversationMessageId, normalizeMSTeamsConversationId } from "./inbound.js";
|
|
9
|
-
import { resolveMSTeamsSenderAccess } from "./monitor-handler/access.js";
|
|
10
|
-
import { createMSTeamsMessageHandler } from "./monitor-handler/message-handler.js";
|
|
11
|
-
import { createMSTeamsReactionHandler } from "./monitor-handler/reaction-handler.js";
|
|
12
|
-
import { getMSTeamsRuntime } from "./runtime.js";
|
|
13
|
-
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
|
14
|
-
import {
|
|
15
|
-
handleSigninTokenExchangeInvoke,
|
|
16
|
-
handleSigninVerifyStateInvoke,
|
|
17
|
-
parseSigninTokenExchangeValue,
|
|
18
|
-
parseSigninVerifyStateValue,
|
|
19
|
-
} from "./sso.js";
|
|
20
|
-
import { buildGroupWelcomeText, buildWelcomeCard } from "./welcome-card.js";
|
|
21
|
-
export type { MSTeamsMessageHandlerDeps } from "./monitor-handler.types.js";
|
|
22
|
-
import type { MSTeamsMessageHandlerDeps } from "./monitor-handler.types.js";
|
|
23
|
-
|
|
24
|
-
export type MSTeamsActivityHandler = {
|
|
25
|
-
onMessage: (
|
|
26
|
-
handler: (context: unknown, next: () => Promise<void>) => Promise<void>,
|
|
27
|
-
) => MSTeamsActivityHandler;
|
|
28
|
-
onMembersAdded: (
|
|
29
|
-
handler: (context: unknown, next: () => Promise<void>) => Promise<void>,
|
|
30
|
-
) => MSTeamsActivityHandler;
|
|
31
|
-
onReactionsAdded: (
|
|
32
|
-
handler: (context: unknown, next: () => Promise<void>) => Promise<void>,
|
|
33
|
-
) => MSTeamsActivityHandler;
|
|
34
|
-
onReactionsRemoved: (
|
|
35
|
-
handler: (context: unknown, next: () => Promise<void>) => Promise<void>,
|
|
36
|
-
) => MSTeamsActivityHandler;
|
|
37
|
-
run?: (context: unknown) => Promise<void>;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function serializeAdaptiveCardActionValue(value: unknown): string | null {
|
|
41
|
-
if (typeof value === "string") {
|
|
42
|
-
const trimmed = value.trim();
|
|
43
|
-
return trimmed ? trimmed : null;
|
|
44
|
-
}
|
|
45
|
-
if (value === undefined) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
return JSON.stringify(value);
|
|
50
|
-
} catch {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function isInvokeAuthorized(params: {
|
|
56
|
-
context: MSTeamsTurnContext;
|
|
57
|
-
deps: MSTeamsMessageHandlerDeps;
|
|
58
|
-
deniedLogs: {
|
|
59
|
-
dm: string;
|
|
60
|
-
channel: string;
|
|
61
|
-
group: string;
|
|
62
|
-
};
|
|
63
|
-
includeInvokeName?: boolean;
|
|
64
|
-
}): Promise<boolean> {
|
|
65
|
-
const { context, deps, deniedLogs, includeInvokeName = false } = params;
|
|
66
|
-
const resolved = await resolveMSTeamsSenderAccess({
|
|
67
|
-
cfg: deps.cfg,
|
|
68
|
-
activity: context.activity,
|
|
69
|
-
});
|
|
70
|
-
const { msteamsCfg, isDirectMessage, conversationId, senderId } = resolved;
|
|
71
|
-
if (!msteamsCfg) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const maybeInvokeName = includeInvokeName ? { name: context.activity.name } : undefined;
|
|
76
|
-
|
|
77
|
-
if (isDirectMessage && resolved.access.decision !== "allow") {
|
|
78
|
-
deps.log.debug?.(deniedLogs.dm, {
|
|
79
|
-
sender: senderId,
|
|
80
|
-
conversationId,
|
|
81
|
-
...maybeInvokeName,
|
|
82
|
-
});
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
!isDirectMessage &&
|
|
88
|
-
resolved.channelGate.allowlistConfigured &&
|
|
89
|
-
!resolved.channelGate.allowed
|
|
90
|
-
) {
|
|
91
|
-
deps.log.debug?.(deniedLogs.channel, {
|
|
92
|
-
conversationId,
|
|
93
|
-
teamKey: resolved.channelGate.teamKey ?? "none",
|
|
94
|
-
channelKey: resolved.channelGate.channelKey ?? "none",
|
|
95
|
-
...maybeInvokeName,
|
|
96
|
-
});
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!isDirectMessage && !resolved.senderGroupAccess.allowed) {
|
|
101
|
-
deps.log.debug?.(deniedLogs.group, {
|
|
102
|
-
sender: senderId,
|
|
103
|
-
conversationId,
|
|
104
|
-
...maybeInvokeName,
|
|
105
|
-
});
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function isFeedbackInvokeAuthorized(
|
|
113
|
-
context: MSTeamsTurnContext,
|
|
114
|
-
deps: MSTeamsMessageHandlerDeps,
|
|
115
|
-
): Promise<boolean> {
|
|
116
|
-
return isInvokeAuthorized({
|
|
117
|
-
context,
|
|
118
|
-
deps,
|
|
119
|
-
deniedLogs: {
|
|
120
|
-
dm: "dropping feedback invoke (dm sender not allowlisted)",
|
|
121
|
-
channel: "dropping feedback invoke (not in team/channel allowlist)",
|
|
122
|
-
group: "dropping feedback invoke (group sender not allowlisted)",
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function isSigninInvokeAuthorized(
|
|
128
|
-
context: MSTeamsTurnContext,
|
|
129
|
-
deps: MSTeamsMessageHandlerDeps,
|
|
130
|
-
): Promise<boolean> {
|
|
131
|
-
return isInvokeAuthorized({
|
|
132
|
-
context,
|
|
133
|
-
deps,
|
|
134
|
-
deniedLogs: {
|
|
135
|
-
dm: "dropping signin invoke (dm sender not allowlisted)",
|
|
136
|
-
channel: "dropping signin invoke (not in team/channel allowlist)",
|
|
137
|
-
group: "dropping signin invoke (group sender not allowlisted)",
|
|
138
|
-
},
|
|
139
|
-
includeInvokeName: true,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Parse and handle feedback invoke activities (thumbs up/down).
|
|
145
|
-
* Returns true if the activity was a feedback invoke, false otherwise.
|
|
146
|
-
*/
|
|
147
|
-
async function handleFeedbackInvoke(
|
|
148
|
-
context: MSTeamsTurnContext,
|
|
149
|
-
deps: MSTeamsMessageHandlerDeps,
|
|
150
|
-
): Promise<boolean> {
|
|
151
|
-
const activity = context.activity;
|
|
152
|
-
const value = activity.value as
|
|
153
|
-
| {
|
|
154
|
-
actionName?: string;
|
|
155
|
-
actionValue?: { reaction?: string; feedback?: string };
|
|
156
|
-
replyToId?: string;
|
|
157
|
-
}
|
|
158
|
-
| undefined;
|
|
159
|
-
|
|
160
|
-
if (!value) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Teams feedback invoke format: actionName="feedback", actionValue.reaction="like"|"dislike"
|
|
165
|
-
if (value.actionName !== "feedback") {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const reaction = value.actionValue?.reaction;
|
|
170
|
-
if (reaction !== "like" && reaction !== "dislike") {
|
|
171
|
-
deps.log.debug?.("ignoring feedback with unknown reaction", { reaction });
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const msteamsCfg = deps.cfg.channels?.msteams;
|
|
176
|
-
if (msteamsCfg?.feedbackEnabled === false) {
|
|
177
|
-
deps.log.debug?.("feedback handling disabled");
|
|
178
|
-
return true; // Still consume the invoke
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (!(await isFeedbackInvokeAuthorized(context, deps))) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Extract user comment from the nested JSON string
|
|
186
|
-
let userComment: string | undefined;
|
|
187
|
-
if (value.actionValue?.feedback) {
|
|
188
|
-
try {
|
|
189
|
-
const parsed = JSON.parse(value.actionValue.feedback) as { feedbackText?: string };
|
|
190
|
-
userComment = parsed.feedbackText || undefined;
|
|
191
|
-
} catch {
|
|
192
|
-
// Best effort — feedback text is optional
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Strip ;messageid=... suffix to match the normalized ID used by the message handler.
|
|
197
|
-
const rawConversationId = activity.conversation?.id ?? "unknown";
|
|
198
|
-
const conversationId = normalizeMSTeamsConversationId(rawConversationId);
|
|
199
|
-
const senderId = activity.from?.aadObjectId ?? activity.from?.id ?? "unknown";
|
|
200
|
-
const messageId = value.replyToId ?? activity.replyToId ?? "unknown";
|
|
201
|
-
const isNegative = reaction === "dislike";
|
|
202
|
-
|
|
203
|
-
// Route feedback using the same chat-type logic as normal messages
|
|
204
|
-
// so session keys, agent IDs, and transcript paths match.
|
|
205
|
-
const convType = normalizeOptionalLowercaseString(activity.conversation?.conversationType);
|
|
206
|
-
const isDirectMessage = convType === "personal" || (!convType && !activity.conversation?.isGroup);
|
|
207
|
-
const isChannel = convType === "channel";
|
|
208
|
-
|
|
209
|
-
const core = getMSTeamsRuntime();
|
|
210
|
-
const route = core.channel.routing.resolveAgentRoute({
|
|
211
|
-
cfg: deps.cfg,
|
|
212
|
-
channel: "msteams",
|
|
213
|
-
peer: {
|
|
214
|
-
kind: isDirectMessage ? "direct" : isChannel ? "channel" : "group",
|
|
215
|
-
id: isDirectMessage ? senderId : conversationId,
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// Match the thread-aware session key used by the message handler so feedback
|
|
220
|
-
// events land in the correct per-thread transcript. For channel threads, the
|
|
221
|
-
// thread root ID comes from the ;messageid= suffix on the conversation ID or
|
|
222
|
-
// from activity.replyToId.
|
|
223
|
-
const feedbackThreadId = isChannel
|
|
224
|
-
? (extractMSTeamsConversationMessageId(rawConversationId) ?? activity.replyToId ?? undefined)
|
|
225
|
-
: undefined;
|
|
226
|
-
if (feedbackThreadId) {
|
|
227
|
-
const threadKeys = resolveThreadSessionKeys({
|
|
228
|
-
baseSessionKey: route.sessionKey,
|
|
229
|
-
threadId: feedbackThreadId,
|
|
230
|
-
parentSessionKey: route.sessionKey,
|
|
231
|
-
});
|
|
232
|
-
route.sessionKey = threadKeys.sessionKey;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Log feedback event to session JSONL
|
|
236
|
-
const feedbackEvent = buildFeedbackEvent({
|
|
237
|
-
messageId,
|
|
238
|
-
value: isNegative ? "negative" : "positive",
|
|
239
|
-
comment: userComment,
|
|
240
|
-
sessionKey: route.sessionKey,
|
|
241
|
-
agentId: route.agentId,
|
|
242
|
-
conversationId,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
deps.log.info("received feedback", {
|
|
246
|
-
value: feedbackEvent.value,
|
|
247
|
-
messageId,
|
|
248
|
-
conversationId,
|
|
249
|
-
hasComment: Boolean(userComment),
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// Write feedback event to session transcript
|
|
253
|
-
try {
|
|
254
|
-
const storePath = core.channel.session.resolveStorePath(deps.cfg.session?.store, {
|
|
255
|
-
agentId: route.agentId,
|
|
256
|
-
});
|
|
257
|
-
const safeKey = route.sessionKey.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
258
|
-
const transcriptFile = path.join(storePath, `${safeKey}.jsonl`);
|
|
259
|
-
await fs.appendFile(transcriptFile, JSON.stringify(feedbackEvent) + "\n", "utf-8").catch(() => {
|
|
260
|
-
// Best effort — transcript dir may not exist yet
|
|
261
|
-
});
|
|
262
|
-
} catch {
|
|
263
|
-
// Best effort
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Build conversation reference for proactive messages (ack + reflection follow-up)
|
|
267
|
-
const conversationRef = {
|
|
268
|
-
activityId: activity.id,
|
|
269
|
-
user: {
|
|
270
|
-
id: activity.from?.id,
|
|
271
|
-
name: activity.from?.name,
|
|
272
|
-
aadObjectId: activity.from?.aadObjectId,
|
|
273
|
-
},
|
|
274
|
-
agent: activity.recipient
|
|
275
|
-
? { id: activity.recipient.id, name: activity.recipient.name }
|
|
276
|
-
: undefined,
|
|
277
|
-
bot: activity.recipient
|
|
278
|
-
? { id: activity.recipient.id, name: activity.recipient.name }
|
|
279
|
-
: undefined,
|
|
280
|
-
conversation: {
|
|
281
|
-
id: conversationId,
|
|
282
|
-
conversationType: activity.conversation?.conversationType,
|
|
283
|
-
tenantId: activity.conversation?.tenantId,
|
|
284
|
-
},
|
|
285
|
-
channelId: activity.channelId ?? "msteams",
|
|
286
|
-
serviceUrl: activity.serviceUrl,
|
|
287
|
-
locale: activity.locale,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// For negative feedback, trigger background reflection (fire-and-forget).
|
|
291
|
-
// No ack message — the reflection follow-up serves as the acknowledgement.
|
|
292
|
-
// Sending anything during the invoke handler causes "unable to reach app" errors.
|
|
293
|
-
if (isNegative && msteamsCfg?.feedbackReflection !== false) {
|
|
294
|
-
// Note: thumbedDownResponse is not populated here because we don't cache
|
|
295
|
-
// sent message text. The agent still has full session context for reflection
|
|
296
|
-
// since the reflection runs in the same session. The user comment (if any)
|
|
297
|
-
// provides additional signal.
|
|
298
|
-
runFeedbackReflection({
|
|
299
|
-
cfg: deps.cfg,
|
|
300
|
-
adapter: deps.adapter,
|
|
301
|
-
appId: deps.appId,
|
|
302
|
-
conversationRef,
|
|
303
|
-
sessionKey: route.sessionKey,
|
|
304
|
-
agentId: route.agentId,
|
|
305
|
-
conversationId,
|
|
306
|
-
feedbackMessageId: messageId,
|
|
307
|
-
userComment,
|
|
308
|
-
log: deps.log,
|
|
309
|
-
}).catch((err) => {
|
|
310
|
-
deps.log.error("feedback reflection failed", { error: formatUnknownError(err) });
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export function registerMSTeamsHandlers<T extends MSTeamsActivityHandler>(
|
|
318
|
-
handler: T,
|
|
319
|
-
deps: MSTeamsMessageHandlerDeps,
|
|
320
|
-
): T {
|
|
321
|
-
const handleTeamsMessage = createMSTeamsMessageHandler(deps);
|
|
322
|
-
const handleReaction = createMSTeamsReactionHandler(deps);
|
|
323
|
-
|
|
324
|
-
// Wrap the original run method to intercept invokes
|
|
325
|
-
const originalRun = handler.run;
|
|
326
|
-
if (originalRun) {
|
|
327
|
-
handler.run = async (context: unknown) => {
|
|
328
|
-
const ctx = context as MSTeamsTurnContext;
|
|
329
|
-
// Handle file consent invokes before passing to normal flow
|
|
330
|
-
if (ctx.activity?.type === "invoke" && ctx.activity?.name === "fileConsent/invoke") {
|
|
331
|
-
await respondToMSTeamsFileConsentInvoke(ctx, deps.log);
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Handle feedback invokes (thumbs up/down on AI-generated messages).
|
|
336
|
-
// Just return after handling — the process() handler sends HTTP 200 automatically.
|
|
337
|
-
// Do NOT call sendActivity with invokeResponse; our custom adapter would POST
|
|
338
|
-
// a new activity to Bot Framework instead of responding to the HTTP request.
|
|
339
|
-
if (ctx.activity?.type === "invoke" && ctx.activity?.name === "message/submitAction") {
|
|
340
|
-
const handled = await handleFeedbackInvoke(ctx, deps);
|
|
341
|
-
if (handled) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (ctx.activity?.type === "invoke" && ctx.activity?.name === "adaptiveCard/action") {
|
|
347
|
-
const text = serializeAdaptiveCardActionValue(ctx.activity?.value);
|
|
348
|
-
if (text) {
|
|
349
|
-
await handleTeamsMessage({
|
|
350
|
-
...ctx,
|
|
351
|
-
activity: {
|
|
352
|
-
...ctx.activity,
|
|
353
|
-
type: "message",
|
|
354
|
-
text,
|
|
355
|
-
},
|
|
356
|
-
});
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
deps.log.debug?.("skipping adaptive card action invoke without value payload");
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Bot Framework OAuth SSO: Teams sends signin/tokenExchange (with a
|
|
363
|
-
// Teams-provided exchangeable token) or signin/verifyState (magic
|
|
364
|
-
// code fallback) after an oauthCard is presented. We must ack with
|
|
365
|
-
// HTTP 200 and, if configured, exchange the token with the Bot
|
|
366
|
-
// Framework User Token service and persist it for downstream tools.
|
|
367
|
-
if (
|
|
368
|
-
ctx.activity?.type === "invoke" &&
|
|
369
|
-
(ctx.activity?.name === "signin/tokenExchange" ||
|
|
370
|
-
ctx.activity?.name === "signin/verifyState")
|
|
371
|
-
) {
|
|
372
|
-
// Always ack immediately — silently dropping the invoke causes
|
|
373
|
-
// the Teams card UI to report "Something went wrong".
|
|
374
|
-
await ctx.sendActivity({ type: "invokeResponse", value: { status: 200, body: {} } });
|
|
375
|
-
|
|
376
|
-
if (!(await isSigninInvokeAuthorized(ctx, deps))) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (!deps.sso) {
|
|
381
|
-
deps.log.debug?.("signin invoke received but msteams.sso is not configured", {
|
|
382
|
-
name: ctx.activity.name,
|
|
383
|
-
});
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const user = {
|
|
388
|
-
userId: ctx.activity.from?.aadObjectId ?? ctx.activity.from?.id ?? "",
|
|
389
|
-
channelId: ctx.activity.channelId ?? "msteams",
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
try {
|
|
393
|
-
if (ctx.activity.name === "signin/tokenExchange") {
|
|
394
|
-
const parsed = parseSigninTokenExchangeValue(ctx.activity.value);
|
|
395
|
-
if (!parsed) {
|
|
396
|
-
deps.log.debug?.("invalid signin/tokenExchange invoke value");
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
const result = await handleSigninTokenExchangeInvoke({
|
|
400
|
-
value: parsed,
|
|
401
|
-
user,
|
|
402
|
-
deps: deps.sso,
|
|
403
|
-
});
|
|
404
|
-
if (result.ok) {
|
|
405
|
-
deps.log.info("msteams sso token exchanged", {
|
|
406
|
-
userId: user.userId,
|
|
407
|
-
hasExpiry: Boolean(result.expiresAt),
|
|
408
|
-
});
|
|
409
|
-
} else {
|
|
410
|
-
deps.log.error("msteams sso token exchange failed", {
|
|
411
|
-
code: result.code,
|
|
412
|
-
status: result.status,
|
|
413
|
-
message: result.message,
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// signin/verifyState
|
|
420
|
-
const parsed = parseSigninVerifyStateValue(ctx.activity.value);
|
|
421
|
-
if (!parsed) {
|
|
422
|
-
deps.log.debug?.("invalid signin/verifyState invoke value");
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const result = await handleSigninVerifyStateInvoke({
|
|
426
|
-
value: parsed,
|
|
427
|
-
user,
|
|
428
|
-
deps: deps.sso,
|
|
429
|
-
});
|
|
430
|
-
if (result.ok) {
|
|
431
|
-
deps.log.info("msteams sso verifyState succeeded", {
|
|
432
|
-
userId: user.userId,
|
|
433
|
-
hasExpiry: Boolean(result.expiresAt),
|
|
434
|
-
});
|
|
435
|
-
} else {
|
|
436
|
-
deps.log.error("msteams sso verifyState failed", {
|
|
437
|
-
code: result.code,
|
|
438
|
-
status: result.status,
|
|
439
|
-
message: result.message,
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
} catch (err) {
|
|
443
|
-
deps.log.error("msteams sso invoke handler error", {
|
|
444
|
-
error: formatUnknownError(err),
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
return originalRun.call(handler, context);
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
handler.onMessage(async (context, next) => {
|
|
455
|
-
try {
|
|
456
|
-
await handleTeamsMessage(context as MSTeamsTurnContext);
|
|
457
|
-
} catch (err) {
|
|
458
|
-
deps.runtime.error?.(`msteams handler failed: ${formatUnknownError(err)}`);
|
|
459
|
-
}
|
|
460
|
-
await next();
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
handler.onMembersAdded(async (context, next) => {
|
|
464
|
-
const ctx = context as MSTeamsTurnContext;
|
|
465
|
-
const membersAdded = ctx.activity?.membersAdded ?? [];
|
|
466
|
-
const botId = ctx.activity?.recipient?.id;
|
|
467
|
-
const msteamsCfg = deps.cfg.channels?.msteams;
|
|
468
|
-
|
|
469
|
-
for (const member of membersAdded) {
|
|
470
|
-
if (member.id === botId) {
|
|
471
|
-
// Bot was added to a conversation — send welcome card if configured.
|
|
472
|
-
const conversationType =
|
|
473
|
-
normalizeOptionalLowercaseString(ctx.activity?.conversation?.conversationType) ??
|
|
474
|
-
"personal";
|
|
475
|
-
const isPersonal = conversationType === "personal";
|
|
476
|
-
|
|
477
|
-
if (isPersonal && msteamsCfg?.welcomeCard !== false) {
|
|
478
|
-
const botName = ctx.activity?.recipient?.name ?? undefined;
|
|
479
|
-
const card = buildWelcomeCard({
|
|
480
|
-
botName,
|
|
481
|
-
promptStarters: msteamsCfg?.promptStarters,
|
|
482
|
-
});
|
|
483
|
-
try {
|
|
484
|
-
await ctx.sendActivity({
|
|
485
|
-
type: "message",
|
|
486
|
-
attachments: [
|
|
487
|
-
{
|
|
488
|
-
contentType: "application/vnd.microsoft.card.adaptive",
|
|
489
|
-
content: card,
|
|
490
|
-
},
|
|
491
|
-
],
|
|
492
|
-
});
|
|
493
|
-
deps.log.info("sent welcome card");
|
|
494
|
-
} catch (err) {
|
|
495
|
-
deps.log.debug?.("failed to send welcome card", { error: formatUnknownError(err) });
|
|
496
|
-
}
|
|
497
|
-
} else if (!isPersonal && msteamsCfg?.groupWelcomeCard === true) {
|
|
498
|
-
const botName = ctx.activity?.recipient?.name ?? undefined;
|
|
499
|
-
try {
|
|
500
|
-
await ctx.sendActivity(buildGroupWelcomeText(botName));
|
|
501
|
-
deps.log.info("sent group welcome message");
|
|
502
|
-
} catch (err) {
|
|
503
|
-
deps.log.debug?.("failed to send group welcome", { error: formatUnknownError(err) });
|
|
504
|
-
}
|
|
505
|
-
} else {
|
|
506
|
-
deps.log.debug?.("skipping welcome (disabled by config or conversation type)");
|
|
507
|
-
}
|
|
508
|
-
} else {
|
|
509
|
-
deps.log.debug?.("member added", { member: member.id });
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
await next();
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
handler.onReactionsAdded(async (context, next) => {
|
|
516
|
-
try {
|
|
517
|
-
await handleReaction(context as MSTeamsTurnContext, "added");
|
|
518
|
-
} catch (err) {
|
|
519
|
-
deps.runtime.error?.(`msteams reaction handler failed: ${String(err)}`);
|
|
520
|
-
}
|
|
521
|
-
await next();
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
handler.onReactionsRemoved(async (context, next) => {
|
|
525
|
-
try {
|
|
526
|
-
await handleReaction(context as MSTeamsTurnContext, "removed");
|
|
527
|
-
} catch (err) {
|
|
528
|
-
deps.runtime.error?.(`msteams reaction handler failed: ${String(err)}`);
|
|
529
|
-
}
|
|
530
|
-
await next();
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
return handler;
|
|
534
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type OpenClawConfig, type RuntimeEnv } from "../runtime-api.js";
|
|
2
|
-
import type { MSTeamsConversationStore } from "./conversation-store.js";
|
|
3
|
-
import type { MSTeamsAdapter } from "./messenger.js";
|
|
4
|
-
import type { MSTeamsMonitorLogger } from "./monitor-types.js";
|
|
5
|
-
import type { MSTeamsPollStore } from "./polls.js";
|
|
6
|
-
import type { MSTeamsSsoDeps } from "./sso.js";
|
|
7
|
-
|
|
8
|
-
export type MSTeamsMessageHandlerDeps = {
|
|
9
|
-
cfg: OpenClawConfig;
|
|
10
|
-
runtime: RuntimeEnv;
|
|
11
|
-
appId: string;
|
|
12
|
-
adapter: MSTeamsAdapter;
|
|
13
|
-
tokenProvider: {
|
|
14
|
-
getAccessToken: (scope: string) => Promise<string>;
|
|
15
|
-
};
|
|
16
|
-
textLimit: number;
|
|
17
|
-
mediaMaxBytes: number;
|
|
18
|
-
conversationStore: MSTeamsConversationStore;
|
|
19
|
-
pollStore: MSTeamsPollStore;
|
|
20
|
-
log: MSTeamsMonitorLogger;
|
|
21
|
-
/**
|
|
22
|
-
* Optional Bot Framework OAuth SSO deps. When omitted the plugin
|
|
23
|
-
* does not handle `signin/tokenExchange` or `signin/verifyState`
|
|
24
|
-
* invokes, matching the pre-SSO behavior.
|
|
25
|
-
*/
|
|
26
|
-
sso?: MSTeamsSsoDeps;
|
|
27
|
-
};
|
package/src/monitor-types.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type MSTeamsMonitorLogger = {
|
|
2
|
-
debug?: (message: string, meta?: Record<string, unknown>) => void;
|
|
3
|
-
info: (message: string, meta?: Record<string, unknown>) => void;
|
|
4
|
-
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
5
|
-
error: (message: string, meta?: Record<string, unknown>) => void;
|
|
6
|
-
};
|