fix(channels): normalize MIME kind parsing and reaction fallbacks

This commit is contained in:
Peter Steinberger
2026-03-02 23:48:00 +00:00
parent 32ecd6f579
commit ea3b7dfde5
13 changed files with 114 additions and 21 deletions

View File

@@ -5,9 +5,8 @@ import type { ReplyToMode } from "../../config/config.js";
import type { MarkdownTableMode } from "../../config/types.base.js";
import { danger, logVerbose } from "../../globals.js";
import { formatErrorMessage } from "../../infra/errors.js";
import { mediaKindFromMime } from "../../media/constants.js";
import { buildOutboundMediaLoadOptions } from "../../media/load-options.js";
import { isGifMedia } from "../../media/mime.js";
import { isGifMedia, kindFromMime } from "../../media/mime.js";
import type { RuntimeEnv } from "../../runtime.js";
import { loadWebMedia } from "../../web/media.js";
import type { TelegramInlineButtons } from "../button-types.js";
@@ -234,7 +233,7 @@ async function deliverMediaReply(params: {
mediaUrl,
buildOutboundMediaLoadOptions({ mediaLocalRoots: params.mediaLocalRoots }),
);
const kind = mediaKindFromMime(media.contentType ?? undefined);
const kind = kindFromMime(media.contentType ?? undefined);
const isGif = isGifMedia({
contentType: media.contentType,
fileName: media.fileName,

View File

@@ -872,6 +872,16 @@ describe("sendMessageTelegram", () => {
expectedMethod: "sendVoice" as const,
expectedOptions: { caption: "caption", parse_mode: "HTML" },
},
{
name: "normalizes parameterized audio MIME with mixed casing",
chatId: "123",
text: "caption",
mediaUrl: "https://example.com/note",
contentType: " Audio/Ogg; codecs=opus ",
fileName: "note.ogg",
expectedMethod: "sendAudio" as const,
expectedOptions: { caption: "caption", parse_mode: "HTML" },
},
];
for (const testCase of cases) {

View File

@@ -15,9 +15,9 @@ import { createTelegramRetryRunner } from "../infra/retry-policy.js";
import type { RetryConfig } from "../infra/retry.js";
import { redactSensitiveText } from "../logging/redact.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import { mediaKindFromMime } from "../media/constants.js";
import type { MediaKind } from "../media/constants.js";
import { buildOutboundMediaLoadOptions } from "../media/load-options.js";
import { isGifMedia } from "../media/mime.js";
import { isGifMedia, kindFromMime } from "../media/mime.js";
import { normalizePollInput, type PollInput } from "../polls.js";
import { loadWebMedia } from "../web/media.js";
import { type ResolvedTelegramAccount, resolveTelegramAccount } from "./accounts.js";
@@ -566,7 +566,7 @@ export async function sendMessageTelegram(
mediaLocalRoots: opts.mediaLocalRoots,
}),
);
const kind = mediaKindFromMime(media.contentType ?? undefined);
const kind = kindFromMime(media.contentType ?? undefined);
const isGif = isGifMedia({
contentType: media.contentType,
fileName: media.fileName,
@@ -944,7 +944,7 @@ export async function editMessageTelegram(
return { ok: true, messageId: String(messageId), chatId };
}
function inferFilename(kind: ReturnType<typeof mediaKindFromMime>) {
function inferFilename(kind: MediaKind) {
switch (kind) {
case "image":
return "image.jpg";