@openclaw/msteams 2026.5.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
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { OpenClawConfig, PluginRuntime } from "../../runtime-api.js";
|
|
3
|
-
import type { MSTeamsMessageHandlerDeps } from "../monitor-handler.js";
|
|
4
|
-
import { setMSTeamsRuntime } from "../runtime.js";
|
|
5
|
-
import { createMSTeamsReactionHandler } from "./reaction-handler.js";
|
|
6
|
-
|
|
7
|
-
function buildMockRuntime(overrides?: Partial<PluginRuntime>): PluginRuntime {
|
|
8
|
-
return {
|
|
9
|
-
logging: { shouldLogVerbose: () => false },
|
|
10
|
-
channel: {
|
|
11
|
-
routing: {
|
|
12
|
-
resolveAgentRoute: vi.fn(() => ({
|
|
13
|
-
sessionKey: "test-session",
|
|
14
|
-
agentId: "agent1",
|
|
15
|
-
accountId: "default",
|
|
16
|
-
})),
|
|
17
|
-
},
|
|
18
|
-
pairing: {
|
|
19
|
-
readAllowFromStore: vi.fn(async () => []),
|
|
20
|
-
upsertPairingRequest: vi.fn(async () => null),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
system: {
|
|
24
|
-
enqueueSystemEvent: vi.fn(),
|
|
25
|
-
},
|
|
26
|
-
...overrides,
|
|
27
|
-
} as unknown as PluginRuntime;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function buildDeps(cfg: OpenClawConfig, _runtime?: PluginRuntime): MSTeamsMessageHandlerDeps {
|
|
31
|
-
return {
|
|
32
|
-
cfg,
|
|
33
|
-
runtime: { error: vi.fn() } as unknown as MSTeamsMessageHandlerDeps["runtime"],
|
|
34
|
-
appId: "test-app",
|
|
35
|
-
adapter: {} as MSTeamsMessageHandlerDeps["adapter"],
|
|
36
|
-
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
37
|
-
textLimit: 4000,
|
|
38
|
-
mediaMaxBytes: 1024 * 1024,
|
|
39
|
-
conversationStore: {
|
|
40
|
-
upsert: vi.fn(async () => undefined),
|
|
41
|
-
} as unknown as MSTeamsMessageHandlerDeps["conversationStore"],
|
|
42
|
-
pollStore: {
|
|
43
|
-
recordVote: vi.fn(async () => null),
|
|
44
|
-
} as unknown as MSTeamsMessageHandlerDeps["pollStore"],
|
|
45
|
-
log: {
|
|
46
|
-
info: vi.fn(),
|
|
47
|
-
debug: vi.fn(),
|
|
48
|
-
error: vi.fn(),
|
|
49
|
-
warn: vi.fn(),
|
|
50
|
-
} as unknown as MSTeamsMessageHandlerDeps["log"],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function createReactionTestHarness() {
|
|
55
|
-
const mockRuntime = buildMockRuntime();
|
|
56
|
-
setMSTeamsRuntime(mockRuntime);
|
|
57
|
-
|
|
58
|
-
const cfg: OpenClawConfig = {
|
|
59
|
-
channels: { msteams: { allowFrom: ["allowed-aad"] } },
|
|
60
|
-
} as OpenClawConfig;
|
|
61
|
-
|
|
62
|
-
const deps = buildDeps(cfg, mockRuntime);
|
|
63
|
-
const handler = createMSTeamsReactionHandler(deps);
|
|
64
|
-
const enqueue = mockRuntime.system.enqueueSystemEvent as ReturnType<typeof vi.fn>;
|
|
65
|
-
|
|
66
|
-
return { handler, enqueue };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function invokeReactionEvent(
|
|
70
|
-
handler: ReturnType<typeof createMSTeamsReactionHandler>,
|
|
71
|
-
activity: Record<string, unknown>,
|
|
72
|
-
direction: "added" | "removed",
|
|
73
|
-
) {
|
|
74
|
-
await handler(
|
|
75
|
-
{
|
|
76
|
-
activity: {
|
|
77
|
-
type: "messageReaction",
|
|
78
|
-
conversation: { id: "dm-conv", conversationType: "personal" },
|
|
79
|
-
...activity,
|
|
80
|
-
},
|
|
81
|
-
sendActivity: vi.fn(async () => undefined),
|
|
82
|
-
} as never,
|
|
83
|
-
direction,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
describe("createMSTeamsReactionHandler", () => {
|
|
88
|
-
describe("emoji mapping", () => {
|
|
89
|
-
it("maps Teams reaction types to unicode emoji in event label", async () => {
|
|
90
|
-
const mockRuntime = buildMockRuntime();
|
|
91
|
-
setMSTeamsRuntime(mockRuntime);
|
|
92
|
-
|
|
93
|
-
const cfg: OpenClawConfig = {
|
|
94
|
-
channels: {
|
|
95
|
-
msteams: {
|
|
96
|
-
allowFrom: ["allowed-aad"],
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
} as OpenClawConfig;
|
|
100
|
-
|
|
101
|
-
const deps = buildDeps(cfg);
|
|
102
|
-
const handler = createMSTeamsReactionHandler(deps);
|
|
103
|
-
|
|
104
|
-
await handler(
|
|
105
|
-
{
|
|
106
|
-
activity: {
|
|
107
|
-
type: "messageReaction",
|
|
108
|
-
reactionsAdded: [{ type: "like" }],
|
|
109
|
-
from: { id: "user-id", aadObjectId: "allowed-aad", name: "Alice" },
|
|
110
|
-
conversation: { id: "personal-conv", conversationType: "personal" },
|
|
111
|
-
replyToId: "msg-123",
|
|
112
|
-
},
|
|
113
|
-
sendActivity: vi.fn(async () => undefined),
|
|
114
|
-
} as never,
|
|
115
|
-
"added",
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const enqueue = mockRuntime.system.enqueueSystemEvent as ReturnType<typeof vi.fn>;
|
|
119
|
-
expect(enqueue).toHaveBeenCalledOnce();
|
|
120
|
-
const label: string = enqueue.mock.calls[0][0];
|
|
121
|
-
expect(label).toContain("👍");
|
|
122
|
-
expect(label).toContain("Alice");
|
|
123
|
-
expect(label).toContain("msg-123");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("maps heart, laugh, surprised, sad, angry reaction types", async () => {
|
|
127
|
-
const emojiMap: Record<string, string> = {
|
|
128
|
-
heart: "❤️",
|
|
129
|
-
laugh: "😆",
|
|
130
|
-
surprised: "😮",
|
|
131
|
-
sad: "😢",
|
|
132
|
-
angry: "😡",
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
for (const [type, expectedEmoji] of Object.entries(emojiMap)) {
|
|
136
|
-
const mockRuntime = buildMockRuntime();
|
|
137
|
-
setMSTeamsRuntime(mockRuntime);
|
|
138
|
-
|
|
139
|
-
const cfg: OpenClawConfig = {
|
|
140
|
-
channels: { msteams: { allowFrom: ["allowed-aad"] } },
|
|
141
|
-
} as OpenClawConfig;
|
|
142
|
-
|
|
143
|
-
const deps = buildDeps(cfg, mockRuntime);
|
|
144
|
-
const handler = createMSTeamsReactionHandler(deps);
|
|
145
|
-
|
|
146
|
-
await handler(
|
|
147
|
-
{
|
|
148
|
-
activity: {
|
|
149
|
-
type: "messageReaction",
|
|
150
|
-
reactionsAdded: [{ type }],
|
|
151
|
-
from: { id: "user-id", aadObjectId: "allowed-aad", name: "Bob" },
|
|
152
|
-
conversation: { id: "dm-conv", conversationType: "personal" },
|
|
153
|
-
replyToId: "msg-456",
|
|
154
|
-
},
|
|
155
|
-
sendActivity: vi.fn(async () => undefined),
|
|
156
|
-
} as never,
|
|
157
|
-
"added",
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const enqueue = mockRuntime.system.enqueueSystemEvent as ReturnType<typeof vi.fn>;
|
|
161
|
-
const label: string = enqueue.mock.calls[0][0];
|
|
162
|
-
expect(label).toContain(expectedEmoji);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("inbound reaction events", () => {
|
|
168
|
-
it("enqueues system event for reactionsAdded", async () => {
|
|
169
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
170
|
-
await invokeReactionEvent(
|
|
171
|
-
handler,
|
|
172
|
-
{
|
|
173
|
-
reactionsAdded: [{ type: "like" }],
|
|
174
|
-
from: { id: "u1", aadObjectId: "allowed-aad", name: "User" },
|
|
175
|
-
replyToId: "msg-1",
|
|
176
|
-
},
|
|
177
|
-
"added",
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
expect(enqueue).toHaveBeenCalledOnce();
|
|
181
|
-
const [label, meta] = enqueue.mock.calls[0];
|
|
182
|
-
expect(label).toContain("added");
|
|
183
|
-
expect(meta.sessionKey).toBe("test-session");
|
|
184
|
-
expect(meta.contextKey).toContain("added");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("enqueues system event for reactionsRemoved", async () => {
|
|
188
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
189
|
-
await invokeReactionEvent(
|
|
190
|
-
handler,
|
|
191
|
-
{
|
|
192
|
-
reactionsRemoved: [{ type: "heart" }],
|
|
193
|
-
from: { id: "u1", aadObjectId: "allowed-aad", name: "User" },
|
|
194
|
-
replyToId: "msg-2",
|
|
195
|
-
},
|
|
196
|
-
"removed",
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
expect(enqueue).toHaveBeenCalledOnce();
|
|
200
|
-
const [label] = enqueue.mock.calls[0];
|
|
201
|
-
expect(label).toContain("removed");
|
|
202
|
-
expect(label).toContain("❤️");
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("skips when reactions array is empty", async () => {
|
|
206
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
207
|
-
await invokeReactionEvent(
|
|
208
|
-
handler,
|
|
209
|
-
{
|
|
210
|
-
reactionsAdded: [],
|
|
211
|
-
from: { id: "u1", aadObjectId: "allowed-aad", name: "User" },
|
|
212
|
-
replyToId: "msg-3",
|
|
213
|
-
},
|
|
214
|
-
"added",
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
expect(enqueue).not.toHaveBeenCalled();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("skips when from.id is missing", async () => {
|
|
221
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
222
|
-
await invokeReactionEvent(
|
|
223
|
-
handler,
|
|
224
|
-
{
|
|
225
|
-
reactionsAdded: [{ type: "like" }],
|
|
226
|
-
from: {},
|
|
227
|
-
replyToId: "msg-4",
|
|
228
|
-
},
|
|
229
|
-
"added",
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
expect(enqueue).not.toHaveBeenCalled();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe("sender authorization", () => {
|
|
237
|
-
it("drops reaction from non-allowlisted DM sender", async () => {
|
|
238
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
239
|
-
await invokeReactionEvent(
|
|
240
|
-
handler,
|
|
241
|
-
{
|
|
242
|
-
reactionsAdded: [{ type: "like" }],
|
|
243
|
-
from: { id: "bad-user", aadObjectId: "not-allowed", name: "Attacker" },
|
|
244
|
-
replyToId: "msg-5",
|
|
245
|
-
},
|
|
246
|
-
"added",
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
expect(enqueue).not.toHaveBeenCalled();
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it("allows reaction from allowlisted DM sender", async () => {
|
|
253
|
-
const { handler, enqueue } = createReactionTestHarness();
|
|
254
|
-
await invokeReactionEvent(
|
|
255
|
-
handler,
|
|
256
|
-
{
|
|
257
|
-
reactionsAdded: [{ type: "like" }],
|
|
258
|
-
from: { id: "good-user", aadObjectId: "allowed-aad", name: "Alice" },
|
|
259
|
-
replyToId: "msg-6",
|
|
260
|
-
},
|
|
261
|
-
"added",
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
expect(enqueue).toHaveBeenCalledOnce();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_ACCOUNT_ID,
|
|
3
|
-
isDangerousNameMatchingEnabled,
|
|
4
|
-
resolveEffectiveAllowFromLists,
|
|
5
|
-
readStoreAllowFromForDmPolicy,
|
|
6
|
-
resolveDmGroupAccessWithLists,
|
|
7
|
-
resolveDefaultGroupPolicy,
|
|
8
|
-
createChannelPairingController,
|
|
9
|
-
} from "../../runtime-api.js";
|
|
10
|
-
import { normalizeMSTeamsConversationId } from "../inbound.js";
|
|
11
|
-
import type { MSTeamsMessageHandlerDeps } from "../monitor-handler.types.js";
|
|
12
|
-
import {
|
|
13
|
-
isMSTeamsGroupAllowed,
|
|
14
|
-
resolveMSTeamsAllowlistMatch,
|
|
15
|
-
resolveMSTeamsRouteConfig,
|
|
16
|
-
} from "../policy.js";
|
|
17
|
-
import { getMSTeamsRuntime } from "../runtime.js";
|
|
18
|
-
import type { MSTeamsTurnContext } from "../sdk-types.js";
|
|
19
|
-
|
|
20
|
-
/** Teams reaction type names → Unicode emoji. */
|
|
21
|
-
const TEAMS_REACTION_EMOJI: Record<string, string> = {
|
|
22
|
-
like: "👍",
|
|
23
|
-
heart: "❤️",
|
|
24
|
-
laugh: "😆",
|
|
25
|
-
surprised: "😮",
|
|
26
|
-
sad: "😢",
|
|
27
|
-
angry: "😡",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Map a Teams reaction type string to a Unicode emoji.
|
|
32
|
-
* Falls back to the raw type if not recognized.
|
|
33
|
-
*/
|
|
34
|
-
function mapReactionEmoji(reactionType: string): string {
|
|
35
|
-
return TEAMS_REACTION_EMOJI[reactionType] ?? reactionType;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ReactionDirection = "added" | "removed";
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create a handler for MS Teams reaction activities (reactionsAdded / reactionsRemoved).
|
|
42
|
-
* The returned function accepts a turn context and a direction string.
|
|
43
|
-
*/
|
|
44
|
-
export function createMSTeamsReactionHandler(deps: MSTeamsMessageHandlerDeps) {
|
|
45
|
-
const { cfg, log } = deps;
|
|
46
|
-
const core = getMSTeamsRuntime();
|
|
47
|
-
const msteamsCfg = cfg.channels?.msteams;
|
|
48
|
-
const pairing = createChannelPairingController({
|
|
49
|
-
core,
|
|
50
|
-
channel: "msteams",
|
|
51
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return async function handleReaction(
|
|
55
|
-
context: MSTeamsTurnContext,
|
|
56
|
-
direction: ReactionDirection,
|
|
57
|
-
): Promise<void> {
|
|
58
|
-
const activity = context.activity;
|
|
59
|
-
|
|
60
|
-
// Reactions are carried in reactionsAdded / reactionsRemoved on the activity.
|
|
61
|
-
const reactions: Array<{ type?: string }> =
|
|
62
|
-
direction === "added"
|
|
63
|
-
? ((activity as unknown as { reactionsAdded?: Array<{ type?: string }> }).reactionsAdded ??
|
|
64
|
-
[])
|
|
65
|
-
: ((activity as unknown as { reactionsRemoved?: Array<{ type?: string }> })
|
|
66
|
-
.reactionsRemoved ?? []);
|
|
67
|
-
|
|
68
|
-
if (reactions.length === 0) {
|
|
69
|
-
log.debug?.("reaction activity has no reactions; skipping");
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const from = activity.from;
|
|
74
|
-
if (!from?.id) {
|
|
75
|
-
log.debug?.("reaction activity missing from.id; skipping");
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const rawConversationId = activity.conversation?.id ?? "";
|
|
80
|
-
const conversationId = normalizeMSTeamsConversationId(rawConversationId);
|
|
81
|
-
const conversationType = activity.conversation?.conversationType ?? "personal";
|
|
82
|
-
const isGroupChat = conversationType === "groupChat" || activity.conversation?.isGroup === true;
|
|
83
|
-
const isChannel = conversationType === "channel";
|
|
84
|
-
const isDirectMessage = !isGroupChat && !isChannel;
|
|
85
|
-
|
|
86
|
-
const senderId = from.aadObjectId ?? from.id;
|
|
87
|
-
const senderName = from.name ?? from.id;
|
|
88
|
-
const dmPolicy = msteamsCfg?.dmPolicy ?? "pairing";
|
|
89
|
-
|
|
90
|
-
// Simplified authorization: reuse the same allowlist/policy checks as the message handler.
|
|
91
|
-
const storedAllowFrom = await readStoreAllowFromForDmPolicy({
|
|
92
|
-
provider: "msteams",
|
|
93
|
-
accountId: pairing.accountId,
|
|
94
|
-
dmPolicy,
|
|
95
|
-
readStore: pairing.readStoreForDmPolicy,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const dmAllowFrom = msteamsCfg?.allowFrom ?? [];
|
|
99
|
-
const groupAllowFrom = msteamsCfg?.groupAllowFrom;
|
|
100
|
-
const resolvedAllowFromLists = resolveEffectiveAllowFromLists({
|
|
101
|
-
allowFrom: dmAllowFrom,
|
|
102
|
-
groupAllowFrom,
|
|
103
|
-
storeAllowFrom: storedAllowFrom,
|
|
104
|
-
dmPolicy,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Enforce dmPolicy for DMs (open / disabled / allowlist / pairing).
|
|
108
|
-
const defaultGroupPolicy = resolveDefaultGroupPolicy(cfg);
|
|
109
|
-
if (isDirectMessage && msteamsCfg) {
|
|
110
|
-
const access = resolveDmGroupAccessWithLists({
|
|
111
|
-
isGroup: false,
|
|
112
|
-
dmPolicy,
|
|
113
|
-
groupPolicy: msteamsCfg.groupPolicy ?? defaultGroupPolicy ?? "allowlist",
|
|
114
|
-
allowFrom: dmAllowFrom,
|
|
115
|
-
groupAllowFrom,
|
|
116
|
-
storeAllowFrom: storedAllowFrom,
|
|
117
|
-
groupAllowFromFallbackToAllowFrom: false,
|
|
118
|
-
isSenderAllowed: (allowFrom) =>
|
|
119
|
-
resolveMSTeamsAllowlistMatch({
|
|
120
|
-
allowFrom,
|
|
121
|
-
senderId,
|
|
122
|
-
senderName,
|
|
123
|
-
allowNameMatching: isDangerousNameMatchingEnabled(msteamsCfg),
|
|
124
|
-
}).allowed,
|
|
125
|
-
});
|
|
126
|
-
if (access.decision !== "allow") {
|
|
127
|
-
log.debug?.("dropping reaction (dm access denied)", {
|
|
128
|
-
sender: senderId,
|
|
129
|
-
reason: access.reason,
|
|
130
|
-
});
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// For group/channel messages, check the route allowlist and sender allowlist.
|
|
136
|
-
if (!isDirectMessage && msteamsCfg) {
|
|
137
|
-
const teamId = (activity as unknown as { channelData?: { team?: { id?: string } } })
|
|
138
|
-
.channelData?.team?.id;
|
|
139
|
-
const teamName = (activity as unknown as { channelData?: { team?: { name?: string } } })
|
|
140
|
-
.channelData?.team?.name;
|
|
141
|
-
const channelName = (activity as unknown as { channelData?: { channel?: { name?: string } } })
|
|
142
|
-
.channelData?.channel?.name;
|
|
143
|
-
const channelGate = resolveMSTeamsRouteConfig({
|
|
144
|
-
cfg: msteamsCfg,
|
|
145
|
-
teamId,
|
|
146
|
-
teamName,
|
|
147
|
-
conversationId,
|
|
148
|
-
channelName,
|
|
149
|
-
allowNameMatching: isDangerousNameMatchingEnabled(msteamsCfg),
|
|
150
|
-
});
|
|
151
|
-
if (channelGate.allowlistConfigured && !channelGate.allowed) {
|
|
152
|
-
log.debug?.("dropping reaction (not in team/channel allowlist)", { conversationId });
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const effectiveGroupAllowFrom = resolvedAllowFromLists.effectiveGroupAllowFrom;
|
|
157
|
-
const groupAllowed = isMSTeamsGroupAllowed({
|
|
158
|
-
groupPolicy: msteamsCfg.groupPolicy ?? defaultGroupPolicy ?? "allowlist",
|
|
159
|
-
allowFrom: effectiveGroupAllowFrom,
|
|
160
|
-
senderId,
|
|
161
|
-
senderName,
|
|
162
|
-
allowNameMatching: isDangerousNameMatchingEnabled(msteamsCfg),
|
|
163
|
-
});
|
|
164
|
-
if (!groupAllowed) {
|
|
165
|
-
log.debug?.("dropping reaction (sender not in group allowlist)", { sender: senderId });
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Resolve the agent route for this conversation/sender.
|
|
171
|
-
// Extract teamId for team-scoped routing bindings (channel/group reactions).
|
|
172
|
-
const teamId = isDirectMessage
|
|
173
|
-
? undefined
|
|
174
|
-
: (activity as unknown as { channelData?: { team?: { id?: string } } }).channelData?.team?.id;
|
|
175
|
-
const route = core.channel.routing.resolveAgentRoute({
|
|
176
|
-
cfg,
|
|
177
|
-
channel: "msteams",
|
|
178
|
-
peer: {
|
|
179
|
-
kind: isDirectMessage ? "direct" : isChannel ? "channel" : "group",
|
|
180
|
-
id: isDirectMessage ? senderId : conversationId,
|
|
181
|
-
},
|
|
182
|
-
...(teamId ? { teamId } : {}),
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// The replyToId points to the message that was reacted to.
|
|
186
|
-
const targetMessageId = (activity as unknown as { replyToId?: string }).replyToId ?? "unknown";
|
|
187
|
-
|
|
188
|
-
for (const reaction of reactions) {
|
|
189
|
-
const reactionType = reaction.type ?? "unknown";
|
|
190
|
-
const emoji = mapReactionEmoji(reactionType);
|
|
191
|
-
const label =
|
|
192
|
-
direction === "added"
|
|
193
|
-
? `Teams reaction ${emoji} added by ${senderName} on message ${targetMessageId}`
|
|
194
|
-
: `Teams reaction ${emoji} removed by ${senderName} from message ${targetMessageId}`;
|
|
195
|
-
|
|
196
|
-
log.info(`reaction ${direction}`, {
|
|
197
|
-
sender: senderId,
|
|
198
|
-
reactionType,
|
|
199
|
-
emoji,
|
|
200
|
-
targetMessageId,
|
|
201
|
-
conversationId,
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
core.system.enqueueSystemEvent(label, {
|
|
205
|
-
sessionKey: route.sessionKey,
|
|
206
|
-
contextKey: `msteams:reaction:${conversationId}:${targetMessageId}:${senderId}:${reactionType}:${direction}`,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
2
|
-
|
|
3
|
-
export function resolveMSTeamsRouteSessionKey(params: {
|
|
4
|
-
baseSessionKey: string;
|
|
5
|
-
isChannel: boolean;
|
|
6
|
-
conversationMessageId?: string;
|
|
7
|
-
replyToId?: string;
|
|
8
|
-
}): string {
|
|
9
|
-
const channelThreadId = params.isChannel
|
|
10
|
-
? (params.conversationMessageId ?? params.replyToId ?? undefined)
|
|
11
|
-
: undefined;
|
|
12
|
-
return resolveThreadSessionKeys({
|
|
13
|
-
baseSessionKey: params.baseSessionKey,
|
|
14
|
-
threadId: channelThreadId,
|
|
15
|
-
parentSessionKey: channelThreadId ? params.baseSessionKey : undefined,
|
|
16
|
-
}).sessionKey;
|
|
17
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
|
|
3
|
-
import type { MSTeamsConversationStore } from "./conversation-store.js";
|
|
4
|
-
import {
|
|
5
|
-
type MSTeamsActivityHandler,
|
|
6
|
-
type MSTeamsMessageHandlerDeps,
|
|
7
|
-
registerMSTeamsHandlers,
|
|
8
|
-
} from "./monitor-handler.js";
|
|
9
|
-
import { installMSTeamsTestRuntime } from "./monitor-handler.test-helpers.js";
|
|
10
|
-
import type { MSTeamsTurnContext } from "./sdk-types.js";
|
|
11
|
-
|
|
12
|
-
const runtimeApiMockState = vi.hoisted(() => ({
|
|
13
|
-
dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
|
|
14
|
-
queuedFinal: false,
|
|
15
|
-
counts: {},
|
|
16
|
-
capturedCtxPayload: params.ctxPayload,
|
|
17
|
-
})),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
vi.mock("openclaw/plugin-sdk/inbound-reply-dispatch", () => {
|
|
21
|
-
return {
|
|
22
|
-
dispatchReplyFromConfigWithSettledDispatcher:
|
|
23
|
-
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
vi.mock("./reply-dispatcher.js", () => ({
|
|
28
|
-
createMSTeamsReplyDispatcher: () => ({
|
|
29
|
-
dispatcher: {},
|
|
30
|
-
replyOptions: {},
|
|
31
|
-
markDispatchIdle: vi.fn(),
|
|
32
|
-
}),
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
function createDeps(): MSTeamsMessageHandlerDeps {
|
|
36
|
-
installMSTeamsTestRuntime();
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
cfg: {} as OpenClawConfig,
|
|
40
|
-
runtime: { error: vi.fn() } as unknown as RuntimeEnv,
|
|
41
|
-
appId: "test-app",
|
|
42
|
-
adapter: {} as MSTeamsMessageHandlerDeps["adapter"],
|
|
43
|
-
tokenProvider: {
|
|
44
|
-
getAccessToken: vi.fn(async () => "token"),
|
|
45
|
-
},
|
|
46
|
-
textLimit: 4000,
|
|
47
|
-
mediaMaxBytes: 1024 * 1024,
|
|
48
|
-
conversationStore: {
|
|
49
|
-
get: vi.fn(async () => null),
|
|
50
|
-
upsert: vi.fn(async () => undefined),
|
|
51
|
-
list: vi.fn(async () => []),
|
|
52
|
-
remove: vi.fn(async () => false),
|
|
53
|
-
findPreferredDmByUserId: vi.fn(async () => null),
|
|
54
|
-
findByUserId: vi.fn(async () => null),
|
|
55
|
-
} satisfies MSTeamsConversationStore,
|
|
56
|
-
pollStore: {
|
|
57
|
-
recordVote: vi.fn(async () => null),
|
|
58
|
-
} as unknown as MSTeamsMessageHandlerDeps["pollStore"],
|
|
59
|
-
log: {
|
|
60
|
-
info: vi.fn(),
|
|
61
|
-
debug: vi.fn(),
|
|
62
|
-
error: vi.fn(),
|
|
63
|
-
} as unknown as MSTeamsMessageHandlerDeps["log"],
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function createActivityHandler() {
|
|
68
|
-
const messageHandlers: Array<(context: unknown, next: () => Promise<void>) => Promise<void>> = [];
|
|
69
|
-
const run = vi.fn(async (context: unknown) => {
|
|
70
|
-
const activityType = (context as MSTeamsTurnContext).activity?.type;
|
|
71
|
-
if (activityType !== "message") {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
for (const handler of messageHandlers) {
|
|
75
|
-
await handler(context, async () => {});
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
let handler: MSTeamsActivityHandler & {
|
|
80
|
-
run: NonNullable<MSTeamsActivityHandler["run"]>;
|
|
81
|
-
};
|
|
82
|
-
handler = {
|
|
83
|
-
onMessage: (nextHandler) => {
|
|
84
|
-
messageHandlers.push(nextHandler);
|
|
85
|
-
return handler;
|
|
86
|
-
},
|
|
87
|
-
onMembersAdded: () => handler,
|
|
88
|
-
onReactionsAdded: () => handler,
|
|
89
|
-
onReactionsRemoved: () => handler,
|
|
90
|
-
run,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return { handler, run };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
describe("msteams adaptive card action invoke", () => {
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher.mockClear();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("forwards adaptive card invoke values to the agent as message text", async () => {
|
|
102
|
-
const deps = createDeps();
|
|
103
|
-
const { handler, run } = createActivityHandler();
|
|
104
|
-
const registered = registerMSTeamsHandlers(handler, deps) as MSTeamsActivityHandler & {
|
|
105
|
-
run: NonNullable<MSTeamsActivityHandler["run"]>;
|
|
106
|
-
};
|
|
107
|
-
const payload = {
|
|
108
|
-
action: {
|
|
109
|
-
type: "Action.Submit",
|
|
110
|
-
data: {
|
|
111
|
-
intent: "deploy",
|
|
112
|
-
environment: "prod",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
trigger: "button-click",
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
await registered.run({
|
|
119
|
-
activity: {
|
|
120
|
-
id: "invoke-1",
|
|
121
|
-
type: "invoke",
|
|
122
|
-
name: "adaptiveCard/action",
|
|
123
|
-
channelId: "msteams",
|
|
124
|
-
serviceUrl: "https://service.example.test",
|
|
125
|
-
from: {
|
|
126
|
-
id: "user-bf",
|
|
127
|
-
aadObjectId: "user-aad",
|
|
128
|
-
name: "User",
|
|
129
|
-
},
|
|
130
|
-
recipient: {
|
|
131
|
-
id: "bot-id",
|
|
132
|
-
name: "Bot",
|
|
133
|
-
},
|
|
134
|
-
conversation: {
|
|
135
|
-
id: "19:personal-chat;messageid=abc123",
|
|
136
|
-
conversationType: "personal",
|
|
137
|
-
},
|
|
138
|
-
channelData: {},
|
|
139
|
-
attachments: [],
|
|
140
|
-
value: payload,
|
|
141
|
-
},
|
|
142
|
-
sendActivity: vi.fn(async () => ({ id: "activity-id" })),
|
|
143
|
-
sendActivities: async () => [],
|
|
144
|
-
} as unknown as MSTeamsTurnContext);
|
|
145
|
-
|
|
146
|
-
expect(run).not.toHaveBeenCalled();
|
|
147
|
-
expect(runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher).toHaveBeenCalledTimes(
|
|
148
|
-
1,
|
|
149
|
-
);
|
|
150
|
-
expect(
|
|
151
|
-
runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher.mock.calls[0]?.[0],
|
|
152
|
-
).toMatchObject({
|
|
153
|
-
ctxPayload: {
|
|
154
|
-
RawBody: JSON.stringify(payload),
|
|
155
|
-
BodyForAgent: JSON.stringify(payload),
|
|
156
|
-
CommandBody: JSON.stringify(payload),
|
|
157
|
-
SessionKey: "msteams:direct:user-aad",
|
|
158
|
-
SenderId: "user-aad",
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|