mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-08 12:56:58 +08:00
feat: add SendBusinessNotification api
This commit is contained in:
parent
7d6788f3ec
commit
db73f09cbf
@ -16,6 +16,8 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||||
|
"github.com/OpenIMSDK/tools/mcontext"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@ -234,6 +236,51 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
|
|||||||
apiresp.GinSuccess(c, respPb)
|
apiresp.GinSuccess(c, respPb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
|
||||||
|
req := struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
SendUserID string `json:"sendUserID"`
|
||||||
|
RecvUserID string `json:"recvUserID"`
|
||||||
|
}{}
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !authverify.IsAppManagerUid(c) {
|
||||||
|
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendMsgReq := msg.SendMsgReq{
|
||||||
|
MsgData: &sdkws.MsgData{
|
||||||
|
SendID: req.SendUserID,
|
||||||
|
RecvID: req.RecvUserID,
|
||||||
|
Content: []byte(utils.StructToJsonString(&sdkws.NotificationElem{
|
||||||
|
Detail: utils.StructToJsonString(&struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
}{Key: req.Key, Data: req.Data}),
|
||||||
|
})),
|
||||||
|
MsgFrom: constant.SysMsgType,
|
||||||
|
ContentType: constant.BusinessNotification,
|
||||||
|
SessionType: constant.SingleChatType,
|
||||||
|
CreateTime: utils.GetCurrentTimestampByMill(),
|
||||||
|
ClientMsgID: utils.GetMsgID(mcontext.GetOpUserID(c)),
|
||||||
|
Options: config.GetOptionsByNotification(config.NotificationConf{
|
||||||
|
IsSendMsg: false,
|
||||||
|
ReliabilityLevel: 1,
|
||||||
|
UnreadCount: false,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
respPb, err := m.Client.SendMsg(c, &sendMsgReq)
|
||||||
|
if err != nil {
|
||||||
|
apiresp.GinError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiresp.GinSuccess(c, respPb)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
req apistruct.BatchSendMsgReq
|
req apistruct.BatchSendMsgReq
|
||||||
|
|||||||
@ -167,6 +167,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
|||||||
msgGroup.POST("/newest_seq", m.GetSeq)
|
msgGroup.POST("/newest_seq", m.GetSeq)
|
||||||
msgGroup.POST("/search_msg", m.SearchMsg)
|
msgGroup.POST("/search_msg", m.SearchMsg)
|
||||||
msgGroup.POST("/send_msg", m.SendMessage)
|
msgGroup.POST("/send_msg", m.SendMessage)
|
||||||
|
msgGroup.POST("/send_business_notification", m.SendBusinessNotification)
|
||||||
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
|
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
|
||||||
msgGroup.POST("/revoke_msg", m.RevokeMsg)
|
msgGroup.POST("/revoke_msg", m.RevokeMsg)
|
||||||
msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)
|
msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user