extended logging #532
@@ -209,16 +209,29 @@ func (m *confirmationManager) HandleUpdate(ctx context.Context, update *telegram
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if update == nil {
|
if update == nil {
|
||||||
m.logDebug("Telegram update ignored: update is nil")
|
m.logInfo("Telegram update ignored: update is nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if update.Message == nil {
|
if update.Message == nil {
|
||||||
m.logDebug("Telegram update ignored: message is nil")
|
m.logInfo("Telegram update ignored: message is nil", zap.Int64("update_id", update.UpdateID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
message := update.Message
|
message := update.Message
|
||||||
|
fields := []zap.Field{
|
||||||
|
zap.Int64("update_id", update.UpdateID),
|
||||||
|
zap.Int64("message_id", message.MessageID),
|
||||||
|
zap.Int64("chat_id", message.Chat.ID),
|
||||||
|
zap.Int("text_length", len(message.Text)),
|
||||||
|
}
|
||||||
|
if message.From != nil {
|
||||||
|
fields = append(fields, zap.Int64("from_user_id", message.From.ID))
|
||||||
|
}
|
||||||
|
if message.ReplyToMessage != nil {
|
||||||
|
fields = append(fields, zap.Int64("reply_to_message_id", message.ReplyToMessage.MessageID))
|
||||||
|
}
|
||||||
|
m.logInfo("Handling Telegram confirmation update", fields...)
|
||||||
if message.ReplyToMessage == nil {
|
if message.ReplyToMessage == nil {
|
||||||
m.logDebug("Telegram update ignored: message is not a reply", zap.Int64("message_id", message.MessageID))
|
m.logInfo("Telegram update ignored: message is not a reply", zap.Int64("message_id", message.MessageID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +239,7 @@ func (m *confirmationManager) HandleUpdate(ctx context.Context, update *telegram
|
|||||||
m.logDebug("Telegram reply received", zap.String("reply_to_message_id", replyToID))
|
m.logDebug("Telegram reply received", zap.String("reply_to_message_id", replyToID))
|
||||||
state := m.lookupByMessageID(replyToID)
|
state := m.lookupByMessageID(replyToID)
|
||||||
if state == nil {
|
if state == nil {
|
||||||
m.logDebug("Telegram reply ignored: no pending confirmation for message", zap.String("reply_to_message_id", replyToID))
|
m.logInfo("Telegram reply ignored: no pending confirmation for message", zap.String("reply_to_message_id", replyToID), zap.Int64("update_id", update.UpdateID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.logDebug("Telegram reply matched pending confirmation",
|
m.logDebug("Telegram reply matched pending confirmation",
|
||||||
@@ -235,7 +248,7 @@ func (m *confirmationManager) HandleUpdate(ctx context.Context, update *telegram
|
|||||||
|
|
||||||
chatID := strconv.FormatInt(message.Chat.ID, 10)
|
chatID := strconv.FormatInt(message.Chat.ID, 10)
|
||||||
if chatID != state.targetChatID {
|
if chatID != state.targetChatID {
|
||||||
m.logDebug("Telegram reply ignored: chat mismatch",
|
m.logInfo("Telegram reply ignored: chat mismatch",
|
||||||
zap.String("request_id", state.request.RequestID),
|
zap.String("request_id", state.request.RequestID),
|
||||||
zap.String("expected_chat_id", state.targetChatID),
|
zap.String("expected_chat_id", state.targetChatID),
|
||||||
zap.String("chat_id", chatID))
|
zap.String("chat_id", chatID))
|
||||||
|
|||||||
@@ -12,7 +12,14 @@ import (
|
|||||||
const telegramWebhookMaxBody = 1 << 20
|
const telegramWebhookMaxBody = 1 << 20
|
||||||
|
|
||||||
func (a *NotificationAPI) handleTelegramWebhook(w http.ResponseWriter, r *http.Request) {
|
func (a *NotificationAPI) handleTelegramWebhook(w http.ResponseWriter, r *http.Request) {
|
||||||
if a == nil || a.confirm == nil {
|
if a == nil {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if a.confirm == nil {
|
||||||
|
if a.logger != nil {
|
||||||
|
a.logger.Warn("Telegram webhook ignored: confirmation manager is not configured")
|
||||||
|
}
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -25,6 +32,26 @@ func (a *NotificationAPI) handleTelegramWebhook(w http.ResponseWriter, r *http.R
|
|||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if a.logger != nil {
|
||||||
|
fields := []zap.Field{
|
||||||
|
zap.Int64("update_id", update.UpdateID),
|
||||||
|
zap.Bool("has_message", update.Message != nil),
|
||||||
|
}
|
||||||
|
if update.Message != nil {
|
||||||
|
fields = append(fields,
|
||||||
|
zap.Int64("message_id", update.Message.MessageID),
|
||||||
|
zap.Int64("chat_id", update.Message.Chat.ID),
|
||||||
|
zap.Int("text_length", len(update.Message.Text)),
|
||||||
|
)
|
||||||
|
if update.Message.From != nil {
|
||||||
|
fields = append(fields, zap.Int64("from_user_id", update.Message.From.ID))
|
||||||
|
}
|
||||||
|
if update.Message.ReplyToMessage != nil {
|
||||||
|
fields = append(fields, zap.Int64("reply_to_message_id", update.Message.ReplyToMessage.MessageID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.logger.Info("Telegram webhook update received", fields...)
|
||||||
|
}
|
||||||
a.confirm.HandleUpdate(r.Context(), &update)
|
a.confirm.HandleUpdate(r.Context(), &update)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user