telegram-bot-api
telegram-bot-api copied to clipboard
Incorrect example implementation of: tgbotapi.NewWebhookWithCert()
If I try to replicate the second example code:
package main
import (
"log"
"net/http"
"github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
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)
wh, _ := tgbotapi.NewWebhookWithCert("https://www.example.com:8443/"+bot.Token, "cert.pem")
_, err = bot.Request(wh)
if err != nil {
log.Fatal(err)
}
info, err := bot.GetWebhookInfo()
if err != nil {
log.Fatal(err)
}
if info.LastErrorDate != 0 {
log.Printf("Telegram callback failed: %s", info.LastErrorMessage)
}
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)
}
}
It does not compile, instead returning the following compilation error:
./main.go:19:89: cannot use "cert.pem" (constant of type string) as type tgbotapi.RequestFileData in argument to tgbotapi.NewWebhookWithCert:
string does not implement tgbotapi.RequestFileData (missing NeedsUpload method)
Yeah!
Needs to be changed to tgbotapi.NewWebhookWithCert("https://www.example.com:8443/"+bot.Token, tgbotapi.FilePath("cert.pem"))
i use above example:
i am open the below url in chrome, its ok!
Post "https://api.telegram.org/botxxxxxxxxxx/getMe": dial tcp 118.180.172.204:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
@freaker2k7 have you encountered the same problem?
@huaiguoguo yes and what I recommended solved it for me.