aboutsummaryrefslogtreecommitdiff
path: root/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'api.go')
-rw-r--r--api.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/api.go b/api.go
index f3bc90e..3d727fd 100644
--- a/api.go
+++ b/api.go
@@ -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{}