feat(im): push escalations to configured support group

This commit is contained in:
姚章浩
2026-07-15 14:37:27 +08:00
parent 0eb13a022e
commit 6a598c4317
7 changed files with 71 additions and 0 deletions
+35
View File
@@ -4,6 +4,7 @@ import (
"context"
"testing"
"github.com/Tencent/WeKnora/internal/types"
"github.com/gin-gonic/gin"
)
@@ -56,3 +57,37 @@ func TestSendReplyToSourceRejectsUnavailableChannel(t *testing.T) {
t.Fatal("expected missing channel error")
}
}
func TestSendSupportNotificationUsesConfiguredGroup(t *testing.T) {
adapter := &recordingReplyAdapter{}
service := &Service{channels: map[string]*channelState{
"channel-1": {
Adapter: adapter,
Channel: &IMChannel{
ID: "channel-1",
Platform: "dingtalk",
Enabled: true,
Credentials: types.JSON(`{"support_group_open_conversation_id":"support-group-1"}`),
},
},
}}
if err := service.SendSupportNotification(context.Background(), "channel-1", "新工单:客户未解决"); err != nil {
t.Fatalf("SendSupportNotification: %v", err)
}
if adapter.incoming == nil || adapter.incoming.ChatType != ChatTypeGroup || adapter.incoming.ChatID != "support-group-1" {
t.Fatalf("support target = %#v", adapter.incoming)
}
if adapter.reply == nil || adapter.reply.Content != "新工单:客户未解决" {
t.Fatalf("support reply = %#v", adapter.reply)
}
}
func TestSendSupportNotificationRequiresConfiguredGroup(t *testing.T) {
service := &Service{channels: map[string]*channelState{
"channel-1": {Adapter: &recordingReplyAdapter{}, Channel: &IMChannel{ID: "channel-1", Platform: "dingtalk", Enabled: true}},
}}
if err := service.SendSupportNotification(context.Background(), "channel-1", "ticket"); err == nil {
t.Fatal("expected missing support group configuration error")
}
}
+22
View File
@@ -1295,6 +1295,28 @@ func (s *Service) SendReplyToSource(ctx context.Context, target ReplyTarget, con
return adapter.SendReply(ctx, incoming, &ReplyMessage{Content: content, IsFinal: true})
}
// SendSupportNotification pushes a newly escalated ticket to the support group
// configured in the source channel credentials. The group identifier is never logged.
func (s *Service) SendSupportNotification(ctx context.Context, channelID, content string) error {
_, channel, ok := s.GetChannelAdapter(channelID)
if !ok || channel == nil {
return fmt.Errorf("IM channel %s is not running", channelID)
}
credentials, err := ParseCredentials(channel.Credentials)
if err != nil {
return fmt.Errorf("parse support group configuration: %w", err)
}
supportGroupID := strings.TrimSpace(GetString(credentials, "support_group_open_conversation_id"))
if supportGroupID == "" {
return fmt.Errorf("support group is not configured for IM channel %s", channelID)
}
return s.SendReplyToSource(ctx, ReplyTarget{
ChannelID: channelID,
ChatID: supportGroupID,
ChatType: ChatTypeGroup,
}, content)
}
// GetChannelByID loads a channel from the database.
func (s *Service) GetChannelByID(channelID string) (*IMChannel, error) {
var ch IMChannel