Skip to content

Commit

Permalink
feat: support custom tgbot api endpoint (#39)
Browse files Browse the repository at this point in the history
* feat: support custom tgbot api endpoint

* fix: removed TELEGRAM_API_ENDPOINT from env.example and merged upstream changes
  • Loading branch information
Mystery00 authored Dec 10, 2022
1 parent 637019c commit 2dc2c2e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/tgbot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tgbot

import (
"log"
"os"
"time"

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

func New(token string, editInterval time.Duration) (*Bot, error) {
api, err := tgbotapi.NewBotAPI(token)
var api *tgbotapi.BotAPI
var err error
apiEndpoint, exist := os.LookupEnv("TELEGRAM_API_ENDPOINT")
if exist && apiEndpoint != "" {
api, err = tgbotapi.NewBotAPIWithAPIEndpoint(token, apiEndpoint)
} else {
api, err = tgbotapi.NewBotAPI(token)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2dc2c2e

Please sign in to comment.