feat(accounts): serialize enabled features
This commit is contained in:
@@ -461,13 +461,74 @@ func serializeAccountSettings(account *model.Account) map[string]any {
|
||||
return settings
|
||||
}
|
||||
|
||||
func parseAccountFeatures(raw string) map[string]any {
|
||||
features := map[string]any{}
|
||||
var chatwootDefaultEnabledAccountFeatures = []string{
|
||||
"inbound_emails",
|
||||
"channel_email",
|
||||
"channel_facebook",
|
||||
"help_center",
|
||||
"agent_bots",
|
||||
"macros",
|
||||
"agent_management",
|
||||
"team_management",
|
||||
"inbox_management",
|
||||
"labels",
|
||||
"custom_attributes",
|
||||
"automations",
|
||||
"canned_responses",
|
||||
"integrations",
|
||||
"voice_recorder",
|
||||
"channel_website",
|
||||
"campaigns",
|
||||
"reports",
|
||||
"crm",
|
||||
"auto_resolve_conversations",
|
||||
"chatwoot_v4",
|
||||
"contact_chatwoot_support_team",
|
||||
"channel_instagram",
|
||||
"channel_tiktok",
|
||||
"assignment_v2",
|
||||
"captain_tasks",
|
||||
}
|
||||
|
||||
func parseAccountFeatures(raw string) map[string]bool {
|
||||
features := defaultEnabledAccountFeatures()
|
||||
if raw == "" {
|
||||
return features
|
||||
return onlyEnabledAccountFeatures(features)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(raw), &features); err != nil {
|
||||
return features
|
||||
|
||||
objectFlags := map[string]bool{}
|
||||
if err := json.Unmarshal([]byte(raw), &objectFlags); err == nil {
|
||||
for key, enabled := range objectFlags {
|
||||
features[key] = enabled
|
||||
}
|
||||
return onlyEnabledAccountFeatures(features)
|
||||
}
|
||||
|
||||
arrayFlags := []string{}
|
||||
if err := json.Unmarshal([]byte(raw), &arrayFlags); err == nil {
|
||||
for _, key := range arrayFlags {
|
||||
features[key] = true
|
||||
}
|
||||
return onlyEnabledAccountFeatures(features)
|
||||
}
|
||||
|
||||
return onlyEnabledAccountFeatures(features)
|
||||
}
|
||||
|
||||
func defaultEnabledAccountFeatures() map[string]bool {
|
||||
features := make(map[string]bool, len(chatwootDefaultEnabledAccountFeatures))
|
||||
for _, key := range chatwootDefaultEnabledAccountFeatures {
|
||||
features[key] = true
|
||||
}
|
||||
return features
|
||||
}
|
||||
|
||||
func onlyEnabledAccountFeatures(features map[string]bool) map[string]bool {
|
||||
enabled := map[string]bool{}
|
||||
for key, value := range features {
|
||||
if value {
|
||||
enabled[key] = true
|
||||
}
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user