





























@@ -814,12 +814,13 @@ export async function sendMessageTelegram(
814814fileName: media.fileName,
815815});
816816817-// Validate photo dimensions before attempting sendPhoto
818817let sendImageAsPhoto = true;
819-if (kind === "image" && !isGif && !opts.forceDocument) {
818+const deliveryKind =
819+opts.forceDocument === true && (kind === "image" || kind === "video") ? "document" : kind;
820+if (deliveryKind === "image" && !isGif) {
820821sendImageAsPhoto = await shouldSendTelegramImageAsPhoto(media.buffer);
821822}
822-const isVideoNote = kind === "video" && opts.asVideoNote === true;
823+const isVideoNote = deliveryKind === "video" && opts.asVideoNote === true;
823824const fileName =
824825media.fileName ?? (isGif ? "animation.gif" : inferFilename(kind ?? "document")) ?? "file";
825826const file = new InputFileCtor(media.buffer, fileName);
@@ -845,7 +846,9 @@ export async function sendMessageTelegram(
845846 ...(!needsSeparateText && replyMarkup ? { reply_markup: replyMarkup } : {}),
846847};
847848const videoDimensions =
848-kind === "video" && !isVideoNote ? await probeVideoDimensions(media.buffer) : undefined;
849+deliveryKind === "video" && !isVideoNote
850+ ? await probeVideoDimensions(media.buffer)
851+ : undefined;
849852const mediaParams = {
850853 ...(htmlCaption ? { caption: htmlCaption, parse_mode: "HTML" as const } : {}),
851854 ...baseMediaParams,
@@ -868,7 +871,7 @@ export async function sendMessageTelegram(
868871);
869872870873const mediaSender = (() => {
871-if (isGif && !opts.forceDocument) {
874+if (isGif && deliveryKind !== "document") {
872875return {
873876label: "animation",
874877sender: (effectiveParams: TelegramThreadScopedParams | undefined) =>
@@ -879,7 +882,7 @@ export async function sendMessageTelegram(
879882) as Promise<TelegramMessageLike>,
880883};
881884}
882-if (kind === "image" && !opts.forceDocument && sendImageAsPhoto) {
885+if (deliveryKind === "image" && !isGif && sendImageAsPhoto) {
883886return {
884887label: "photo",
885888sender: (effectiveParams: TelegramThreadScopedParams | undefined) =>
@@ -890,7 +893,7 @@ export async function sendMessageTelegram(
890893) as Promise<TelegramMessageLike>,
891894};
892895}
893-if (kind === "video") {
896+if (deliveryKind === "video") {
894897if (isVideoNote) {
895898return {
896899label: "video_note",
@@ -946,8 +949,6 @@ export async function sendMessageTelegram(
946949api.sendDocument(
947950chatId,
948951file,
949-// Only force Telegram to keep the uploaded media type when callers explicitly
950-// opt into document delivery for image/GIF uploads.
951952(opts.forceDocument
952953 ? { ...effectiveParams, disable_content_type_detection: true }
953954 : effectiveParams) as Parameters<typeof api.sendDocument>[2],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。