55 lines
2.6 KiB
Go
55 lines
2.6 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
// Account represents a tenant/organization in the system.
|
|
type Account struct {
|
|
Base
|
|
Name string `gorm:"size:255;not null" json:"name"`
|
|
Domain string `gorm:"size:255" json:"domain,omitempty"`
|
|
Locale string `gorm:"size:10;default:zh_CN" json:"locale"`
|
|
Timezone string `gorm:"size:50;default:UTC" json:"timezone"`
|
|
ReportingTimezone string `gorm:"size:100" json:"reporting_timezone,omitempty"`
|
|
Active bool `gorm:"default:true" json:"active"`
|
|
Status string `gorm:"size:50;default:active" json:"status"`
|
|
OnboardingStep string `gorm:"size:100" json:"onboarding_step,omitempty"`
|
|
CustomAttributes datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"custom_attributes,omitempty"`
|
|
FeatureFlags string `gorm:"type:text" json:"feature_flags,omitempty"` // JSON-encoded feature flags
|
|
AutoResolveDuration int `gorm:"default:0" json:"auto_resolve_duration,omitempty"` // days
|
|
AudioTranscriptions bool `gorm:"default:false" json:"audio_transcriptions"`
|
|
Limits datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"limits,omitempty"` // Chatwoot account limits, e.g. emails
|
|
AgentLimit int `gorm:"default:0" json:"agent_limit,omitempty"` // max agents allowed (0 = unlimited), Chatwoot usage_limits[:agents]
|
|
InboxLimit int `gorm:"default:0" json:"inbox_limit,omitempty"` // max inboxes allowed (0 = unlimited), Chatwoot usage_limits[:inboxes]
|
|
CaptainModels datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"captain_models,omitempty"`
|
|
CaptainFeatures datatypes.JSON `gorm:"type:jsonb;default:'{}'" json:"captain_features,omitempty"`
|
|
// Chatwoot: store_accessor :settings, :keep_pending_on_bot_failure
|
|
// When true, agent bot webhook failures do NOT reopen pending conversations.
|
|
KeepPendingOnBotFailure bool `gorm:"default:false" json:"keep_pending_on_bot_failure,omitempty"`
|
|
}
|
|
|
|
func (Account) TableName() string { return "accounts" }
|
|
|
|
func (a *Account) CustomAttributesMap() map[string]any {
|
|
attrs := map[string]any{}
|
|
if len(a.CustomAttributes) > 0 {
|
|
_ = json.Unmarshal(a.CustomAttributes, &attrs)
|
|
}
|
|
return attrs
|
|
}
|
|
|
|
func (a *Account) SetCustomAttributesMap(attrs map[string]any) error {
|
|
if attrs == nil {
|
|
attrs = map[string]any{}
|
|
}
|
|
encoded, err := json.Marshal(attrs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
a.CustomAttributes = datatypes.JSON(encoded)
|
|
return nil
|
|
}
|