Skip to content

Instantly share code, notes, and snippets.

@vodolaz095
Created May 20, 2017 11:17
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 vodolaz095/ea09eab801abf412dc49242c42628bc4 to your computer and use it in GitHub Desktop.
Save vodolaz095/ea09eab801abf412dc49242c42628bc4 to your computer and use it in GitHub Desktop.
Example of how to host telegram bot on heroky
package main
import (
"gopkg.in/telegram-bot-api.v4"
"log"
"net/http"
"os"
)
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv("BOT_TOKEN"))
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
bot.RemoveWebhook()
_, err = bot.SetWebhook(tgbotapi.NewWebhook("https://name_of_your_app.herokuapp.com/" + bot.Token))
if err != nil {
log.Fatal(err)
}
updates := bot.ListenForWebhook("/" + bot.Token)
go http.ListenAndServe("0.0.0.0:"+os.Getenv("PORT"), nil)
for update := range updates {
// log.Printf("%+v\n", update)
if update.Message == nil {
continue
}
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment