package main import ( "html/template" "log" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) func getCurrentStatus(dataStore *DataStore, logger *log.Logger, config AppConfig, tpl *template.Template, s SatelNameGetter) string { elements := FilterBasicElementsByTypeOrIndex(dataStore.GetBasicEventElements(), config.AllowedTypes, config.AllowedIndexes) msg := GenericMessage{elements} return msg.Format(tpl, s, logger) } func HandleTelegramCommands(bot TelegramBot, logger *log.Logger, dataStore *DataStore, config AppConfig, tpl *template.Template, s SatelNameGetter) { u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates := bot.GetUpdatesChan(u) for update := range updates { if update.Message == nil { // ignore any non-Message updates continue } if !update.Message.IsCommand() { // ignore any non-command Messages continue } // Create a new MessageConfig. We don't have text yet, // so we leave it empty. msg := tgbotapi.NewMessage(update.Message.Chat.ID, "") // Extract the command from the Message. switch update.Message.Command() { case "status": msg.Text = getCurrentStatus(dataStore, logger, config, tpl, s) } if _, err := bot.Send(msg); err != nil { logger.Print(err) } } logger.Println("Stopping command handler") }