package model import "gorm.io/datatypes" // PreChatForm stores the pre-chat form configuration for a web widget inbox. // Reference: Chatwoot app/models/channel/web_widget.rb — pre_chat_form_settings attribute // When enabled, visitors must fill out a form before starting a conversation. // The form collects contact info (name, email, phone) and custom fields. type PreChatForm struct { Base InboxID uint `gorm:"index;not null" json:"inbox_id"` Enabled bool `gorm:"default:false" json:"enabled"` // Whether the pre-chat form is shown Message string `gorm:"size:500;default:'Please fill the form below'" json:"message"` // Introductory message RequireName bool `gorm:"default:true" json:"require_name"` // Require visitor name RequireEmail bool `gorm:"default:true" json:"require_email"` // Require visitor email RequirePhone bool `gorm:"default:false" json:"require_phone"` // Require visitor phone ShowPhoneNumber bool `gorm:"default:false" json:"show_phone_number"` // Show phone field (not required) ShowCompany bool `gorm:"default:false" json:"show_company"` // Show company name field ShowCity bool `gorm:"default:false" json:"show_city"` // Show city field ShowCountry bool `gorm:"default:false" json:"show_country"` // Show country field ConsentEnabled bool `gorm:"default:false" json:"consent_enabled"` // Show GDPR consent checkbox ConsentMessage string `gorm:"size:1000" json:"consent_message,omitempty"` // GDPR consent message text ConsentLink string `gorm:"size:512" json:"consent_link,omitempty"` // Link to privacy policy CustomFields datatypes.JSON `gorm:"type:jsonb" json:"custom_fields,omitempty"` // JSON array of custom field definitions Inbox Inbox `gorm:"foreignKey:InboxID" json:"inbox,omitempty"` } func (PreChatForm) TableName() string { return "pre_chat_forms" } // PreChatCustomField defines a custom field on the pre-chat form. type PreChatCustomField struct { Name string `json:"name"` // Field display name Label string `json:"label"` // Label shown to user Type string `json:"type"` // "text", "email", "phone", "select", "checkbox", "date" Required bool `json:"required"` // Whether this field is mandatory Placeholder string `json:"placeholder"` // Placeholder text in input Options []string `json:"options,omitempty"` // Options for "select" type fields DefaultValue string `json:"default_value,omitempty"` // Default value } // PreChatFormSubmission represents a submitted pre-chat form from a widget visitor. // This is stored as part of the contact's additional_attributes or conversation metadata. type PreChatFormSubmission struct { Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` Phone string `json:"phone_number,omitempty"` Company string `json:"company_name,omitempty"` City string `json:"city,omitempty"` Country string `json:"country,omitempty"` Consent bool `json:"consent_accepted,omitempty"` Custom map[string]interface{} `json:"custom_fields,omitempty"` }