mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 14:29:19 +08:00
feat: Change after webhook filter && feat SendSimpleMsg (#3151)
* feat: msg filter and search system account * feat: search system account * chore: msg * chore: msg * chore: msg * chore: webhook filter && sendSimpleMessage
This commit is contained in:
@@ -111,6 +111,21 @@ type BatchSendMsgResp struct {
|
||||
FailedIDs []string `json:"failedUserIDs"`
|
||||
}
|
||||
|
||||
// SendSingleMsgReq defines the structure for sending a message to multiple recipients.
|
||||
type SendSingleMsgReq struct {
|
||||
// groupMsg should appoint sendID
|
||||
SendID string `json:"sendID"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type KeyMsgData struct {
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
GroupID string `json:"groupID"`
|
||||
}
|
||||
|
||||
// SingleReturnResult encapsulates the result of a single message send attempt.
|
||||
type SingleReturnResult struct {
|
||||
// ServerMsgID is the message identifier on the server-side.
|
||||
|
||||
@@ -334,19 +334,17 @@ type Redis struct {
|
||||
}
|
||||
|
||||
type BeforeConfig struct {
|
||||
Enable bool `yaml:"enable"`
|
||||
Timeout int `yaml:"timeout"`
|
||||
FailedContinue bool `yaml:"failedContinue"`
|
||||
AllowedTypes []string `yaml:"allowedTypes"`
|
||||
DeniedTypes []string `yaml:"deniedTypes"`
|
||||
Enable bool `yaml:"enable"`
|
||||
Timeout int `yaml:"timeout"`
|
||||
FailedContinue bool `yaml:"failedContinue"`
|
||||
DeniedTypes []int32 `yaml:"deniedTypes"`
|
||||
}
|
||||
|
||||
type AfterConfig struct {
|
||||
Enable bool `yaml:"enable"`
|
||||
Timeout int `yaml:"timeout"`
|
||||
AttentionIds []string `yaml:"attentionIds"`
|
||||
AllowedTypes []string `yaml:"allowedTypes"`
|
||||
DeniedTypes []string `yaml:"deniedTypes"`
|
||||
DeniedTypes []int32 `yaml:"deniedTypes"`
|
||||
}
|
||||
|
||||
type Share struct {
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/tools/db/pagination"
|
||||
"github.com/openimsdk/tools/db/tx"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
@@ -37,8 +38,10 @@ type UserDatabase interface {
|
||||
Find(ctx context.Context, userIDs []string) (users []*model.User, err error)
|
||||
// Find userInfo By Nickname
|
||||
FindByNickname(ctx context.Context, nickname string) (users []*model.User, err error)
|
||||
// Find notificationAccounts
|
||||
// FindNotification find system account by level
|
||||
FindNotification(ctx context.Context, level int64) (users []*model.User, err error)
|
||||
// FindSystemAccount find all system account
|
||||
FindSystemAccount(ctx context.Context) (users []*model.User, err error)
|
||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the storage
|
||||
Create(ctx context.Context, users []*model.User) (err error)
|
||||
// UpdateByMap update (zero value) external guarantee userID exists
|
||||
@@ -139,6 +142,10 @@ func (u *userDatabase) FindNotification(ctx context.Context, level int64) (users
|
||||
return u.userDB.TakeNotification(ctx, level)
|
||||
}
|
||||
|
||||
func (u *userDatabase) FindSystemAccount(ctx context.Context) (users []*model.User, err error) {
|
||||
return u.userDB.TakeGTEAppManagerLevel(ctx, constant.AppNotificationAdmin)
|
||||
}
|
||||
|
||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the storage.
|
||||
func (u *userDatabase) Create(ctx context.Context, users []*model.User) (err error) {
|
||||
return u.tx.Transaction(ctx, func(ctx context.Context) error {
|
||||
|
||||
@@ -16,9 +16,10 @@ package mgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/db/mongoutil"
|
||||
@@ -71,6 +72,10 @@ func (u *UserMgo) TakeNotification(ctx context.Context, level int64) (user []*mo
|
||||
return mongoutil.Find[*model.User](ctx, u.coll, bson.M{"app_manger_level": level})
|
||||
}
|
||||
|
||||
func (u *UserMgo) TakeGTEAppManagerLevel(ctx context.Context, level int64) (user []*model.User, err error) {
|
||||
return mongoutil.Find[*model.User](ctx, u.coll, bson.M{"app_manager_level": bson.M{"$gte": level}})
|
||||
}
|
||||
|
||||
func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*model.User, err error) {
|
||||
return mongoutil.Find[*model.User](ctx, u.coll, bson.M{"nickname": nickname})
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/db/pagination"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User interface {
|
||||
@@ -28,6 +29,7 @@ type User interface {
|
||||
Find(ctx context.Context, userIDs []string) (users []*model.User, err error)
|
||||
Take(ctx context.Context, userID string) (user *model.User, err error)
|
||||
TakeNotification(ctx context.Context, level int64) (user []*model.User, err error)
|
||||
TakeGTEAppManagerLevel(ctx context.Context, level int64) (user []*model.User, err error)
|
||||
TakeByNickname(ctx context.Context, nickname string) (user []*model.User, err error)
|
||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*model.User, err error)
|
||||
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*model.User, err error)
|
||||
|
||||
@@ -17,6 +17,9 @@ package webhook
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||
@@ -25,7 +28,6 @@ import (
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
"github.com/openimsdk/tools/mq/memamq"
|
||||
"github.com/openimsdk/tools/utils/httputil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -37,6 +39,8 @@ type Client struct {
|
||||
const (
|
||||
webhookWorkerCount = 2
|
||||
webhookBufferSize = 100
|
||||
|
||||
Key = "key"
|
||||
)
|
||||
|
||||
func NewWebhookClient(url string, options ...*memamq.MemoryQueue) *Client {
|
||||
@@ -66,6 +70,12 @@ func (c *Client) AsyncPost(ctx context.Context, command string, req callbackstru
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) AsyncPostWithQuery(ctx context.Context, command string, req callbackstruct.CallbackReq, resp callbackstruct.CallbackResp, after *config.AfterConfig, queryParams map[string]string) {
|
||||
if after.Enable {
|
||||
c.queue.Push(func() { c.postWithQuery(ctx, command, req, resp, after.Timeout, queryParams) })
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) post(ctx context.Context, command string, input interface{}, output callbackstruct.CallbackResp, timeout int) error {
|
||||
ctx = mcontext.WithMustInfoCtx([]string{mcontext.GetOperationID(ctx), mcontext.GetOpUserID(ctx), mcontext.GetOpUserPlatform(ctx), mcontext.GetConnID(ctx)})
|
||||
fullURL := c.url + "/" + command
|
||||
@@ -84,3 +94,41 @@ func (c *Client) post(ctx context.Context, command string, input interface{}, ou
|
||||
log.ZInfo(ctx, "webhook success", "url", fullURL, "input", input, "response", string(b))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) postWithQuery(ctx context.Context, command string, input interface{}, output callbackstruct.CallbackResp, timeout int, queryParams map[string]string) error {
|
||||
ctx = mcontext.WithMustInfoCtx([]string{mcontext.GetOperationID(ctx), mcontext.GetOpUserID(ctx), mcontext.GetOpUserPlatform(ctx), mcontext.GetConnID(ctx)})
|
||||
fullURL := c.url + "/" + command
|
||||
|
||||
parsedURL, err := url.Parse(fullURL)
|
||||
if err != nil {
|
||||
return servererrs.ErrNetwork.WrapMsg(err.Error(), "failed to parse URL", fullURL)
|
||||
}
|
||||
|
||||
query := parsedURL.Query()
|
||||
|
||||
operationID, _ := ctx.Value(constant.OperationID).(string)
|
||||
|
||||
for key, value := range queryParams {
|
||||
query.Set(key, value)
|
||||
}
|
||||
|
||||
parsedURL.RawQuery = query.Encode()
|
||||
|
||||
fullURL = parsedURL.String()
|
||||
log.ZInfo(ctx, "webhook", "url", fullURL, "input", input, "config", timeout)
|
||||
|
||||
b, err := c.client.Post(ctx, fullURL, map[string]string{constant.OperationID: operationID}, input, timeout)
|
||||
if err != nil {
|
||||
return servererrs.ErrNetwork.WrapMsg(err.Error(), "post url", fullURL)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(b, output); err != nil {
|
||||
return servererrs.ErrData.WithDetail(err.Error() + " response format error")
|
||||
}
|
||||
if err := output.Parse(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.ZInfo(ctx, "webhook success", "url", fullURL, "input", input, "response", string(b))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user