mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 11:15:00 +00:00
fix: harden msteams revoked-context fallback delivery (#27224) (thanks @openperf)
This commit is contained in:
@@ -441,9 +441,13 @@ export async function sendMSTeamsMessages(params: {
|
||||
}
|
||||
};
|
||||
|
||||
const sendMessagesInContext = async (ctx: SendContext): Promise<string[]> => {
|
||||
const sendMessagesInContext = async (
|
||||
ctx: SendContext,
|
||||
batch: MSTeamsRenderedMessage[] = messages,
|
||||
offset = 0,
|
||||
): Promise<string[]> => {
|
||||
const messageIds: string[] = [];
|
||||
for (const [idx, message] of messages.entries()) {
|
||||
for (const [idx, message] of batch.entries()) {
|
||||
const response = await sendWithRetry(
|
||||
async () =>
|
||||
await ctx.sendActivity(
|
||||
@@ -455,38 +459,52 @@ export async function sendMSTeamsMessages(params: {
|
||||
params.mediaMaxBytes,
|
||||
),
|
||||
),
|
||||
{ messageIndex: idx, messageCount: messages.length },
|
||||
{ messageIndex: offset + idx, messageCount: messages.length },
|
||||
);
|
||||
messageIds.push(extractMessageId(response) ?? "unknown");
|
||||
}
|
||||
return messageIds;
|
||||
};
|
||||
|
||||
const sendProactively = async (
|
||||
batch: MSTeamsRenderedMessage[] = messages,
|
||||
offset = 0,
|
||||
): Promise<string[]> => {
|
||||
const baseRef = buildConversationReference(params.conversationRef);
|
||||
const proactiveRef: MSTeamsConversationReference = {
|
||||
...baseRef,
|
||||
activityId: undefined,
|
||||
};
|
||||
|
||||
const messageIds: string[] = [];
|
||||
await params.adapter.continueConversation(params.appId, proactiveRef, async (ctx) => {
|
||||
messageIds.push(...(await sendMessagesInContext(ctx, batch, offset)));
|
||||
});
|
||||
return messageIds;
|
||||
};
|
||||
|
||||
if (params.replyStyle === "thread") {
|
||||
const ctx = params.context;
|
||||
if (!ctx) {
|
||||
throw new Error("Missing context for replyStyle=thread");
|
||||
}
|
||||
try {
|
||||
return await sendMessagesInContext(ctx);
|
||||
} catch (err) {
|
||||
if (!isRevokedProxyError(err)) {
|
||||
throw err;
|
||||
const messageIds: string[] = [];
|
||||
for (const [idx, message] of messages.entries()) {
|
||||
try {
|
||||
messageIds.push(...(await sendMessagesInContext(ctx, [message], idx)));
|
||||
} catch (err) {
|
||||
if (!isRevokedProxyError(err)) {
|
||||
throw err;
|
||||
}
|
||||
const remaining = messages.slice(idx);
|
||||
if (remaining.length > 0) {
|
||||
messageIds.push(...(await sendProactively(remaining, idx)));
|
||||
}
|
||||
return messageIds;
|
||||
}
|
||||
// Turn context revoked (debounced message) — fall back to proactive
|
||||
// messaging so the reply still reaches the user.
|
||||
}
|
||||
return messageIds;
|
||||
}
|
||||
|
||||
const baseRef = buildConversationReference(params.conversationRef);
|
||||
const proactiveRef: MSTeamsConversationReference = {
|
||||
...baseRef,
|
||||
activityId: undefined,
|
||||
};
|
||||
|
||||
const messageIds: string[] = [];
|
||||
await params.adapter.continueConversation(params.appId, proactiveRef, async (ctx) => {
|
||||
messageIds.push(...(await sendMessagesInContext(ctx)));
|
||||
});
|
||||
return messageIds;
|
||||
return await sendProactively(messages, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user