Skip to content

Commit 84b88e6

Browse files
Adding settings to Dialogflow CX resources (#9078) (#16315)
[upstream:465cfd537dbbb13854796e5954994c4c4a3c92e6] Signed-off-by: Modular Magician <[email protected]>
1 parent cfa2c60 commit 84b88e6

23 files changed

+1651
-51
lines changed

.changelog/9078.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:enhancement
2+
dialogflowcx: added `advanced_settings`, `text_to_speech_settings`, `git_integration_settings` fields to `google_dialogflow_cx_agent` resource
3+
```
4+
```release-note:enhancement
5+
dialogflowcx: added `advanced_settings` field to `google_dialogflow_cx_flow` resource
6+
```
7+
```release-note:enhancement
8+
dialogflowcx: added `advanced_settings` fields to `google_dialogflow_cx_page` resource
9+
```

google/services/dialogflowcx/resource_dialogflow_cx_agent.go

+555
Large diffs are not rendered by default.

google/services/dialogflowcx/resource_dialogflow_cx_agent_generated_test.go

+43-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@ func TestAccDialogflowCXAgent_dialogflowcxAgentFullExample(t *testing.T) {
4949
ResourceName: "google_dialogflow_cx_agent.full_agent",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"location"},
52+
ImportStateVerifyIgnore: []string{"location", "git_integration_settings.0.github_settings.0.access_token"},
5353
},
5454
},
5555
})
5656
}
5757

5858
func testAccDialogflowCXAgent_dialogflowcxAgentFullExample(context map[string]interface{}) string {
5959
return acctest.Nprintf(`
60+
resource "google_storage_bucket" "bucket" {
61+
name = "tf-test-dialogflowcx-bucket%{random_suffix}"
62+
location = "US"
63+
uniform_bucket_level_access = true
64+
}
65+
6066
resource "google_dialogflow_cx_agent" "full_agent" {
6167
display_name = "tf-test-dialogflowcx-agent%{random_suffix}"
6268
location = "global"
@@ -67,9 +73,42 @@ resource "google_dialogflow_cx_agent" "full_agent" {
6773
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
6874
enable_stackdriver_logging = true
6975
enable_spell_correction = true
70-
speech_to_text_settings {
71-
enable_speech_adaptation = true
72-
}
76+
speech_to_text_settings {
77+
enable_speech_adaptation = true
78+
}
79+
advanced_settings {
80+
audio_export_gcs_destination {
81+
uri = "${google_storage_bucket.bucket.url}/prefix-"
82+
}
83+
dtmf_settings {
84+
enabled = true
85+
max_digits = 1
86+
finish_digit = "#"
87+
}
88+
}
89+
git_integration_settings {
90+
github_settings {
91+
display_name = "Github Repo"
92+
repository_uri = "https://api.github.com/repos/githubtraining/hellogitworld"
93+
tracking_branch = "main"
94+
access_token = "secret-token"
95+
branches = ["main"]
96+
}
97+
}
98+
text_to_speech_settings {
99+
synthesize_speech_configs = jsonencode({
100+
en = {
101+
voice = {
102+
name = "en-US-Neural2-A"
103+
}
104+
}
105+
fr = {
106+
voice = {
107+
name = "fr-CA-Neural2-A",
108+
}
109+
}
110+
})
111+
}
73112
}
74113
`, context)
75114
}

google/services/dialogflowcx/resource_dialogflow_cx_entity_type_generated_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ resource "google_dialogflow_cx_agent" "agent" {
6767
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
6868
enable_stackdriver_logging = true
6969
enable_spell_correction = true
70-
speech_to_text_settings {
71-
enable_speech_adaptation = true
72-
}
70+
speech_to_text_settings {
71+
enable_speech_adaptation = true
72+
}
7373
}
7474
7575

google/services/dialogflowcx/resource_dialogflow_cx_environment_generated_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ resource "google_dialogflow_cx_agent" "agent" {
6767
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
6868
enable_stackdriver_logging = true
6969
enable_spell_correction = true
70-
speech_to_text_settings {
71-
enable_speech_adaptation = true
72-
}
70+
speech_to_text_settings {
71+
enable_speech_adaptation = true
72+
}
7373
}
7474
7575
resource "google_dialogflow_cx_version" "version_1" {

google/services/dialogflowcx/resource_dialogflow_cx_flow.go

+245
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,64 @@ func ResourceDialogflowCXFlow() *schema.Resource {
5858
Required: true,
5959
Description: `The human-readable name of the flow.`,
6060
},
61+
"advanced_settings": {
62+
Type: schema.TypeList,
63+
Optional: true,
64+
Description: `Hierarchical advanced settings for this flow. The settings exposed at the lower level overrides the settings exposed at the higher level.
65+
Hierarchy: Agent->Flow->Page->Fulfillment/Parameter.`,
66+
MaxItems: 1,
67+
Elem: &schema.Resource{
68+
Schema: map[string]*schema.Schema{
69+
"audio_export_gcs_destination": {
70+
Type: schema.TypeList,
71+
Optional: true,
72+
Description: `If present, incoming audio is exported by Dialogflow to the configured Google Cloud Storage destination. Exposed at the following levels:
73+
* Agent level
74+
* Flow level`,
75+
MaxItems: 1,
76+
Elem: &schema.Resource{
77+
Schema: map[string]*schema.Schema{
78+
"uri": {
79+
Type: schema.TypeString,
80+
Optional: true,
81+
Description: `The Google Cloud Storage URI for the exported objects. Whether a full object name, or just a prefix, its usage depends on the Dialogflow operation.
82+
Format: gs://bucket/object-name-or-prefix`,
83+
},
84+
},
85+
},
86+
},
87+
"dtmf_settings": {
88+
Type: schema.TypeList,
89+
Optional: true,
90+
Description: `Define behaviors for DTMF (dual tone multi frequency). DTMF settings does not override each other. DTMF settings set at different levels define DTMF detections running in parallel. Exposed at the following levels:
91+
* Agent level
92+
* Flow level
93+
* Page level
94+
* Parameter level`,
95+
MaxItems: 1,
96+
Elem: &schema.Resource{
97+
Schema: map[string]*schema.Schema{
98+
"enabled": {
99+
Type: schema.TypeBool,
100+
Optional: true,
101+
Description: `If true, incoming audio is processed for DTMF (dual tone multi frequency) events. For example, if the caller presses a button on their telephone keypad and DTMF processing is enabled, Dialogflow will detect the event (e.g. a "3" was pressed) in the incoming audio and pass the event to the bot to drive business logic (e.g. when 3 is pressed, return the account balance).`,
102+
},
103+
"finish_digit": {
104+
Type: schema.TypeString,
105+
Optional: true,
106+
Description: `The digit that terminates a DTMF digit sequence.`,
107+
},
108+
"max_digits": {
109+
Type: schema.TypeInt,
110+
Optional: true,
111+
Description: `Max length of DTMF digits.`,
112+
},
113+
},
114+
},
115+
},
116+
},
117+
},
118+
},
61119
"description": {
62120
Type: schema.TypeString,
63121
Optional: true,
@@ -678,6 +736,12 @@ func resourceDialogflowCXFlowCreate(d *schema.ResourceData, meta interface{}) er
678736
} else if v, ok := d.GetOkExists("nlu_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(nluSettingsProp)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) {
679737
obj["nluSettings"] = nluSettingsProp
680738
}
739+
advancedSettingsProp, err := expandDialogflowCXFlowAdvancedSettings(d.Get("advanced_settings"), d, config)
740+
if err != nil {
741+
return err
742+
} else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(advancedSettingsProp)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) {
743+
obj["advancedSettings"] = advancedSettingsProp
744+
}
681745
languageCodeProp, err := expandDialogflowCXFlowLanguageCode(d.Get("language_code"), d, config)
682746
if err != nil {
683747
return err
@@ -805,6 +869,9 @@ func resourceDialogflowCXFlowRead(d *schema.ResourceData, meta interface{}) erro
805869
if err := d.Set("nlu_settings", flattenDialogflowCXFlowNluSettings(res["nluSettings"], d, config)); err != nil {
806870
return fmt.Errorf("Error reading Flow: %s", err)
807871
}
872+
if err := d.Set("advanced_settings", flattenDialogflowCXFlowAdvancedSettings(res["advancedSettings"], d, config)); err != nil {
873+
return fmt.Errorf("Error reading Flow: %s", err)
874+
}
808875
if err := d.Set("language_code", flattenDialogflowCXFlowLanguageCode(res["languageCode"], d, config)); err != nil {
809876
return fmt.Errorf("Error reading Flow: %s", err)
810877
}
@@ -858,6 +925,12 @@ func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) er
858925
} else if v, ok := d.GetOkExists("nlu_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) {
859926
obj["nluSettings"] = nluSettingsProp
860927
}
928+
advancedSettingsProp, err := expandDialogflowCXFlowAdvancedSettings(d.Get("advanced_settings"), d, config)
929+
if err != nil {
930+
return err
931+
} else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) {
932+
obj["advancedSettings"] = advancedSettingsProp
933+
}
861934

