From 9b7184fa7951958c72a6a0fcc1e456065bc829fa Mon Sep 17 00:00:00 2001 From: scnace Date: Mon, 8 Jan 2018 02:10:50 +0800 Subject: [PATCH] check telegram webhook tls handshake --- README.md | 8 +++++++- bot_test.go | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 266f4ed..d9a6873 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,13 @@ func main() { 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) diff --git a/bot_test.go b/bot_test.go index 0fb0855..5a3057d 100644 --- a/bot_test.go +++ b/bot_test.go @@ -467,7 +467,13 @@ func TestSetWebhookWithCert(t *testing.T) { t.Error(err) t.Fail() } - + info, err := bot.GetWebhookInfo() + if err != nil { + t.Error(err) + } + if info.LastErrorDate != 0 { + t.Errorf("[Telegram callback failed]%s", info.LastErrorMessage) + } bot.RemoveWebhook() } @@ -484,7 +490,13 @@ func TestSetWebhookWithoutCert(t *testing.T) { t.Error(err) t.Fail() } - + info, err := bot.GetWebhookInfo() + if err != nil { + t.Error(err) + } + if info.LastErrorDate != 0 { + t.Errorf("[Telegram callback failed]%s", info.LastErrorMessage) + } bot.RemoveWebhook() } @@ -549,7 +561,13 @@ func ExampleNewWebhook() { 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)