Seeting up a webhook for GAE (telegram bot deployed)

29 views
Skip to first unread message

Andreas

unread,
Sep 16, 2019, 1:30:52 AM9/16/19
to golang-nuts
I deployed a telegram bot on GAE but it seems something went wrong - I do not recive any updates from channel.
Is this a valid example, or there is an error?

import (
   
"log"
   
"net/http"

    tgbotapi
"github.com/go-telegram-bot-api/telegram-bot-api"
)

func main
() {

    log
.Printf("%s", "\n#============================================================#")
    apiToken
:= "sometokenhere"

    bot
, err := tgbotapi.NewBotAPI(apiToken)
   
if err != nil {
        log
.Fatal(err)
   
}

    bot
.Debug = true

    log
.Printf("Authorized on account %s", bot.Self.UserName)

    _
, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://patternbot.appspot.com:8443/"+bot.Token, "cert.pem"))
   
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)
   
} else {
        log
.Printf("Webhook info: %v", info)
   
}

    updates
:= bot.ListenForWebhook("/" + bot.Token)
    go http
.ListenAndServeTLS("91.108.4.0/22:8443", "cert.pem", "key.pem", nil)

   
for update := range updates {
        log
.Printf("%s%+v\n", "----------------------- ", update)
   
}
}

A console output from GAE:

2019-09-16 05:21:48 default[20190916t082016]  #============================================================#
2019-09-16 05:21:49 default[20190916t082016]  2019/09/16 05:21:49 Authorized on account leonardo_da_vinchi_bot
2019-09-16 05:21:49 default[20190916t082016]  2019/09/16 05:21:49 {"ok":true,"result":true,"description":"Webhook was set"}
2019-09-16 05:21:49 default[20190916t082016]  2019/09/16 05:21:49 getWebhookInfo resp: {"ok":true,"result":{"url":"https://patternbot.appspot.com:8443/sometokenhere","has_custom_certificate":true,"pending_update_count":9,"max_connections":40}}
2019-09-16 05:21:49 default[20190916t082016]  2019/09/16 05:21:49 Webhook info: {https://patternbot.appspot.com:8443/sometokenhere true 9 0 }

There should be messages from the `updates` channel but they do not come. What is wrong with it?
Reply all
Reply to author
Forward
0 new messages