feat: 增加 bug/优化 机器人
This commit is contained in:
parent
92218ceb4d
commit
4ad3bfa614
|
|
@ -99,9 +99,14 @@ func (h *ChatService) Chat(c *websocket.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//简单协议:bind:<uid>
|
//简单协议:bind:<uid>
|
||||||
if c.Headers("Sec-Websocket-Protocol") == "bind" && req.SessionID != "" {
|
// if c.Headers("Sec-Websocket-Protocol") == "bind" && req.SessionID != "" {
|
||||||
uid := c.Query("x-session")
|
// uid := c.Query("x-session")
|
||||||
_ = h.Gw.BindUid(clientID, req.SessionID)
|
// _ = h.Gw.BindUid(clientID, req.SessionID)
|
||||||
|
// log.Printf("bind %s -> uid:%s\n", clientID, uid)
|
||||||
|
// }
|
||||||
|
uid := c.Query("x-session")
|
||||||
|
if uid != "" {
|
||||||
|
_ = h.Gw.BindUid(clientID, uid)
|
||||||
log.Printf("bind %s -> uid:%s\n", clientID, uid)
|
log.Printf("bind %s -> uid:%s\n", clientID, uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,37 @@ import (
|
||||||
"ai_scheduler/internal/config"
|
"ai_scheduler/internal/config"
|
||||||
"ai_scheduler/internal/data/constants"
|
"ai_scheduler/internal/data/constants"
|
||||||
errors "ai_scheduler/internal/data/error"
|
errors "ai_scheduler/internal/data/error"
|
||||||
|
"ai_scheduler/internal/data/impl"
|
||||||
"ai_scheduler/internal/entitys"
|
"ai_scheduler/internal/entitys"
|
||||||
|
"ai_scheduler/internal/pkg"
|
||||||
|
"ai_scheduler/internal/pkg/l_request"
|
||||||
"ai_scheduler/internal/pkg/utils_ollama"
|
"ai_scheduler/internal/pkg/utils_ollama"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2/log"
|
"github.com/gofiber/fiber/v2/log"
|
||||||
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BotTool struct {
|
type BotTool struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
llm *utils_ollama.Client
|
llm *utils_ollama.Client
|
||||||
|
sessionImpl *impl.SessionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBotTool 创建直连天下订单详情工具
|
// NewBotTool 创建直连天下订单详情工具
|
||||||
func NewBotTool(config *config.Config, llm *utils_ollama.Client) *BotTool {
|
func NewBotTool(config *config.Config, llm *utils_ollama.Client, sessionImpl *impl.SessionImpl) *BotTool {
|
||||||
return &BotTool{config: config, llm: llm}
|
return &BotTool{config: config, llm: llm, sessionImpl: sessionImpl}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BugOptimizationSubmitForm 工单提交表单参数
|
||||||
|
type BugOptimizationSubmitForm struct {
|
||||||
|
Mark string `json:"mark"` // 工单标识
|
||||||
|
Text string `json:"text"` // 工单描述
|
||||||
|
Img string `json:"img"` // 工单截图
|
||||||
|
Creator string `json:"creator"` // 工单创建人
|
||||||
|
Session string `json:"session"` // 会话ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 执行直连天下订单详情查询
|
// Execute 执行直连天下订单详情查询
|
||||||
|
|
@ -34,6 +50,49 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BotTool) BugOptimizationSubmit(ctx context.Context, requireData *entitys.RequireData) (err error) {
|
func (w *BotTool) BugOptimizationSubmit(ctx context.Context, requireData *entitys.RequireData) (err error) {
|
||||||
|
// 获取用户信息
|
||||||
|
cond := builder.NewCond()
|
||||||
|
cond = cond.And(builder.Eq{"session_id": requireData.Session})
|
||||||
|
sessionInfo, err := w.sessionImpl.GetOneBySearch(&cond)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.SysErr("获取历史记录失败:%v", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userName := sessionInfo["user_name"].(string)
|
||||||
|
|
||||||
|
// 构建工单表单参数
|
||||||
|
body := BugOptimizationSubmitForm{
|
||||||
|
Mark: requireData.Match.Index,
|
||||||
|
Text: requireData.Req.Text,
|
||||||
|
Img: requireData.Req.Img,
|
||||||
|
Creator: userName,
|
||||||
|
Session: requireData.Session,
|
||||||
|
}
|
||||||
|
|
||||||
|
request := l_request.Request{
|
||||||
|
Url: "https://connector.dingtalk.com/webhook/flow/10352c521dd02104cee9000c",
|
||||||
|
Method: "POST",
|
||||||
|
Headers: map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
JsonByte: pkg.JsonByteIgonErr(body),
|
||||||
|
}
|
||||||
|
res, err := request.Send()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("发送请求失败: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := make(map[string]bool)
|
||||||
|
if err = json.Unmarshal(res.Content, &data); err != nil {
|
||||||
|
return fmt.Errorf("解析商品数据失败:%w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data["success"] {
|
||||||
|
entitys.ResLoading(requireData.Ch, requireData.Match.Index, "问题信息记录中...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entitys.ResJson(requireData.Ch, requireData.Match.Index, "bug问题请咨询 @温子新 ,优化建议请咨询 @贺泽琨 。")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue