From 4561356ecdb1b77ecf977815b83c67ef0187ac6b Mon Sep 17 00:00:00 2001 From: sheben404 Date: Sat, 28 Mar 2026 06:33:35 -0700 Subject: [PATCH] feat: add proxy URL setting for bot connection node-telegram-bot-api uses Node.js native HTTP which bypasses Electron's session proxy. This adds a proxy URL field in Advanced Settings and passes it to the bot constructor's request options. --- src/settings/Settings.ts | 2 ++ src/settings/modals/AdvancedSettings.ts | 15 +++++++++++++++ src/telegram/bot/bot.ts | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 04d54a42..bbf4802a 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -68,6 +68,7 @@ export interface TelegramSyncSettings { processOldMessagesSettings: ProcessOldMessagesSettings; processOtherBotsMessages: boolean; retryFailedMessagesProcessing: boolean; + proxyUrl: string; // add new settings above this line topicNames: Topic[]; } @@ -92,6 +93,7 @@ export const DEFAULT_SETTINGS: TelegramSyncSettings = { processOldMessagesSettings: getDefaultProcessOldMessagesSettings(), processOtherBotsMessages: false, retryFailedMessagesProcessing: false, + proxyUrl: "", // add new settings above this line topicNames: [], }; diff --git a/src/settings/modals/AdvancedSettings.ts b/src/settings/modals/AdvancedSettings.ts index 7cdd7592..ebd44192 100644 --- a/src/settings/modals/AdvancedSettings.ts +++ b/src/settings/modals/AdvancedSettings.ts @@ -21,6 +21,7 @@ export class AdvancedSettingsModal extends Modal { this.addDeleteMessagesFromTelegram(); this.addMessageDelimiterSetting(); this.addParallelMessageProcessing(); + this.addProxyUrl(); } addHeader() { @@ -85,6 +86,20 @@ export class AdvancedSettingsModal extends Modal { }); } + addProxyUrl() { + new Setting(this.advancedSettingsDiv) + .setName("Proxy URL") + .setDesc("HTTP proxy for connecting to Telegram (e.g., http://127.0.0.1:7897). Restart the plugin after changing.") + .addText((text) => { + text.setPlaceholder("http://127.0.0.1:7897"); + text.setValue(this.plugin.settings.proxyUrl); + text.onChange(async (value) => { + this.plugin.settings.proxyUrl = value.trim(); + await this.plugin.saveSettings(); + }); + }); + } + onOpen() { this.display(); } diff --git a/src/telegram/bot/bot.ts b/src/telegram/bot/bot.ts index 063b7831..ebbd7641 100644 --- a/src/telegram/bot/bot.ts +++ b/src/telegram/bot/bot.ts @@ -18,7 +18,11 @@ export async function connect(plugin: TelegramSyncPlugin) { return; } // Create a new bot instance and start polling - plugin.bot = new TelegramBot(await enqueue(plugin, plugin.getBotToken)); + const botOptions: TelegramBot.ConstructorOptions = {}; + if (plugin.settings.proxyUrl) { + botOptions.request = { proxy: plugin.settings.proxyUrl }; + } + plugin.bot = new TelegramBot(await enqueue(plugin, plugin.getBotToken), botOptions); const bot = plugin.bot; // Set connected flag to false and log errors when a polling error occurs bot.on("polling_error", async (error: unknown) => {