Skip to content

Commit 2dc2c2e

Browse files
authored
feat: support custom tgbot api endpoint (#39)
* feat: support custom tgbot api endpoint * fix: removed TELEGRAM_API_ENDPOINT from env.example and merged upstream changes
1 parent 637019c commit 2dc2c2e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/tgbot/bot.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tgbot
22

33
import (
44
"log"
5+
"os"
56
"time"
67

78
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
@@ -17,7 +18,14 @@ type Bot struct {
1718
}
1819

1920
func New(token string, editInterval time.Duration) (*Bot, error) {
20-
api, err := tgbotapi.NewBotAPI(token)
21+
var api *tgbotapi.BotAPI
22+
var err error
23+
apiEndpoint, exist := os.LookupEnv("TELEGRAM_API_ENDPOINT")
24+
if exist && apiEndpoint != "" {
25+
api, err = tgbotapi.NewBotAPIWithAPIEndpoint(token, apiEndpoint)
26+
} else {
27+
api, err = tgbotapi.NewBotAPI(token)
28+
}
2129
if err != nil {
2230
return nil, err
2331
}

0 commit comments

Comments
 (0)