Preserve campaign defaults in materialized sessions
This commit is contained in:
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -49,18 +50,35 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
if id == "" {
|
||||
id = sessionID
|
||||
}
|
||||
result := doc.ConfigKitResult()
|
||||
var metadata configkit.Metadata
|
||||
if result != nil {
|
||||
metadata = result.Metadata()
|
||||
}
|
||||
// Materialized sessions retain authored overrides and receiving-campaign defaults.
|
||||
inputValue := func(name, value string) *string {
|
||||
if result != nil {
|
||||
if !metadata.IsExplicit(configkit.Keys("inputs", name)) {
|
||||
return nil
|
||||
}
|
||||
} else if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
inputs := struct {
|
||||
AudioDir string `yaml:"audio_dir,omitempty"`
|
||||
AudioFiles []string `yaml:"audio_files,omitempty"`
|
||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
||||
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
||||
GlossaryFile string `yaml:"glossary_file,omitempty"`
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile *string `yaml:"autocorrect_file,omitempty"`
|
||||
GlossaryFile *string `yaml:"glossary_file,omitempty"`
|
||||
SpellCatalogFile *string `yaml:"spell_catalog_file,omitempty"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3, doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.GlossaryFile, nil}
|
||||
if doc.Inputs.SpellCatalogFile != "" || sessionFieldExplicit(doc, "spell_catalog_file") {
|
||||
inputs.SpellCatalogFile = &doc.Inputs.SpellCatalogFile
|
||||
}
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
inputValue("autocorrect_file", doc.Inputs.AutocorrectFile),
|
||||
inputValue("glossary_file", doc.Inputs.GlossaryFile),
|
||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile)}
|
||||
value := struct {
|
||||
SessionID string `yaml:"session_id"`
|
||||
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user