fix(telegram): use configured proxy for outbound API calls

The proxy configuration (`channels.telegram.proxy`) was only used for
the gateway monitor (polling), but not for outbound sends (sendMessage,
reactMessage, deleteMessage). This caused outbound messages to bypass
the configured proxy, which is problematic for users behind corporate
proxies or those who want to route all traffic through a specific proxy.

This change ensures that all three outbound functions use the same
proxy configuration as the monitor:
- sendMessageTelegram
- reactMessageTelegram
- deleteMessageTelegram

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Developer
2026-01-25 10:46:28 +01:00
committed by Peter Steinberger
parent 67db63ba05
commit 65e2d939e1

View File

@@ -19,6 +19,7 @@ import { isGifMedia } from "../media/mime.js";
import { loadWebMedia } from "../web/media.js"; import { loadWebMedia } from "../web/media.js";
import { resolveTelegramAccount } from "./accounts.js"; import { resolveTelegramAccount } from "./accounts.js";
import { resolveTelegramFetch } from "./fetch.js"; import { resolveTelegramFetch } from "./fetch.js";
import { makeProxyFetch } from "./proxy.js";
import { renderTelegramHtmlText } from "./format.js"; import { renderTelegramHtmlText } from "./format.js";
import { resolveMarkdownTableMode } from "../config/markdown-tables.js"; import { resolveMarkdownTableMode } from "../config/markdown-tables.js";
import { splitTelegramCaption } from "./caption.js"; import { splitTelegramCaption } from "./caption.js";
@@ -162,7 +163,9 @@ export async function sendMessageTelegram(
const chatId = normalizeChatId(target.chatId); const chatId = normalizeChatId(target.chatId);
// Use provided api or create a new Bot instance. The nullish coalescing // Use provided api or create a new Bot instance. The nullish coalescing
// operator ensures api is always defined (Bot.api is always non-null). // operator ensures api is always defined (Bot.api is always non-null).
const fetchImpl = resolveTelegramFetch(); const proxyUrl = account.config.proxy;
const proxyFetch = proxyUrl ? makeProxyFetch(proxyUrl as string) : undefined;
const fetchImpl = resolveTelegramFetch(proxyFetch);
const timeoutSeconds = const timeoutSeconds =
typeof account.config.timeoutSeconds === "number" && typeof account.config.timeoutSeconds === "number" &&
Number.isFinite(account.config.timeoutSeconds) Number.isFinite(account.config.timeoutSeconds)
@@ -416,7 +419,9 @@ export async function reactMessageTelegram(
const token = resolveToken(opts.token, account); const token = resolveToken(opts.token, account);
const chatId = normalizeChatId(String(chatIdInput)); const chatId = normalizeChatId(String(chatIdInput));
const messageId = normalizeMessageId(messageIdInput); const messageId = normalizeMessageId(messageIdInput);
const fetchImpl = resolveTelegramFetch(); const proxyUrl = account.config.proxy;
const proxyFetch = proxyUrl ? makeProxyFetch(proxyUrl as string) : undefined;
const fetchImpl = resolveTelegramFetch(proxyFetch);
const client: ApiClientOptions | undefined = fetchImpl const client: ApiClientOptions | undefined = fetchImpl
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] } ? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
: undefined; : undefined;
@@ -468,7 +473,9 @@ export async function deleteMessageTelegram(
const token = resolveToken(opts.token, account); const token = resolveToken(opts.token, account);
const chatId = normalizeChatId(String(chatIdInput)); const chatId = normalizeChatId(String(chatIdInput));
const messageId = normalizeMessageId(messageIdInput); const messageId = normalizeMessageId(messageIdInput);
const fetchImpl = resolveTelegramFetch(); const proxyUrl = account.config.proxy;
const proxyFetch = proxyUrl ? makeProxyFetch(proxyUrl as string) : undefined;
const fetchImpl = resolveTelegramFetch(proxyFetch);
const client: ApiClientOptions | undefined = fetchImpl const client: ApiClientOptions | undefined = fetchImpl
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] } ? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
: undefined; : undefined;