Files
gochat/backend/internal/model/widget_offline_message.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

55 lines
3.7 KiB
Go

package model
import "time"
// WidgetOfflineMessage stores messages submitted by visitors when no agents are online.
// Reference: Chatwoot app/models/channel/web_widget.rb — agent_away_message + offline messaging
//
// When a visitor sends a message via the widget and no agents are available
// (based on business hours or agent presence), the message is stored as an offline
// message. When an agent becomes available, the offline message is converted into
// a conversation automatically.
//
// This replaces the simpler approach of just showing an away message — visitors
// can still leave their contact info and message, which creates a pending conversation
// that agents can respond to when they return.
type WidgetOfflineMessage struct {
Base
InboxID uint `gorm:"index;not null" json:"inbox_id"` // The web_widget inbox
AccountID uint `gorm:"index;not null" json:"account_id"` // Account scope for the message
ContactName string `gorm:"size:255" json:"contact_name,omitempty"` // Visitor name (from pre-chat form or anonymous)
ContactEmail string `gorm:"size:512" json:"contact_email,omitempty"` // Visitor email (from pre-chat form)
ContactPhone string `gorm:"size:30" json:"contact_phone,omitempty"` // Visitor phone (from pre-chat form)
ContactCompany string `gorm:"size:255" json:"contact_company,omitempty"` // Visitor company (from pre-chat form)
ContactCity string `gorm:"size:255" json:"contact_city,omitempty"` // Visitor city (from pre-chat form)
ContactCountry string `gorm:"size:255" json:"contact_country,omitempty"` // Visitor country (from pre-chat form)
Content string `gorm:"type:text;not null" json:"content"` // The message content
Referer string `gorm:"size:1024" json:"referer,omitempty"` // Page URL where widget was embedded
BrowserInfo string `gorm:"size:512" json:"browser_info,omitempty"` // Browser metadata
ConversationID *uint `gorm:"index" json:"conversation_id,omitempty"` // Set when converted to a conversation (null until then)
Status OfflineStatus `gorm:"size:30;default:'pending'" json:"status"` // pending → converted → dismissed
ConvertedAt *time.Time `json:"converted_at,omitempty"` // When the message was converted to a conversation
}
func (WidgetOfflineMessage) TableName() string { return "widget_offline_messages" }
// OfflineStatus represents the lifecycle of an offline message.
type OfflineStatus string
const (
OfflineStatusPending OfflineStatus = "pending" // Awaiting agent to come online
OfflineStatusConverted OfflineStatus = "converted" // Converted into a conversation
OfflineStatusDismissed OfflineStatus = "dismissed" // Dismissed by admin without conversion
)
// WidgetOfflineMessageSubmission is the request body from the widget SDK
// when a visitor submits a message while agents are offline.
type WidgetOfflineMessageSubmission struct {
Name string `json:"name,omitempty"` // Visitor name
Email string `json:"email,omitempty"` // Visitor email
Phone string `json:"phone,omitempty"` // Visitor phone
Company string `json:"company,omitempty"` // Visitor company
City string `json:"city,omitempty"` // Visitor city
Country string `json:"country,omitempty"` // Visitor country
Message string `json:"message" binding:"required"` // The offline message content
}