fix: 处理问题群卡片推送所有人
This commit is contained in:
parent
634bca5c60
commit
c74fe839d8
|
|
@ -246,6 +246,9 @@ func (d *DingTalkBotBiz) getHis(ctx context.Context, conversationType constants.
|
||||||
}
|
}
|
||||||
messages := make([]entitys.HisMessage, 0, len(his))
|
messages := make([]entitys.HisMessage, 0, len(his))
|
||||||
for _, v := range his {
|
for _, v := range his {
|
||||||
|
if v.Role != "user" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
messages = append(messages, entitys.HisMessage{
|
messages = append(messages, entitys.HisMessage{
|
||||||
Role: constants.Caller(v.Role), // 用户角色
|
Role: constants.Caller(v.Role), // 用户角色
|
||||||
Content: v.Content, // 用户输入内容
|
Content: v.Content, // 用户输入内容
|
||||||
|
|
|
||||||
|
|
@ -165,10 +165,10 @@ func (f *WithDingTalkBot) getUserContent(ctx context.Context, rec *entitys.Recog
|
||||||
content.WriteString(rec.UserContent.Tag)
|
content.WriteString(rec.UserContent.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rec.ChatHis.Messages) > 0 {
|
// if len(rec.ChatHis.Messages) > 0 {
|
||||||
content.WriteString("### 引用历史聊天记录:\n")
|
// content.WriteString("### 引用历史聊天记录:\n")
|
||||||
content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis))
|
// content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis))
|
||||||
}
|
// }
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -582,10 +582,12 @@ func (g *GroupConfigBiz) shouldCreateIssueHandlingGroup(ctx context.Context, rec
|
||||||
if err := json.Unmarshal([]byte(groupConfig.IssueOwner), &issueOwner); err != nil {
|
if err := json.Unmarshal([]byte(groupConfig.IssueOwner), &issueOwner); err != nil {
|
||||||
return fmt.Errorf("解析群问题处理人失败,err: %v", err)
|
return fmt.Errorf("解析群问题处理人失败,err: %v", err)
|
||||||
}
|
}
|
||||||
// 合并所有name
|
// 合并所有name、Id
|
||||||
var userNames []string
|
userNames := make([]string, 0, len(issueOwner))
|
||||||
|
userIds := make([]*string, 0, len(issueOwner))
|
||||||
for _, owner := range issueOwner {
|
for _, owner := range issueOwner {
|
||||||
userNames = append(userNames, "@"+owner.Name)
|
userNames = append(userNames, "@"+owner.Name)
|
||||||
|
userIds = append(userIds, tea.String(owner.UserId))
|
||||||
}
|
}
|
||||||
issueOwnerStr := strings.Join(userNames, "、")
|
issueOwnerStr := strings.Join(userNames, "、")
|
||||||
|
|
||||||
|
|
@ -624,9 +626,7 @@ func (g *GroupConfigBiz) shouldCreateIssueHandlingGroup(ctx context.Context, rec
|
||||||
OpenSpaceId: tea.String("dtv1.card//im_group." + callback.ConversationId),
|
OpenSpaceId: tea.String("dtv1.card//im_group." + callback.ConversationId),
|
||||||
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
||||||
RobotCode: tea.String(callback.RobotCode),
|
RobotCode: tea.String(callback.RobotCode),
|
||||||
Recipients: []*string{
|
Recipients: userIds,
|
||||||
tea.String(callback.SenderStaffId),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"ai_scheduler/internal/pkg/util"
|
"ai_scheduler/internal/pkg/util"
|
||||||
"ai_scheduler/internal/pkg/utils_ollama"
|
"ai_scheduler/internal/pkg/utils_ollama"
|
||||||
"ai_scheduler/internal/tool_callback"
|
"ai_scheduler/internal/tool_callback"
|
||||||
"bufio"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -572,9 +571,6 @@ func (s *CallbackService) issueHandlingExtractContent(data chatbot.BotCallbackDa
|
||||||
OpenSpaceId: tea.String("dtv1.card//im_group." + data.ConversationId),
|
OpenSpaceId: tea.String("dtv1.card//im_group." + data.ConversationId),
|
||||||
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
||||||
RobotCode: tea.String(constants.GroupTemplateRobotIdIssueHandling),
|
RobotCode: tea.String(constants.GroupTemplateRobotIdIssueHandling),
|
||||||
Recipients: []*string{
|
|
||||||
tea.String(data.SenderStaffId),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -616,9 +612,6 @@ func (s *CallbackService) issueHandlingQueryKnowledgeBase(data chatbot.BotCallba
|
||||||
OpenSpaceId: tea.String("dtv1.card//im_group." + data.ConversationId),
|
OpenSpaceId: tea.String("dtv1.card//im_group." + data.ConversationId),
|
||||||
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
||||||
RobotCode: tea.String(data.RobotCode),
|
RobotCode: tea.String(data.RobotCode),
|
||||||
Recipients: []*string{
|
|
||||||
tea.String(data.SenderStaffId),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -681,65 +674,6 @@ func (s *CallbackService) issueHandlingQueryKnowledgeBase(data chatbot.BotCallba
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取知识库 SSE 数据
|
|
||||||
func (s *CallbackService) readKnowledgeSSE(resp io.ReadCloser, channel chan string) (isRetrieved bool, err error) {
|
|
||||||
scanner := bufio.NewScanner(resp)
|
|
||||||
var buffer strings.Builder
|
|
||||||
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Text()
|
|
||||||
|
|
||||||
delta, done, err := knowledge_base.ParseOpenAIStreamData(line)
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("解析SSE数据失败: %w", err)
|
|
||||||
}
|
|
||||||
if done {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if delta == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 知识库未命中 输出提示后中断
|
|
||||||
if delta.XRagStatus == constants.KnowledgeRagStatusMiss {
|
|
||||||
var missContent string = "知识库未检测到匹配信息,即将为您创建群聊解决问题。"
|
|
||||||
channel <- missContent
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
// 推理内容
|
|
||||||
if delta.ReasoningContent != "" {
|
|
||||||
channel <- delta.ReasoningContent
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// 输出内容 - 段落
|
|
||||||
// 存入缓冲区
|
|
||||||
buffer.WriteString(delta.Content)
|
|
||||||
content := buffer.String()
|
|
||||||
|
|
||||||
// 检查是否有换行符,按段落输出
|
|
||||||
if idx := strings.LastIndex(content, "\n"); idx != -1 {
|
|
||||||
// 发送直到最后一个换行符的内容
|
|
||||||
toSend := content[:idx+1]
|
|
||||||
channel <- toSend
|
|
||||||
|
|
||||||
// 重置缓冲区,保留剩余部分
|
|
||||||
remaining := content[idx+1:]
|
|
||||||
buffer.Reset()
|
|
||||||
buffer.WriteString(remaining)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := scanner.Err(); err != nil {
|
|
||||||
return true, fmt.Errorf("读取SSE流中断: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送缓冲区剩余内容(仅在段落模式下需要)
|
|
||||||
if buffer.Len() > 0 {
|
|
||||||
channel <- buffer.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CallbackDingtalkCard 处理钉钉卡片回调
|
// CallbackDingtalkCard 处理钉钉卡片回调
|
||||||
// 钉钉 callbackRouteKey: gateway.dev.cdlsxd.cn-dingtalk-card
|
// 钉钉 callbackRouteKey: gateway.dev.cdlsxd.cn-dingtalk-card
|
||||||
// 钉钉 apiSecret: aB3dE7fG9hI2jK4L5M6N7O8P9Q0R1S2T
|
// 钉钉 apiSecret: aB3dE7fG9hI2jK4L5M6N7O8P9Q0R1S2T
|
||||||
|
|
@ -840,9 +774,6 @@ func (s *CallbackService) issueHandlingCollectQA(data card.CardRequest) *card.Ca
|
||||||
OpenSpaceId: tea.String("dtv1.card//im_group." + conversationId),
|
OpenSpaceId: tea.String("dtv1.card//im_group." + conversationId),
|
||||||
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
ImGroupOpenDeliverModel: &card_1_0.CreateAndDeliverRequestImGroupOpenDeliverModel{
|
||||||
RobotCode: tea.String(robotCode),
|
RobotCode: tea.String(robotCode),
|
||||||
Recipients: []*string{
|
|
||||||
tea.String(data.UserId),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -339,7 +339,7 @@ func (d *DingBotService) createIssueHandlingGroupAndInit(ctx context.Context, ca
|
||||||
CardData: &card_1_0.CreateAndDeliverRequestCardData{
|
CardData: &card_1_0.CreateAndDeliverRequestCardData{
|
||||||
CardParamMap: map[string]*string{
|
CardParamMap: map[string]*string{
|
||||||
"title": tea.String("当前机器人能力"),
|
"title": tea.String("当前机器人能力"),
|
||||||
"markdown": tea.String("- 聊天内容提取(@机器人 [内容提取]) \n - QA知识收集 (@机器人 [QA收集])"),
|
"markdown": tea.String("- 聊天内容提取(@机器人 [内容提取]{聊天记录/问答描述}) \n - QA知识收集(卡片信息收集) \n - QA知识问答(@机器人 [知识库查询]{问题描述})"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ImGroupOpenSpaceModel: &card_1_0.CreateAndDeliverRequestImGroupOpenSpaceModel{
|
ImGroupOpenSpaceModel: &card_1_0.CreateAndDeliverRequestImGroupOpenSpaceModel{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue