all repos — telegram-bot-api @ 1bceea1ca532fa0d7107a1ad08549f7d41d42b5c

Golang bindings for the Telegram Bot API

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}