Files
gochat/internal/model/custom_attribute_definition.go
T
2026-06-04 15:44:48 +08:00

30 lines
2.2 KiB
Go

package model
import "gorm.io/datatypes"
// CustomAttributeDefinition defines a custom attribute schema for conversations or contacts.
// Reference: Chatwoot app/models/custom_attribute_definition.rb
// Account-scoped: each definition belongs to an account and applies to either
// conversation or contact models (attribute_model field).
//
// Chatwoot compatibility notes:
// - JSON uses "attribute_key" (Chatwoot name) as alias for attribute_name
// - JSON uses "attribute_display_type" (Chatwoot name) as alias for attribute_type
// - JSON uses "attribute_description" (Chatwoot name) as alias for description
// - attribute_values stores predefined options for list-type attributes
// - regex_pattern / regex_cue provide input validation beyond type checking
type CustomAttributeDefinition struct {
Base
AccountID uint `gorm:"index;not null" json:"account_id"`
AttributeName string `gorm:"size:255;not null;uniqueIndex:idx_attr_name_account_model" json:"attribute_key"` // Chatwoot: attribute_key
AttributeDisplayName string `gorm:"size:255;not null" json:"attribute_display_name"`
AttributeType string `gorm:"size:50;not null;default:text" json:"attribute_display_type"` // Chatwoot: attribute_display_type; text, number, date, checkbox, list, link
AttributeModel string `gorm:"size:50;not null;uniqueIndex:idx_attr_name_account_model" json:"attribute_model"` // conversation, contact
DefaultValue datatypes.JSON `gorm:"type:jsonb" json:"default_value,omitempty"`
AttributeValues datatypes.JSON `gorm:"type:jsonb" json:"attribute_values,omitempty"` // Chatwoot: predefined valid values for list-type attributes
RegexPattern string `gorm:"size:255" json:"regex_pattern,omitempty"` // Chatwoot: regex validation pattern
RegexCue string `gorm:"size:255" json:"regex_cue,omitempty"` // Chatwoot: human-readable hint about the regex constraint
Description string `gorm:"type:text" json:"attribute_description,omitempty"` // Chatwoot: attribute_description
}
func (CustomAttributeDefinition) TableName() string { return "custom_attribute_definitions" }