862935
url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows/{{name}}")
863936
if err != nil {
@@ -890,6 +963,10 @@ func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) er
890963
if d.HasChange("nlu_settings") {
891964
updateMask = append(updateMask, "nluSettings")
892965
}
966+
967+
if d.HasChange("advanced_settings") {
968+
updateMask = append(updateMask, "advancedSettings")
969+
}
893970
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
894971
// won't set it
895972
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -1710,6 +1787,80 @@ func flattenDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d *schem
17101787
return v
17111788
}
17121789

1790+
func flattenDialogflowCXFlowAdvancedSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1791+
if v == nil {
1792+
return nil
1793+
}
1794+
original := v.(map[string]interface{})
1795+
if len(original) == 0 {
1796+
return nil
1797+
}
1798+
transformed := make(map[string]interface{})
1799+
transformed["audio_export_gcs_destination"] =
1800+
flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(original["audioExportGcsDestination"], d, config)
1801+
transformed["dtmf_settings"] =
1802+
flattenDialogflowCXFlowAdvancedSettingsDtmfSettings(original["dtmfSettings"], d, config)
1803+
return []interface{}{transformed}
1804+
}
1805+
func flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1806+
if v == nil {
1807+
return nil
1808+
}
1809+
original := v.(map[string]interface{})
1810+
if len(original) == 0 {
1811+
return nil
1812+
}
1813+
transformed := make(map[string]interface{})
1814+
transformed["uri"] =
1815+
flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config)
1816+
return []interface{}{transformed}
1817+
}
1818+
func flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1819+
return v
1820+
}
1821+
1822+
func flattenDialogflowCXFlowAdvancedSettingsDtmfSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1823+
if v == nil {
1824+
return nil
1825+
}
1826+
original := v.(map[string]interface{})
1827+
if len(original) == 0 {
1828+
return nil
1829+
}
1830+
transformed := make(map[string]interface{})
1831+
transformed["enabled"] =
1832+
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config)
1833+
transformed["max_digits"] =
1834+
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(original["maxDigits"], d, config)
1835+
transformed["finish_digit"] =
1836+
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(original["finishDigit"], d, config)
1837+
return []interface{}{transformed}
1838+
}
1839+
func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1840+
return v
1841+
}
1842+
1843+
func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1844+
// Handles the string fixed64 format
1845+
if strVal, ok := v.(string); ok {
1846+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
1847+
return intVal
1848+
}
1849+
}
1850+
1851+
// number values are represented as float64
1852+
if floatVal, ok := v.(float64); ok {
1853+
intVal := int(floatVal)
1854+
return intVal
1855+
}
1856+
1857+
return v // let terraform core handle it otherwise
1858+
}
1859+
1860+
func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1861+
return v
1862+
}
1863+
17131864
func flattenDialogflowCXFlowLanguageCode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
17141865
return v
17151866
}
@@ -2774,6 +2925,100 @@ func expandDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d tpgreso
27742925
return v, nil
27752926
}
27762927

