From 31ae8271e7ee71e5c42793509e18a2eb06a38b8e Mon Sep 17 00:00:00 2001 From: WangchuXiao Date: Fri, 25 Aug 2023 21:03:14 +0800 Subject: [PATCH] fix: send text message by api doesn't work. (#954) * send msg * send_msg * fix: text * text --- internal/api/msg.go | 10 ++++++++-- pkg/apistruct/msg.go | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index 3d6d4bc5d..ad89742af 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -167,9 +167,15 @@ func (m *MessageApi) DeleteMsgPhysical(c *gin.Context) { func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendMsgReq *msg.SendMsgReq, err error) { var data interface{} + log.ZDebug(c, "getSendMsgReq", "req", req.Content) switch req.ContentType { case constant.Text: - data = apistruct.TextElem{} + text, ok := req.Content["content"].(string) + if !ok { + return nil, errs.ErrArgs.WithDetail("text is not string") + } + data = apistruct.TextContentElem{Content: text} + log.ZDebug(c, "getSendMsgReq", "data", data) case constant.Picture: data = apistruct.PictureElem{} case constant.Voice: @@ -195,7 +201,7 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM if err := mapstructure.WeakDecode(req.Content, &data); err != nil { return nil, err } - log.ZDebug(c, "getSendMsgReq", "data", data) + log.ZDebug(c, "getSendMsgReq", "req", req.Content) if err := m.validate.Struct(data); err != nil { return nil, err } diff --git a/pkg/apistruct/msg.go b/pkg/apistruct/msg.go index a0c5e1429..d31752f38 100644 --- a/pkg/apistruct/msg.go +++ b/pkg/apistruct/msg.go @@ -76,6 +76,10 @@ type TextElem struct { Text string `mapstructure:"text" validate:"required"` } +type TextContentElem struct { + Content string `json:"content" validate:"required"` +} + type RevokeElem struct { RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"` }