mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
fix(channels): normalize MIME kind parsing and reaction fallbacks
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user