diff --git a/internal/builders/conversation_builder.go b/internal/builders/conversation_builder.go index 3250aa1..1d3bddd 100644 --- a/internal/builders/conversation_builder.go +++ b/internal/builders/conversation_builder.go @@ -17,6 +17,7 @@ func BuildConversation(item *models.Conversation) response.ConversationResponse ret := response.ConversationResponse{ ID: item.ID, AIAgentID: item.AIAgentID, + ChannelID: item.ChannelID, CustomerID: item.CustomerID, ExternalSource: item.ExternalSource, ExternalID: item.ExternalID, diff --git a/internal/controllers/api/conversation_controller.go b/internal/controllers/api/conversation_controller.go index 4ae9235..0bf8782 100644 --- a/internal/controllers/api/conversation_controller.go +++ b/internal/controllers/api/conversation_controller.go @@ -50,7 +50,7 @@ func (c *ConversationController) PostCreate_or_match() *web.JsonResult { return web.JsonErrorMsg("外部身份未初始化") } - item, err := services.ConversationService.Create(*external, channel.AIAgentID) + item, err := services.ConversationService.Create(*external, channel.ID, channel.AIAgentID) if err != nil { return web.JsonError(err) } diff --git a/internal/models/models.go b/internal/models/models.go index c7aef65..79e6aa9 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -325,6 +325,7 @@ type Tag struct { type Conversation struct { ID int64 `gorm:"primaryKey;autoIncrement"` // ID 为会话主键。 AIAgentID int64 `gorm:"type:bigint;not null;default:0;index"` // AIAgentID 为当前会话绑定的 AI Agent ID。 + ChannelID int64 `gorm:"type:bigint;not null;default:0;index"` // ChannelID 为该会话来源接入渠道ID。 CustomerID int64 `gorm:"type:bigint;not null;default:0;index"` // CustomerID 为已关联的 CRM 客户 ID;0 表示未关联(访客仅 ExternalUserID)。 ExternalSource enums.ExternalSource `gorm:"type:varchar(50);not null;default:'';index"` // ExternalSource 为外部身份来源。 ExternalID string `gorm:"type:varchar(128);not null;default:'';index"` // ExternalID 为外部访客ID。 diff --git a/internal/pkg/dto/response/conversation_response.go b/internal/pkg/dto/response/conversation_response.go index c2e440f..e0d34d1 100644 --- a/internal/pkg/dto/response/conversation_response.go +++ b/internal/pkg/dto/response/conversation_response.go @@ -20,6 +20,7 @@ type ConversationParticipantResponse struct { type ConversationResponse struct { ID int64 `json:"id"` AIAgentID int64 `json:"aiAgentId"` + ChannelID int64 `json:"channelId"` CustomerID int64 `json:"customerId"` ExternalSource enums.ExternalSource `json:"externalSource"` ExternalID string `json:"externalId"` diff --git a/internal/services/conversation_service.go b/internal/services/conversation_service.go index 013b693..888ab21 100644 --- a/internal/services/conversation_service.go +++ b/internal/services/conversation_service.go @@ -99,7 +99,7 @@ func (s *conversationService) getLatestNotFinished(externalInfo openidentity.Ext return s.FindOne(cnd) } -func (s *conversationService) Create(externalInfo openidentity.ExternalInfo, aiAgentID int64) (*models.Conversation, error) { +func (s *conversationService) Create(externalInfo openidentity.ExternalInfo, channelID, aiAgentID int64) (*models.Conversation, error) { subject := s.buildDefaultSubject(externalInfo) // 会话存在,直接返回 @@ -114,6 +114,7 @@ func (s *conversationService) Create(externalInfo openidentity.ExternalInfo, aiA conversation := &models.Conversation{ AIAgentID: aiAgentID, + ChannelID: channelID, ExternalSource: externalInfo.ExternalSource, Subject: subject, Status: s.resolveInitialStatus(aiAgent.ServiceMode), diff --git a/internal/services/wxwork_kf_inbound_service.go b/internal/services/wxwork_kf_inbound_service.go index b2e7bde..aa8d560 100644 --- a/internal/services/wxwork_kf_inbound_service.go +++ b/internal/services/wxwork_kf_inbound_service.go @@ -389,7 +389,7 @@ func (s *wxWorkKFInboundService) ensureConversation(base syncmsg.BaseMessage, pr Desc("id")) if conversation == nil { - conversation, err = ConversationService.Create(external, channel.AIAgentID) + conversation, err = ConversationService.Create(external, channel.ID, channel.AIAgentID) if err != nil { return nil, err } diff --git a/web/lib/api/admin.ts b/web/lib/api/admin.ts index fc1dbe7..be86cfe 100644 --- a/web/lib/api/admin.ts +++ b/web/lib/api/admin.ts @@ -108,6 +108,7 @@ export type ConversationParticipant = { export type AdminConversation = { id: number + channelId: number externalSource: string externalId: string subject: string diff --git a/web/lib/api/agent.ts b/web/lib/api/agent.ts index bfe2dbb..fe47e72 100644 --- a/web/lib/api/agent.ts +++ b/web/lib/api/agent.ts @@ -35,6 +35,7 @@ export type AgentConversationParticipant = { export type AgentConversation = { id: number aiAgentId?: number + channelId?: number customerId?: number externalSource: string externalId: string diff --git a/web/lib/api/im.ts b/web/lib/api/im.ts index b42eeee..064620d 100644 --- a/web/lib/api/im.ts +++ b/web/lib/api/im.ts @@ -33,6 +33,7 @@ export type ImConversationParticipant = { export type ImConversation = { id: number + channelId: number externalSource: string externalId: string subject: string