Skip to content

Commit 88316f5

Browse files
committed
fix(msteams): connect DM quotes and mention order
1 parent 77149ac commit 88316f5

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

extensions/msteams/src/inbound.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("msteams inbound", () => {
112112
it("matches duplicate rendered mention tags by entity occurrence", () => {
113113
expect(
114114
buildMSTeamsNormalizedText({
115-
text: "<at>Bot</at> <at>Bot</at> please check this",
115+
text: '<at id="0">Bot</at> <at>Bot</at> please check this',
116116
botId: "bot-id",
117117
botName: "Bot",
118118
entities: [

extensions/msteams/src/inbound.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function normalizeMSTeamsMentionTags(
194194
botId?: string | null,
195195
botName?: string | null,
196196
): string {
197-
const mentionsByTag = new Map<string, Array<{ id?: string; name: string }>>();
197+
const mentions: Array<{ id?: string; name: string }> = [];
198198
const botMentionNames = new Set<string>();
199199
for (const entity of entities) {
200200
if (
@@ -208,15 +208,13 @@ function normalizeMSTeamsMentionTags(
208208
if (mentionedId && botId && mentionedId === botId) {
209209
botMentionNames.add(entity.mentioned.name.trim());
210210
}
211-
const mentions = mentionsByTag.get(entity.text) ?? [];
212211
mentions.push({
213212
id: mentionedId,
214213
name: entity.mentioned.name,
215214
});
216-
mentionsByTag.set(entity.text, mentions);
217215
}
218216
return text.replace(/<at\b[^>]*>.*?<\/at>/gis, (tag) => {
219-
const mention = mentionsByTag.get(tag)?.shift();
217+
const mention = mentions.shift();
220218
if (mention?.id && botId && mention.id === botId) {
221219
return "";
222220
}

extensions/msteams/src/monitor-handler/message-handler.authz.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ describe("msteams monitor handler authz", () => {
15431543
id: "dm-quote-1",
15441544
text: "what about this?",
15451545
from: { id: "user-id", aadObjectId: "user-aad", name: "User" },
1546-
conversation: { id: "19:dm@thread.v2", conversationType: "personal" },
1546+
conversation: { id: "a:dm-conversation", conversationType: "personal" },
15471547
attachments: [
15481548
{
15491549
contentType: "text/html",
@@ -1559,7 +1559,7 @@ describe("msteams monitor handler authz", () => {
15591559
expect(deps.tokenProvider.getAccessToken).toHaveBeenCalledWith("https://graph.microsoft.com");
15601560
expect(graphThreadMockState.fetchChatMessageText).toHaveBeenCalledWith(
15611561
"token",
1562-
1562+
15631563
"message-1",
15641564
expect.objectContaining({
15651565
label: "MS Teams inbound preprocessing",

extensions/msteams/src/monitor-handler/message-handler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
extractMSTeamsQuoteInfo,
4949
normalizeMSTeamsConversationId,
5050
parseMSTeamsActivityTimestamp,
51+
translateMSTeamsDmConversationIdForGraph,
5152
wasMSTeamsBotMentioned,
5253
} from "../inbound.js";
5354
import { createMSTeamsInboundDeadline, withMSTeamsRequestDeadline } from "../request-timeout.js";
@@ -663,7 +664,13 @@ export function createMSTeamsMessageHandler(deps: MSTeamsMessageHandlerDeps) {
663664
// and channel quotes retain their visibility-filtered preview.
664665
let quoteBodyFull: string | undefined;
665666
const quoteMessageId = quoteInfo?.id;
666-
if (quoteMessageId && isDirectMessage && conversationId.startsWith("19:")) {
667+
const graphConversationId = translateMSTeamsDmConversationIdForGraph({
668+
isDirectMessage,
669+
conversationId,
670+
aadObjectId,
671+
appId,
672+
});
673+
if (quoteMessageId && isDirectMessage && graphConversationId.startsWith("19:")) {
667674
try {
668675
const graphToken = await withMSTeamsRequestDeadline({
669676
deadline: preprocessingDeadline,
@@ -674,7 +681,12 @@ export function createMSTeamsMessageHandler(deps: MSTeamsMessageHandlerDeps) {
674681
deadline: preprocessingDeadline,
675682
label: "MS Teams quote lookup",
676683
work: () =>
677-
fetchChatMessageText(graphToken, conversationId, quoteMessageId, preprocessingDeadline),
684+
fetchChatMessageText(
685+
graphToken,
686+
graphConversationId,
687+
quoteMessageId,
688+
preprocessingDeadline,
689+
),
678690
});
679691
} catch (err) {
680692
log.debug?.("failed to fetch full quoted message text", {

0 commit comments

Comments
 (0)