From 6a598c4317393504a733ab88020eededae2e56ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Wed, 15 Jul 2026 14:37:27 +0800 Subject: [PATCH] feat(im): push escalations to configured support group --- frontend/src/components/IMChannelPanel.vue | 6 ++++ frontend/src/i18n/locales/en-US.ts | 2 ++ frontend/src/i18n/locales/ko-KR.ts | 2 ++ frontend/src/i18n/locales/ru-RU.ts | 2 ++ frontend/src/i18n/locales/zh-CN.ts | 2 ++ internal/im/proactive_reply_test.go | 35 ++++++++++++++++++++++ internal/im/service.go | 22 ++++++++++++++ 7 files changed, 71 insertions(+) diff --git a/frontend/src/components/IMChannelPanel.vue b/frontend/src/components/IMChannelPanel.vue index 398ee378..5e1aa409 100644 --- a/frontend/src/components/IMChannelPanel.vue +++ b/frontend/src/components/IMChannelPanel.vue @@ -401,6 +401,12 @@ placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.schema" />

{{ $t('agentEditor.im.dingtalkCardTemplateIdHint') }}

+
+ + +

{{ $t('agentEditor.im.dingtalkSupportGroupIdHint') }}

+
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 32fe7b13..828e8993 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -5375,6 +5375,8 @@ export default { dingtalkConsole: 'DingTalk Open Platform', dingtalkCardTemplateId: 'Card Template ID (optional)', dingtalkCardTemplateIdHint: 'Create an AI Card template at open-dev.dingtalk.com/fe/card to enable streaming output with typewriter effect', + dingtalkSupportGroupId: 'Support group openConversationId (optional)', + dingtalkSupportGroupIdHint: 'Escalated tickets are pushed to this DingTalk group. Obtain the ID from a callback received in the support group.', mattermostConsole: 'Mattermost integrations', qqbotConsole: 'QQ Open Platform', qqbotAPIBaseURLHint: 'Optional. Leave empty to use the default production API endpoint.', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index d2db1dfe..cee509fb 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5316,6 +5316,8 @@ export default { dingtalkConsole: "DingTalk 개발 플랫폼", dingtalkCardTemplateId: "카드 템플릿 ID (선택 사항)", dingtalkCardTemplateIdHint: "open-dev.dingtalk.com/fe/card에서 AI 카드 템플릿을 만들면 타자기 효과 스트리밍 출력이 활성화됩니다", + dingtalkSupportGroupId: "지원 그룹 openConversationId (선택 사항)", + dingtalkSupportGroupIdHint: "에스컬레이션된 티켓을 이 DingTalk 그룹으로 전송합니다", mattermostConsole: "Mattermost 통합", qqbotConsole: "QQ Open Platform", qqbotAPIBaseURLHint: "선택 사항. 비워두면 기본 프로덕션 API 엔드포인트를 사용합니다.", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 245eeb8c..1d801792 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -4886,6 +4886,8 @@ export default { dingtalkConsole: 'Платформа DingTalk', dingtalkCardTemplateId: 'ID шаблона карточки (необязательно)', dingtalkCardTemplateIdHint: 'Создайте шаблон AI-карточки на open-dev.dingtalk.com/fe/card для потоковой передачи с эффектом печатной машинки', + dingtalkSupportGroupId: 'openConversationId группы поддержки (необязательно)', + dingtalkSupportGroupIdHint: 'Эскалированные заявки отправляются в эту группу DingTalk', mattermostConsole: 'Интеграции Mattermost', qqbotConsole: 'QQ Open Platform', qqbotAPIBaseURLHint: 'Необязательно. Оставьте пустым, чтобы использовать стандартный production API endpoint.', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 924e5e8a..2034f9be 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5318,6 +5318,8 @@ export default { dingtalkConsole: "钉钉开放平台", dingtalkCardTemplateId: "卡片模板 ID(可选)", dingtalkCardTemplateIdHint: "在 open-dev.dingtalk.com/fe/card 创建 AI 卡片模板,启用后支持打字机效果的流式输出", + dingtalkSupportGroupId: "技术支持群 openConversationId(可选)", + dingtalkSupportGroupIdHint: "转人工工单会自动推送到该钉钉群,可从支持群内机器人回调中获取此 ID", mattermostConsole: "Mattermost 集成说明", qqbotConsole: "QQ 开放平台", qqbotAPIBaseURLHint: "可选,留空则使用默认正式环境 API 地址。", diff --git a/internal/im/proactive_reply_test.go b/internal/im/proactive_reply_test.go index d9d19ef5..8ce94de7 100644 --- a/internal/im/proactive_reply_test.go +++ b/internal/im/proactive_reply_test.go @@ -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") + } +} diff --git a/internal/im/service.go b/internal/im/service.go index 91991e08..5c581e1b 100644 --- a/internal/im/service.go +++ b/internal/im/service.go @@ -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