2928+
func expandDialogflowCXFlowAdvancedSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2929+
l := v.([]interface{})
2930+
if len(l) == 0 || l[0] == nil {
2931+
return nil, nil
2932+
}
2933+
raw := l[0]
2934+
original := raw.(map[string]interface{})
2935+
transformed := make(map[string]interface{})
2936+
2937+
transformedAudioExportGcsDestination, err := expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(original["audio_export_gcs_destination"], d, config)
2938+
if err != nil {
2939+
return nil, err
2940+
} else if val := reflect.ValueOf(transformedAudioExportGcsDestination); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2941+
transformed["audioExportGcsDestination"] = transformedAudioExportGcsDestination
2942+
}
2943+
2944+
transformedDtmfSettings, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettings(original["dtmf_settings"], d, config)
2945+
if err != nil {
2946+
return nil, err
2947+
} else if val := reflect.ValueOf(transformedDtmfSettings); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2948+
transformed["dtmfSettings"] = transformedDtmfSettings
2949+
}
2950+
2951+
return transformed, nil
2952+
}
2953+
2954+
func expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2955+
l := v.([]interface{})
2956+
if len(l) == 0 || l[0] == nil {
2957+
return nil, nil
2958+
}
2959+
raw := l[0]
2960+
original := raw.(map[string]interface{})
2961+
transformed := make(map[string]interface{})
2962+
2963+
transformedUri, err := expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config)
2964+
if err != nil {
2965+
return nil, err
2966+
} else if val := reflect.ValueOf(transformedUri); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2967+
transformed["uri"] = transformedUri
2968+
}
2969+
2970+
return transformed, nil
2971+
}
2972+
2973+
func expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2974+
return v, nil
2975+
}
2976+
2977+
func expandDialogflowCXFlowAdvancedSettingsDtmfSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2978+
l := v.([]interface{})
2979+
if len(l) == 0 || l[0] == nil {
2980+
return nil, nil
2981+
}
2982+
raw := l[0]
2983+
original := raw.(map[string]interface{})
2984+
transformed := make(map[string]interface{})
2985+
2986+
transformedEnabled, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config)
2987+
if err != nil {
2988+
return nil, err
2989+
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2990+
transformed["enabled"] = transformedEnabled
2991+
}
2992+
2993+
transformedMaxDigits, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(original["max_digits"], d, config)
2994+
if err != nil {
2995+
return nil, err
2996+
} else if val := reflect.ValueOf(transformedMaxDigits); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2997+
transformed["maxDigits"] = transformedMaxDigits
2998+
}
2999+
3000+
transformedFinishDigit, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(original["finish_digit"], d, config)
3001+
if err != nil {
3002+
return nil, err
3003+
} else if val := reflect.ValueOf(transformedFinishDigit); val.IsValid() && !tpgresource.IsEmptyValue(val) {
3004+
transformed["finishDigit"] = transformedFinishDigit
3005+
}
3006+
3007+
return transformed, nil
3008+
}
3009+
3010+
func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3011+
return v, nil
3012+
}
3013+
3014+
func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3015+
return v, nil
3016+
}
3017+
3018+
func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3019+
return v, nil
3020+
}
3021+
27773022
func expandDialogflowCXFlowLanguageCode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
27783023
return v, nil
27793024
}

0 commit comments

Comments
 (0)