@openclaw/msteams 2026.3.13 → 2026.5.1-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/api.ts +3 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +2 -0
- package/config-api.ts +4 -0
- package/contract-api.ts +4 -0
- package/index.ts +15 -12
- package/openclaw.plugin.json +553 -1
- package/package.json +46 -12
- package/runtime-api.ts +73 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/setup-plugin-api.ts +3 -0
- package/src/ai-entity.ts +7 -0
- package/src/approval-auth.ts +44 -0
- package/src/attachments/bot-framework.test.ts +461 -0
- package/src/attachments/bot-framework.ts +362 -0
- package/src/attachments/download.ts +63 -19
- package/src/attachments/graph.test.ts +416 -0
- package/src/attachments/graph.ts +163 -72
- package/src/attachments/html.ts +33 -1
- package/src/attachments/payload.ts +1 -1
- package/src/attachments/remote-media.test.ts +137 -0
- package/src/attachments/remote-media.ts +75 -8
- package/src/attachments/shared.test.ts +138 -1
- package/src/attachments/shared.ts +193 -26
- package/src/attachments/types.ts +10 -0
- package/src/attachments.graph.test.ts +342 -0
- package/src/attachments.helpers.test.ts +246 -0
- package/src/attachments.test-helpers.ts +17 -0
- package/src/attachments.test.ts +163 -418
- package/src/attachments.ts +5 -5
- package/src/block-streaming-config.test.ts +61 -0
- package/src/channel-api.ts +1 -0
- package/src/channel.actions.test.ts +742 -0
- package/src/channel.directory.test.ts +145 -4
- package/src/channel.runtime.ts +56 -0
- package/src/channel.setup.ts +77 -0
- package/src/channel.test.ts +128 -0
- package/src/channel.ts +1077 -395
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +12 -0
- package/src/conversation-store-fs.test.ts +4 -5
- package/src/conversation-store-fs.ts +35 -51
- package/src/conversation-store-helpers.test.ts +202 -0
- package/src/conversation-store-helpers.ts +105 -0
- package/src/conversation-store-memory.ts +27 -23
- package/src/conversation-store.shared.test.ts +225 -0
- package/src/conversation-store.ts +30 -0
- package/src/directory-live.test.ts +156 -0
- package/src/directory-live.ts +7 -4
- package/src/doctor.ts +27 -0
- package/src/errors.test.ts +64 -1
- package/src/errors.ts +50 -9
- package/src/feedback-reflection-prompt.ts +117 -0
- package/src/feedback-reflection-store.ts +114 -0
- package/src/feedback-reflection.test.ts +237 -0
- package/src/feedback-reflection.ts +283 -0
- package/src/file-consent-helpers.test.ts +83 -0
- package/src/file-consent-helpers.ts +64 -11
- package/src/file-consent-invoke.ts +150 -0
- package/src/file-consent.test.ts +363 -0
- package/src/file-consent.ts +165 -4
- package/src/graph-chat.ts +5 -3
- package/src/graph-group-management.test.ts +318 -0
- package/src/graph-group-management.ts +168 -0
- package/src/graph-members.test.ts +89 -0
- package/src/graph-members.ts +48 -0
- package/src/graph-messages.actions.test.ts +243 -0
- package/src/graph-messages.read.test.ts +391 -0
- package/src/graph-messages.search.test.ts +213 -0
- package/src/graph-messages.test-helpers.ts +50 -0
- package/src/graph-messages.ts +534 -0
- package/src/graph-teams.test.ts +215 -0
- package/src/graph-teams.ts +114 -0
- package/src/graph-thread.test.ts +246 -0
- package/src/graph-thread.ts +146 -0
- package/src/graph-upload.test.ts +161 -4
- package/src/graph-upload.ts +147 -56
- package/src/graph.test.ts +516 -0
- package/src/graph.ts +233 -21
- package/src/inbound.test.ts +156 -1
- package/src/inbound.ts +101 -1
- package/src/media-helpers.ts +1 -1
- package/src/mentions.test.ts +27 -18
- package/src/mentions.ts +2 -2
- package/src/messenger.test.ts +504 -23
- package/src/messenger.ts +133 -52
- package/src/monitor-handler/access.ts +125 -0
- package/src/monitor-handler/inbound-media.test.ts +289 -0
- package/src/monitor-handler/inbound-media.ts +57 -5
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
- package/src/monitor-handler/message-handler.authz.test.ts +588 -74
- package/src/monitor-handler/message-handler.dm-media.test.ts +54 -0
- package/src/monitor-handler/message-handler.test-support.ts +100 -0
- package/src/monitor-handler/message-handler.thread-parent.test.ts +223 -0
- package/src/monitor-handler/message-handler.thread-session.test.ts +77 -0
- package/src/monitor-handler/message-handler.ts +470 -164
- package/src/monitor-handler/reaction-handler.test.ts +267 -0
- package/src/monitor-handler/reaction-handler.ts +210 -0
- package/src/monitor-handler/thread-session.ts +17 -0
- package/src/monitor-handler.adaptive-card.test.ts +162 -0
- package/src/monitor-handler.feedback-authz.test.ts +314 -0
- package/src/monitor-handler.file-consent.test.ts +281 -79
- package/src/monitor-handler.sso.test.ts +563 -0
- package/src/monitor-handler.test-helpers.ts +180 -0
- package/src/monitor-handler.ts +459 -115
- package/src/monitor-handler.types.ts +27 -0
- package/src/monitor-types.ts +1 -0
- package/src/monitor.lifecycle.test.ts +74 -10
- package/src/monitor.test.ts +35 -1
- package/src/monitor.ts +143 -46
- package/src/oauth.flow.ts +77 -0
- package/src/oauth.shared.ts +37 -0
- package/src/oauth.test.ts +305 -0
- package/src/oauth.token.ts +158 -0
- package/src/oauth.ts +130 -0
- package/src/outbound.test.ts +10 -11
- package/src/outbound.ts +62 -44
- package/src/pending-uploads-fs.test.ts +246 -0
- package/src/pending-uploads-fs.ts +235 -0
- package/src/pending-uploads.test.ts +173 -0
- package/src/pending-uploads.ts +34 -2
- package/src/policy.test.ts +11 -5
- package/src/policy.ts +5 -5
- package/src/polls.test.ts +106 -5
- package/src/polls.ts +15 -7
- package/src/presentation.ts +68 -0
- package/src/probe.test.ts +27 -8
- package/src/probe.ts +43 -9
- package/src/reply-dispatcher.test.ts +437 -0
- package/src/reply-dispatcher.ts +259 -73
- package/src/reply-stream-controller.test.ts +235 -0
- package/src/reply-stream-controller.ts +147 -0
- package/src/resolve-allowlist.test.ts +105 -1
- package/src/resolve-allowlist.ts +112 -7
- package/src/runtime.ts +6 -3
- package/src/sdk-types.ts +43 -3
- package/src/sdk.test.ts +666 -0
- package/src/sdk.ts +867 -16
- package/src/secret-contract.ts +49 -0
- package/src/secret-input.ts +1 -1
- package/src/send-context.ts +76 -9
- package/src/send.test.ts +389 -5
- package/src/send.ts +140 -32
- package/src/sent-message-cache.ts +30 -18
- package/src/session-route.ts +40 -0
- package/src/setup-core.ts +160 -0
- package/src/setup-surface.test.ts +202 -0
- package/src/setup-surface.ts +320 -0
- package/src/sso-token-store.test.ts +72 -0
- package/src/sso-token-store.ts +166 -0
- package/src/sso.ts +300 -0
- package/src/storage.ts +1 -1
- package/src/store-fs.ts +2 -2
- package/src/streaming-message.test.ts +262 -0
- package/src/streaming-message.ts +297 -0
- package/src/test-runtime.ts +1 -1
- package/src/thread-parent-context.test.ts +224 -0
- package/src/thread-parent-context.ts +159 -0
- package/src/token.test.ts +237 -50
- package/src/token.ts +162 -7
- package/src/user-agent.test.ts +86 -0
- package/src/user-agent.ts +53 -0
- package/src/webhook-timeouts.ts +27 -0
- package/src/welcome-card.test.ts +81 -0
- package/src/welcome-card.ts +57 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
- package/CHANGELOG.md +0 -107
- package/src/file-lock.ts +0 -1
- package/src/graph-users.test.ts +0 -66
- package/src/onboarding.ts +0 -381
- package/src/polls-store.test.ts +0 -38
- package/src/revoked-context.test.ts +0 -39
- package/src/token-response.test.ts +0 -23
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
+
import type { ReplyPayload } from "../runtime-api.js";
|
|
3
|
+
import { formatUnknownError } from "./errors.js";
|
|
4
|
+
import type { MSTeamsMonitorLogger } from "./monitor-types.js";
|
|
5
|
+
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
|
6
|
+
import { TeamsHttpStream } from "./streaming-message.js";
|
|
7
|
+
|
|
8
|
+
// Local generic wrapper to defer union resolution. Works around a
|
|
9
|
+
// single-file-mode limitation in the type-aware lint where imported
|
|
10
|
+
// types resolved via extension runtime-api barrels are treated as
|
|
11
|
+
// `error` (acting as `any`) and trip `no-redundant-type-constituents`
|
|
12
|
+
// when combined with `undefined` in a union.
|
|
13
|
+
type Maybe<T> = T | undefined;
|
|
14
|
+
|
|
15
|
+
const INFORMATIVE_STATUS_TEXTS = [
|
|
16
|
+
"Thinking...",
|
|
17
|
+
"Working on that...",
|
|
18
|
+
"Checking the details...",
|
|
19
|
+
"Putting an answer together...",
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export function pickInformativeStatusText(random = Math.random): string {
|
|
23
|
+
const index = Math.floor(random() * INFORMATIVE_STATUS_TEXTS.length);
|
|
24
|
+
return INFORMATIVE_STATUS_TEXTS[index] ?? INFORMATIVE_STATUS_TEXTS[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createTeamsReplyStreamController(params: {
|
|
28
|
+
conversationType?: string;
|
|
29
|
+
context: MSTeamsTurnContext;
|
|
30
|
+
feedbackLoopEnabled: boolean;
|
|
31
|
+
log: MSTeamsMonitorLogger;
|
|
32
|
+
random?: () => number;
|
|
33
|
+
}) {
|
|
34
|
+
const isPersonal = normalizeOptionalLowercaseString(params.conversationType) === "personal";
|
|
35
|
+
const stream = isPersonal
|
|
36
|
+
? new TeamsHttpStream({
|
|
37
|
+
sendActivity: (activity) => params.context.sendActivity(activity),
|
|
38
|
+
feedbackLoopEnabled: params.feedbackLoopEnabled,
|
|
39
|
+
onError: (err) => {
|
|
40
|
+
params.log.debug?.(`stream error: ${formatUnknownError(err)}`);
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
: undefined;
|
|
44
|
+
|
|
45
|
+
let streamReceivedTokens = false;
|
|
46
|
+
let informativeUpdateSent = false;
|
|
47
|
+
let pendingFinalize: Promise<void> | undefined;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
async onReplyStart(): Promise<void> {
|
|
51
|
+
if (!stream || informativeUpdateSent) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
informativeUpdateSent = true;
|
|
55
|
+
await stream.sendInformativeUpdate(pickInformativeStatusText(params.random));
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
onPartialReply(payload: { text?: string }): void {
|
|
59
|
+
if (!stream || !payload.text) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
streamReceivedTokens = true;
|
|
63
|
+
stream.update(payload.text);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
preparePayload(payload: ReplyPayload): Maybe<ReplyPayload> {
|
|
67
|
+
if (!stream || !streamReceivedTokens) {
|
|
68
|
+
return payload;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const hasMedia = Boolean(payload.mediaUrl || payload.mediaUrls?.length);
|
|
72
|
+
|
|
73
|
+
// Stream failed after partial delivery (e.g. > 4000 chars). Send only
|
|
74
|
+
// the unstreamed suffix via block delivery to avoid duplicate text.
|
|
75
|
+
if (stream.isFailed) {
|
|
76
|
+
streamReceivedTokens = false;
|
|
77
|
+
|
|
78
|
+
if (!payload.text) {
|
|
79
|
+
return payload;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const streamedLength = stream.streamedLength;
|
|
83
|
+
if (streamedLength <= 0) {
|
|
84
|
+
return payload;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const remainingText = payload.text.slice(streamedLength);
|
|
88
|
+
if (!remainingText) {
|
|
89
|
+
return hasMedia ? { ...payload, text: undefined } : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { ...payload, text: remainingText };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!stream.hasContent || stream.isFinalized) {
|
|
96
|
+
return payload;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Stream handled this text segment. Finalize it and reset so any
|
|
100
|
+
// subsequent text segments (after tool calls) use fallback delivery.
|
|
101
|
+
// finalize() is idempotent; the later call in markDispatchIdle is a no-op.
|
|
102
|
+
streamReceivedTokens = false;
|
|
103
|
+
pendingFinalize = stream.finalize();
|
|
104
|
+
|
|
105
|
+
if (!hasMedia) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return { ...payload, text: undefined };
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async finalize(): Promise<void> {
|
|
112
|
+
await pendingFinalize;
|
|
113
|
+
await stream?.finalize();
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
hasStream(): boolean {
|
|
117
|
+
return Boolean(stream);
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether the Teams streaming card is currently receiving LLM tokens.
|
|
122
|
+
* Used to gate side-channel keepalive activity so we don't overlay plain
|
|
123
|
+
* "typing" indicators on top of a live streaming card.
|
|
124
|
+
*
|
|
125
|
+
* Returns true only while the stream is actively chunking text into the
|
|
126
|
+
* streaming card. The informative update (blue progress bar) is short
|
|
127
|
+
* lived so we intentionally do not count it as "active"; this way the
|
|
128
|
+
* typing keepalive can still fire during the informative window and
|
|
129
|
+
* during tool chains between text segments.
|
|
130
|
+
*
|
|
131
|
+
* Returns false when:
|
|
132
|
+
* - No stream exists (non-personal conversation).
|
|
133
|
+
* - Stream has not yet received any text tokens.
|
|
134
|
+
* - Stream has been finalized (e.g. after the first text segment, while
|
|
135
|
+
* tools run before the next segment).
|
|
136
|
+
*/
|
|
137
|
+
isStreamActive(): boolean {
|
|
138
|
+
if (!stream) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (stream.isFinalized || stream.isFailed) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return streamReceivedTokens;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
listTeamsByName,
|
|
@@ -26,10 +26,19 @@ vi.mock("./graph-users.js", () => ({
|
|
|
26
26
|
}));
|
|
27
27
|
|
|
28
28
|
import {
|
|
29
|
+
looksLikeMSTeamsTargetId,
|
|
29
30
|
resolveMSTeamsChannelAllowlist,
|
|
30
31
|
resolveMSTeamsUserAllowlist,
|
|
31
32
|
} from "./resolve-allowlist.js";
|
|
32
33
|
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
listTeamsByName.mockReset();
|
|
36
|
+
listChannelsForTeam.mockReset();
|
|
37
|
+
normalizeQuery.mockImplementation((value: string) => value.trim().toLowerCase());
|
|
38
|
+
resolveGraphToken.mockReset().mockResolvedValue("graph-token");
|
|
39
|
+
searchGraphUsers.mockReset();
|
|
40
|
+
});
|
|
41
|
+
|
|
33
42
|
describe("resolveMSTeamsUserAllowlist", () => {
|
|
34
43
|
it("marks empty input unresolved", async () => {
|
|
35
44
|
const [result] = await resolveMSTeamsUserAllowlist({ cfg: {}, entries: [" "] });
|
|
@@ -53,6 +62,39 @@ describe("resolveMSTeamsUserAllowlist", () => {
|
|
|
53
62
|
});
|
|
54
63
|
|
|
55
64
|
describe("resolveMSTeamsChannelAllowlist", () => {
|
|
65
|
+
it("keeps configured Teams conversation IDs resolved without Graph lookup", async () => {
|
|
66
|
+
const [result] = await resolveMSTeamsChannelAllowlist({
|
|
67
|
+
cfg: {},
|
|
68
|
+
entries: ["19:team-general@thread.skype/19:roadmap@thread.skype"],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result).toEqual({
|
|
72
|
+
input: "19:team-general@thread.skype/19:roadmap@thread.skype",
|
|
73
|
+
resolved: true,
|
|
74
|
+
teamId: "19:team-general@thread.skype",
|
|
75
|
+
teamName: "19:team-general@thread.skype",
|
|
76
|
+
channelId: "19:roadmap@thread.skype",
|
|
77
|
+
channelName: "19:roadmap@thread.skype",
|
|
78
|
+
});
|
|
79
|
+
expect(resolveGraphToken).not.toHaveBeenCalled();
|
|
80
|
+
expect(listTeamsByName).not.toHaveBeenCalled();
|
|
81
|
+
expect(listChannelsForTeam).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("normalizes conversation-prefixed configured channel IDs", async () => {
|
|
85
|
+
const [result] = await resolveMSTeamsChannelAllowlist({
|
|
86
|
+
cfg: {},
|
|
87
|
+
entries: ["19:team-general@thread.tacv2/conversation:19:roadmap@thread.tacv2"],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(result).toMatchObject({
|
|
91
|
+
resolved: true,
|
|
92
|
+
teamId: "19:team-general@thread.tacv2",
|
|
93
|
+
channelId: "19:roadmap@thread.tacv2",
|
|
94
|
+
});
|
|
95
|
+
expect(resolveGraphToken).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
|
|
56
98
|
it("resolves team/channel by team name + channel display name", async () => {
|
|
57
99
|
// After the fix, listChannelsForTeam is called once and reused for both
|
|
58
100
|
// General channel resolution and channel matching.
|
|
@@ -144,3 +186,65 @@ describe("resolveMSTeamsChannelAllowlist", () => {
|
|
|
144
186
|
});
|
|
145
187
|
});
|
|
146
188
|
});
|
|
189
|
+
|
|
190
|
+
describe("looksLikeMSTeamsTargetId", () => {
|
|
191
|
+
// Regression suite for https://github.com/openclaw/openclaw/issues/58001:
|
|
192
|
+
// cron announce delivery rejected valid Teams conversation ids because the
|
|
193
|
+
// validator only matched the `conversation:`-prefixed and `@thread`-suffixed
|
|
194
|
+
// forms. It must now accept every documented Bot Framework + Graph format.
|
|
195
|
+
it.each([
|
|
196
|
+
"conversation:19:abc@thread.tacv2",
|
|
197
|
+
"conversation:a:1abc",
|
|
198
|
+
"conversation:8:orgid:2d8c2d2c-1111-2222-3333-444444444444",
|
|
199
|
+
])("accepts conversation-prefixed ids (%s)", (raw) => {
|
|
200
|
+
expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it.each(["19:AdviChannelId@thread.tacv2", "19:abc@thread.tacv2", "19:abc@thread.skype"])(
|
|
204
|
+
"accepts bare channel/group conversation ids (%s)",
|
|
205
|
+
(raw) => {
|
|
206
|
+
expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
it("accepts the Graph 1:1 chat thread format", () => {
|
|
211
|
+
expect(
|
|
212
|
+
looksLikeMSTeamsTargetId(
|
|
213
|
+
"19:40a1a0ed4ff24164a21955518990c197_2d8c2d2c11112222@unq.gbl.spaces",
|
|
214
|
+
),
|
|
215
|
+
).toBe(true);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it.each(["a:1abc123def", "a:1xyz-abc_def", "A:1UPPER"])(
|
|
219
|
+
"accepts Bot Framework personal chat ids (%s)",
|
|
220
|
+
(raw) => {
|
|
221
|
+
expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
it.each(["8:orgid:2d8c2d2c-1111-2222-3333-444444444444", "8:orgid:user-object-id"])(
|
|
226
|
+
"accepts Bot Framework org-scoped personal chat ids (%s)",
|
|
227
|
+
(raw) => {
|
|
228
|
+
expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
it("accepts Bot Framework user ids", () => {
|
|
233
|
+
expect(looksLikeMSTeamsTargetId("29:1a2b3c4d5e6f")).toBe(true);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("accepts user:<aad-object-id> ids", () => {
|
|
237
|
+
expect(looksLikeMSTeamsTargetId("user:40a1a0ed-4ff2-4164-a219-55518990c197")).toBe(true);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it.each(["", " ", "user:John Smith", "Product Team/Roadmap", "Engineering", "hello"])(
|
|
241
|
+
"rejects non-id inputs (%s)",
|
|
242
|
+
(raw) => {
|
|
243
|
+
expect(looksLikeMSTeamsTargetId(raw)).toBe(false);
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
it("normalizes leading/trailing whitespace before classifying", () => {
|
|
248
|
+
expect(looksLikeMSTeamsTargetId(" 19:abc@thread.tacv2 ")).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
});
|
package/src/resolve-allowlist.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { mapAllowlistResolutionInputs } from "openclaw/plugin-sdk/
|
|
1
|
+
import { mapAllowlistResolutionInputs } from "openclaw/plugin-sdk/allow-from";
|
|
2
|
+
import {
|
|
3
|
+
normalizeLowercaseStringOrEmpty,
|
|
4
|
+
normalizeOptionalLowercaseString,
|
|
5
|
+
} from "openclaw/plugin-sdk/text-runtime";
|
|
2
6
|
import { searchGraphUsers } from "./graph-users.js";
|
|
3
7
|
import {
|
|
4
8
|
listChannelsForTeam,
|
|
@@ -7,7 +11,7 @@ import {
|
|
|
7
11
|
resolveGraphToken,
|
|
8
12
|
} from "./graph.js";
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
type MSTeamsChannelResolution = {
|
|
11
15
|
input: string;
|
|
12
16
|
resolved: boolean;
|
|
13
17
|
teamId?: string;
|
|
@@ -17,7 +21,7 @@ export type MSTeamsChannelResolution = {
|
|
|
17
21
|
note?: string;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
type MSTeamsUserResolution = {
|
|
21
25
|
input: string;
|
|
22
26
|
resolved: boolean;
|
|
23
27
|
id?: string;
|
|
@@ -61,6 +65,63 @@ export function parseMSTeamsConversationId(raw: string): string | null {
|
|
|
61
65
|
return id;
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Detect whether a raw target string looks like a Microsoft Teams conversation
|
|
70
|
+
* or user id that cron announce delivery and other explicit-target paths can
|
|
71
|
+
* forward verbatim to the channel adapter.
|
|
72
|
+
*
|
|
73
|
+
* Accepts both prefixed and bare formats:
|
|
74
|
+
* - `conversation:<id>` — explicit conversation prefix
|
|
75
|
+
* - `user:<aad-guid>` — user id (16+ hex chars, UUID-like)
|
|
76
|
+
* - `19:abc@thread.tacv2` / `19:abc@thread.skype` — channel / legacy group
|
|
77
|
+
* - `19:{userId}_{appId}@unq.gbl.spaces` — Graph 1:1 chat thread format
|
|
78
|
+
* - `a:1xxx` — Bot Framework personal (1:1) chat id
|
|
79
|
+
* - `8:orgid:xxx` — Bot Framework org-scoped personal chat id
|
|
80
|
+
* - `29:xxx` — Bot Framework user id
|
|
81
|
+
*
|
|
82
|
+
* Display-name user targets such as `user:John Smith` intentionally return
|
|
83
|
+
* false so that the Graph API directory lookup still runs for them.
|
|
84
|
+
*/
|
|
85
|
+
export function looksLikeMSTeamsTargetId(raw: string): boolean {
|
|
86
|
+
const trimmed = raw.trim();
|
|
87
|
+
if (!trimmed) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (/^conversation:/i.test(trimmed)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (/^user:/i.test(trimmed)) {
|
|
94
|
+
// Only treat as an id when the value after `user:` looks like a UUID;
|
|
95
|
+
// display names must fall through to directory lookup.
|
|
96
|
+
const id = trimmed.slice("user:".length).trim();
|
|
97
|
+
return /^[0-9a-fA-F-]{16,}$/.test(id);
|
|
98
|
+
}
|
|
99
|
+
// Bare Bot Framework / Graph conversation id formats.
|
|
100
|
+
// Channel / group ids always start with `19:` and include an `@thread.*`
|
|
101
|
+
// suffix (`@thread.tacv2` or the legacy `@thread.skype`). Personal chat
|
|
102
|
+
// ids come in three shapes: `a:1...` (Bot Framework), `8:orgid:...`
|
|
103
|
+
// (org-scoped Bot Framework), and `19:{userId}_{appId}@unq.gbl.spaces`
|
|
104
|
+
// (Graph API 1:1 chat thread). Bot Framework user ids use `29:...`.
|
|
105
|
+
if (/^19:.+@thread\.(tacv2|skype)$/i.test(trimmed)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (/^19:.+@unq\.gbl\.spaces$/i.test(trimmed)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (/^a:1[A-Za-z0-9_-]+$/i.test(trimmed)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
if (/^8:orgid:[A-Za-z0-9-]+$/i.test(trimmed)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (/^29:[A-Za-z0-9_-]+$/i.test(trimmed)) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
// Fallback: anything containing @thread is still treated as a conversation
|
|
121
|
+
// id so the current matches for tenant-specific suffixes remain accepted.
|
|
122
|
+
return /@thread\b/i.test(trimmed);
|
|
123
|
+
}
|
|
124
|
+
|
|
64
125
|
function normalizeMSTeamsTeamKey(raw: string): string | undefined {
|
|
65
126
|
const trimmed = stripProviderPrefix(raw)
|
|
66
127
|
.replace(/^team:/i, "")
|
|
@@ -73,6 +134,16 @@ function normalizeMSTeamsChannelKey(raw?: string | null): string | undefined {
|
|
|
73
134
|
return trimmed || undefined;
|
|
74
135
|
}
|
|
75
136
|
|
|
137
|
+
function normalizeMSTeamsConversationTargetId(raw: string): string {
|
|
138
|
+
const trimmed = stripProviderPrefix(raw).trim();
|
|
139
|
+
return parseMSTeamsConversationId(trimmed) ?? trimmed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function looksLikeMSTeamsThreadConversationId(raw: string): boolean {
|
|
143
|
+
const normalized = normalizeMSTeamsConversationTargetId(raw);
|
|
144
|
+
return /^19:.+@thread\./i.test(normalized);
|
|
145
|
+
}
|
|
146
|
+
|
|
76
147
|
export function parseMSTeamsTeamChannelInput(raw: string): { team?: string; channel?: string } {
|
|
77
148
|
const trimmed = stripProviderPrefix(raw).trim();
|
|
78
149
|
if (!trimmed) {
|
|
@@ -105,7 +176,11 @@ export async function resolveMSTeamsChannelAllowlist(params: {
|
|
|
105
176
|
cfg: unknown;
|
|
106
177
|
entries: string[];
|
|
107
178
|
}): Promise<MSTeamsChannelResolution[]> {
|
|
108
|
-
|
|
179
|
+
let tokenPromise: Promise<string> | undefined;
|
|
180
|
+
const getToken = () => {
|
|
181
|
+
tokenPromise ??= resolveGraphToken(params.cfg);
|
|
182
|
+
return tokenPromise;
|
|
183
|
+
};
|
|
109
184
|
return await mapAllowlistResolutionInputs({
|
|
110
185
|
inputs: params.entries,
|
|
111
186
|
mapInput: async (input): Promise<MSTeamsChannelResolution> => {
|
|
@@ -113,6 +188,31 @@ export async function resolveMSTeamsChannelAllowlist(params: {
|
|
|
113
188
|
if (!team) {
|
|
114
189
|
return { input, resolved: false };
|
|
115
190
|
}
|
|
191
|
+
if (looksLikeMSTeamsThreadConversationId(team)) {
|
|
192
|
+
const teamId = normalizeMSTeamsConversationTargetId(team);
|
|
193
|
+
if (!channel) {
|
|
194
|
+
return { input, resolved: true, teamId, teamName: teamId };
|
|
195
|
+
}
|
|
196
|
+
if (!looksLikeMSTeamsThreadConversationId(channel)) {
|
|
197
|
+
return {
|
|
198
|
+
input,
|
|
199
|
+
resolved: false,
|
|
200
|
+
teamId,
|
|
201
|
+
teamName: teamId,
|
|
202
|
+
note: "channel id required for conversation-id team",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const channelId = normalizeMSTeamsConversationTargetId(channel);
|
|
206
|
+
return {
|
|
207
|
+
input,
|
|
208
|
+
resolved: true,
|
|
209
|
+
teamId,
|
|
210
|
+
teamName: teamId,
|
|
211
|
+
channelId,
|
|
212
|
+
channelName: channelId,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const token = await getToken();
|
|
116
216
|
const teams = /^[0-9a-fA-F-]{16,}$/.test(team)
|
|
117
217
|
? [{ id: team, displayName: team }]
|
|
118
218
|
: await listTeamsByName(token, team);
|
|
@@ -135,7 +235,9 @@ export async function resolveMSTeamsChannelAllowlist(params: {
|
|
|
135
235
|
} catch {
|
|
136
236
|
// API failure (rate limit, network error) — fall back to Graph GUID as team key
|
|
137
237
|
}
|
|
138
|
-
const generalChannel = teamChannels.find(
|
|
238
|
+
const generalChannel = teamChannels.find(
|
|
239
|
+
(ch) => normalizeOptionalLowercaseString(ch.displayName) === "general",
|
|
240
|
+
);
|
|
139
241
|
// Use the General channel's conversation ID as the team key — this
|
|
140
242
|
// matches what Bot Framework sends at runtime. Fall back to the Graph
|
|
141
243
|
// GUID if the General channel isn't found (renamed or deleted).
|
|
@@ -150,11 +252,14 @@ export async function resolveMSTeamsChannelAllowlist(params: {
|
|
|
150
252
|
};
|
|
151
253
|
}
|
|
152
254
|
// Reuse teamChannels — already fetched above
|
|
255
|
+
const normalizedChannel = normalizeOptionalLowercaseString(channel);
|
|
153
256
|
const channelMatch =
|
|
154
257
|
teamChannels.find((item) => item.id === channel) ??
|
|
155
|
-
teamChannels.find(
|
|
258
|
+
teamChannels.find(
|
|
259
|
+
(item) => normalizeOptionalLowercaseString(item.displayName) === normalizedChannel,
|
|
260
|
+
) ??
|
|
156
261
|
teamChannels.find((item) =>
|
|
157
|
-
item.displayName
|
|
262
|
+
normalizeLowercaseStringOrEmpty(item.displayName ?? "").includes(normalizedChannel ?? ""),
|
|
158
263
|
);
|
|
159
264
|
if (!channelMatch?.id) {
|
|
160
265
|
return { input, resolved: false, note: "channel not found" };
|
package/src/runtime.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/
|
|
2
|
-
import type { PluginRuntime } from "openclaw/plugin-sdk/
|
|
1
|
+
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
|
|
2
|
+
import type { PluginRuntime } from "openclaw/plugin-sdk/runtime-store";
|
|
3
3
|
|
|
4
4
|
const { setRuntime: setMSTeamsRuntime, getRuntime: getMSTeamsRuntime } =
|
|
5
|
-
createPluginRuntimeStore<PluginRuntime>(
|
|
5
|
+
createPluginRuntimeStore<PluginRuntime>({
|
|
6
|
+
pluginId: "msteams",
|
|
7
|
+
errorMessage: "MSTeams runtime not initialized",
|
|
8
|
+
});
|
|
6
9
|
export { getMSTeamsRuntime, setMSTeamsRuntime };
|
package/src/sdk-types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { TurnContext } from "@microsoft/agents-hosting";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Minimal public surface we depend on from the Microsoft SDK types.
|
|
5
3
|
*
|
|
@@ -8,7 +6,47 @@ import type { TurnContext } from "@microsoft/agents-hosting";
|
|
|
8
6
|
* stricter than what the runtime accepts (e.g. it allows plain activity-like
|
|
9
7
|
* objects), so we model the minimal structural shape we rely on.
|
|
10
8
|
*/
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
type MSTeamsActivity = {
|
|
11
|
+
type: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
timestamp?: string;
|
|
14
|
+
localTimestamp?: string;
|
|
15
|
+
channelId?: string;
|
|
16
|
+
from?: { id?: string; name?: string; aadObjectId?: string; role?: string };
|
|
17
|
+
conversation?: {
|
|
18
|
+
id?: string;
|
|
19
|
+
conversationType?: string;
|
|
20
|
+
tenantId?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
isGroup?: boolean;
|
|
23
|
+
};
|
|
24
|
+
recipient?: { id?: string; name?: string };
|
|
25
|
+
text?: string;
|
|
26
|
+
textFormat?: string;
|
|
27
|
+
locale?: string;
|
|
28
|
+
serviceUrl?: string;
|
|
29
|
+
channelData?: {
|
|
30
|
+
team?: { id?: string; name?: string };
|
|
31
|
+
channel?: { id?: string; name?: string };
|
|
32
|
+
tenant?: { id?: string };
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
attachments?: Array<{
|
|
36
|
+
contentType?: string;
|
|
37
|
+
contentUrl?: string;
|
|
38
|
+
content?: unknown;
|
|
39
|
+
name?: string;
|
|
40
|
+
thumbnailUrl?: string;
|
|
41
|
+
}>;
|
|
42
|
+
entities?: Array<Record<string, unknown>>;
|
|
43
|
+
value?: unknown;
|
|
44
|
+
name?: string;
|
|
45
|
+
membersAdded?: Array<{ id?: string; name?: string }>;
|
|
46
|
+
membersRemoved?: Array<{ id?: string; name?: string }>;
|
|
47
|
+
replyToId?: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
12
50
|
|
|
13
51
|
export type MSTeamsTurnContext = {
|
|
14
52
|
activity: MSTeamsActivity;
|
|
@@ -16,4 +54,6 @@ export type MSTeamsTurnContext = {
|
|
|
16
54
|
sendActivities: (
|
|
17
55
|
activities: Array<{ type: string } & Record<string, unknown>>,
|
|
18
56
|
) => Promise<unknown>;
|
|
57
|
+
updateActivity: (activity: object) => Promise<{ id?: string } | void>;
|
|
58
|
+
deleteActivity: (activityId: string) => Promise<void>;
|
|
19
59
|
};
|