Files
gochat/backend/internal/model/pre_chat_form.go
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

53 lines
3.4 KiB
Go

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"`
}