From c488478ab990920f7c5ee5511ecf84cbee6aab20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BCbler?= Date: Wed, 2 Sep 2020 16:43:05 +0200 Subject: [PATCH] enable delay suggestions (#23) --- cmd/bot.go | 11 ++++++++--- pkg/interface/telegram/editdelay.go | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/bot.go b/cmd/bot.go index e67ca70..b9e6674 100644 --- a/cmd/bot.go +++ b/cmd/bot.go @@ -161,11 +161,16 @@ func BotCommand(ctx context.Context, cmd *cobra.Command, args []string) { if tctx.IsRemoveSuggestions() { reply.ReplyMarkup = tgbotapi.NewRemoveKeyboard(true) } else if tctx.IsSuggestions() { - buttons := []tgbotapi.KeyboardButton{} + buttons := [][]tgbotapi.KeyboardButton{} for _, button := range tctx.Suggestions() { - buttons = append(buttons, tgbotapi.NewKeyboardButton(button.Label)) + buttons = append( + buttons, + tgbotapi.NewKeyboardButtonRow( + tgbotapi.NewKeyboardButton(button.Label), + ), + ) } - keyboard := tgbotapi.NewReplyKeyboard(buttons) + keyboard := tgbotapi.NewReplyKeyboard(buttons...) reply.ReplyMarkup = keyboard } diff --git a/pkg/interface/telegram/editdelay.go b/pkg/interface/telegram/editdelay.go index 22411f6..365d48a 100644 --- a/pkg/interface/telegram/editdelay.go +++ b/pkg/interface/telegram/editdelay.go @@ -30,5 +30,16 @@ func (t *TelegramService) EditDelay(ctx telegramconversation.TContext) telegramc } ctx.SetStatePayload(alarm.GetID()) - return ctx.SendWithState(fmt.Sprintf("Ab wie viel Abweichung von `%s > %s` soll bescheid gesagt werden? z.B. 1h5min oder 10m", alarm.GetTrainName(), alarm.GetFinalDestinationName()), "savedelay") + ctx.ChangeState("savedelay") + + txt := fmt.Sprintf("Ab wie viel Abweichung von `%s > %s` soll bescheid gesagt werden? z.B. 1h5min oder 10m", alarm.GetTrainName(), alarm.GetFinalDestinationName()) + + buttons := []telegramconversation.TButton{} + units := []string{"1m", "5m", "10m", "15m", "20m", "30m", "1h", "1h30m"} + for _, unit := range units { + button := telegramconversation.NewTButton(unit, unit) + buttons = append(buttons, button) + } + + return ctx.SendWithSuggestions(txt, buttons, 1) }