Closed roxyash closed 1 year ago
It was easier than I thought
func GenerateKeyboardWithSubjects() (tgbotapi.InlineKeyboardMarkup, error) {
dateTo := strings.Split(time.Now().Format(time.RFC3339), "T")[0]
dateStart := fmt.Sprintf("%v-%v-%v", strings.Split(dateTo, "-")[0], strings.Split(dateTo, "-")[1], "01")
arg := params.GetSubjectsForAnyDateParams{
ToDate: dateStart,
ToDate_2: dateTo,
}
subjects, err := store.GetSubjectsForAnyDate(context.Background(), arg)
if err != nil {
return tgbotapi.NewInlineKeyboardMarkup(), err
}
rows := make([][]tgbotapi.InlineKeyboardButton, len(subjects))
for index, subject := range subjects {
rows[index] = tgbotapi.NewInlineKeyboardRow(tgbotapi.InlineKeyboardButton{
Text: subject,
CallbackData: &subject,
})
}
return tgbotapi.NewInlineKeyboardMarkup(rows...), nil
}
I'm considering a similar question (https://github.com/go-telegram-bot-api/telegram-bot-api/issues/225), but not quite putting it into practice for inline keyboard markup.