Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'web/service')
-rw-r--r--web/service/setting.go9
-rw-r--r--web/service/tgbot.go42
2 files changed, 40 insertions, 11 deletions
diff --git a/web/service/setting.go b/web/service/setting.go
index 90bf8fc4..bbdac81d 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -41,6 +41,7 @@ var defaultValueMap = map[string]string{
"tgBotEnable": "false",
"tgBotToken": "",
"tgBotProxy": "",
+ "tgBotAPIServer": "",
"tgBotChatId": "",
"tgRunTime": "@daily",
"tgBotBackup": "false",
@@ -262,6 +263,14 @@ func (s *SettingService) SetTgBotProxy(token string) error {
return s.setString("tgBotProxy", token)
}
+func (s *SettingService) GetTgBotAPIServer() (string, error) {
+ return s.getString("tgBotAPIServer")
+}
+
+func (s *SettingService) SetTgBotAPIServer(token string) error {
+ return s.setString("tgBotAPIServer", token)
+}
+
func (s *SettingService) GetTgBotChatId() (string, error) {
return s.getString("tgBotChatId")
}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 449161d3..7c6780d8 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -108,8 +108,14 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
logger.Warning("Failed to get Telegram bot proxy URL:", err)
}
+ // Get Telegram bot API server URL
+ tgBotAPIServer, err := t.settingService.GetTgBotAPIServer()
+ if err != nil {
+ logger.Warning("Failed to get Telegram bot API server URL:", err)
+ }
+
// Create new Telegram bot instance
- bot, err = t.NewBot(tgBotToken, tgBotProxy)
+ bot, err = t.NewBot(tgBotToken, tgBotProxy, tgBotAPIServer)
if err != nil {
logger.Error("Failed to initialize Telegram bot API:", err)
return err
@@ -125,26 +131,40 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
return nil
}
-func (t *Tgbot) NewBot(token string, proxyUrl string) (*telego.Bot, error) {
- if proxyUrl == "" {
- // No proxy URL provided, use default instance
+func (t *Tgbot) NewBot(token string, proxyUrl string, apiServerUrl string) (*telego.Bot, error) {
+ if proxyUrl == "" && apiServerUrl == "" {
return telego.NewBot(token)
}
- if !strings.HasPrefix(proxyUrl, "socks5://") {
- logger.Warning("Invalid socks5 URL, starting with default")
+ if proxyUrl != "" {
+ if !strings.HasPrefix(proxyUrl, "socks5://") {
+ logger.Warning("Invalid socks5 URL, using default")
+ return telego.NewBot(token)
+ }
+
+ _, err := url.Parse(proxyUrl)
+ if err != nil {
+ logger.Warningf("Can't parse proxy URL, using default instance for tgbot: %v", err)
+ return telego.NewBot(token)
+ }
+
+ return telego.NewBot(token, telego.WithFastHTTPClient(&fasthttp.Client{
+ Dial: fasthttpproxy.FasthttpSocksDialer(proxyUrl),
+ }))
+ }
+
+ if !strings.HasPrefix(apiServerUrl, "http") {
+ logger.Warning("Invalid http(s) URL, using default")
return telego.NewBot(token)
}
- _, err := url.Parse(proxyUrl)
+ _, err := url.Parse(apiServerUrl)
if err != nil {
- logger.Warning("Can't parse proxy URL, using default instance for tgbot:", err)
+ logger.Warningf("Can't parse API server URL, using default instance for tgbot: %v", err)
return telego.NewBot(token)
}
- return telego.NewBot(token, telego.WithFastHTTPClient(&fasthttp.Client{
- Dial: fasthttpproxy.FasthttpSocksDialer(proxyUrl),
- }))
+ return telego.NewBot(token, telego.WithAPIServer(apiServerUrl))
}
func (t *Tgbot) IsRunning() bool {