@kodelyth/msteams 2026.5.42 → 2026.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/klaw.plugin.json +726 -2
- package/package.json +18 -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 -66
- 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 -506
- package/src/attachments/bot-framework.ts +0 -348
- package/src/attachments/download.ts +0 -328
- package/src/attachments/graph.test.ts +0 -441
- package/src/attachments/graph.ts +0 -489
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -187
- package/src/attachments/remote-media.ts +0 -86
- package/src/attachments/shared.test.ts +0 -547
- package/src/attachments/shared.ts +0 -655
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -414
- package/src/attachments.helpers.test.ts +0 -245
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -754
- 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 -797
- package/src/channel.directory.test.ts +0 -176
- package/src/channel.message-adapter.test.ts +0 -227
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -136
- package/src/channel.ts +0 -1176
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -40
- package/src/conversation-store-fs.test.ts +0 -81
- 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 -260
- 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 -154
- package/src/errors.ts +0 -270
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -113
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -268
- package/src/file-consent-helpers.test.ts +0 -328
- package/src/file-consent-helpers.ts +0 -115
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -378
- package/src/file-consent.ts +0 -223
- package/src/graph-chat.ts +0 -36
- package/src/graph-group-management.test.ts +0 -332
- 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 -253
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -227
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -222
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -252
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -253
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -540
- package/src/graph.ts +0 -308
- 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 -220
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -254
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -961
- package/src/messenger.ts +0 -608
- package/src/monitor-handler/access.ts +0 -136
- package/src/monitor-handler/inbound-media.test.ts +0 -314
- 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 -739
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -99
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
- package/src/monitor-handler/message-handler.ts +0 -1003
- package/src/monitor-handler/reaction-handler.test.ts +0 -325
- package/src/monitor-handler/reaction-handler.ts +0 -122
- package/src/monitor-handler/thread-session.ts +0 -30
- package/src/monitor-handler.adaptive-card.test.ts +0 -158
- package/src/monitor-handler.feedback-authz.test.ts +0 -357
- package/src/monitor-handler.file-consent.test.ts +0 -443
- package/src/monitor-handler.sso.test.ts +0 -576
- package/src/monitor-handler.test-helpers.ts +0 -181
- package/src/monitor-handler.ts +0 -538
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -457
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -476
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -350
- package/src/oauth.token.ts +0 -162
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -400
- package/src/outbound.ts +0 -198
- package/src/pending-uploads-fs.test.ts +0 -261
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -186
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -156
- package/src/policy.ts +0 -245
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -169
- package/src/polls.ts +0 -312
- package/src/presentation.ts +0 -93
- package/src/probe.test.ts +0 -79
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -543
- package/src/reply-dispatcher.ts +0 -523
- package/src/reply-stream-controller.test.ts +0 -424
- package/src/reply-stream-controller.ts +0 -334
- package/src/resolve-allowlist.test.ts +0 -253
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -12
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -727
- package/src/sdk.ts +0 -916
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.test.ts +0 -93
- package/src/send-context.ts +0 -269
- package/src/send.test.ts +0 -588
- package/src/send.ts +0 -697
- package/src/sent-message-cache.test.ts +0 -106
- package/src/sent-message-cache.ts +0 -174
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -162
- package/src/setup-surface.test.ts +0 -175
- package/src/setup-surface.ts +0 -319
- package/src/sso-token-store.test.ts +0 -74
- 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 -42
- package/src/streaming-message.test.ts +0 -323
- package/src/streaming-message.ts +0 -327
- 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 -268
- package/src/token.ts +0 -194
- package/src/user-agent.test.ts +0 -121
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -104
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
package/src/send.test.ts
DELETED
|
@@ -1,588 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { KlawConfig } from "../runtime-api.js";
|
|
3
|
-
import { deleteMessageMSTeams, editMessageMSTeams, sendMessageMSTeams } from "./send.js";
|
|
4
|
-
|
|
5
|
-
const mockState = vi.hoisted(() => ({
|
|
6
|
-
loadOutboundMediaFromUrl: vi.fn(),
|
|
7
|
-
resolveMSTeamsSendContext: vi.fn(),
|
|
8
|
-
resolveMarkdownTableMode: vi.fn(() => "off"),
|
|
9
|
-
convertMarkdownTables: vi.fn((text: string) => text),
|
|
10
|
-
runtimeResolveMarkdownTableMode: vi.fn(() => "off"),
|
|
11
|
-
runtimeConvertMarkdownTables: vi.fn((text: string) => text),
|
|
12
|
-
requiresFileConsent: vi.fn(),
|
|
13
|
-
prepareFileConsentActivity: vi.fn(),
|
|
14
|
-
prepareFileConsentActivityFs: vi.fn(),
|
|
15
|
-
extractFilename: vi.fn(async () => "fallback.bin"),
|
|
16
|
-
sendMSTeamsMessages: vi.fn(),
|
|
17
|
-
uploadAndShareSharePoint: vi.fn(),
|
|
18
|
-
getDriveItemProperties: vi.fn(),
|
|
19
|
-
buildTeamsFileInfoCard: vi.fn(),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
vi.mock("klaw/plugin-sdk/outbound-media", () => ({
|
|
23
|
-
loadOutboundMediaFromUrl: mockState.loadOutboundMediaFromUrl,
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
vi.mock("klaw/plugin-sdk/markdown-table-runtime", () => ({
|
|
27
|
-
resolveMarkdownTableMode: mockState.resolveMarkdownTableMode,
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
vi.mock("klaw/plugin-sdk/text-chunking", async (importOriginal) => {
|
|
31
|
-
const actual = await importOriginal<typeof import("klaw/plugin-sdk/text-chunking")>();
|
|
32
|
-
return {
|
|
33
|
-
...actual,
|
|
34
|
-
convertMarkdownTables: mockState.convertMarkdownTables,
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
vi.mock("./send-context.js", () => ({
|
|
39
|
-
resolveMSTeamsSendContext: mockState.resolveMSTeamsSendContext,
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
vi.mock("./file-consent-helpers.js", () => ({
|
|
43
|
-
requiresFileConsent: mockState.requiresFileConsent,
|
|
44
|
-
prepareFileConsentActivity: mockState.prepareFileConsentActivity,
|
|
45
|
-
prepareFileConsentActivityFs: mockState.prepareFileConsentActivityFs,
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
vi.mock("./media-helpers.js", () => ({
|
|
49
|
-
extractFilename: mockState.extractFilename,
|
|
50
|
-
extractMessageId: () => "message-1",
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
vi.mock("./messenger.js", () => ({
|
|
54
|
-
sendMSTeamsMessages: mockState.sendMSTeamsMessages,
|
|
55
|
-
buildConversationReference: () => ({}),
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
vi.mock("./runtime.js", () => ({
|
|
59
|
-
getMSTeamsRuntime: () => ({
|
|
60
|
-
channel: {
|
|
61
|
-
text: {
|
|
62
|
-
resolveMarkdownTableMode: mockState.runtimeResolveMarkdownTableMode,
|
|
63
|
-
convertMarkdownTables: mockState.runtimeConvertMarkdownTables,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
}),
|
|
67
|
-
}));
|
|
68
|
-
|
|
69
|
-
vi.mock("./graph-upload.js", () => ({
|
|
70
|
-
uploadAndShareSharePoint: mockState.uploadAndShareSharePoint,
|
|
71
|
-
getDriveItemProperties: mockState.getDriveItemProperties,
|
|
72
|
-
uploadAndShareOneDrive: vi.fn(),
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
vi.mock("./graph-chat.js", () => ({
|
|
76
|
-
buildTeamsFileInfoCard: mockState.buildTeamsFileInfoCard,
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
function mockContinueConversationFailure(error: string) {
|
|
80
|
-
const mockContinueConversation = vi.fn().mockRejectedValue(new Error(error));
|
|
81
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
82
|
-
adapter: { continueConversation: mockContinueConversation },
|
|
83
|
-
appId: "app-id",
|
|
84
|
-
conversationId: "19:conversation@thread.tacv2",
|
|
85
|
-
ref: {
|
|
86
|
-
user: { id: "user-1" },
|
|
87
|
-
agent: { id: "agent-1" },
|
|
88
|
-
conversation: { id: "19:conversation@thread.tacv2" },
|
|
89
|
-
channelId: "msteams",
|
|
90
|
-
},
|
|
91
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
92
|
-
conversationType: "personal",
|
|
93
|
-
tokenProvider: {},
|
|
94
|
-
});
|
|
95
|
-
return mockContinueConversation;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const continueConversationFailureCases = [
|
|
99
|
-
{
|
|
100
|
-
name: "editMessageMSTeams",
|
|
101
|
-
error: "Service unavailable",
|
|
102
|
-
expected: "msteams edit failed",
|
|
103
|
-
invoke: () =>
|
|
104
|
-
editMessageMSTeams({
|
|
105
|
-
cfg: {} as KlawConfig,
|
|
106
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
107
|
-
activityId: "activity-123",
|
|
108
|
-
text: "Updated text",
|
|
109
|
-
}),
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: "deleteMessageMSTeams",
|
|
113
|
-
error: "Not found",
|
|
114
|
-
expected: "msteams delete failed",
|
|
115
|
-
invoke: () =>
|
|
116
|
-
deleteMessageMSTeams({
|
|
117
|
-
cfg: {} as KlawConfig,
|
|
118
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
119
|
-
activityId: "activity-456",
|
|
120
|
-
}),
|
|
121
|
-
},
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
function createSharePointSendContext(params: {
|
|
125
|
-
conversationId: string;
|
|
126
|
-
graphChatId: string | null;
|
|
127
|
-
siteId: string;
|
|
128
|
-
}) {
|
|
129
|
-
return {
|
|
130
|
-
adapter: {
|
|
131
|
-
continueConversation: vi.fn(
|
|
132
|
-
async (
|
|
133
|
-
_id: string,
|
|
134
|
-
_ref: unknown,
|
|
135
|
-
fn: (ctx: { sendActivity: () => { id: "msg-1" } }) => Promise<void>,
|
|
136
|
-
) => fn({ sendActivity: () => ({ id: "msg-1" }) }),
|
|
137
|
-
),
|
|
138
|
-
},
|
|
139
|
-
appId: "app-id",
|
|
140
|
-
conversationId: params.conversationId,
|
|
141
|
-
graphChatId: params.graphChatId,
|
|
142
|
-
ref: {},
|
|
143
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
144
|
-
conversationType: "groupChat" as const,
|
|
145
|
-
replyStyle: "top-level" as const,
|
|
146
|
-
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
147
|
-
mediaMaxBytes: 8 * 1024 * 1024,
|
|
148
|
-
sharePointSiteId: params.siteId,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function mockSharePointPdfUpload(params: {
|
|
153
|
-
bufferSize: number;
|
|
154
|
-
fileName: string;
|
|
155
|
-
itemId: string;
|
|
156
|
-
uniqueId: string;
|
|
157
|
-
}) {
|
|
158
|
-
mockState.loadOutboundMediaFromUrl.mockResolvedValueOnce({
|
|
159
|
-
buffer: Buffer.alloc(params.bufferSize, "pdf"),
|
|
160
|
-
contentType: "application/pdf",
|
|
161
|
-
fileName: params.fileName,
|
|
162
|
-
kind: "file",
|
|
163
|
-
});
|
|
164
|
-
mockState.requiresFileConsent.mockReturnValue(false);
|
|
165
|
-
mockState.uploadAndShareSharePoint.mockResolvedValue({
|
|
166
|
-
itemId: params.itemId,
|
|
167
|
-
webUrl: `https://sp.example.com/${params.fileName}`,
|
|
168
|
-
shareUrl: `https://sp.example.com/share/${params.fileName}`,
|
|
169
|
-
name: params.fileName,
|
|
170
|
-
});
|
|
171
|
-
mockState.getDriveItemProperties.mockResolvedValue({
|
|
172
|
-
eTag: `"${params.uniqueId},1"`,
|
|
173
|
-
webDavUrl: `https://sp.example.com/dav/${params.fileName}`,
|
|
174
|
-
name: params.fileName,
|
|
175
|
-
});
|
|
176
|
-
mockState.buildTeamsFileInfoCard.mockReturnValue({
|
|
177
|
-
contentType: "application/vnd.microsoft.teams.card.file.info",
|
|
178
|
-
contentUrl: `https://sp.example.com/dav/${params.fileName}`,
|
|
179
|
-
name: params.fileName,
|
|
180
|
-
content: { uniqueId: params.uniqueId, fileType: "pdf" },
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
type MockWithCalls = {
|
|
185
|
-
mock: { calls: unknown[][] };
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function mockCallAt(mock: MockWithCalls, index = 0): unknown[] {
|
|
189
|
-
const call = mock.mock.calls[index];
|
|
190
|
-
if (!call) {
|
|
191
|
-
throw new Error(`expected mock call ${index}`);
|
|
192
|
-
}
|
|
193
|
-
return call;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function firstObjectArg(mock: MockWithCalls): Record<string, unknown> {
|
|
197
|
-
const value = mockCallAt(mock)[0];
|
|
198
|
-
if (value === undefined || value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
199
|
-
throw new Error("expected first mock call to receive an object argument");
|
|
200
|
-
}
|
|
201
|
-
return value as Record<string, unknown>;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function continueConversationCall(mock: MockWithCalls): unknown[] {
|
|
205
|
-
return mockCallAt(mock);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function continueConversationRef(mock: MockWithCalls): Record<string, unknown> {
|
|
209
|
-
const ref = continueConversationCall(mock)[1];
|
|
210
|
-
if (ref === undefined || ref === null || typeof ref !== "object" || Array.isArray(ref)) {
|
|
211
|
-
throw new Error("expected continueConversation ref object");
|
|
212
|
-
}
|
|
213
|
-
return ref as Record<string, unknown>;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
describe("sendMessageMSTeams", () => {
|
|
217
|
-
beforeEach(() => {
|
|
218
|
-
mockState.loadOutboundMediaFromUrl.mockReset();
|
|
219
|
-
mockState.resolveMSTeamsSendContext.mockReset();
|
|
220
|
-
mockState.resolveMarkdownTableMode.mockReset();
|
|
221
|
-
mockState.resolveMarkdownTableMode.mockReturnValue("off");
|
|
222
|
-
mockState.convertMarkdownTables.mockReset();
|
|
223
|
-
mockState.convertMarkdownTables.mockImplementation((text: string) => text);
|
|
224
|
-
mockState.runtimeResolveMarkdownTableMode.mockReset();
|
|
225
|
-
mockState.runtimeResolveMarkdownTableMode.mockReturnValue("off");
|
|
226
|
-
mockState.runtimeConvertMarkdownTables.mockReset();
|
|
227
|
-
mockState.runtimeConvertMarkdownTables.mockImplementation((text: string) => text);
|
|
228
|
-
mockState.requiresFileConsent.mockReset();
|
|
229
|
-
mockState.prepareFileConsentActivity.mockReset();
|
|
230
|
-
mockState.prepareFileConsentActivityFs.mockReset();
|
|
231
|
-
mockState.extractFilename.mockReset();
|
|
232
|
-
mockState.sendMSTeamsMessages.mockReset();
|
|
233
|
-
mockState.uploadAndShareSharePoint.mockReset();
|
|
234
|
-
mockState.getDriveItemProperties.mockReset();
|
|
235
|
-
mockState.buildTeamsFileInfoCard.mockReset();
|
|
236
|
-
|
|
237
|
-
mockState.extractFilename.mockResolvedValue("fallback.bin");
|
|
238
|
-
mockState.requiresFileConsent.mockReturnValue(false);
|
|
239
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
240
|
-
adapter: {},
|
|
241
|
-
appId: "app-id",
|
|
242
|
-
conversationId: "19:conversation@thread.tacv2",
|
|
243
|
-
ref: {},
|
|
244
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
245
|
-
conversationType: "personal",
|
|
246
|
-
replyStyle: "top-level",
|
|
247
|
-
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
248
|
-
mediaMaxBytes: 8 * 1024,
|
|
249
|
-
sharePointSiteId: undefined,
|
|
250
|
-
});
|
|
251
|
-
mockState.sendMSTeamsMessages.mockResolvedValue(["message-1"]);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("loads media through shared helper and forwards mediaLocalRoots", async () => {
|
|
255
|
-
const mediaBuffer = Buffer.from("tiny-image");
|
|
256
|
-
mockState.loadOutboundMediaFromUrl.mockResolvedValueOnce({
|
|
257
|
-
buffer: mediaBuffer,
|
|
258
|
-
contentType: "image/png",
|
|
259
|
-
fileName: "inline.png",
|
|
260
|
-
kind: "image",
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
const result = await sendMessageMSTeams({
|
|
264
|
-
cfg: {} as KlawConfig,
|
|
265
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
266
|
-
text: "hello",
|
|
267
|
-
mediaUrl: "file:///tmp/agent-workspace/inline.png",
|
|
268
|
-
mediaLocalRoots: ["/tmp/agent-workspace"],
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
expect(mockState.loadOutboundMediaFromUrl).toHaveBeenCalledWith(
|
|
272
|
-
"file:///tmp/agent-workspace/inline.png",
|
|
273
|
-
{
|
|
274
|
-
maxBytes: 8 * 1024,
|
|
275
|
-
mediaLocalRoots: ["/tmp/agent-workspace"],
|
|
276
|
-
},
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
const sendPayload = firstObjectArg(mockState.sendMSTeamsMessages);
|
|
280
|
-
const messages = sendPayload.messages as Array<Record<string, unknown>>;
|
|
281
|
-
expect(messages).toHaveLength(1);
|
|
282
|
-
expect(messages[0]?.text).toBe("hello");
|
|
283
|
-
expect(messages[0]?.mediaUrl).toBe(`data:image/png;base64,${mediaBuffer.toString("base64")}`);
|
|
284
|
-
expect(result.receipt?.primaryPlatformMessageId).toBe("message-1");
|
|
285
|
-
expect(result.receipt?.platformMessageIds).toEqual(["message-1"]);
|
|
286
|
-
expect(result.receipt?.parts).toHaveLength(1);
|
|
287
|
-
expect(result.receipt?.parts[0]?.platformMessageId).toBe("message-1");
|
|
288
|
-
expect(result.receipt?.parts[0]?.kind).toBe("media");
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it("sends with provided cfg even when Teams runtime text helpers are unavailable", async () => {
|
|
292
|
-
mockState.runtimeResolveMarkdownTableMode.mockImplementation(() => {
|
|
293
|
-
throw new Error("MSTeams runtime not initialized");
|
|
294
|
-
});
|
|
295
|
-
mockState.runtimeConvertMarkdownTables.mockImplementation(() => {
|
|
296
|
-
throw new Error("MSTeams runtime not initialized");
|
|
297
|
-
});
|
|
298
|
-
mockState.resolveMarkdownTableMode.mockReturnValue("off");
|
|
299
|
-
mockState.convertMarkdownTables.mockReturnValue("hello");
|
|
300
|
-
|
|
301
|
-
const result = await sendMessageMSTeams({
|
|
302
|
-
cfg: {} as KlawConfig,
|
|
303
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
304
|
-
text: "hello",
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
expect(result.messageId).toBe("message-1");
|
|
308
|
-
expect(result.conversationId).toBe("19:conversation@thread.tacv2");
|
|
309
|
-
expect(result.receipt?.primaryPlatformMessageId).toBe("message-1");
|
|
310
|
-
expect(result.receipt?.platformMessageIds).toEqual(["message-1"]);
|
|
311
|
-
expect(result.receipt?.parts).toHaveLength(1);
|
|
312
|
-
expect(result.receipt?.parts[0]?.platformMessageId).toBe("message-1");
|
|
313
|
-
expect(result.receipt?.parts[0]?.kind).toBe("text");
|
|
314
|
-
|
|
315
|
-
expect(mockState.resolveMarkdownTableMode).toHaveBeenCalledWith({
|
|
316
|
-
cfg: {},
|
|
317
|
-
channel: "msteams",
|
|
318
|
-
});
|
|
319
|
-
expect(mockState.convertMarkdownTables).toHaveBeenCalledWith("hello", "off");
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("passes the resolved proactive replyStyle to text sends", async () => {
|
|
323
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
324
|
-
adapter: {},
|
|
325
|
-
appId: "app-id",
|
|
326
|
-
conversationId: "19:channel@thread.tacv2",
|
|
327
|
-
ref: {
|
|
328
|
-
threadId: "thread-root-1",
|
|
329
|
-
conversation: { id: "19:channel@thread.tacv2", conversationType: "channel" },
|
|
330
|
-
},
|
|
331
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
332
|
-
conversationType: "channel",
|
|
333
|
-
replyStyle: "thread",
|
|
334
|
-
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
335
|
-
mediaMaxBytes: 8 * 1024,
|
|
336
|
-
sharePointSiteId: undefined,
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
await sendMessageMSTeams({
|
|
340
|
-
cfg: {} as KlawConfig,
|
|
341
|
-
to: "conversation:19:channel@thread.tacv2",
|
|
342
|
-
text: "threaded reply",
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
expect(firstObjectArg(mockState.sendMSTeamsMessages).replyStyle).toBe("thread");
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it("keeps top-level proactive replyStyle when resolved for a channel", async () => {
|
|
349
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
350
|
-
adapter: {},
|
|
351
|
-
appId: "app-id",
|
|
352
|
-
conversationId: "19:channel@thread.tacv2",
|
|
353
|
-
ref: {
|
|
354
|
-
threadId: "thread-root-1",
|
|
355
|
-
conversation: { id: "19:channel@thread.tacv2", conversationType: "channel" },
|
|
356
|
-
},
|
|
357
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
358
|
-
conversationType: "channel",
|
|
359
|
-
replyStyle: "top-level",
|
|
360
|
-
tokenProvider: { getAccessToken: vi.fn(async () => "token") },
|
|
361
|
-
mediaMaxBytes: 8 * 1024,
|
|
362
|
-
sharePointSiteId: undefined,
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
await sendMessageMSTeams({
|
|
366
|
-
cfg: {} as KlawConfig,
|
|
367
|
-
to: "conversation:19:channel@thread.tacv2",
|
|
368
|
-
text: "top-level reply",
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
expect(firstObjectArg(mockState.sendMSTeamsMessages).replyStyle).toBe("top-level");
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it("uses graphChatId instead of conversationId when uploading to SharePoint", async () => {
|
|
375
|
-
// Simulates a group chat where Bot Framework conversationId is valid but we have
|
|
376
|
-
// a resolved Graph chat ID cached from a prior send.
|
|
377
|
-
const graphChatId = "19:graph-native-chat-id@thread.tacv2";
|
|
378
|
-
const botFrameworkConversationId = "19:bot-framework-id@thread.tacv2";
|
|
379
|
-
|
|
380
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue(
|
|
381
|
-
createSharePointSendContext({
|
|
382
|
-
conversationId: botFrameworkConversationId,
|
|
383
|
-
graphChatId,
|
|
384
|
-
siteId: "site-123",
|
|
385
|
-
}),
|
|
386
|
-
);
|
|
387
|
-
mockSharePointPdfUpload({
|
|
388
|
-
bufferSize: 100,
|
|
389
|
-
fileName: "doc.pdf",
|
|
390
|
-
itemId: "item-1",
|
|
391
|
-
uniqueId: "{GUID-123}",
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
await sendMessageMSTeams({
|
|
395
|
-
cfg: {} as KlawConfig,
|
|
396
|
-
to: "conversation:19:bot-framework-id@thread.tacv2",
|
|
397
|
-
text: "here is a file",
|
|
398
|
-
mediaUrl: "https://example.com/doc.pdf",
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// The Graph-native chatId must be passed to SharePoint upload, not the Bot Framework ID
|
|
402
|
-
const uploadPayload = firstObjectArg(mockState.uploadAndShareSharePoint);
|
|
403
|
-
expect(uploadPayload.chatId).toBe(graphChatId);
|
|
404
|
-
expect(uploadPayload.siteId).toBe("site-123");
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
it("falls back to conversationId when graphChatId is not available", async () => {
|
|
408
|
-
const botFrameworkConversationId = "19:fallback-id@thread.tacv2";
|
|
409
|
-
|
|
410
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue(
|
|
411
|
-
createSharePointSendContext({
|
|
412
|
-
conversationId: botFrameworkConversationId,
|
|
413
|
-
graphChatId: null,
|
|
414
|
-
siteId: "site-456",
|
|
415
|
-
}),
|
|
416
|
-
);
|
|
417
|
-
mockSharePointPdfUpload({
|
|
418
|
-
bufferSize: 50,
|
|
419
|
-
fileName: "report.pdf",
|
|
420
|
-
itemId: "item-2",
|
|
421
|
-
uniqueId: "{GUID-456}",
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
await sendMessageMSTeams({
|
|
425
|
-
cfg: {} as KlawConfig,
|
|
426
|
-
to: "conversation:19:fallback-id@thread.tacv2",
|
|
427
|
-
text: "report",
|
|
428
|
-
mediaUrl: "https://example.com/report.pdf",
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Falls back to conversationId when graphChatId is null
|
|
432
|
-
const uploadPayload = firstObjectArg(mockState.uploadAndShareSharePoint);
|
|
433
|
-
expect(uploadPayload.chatId).toBe(botFrameworkConversationId);
|
|
434
|
-
expect(uploadPayload.siteId).toBe("site-456");
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
describe("MSTeams continueConversation failure handling", () => {
|
|
439
|
-
beforeEach(() => {
|
|
440
|
-
mockState.resolveMSTeamsSendContext.mockReset();
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it.each(continueConversationFailureCases)(
|
|
444
|
-
"$name throws a descriptive error when continueConversation fails",
|
|
445
|
-
async ({ error, expected, invoke }) => {
|
|
446
|
-
mockContinueConversationFailure(error);
|
|
447
|
-
|
|
448
|
-
await expect(invoke()).rejects.toThrow(expected);
|
|
449
|
-
},
|
|
450
|
-
);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
describe("editMessageMSTeams", () => {
|
|
454
|
-
beforeEach(() => {
|
|
455
|
-
mockState.resolveMSTeamsSendContext.mockReset();
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it("calls continueConversation and updateActivity with correct params", async () => {
|
|
459
|
-
const mockUpdateActivity = vi.fn();
|
|
460
|
-
const mockContinueConversation = vi.fn(
|
|
461
|
-
async (_appId: string, _ref: unknown, logic: (ctx: unknown) => Promise<void>) => {
|
|
462
|
-
await logic({
|
|
463
|
-
sendActivity: vi.fn(),
|
|
464
|
-
updateActivity: mockUpdateActivity,
|
|
465
|
-
deleteActivity: vi.fn(),
|
|
466
|
-
});
|
|
467
|
-
},
|
|
468
|
-
);
|
|
469
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
470
|
-
adapter: { continueConversation: mockContinueConversation },
|
|
471
|
-
appId: "app-id",
|
|
472
|
-
conversationId: "19:conversation@thread.tacv2",
|
|
473
|
-
ref: {
|
|
474
|
-
user: { id: "user-1" },
|
|
475
|
-
agent: { id: "agent-1" },
|
|
476
|
-
conversation: { id: "19:conversation@thread.tacv2", conversationType: "personal" },
|
|
477
|
-
channelId: "msteams",
|
|
478
|
-
},
|
|
479
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
480
|
-
conversationType: "personal",
|
|
481
|
-
tokenProvider: {},
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
const result = await editMessageMSTeams({
|
|
485
|
-
cfg: {} as KlawConfig,
|
|
486
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
487
|
-
activityId: "activity-123",
|
|
488
|
-
text: "Updated message text",
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
expect(result.conversationId).toBe("19:conversation@thread.tacv2");
|
|
492
|
-
expect(mockContinueConversation).toHaveBeenCalledTimes(1);
|
|
493
|
-
const call = continueConversationCall(mockContinueConversation);
|
|
494
|
-
expect(call[0]).toBe("app-id");
|
|
495
|
-
expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
|
|
496
|
-
expect(typeof call[2]).toBe("function");
|
|
497
|
-
expect(mockUpdateActivity).toHaveBeenCalledWith({
|
|
498
|
-
type: "message",
|
|
499
|
-
id: "activity-123",
|
|
500
|
-
text: "Updated message text",
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
describe("deleteMessageMSTeams", () => {
|
|
506
|
-
beforeEach(() => {
|
|
507
|
-
mockState.resolveMSTeamsSendContext.mockReset();
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
it("calls continueConversation and deleteActivity with correct activityId", async () => {
|
|
511
|
-
const mockDeleteActivity = vi.fn();
|
|
512
|
-
const mockContinueConversation = vi.fn(
|
|
513
|
-
async (_appId: string, _ref: unknown, logic: (ctx: unknown) => Promise<void>) => {
|
|
514
|
-
await logic({
|
|
515
|
-
sendActivity: vi.fn(),
|
|
516
|
-
updateActivity: vi.fn(),
|
|
517
|
-
deleteActivity: mockDeleteActivity,
|
|
518
|
-
});
|
|
519
|
-
},
|
|
520
|
-
);
|
|
521
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
522
|
-
adapter: { continueConversation: mockContinueConversation },
|
|
523
|
-
appId: "app-id",
|
|
524
|
-
conversationId: "19:conversation@thread.tacv2",
|
|
525
|
-
ref: {
|
|
526
|
-
user: { id: "user-1" },
|
|
527
|
-
agent: { id: "agent-1" },
|
|
528
|
-
conversation: { id: "19:conversation@thread.tacv2", conversationType: "groupChat" },
|
|
529
|
-
channelId: "msteams",
|
|
530
|
-
},
|
|
531
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
532
|
-
conversationType: "groupChat",
|
|
533
|
-
tokenProvider: {},
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
const result = await deleteMessageMSTeams({
|
|
537
|
-
cfg: {} as KlawConfig,
|
|
538
|
-
to: "conversation:19:conversation@thread.tacv2",
|
|
539
|
-
activityId: "activity-456",
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
expect(result.conversationId).toBe("19:conversation@thread.tacv2");
|
|
543
|
-
expect(mockContinueConversation).toHaveBeenCalledTimes(1);
|
|
544
|
-
const call = continueConversationCall(mockContinueConversation);
|
|
545
|
-
expect(call[0]).toBe("app-id");
|
|
546
|
-
expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
|
|
547
|
-
expect(typeof call[2]).toBe("function");
|
|
548
|
-
expect(mockDeleteActivity).toHaveBeenCalledWith("activity-456");
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it("passes the appId and proactive ref to continueConversation", async () => {
|
|
552
|
-
const mockContinueConversation = vi.fn(
|
|
553
|
-
async (_appId: string, _ref: unknown, logic: (ctx: unknown) => Promise<void>) => {
|
|
554
|
-
await logic({
|
|
555
|
-
sendActivity: vi.fn(),
|
|
556
|
-
updateActivity: vi.fn(),
|
|
557
|
-
deleteActivity: vi.fn(),
|
|
558
|
-
});
|
|
559
|
-
},
|
|
560
|
-
);
|
|
561
|
-
mockState.resolveMSTeamsSendContext.mockResolvedValue({
|
|
562
|
-
adapter: { continueConversation: mockContinueConversation },
|
|
563
|
-
appId: "my-app-id",
|
|
564
|
-
conversationId: "19:conv@thread.tacv2",
|
|
565
|
-
ref: {
|
|
566
|
-
activityId: "original-activity",
|
|
567
|
-
user: { id: "user-1" },
|
|
568
|
-
agent: { id: "agent-1" },
|
|
569
|
-
conversation: { id: "19:conv@thread.tacv2" },
|
|
570
|
-
channelId: "msteams",
|
|
571
|
-
},
|
|
572
|
-
log: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
573
|
-
conversationType: "personal",
|
|
574
|
-
tokenProvider: {},
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
await deleteMessageMSTeams({
|
|
578
|
-
cfg: {} as KlawConfig,
|
|
579
|
-
to: "conversation:19:conv@thread.tacv2",
|
|
580
|
-
activityId: "activity-789",
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
// appId should be forwarded correctly
|
|
584
|
-
expect(continueConversationCall(mockContinueConversation)[0]).toBe("my-app-id");
|
|
585
|
-
// activityId on the proactive ref should be cleared (undefined) — proactive pattern
|
|
586
|
-
expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
|
|
587
|
-
});
|
|
588
|
-
});
|