From d7db586637daf1f993c122ff604b8aa994aa87df Mon Sep 17 00:00:00 2001 From: surdeus Date: Sat, 8 Jul 2023 22:26:21 +0300 Subject: [PATCH] Checking working with the keyboard. --- go.mod | 2 ++ go.sum | 2 ++ src/cmd/test/main.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 go.sum diff --git a/go.mod b/go.mod index a3b7039..cd8348f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module boteval go 1.20 + +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= diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index da29a2c..2416681 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -1,4 +1,61 @@ + package main +import ( + "log" + "os" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + +) + +var numericKeyboard = tgbotapi.NewReplyKeyboard( + tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton("1"), + tgbotapi.NewKeyboardButton("2"), + tgbotapi.NewKeyboardButton("3"), + ), + tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton("4"), + tgbotapi.NewKeyboardButton("5"), + tgbotapi.NewKeyboardButton("6"), + ), +) + func main() { + token := os.Getenv("BOT_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 { // ignore non-Message updates + continue + } + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) + + switch update.Message.Text { + case "open": + msg.ReplyMarkup = numericKeyboard + case "close": + msg.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true) + } + + if _, err := bot.Send(msg); err != nil { + log.Panic(err) + } + } } +