callback update

This commit is contained in:
wangchuxiao
2022-10-21 15:44:55 +08:00
parent 942afd7fec
commit 16b3ea8b7e
13 changed files with 220 additions and 44 deletions
+67 -13
View File
@@ -47,7 +47,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackRes
RecvID: msg.MsgData.RecvID,
}
resp := &cbApi.CallbackBeforeSendSingleMsgResp{
CommonCallbackResp: &callbackResp,
CommonCallbackResp: callbackResp,
}
//utils.CopyStructFields(req, msg.MsgData)
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
@@ -77,7 +77,7 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
CommonCallbackReq: commonCallbackReq,
RecvID: msg.MsgData.RecvID,
}
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: &callbackResp}
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: callbackResp}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
@@ -99,7 +99,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
CommonCallbackReq: commonCallbackReq,
GroupID: msg.MsgData.GroupID,
}
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: &callbackResp}
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: callbackResp}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
@@ -127,7 +127,7 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
CommonCallbackReq: commonCallbackReq,
GroupID: msg.MsgData.GroupID,
}
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: &callbackResp}
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: callbackResp}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
@@ -137,23 +137,23 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp
return callbackResp
}
func callbackWordFilter(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
func callbackMsgModify(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
callbackResp := cbApi.CommonCallbackResp{OperationID: msg.OperationID}
if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text {
if !config.Config.Callback.CallbackMsgModify.Enable || msg.MsgData.ContentType != constant.Text {
return callbackResp
}
commonCallbackReq := copyCallbackCommonReqStruct(msg)
commonCallbackReq.CallbackCommand = constant.CallbackWordFilterCommand
req := cbApi.CallbackWordFilterReq{
commonCallbackReq.CallbackCommand = constant.CallbackMsgModifyCommand
req := cbApi.CallbackMsgModifyCommandReq{
CommonCallbackReq: commonCallbackReq,
}
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: &callbackResp}
resp := &cbApi.CallbackMsgModifyCommandResp{CommonCallbackResp: callbackResp}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackWordFilterCommand, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackMsgModifyCommand, req, resp, config.Config.Callback.CallbackMsgModify.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
if !config.Config.Callback.CallbackMsgModify.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
@@ -161,8 +161,62 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp {
return callbackResp
}
}
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow && resp.Content != "" {
msg.MsgData.Content = []byte(resp.Content)
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
if resp.Content != nil {
msg.MsgData.Content = []byte(*resp.Content)
}
if resp.RecvID != nil {
msg.MsgData.RecvID = *resp.RecvID
}
if resp.GroupID != nil {
msg.MsgData.GroupID = *resp.GroupID
}
if resp.ClientMsgID != nil {
msg.MsgData.ClientMsgID = *resp.ClientMsgID
}
if resp.ServerMsgID != nil {
msg.MsgData.ServerMsgID = *resp.ServerMsgID
}
if resp.SenderPlatformID != nil {
msg.MsgData.SenderPlatformID = *resp.SenderPlatformID
}
if resp.SenderNickname != nil {
msg.MsgData.SenderNickname = *resp.SenderNickname
}
if resp.SenderFaceURL != nil {
msg.MsgData.SenderFaceURL = *resp.SenderFaceURL
}
if resp.SessionType != nil {
msg.MsgData.SessionType = *resp.SessionType
}
if resp.MsgFrom != nil {
msg.MsgData.MsgFrom = *resp.MsgFrom
}
if resp.ContentType != nil {
msg.MsgData.ContentType = *resp.ContentType
}
if resp.Status != nil {
msg.MsgData.Status = *resp.Status
}
if resp.Options != nil {
msg.MsgData.Options = *resp.Options
}
if resp.OfflinePushInfo != nil {
msg.MsgData.OfflinePushInfo = resp.OfflinePushInfo
}
if resp.AtUserIDList != nil {
msg.MsgData.AtUserIDList = *resp.AtUserIDList
}
if resp.MsgDataList != nil {
msg.MsgData.MsgDataList = *resp.MsgDataList
}
if resp.AttachedInfo != nil {
msg.MsgData.AttachedInfo = *resp.AttachedInfo
}
if resp.Ex != nil {
msg.MsgData.Ex = *resp.Ex
}
}
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content))
return callbackResp