55 lines
3.7 KiB
Go
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
|
|
} |