add callback

This commit is contained in:
wangchuxiao 2022-03-03 14:18:28 +08:00
parent 60e29cc894
commit f1c11ac114
3 changed files with 13 additions and 12 deletions

View File

@ -202,7 +202,6 @@ callback:
callbackAfterSendSingleMsg:
enable: true
callbackTimeOut: 5
CallbackFailedContinue: true
callbackBeforeSendGroupMsg:
enable: true
callbackTimeOut: 5
@ -210,7 +209,6 @@ callback:
callbackAfterSendGroupMsg:
enable: true
callbackTimeOut: 5
CallbackFailedContinue: true
callbackWordFilter:
enable: true
callbackTimeOut: 5

View File

@ -62,9 +62,10 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
return false, nil
}
}
if resp.ActionCode == constant.ActionForbidden {
return false, nil
} else {
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
}
return true, nil
}
@ -94,15 +95,17 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
utils.CopyStructFields(&req, msg.MsgData)
req.Content = string(msg.MsgData.Content)
if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
return false, err
}
} else {
msg.MsgData.Content = []byte(resp.Content)
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
}
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
msg.MsgData.Content = resp.Content
return true, nil
}

View File

@ -5,7 +5,7 @@ type msg struct {
ClientMsgID string `json:"clientMsgID"`
ServerMsgID string `json:"serverMsgId"`
CreateTime int64 `json:"createTime"`
Content []byte `json:"content"`
Content string `json:"content"`
}
type singleMsg struct {
@ -58,10 +58,10 @@ type CallbackAfterSendGroupMsgResp struct {
type CallbackWordFilterReq struct {
CommonCallbackReq
Content []byte `json:"content"`
Content string `json:"content"`
}
type CallbackWordFilterResp struct {
CommonCallbackResp
Content []byte `json:"content"`
Content string `json:"content"`
}