From 936966ac6d6b3d5e760bea4614b3262bdc03c058 Mon Sep 17 00:00:00 2001 From: dmekhov Date: Mon, 4 Mar 2024 21:22:58 +0300 Subject: [PATCH] fix unmarshalling MessageOrigin senderChat info for channels --- types.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/types.go b/types.go index 44cd681..bc7eb0b 100644 --- a/types.go +++ b/types.go @@ -1191,6 +1191,24 @@ func (m MessageOrigin) IsChannel() bool { return m.Type == MessageOriginChannel } +func (m *MessageOrigin) UnmarshalJSON(data []byte) error { + type Alias MessageOrigin + aux := &struct { + Chat *Chat `json:"chat,omitempty"` + *Alias + }{ + Alias: (*Alias)(m), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + if m.IsChannel() { + // MessageOriginChannel struct has Chat struct in chat field and MessageOriginChat in sender_chat + m.SenderChat = aux.Chat + } + return nil +} + // PhotoSize represents one size of a photo or a file / sticker thumbnail. type PhotoSize struct { // FileID identifier for this file, which can be used to download or reuse