@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/polls.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import { resolveMSTeamsStorePath } from "./storage.js";
|
|
3
|
-
import { readJsonFile, withFileLock, writeJsonFile } from "./store-fs.js";
|
|
4
|
-
|
|
5
|
-
type MSTeamsPollVote = {
|
|
6
|
-
pollId: string;
|
|
7
|
-
selections: string[];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type MSTeamsPoll = {
|
|
11
|
-
id: string;
|
|
12
|
-
question: string;
|
|
13
|
-
options: string[];
|
|
14
|
-
maxSelections: number;
|
|
15
|
-
createdAt: string;
|
|
16
|
-
updatedAt?: string;
|
|
17
|
-
conversationId?: string;
|
|
18
|
-
messageId?: string;
|
|
19
|
-
votes: Record<string, string[]>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type MSTeamsPollStore = {
|
|
23
|
-
createPoll: (poll: MSTeamsPoll) => Promise<void>;
|
|
24
|
-
getPoll: (pollId: string) => Promise<MSTeamsPoll | null>;
|
|
25
|
-
recordVote: (params: {
|
|
26
|
-
pollId: string;
|
|
27
|
-
voterId: string;
|
|
28
|
-
selections: string[];
|
|
29
|
-
}) => Promise<MSTeamsPoll | null>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type MSTeamsPollCard = {
|
|
33
|
-
pollId: string;
|
|
34
|
-
question: string;
|
|
35
|
-
options: string[];
|
|
36
|
-
maxSelections: number;
|
|
37
|
-
card: Record<string, unknown>;
|
|
38
|
-
fallbackText: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type PollStoreData = {
|
|
42
|
-
version: 1;
|
|
43
|
-
polls: Record<string, MSTeamsPoll>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const STORE_FILENAME = "msteams-polls.json";
|
|
47
|
-
const MAX_POLLS = 1000;
|
|
48
|
-
const POLL_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
49
|
-
|
|
50
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
51
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function normalizeOptionalString(value: unknown): string | undefined {
|
|
55
|
-
if (typeof value !== "string") {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
const trimmed = value.trim();
|
|
59
|
-
return trimmed ? trimmed : undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function normalizeChoiceValue(value: unknown): string | null {
|
|
63
|
-
if (typeof value === "string") {
|
|
64
|
-
const trimmed = value.trim();
|
|
65
|
-
return trimmed ? trimmed : null;
|
|
66
|
-
}
|
|
67
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
68
|
-
return String(value);
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function extractSelections(value: unknown): string[] {
|
|
74
|
-
if (Array.isArray(value)) {
|
|
75
|
-
return value.map(normalizeChoiceValue).filter((entry): entry is string => Boolean(entry));
|
|
76
|
-
}
|
|
77
|
-
const normalized = normalizeChoiceValue(value);
|
|
78
|
-
if (!normalized) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
if (normalized.includes(",")) {
|
|
82
|
-
return normalized
|
|
83
|
-
.split(",")
|
|
84
|
-
.map((entry) => entry.trim())
|
|
85
|
-
.filter(Boolean);
|
|
86
|
-
}
|
|
87
|
-
return [normalized];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function readNestedValue(value: unknown, keys: Array<string | number>): unknown {
|
|
91
|
-
let current: unknown = value;
|
|
92
|
-
for (const key of keys) {
|
|
93
|
-
if (!isRecord(current)) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
current = current[key as keyof typeof current];
|
|
97
|
-
}
|
|
98
|
-
return current;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function readNestedString(value: unknown, keys: Array<string | number>): string | undefined {
|
|
102
|
-
return normalizeOptionalString(readNestedValue(value, keys));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function extractMSTeamsPollVote(
|
|
106
|
-
activity: { value?: unknown } | undefined,
|
|
107
|
-
): MSTeamsPollVote | null {
|
|
108
|
-
const value = activity?.value;
|
|
109
|
-
if (!value || !isRecord(value)) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
const pollId =
|
|
113
|
-
readNestedString(value, ["openclawPollId"]) ??
|
|
114
|
-
readNestedString(value, ["pollId"]) ??
|
|
115
|
-
readNestedString(value, ["openclaw", "pollId"]) ??
|
|
116
|
-
readNestedString(value, ["openclaw", "poll", "id"]) ??
|
|
117
|
-
readNestedString(value, ["data", "openclawPollId"]) ??
|
|
118
|
-
readNestedString(value, ["data", "pollId"]) ??
|
|
119
|
-
readNestedString(value, ["data", "openclaw", "pollId"]);
|
|
120
|
-
if (!pollId) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const directSelections = extractSelections(value.choices);
|
|
125
|
-
const nestedSelections = extractSelections(readNestedValue(value, ["choices"]));
|
|
126
|
-
const dataSelections = extractSelections(readNestedValue(value, ["data", "choices"]));
|
|
127
|
-
const selections =
|
|
128
|
-
directSelections.length > 0
|
|
129
|
-
? directSelections
|
|
130
|
-
: nestedSelections.length > 0
|
|
131
|
-
? nestedSelections
|
|
132
|
-
: dataSelections;
|
|
133
|
-
|
|
134
|
-
if (selections.length === 0) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
pollId,
|
|
140
|
-
selections,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function buildMSTeamsPollCard(params: {
|
|
145
|
-
question: string;
|
|
146
|
-
options: string[];
|
|
147
|
-
maxSelections?: number;
|
|
148
|
-
pollId?: string;
|
|
149
|
-
}): MSTeamsPollCard {
|
|
150
|
-
const pollId = params.pollId ?? crypto.randomUUID();
|
|
151
|
-
const maxSelections =
|
|
152
|
-
typeof params.maxSelections === "number" && params.maxSelections > 1
|
|
153
|
-
? Math.floor(params.maxSelections)
|
|
154
|
-
: 1;
|
|
155
|
-
const cappedMaxSelections = Math.min(Math.max(1, maxSelections), params.options.length);
|
|
156
|
-
const choices = params.options.map((option, index) => ({
|
|
157
|
-
title: option,
|
|
158
|
-
value: String(index),
|
|
159
|
-
}));
|
|
160
|
-
const hint =
|
|
161
|
-
cappedMaxSelections > 1
|
|
162
|
-
? `Select up to ${cappedMaxSelections} option${cappedMaxSelections === 1 ? "" : "s"}.`
|
|
163
|
-
: "Select one option.";
|
|
164
|
-
|
|
165
|
-
const card = {
|
|
166
|
-
type: "AdaptiveCard",
|
|
167
|
-
version: "1.5",
|
|
168
|
-
body: [
|
|
169
|
-
{
|
|
170
|
-
type: "TextBlock",
|
|
171
|
-
text: params.question,
|
|
172
|
-
wrap: true,
|
|
173
|
-
weight: "Bolder",
|
|
174
|
-
size: "Medium",
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
type: "Input.ChoiceSet",
|
|
178
|
-
id: "choices",
|
|
179
|
-
isMultiSelect: cappedMaxSelections > 1,
|
|
180
|
-
style: "expanded",
|
|
181
|
-
choices,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
type: "TextBlock",
|
|
185
|
-
text: hint,
|
|
186
|
-
wrap: true,
|
|
187
|
-
isSubtle: true,
|
|
188
|
-
spacing: "Small",
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
actions: [
|
|
192
|
-
{
|
|
193
|
-
type: "Action.Submit",
|
|
194
|
-
title: "Vote",
|
|
195
|
-
data: {
|
|
196
|
-
openclawPollId: pollId,
|
|
197
|
-
pollId,
|
|
198
|
-
},
|
|
199
|
-
msteams: {
|
|
200
|
-
type: "messageBack",
|
|
201
|
-
text: "openclaw poll vote",
|
|
202
|
-
displayText: "Vote recorded",
|
|
203
|
-
value: { openclawPollId: pollId, pollId },
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const fallbackLines = [
|
|
210
|
-
`Poll: ${params.question}`,
|
|
211
|
-
...params.options.map((option, index) => `${index + 1}. ${option}`),
|
|
212
|
-
];
|
|
213
|
-
|
|
214
|
-
return {
|
|
215
|
-
pollId,
|
|
216
|
-
question: params.question,
|
|
217
|
-
options: params.options,
|
|
218
|
-
maxSelections: cappedMaxSelections,
|
|
219
|
-
card,
|
|
220
|
-
fallbackText: fallbackLines.join("\n"),
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
type MSTeamsPollStoreFsOptions = {
|
|
225
|
-
env?: NodeJS.ProcessEnv;
|
|
226
|
-
homedir?: () => string;
|
|
227
|
-
stateDir?: string;
|
|
228
|
-
storePath?: string;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
function parseTimestamp(value?: string): number | null {
|
|
232
|
-
if (!value) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
const parsed = Date.parse(value);
|
|
236
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function pruneExpired(polls: Record<string, MSTeamsPoll>) {
|
|
240
|
-
const cutoff = Date.now() - POLL_TTL_MS;
|
|
241
|
-
const entries = Object.entries(polls).filter(([, poll]) => {
|
|
242
|
-
const ts = parseTimestamp(poll.updatedAt ?? poll.createdAt) ?? 0;
|
|
243
|
-
return ts >= cutoff;
|
|
244
|
-
});
|
|
245
|
-
return Object.fromEntries(entries);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function pruneToLimit(polls: Record<string, MSTeamsPoll>) {
|
|
249
|
-
const entries = Object.entries(polls);
|
|
250
|
-
if (entries.length <= MAX_POLLS) {
|
|
251
|
-
return polls;
|
|
252
|
-
}
|
|
253
|
-
entries.sort((a, b) => {
|
|
254
|
-
const aTs = parseTimestamp(a[1].updatedAt ?? a[1].createdAt) ?? 0;
|
|
255
|
-
const bTs = parseTimestamp(b[1].updatedAt ?? b[1].createdAt) ?? 0;
|
|
256
|
-
return aTs - bTs;
|
|
257
|
-
});
|
|
258
|
-
const keep = entries.slice(entries.length - MAX_POLLS);
|
|
259
|
-
return Object.fromEntries(keep);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function normalizeMSTeamsPollSelections(poll: MSTeamsPoll, selections: string[]) {
|
|
263
|
-
const maxSelections = Math.max(1, poll.maxSelections);
|
|
264
|
-
const mapped = selections
|
|
265
|
-
.map((entry) => Number.parseInt(entry, 10))
|
|
266
|
-
.filter((value) => Number.isFinite(value))
|
|
267
|
-
.filter((value) => value >= 0 && value < poll.options.length)
|
|
268
|
-
.map((value) => String(value));
|
|
269
|
-
const limited = maxSelections > 1 ? mapped.slice(0, maxSelections) : mapped.slice(0, 1);
|
|
270
|
-
return Array.from(new Set(limited));
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export function createMSTeamsPollStoreFs(params?: MSTeamsPollStoreFsOptions): MSTeamsPollStore {
|
|
274
|
-
const filePath = resolveMSTeamsStorePath({
|
|
275
|
-
filename: STORE_FILENAME,
|
|
276
|
-
env: params?.env,
|
|
277
|
-
homedir: params?.homedir,
|
|
278
|
-
stateDir: params?.stateDir,
|
|
279
|
-
storePath: params?.storePath,
|
|
280
|
-
});
|
|
281
|
-
const empty: PollStoreData = { version: 1, polls: {} };
|
|
282
|
-
|
|
283
|
-
const readStore = async (): Promise<PollStoreData> => {
|
|
284
|
-
const { value } = await readJsonFile(filePath, empty);
|
|
285
|
-
const pruned = pruneToLimit(pruneExpired(value.polls ?? {}));
|
|
286
|
-
return { version: 1, polls: pruned };
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
const writeStore = async (data: PollStoreData) => {
|
|
290
|
-
await writeJsonFile(filePath, data);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const createPoll = async (poll: MSTeamsPoll) => {
|
|
294
|
-
await withFileLock(filePath, empty, async () => {
|
|
295
|
-
const data = await readStore();
|
|
296
|
-
data.polls[poll.id] = poll;
|
|
297
|
-
await writeStore({ version: 1, polls: pruneToLimit(data.polls) });
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const getPoll = async (pollId: string) =>
|
|
302
|
-
await withFileLock(filePath, empty, async () => {
|
|
303
|
-
const data = await readStore();
|
|
304
|
-
return data.polls[pollId] ?? null;
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const recordVote = async (params: { pollId: string; voterId: string; selections: string[] }) =>
|
|
308
|
-
await withFileLock(filePath, empty, async () => {
|
|
309
|
-
const data = await readStore();
|
|
310
|
-
const poll = data.polls[params.pollId];
|
|
311
|
-
if (!poll) {
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
const normalized = normalizeMSTeamsPollSelections(poll, params.selections);
|
|
315
|
-
poll.votes[params.voterId] = normalized;
|
|
316
|
-
poll.updatedAt = new Date().toISOString();
|
|
317
|
-
data.polls[poll.id] = poll;
|
|
318
|
-
await writeStore({ version: 1, polls: pruneToLimit(data.polls) });
|
|
319
|
-
return poll;
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
return { createPoll, getPoll, recordVote };
|
|
323
|
-
}
|
package/src/presentation.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { MessagePresentation } from "openclaw/plugin-sdk/interactive-runtime";
|
|
2
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
3
|
-
|
|
4
|
-
export function buildMSTeamsPresentationCard(params: {
|
|
5
|
-
presentation: MessagePresentation;
|
|
6
|
-
text?: string | null;
|
|
7
|
-
}) {
|
|
8
|
-
const body: Record<string, unknown>[] = [];
|
|
9
|
-
const text = normalizeOptionalString(params.text);
|
|
10
|
-
if (text) {
|
|
11
|
-
body.push({
|
|
12
|
-
type: "TextBlock",
|
|
13
|
-
text,
|
|
14
|
-
wrap: true,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const { presentation } = params;
|
|
18
|
-
if (presentation.title) {
|
|
19
|
-
body.push({
|
|
20
|
-
type: "TextBlock",
|
|
21
|
-
text: presentation.title,
|
|
22
|
-
weight: "Bolder",
|
|
23
|
-
size: "Medium",
|
|
24
|
-
wrap: true,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const actions: Record<string, unknown>[] = [];
|
|
28
|
-
for (const block of presentation.blocks) {
|
|
29
|
-
if (block.type === "text" || block.type === "context") {
|
|
30
|
-
body.push({
|
|
31
|
-
type: "TextBlock",
|
|
32
|
-
text: block.text,
|
|
33
|
-
wrap: true,
|
|
34
|
-
...(block.type === "context" ? { isSubtle: true, size: "Small" } : {}),
|
|
35
|
-
});
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (block.type === "divider") {
|
|
39
|
-
body.push({ type: "TextBlock", text: "---", wrap: true, isSubtle: true });
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (block.type === "buttons") {
|
|
43
|
-
for (const button of block.buttons) {
|
|
44
|
-
if (button.url) {
|
|
45
|
-
actions.push({
|
|
46
|
-
type: "Action.OpenUrl",
|
|
47
|
-
title: button.label,
|
|
48
|
-
url: button.url,
|
|
49
|
-
});
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (button.value) {
|
|
53
|
-
actions.push({
|
|
54
|
-
type: "Action.Submit",
|
|
55
|
-
title: button.label,
|
|
56
|
-
data: { value: button.value, label: button.label },
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
type: "AdaptiveCard",
|
|
64
|
-
version: "1.4",
|
|
65
|
-
body,
|
|
66
|
-
...(actions.length ? { actions } : {}),
|
|
67
|
-
};
|
|
68
|
-
}
|
package/src/probe.test.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { MSTeamsConfig } from "../runtime-api.js";
|
|
3
|
-
|
|
4
|
-
const hostMockState = vi.hoisted(() => ({
|
|
5
|
-
tokenError: null as Error | null,
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
vi.mock("@microsoft/teams.apps", () => ({
|
|
9
|
-
App: class {
|
|
10
|
-
protected async getBotToken() {
|
|
11
|
-
if (hostMockState.tokenError) {
|
|
12
|
-
throw hostMockState.tokenError;
|
|
13
|
-
}
|
|
14
|
-
return { value: "token" };
|
|
15
|
-
}
|
|
16
|
-
protected async getAppGraphToken() {
|
|
17
|
-
if (hostMockState.tokenError) {
|
|
18
|
-
throw hostMockState.tokenError;
|
|
19
|
-
}
|
|
20
|
-
return { value: "token" };
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
vi.mock("@microsoft/teams.api", () => ({
|
|
26
|
-
Client: function Client() {},
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
import { probeMSTeams } from "./probe.js";
|
|
30
|
-
|
|
31
|
-
describe("msteams probe", () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
hostMockState.tokenError = null;
|
|
34
|
-
vi.stubEnv("MSTEAMS_APP_ID", "");
|
|
35
|
-
vi.stubEnv("MSTEAMS_APP_PASSWORD", "");
|
|
36
|
-
vi.stubEnv("MSTEAMS_TENANT_ID", "");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
afterEach(() => {
|
|
40
|
-
vi.unstubAllEnvs();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("returns an error when credentials are missing", async () => {
|
|
44
|
-
const cfg = { enabled: true } as unknown as MSTeamsConfig;
|
|
45
|
-
await expect(probeMSTeams(cfg)).resolves.toMatchObject({
|
|
46
|
-
ok: false,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("validates credentials by acquiring a token", async () => {
|
|
51
|
-
const cfg = {
|
|
52
|
-
enabled: true,
|
|
53
|
-
appId: "app",
|
|
54
|
-
appPassword: "pw",
|
|
55
|
-
tenantId: "tenant",
|
|
56
|
-
} as unknown as MSTeamsConfig;
|
|
57
|
-
await expect(probeMSTeams(cfg)).resolves.toMatchObject({
|
|
58
|
-
ok: true,
|
|
59
|
-
appId: "app",
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("returns a helpful error when token acquisition fails", async () => {
|
|
64
|
-
hostMockState.tokenError = new Error("bad creds");
|
|
65
|
-
const cfg = {
|
|
66
|
-
enabled: true,
|
|
67
|
-
appId: "app",
|
|
68
|
-
appPassword: "pw",
|
|
69
|
-
tenantId: "tenant",
|
|
70
|
-
} as unknown as MSTeamsConfig;
|
|
71
|
-
await expect(probeMSTeams(cfg)).resolves.toMatchObject({
|
|
72
|
-
ok: false,
|
|
73
|
-
appId: "app",
|
|
74
|
-
error: "bad creds",
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
package/src/probe.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalizeStringEntries,
|
|
3
|
-
type BaseProbeResult,
|
|
4
|
-
type MSTeamsConfig,
|
|
5
|
-
} from "../runtime-api.js";
|
|
6
|
-
import { formatUnknownError } from "./errors.js";
|
|
7
|
-
import { createMSTeamsTokenProvider, loadMSTeamsSdkWithAuth } from "./sdk.js";
|
|
8
|
-
import { readAccessToken } from "./token-response.js";
|
|
9
|
-
import { loadDelegatedTokens, resolveMSTeamsCredentials } from "./token.js";
|
|
10
|
-
|
|
11
|
-
export type ProbeMSTeamsResult = BaseProbeResult<string> & {
|
|
12
|
-
appId?: string;
|
|
13
|
-
graph?: {
|
|
14
|
-
ok: boolean;
|
|
15
|
-
error?: string;
|
|
16
|
-
roles?: string[];
|
|
17
|
-
scopes?: string[];
|
|
18
|
-
};
|
|
19
|
-
delegatedAuth?: {
|
|
20
|
-
ok: boolean;
|
|
21
|
-
error?: string;
|
|
22
|
-
scopes?: string[];
|
|
23
|
-
userPrincipalName?: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function decodeJwtPayload(token: string): Record<string, unknown> | null {
|
|
28
|
-
const parts = token.split(".");
|
|
29
|
-
if (parts.length < 2) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const payload = parts[1] ?? "";
|
|
33
|
-
const padded = payload.padEnd(payload.length + ((4 - (payload.length % 4)) % 4), "=");
|
|
34
|
-
const normalized = padded.replace(/-/g, "+").replace(/_/g, "/");
|
|
35
|
-
try {
|
|
36
|
-
const decoded = Buffer.from(normalized, "base64").toString("utf8");
|
|
37
|
-
const parsed = JSON.parse(decoded) as Record<string, unknown>;
|
|
38
|
-
return parsed && typeof parsed === "object" ? parsed : null;
|
|
39
|
-
} catch {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function readStringArray(value: unknown): string[] | undefined {
|
|
45
|
-
if (!Array.isArray(value)) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
const out = normalizeStringEntries(value);
|
|
49
|
-
return out.length > 0 ? out : undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function readScopes(value: unknown): string[] | undefined {
|
|
53
|
-
if (typeof value !== "string") {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const out = value
|
|
57
|
-
.split(/\s+/)
|
|
58
|
-
.map((entry) => entry.trim())
|
|
59
|
-
.filter(Boolean);
|
|
60
|
-
return out.length > 0 ? out : undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function probeMSTeams(cfg?: MSTeamsConfig): Promise<ProbeMSTeamsResult> {
|
|
64
|
-
const creds = resolveMSTeamsCredentials(cfg);
|
|
65
|
-
if (!creds) {
|
|
66
|
-
return {
|
|
67
|
-
ok: false,
|
|
68
|
-
error: "missing credentials (appId, appPassword, tenantId)",
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const { app } = await loadMSTeamsSdkWithAuth(creds);
|
|
74
|
-
const tokenProvider = createMSTeamsTokenProvider(app);
|
|
75
|
-
const botTokenValue = await tokenProvider.getAccessToken("https://api.botframework.com");
|
|
76
|
-
if (!botTokenValue) {
|
|
77
|
-
throw new Error("Failed to acquire bot token");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let graph:
|
|
81
|
-
| {
|
|
82
|
-
ok: boolean;
|
|
83
|
-
error?: string;
|
|
84
|
-
roles?: string[];
|
|
85
|
-
scopes?: string[];
|
|
86
|
-
}
|
|
87
|
-
| undefined;
|
|
88
|
-
try {
|
|
89
|
-
const graphTokenValue = await tokenProvider.getAccessToken("https://graph.microsoft.com");
|
|
90
|
-
const accessToken = readAccessToken(graphTokenValue);
|
|
91
|
-
const payload = accessToken ? decodeJwtPayload(accessToken) : null;
|
|
92
|
-
graph = {
|
|
93
|
-
ok: true,
|
|
94
|
-
roles: readStringArray(payload?.roles),
|
|
95
|
-
scopes: readScopes(payload?.scp),
|
|
96
|
-
};
|
|
97
|
-
} catch (err) {
|
|
98
|
-
graph = { ok: false, error: formatUnknownError(err) };
|
|
99
|
-
}
|
|
100
|
-
let delegatedAuth: ProbeMSTeamsResult["delegatedAuth"];
|
|
101
|
-
if (cfg?.delegatedAuth?.enabled) {
|
|
102
|
-
try {
|
|
103
|
-
const tokens = loadDelegatedTokens();
|
|
104
|
-
if (tokens) {
|
|
105
|
-
const isExpired = tokens.expiresAt <= Date.now();
|
|
106
|
-
delegatedAuth = {
|
|
107
|
-
ok: !isExpired,
|
|
108
|
-
scopes: tokens.scopes,
|
|
109
|
-
userPrincipalName: tokens.userPrincipalName,
|
|
110
|
-
...(isExpired ? { error: "token expired (will auto-refresh on next use)" } : {}),
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
delegatedAuth = { ok: false, error: "no delegated tokens found (run setup wizard)" };
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
delegatedAuth = { ok: false, error: "failed to load delegated tokens" };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
ok: true,
|
|
121
|
-
appId: creds.appId,
|
|
122
|
-
...(graph ? { graph } : {}),
|
|
123
|
-
...(delegatedAuth ? { delegatedAuth } : {}),
|
|
124
|
-
};
|
|
125
|
-
} catch (err) {
|
|
126
|
-
return {
|
|
127
|
-
ok: false,
|
|
128
|
-
appId: creds.appId,
|
|
129
|
-
error: formatUnknownError(err),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|