Created
May 20, 2017 11:17
-
-
Save vodolaz095/ea09eab801abf412dc49242c42628bc4 to your computer and use it in GitHub Desktop.
Example of how to host telegram bot on heroky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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