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 ( import (
"fmt" "fmt"
"net/url"
"os/exec" "os/exec"
"runtime" "runtime"
"strings" "strings"
@ -11,17 +12,32 @@ import (
// ConfigureProxy opens Telegram's proxy configuration URL. // ConfigureProxy opens Telegram's proxy configuration URL.
// Returns true if successful, false otherwise. // Returns true if successful, false otherwise.
func ConfigureProxy(host string, port int, username, password string) bool { func ConfigureProxy(host string, port int, username, password string) bool {
// Build tg:// proxy URL // Build tg:// proxy URL with proper encoding
url := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port) // 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 != "" { if username != "" {
url += fmt.Sprintf("&user=%s", username) params.Set("user", username)
} }
if password != "" { 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. // openURL opens a URL in the default browser/application.