import { Buffer } from "node:buffer"; import { getMSTeamsRuntime } from "../runtime.js"; import { ensureUserAgentHeader } from "../user-agent.js"; import {
inferPlaceholder,
isUrlAllowed,
type MSTeamsAttachmentDownloadLogger,
type MSTeamsAttachmentFetchPolicy,
type MSTeamsAttachmentResolveFn,
resolveAttachmentFetchPolicy,
safeFetchWithPolicy,
} from "./shared.js"; import type {
MSTeamsAccessTokenProvider,
MSTeamsGraphMediaResult,
MSTeamsInboundMedia,
} from "./types.js";
function normalizeServiceUrl(serviceUrl: string): string { // Bot Framework service URLs sometimes carry a trailing slash; normalize so // we can safely append `/v3/attachments/...` below. return serviceUrl.replace(/\/+$/, "");
}
async function fetchBotFrameworkAttachmentInfo(params: {
serviceUrl: string;
attachmentId: string;
accessToken: string;
policy: MSTeamsAttachmentFetchPolicy;
fetchFn?: typeof fetch;
resolveFn?: MSTeamsAttachmentResolveFn;
logger?: MSTeamsAttachmentDownloadLogger;
}): Promise<BotFrameworkAttachmentInfo | undefined> { const url = `${normalizeServiceUrl(params.serviceUrl)}/v3/attachments/${encodeURIComponent(params.attachmentId)}`; // Use `safeFetchWithPolicy` instead of `fetchWithSsrFGuard`. The strict // pinned undici dispatcher used by `fetchWithSsrFGuard` is incompatible // with Node 24+'s built-in undici v7 and silently breaks Bot Framework // attachment downloads (same root cause as the SharePoint fix in #63396). // `safeFetchWithPolicy` already enforces hostname allowlist validation // across every redirect hop, which is sufficient for these attachment // service URLs.
let response: Response; try {
response = await safeFetchWithPolicy({
url,
policy: params.policy,
fetchFn: params.fetchFn,
resolveFn: params.resolveFn,
requestInit: {
headers: ensureUserAgentHeader({ Authorization: `Bearer ${params.accessToken}` }),
},
});
} catch (err) {
params.logger?.warn?.("msteams botFramework attachmentInfo fetch failed", {
error: err instanceof Error ? err.message : String(err),
}); return undefined;
} if (!response.ok) {
params.logger?.warn?.("msteams botFramework attachmentInfo non-ok", {
status: response.status,
}); return undefined;
} try { return (await response.json()) as BotFrameworkAttachmentInfo;
} catch (err) {
params.logger?.warn?.("msteams botFramework attachmentInfo parse failed", {
error: err instanceof Error ? err.message : String(err),
}); return undefined;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.