Merge pull request #270 from Gropher/master

Added HandleUpdate method for serverless deploy. Fixes #260
This commit is contained in:
Syfaro 2020-07-20 13:41:14 -05:00 committed by GitHub
commit 8717c40e7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 7 deletions

19
bot.go
View file

@ -552,18 +552,23 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
ch := make(chan Update, bot.Buffer)
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
bytes, _ := ioutil.ReadAll(r.Body)
r.Body.Close()
var update Update
json.Unmarshal(bytes, &update)
ch <- update
ch <- bot.HandleUpdate(w, r)
})
return ch
}
// HandleUpdate parses and returns update received via webhook
func (bot *BotAPI) HandleUpdate(res http.ResponseWriter, req *http.Request) Update {
bytes, _ := ioutil.ReadAll(req.Body)
req.Body.Close()
var update Update
json.Unmarshal(bytes, &update)
return update
}
// AnswerInlineQuery sends a response to an inline query.
//
// Note that you must respond to an inline query within 30 seconds.