Added HandleUpdate method for serverless deploy
(cherry picked from commit d4b2e3c213
)
This commit is contained in:
parent
da98517cd2
commit
ca07bb78e4
2 changed files with 41 additions and 7 deletions
19
bot.go
19
bot.go
|
@ -451,18 +451,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
|
||||
}
|
||||
|
||||
// WriteToHTTPResponse writes the request to the HTTP ResponseWriter.
|
||||
//
|
||||
// It doesn't support uploading files.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue