79614b2d07
- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params". - Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context. - Ensured consistent usage of HTTP status responses across websocket handlers.
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package api
|
|
|
|
import (
|
|
"cs-agent/internal/builders"
|
|
"cs-agent/internal/pkg/dto/request"
|
|
"cs-agent/internal/pkg/dto/response"
|
|
"cs-agent/internal/pkg/httpx"
|
|
"cs-agent/internal/services"
|
|
|
|
"cs-agent/internal/pkg/httpx/params"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mlogclub/simple/web"
|
|
)
|
|
|
|
type ConversationController struct {
|
|
Ctx *gin.Context
|
|
}
|
|
|
|
func (c *ConversationController) GetBy(id int64) *web.JsonResult {
|
|
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
|
return web.JsonErrorMsg("接入渠道未初始化")
|
|
}
|
|
external := httpx.GetExternalUser(c.Ctx)
|
|
if external == nil {
|
|
return web.JsonErrorMsg("外部身份未初始化")
|
|
}
|
|
|
|
item := services.ConversationService.Get(id)
|
|
if item == nil {
|
|
return web.JsonErrorMsg("会话不存在")
|
|
}
|
|
if !services.ConversationService.IsCustomerConversationOwner(item, *external) {
|
|
return web.JsonErrorMsg("无权访问该会话")
|
|
}
|
|
|
|
detail := response.ConversationDetailResponse{
|
|
ConversationResponse: builders.BuildConversation(item),
|
|
Participants: builders.BuildParticipantResponses(id),
|
|
}
|
|
return web.JsonData(detail)
|
|
}
|
|
|
|
func (c *ConversationController) PostCreate_or_match() *web.JsonResult {
|
|
channel := services.ChannelService.GetEnabledChannel(c.Ctx)
|
|
if channel == nil {
|
|
return web.JsonErrorMsg("接入渠道未初始化")
|
|
}
|
|
external := httpx.GetExternalUser(c.Ctx)
|
|
if external == nil {
|
|
return web.JsonErrorMsg("外部身份未初始化")
|
|
}
|
|
|
|
item, err := services.ConversationService.Create(*external, channel.ID, channel.AIAgentID)
|
|
if err != nil {
|
|
return web.JsonError(err)
|
|
}
|
|
return web.JsonData(builders.BuildConversation(item))
|
|
}
|
|
|
|
func (c *ConversationController) PostClose() *web.JsonResult {
|
|
if services.ChannelService.GetEnabledChannel(c.Ctx) == nil {
|
|
return web.JsonErrorMsg("接入渠道未初始化")
|
|
}
|
|
external := httpx.GetExternalUser(c.Ctx)
|
|
if external == nil {
|
|
return web.JsonErrorMsg("外部身份未初始化")
|
|
}
|
|
|
|
req := request.CloseConversationRequest{}
|
|
if err := params.ReadJSON(c.Ctx, &req); err != nil {
|
|
return web.JsonError(err)
|
|
}
|
|
if err := services.ConversationService.CloseCustomerConversation(req.ConversationID, *external); err != nil {
|
|
return web.JsonError(err)
|
|
}
|
|
return web.JsonSuccess()
|
|
}
|