MS Teams: fix top-level replies (agent reference)
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user