feat: add ChannelID to conversation model and update related services and responses

This commit is contained in:
mlogclub
2026-04-27 17:59:23 +08:00
parent bc98fc572f
commit 1bb4608051
9 changed files with 10 additions and 3 deletions
@@ -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,
@@ -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)
}
+1
View File
@@ -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。
@@ -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"`
+2 -1
View File
@@ -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),
@@ -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
}
+1
View File
@@ -108,6 +108,7 @@ export type ConversationParticipant = {
export type AdminConversation = {
id: number
channelId: number
externalSource: string
externalId: string
subject: string
+1
View File
@@ -35,6 +35,7 @@ export type AgentConversationParticipant = {
export type AgentConversation = {
id: number
aiAgentId?: number
channelId?: number
customerId?: number
externalSource: string
externalId: string
+1
View File
@@ -33,6 +33,7 @@ export type ImConversationParticipant = {
export type ImConversation = {
id: number
channelId: number
externalSource: string
externalId: string
subject: string