示例#1
0
func setWebhookHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	bot, err := botApi.NewBotAPIWithClient(TOKEN, urlfetch.Client(appengine.NewContext(r)))
	resp, err := bot.SetWebhook(botApi.NewWebhook(r.URL.Query().Get("url")))
	str, err := json.Marshal(resp)
	checkErr(w, err)
	fmt.Fprint(w, string(str))
}
示例#2
0
//----------------------------------------------Handlers
func meHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	bot, err := botApi.NewBotAPIWithClient(TOKEN, urlfetch.Client(appengine.NewContext(r)))
	user, err := bot.GetMe()
	resp, err := json.Marshal(user)
	checkErr(w, err)
	fmt.Fprint(w, string(resp))
}
示例#3
0
func updateHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	bot, err := botApi.NewBotAPIWithClient(TOKEN, urlfetch.Client(appengine.NewContext(r)))
	num, err := strconv.Atoi(r.URL.Query().Get("offset"))
	updates, err := bot.GetUpdates(botApi.NewUpdate(num))
	resp, err := json.Marshal(updates)
	checkErr(w, err)
	fmt.Fprint(w, string(resp))
}