From 04b1eb57eb5ec7cc477fc72aeaf7128f09f0cf39 Mon Sep 17 00:00:00 2001 From: Onur Date: Thu, 8 Jan 2026 10:01:05 +0300 Subject: [PATCH] MS Teams: fix top-level replies (agent reference) --- src/msteams/conversation-store.ts | 4 +++- src/msteams/messenger.test.ts | 2 ++ src/msteams/messenger.ts | 14 +++++++++++--- src/msteams/monitor.ts | 12 +++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/msteams/conversation-store.ts b/src/msteams/conversation-store.ts index 75bd63c92..a76b4d3f2 100644 --- a/src/msteams/conversation-store.ts +++ b/src/msteams/conversation-store.ts @@ -11,7 +11,9 @@ export type StoredConversationReference = { activityId?: string; /** User who sent the message */ user?: { id?: string; name?: string; aadObjectId?: string }; - /** Bot that received the message */ + /** Agent/bot that received the message */ + agent?: { id?: string; name?: string; aadObjectId?: string } | null; + /** @deprecated legacy field (pre-Agents SDK). Prefer `agent`. */ bot?: { id?: string; name?: string }; /** Conversation details */ conversation?: { id?: string; conversationType?: string; tenantId?: string }; diff --git a/src/msteams/messenger.test.ts b/src/msteams/messenger.test.ts index 0fbbdb764..2da449d4f 100644 --- a/src/msteams/messenger.test.ts +++ b/src/msteams/messenger.test.ts @@ -46,6 +46,8 @@ describe("msteams messenger", () => { describe("sendMSTeamsMessages", () => { const baseRef: StoredConversationReference = { activityId: "activity123", + user: { id: "user123", name: "User" }, + agent: { id: "bot123", name: "Bot" }, conversation: { id: "19:abc@thread.tacv2;messageid=deadbeef" }, channelId: "msteams", serviceUrl: "https://service.example.com", diff --git a/src/msteams/messenger.ts b/src/msteams/messenger.ts index aa21be60a..b33db42f2 100644 --- a/src/msteams/messenger.ts +++ b/src/msteams/messenger.ts @@ -12,7 +12,7 @@ type SendContext = { type ConversationReference = { activityId?: string; user?: { id?: string; name?: string; aadObjectId?: string }; - bot?: { id?: string; name?: string }; + agent?: { id?: string; name?: string; aadObjectId?: string } | null; conversation: { id: string; conversationType?: string; tenantId?: string }; channelId: string; serviceUrl?: string; @@ -59,10 +59,18 @@ function buildConversationReference( if (!conversationId) { throw new Error("Invalid stored reference: missing conversation.id"); } + const agent = ref.agent ?? ref.bot ?? undefined; + if (agent == null || !agent.id) { + throw new Error("Invalid stored reference: missing agent.id"); + } + const user = ref.user; + if (!user?.id) { + throw new Error("Invalid stored reference: missing user.id"); + } return { activityId: ref.activityId, - user: ref.user, - bot: ref.bot, + user, + agent, conversation: { id: normalizeConversationId(conversationId), conversationType: ref.conversation?.conversationType, diff --git a/src/msteams/monitor.ts b/src/msteams/monitor.ts index 5b9cebe5f..11be94d43 100644 --- a/src/msteams/monitor.ts +++ b/src/msteams/monitor.ts @@ -143,12 +143,18 @@ export async function monitorMSTeamsProvider( const senderId = from.aadObjectId ?? from.id; // Save conversation reference for proactive messaging + const agent = activity.recipient + ? { + id: activity.recipient.id, + name: activity.recipient.name, + aadObjectId: activity.recipient.aadObjectId, + } + : undefined; const conversationRef: StoredConversationReference = { activityId: activity.id, user: { id: from.id, name: from.name, aadObjectId: from.aadObjectId }, - bot: activity.recipient - ? { id: activity.recipient.id, name: activity.recipient.name } - : undefined, + agent, + bot: agent ? { id: agent.id, name: agent.name } : undefined, conversation: { id: conversationId, conversationType,