mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-29 13:46:40 +08:00
msg callback
This commit is contained in:
parent
9f80e0a0e6
commit
4d4520226d
@ -10,18 +10,38 @@ import (
|
|||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq {
|
||||||
|
return cbApi.CommonCallbackReq{
|
||||||
|
SendID: msg.MsgData.SendID,
|
||||||
|
ServerMsgID: msg.MsgData.ServerMsgID,
|
||||||
|
ClientMsgID: msg.MsgData.ClientMsgID,
|
||||||
|
OperationID: msg.OperationID,
|
||||||
|
SenderPlatformID: msg.MsgData.SenderPlatformID,
|
||||||
|
SenderNickname: msg.MsgData.SenderNickname,
|
||||||
|
SessionType: msg.MsgData.SessionType,
|
||||||
|
MsgFrom: msg.MsgData.MsgFrom,
|
||||||
|
ContentType: msg.MsgData.ContentType,
|
||||||
|
Status: msg.MsgData.Status,
|
||||||
|
CreateTime: msg.MsgData.CreateTime,
|
||||||
|
Content: string(msg.MsgData.Content),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||||
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable {
|
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
CallbackCommand: constant.CallbackBeforeSendSingleMsgCommand,
|
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand
|
||||||
}}
|
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
||||||
resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{
|
CommonCallbackReq: commonCallbackReq,
|
||||||
}}
|
RecvID: msg.MsgData.RecvID,
|
||||||
utils.CopyStructFields(req, msg.MsgData)
|
}
|
||||||
req.Content = string(msg.MsgData.Content)
|
resp := &cbApi.CallbackBeforeSendSingleMsgResp{
|
||||||
|
CommonCallbackResp: cbApi.CommonCallbackResp{},
|
||||||
|
}
|
||||||
|
//utils.CopyStructFields(req, msg.MsgData)
|
||||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{
|
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{
|
||||||
if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
|
if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
|
||||||
@ -41,10 +61,14 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendSingleMsgCommand}}
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
|
commonCallbackReq.CallbackCommand = constant.CallbackAfterSendSingleMsgCommand
|
||||||
|
req := cbApi.CallbackAfterSendSingleMsgReq{
|
||||||
|
CommonCallbackReq: commonCallbackReq,
|
||||||
|
RecvID: msg.MsgData.RecvID,
|
||||||
|
}
|
||||||
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||||
utils.CopyStructFields(req, msg.MsgData)
|
//utils.CopyStructFields(req, msg.MsgData)
|
||||||
req.Content = string(msg.MsgData.Content)
|
|
||||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{
|
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{
|
||||||
return err
|
return err
|
||||||
@ -58,10 +82,14 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackBeforeSendGroupMsgCommand}}
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
|
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand
|
||||||
|
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
||||||
|
CommonCallbackReq: commonCallbackReq,
|
||||||
|
RecvID: msg.MsgData.RecvID,
|
||||||
|
}
|
||||||
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||||
utils.CopyStructFields(req, msg.MsgData)
|
//utils.CopyStructFields(req, msg.MsgData)
|
||||||
req.Content = string(msg.MsgData.Content)
|
|
||||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
|
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
|
||||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
|
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
|
||||||
@ -80,25 +108,15 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
req := cbApi.CallbackAfterSendGroupMsgReq{
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
CommonCallbackReq: cbApi.CommonCallbackReq{
|
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand
|
||||||
CallbackCommand:constant.CallbackAfterSendGroupMsgCommand,
|
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
||||||
ServerMsgID: msg.MsgData.ServerMsgID,
|
CommonCallbackReq: commonCallbackReq,
|
||||||
ClientMsgID: msg.MsgData.ClientMsgID,
|
RecvID: msg.MsgData.RecvID,
|
||||||
OperationID: msg.OperationID,
|
|
||||||
|
|
||||||
},
|
|
||||||
//GroupMsg: cbApi.GroupMsg{
|
|
||||||
// Msg: cbApi.Msg{
|
|
||||||
// SendID: msg.MsgData.
|
|
||||||
// },
|
|
||||||
// GroupID: msg.MsgData.GroupID,
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||||
|
|
||||||
//utils.CopyStructFields(req, msg.MsgData)
|
//utils.CopyStructFields(req, msg.MsgData)
|
||||||
req.Content = string(msg.MsgData.Content)
|
|
||||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -112,19 +130,11 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
//req := cbApi.CallbackWordFilterReq{
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
// CommonCallbackReq: cbApi.CommonCallbackReq{
|
commonCallbackReq.CallbackCommand = constant.CallbackWordFilterCommand
|
||||||
// CallbackCommand: constant.CallbackWordFilterCommand,
|
|
||||||
// ServerMsgID: msg.MsgData.ServerMsgID,
|
|
||||||
// ClientMsgID: msg.MsgData.ClientMsgID,
|
|
||||||
// OperationID: msg.OperationID,
|
|
||||||
// },
|
|
||||||
// Content: string(msg.MsgData.Content),
|
|
||||||
//}
|
|
||||||
req := cbApi.CallbackWordFilterReq{
|
req := cbApi.CallbackWordFilterReq{
|
||||||
CommonCallbackReq: cbApi.CommonCallbackReq{},
|
CommonCallbackReq: commonCallbackReq,
|
||||||
}
|
}
|
||||||
utils.CopyStructFields(req.CommonCallbackReq, msg.MsgData)
|
|
||||||
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||||
//utils.CopyStructFields(&req., msg.MsgData)
|
//utils.CopyStructFields(&req., msg.MsgData)
|
||||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package call_back_struct
|
package call_back_struct
|
||||||
|
|
||||||
type CommonCallbackReq struct {
|
type CommonCallbackReq struct {
|
||||||
|
SendID string `json:"sendID"`
|
||||||
CallbackCommand string `json:"callbackCommand"`
|
CallbackCommand string `json:"callbackCommand"`
|
||||||
ServerMsgID string `json:"serverID"`
|
ServerMsgID string `json:"serverID"`
|
||||||
ClientMsgID string `json:"clientID"`
|
ClientMsgID string `json:"clientID"`
|
||||||
@ -11,6 +12,8 @@ type CommonCallbackReq struct {
|
|||||||
MsgFrom int32 `json:"MsgFrom"`
|
MsgFrom int32 `json:"MsgFrom"`
|
||||||
ContentType int32 `json:"contentType"`
|
ContentType int32 `json:"contentType"`
|
||||||
Status int32 `json:"status"`
|
Status int32 `json:"status"`
|
||||||
|
CreateTime int64 `json:"createTime"`
|
||||||
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommonCallbackResp struct {
|
type CommonCallbackResp struct {
|
||||||
|
@ -1,53 +1,36 @@
|
|||||||
package call_back_struct
|
package call_back_struct
|
||||||
|
|
||||||
type Msg struct {
|
|
||||||
SendID string `json:"sendID"`
|
|
||||||
CreateTime int64 `json:"createTime"`
|
|
||||||
Content string `json:"content"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SingleMsg struct {
|
|
||||||
Msg
|
|
||||||
RecvID string `json:"recvID"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CallbackBeforeSendSingleMsgReq struct {
|
type CallbackBeforeSendSingleMsgReq struct {
|
||||||
CommonCallbackReq
|
CommonCallbackReq
|
||||||
SingleMsg
|
RecvID string `json:"recvID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackBeforeSendSingleMsgResp struct {
|
type CallbackBeforeSendSingleMsgResp struct {
|
||||||
CommonCallbackResp
|
CommonCallbackResp
|
||||||
SingleMsg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackAfterSendSingleMsgReq struct {
|
type CallbackAfterSendSingleMsgReq struct {
|
||||||
CommonCallbackReq
|
CommonCallbackReq
|
||||||
SingleMsg
|
RecvID string `json:"recvID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackAfterSendSingleMsgResp struct {
|
type CallbackAfterSendSingleMsgResp struct {
|
||||||
CommonCallbackResp
|
CommonCallbackResp
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupMsg struct {
|
|
||||||
Msg
|
|
||||||
GroupID string `json:"groupID"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CallbackBeforeSendGroupMsgReq struct {
|
type CallbackBeforeSendGroupMsgReq struct {
|
||||||
CommonCallbackReq
|
CommonCallbackReq
|
||||||
GroupMsg
|
GroupID string `json:"groupID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackBeforeSendGroupMsgResp struct {
|
type CallbackBeforeSendGroupMsgResp struct {
|
||||||
CommonCallbackResp
|
CommonCallbackResp
|
||||||
GroupMsg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackAfterSendGroupMsgReq struct {
|
type CallbackAfterSendGroupMsgReq struct {
|
||||||
GroupMsg
|
|
||||||
CommonCallbackReq
|
CommonCallbackReq
|
||||||
|
GroupID string `json:"groupID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackAfterSendGroupMsgResp struct {
|
type CallbackAfterSendGroupMsgResp struct {
|
||||||
@ -56,7 +39,6 @@ type CallbackAfterSendGroupMsgResp struct {
|
|||||||
|
|
||||||
type CallbackWordFilterReq struct {
|
type CallbackWordFilterReq struct {
|
||||||
CommonCallbackReq
|
CommonCallbackReq
|
||||||
Content string `json:"content"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallbackWordFilterResp struct {
|
type CallbackWordFilterResp struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user