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)
} else if m.Msgtype == string(message.MsgTypeText) {
m.parseText(data)
} else if m.Msgtype == message.MsgTypeImage {
m.parseText(data)
} else if m.Msgtype == message.MsgTypeImage || m.Msgtype == message.MsgTypeVideo || m.Msgtype == message.MsgTypeVoice {
m.parseMedia(m.Msgtype, data)
}
}
@ -361,14 +361,24 @@ func (m *CustomerMessage) parseText(data map[string]interface{}) error {
return nil
}
func (m *CustomerMessage) parseImage(data map[string]interface{}) error {
image, err := cast.ToStringMapE(data["image"])
func (m *CustomerMessage) parseMedia(msgType string, data map[string]interface{}) error {
media, err := cast.ToStringMapE(data[msgType])
if err != nil {
return err
}
m.Image = &CustomerImage{
MediaId: cast.ToString(image["media_id"]),
if msgType == message.MsgTypeImage {
m.Image = &CustomerImage{
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
}