all repos — telegram-bot-api @ 8d345836d6a6a3b188ef4ff0cf2a54afd27edde5

Golang bindings for the Telegram Bot API

Allow to change API endpoint for bot
zhuharev unybigk@gmail.com
Fri, 24 May 2019 13:14:48 +0300
commit

8d345836d6a6a3b188ef4ff0cf2a54afd27edde5

parent

87e7035a900c7cb1fd896e5f33b461c96c3ac31e

1 files changed, 16 insertions(+), 8 deletions(-)

jump to
M bot.gobot.go

@@ -25,9 +25,11 @@ Token string `json:"token"`

Debug bool `json:"debug"` Buffer int `json:"buffer"` - Self User `json:"-"` - Client *http.Client `json:"-"` + Self User `json:"-"` + Client *http.Client `json:"-"` shutdownChannel chan interface{} + + apiEndpoint string } // NewBotAPI creates a new BotAPI instance.

@@ -43,10 +45,12 @@ //

// It requires a token, provided by @BotFather on Telegram. func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { bot := &BotAPI{ - Token: token, - Client: client, - Buffer: 100, + Token: token, + Client: client, + Buffer: 100, shutdownChannel: make(chan interface{}), + + apiEndpoint: APIEndpoint, } self, err := bot.GetMe()

@@ -59,9 +63,13 @@

return bot, nil } +func (b *BotAPI) SetAPIEndpoint(apiEndpoint string) { + b.apiEndpoint = apiEndpoint +} + // 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 {

@@ -186,7 +194,7 @@ default:

return APIResponse{}, errors.New(ErrBadFileType) } - method := fmt.Sprintf(APIEndpoint, bot.Token, endpoint) + method := fmt.Sprintf(bot.apiEndpoint, bot.Token, endpoint) req, err := http.NewRequest("POST", method, nil) if err != nil {

@@ -490,7 +498,7 @@ case <-bot.shutdownChannel:

return default: } - + updates, err := bot.GetUpdates(config) if err != nil { log.Println(err)