Skip to content

Commit e5372bb

Browse files
jonnyzzzclaude
andcommitted
fix(telegram): accept unknown fields in Bot API responses
Production deploy revealed that Telegram returns many fields beyond what we model (User.language_code, Chat.title, assorted flags) and the strict DisallowUnknownFields decoder rejected every response. getMe and sendMessage both failed with "unknown field" errors, taking the bot process down on startup. Switch to permissive decoding: we only need the fields we declared, any extras are ignored. Also survives Telegram API version bumps. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a65fcc0 commit e5372bb

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

internal/telegram/bot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,12 @@ func (a *HTTPAPI) call(ctx context.Context, method string, params url.Values, ou
414414
if resp.StatusCode >= 500 {
415415
return fmt.Errorf("telegram %s: HTTP %d", method, resp.StatusCode)
416416
}
417+
// Accept unknown fields: Telegram returns many incidental fields beyond
418+
// what we model (e.g. User.language_code, Chat.title, etc.) and those
419+
// vary across API versions. Strict decoding would break every tiny
420+
// upstream change.
417421
dec := json.NewDecoder(resp.Body)
418-
dec.DisallowUnknownFields()
419422
if err := dec.Decode(out); err != nil {
420-
// Re-read body for error context is awkward; report the decoder error.
421423
if errors.Is(err, io.EOF) {
422424
return fmt.Errorf("telegram %s: empty body (HTTP %d)", method, resp.StatusCode)
423425
}

0 commit comments

Comments
 (0)