fix: tighten Teams and device typing

This commit is contained in:
Peter Steinberger
2026-04-04 19:38:43 +09:00
parent 75fb29ffe6
commit 87d840e9ee
2 changed files with 10 additions and 5 deletions

View File

@@ -39,18 +39,23 @@ import {
wasMSTeamsBotMentioned,
} from "../inbound.js";
function isStringRecord(value: unknown): value is Record<string, string> {
return typeof value === "object" && value !== null;
}
function extractTextFromHtmlAttachments(attachments: MSTeamsAttachmentLike[]): string {
for (const attachment of attachments) {
if (attachment.contentType !== "text/html") {
continue;
}
const structuredContent = isStringRecord(attachment.content) ? attachment.content : null;
const raw =
typeof attachment.content === "string"
? attachment.content
: typeof attachment.content?.text === "string"
? attachment.content.text
: typeof attachment.content?.body === "string"
? attachment.content.body
: typeof structuredContent?.text === "string"
? structuredContent.text
: typeof structuredContent?.body === "string"
? structuredContent.body
: "";
if (!raw) {
continue;

View File

@@ -29,7 +29,7 @@ import type { GatewayRequestHandlers } from "./types.js";
const DEVICE_TOKEN_ROTATION_DENIED_MESSAGE = "device token rotation denied";
type DeviceTokenRotateTarget = {
pairedDevice: Awaited<ReturnType<typeof getPairedDevice>>;
pairedDevice: NonNullable<Awaited<ReturnType<typeof getPairedDevice>>>;
normalizedRole: string;
};