mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
feat: Sending messages supports returning fields modified by webhook
This commit is contained in:
@@ -17,9 +17,11 @@ package msg
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/apistruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/openimsdk/tools/utils/stringutil"
|
||||
|
||||
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
@@ -136,11 +138,11 @@ func (m *msgServer) webhookAfterSendGroupMsg(ctx context.Context, after *config.
|
||||
m.webhookClient.AsyncPostWithQuery(ctx, cbReq.GetCallbackCommand(), cbReq, &cbapi.CallbackAfterSendGroupMsgResp{}, after, buildKeyMsgDataQuery(msg.MsgData))
|
||||
}
|
||||
|
||||
func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error {
|
||||
func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq, beforeMsgData **sdkws.MsgData) error {
|
||||
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||
if msg.MsgData.ContentType != constant.Text {
|
||||
return nil
|
||||
}
|
||||
//if msg.MsgData.ContentType != constant.Text {
|
||||
// return nil
|
||||
//}
|
||||
if !filterBeforeMsg(msg, before) {
|
||||
return nil
|
||||
}
|
||||
@@ -151,9 +153,14 @@ func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.B
|
||||
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if beforeMsgData != nil {
|
||||
*beforeMsgData = proto.Clone(msg.MsgData).(*sdkws.MsgData)
|
||||
}
|
||||
if resp.Content != nil {
|
||||
msg.MsgData.Content = []byte(*resp.Content)
|
||||
if err := json.Unmarshal(msg.MsgData.Content, &struct{}{}); err != nil {
|
||||
return errs.ErrArgs.WrapMsg("webhook msg modify content is not json", "content", string(msg.MsgData.Content))
|
||||
}
|
||||
}
|
||||
datautil.NotNilReplace(msg.MsgData.OfflinePushInfo, resp.OfflinePushInfo)
|
||||
datautil.NotNilReplace(&msg.MsgData.RecvID, resp.RecvID)
|
||||
|
||||
Reference in New Issue
Block a user