From 118c5f56f3e671d28248ff3d90529eb9cb1d5376 Mon Sep 17 00:00:00 2001 From: printlin <32053356+printlin@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:10:06 +0800 Subject: [PATCH] feature: add webhook AttentionIds (#2370) --- config/webhooks.yml | 3 +++ internal/rpc/msg/callback.go | 5 +++++ pkg/common/config/config.go | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/webhooks.yml b/config/webhooks.yml index c7839d4f2..11a85ba0c 100644 --- a/config/webhooks.yml +++ b/config/webhooks.yml @@ -13,6 +13,9 @@ afterUpdateUserInfoEx: afterSendSingleMsg: enable: false timeout: 5 + # Only the senID/recvID specified in attentionIds will send the callback + # if not set, all user messages will be callback + attentionIds: [] beforeSendGroupMsg: enable: false timeout: 5 diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 10404675e..be58d7504 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -83,6 +83,11 @@ func (m *msgServer) webhookAfterSendSingleMsg(ctx context.Context, after *config if msg.MsgData.ContentType == constant.Typing { return } + // According to the attentionIds configuration, only some users are sent + attentionIds := after.AttentionIds + if attentionIds != nil && !datautil.Contain(msg.MsgData.RecvID, attentionIds...) && !datautil.Contain(msg.MsgData.SendID, attentionIds...) { + return + } cbReq := &cbapi.CallbackAfterSendSingleMsgReq{ CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackAfterSendSingleMsgCommand), RecvID: msg.MsgData.RecvID, diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 6260dc00f..0b6176fb7 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -339,8 +339,9 @@ type BeforeConfig struct { } type AfterConfig struct { - Enable bool `mapstructure:"enable"` - Timeout int `mapstructure:"timeout"` + Enable bool `mapstructure:"enable"` + Timeout int `mapstructure:"timeout"` + AttentionIds []string `mapstructure:"attentionIds"` } type Share struct {