Fix Telegram proxy URL format (tg://proxy)

This commit is contained in:
y0sy4 2026-03-22 20:27:53 +03:00
parent ab25511f6e
commit 1217034551
1 changed files with 22 additions and 6 deletions

View File

@ -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.