Repository: sealdice/sealdice-core (language: go)

Issue:
Telegram账号支持使用代理
### 在提问之前...

- [X] 我填写了简短且清晰明确的标题，以便开发者在翻阅 issue 列表时能快速确定大致问题。而不是“一个建议”、“卡住了”等
- [X] 我基本确定这是一个新功能/建议，而不是遇到了 bug（不确定的话请附上日志）

### 说说你遇到的问题？

目前只有Discord账号支持在添加时选择代理，需要Telegram也同样支持

### 有什么好的想法？

_No response_

### 其他内容

_No response_


Discussion / hints:

Fix patch:
diff --git a/api/conn.go b/api/conn.go
index 944def21..75b898fe 100644
--- a/api/conn.go
+++ b/api/conn.go
@@ -425,12 +425,13 @@ func ImConnectionsAddTelegram(c echo.Context) error {
 
 	//myDice.Logger.Infof("后端add调用")
 	v := struct {
-		Token string `yaml:"token" json:"token"`
+		Token    string `yaml:"token" json:"token"`
+		ProxyURL string `yaml:"proxyURL" json:"proxyURL"`
 	}{}
 	err := c.Bind(&v)
 	if err == nil {
 		//myDice.Logger.Infof("bind无异常")
-		conn := dice.NewTelegramConnItem(v.Token)
+		conn := dice.NewTelegramConnItem(v.Token, v.ProxyURL)
 		conn.Session = myDice.ImSession
 
 		//myDice.Logger.Infof("成功创建endpoint")
diff --git a/dice/platform_adapter_telegram.go b/dice/platform_adapter_telegram.go
index bd835a8a..71e59d42 100644
--- a/dice/platform_adapter_telegram.go
+++ b/dice/platform_adapter_telegram.go
@@ -2,16 +2,20 @@ package dice
 
 import (
 	"fmt"
-	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
 	"io"
+	"net/http"
+	"net/url"
 	"strconv"
 	"strings"
 	"time"
+
+	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
 )
 
 type PlatformAdapterTelegram struct {
 	Session       *IMSession       `yaml:"-" json:"-"`
 	Token         string           `yaml:"token" json:"token"`
+	ProxyURL      string           `yaml:"proxyURL" json:"proxyURL"`
 	EndPoint      *EndPointInfo    `yaml:"-" json:"-"`
 	IntentSession *tgbotapi.BotAPI `yaml:"-" json:"-"`
 }
@@ -44,7 +48,21 @@ func (pa *PlatformAdapterTelegram) Serve() int {
 	logger := pa.Session.Parent.Logger
 	ep := pa.EndPoint
 	logger.Info("尝试连接Telegram服务……")
-	bot, err := tgbotapi.NewBotAPI(pa.Token)
+
+	var bot *tgbotapi.BotAPI
+	var err error
+
+	if len(pa.ProxyURL) > 0 {
+		var u *url.URL
+		u, err = url.Parse(pa.ProxyURL)
+		if err == nil {
+			bot, err = tgbotapi.NewBotAPIWithClient(pa.Token, tgbotapi.APIEndpoint, &http.Client{
+				Transport: &http.Transport{Proxy: http.ProxyURL(u)},
+			})
+		}
+	} else {
+		bot, err = tgbotapi.NewBotAPI(pa.Token)
+	}
 	if err != nil {
 		pa.Session.Parent.Logger.Errorf("与Telegram服务进行连接时出错:%s", err.Error())
 		ep.State = 3
@@ -54,6 +72,7 @@ func (pa *PlatformAdapterTelegram) Serve() int {
 		d.Save(false)
 		return 1
 	}
+
 	pa.IntentSession = bot
 	ep.UserId = FormatDiceIdTelegram(strconv.FormatInt(bot.Self.ID, 10))
 	ep.Nickname = bot.Self.UserName
diff --git a/dice/telegram_helper.go b/dice/telegram_helper.go
index 9a1187b7..2a55e4fa 100644
--- a/dice/telegram_helper.go
+++ b/dice/telegram_helper.go
@@ -2,7 +2,7 @@ package dice
 
 import "github.com/google/uuid"
 
-func NewTelegramConnItem(token string) *EndPointInfo {
+func NewTelegramConnItem(token string, proxy string) *EndPointInfo {
 	conn := new(EndPointInfo)
 	conn.Id = uuid.New().String()
 	conn.Platform = "TG"
@@ -12,6 +12,7 @@ func NewTelegramConnItem(token string) *EndPointInfo {
 	conn.Adapter = &PlatformAdapterTelegram{
 		EndPoint: conn,
 		Token:    token,
+		ProxyURL: proxy,
 	}
 	return conn
 }


Test patch: