summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go')
-rw-r--r--vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go
index 7ae3b472..c2b4529b 100644
--- a/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go
+++ b/vendor/github.com/go-telegram-bot-api/telegram-bot-api/bot.go
@@ -21,8 +21,10 @@ import (
// BotAPI allows you to interact with the Telegram Bot API.
type BotAPI struct {
- Token string `json:"token"`
- Debug bool `json:"debug"`
+ Token string `json:"token"`
+ Debug bool `json:"debug"`
+ Buffer int `json:"buffer"`
+
Self User `json:"-"`
Client *http.Client `json:"-"`
}
@@ -42,11 +44,12 @@ func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
bot := &BotAPI{
Token: token,
Client: client,
+ Buffer: 100,
}
self, err := bot.GetMe()
if err != nil {
- return &BotAPI{}, err
+ return nil, err
}
bot.Self = self
@@ -68,6 +71,10 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse,
return APIResponse{}, errors.New(ErrAPIForbidden)
}
+ if resp.StatusCode != http.StatusOK {
+ return APIResponse{}, errors.New(http.StatusText(resp.StatusCode))
+ }
+
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return APIResponse{}, err
@@ -457,7 +464,7 @@ func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
// GetUpdatesChan starts and returns a channel for getting updates.
func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
- ch := make(chan Update, 100)
+ ch := make(chan Update, bot.Buffer)
go func() {
for {
@@ -484,7 +491,7 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
// ListenForWebhook registers a http handler for a webhook.
func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
- ch := make(chan Update, 100)
+ ch := make(chan Update, bot.Buffer)
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
bytes, _ := ioutil.ReadAll(r.Body)