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
@@ -401,6 +401,12 @@
placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.schema" />
<p class="form-desc">{{ $t('agentEditor.im.dingtalkCardTemplateIdHint') }}</p>
</div>
<div class="form-item">
<label class="form-label">{{ $t('agentEditor.im.dingtalkSupportGroupId') }}</label>
<t-input v-model="formData.credentials.support_group_open_conversation_id"
placeholder="cidxxxxxxxxxxxxxxxx" />
<p class="form-desc">{{ $t('agentEditor.im.dingtalkSupportGroupIdHint') }}</p>
</div>
</template>
<!-- QQBot credentials -->
+2
View File
@@ -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.',
+2
View File
@@ -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 엔드포인트를 사용합니다.",
+2
View File
@@ -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.',
+2
View File
@@ -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 地址。",
+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