Skip to content

Instantly share code, notes, and snippets.

@peeyushsrj
Last active February 1, 2017 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peeyushsrj/51c349f1181b806ad58d9c0853219c2a to your computer and use it in GitHub Desktop.
Save peeyushsrj/51c349f1181b806ad58d9c0853219c2a to your computer and use it in GitHub Desktop.
Hosting a telegram go webhook on digitalocean
package main
import (
"gopkg.in/telegram-bot-api.v4"
"log"
"net/http"
)
func main() {
bot, err := tgbotapi.NewBotAPI("328357664:AAGrnpzHV6_mzy-OCm5trALxdMstwNyZEHQ")
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.peeyushsrj.me: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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment