commit 28b54f9cd9dd750007f02b27caa7e92911188386 Author: Akulij Date: Sat May 4 20:55:52 2024 +0300 implement base telegram bot (echo) diff --git a/cmd/app/main.go b/cmd/app/main.go new file mode 100644 index 0000000..59d173e --- /dev/null +++ b/cmd/app/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + "os" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" +) + +func main() { + token := os.Getenv("BOTTOKEN") + fmt.Printf("Token value: '%v'\n", token) + bot, err := tgbotapi.NewBotAPI(token) + if err != nil { + log.Panic(err) + } + + bot.Debug = true + + log.Printf("Authorized on account %s", bot.Self.UserName) + + u := tgbotapi.NewUpdate(0) + u.Timeout = 60 + + updates := bot.GetUpdatesChan(u) + + for update := range updates { + if update.Message != nil { + log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) + msg.ReplyToMessageID = update.Message.MessageID + + bot.Send(msg) + } + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..63616cb --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/akulij/zarabot + +go 1.22.2 + +require github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..db8e45c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc= +github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=