all repos — telegram-bot-api @ d1358d12aaa4207728e8a60aa1c62b670611f9c3

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.
10// Useful for Google App Engine or other places where you cannot
11// use a normal update chan.
12func (bot *BotAPI) ListenForWebhook(config WebhookConfig) {
13	bot.Updates = make(chan Update, 100)
14
15	http.HandleFunc("/"+config.Url.Path, func(w http.ResponseWriter, r *http.Request) {
16		bytes, _ := ioutil.ReadAll(r.Body)
17
18		var update Update
19		json.Unmarshal(bytes, &update)
20
21		bot.Updates <- update
22	})
23}