feat: enhance event consumption logic and add success reply handling
This commit is contained in:
@@ -514,7 +514,7 @@ func (s *messageService) ValidateConversationSender(conversationID int64, sender
|
||||
if operator == nil {
|
||||
return nil, errorsx.Unauthorized("未登录或登录已过期")
|
||||
}
|
||||
if conversation.Status != enums.IMConversationStatusAIServing {
|
||||
if conversation.Status != enums.IMConversationStatusAIServing && !allowAIMessageOnPendingHandoff(conversation) {
|
||||
return nil, errorsx.Forbidden("当前会话不处于 AI 接待状态")
|
||||
}
|
||||
if conversation.CurrentAssigneeID != 0 {
|
||||
@@ -530,6 +530,15 @@ func (s *messageService) ValidateConversationSender(conversationID int64, sender
|
||||
return conversation, nil
|
||||
}
|
||||
|
||||
func allowAIMessageOnPendingHandoff(conversation *models.Conversation) bool {
|
||||
if conversation == nil {
|
||||
return false
|
||||
}
|
||||
return conversation.Status == enums.IMConversationStatusPending &&
|
||||
conversation.HandoffAt != nil &&
|
||||
conversation.CurrentAssigneeID == 0
|
||||
}
|
||||
|
||||
func suffixFilenameForSummary(filename string) string {
|
||||
filename = strings.TrimSpace(filename)
|
||||
if filename == "" {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
)
|
||||
|
||||
func TestAllowAIMessageOnPendingHandoff(t *testing.T) {
|
||||
conversation := &models.Conversation{
|
||||
Status: enums.IMConversationStatusPending,
|
||||
CurrentAssigneeID: 0,
|
||||
HandoffAt: ptrTime(time.Now()),
|
||||
}
|
||||
if !allowAIMessageOnPendingHandoff(conversation) {
|
||||
t.Fatalf("expected pending handoff conversation to allow ai handoff notice")
|
||||
}
|
||||
|
||||
conversation.Status = enums.IMConversationStatusAIServing
|
||||
if allowAIMessageOnPendingHandoff(conversation) {
|
||||
t.Fatalf("expected ai serving conversation not to use pending handoff allowance")
|
||||
}
|
||||
}
|
||||
|
||||
func ptrTime(v time.Time) *time.Time {
|
||||
return &v
|
||||
}
|
||||
Reference in New Issue
Block a user