mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 19:50:07 +08:00
add callback
This commit is contained in:
parent
399d0b94d5
commit
bcae7720e1
@ -102,7 +102,7 @@ func main() {
|
|||||||
conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt) //1
|
conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt) //1
|
||||||
conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt) //1
|
conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt) //1
|
||||||
}
|
}
|
||||||
|
apiThird.MinioInit()
|
||||||
log.NewPrivateLog("api")
|
log.NewPrivateLog("api")
|
||||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -91,8 +91,8 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申
|
|||||||
bucket: openim
|
bucket: openim
|
||||||
location: us-east-1
|
location: us-east-1
|
||||||
endpoint: http://127.0.0.1:9000
|
endpoint: http://127.0.0.1:9000
|
||||||
accessKeyID: minioadmin
|
accessKeyID: user12345
|
||||||
secretAccessKey: minioadmin
|
secretAccessKey: key12345
|
||||||
|
|
||||||
|
|
||||||
rpcport: #rpc服务端口 默认即可
|
rpcport: #rpc服务端口 默认即可
|
||||||
@ -196,21 +196,21 @@ callback:
|
|||||||
callbackUrl : "http://127.0.0.1:8080/callback"
|
callbackUrl : "http://127.0.0.1:8080/callback"
|
||||||
# 开启关闭操作前后回调的配置
|
# 开启关闭操作前后回调的配置
|
||||||
callbackbeforeSendSingleMsg:
|
callbackbeforeSendSingleMsg:
|
||||||
enable: false # 回调是否启用
|
enable: true # 回调是否启用
|
||||||
callbackTimeOut: 2 # 回调超时时间
|
callbackTimeOut: 2 # 回调超时时间
|
||||||
CallbackFailedContinue: true # 回调超时是否继续执行代码
|
CallbackFailedContinue: true # 回调超时是否继续执行代码
|
||||||
callbackAfterSendSingleMsg:
|
callbackAfterSendSingleMsg:
|
||||||
enable: false
|
enable: true
|
||||||
callbackTimeOut: 2
|
callbackTimeOut: 2
|
||||||
callbackBeforeSendGroupMsg:
|
callbackBeforeSendGroupMsg:
|
||||||
enable: false
|
enable: true
|
||||||
callbackTimeOut: 2
|
callbackTimeOut: 2
|
||||||
CallbackFailedContinue: true
|
CallbackFailedContinue: true
|
||||||
callbackAfterSendGroupMsg:
|
callbackAfterSendGroupMsg:
|
||||||
enable: false
|
enable: true
|
||||||
callbackTimeOut: 2
|
callbackTimeOut: 2
|
||||||
callbackWordFilter:
|
callbackWordFilter:
|
||||||
enable: false
|
enable: true
|
||||||
callbackTimeOut: 2
|
callbackTimeOut: 2
|
||||||
CallbackFailedContinue: true
|
CallbackFailedContinue: true
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
url2 "net/url"
|
url2 "net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func MinioInit() {
|
||||||
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||||
|
@ -113,10 +113,10 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
|
|||||||
}
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||||
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand
|
commonCallbackReq.CallbackCommand = constant.CallbackAfterSendGroupMsgCommand
|
||||||
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
req := cbApi.CallbackAfterSendGroupMsgReq{
|
||||||
CommonCallbackReq: commonCallbackReq,
|
CommonCallbackReq: commonCallbackReq,
|
||||||
RecvID: msg.MsgData.RecvID,
|
GroupID: msg.MsgData.GroupID,
|
||||||
}
|
}
|
||||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||||
|
|
||||||
@ -152,7 +152,9 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
|||||||
if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess {
|
if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
msg.MsgData.Content = []byte(resp.Content)
|
if resp.ErrCode == constant.CallbackHandleSuccess {
|
||||||
|
msg.MsgData.Content = []byte(resp.Content)
|
||||||
|
}
|
||||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content))
|
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content))
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -128,21 +128,22 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|||||||
// callback
|
// callback
|
||||||
canSend, err := callbackWordFilter(pb)
|
canSend, err := callbackWordFilter(pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackWordFilter failed", err.Error(), pb.MsgData)
|
||||||
}
|
}
|
||||||
if !canSend {
|
if !canSend {
|
||||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData)
|
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackWordFilter result", canSend, "end rpc and return", pb.MsgData)
|
||||||
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
return returnMsg(&replay, pb, 201, "callbackWordFilter result stop rpc and return", "", 0)
|
||||||
}
|
}
|
||||||
switch pb.MsgData.SessionType {
|
switch pb.MsgData.SessionType {
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
|
// callback
|
||||||
canSend, err := callbackBeforeSendSingleMsg(pb)
|
canSend, err := callbackBeforeSendSingleMsg(pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
if !canSend {
|
if !canSend {
|
||||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return")
|
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", canSend, "end rpc and return")
|
||||||
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
return returnMsg(&replay, pb, 201, "callbackBeforeSendSingleMsg result stop rpc and return", "", 0)
|
||||||
}
|
}
|
||||||
isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb)
|
isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb)
|
||||||
if isSend {
|
if isSend {
|
||||||
@ -161,18 +162,20 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|||||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// callback
|
||||||
if err := callbackAfterSendSingleMsg(pb); err != nil {
|
if err := callbackAfterSendSingleMsg(pb); err != nil {
|
||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendSingleMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||||
case constant.GroupChatType:
|
case constant.GroupChatType:
|
||||||
|
// callback
|
||||||
canSend, err := callbackBeforeSendGroupMsg(pb)
|
canSend, err := callbackBeforeSendGroupMsg(pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendGroupMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
if !canSend {
|
if !canSend {
|
||||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return")
|
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendGroupMsg result", canSend, "end rpc and return")
|
||||||
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
return returnMsg(&replay, pb, 201, "callbackBeforeSendGroupMsg result stop rpc and return", "", 0)
|
||||||
}
|
}
|
||||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
client := pbGroup.NewGroupClient(etcdConn)
|
client := pbGroup.NewGroupClient(etcdConn)
|
||||||
@ -237,8 +240,8 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|||||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// callback
|
||||||
if err := callbackAfterSendGroupMsg(pb); err != nil {
|
if err := callbackAfterSendGroupMsg(pb); err != nil {
|
||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,13 @@ package call_back_struct
|
|||||||
type CommonCallbackReq struct {
|
type CommonCallbackReq struct {
|
||||||
SendID string `json:"sendID"`
|
SendID string `json:"sendID"`
|
||||||
CallbackCommand string `json:"callbackCommand"`
|
CallbackCommand string `json:"callbackCommand"`
|
||||||
ServerMsgID string `json:"serverID"`
|
ServerMsgID string `json:"serverMsgID"`
|
||||||
ClientMsgID string `json:"clientID"`
|
ClientMsgID string `json:"clientMsgID"`
|
||||||
OperationID string `json:"operationID"`
|
OperationID string `json:"operationID"`
|
||||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||||
SenderNickname string `json:"senderNickname"`
|
SenderNickname string `json:"senderNickname"`
|
||||||
SessionType int32 `json:"sessionType"`
|
SessionType int32 `json:"sessionType"`
|
||||||
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"`
|
CreateTime int64 `json:"createTime"`
|
||||||
|
@ -138,15 +138,15 @@ const (
|
|||||||
VerificationCodeForResetSuffix = "_forReset"
|
VerificationCodeForResetSuffix = "_forReset"
|
||||||
|
|
||||||
//callbackCommand
|
//callbackCommand
|
||||||
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsg"
|
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"
|
||||||
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsg"
|
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand"
|
||||||
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsg"
|
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand"
|
||||||
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
||||||
CallbackWordFilterCommand = "callbackWordFilterCommand"
|
CallbackWordFilterCommand = "callbackWordFilterCommand"
|
||||||
//actionCode
|
//callback actionCode
|
||||||
ActionAllow = 0
|
ActionAllow = 0
|
||||||
ActionForbidden = 1
|
ActionForbidden = 1
|
||||||
//callbackHandleCode
|
//callback callbackHandleCode
|
||||||
CallbackHandleSuccess = 0
|
CallbackHandleSuccess = 0
|
||||||
CallbackHandleFailed = 1
|
CallbackHandleFailed = 1
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user