diff options
-rw-r--r-- | api.go | 50 | ||||
-rw-r--r-- | models.go | 3 |
2 files changed, 52 insertions, 1 deletions
@@ -351,6 +351,9 @@ func (a *Api) bytesToProperUpdate(b []byte) interface{} { case UpdateTypeMessageCreated: upd := UpdateMessageCreated{} _ = json.Unmarshal(b, &upd) + for _, att := range upd.Message.Body.RawAttachments { + upd.Message.Body.Attachments = append(upd.Message.Body.Attachments, a.bytesToProperAttachment(att)) + } return upd case UpdateTypeMessageRemoved: upd := UpdateMessageRemoved{} @@ -359,6 +362,9 @@ func (a *Api) bytesToProperUpdate(b []byte) interface{} { case UpdateTypeMessageEdited: upd := UpdateMessageEdited{} _ = json.Unmarshal(b, &upd) + for _, att := range upd.Message.Body.RawAttachments { + upd.Message.Body.Attachments = append(upd.Message.Body.Attachments, a.bytesToProperAttachment(att)) + } return upd case UpdateTypeMessageRestored: upd := UpdateMessageRestored{} @@ -392,6 +398,50 @@ func (a *Api) bytesToProperUpdate(b []byte) interface{} { return nil } +func (a *Api) bytesToProperAttachment(b []byte) interface{} { + attachment := new(Attachment) + _ = json.Unmarshal(b, attachment) + switch attachment.Type { + case AttachmentAudio: + res := &AudioAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentContact: + res := &ContactAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentFile: + res := &FileAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentImage: + res := &PhotoAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentKeyboard: + res := &InlineKeyboardAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentLocation: + res := &LocationAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentShare: + res := &ShareAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentSticker: + res := &StickerAttachment{} + _ = json.Unmarshal(b, &res) + return res + case AttachmentVideo: + res := &VideoAttachment{} + _ = json.Unmarshal(b, &res) + return res + } + return attachment +} + func (a *Api) getUpdates(limit int, timeout int, marker int64, types []string) (*UpdateList, error) { result := new(UpdateList) values := url.Values{} @@ -387,7 +387,8 @@ type MessageBody struct { // Message text Text string `json:"text"` // Message attachments. Could be one of `Attachment` type. See description of this schema - Attachments []Attachment `json:"attachments"` + RawAttachments []json.RawMessage `json:"attachments"` + Attachments []interface{} // In case this message is repled to, it is the unique identifier of the replied message ReplyTo string `json:"reply_to,omitempty"` } |