mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
add callback
This commit is contained in:
parent
48f03f306a
commit
d13a6b0c36
@ -193,7 +193,7 @@ iospush:
|
||||
badgeCount: true
|
||||
|
||||
callback:
|
||||
callbackUrl : "http://xxx.com"
|
||||
callbackUrl : "http://127.0.0.1:8070"
|
||||
# 开启关闭操作前后回调的配置
|
||||
callbackbeforeSendSingleMsg:
|
||||
enable: true # 回调是否启用
|
||||
|
@ -21,13 +21,15 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro
|
||||
}}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
|
||||
utils.CopyStructFields(req, msg.MsgData)
|
||||
req.Content = string(msg.MsgData.Content)
|
||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{
|
||||
if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
} else {
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
@ -42,6 +44,7 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
|
||||
resp := &cbApi.CallbackAfterSendSingleMsgResp{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(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{
|
||||
return err
|
||||
}
|
||||
@ -58,6 +61,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
|
||||
resp := &cbApi.CallbackBeforeSendGroupMsgResp{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(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
|
||||
return false, nil
|
||||
@ -79,6 +83,7 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
|
||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{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(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -101,10 +106,10 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
return false, err
|
||||
}
|
||||
} else {
|
||||
msg.MsgData.Content = []byte(resp.Content)
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
}
|
||||
msg.MsgData.Content = []byte(resp.Content)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
@ -126,14 +126,14 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
}
|
||||
|
||||
// callback
|
||||
//canSend, err := callBackWordFilter(pb)
|
||||
//if err != nil {
|
||||
// log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
|
||||
//}
|
||||
//if !canSend {
|
||||
// log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData)
|
||||
// return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
||||
//}
|
||||
canSend, err := callBackWordFilter(pb)
|
||||
if err != nil {
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
|
||||
}
|
||||
if !canSend {
|
||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData)
|
||||
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
||||
}
|
||||
switch pb.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
canSend, err := callbackBeforeSendSingleMsg(pb)
|
||||
|
Loading…
x
Reference in New Issue
Block a user