1
0
Fork 0
telegram-group2mastodon/main.go
Daniele Tricoli 629370c1c5
All checks were successful
continuous-integration/drone/push Build is passing
Create a bot that read messages
2022-02-27 02:48:51 +01:00

45 lines
708 B
Go

package main
import (
"log"
"os"
"strconv"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
const (
DEBUG = "DEBUG"
TELEGRAM_BOT_TOKEN = "TELEGRAM_BOT_TOKEN"
)
func main() {
bot, err := tgbotapi.NewBotAPI(os.Getenv(TELEGRAM_BOT_TOKEN))
if err != nil {
log.Panic(err)
}
bot.Debug = parseBoolOrFalse(os.Getenv(DEBUG))
u := tgbotapi.NewUpdate(0)
u.Timeout = 30
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message != nil {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
}
}
}
func parseBoolOrFalse(s string) bool {
r, err := strconv.ParseBool(s)
if err != nil {
return false
}
return r
}