feat: api and proxy optional
This commit is contained in:
@@ -16,18 +16,26 @@ import (
|
||||
func Run(sendFunc func(string)) {
|
||||
var err error
|
||||
|
||||
api := conf.GetBotSettings().BotAPI
|
||||
if len(api) == 0 {
|
||||
api = tgbotapi.APIEndpoint
|
||||
}
|
||||
|
||||
HttpProxy := conf.GetBotSettings().HTTPProxy
|
||||
proxyUrl, err := url.Parse(HttpProxy)
|
||||
if err != nil {
|
||||
log.Panic(err, "HTTP_PROXY environment variable is not set correctly")
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithClient(
|
||||
conf.GetBotSettings().BotToken,
|
||||
tgbotapi.APIEndpoint,
|
||||
// conf.GetBotSettings().TGBotApi,
|
||||
client)
|
||||
if len(HttpProxy) != 0 {
|
||||
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}}
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithClient(
|
||||
conf.GetBotSettings().BotToken,
|
||||
api,
|
||||
client)
|
||||
} else {
|
||||
conf.Bot, err = tgbotapi.NewBotAPIWithAPIEndpoint(conf.GetBotSettings().BotToken, api)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
|
Reference in New Issue
Block a user