all repos — telegram-bot-api @ 8b33fd5a507598ec18d38a51be13f7fe0300d6cd

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() {
13	bot.Updates = make(chan Update, 100)
14
15	http.HandleFunc("/"+bot.Token, 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}