From 4b9d6de0a9c8776212821e2adf24c00717676d09 Mon Sep 17 00:00:00 2001 From: Jiayu Yi Date: Mon, 5 Jun 2017 15:00:09 +0800 Subject: [PATCH] Allow APIEndpoint to be overridden in BotAPI --- bot.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index 2ff6fa2..19f9b8b 100644 --- a/bot.go +++ b/bot.go @@ -21,6 +21,8 @@ import ( // BotAPI allows you to interact with the Telegram Bot API. type BotAPI struct { + APIEndpoint string `json:"api_endpoint"` + Token string `json:"token"` Debug bool `json:"debug"` Buffer int `json:"buffer"` @@ -42,6 +44,7 @@ func NewBotAPI(token string) (*BotAPI, error) { // It requires a token, provided by @BotFather on Telegram. func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { bot := &BotAPI{ + APIEndpoint: APIEndpoint, Token: token, Client: client, 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. 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) if err != nil {