parsemedia

This commit is contained in:
jiangyong27 2024-01-24 22:59:28 +08:00
parent f49fff3121
commit bcfab4f3d8
1 changed files with 16 additions and 6 deletions

View File

@ -318,8 +318,8 @@ func (m *CustomerMessage) From(data map[string]interface{}) {
m.parseEvent(data) m.parseEvent(data)
} else if m.Msgtype == string(message.MsgTypeText) { } else if m.Msgtype == string(message.MsgTypeText) {
m.parseText(data) m.parseText(data)
} else if m.Msgtype == message.MsgTypeImage { } else if m.Msgtype == message.MsgTypeImage || m.Msgtype == message.MsgTypeVideo || m.Msgtype == message.MsgTypeVoice {
m.parseText(data) m.parseMedia(m.Msgtype, data)
} }
} }
@ -361,14 +361,24 @@ func (m *CustomerMessage) parseText(data map[string]interface{}) error {
return nil return nil
} }
func (m *CustomerMessage) parseImage(data map[string]interface{}) error { func (m *CustomerMessage) parseMedia(msgType string, data map[string]interface{}) error {
image, err := cast.ToStringMapE(data["image"]) media, err := cast.ToStringMapE(data[msgType])
if err != nil { if err != nil {
return err return err
} }
if msgType == message.MsgTypeImage {
m.Image = &CustomerImage{ m.Image = &CustomerImage{
MediaId: cast.ToString(image["media_id"]), MediaId: cast.ToString(media["media_id"]),
}
} else if msgType == message.MsgTypeVideo {
m.Video = &CustomerVideo{
MediaId: cast.ToString(media["media_id"]),
}
} else if msgType == message.MsgTypeVoice {
m.Voice = &CustomerVoice{
MediaId: cast.ToString(media["media_id"]),
}
} }
return nil return nil
} }