Skip to content

Commit 6180587

Browse files
committed
fix: resolve message update issue for AI processing
- Fix ReplyMarkup handling in EditMessageText method - Add comprehensive logging for message update process - Improve error handling for message editing - Add request/response logging for debugging - Ensure '🤔 Thinking...' message is properly replaced with 'Choose a folder:' - Fix keyboard attachment to updated messages
1 parent 21b9ef8 commit 6180587

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

bot_modular

792 Bytes
Binary file not shown.

internal/handlers/ai_handlers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (ah *AIHandlers) HandleGeneralTopicMessage(update *gotgbot.Update) error {
8484
ah.storeMessageReferences(msg, suggestions, topics)
8585

8686
// Update the waiting message with suggestions
87+
log.Printf("[AIHandlers] Updating waiting message: ChatID=%d, MessageID=%d, Text='%s'", msg.Chat.Id, waitingMsg.MessageId, config.ChooseFolderMessage)
8788
_, err = ah.messageService.EditMessageText(msg.Chat.Id, int64(waitingMsg.MessageId), config.ChooseFolderMessage, &gotgbot.EditMessageTextOpts{
8889
ReplyMarkup: *keyboard,
8990
})
@@ -92,6 +93,7 @@ func (ah *AIHandlers) HandleGeneralTopicMessage(update *gotgbot.Update) error {
9293
// If update fails, try to find the message by searching through all stored keyboard messages
9394
ah.tryUpdateExistingMessage(msg, keyboard)
9495
} else {
96+
log.Printf("[AIHandlers] Successfully updated waiting message with keyboard")
9597
// Store keyboard message ID for all suggestion buttons
9698
ah.storeKeyboardMessageIDs(msg, suggestions, topics, int(waitingMsg.MessageId))
9799
}

internal/services/message_service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ func (ms *MessageService) EditMessageText(chatID int64, messageID int64, text st
258258
if opts.ParseMode != "" {
259259
requestBody["parse_mode"] = opts.ParseMode
260260
}
261-
// ReplyMarkup is not a pointer, so we can't check for nil
262-
// We'll include it if it's not the zero value
263-
if opts.ReplyMarkup.InlineKeyboard != nil {
261+
// Check if ReplyMarkup has any content
262+
if len(opts.ReplyMarkup.InlineKeyboard) > 0 {
264263
requestBody["reply_markup"] = opts.ReplyMarkup
265264
}
266265
}
267266

268267
bodyBytes, _ := json.Marshal(requestBody)
268+
log.Printf("[MessageService] Edit request body: %s", string(bodyBytes))
269269

270270
req, err := http.NewRequest("POST", url, strings.NewReader(string(bodyBytes)))
271271
if err != nil {
@@ -283,6 +283,7 @@ func (ms *MessageService) EditMessageText(chatID int64, messageID int64, text st
283283
defer resp.Body.Close()
284284

285285
body, _ := io.ReadAll(resp.Body)
286+
log.Printf("[MessageService] Edit response: %s", string(body))
286287

287288
var result struct {
288289
Ok bool `json:"ok"`

0 commit comments

Comments
 (0)