Ability to pass a client to the bot
Changed every instance of a DefaultClient to a Client stored in the bot.
This commit is contained in:
parent
60337023c5
commit
612584dbd3
2 changed files with 13 additions and 6 deletions
12
bot.go
12
bot.go
|
@ -1,19 +1,27 @@
|
|||
// Package tgbotapi has bindings for interacting with the Telegram Bot API.
|
||||
package tgbotapi
|
||||
|
||||
import "net/http"
|
||||
|
||||
// BotAPI has methods for interacting with all of Telegram's Bot API endpoints.
|
||||
type BotAPI struct {
|
||||
Token string `json:"token"`
|
||||
Debug bool `json:"debug"`
|
||||
Self User `json:"-"`
|
||||
Updates chan Update `json:"-"`
|
||||
Client http.Client `json:"-"`
|
||||
}
|
||||
|
||||
// NewBotAPI creates a new BotAPI instance.
|
||||
// Requires a token, provided by @BotFather on Telegram
|
||||
func NewBotAPI(token string) (*BotAPI, error) {
|
||||
func NewBotAPI(token string, client http.Client) (*BotAPI, error) {
|
||||
if client == nil {
|
||||
client = &http.Client{}
|
||||
}
|
||||
|
||||
bot := &BotAPI{
|
||||
Token: token,
|
||||
Token: token,
|
||||
Client: client,
|
||||
}
|
||||
|
||||
self, err := bot.GetMe()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue