feat: add manual "转人工" (request human) action for conversations
- Backend: RequestHuman service method changes status from AI_SERVING to PENDING - Backend: POST /api/dashboard/conversation/request-human endpoint - Frontend: requestHumanConversation API client - Frontend: "转人工" button in conversation list dropdown and detail dialog
This commit is contained in:
@@ -185,6 +185,22 @@ func (c *ConversationController) PostTransfer() *web.JsonResult {
|
||||
return web.JsonSuccess()
|
||||
}
|
||||
|
||||
func (c *ConversationController) PostRequest_human() *web.JsonResult {
|
||||
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationAssign)
|
||||
if err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
|
||||
req := request.RequestHumanConversationRequest{}
|
||||
if err := params.ReadJSON(c.Ctx, &req); err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
if err := services.ConversationService.RequestHuman(req.ConversationID, operator); err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
return web.JsonSuccess()
|
||||
}
|
||||
|
||||
func (c *ConversationController) PostClose() *web.JsonResult {
|
||||
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationClose)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,6 +34,10 @@ type TransferConversationRequest struct {
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
type RequestHumanConversationRequest struct {
|
||||
ConversationID int64 `json:"conversationId"`
|
||||
}
|
||||
|
||||
type CloseConversationRequest struct {
|
||||
ConversationID int64 `json:"conversationId"`
|
||||
CloseReason string `json:"closeReason"`
|
||||
|
||||
@@ -374,6 +374,38 @@ func (s *conversationService) TryOffHoursHandoffByAI(conversationID int64, aiAge
|
||||
return handled, err
|
||||
}
|
||||
|
||||
func (s *conversationService) RequestHuman(conversationID int64, operator *dto.AuthPrincipal) error {
|
||||
if operator == nil {
|
||||
return errorsx.Unauthorized("未登录或登录已过期")
|
||||
}
|
||||
conversation := s.Get(conversationID)
|
||||
if conversation == nil {
|
||||
return errorsx.InvalidParam("会话不存在")
|
||||
}
|
||||
if conversation.Status != enums.IMConversationStatusAIServing {
|
||||
return errorsx.InvalidParam("当前会话状态不允许转人工")
|
||||
}
|
||||
now := time.Now()
|
||||
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
||||
if err := repositories.ConversationRepository.Updates(ctx.Tx, conversationID, map[string]any{
|
||||
"status": enums.IMConversationStatusPending,
|
||||
"update_user_id": operator.UserID,
|
||||
"update_user_name": operator.Username,
|
||||
"updated_at": now,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return ConversationEventLogService.CreateEvent(ctx, conversationID,
|
||||
enums.IMEventTypeTransfer, enums.IMSenderTypeSystem, 0,
|
||||
"管理员手动转人工",
|
||||
buildEventPayload(map[string]any{
|
||||
"operator": operator.Username,
|
||||
"fromStatus": enums.IMConversationStatusAIServing,
|
||||
"toStatus": enums.IMConversationStatusPending,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
func (s *conversationService) CloseConversation(conversationID int64, closeReason string, operator *dto.AuthPrincipal) error {
|
||||
if operator == nil {
|
||||
return errorsx.Unauthorized("未登录或登录已过期")
|
||||
|
||||
@@ -40,7 +40,8 @@ type ConversationDetailDialogProps = {
|
||||
onLoadMoreMessages?: () => void | Promise<void>;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onOpenAssign: () => void;
|
||||
onDispatch: () => Promise<void>;
|
||||
onDispatch: () => Promise<void>
|
||||
onRequestHuman?: () => Promise<void>;
|
||||
onOpenTransfer: () => void;
|
||||
onRead: () => Promise<void>;
|
||||
onOpenClose: () => void;
|
||||
@@ -272,6 +273,14 @@ export function ConversationDetailDialog({
|
||||
: "暂无会话信息"}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => void onRequestHuman?.()}
|
||||
disabled={saving || !currentConversation || currentConversation.status !== 1}
|
||||
>
|
||||
<MessageCircleMoreIcon />
|
||||
{saving ? "处理中..." : "转人工"}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onOpenAssign}
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
fetchConversations,
|
||||
fetchTagsAll,
|
||||
markConversationRead,
|
||||
requestHumanConversation,
|
||||
type AdminAgentProfile,
|
||||
type AdminAgentTeam,
|
||||
type AdminConversation,
|
||||
@@ -610,6 +611,22 @@ export default function DashboardConversationsPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRequestHuman(item: AdminConversation) {
|
||||
setActionLoadingId(item.id)
|
||||
try {
|
||||
await requestHumanConversation(item.id)
|
||||
toast.success(`已转人工:${item.customerName || `#${item.id}`}`)
|
||||
await loadConversations()
|
||||
if (detailItem?.id === item.id) {
|
||||
await refreshDetail()
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "转人工失败")
|
||||
} finally {
|
||||
setActionLoadingId(null)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDispatch(item: AdminConversation) {
|
||||
setActionLoadingId(item.id)
|
||||
try {
|
||||
@@ -761,6 +778,13 @@ export default function DashboardConversationsPage() {
|
||||
<MoreHorizontalIcon />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-44 min-w-44">
|
||||
<DropdownMenuItem
|
||||
onClick={() => void handleRequestHuman(item)}
|
||||
disabled={actionLoadingId === item.id || item.status !== 1}
|
||||
>
|
||||
<MessageCircleMoreIcon />
|
||||
{actionLoadingId === item.id ? "处理中..." : "转人工"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => openAssign(item)}
|
||||
disabled={actionLoadingId === item.id || item.status !== 2}
|
||||
@@ -838,6 +862,12 @@ export default function DashboardConversationsPage() {
|
||||
loadingMoreMessages={detailMessagesLoadingMore}
|
||||
onLoadMoreMessages={loadMoreDetailMessages}
|
||||
onOpenChange={handleDetailOpenChange}
|
||||
onRequestHuman={async () => {
|
||||
if (!detailItem) {
|
||||
return
|
||||
}
|
||||
await handleRequestHuman(detailItem)
|
||||
}}
|
||||
onOpenAssign={() => {
|
||||
if (!detailItem) {
|
||||
return
|
||||
|
||||
@@ -833,6 +833,13 @@ export function assignConversation(
|
||||
})
|
||||
}
|
||||
|
||||
export function requestHumanConversation(conversationId: number) {
|
||||
return request<void>("/api/dashboard/conversation/request-human", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ conversationId }),
|
||||
})
|
||||
}
|
||||
|
||||
export function dispatchConversation(conversationId: number) {
|
||||
return request<void>("/api/dashboard/conversation/dispatch", {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user