diff --git a/message/elements.go b/message/elements.go index 528ca9a3..c369251d 100644 --- a/message/elements.go +++ b/message/elements.go @@ -92,6 +92,10 @@ type ForwardElement struct { ResId string } +type LightAppElement struct { + Content string +} + func NewText(s string) *TextElement { return &TextElement{Content: s} } @@ -161,7 +165,7 @@ func NewUrlShare(url, title, content, image string) *ServiceElement { SubType: "UrlShare", } } -func NewXmlMsg(template string, ResId int64) *ServiceElement { +func NewRichXml(template string, ResId int64) *ServiceElement { if ResId == 0 { ResId = 60 //默认值60 } @@ -172,7 +176,7 @@ func NewXmlMsg(template string, ResId int64) *ServiceElement { } } -func NewJsonMsg(template string) *ServiceElement { +func NewRichJson(template string) *ServiceElement { return &ServiceElement{ Id: 1, Content: template, @@ -180,6 +184,10 @@ func NewJsonMsg(template string) *ServiceElement { } } +func NewLightApp(content string) *LightAppElement { + return &LightAppElement{Content: content} +} + func (e *TextElement) Type() ElementType { return Text } @@ -232,6 +240,10 @@ func (e *ShortVideoElement) Type() ElementType { return Video } +func (e *LightAppElement) Type() ElementType { + return LightApp +} + var faceMap = map[int]string{ 14: "微笑", 1: "撇嘴", diff --git a/message/message.go b/message/message.go index cbca629d..e120a9ab 100644 --- a/message/message.go +++ b/message/message.go @@ -82,6 +82,7 @@ const ( File Voice Video + LightApp ) func (s *Sender) IsAnonymous() bool { @@ -347,21 +348,19 @@ func ToProtoElems(elems []IMessageElement, generalFlags bool) (r []*msg.Elem) { }) continue } - if e.SubType == "json" { - r = append(r, &msg.Elem{ - LightApp: &msg.LightAppElem{ - Data: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), - MsgResid: []byte{1}, - }, - }) - continue - } r = append(r, &msg.Elem{ RichMsg: &msg.RichMsg{ Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), ServiceId: e.Id, }, }) + case *LightAppElement: + r = append(r, &msg.Elem{ + LightApp: &msg.LightAppElem{ + Data: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), + MsgResid: []byte{1}, + }, + }) } } if generalFlags { @@ -459,7 +458,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement { } if content != "" { // TODO: 解析具体的APP - return append(res, NewText(content)) + return append(res, &LightAppElement{Content: content}) } } if elem.VideoFile != nil {