feat: Implement webhook in createConversation (#3228)
* update test method args. * feat: implement createConversations webhook function. * improve webhookCreateConversations Implement * implement createconversation webhook. * remove unused paramaters.pull/3239/head
parent
0b9dbd301c
commit
b969827b9a
@ -0,0 +1,117 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
dbModel "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
func (c *conversationServer) webhookBeforeCreateSingleChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error {
|
||||
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||
cbReq := &callbackstruct.CallbackBeforeCreateSingleChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackBeforeCreateSingleChatConversationsCommand,
|
||||
OwnerUserID: req.OwnerUserID,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
UserID: req.UserID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
resp := &callbackstruct.CallbackBeforeCreateSingleChatConversationsResp{}
|
||||
|
||||
if err := c.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt)
|
||||
datautil.NotNilReplace(&req.IsPinned, resp.IsPinned)
|
||||
datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat)
|
||||
datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration)
|
||||
datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType)
|
||||
datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo)
|
||||
datautil.NotNilReplace(&req.Ex, resp.Ex)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookAfterCreateSingleChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error {
|
||||
cbReq := &callbackstruct.CallbackAfterCreateSingleChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackAfterCreateSingleChatConversationsCommand,
|
||||
OwnerUserID: req.OwnerUserID,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
UserID: req.UserID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateSingleChatConversationsResp{}, after)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookBeforeCreateGroupChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error {
|
||||
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||
cbReq := &callbackstruct.CallbackBeforeCreateGroupChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackBeforeCreateGroupChatConversationsCommand,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
GroupID: req.GroupID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
resp := &callbackstruct.CallbackBeforeCreateGroupChatConversationsResp{}
|
||||
|
||||
if err := c.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt)
|
||||
datautil.NotNilReplace(&req.IsPinned, resp.IsPinned)
|
||||
datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat)
|
||||
datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration)
|
||||
datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType)
|
||||
datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo)
|
||||
datautil.NotNilReplace(&req.Ex, resp.Ex)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *conversationServer) webhookAfterCreateGroupChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error {
|
||||
cbReq := &callbackstruct.CallbackAfterCreateGroupChatConversationsReq{
|
||||
CallbackCommand: callbackstruct.CallbackAfterCreateGroupChatConversationsCommand,
|
||||
ConversationID: req.ConversationID,
|
||||
ConversationType: req.ConversationType,
|
||||
GroupID: req.GroupID,
|
||||
RecvMsgOpt: req.RecvMsgOpt,
|
||||
IsPinned: req.IsPinned,
|
||||
IsPrivateChat: req.IsPrivateChat,
|
||||
BurnDuration: req.BurnDuration,
|
||||
GroupAtType: req.GroupAtType,
|
||||
AttachedInfo: req.AttachedInfo,
|
||||
Ex: req.Ex,
|
||||
}
|
||||
|
||||
c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateGroupChatConversationsResp{}, after)
|
||||
return nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package callbackstruct
|
||||
|
||||
type CallbackBeforeCreateSingleChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
UserID string `json:"user_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateSingleChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
RecvMsgOpt *int32 `json:"recv_msg_opt"`
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
IsPrivateChat *bool `json:"is_private_chat"`
|
||||
BurnDuration *int32 `json:"burn_duration"`
|
||||
GroupAtType *int32 `json:"group_at_type"`
|
||||
AttachedInfo *string `json:"attached_info"`
|
||||
Ex *string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateSingleChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
UserID string `json:"user_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateSingleChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateGroupChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackBeforeCreateGroupChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
RecvMsgOpt *int32 `json:"recv_msg_opt"`
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
IsPrivateChat *bool `json:"is_private_chat"`
|
||||
BurnDuration *int32 `json:"burn_duration"`
|
||||
GroupAtType *int32 `json:"group_at_type"`
|
||||
AttachedInfo *string `json:"attached_info"`
|
||||
Ex *string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateGroupChatConversationsReq struct {
|
||||
CallbackCommand `json:"callbackCommand"`
|
||||
OwnerUserID string `json:"owner_user_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ConversationType int32 `json:"conversation_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
RecvMsgOpt int32 `json:"recv_msg_opt"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsPrivateChat bool `json:"is_private_chat"`
|
||||
BurnDuration int32 `json:"burn_duration"`
|
||||
GroupAtType int32 `json:"group_at_type"`
|
||||
AttachedInfo string `json:"attached_info"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type CallbackAfterCreateGroupChatConversationsResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
Loading…
Reference in new issue