Merge pull request #313 from AdelyaGarieva/master

Ability to create BotAPI instance directly with new API endpoint
This commit is contained in:
Kirill Zhuharev 2020-03-11 09:10:48 +03:00 committed by GitHub
commit 1569b35611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

16
bot.go
View file

@ -36,21 +36,29 @@ type BotAPI struct {
//
// It requires a token, provided by @BotFather on Telegram.
func NewBotAPI(token string) (*BotAPI, error) {
return NewBotAPIWithClient(token, &http.Client{})
return NewBotAPIWithClient(token, APIEndpoint, &http.Client{})
}
// NewBotAPIWithAPIEndpoint creates a new BotAPI instance
// and allows you to pass API endpoint.
//
// It requires a token, provided by @BotFather on Telegram and API endpoint.
func NewBotAPIWithAPIEndpoint(token, apiEndpoint string) (*BotAPI, error) {
return NewBotAPIWithClient(token, apiEndpoint, &http.Client{})
}
// NewBotAPIWithClient creates a new BotAPI instance
// and allows you to pass a http.Client.
//
// It requires a token, provided by @BotFather on Telegram.
func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
// It requires a token, provided by @BotFather on Telegram and API endpoint.
func NewBotAPIWithClient(token, apiEndpoint string, client *http.Client) (*BotAPI, error) {
bot := &BotAPI{
Token: token,
Client: client,
Buffer: 100,
shutdownChannel: make(chan interface{}),
apiEndpoint: APIEndpoint,
apiEndpoint: apiEndpoint,
}
self, err := bot.GetMe()