|
|
|
@ -62,64 +62,7 @@ func main() { |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki) |
|
|
|
|
There are more examples on the [site](https://go-telegram-bot-api.github.io/) |
|
|
|
|
with detailed information on how to do many different kinds of things. |
|
|
|
|
It's a great place to get started on using keyboards, commands, or other |
|
|
|
|
kinds of reply markup. |
|
|
|
|
|
|
|
|
|
If you need to use webhooks (if you wish to run on Google App Engine), |
|
|
|
|
you may use a slightly different method. |
|
|
|
|
|
|
|
|
|
```go |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"log" |
|
|
|
|
"net/http" |
|
|
|
|
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
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.Request(tgbotapi.NewWebhookWithCert("https://www.google.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) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
If you need, you may generate a self signed certficate, as this requires |
|
|
|
|
HTTPS / TLS. The above example tells Telegram that this is your |
|
|
|
|
certificate and that it should be trusted, even though it is not |
|
|
|
|
properly signed. |
|
|
|
|
|
|
|
|
|
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes |
|
|
|
|
|
|
|
|
|
Now that [Let's Encrypt](https://letsencrypt.org) is available, you may |
|
|
|
|
wish to generate your free TLS certificate there. |
|
|
|
|