diff --git a/internal/api/msg.go b/internal/api/msg.go index 3d6d4bc5d..acc4e0a2f 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -15,6 +15,8 @@ package api import ( + "encoding/json" + "github.com/OpenIMSDK/tools/mcontext" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" @@ -167,9 +169,18 @@ 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["text"].(string) + if !ok { + return nil, errs.ErrArgs.WithDetail("text is not string") + } + bytes, err := json.Marshal(apistruct.TextContentElem{Content: text}) + if err != nil { + return nil, errs.ErrArgs.WithDetail(err.Error()) + } + data = apistruct.TextElem{Text: string(bytes)} case constant.Picture: data = apistruct.PictureElem{} case constant.Voice: 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"` }