From 541c1d3bbf7d141386ba3fc2ac5630c8556a2b0a Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 4 Nov 2024 01:24:40 +0300 Subject: [PATCH] Storing /summarize replies in history too (#32). --- bot/bot.go | 6 +++++- bot/message_history.go | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index b5817c6..a0282ca 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -233,9 +233,11 @@ func (b *Bot) summarizeHandler(bot *telego.Bot, update telego.Update) { slog.Debug("Got completion. Going to send.", "llm-completion", llmReply) + replyMarkdown := b.escapeMarkdownV1Symbols(llmReply) + message := tu.Message( chatID, - b.escapeMarkdownV1Symbols(llmReply), + replyMarkdown, ).WithParseMode("Markdown") _, err = bot.SendMessage(b.reply(update.Message, message)) @@ -245,6 +247,8 @@ func (b *Bot) summarizeHandler(bot *telego.Bot, update telego.Update) { b.trySendReplyError(update.Message) } + + b.saveBotReplyToHistory(update.Message, replyMarkdown) } func (b *Bot) helpHandler(bot *telego.Bot, update telego.Update) { diff --git a/bot/message_history.go b/bot/message_history.go index 1bdab0d..e58ee2d 100644 --- a/bot/message_history.go +++ b/bot/message_history.go @@ -61,14 +61,14 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) { b.history[chatId].Push(msgData) } -func (b *Bot) saveBotReplyToHistory(message *telego.Message, text string) { - chatId := message.Chat.ID +func (b *Bot) saveBotReplyToHistory(replyTo *telego.Message, text string) { + chatId := replyTo.Chat.ID slog.Info( "history-reply-save", "chat", chatId, - "to_id", message.From.ID, - "to_name", message.From.FirstName, + "to_id", replyTo.From.ID, + "to_name", replyTo.From.FirstName, "text", text, ) @@ -84,8 +84,8 @@ func (b *Bot) saveBotReplyToHistory(message *telego.Message, text string) { IsMe: true, } - if message.ReplyToMessage != nil { - replyMessage := message.ReplyToMessage + if replyTo.ReplyToMessage != nil { + replyMessage := replyTo.ReplyToMessage msgData.ReplyTo = &MessageData{ Name: replyMessage.From.FirstName,