по реакции теперь сохраняем сообщение

This commit is contained in:
Taz
2026-04-22 23:27:35 +02:00
parent 90e83bcb1d
commit 6d57767344
2 changed files with 62 additions and 1 deletions
BIN
View File
Binary file not shown.
+62 -1
View File
@@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"sort"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
) )
@@ -61,6 +63,14 @@ func (b *Bridge) StartTelegramListener(
log.Printf("[Telegram] cannot decode update item: %v", err) log.Printf("[Telegram] cannot decode update item: %v", err)
continue continue
} }
updateKinds := detectTelegramUpdateKinds(raw)
log.Printf(
"[Telegram][diag] update_id=%d kinds=%s has_message=%t has_message_reaction=%t",
update.UpdateID,
strings.Join(updateKinds, ","),
update.Message != nil,
update.MessageReaction != nil,
)
offset = update.UpdateID + 1 offset = update.UpdateID + 1
if update.Message != nil { if update.Message != nil {
@@ -77,7 +87,28 @@ func (b *Bridge) StartTelegramListener(
} }
if update.MessageReaction != nil { if update.MessageReaction != nil {
for _, reaction := range addedReactions(update.MessageReaction.OldReaction, update.MessageReaction.NewReaction) { log.Printf(
"[Telegram][diag] message_reaction chat_id=%d message_id=%d old=%s new=%s",
update.MessageReaction.Chat.ID,
update.MessageReaction.MessageID,
formatTelegramReactions(update.MessageReaction.OldReaction),
formatTelegramReactions(update.MessageReaction.NewReaction),
)
added := addedReactions(update.MessageReaction.OldReaction, update.MessageReaction.NewReaction)
if len(added) == 0 {
log.Printf(
"[Telegram][diag] message_reaction chat_id=%d message_id=%d has no added reactions",
update.MessageReaction.Chat.ID,
update.MessageReaction.MessageID,
)
}
for _, reaction := range added {
log.Printf(
"[Telegram][diag] added reaction chat_id=%d message_id=%d reaction=%q",
update.MessageReaction.Chat.ID,
update.MessageReaction.MessageID,
reaction,
)
onReactionAdded(update.MessageReaction.Chat.ID, update.MessageReaction.MessageID, reaction) onReactionAdded(update.MessageReaction.Chat.ID, update.MessageReaction.MessageID, reaction)
} }
} }
@@ -171,3 +202,33 @@ func reactionDisplayValue(reaction telegramReactionType) string {
} }
return reaction.Type return reaction.Type
} }
func detectTelegramUpdateKinds(raw json.RawMessage) []string {
var payload map[string]json.RawMessage
if err := json.Unmarshal(raw, &payload); err != nil {
return []string{"unmarshal_error"}
}
kinds := make([]string, 0, len(payload))
for key := range payload {
if key == "update_id" {
continue
}
kinds = append(kinds, key)
}
if len(kinds) == 0 {
return []string{"none"}
}
sort.Strings(kinds)
return kinds
}
func formatTelegramReactions(list []telegramReactionType) string {
if len(list) == 0 {
return "[]"
}
parts := make([]string, 0, len(list))
for _, reaction := range list {
parts = append(parts, reactionKey(reaction)+"="+reactionDisplayValue(reaction))
}
return "[" + strings.Join(parts, ", ") + "]"
}