diff --git a/go-chat-bridge b/go-chat-bridge index 6a69ce0..0b0b629 100755 Binary files a/go-chat-bridge and b/go-chat-bridge differ diff --git a/telegram_listener.go b/telegram_listener.go index 62e5537..0b5fce2 100644 --- a/telegram_listener.go +++ b/telegram_listener.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "log" + "sort" + "strings" 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) 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 if update.Message != nil { @@ -77,7 +87,28 @@ func (b *Bridge) StartTelegramListener( } 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) } } @@ -171,3 +202,33 @@ func reactionDisplayValue(reaction telegramReactionType) string { } 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, ", ") + "]" +}