fix(dialog): use uuid.New() for ticket and audit IDs
- Replace fmt.Sprintf with sess.ID+nanotime that generated non-UUID strings - ticket creation and audit logging now use github.com/google/uuid - Fixes 500 error when webhook processes messages with PG store - All 23/23 tests pass, verified Gate B end-to-end
This commit is contained in:
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module github.com/bridge/ai-customer-service
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
require github.com/lib/pq v1.10.9
|
require (
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/lib/pq v1.10.9
|
||||||
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1,2 +1,4 @@
|
|||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/bridge/ai-customer-service/internal/domain/audit"
|
"github.com/bridge/ai-customer-service/internal/domain/audit"
|
||||||
intentdomain "github.com/bridge/ai-customer-service/internal/domain/intent"
|
intentdomain "github.com/bridge/ai-customer-service/internal/domain/intent"
|
||||||
"github.com/bridge/ai-customer-service/internal/domain/message"
|
"github.com/bridge/ai-customer-service/internal/domain/message"
|
||||||
@@ -110,7 +112,7 @@ func (s *Service) Process(ctx context.Context, msg *message.UnifiedMessage) (*Re
|
|||||||
sess.Status = session.StatusHandoff
|
sess.Status = session.StatusHandoff
|
||||||
replyText = "已为您转人工客服,请稍候,我们会尽快处理。"
|
replyText = "已为您转人工客服,请稍候,我们会尽快处理。"
|
||||||
if s.tickets != nil {
|
if s.tickets != nil {
|
||||||
ticketID = fmt.Sprintf("%s-%d", sess.ID, now.UnixNano())
|
ticketID = uuid.New().String()
|
||||||
ticketPriority := ticket.Priority(handoffDecision.Priority)
|
ticketPriority := ticket.Priority(handoffDecision.Priority)
|
||||||
if ticketPriority == "" {
|
if ticketPriority == "" {
|
||||||
ticketPriority = ticket.PriorityP2
|
ticketPriority = ticket.PriorityP2
|
||||||
@@ -136,7 +138,7 @@ func (s *Service) Process(ctx context.Context, msg *message.UnifiedMessage) (*Re
|
|||||||
if ticketID != "" {
|
if ticketID != "" {
|
||||||
auditPayload["ticket_id"] = ticketID
|
auditPayload["ticket_id"] = ticketID
|
||||||
}
|
}
|
||||||
if err := s.audits.Add(ctx, audit.Event{ID: fmt.Sprintf("%s-%d", sess.ID, now.UnixNano()), SessionID: sess.ID, Type: "message_processed", Action: "process", Channel: msg.Channel, OpenID: msg.OpenID, ActorID: msg.OpenID, Payload: auditPayload, CreatedAt: now}); err != nil {
|
if err := s.audits.Add(ctx, audit.Event{ID: uuid.New().String(), SessionID: sess.ID, Type: "message_processed", Action: "process", Channel: msg.Channel, OpenID: msg.OpenID, ActorID: msg.OpenID, Payload: auditPayload, CreatedAt: now}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user