webhook.go (view raw)
1package tgbotapi
2
3import (
4 "encoding/json"
5 "io/ioutil"
6 "net/http"
7)
8
9// ListenForWebhook registers a http handler for a webhook.
10func (bot *BotAPI) ListenForWebhook(pattern string) {
11 bot.Updates = make(chan Update, 100)
12
13 http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
14 bytes, _ := ioutil.ReadAll(r.Body)
15
16 var update Update
17 json.Unmarshal(bytes, &update)
18
19 bot.Updates <- update
20 })
21}