From 1217034551c72f258ed1510bd29dcbb6a2eb47c0 Mon Sep 17 00:00:00 2001 From: y0sy4 Date: Sun, 22 Mar 2026 20:27:53 +0300 Subject: [PATCH] Fix Telegram proxy URL format (tg://proxy) --- internal/telegram/telegram.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/internal/telegram/telegram.go b/internal/telegram/telegram.go index ba339f2..12c846c 100644 --- a/internal/telegram/telegram.go +++ b/internal/telegram/telegram.go @@ -3,6 +3,7 @@ package telegram import ( "fmt" + "net/url" "os/exec" "runtime" "strings" @@ -11,17 +12,32 @@ import ( // ConfigureProxy opens Telegram's proxy configuration URL. // Returns true if successful, false otherwise. func ConfigureProxy(host string, port int, username, password string) bool { - // Build tg:// proxy URL - url := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port) + // Build tg:// proxy URL with proper encoding + // Format: tg://proxy?server=host&port=port&user=username&pass=password + params := url.Values{} + params.Set("server", host) + params.Set("port", fmt.Sprintf("%d", port)) if username != "" { - url += fmt.Sprintf("&user=%s", username) + params.Set("user", username) } if password != "" { - url += fmt.Sprintf("&pass=%s", password) + params.Set("pass", password) } - - return openURL(url) + + // Try both formats + urls := []string{ + fmt.Sprintf("tg://proxy?%s", params.Encode()), + fmt.Sprintf("tg://socks?%s", params.Encode()), + } + + for _, testURL := range urls { + if openURL(testURL) { + return true + } + } + + return false } // openURL opens a URL in the default browser/application.