msg callback

This commit is contained in:
wangchuxiao 2022-03-03 18:49:36 +08:00
parent 9f80e0a0e6
commit 4d4520226d
3 changed files with 56 additions and 61 deletions

View File

@ -10,18 +10,38 @@ import (
"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) {
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable {
return true, nil
}
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{
CallbackCommand: constant.CallbackBeforeSendSingleMsgCommand,
}}
resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{
}}
utils.CopyStructFields(req, msg.MsgData)
req.Content = string(msg.MsgData.Content)
commonCallbackReq := copyCallbackCommonReqStruct(msg)
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand
req := cbApi.CallbackBeforeSendSingleMsgReq{
CommonCallbackReq: commonCallbackReq,
RecvID: msg.MsgData.RecvID,
}
resp := &cbApi.CallbackBeforeSendSingleMsgResp{
CommonCallbackResp: cbApi.CommonCallbackResp{},
}
//utils.CopyStructFields(req, msg.MsgData)
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 !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
@ -41,10 +61,14 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
return nil
}
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{}}
utils.CopyStructFields(req, msg.MsgData)
req.Content = string(msg.MsgData.Content)
//utils.CopyStructFields(req, msg.MsgData)
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{
return err
@ -58,10 +82,14 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
return true, nil
}
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{}}
utils.CopyStructFields(req, msg.MsgData)
req.Content = string(msg.MsgData.Content)
//utils.CopyStructFields(req, msg.MsgData)
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 !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
@ -80,25 +108,15 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
return nil
}
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
req := cbApi.CallbackAfterSendGroupMsgReq{
CommonCallbackReq: cbApi.CommonCallbackReq{
CallbackCommand:constant.CallbackAfterSendGroupMsgCommand,
ServerMsgID: msg.MsgData.ServerMsgID,
ClientMsgID: msg.MsgData.ClientMsgID,
OperationID: msg.OperationID,
},
//GroupMsg: cbApi.GroupMsg{
// Msg: cbApi.Msg{
// SendID: msg.MsgData.
// },
// GroupID: msg.MsgData.GroupID,
//}
commonCallbackReq := copyCallbackCommonReqStruct(msg)
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand
req := cbApi.CallbackBeforeSendSingleMsgReq{
CommonCallbackReq: commonCallbackReq,
RecvID: msg.MsgData.RecvID,
}
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
//utils.CopyStructFields(req, msg.MsgData)
req.Content = string(msg.MsgData.Content)
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 {
return err
@ -112,19 +130,11 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
return true, nil
}
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
//req := cbApi.CallbackWordFilterReq{
// CommonCallbackReq: cbApi.CommonCallbackReq{
// CallbackCommand: constant.CallbackWordFilterCommand,
// ServerMsgID: msg.MsgData.ServerMsgID,
// ClientMsgID: msg.MsgData.ClientMsgID,
// OperationID: msg.OperationID,
// },
// Content: string(msg.MsgData.Content),
//}
commonCallbackReq := copyCallbackCommonReqStruct(msg)
commonCallbackReq.CallbackCommand = constant.CallbackWordFilterCommand
req := cbApi.CallbackWordFilterReq{
CommonCallbackReq: cbApi.CommonCallbackReq{},
CommonCallbackReq: commonCallbackReq,
}
utils.CopyStructFields(req.CommonCallbackReq, msg.MsgData)
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
//utils.CopyStructFields(&req., msg.MsgData)
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)

View File

@ -1,6 +1,7 @@
package call_back_struct
type CommonCallbackReq struct {
SendID string `json:"sendID"`
CallbackCommand string `json:"callbackCommand"`
ServerMsgID string `json:"serverID"`
ClientMsgID string `json:"clientID"`
@ -11,6 +12,8 @@ type CommonCallbackReq struct {
MsgFrom int32 `json:"MsgFrom"`
ContentType int32 `json:"contentType"`
Status int32 `json:"status"`
CreateTime int64 `json:"createTime"`
Content string `json:"content"`
}
type CommonCallbackResp struct {

View File

@ -1,53 +1,36 @@
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 {
CommonCallbackReq
SingleMsg
RecvID string `json:"recvID"`
}
type CallbackBeforeSendSingleMsgResp struct {
CommonCallbackResp
SingleMsg
}
type CallbackAfterSendSingleMsgReq struct {
CommonCallbackReq
SingleMsg
RecvID string `json:"recvID"`
}
type CallbackAfterSendSingleMsgResp struct {
CommonCallbackResp
}
type GroupMsg struct {
Msg
GroupID string `json:"groupID"`
}
type CallbackBeforeSendGroupMsgReq struct {
CommonCallbackReq
GroupMsg
GroupID string `json:"groupID"`
}
type CallbackBeforeSendGroupMsgResp struct {
CommonCallbackResp
GroupMsg
}
type CallbackAfterSendGroupMsgReq struct {
GroupMsg
CommonCallbackReq
GroupID string `json:"groupID"`
}
type CallbackAfterSendGroupMsgResp struct {
@ -56,7 +39,6 @@ type CallbackAfterSendGroupMsgResp struct {
type CallbackWordFilterReq struct {
CommonCallbackReq
Content string `json:"content"`
}
type CallbackWordFilterResp struct {