Skip to content

Commit d759f2d

Browse files
committed
fix: remove clarify inline keyboard after user answers; add reply_markup support to EditMessageText
1 parent 57ea86d commit d759f2d

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

cmd/odek/telegram.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ var chatCancels sync.Map // map[int64]context.CancelFunc
4242
// interrupted task.
4343
var chatRunInfos sync.Map // map[int64]loop.IterationInfo
4444

45+
// clarifyMsgIDs stores the message ID of the active clarify prompt
46+
// per chat, so the callback handler can edit/remove it after the user
47+
// responds. Cleared when the clarify tool completes or times out.
48+
var clarifyMsgIDs sync.Map // map[int64]int
49+
4550
// pendingSuggestions stores SkillSuggestion values keyed by skill name,
4651
// awaiting user approval via inline keyboard callbacks.
4752
var pendingSuggestions sync.Map // map[string]skills.SkillSuggestion
@@ -400,7 +405,14 @@ func telegramCmd(args []string) error {
400405
// Channel full or closed — clarify already resolved.
401406
}
402407
}
403-
return "✅ You chose **" + answer + "**", nil
408+
// Remove the inline keyboard and update text to show the answer.
409+
if msgID, ok := clarifyMsgIDs.Load(chatID); ok {
410+
bot.EditMessageText(chatID, msgID.(int),
411+
"✅ *User answered:* "+answer,
412+
&telegram.SendOpts{ParseMode: telegram.ParseModeMarkdownV2, ReplyMarkup: &telegram.InlineKeyboardMarkup{InlineKeyboard: [][]telegram.InlineKeyboardButton{}}})
413+
clarifyMsgIDs.Delete(chatID)
414+
}
415+
return "", nil
404416
}
405417

406418
// Route skill suggestion callbacks — Save or Skip.
@@ -1072,9 +1084,12 @@ func handleChatMessage(
10721084
},
10731085
},
10741086
}
1075-
if _, err := bot.SendMessage(chatID, "❓ "+question,
1087+
if msg, err := bot.SendMessage(chatID, "❓ "+question,
10761088
&telegram.SendOpts{ReplyMarkup: replyMarkup, ParseMode: "Markdown", ReplyToMessageID: messageID}); err != nil {
10771089
return "", fmt.Errorf("clarify: send message: %w", err)
1090+
} else {
1091+
clarifyMsgIDs.Store(chatID, msg.ID)
1092+
defer clarifyMsgIDs.Delete(chatID)
10781093
}
10791094

10801095
// Wait for the user to click a button (or timeout).

internal/telegram/bot.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ func (b *Bot) EditMessageText(chatID int64, messageID int, text string, opts *Se
338338
if opts != nil && opts.ParseMode != "" {
339339
params["parse_mode"] = opts.ParseMode
340340
}
341+
if opts != nil && opts.ReplyMarkup != nil {
342+
params["reply_markup"] = opts.ReplyMarkup
343+
}
341344
return b.doJSON("editMessageText", params, nil)
342345
}
343346

0 commit comments

Comments
 (0)