【发布时间】:2018-04-24 00:34:24
【问题描述】:
我使用 go-telegram-bot-api 构建 Telegram Bot 并将其部署在 Heroku 上。
我需要像以前在 Python 中那样设置 Webhooks,例如 in this Python case。
在不提供证书文件的情况下,无法理解如何在go-telegram-bot-api 中设置 Webhooks。
主要示例包含这样的行:
如果您需要使用 webhook(如果您希望在 Google App Engine 上运行),您可以使用稍微不同的方法。
package main
import (
"gopkg.in/telegram-bot-api.v4"
"log"
"net/http"
)
func main() {
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
if err != nil {
log.Fatal(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
_, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
if err != nil {
log.Fatal(err)
}
updates := bot.ListenForWebhook("/" + bot.Token)
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
for update := range updates {
log.Printf("%+v\n", update)
}
}
但是使用 Heroku 进行部署我如何在不提供 pem 证书文件的情况下收听 Webhooks?
【问题讨论】:
-
我也在 Github 问题中向
go-telegram-bot-api存储库提出了这个问题,并得到了一个很好的答案:您只需将其替换为go http.ListenAndServe(":8080", nil),它似乎正在工作!
标签: heroku go webhooks telegram-bot telegram-webhook