MS Teams: fix top-level replies (agent reference)
This commit is contained in:
@@ -11,7 +11,9 @@ export type StoredConversationReference = {
|
|||||||
activityId?: string;
|
activityId?: string;
|
||||||
/** User who sent the message */
|
/** User who sent the message */
|
||||||
user?: { id?: string; name?: string; aadObjectId?: string };
|
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 };
|
bot?: { id?: string; name?: string };
|
||||||
/** Conversation details */
|
/** Conversation details */
|
||||||
conversation?: { id?: string; conversationType?: string; tenantId?: string };
|
conversation?: { id?: string; conversationType?: string; tenantId?: string };
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ describe("msteams messenger", () => {
|
|||||||
describe("sendMSTeamsMessages", () => {
|
describe("sendMSTeamsMessages", () => {
|
||||||
const baseRef: StoredConversationReference = {
|
const baseRef: StoredConversationReference = {
|
||||||
activityId: "activity123",
|
activityId: "activity123",
|
||||||
|
user: { id: "user123", name: "User" },
|
||||||
|
agent: { id: "bot123", name: "Bot" },
|
||||||
conversation: { id: "19:abc@thread.tacv2;messageid=deadbeef" },
|
conversation: { id: "19:abc@thread.tacv2;messageid=deadbeef" },
|
||||||
channelId: "msteams",
|
channelId: "msteams",
|
||||||
serviceUrl: "https://service.example.com",
|
serviceUrl: "https://service.example.com",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type SendContext = {
|
|||||||
type ConversationReference = {
|
type ConversationReference = {
|
||||||
activityId?: string;
|
activityId?: string;
|
||||||
user?: { id?: string; name?: string; aadObjectId?: 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 };
|
conversation: { id: string; conversationType?: string; tenantId?: string };
|
||||||
channelId: string;
|
channelId: string;
|
||||||
serviceUrl?: string;
|
serviceUrl?: string;
|
||||||
@@ -59,10 +59,18 @@ function buildConversationReference(
|
|||||||
if (!conversationId) {
|
if (!conversationId) {
|
||||||
throw new Error("Invalid stored reference: missing conversation.id");
|
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 {
|
return {
|
||||||
activityId: ref.activityId,
|
activityId: ref.activityId,
|
||||||
user: ref.user,
|
user,
|
||||||
bot: ref.bot,
|
agent,
|
||||||
conversation: {
|
conversation: {
|
||||||
id: normalizeConversationId(conversationId),
|
id: normalizeConversationId(conversationId),
|
||||||
conversationType: ref.conversation?.conversationType,
|
conversationType: ref.conversation?.conversationType,
|
||||||
|
|||||||
@@ -143,12 +143,18 @@ export async function monitorMSTeamsProvider(
|
|||||||
const senderId = from.aadObjectId ?? from.id;
|
const senderId = from.aadObjectId ?? from.id;
|
||||||
|
|
||||||
// Save conversation reference for proactive messaging
|
// 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 = {
|
const conversationRef: StoredConversationReference = {
|
||||||
activityId: activity.id,
|
activityId: activity.id,
|
||||||
user: { id: from.id, name: from.name, aadObjectId: from.aadObjectId },
|
user: { id: from.id, name: from.name, aadObjectId: from.aadObjectId },
|
||||||
bot: activity.recipient
|
agent,
|
||||||
? { id: activity.recipient.id, name: activity.recipient.name }
|
bot: agent ? { id: agent.id, name: agent.name } : undefined,
|
||||||
: undefined,
|
|
||||||
conversation: {
|
conversation: {
|
||||||
id: conversationId,
|
id: conversationId,
|
||||||
conversationType,
|
conversationType,
|
||||||
|
|||||||
Reference in New Issue
Block a user