Allow APIEndpoint to be overridden in BotAPI

pull/98/head
Jiayu Yi 8 years ago
parent 79b26b07c5
commit 4b9d6de0a9
No known key found for this signature in database
GPG Key ID: 84B60878E8AEAD6C
  1. 5
      bot.go

@ -21,6 +21,8 @@ import (
// BotAPI allows you to interact with the Telegram Bot API. // BotAPI allows you to interact with the Telegram Bot API.
type BotAPI struct { type BotAPI struct {
APIEndpoint string `json:"api_endpoint"`
Token string `json:"token"` Token string `json:"token"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
Buffer int `json:"buffer"` Buffer int `json:"buffer"`
@ -42,6 +44,7 @@ func NewBotAPI(token string) (*BotAPI, error) {
// It requires a token, provided by @BotFather on Telegram. // It requires a token, provided by @BotFather on Telegram.
func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
bot := &BotAPI{ bot := &BotAPI{
APIEndpoint: APIEndpoint,
Token: token, Token: token,
Client: client, Client: client,
Buffer: 100, Buffer: 100,
@ -59,7 +62,7 @@ func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
// MakeRequest makes a request to a specific endpoint with our token. // MakeRequest makes a request to a specific endpoint with our token.
func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) { func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) {
method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint) method := fmt.Sprintf(bot.APIEndpoint, bot.Token, endpoint)
resp, err := bot.Client.PostForm(method, params) resp, err := bot.Client.PostForm(method, params)
if err != nil { if err != nil {