修复(AI客服): 退款操作统一转人工处理
隐藏并拦截退款类业务动作,兼容旧确认流程,确保所有客户类型的退款请求进入人工支持,并补充回归测试。
This commit is contained in:
@@ -13,6 +13,15 @@ import (
|
||||
|
||||
var BusinessActionToolService = &businessActionToolService{}
|
||||
|
||||
const RefundHumanSupportMessage = "退款需要由人工客服核实并处理,AI 无法代您申请或办理退款。请回复“人工客服”联系人工处理。"
|
||||
|
||||
// BusinessActionRequiresHuman also covers the legacy mall application tool,
|
||||
// whose refund_only and return_refund actions do not mention refund in its code.
|
||||
func BusinessActionRequiresHuman(code string) bool {
|
||||
code = strings.ToLower(strings.TrimSpace(code))
|
||||
return code == "business/mall_apply_after_sale" || strings.Contains(code, "refund")
|
||||
}
|
||||
|
||||
type businessActionToolService struct {
|
||||
mu sync.RWMutex
|
||||
tools map[string]contract.BusinessActionTool
|
||||
@@ -55,7 +64,7 @@ func (s *businessActionToolService) ListForCustomerType(customerType string) []c
|
||||
defer s.mu.RUnlock()
|
||||
ret := make([]contract.BusinessActionTool, 0, len(s.tools))
|
||||
for _, tool := range s.tools {
|
||||
if businessActionToolSupportsCustomerType(tool, customerType) {
|
||||
if !BusinessActionRequiresHuman(tool.Code) && businessActionToolSupportsCustomerType(tool, customerType) {
|
||||
ret = append(ret, tool)
|
||||
}
|
||||
}
|
||||
@@ -67,7 +76,7 @@ func (s *businessActionToolService) ResolveForCustomerType(code, customerType st
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
tool, ok := s.tools[strings.TrimSpace(code)]
|
||||
if !ok || !businessActionToolSupportsCustomerType(tool, customerType) {
|
||||
if !ok || BusinessActionRequiresHuman(tool.Code) || !businessActionToolSupportsCustomerType(tool, customerType) {
|
||||
return contract.BusinessActionTool{}, false
|
||||
}
|
||||
return tool, true
|
||||
@@ -77,14 +86,23 @@ func (s *businessActionToolService) Resolve(code string) (contract.BusinessActio
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
tool, ok := s.tools[strings.TrimSpace(code)]
|
||||
if ok && BusinessActionRequiresHuman(tool.Code) {
|
||||
return contract.BusinessActionTool{}, false
|
||||
}
|
||||
return tool, ok
|
||||
}
|
||||
|
||||
func (s *businessActionToolService) Preview(ctx context.Context, tool contract.BusinessActionTool, businessContext contract.BusinessReadContext, arguments map[string]any) (string, error) {
|
||||
if BusinessActionRequiresHuman(tool.Code) {
|
||||
return "", contract.NewBusinessActionError(RefundHumanSupportMessage, nil)
|
||||
}
|
||||
return tool.Preview(ctx, businessContext, arguments)
|
||||
}
|
||||
|
||||
func (s *businessActionToolService) Execute(ctx context.Context, conversationID, aiAgentID int64, idempotencyKey string, tool contract.BusinessActionTool, businessContext contract.BusinessReadContext, arguments map[string]any) (*contract.BusinessActionResult, bool, error) {
|
||||
if BusinessActionRequiresHuman(tool.Code) {
|
||||
return nil, false, contract.NewBusinessActionError(RefundHumanSupportMessage, nil)
|
||||
}
|
||||
businessContext.CheckPointID = strings.TrimSpace(idempotencyKey)
|
||||
if tool.AuthorizeConfirmation != nil {
|
||||
if err := tool.AuthorizeConfirmation(ctx, businessContext, arguments, businessContext.CheckPointID); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user