refactor: consolidate reply/media helpers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import path from "node:path";
|
||||
import { getFileExtension } from "../media/mime.js";
|
||||
|
||||
export function isTelegramVoiceCompatible(opts: {
|
||||
contentType?: string | null;
|
||||
@@ -10,7 +10,8 @@ export function isTelegramVoiceCompatible(opts: {
|
||||
}
|
||||
const fileName = opts.fileName?.trim();
|
||||
if (!fileName) return false;
|
||||
const ext = path.extname(fileName).toLowerCase();
|
||||
const ext = getFileExtension(fileName);
|
||||
if (!ext) return false;
|
||||
return ext === ".ogg" || ext === ".opus" || ext === ".oga";
|
||||
}
|
||||
|
||||
@@ -28,3 +29,18 @@ export function resolveTelegramVoiceDecision(opts: {
|
||||
reason: `media is ${contentType} (${fileName})`,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveTelegramVoiceSend(opts: {
|
||||
wantsVoice: boolean;
|
||||
contentType?: string | null;
|
||||
fileName?: string | null;
|
||||
logFallback?: (message: string) => void;
|
||||
}): { useVoice: boolean } {
|
||||
const decision = resolveTelegramVoiceDecision(opts);
|
||||
if (decision.reason && opts.logFallback) {
|
||||
opts.logFallback(
|
||||
`Telegram voice requested but ${decision.reason}; sending as audio file instead.`,
|
||||
);
|
||||
}
|
||||
return { useVoice: decision.useVoice };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user