Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding settings to Dialogflow CX resources #16315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changelog/9078.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
dialogflowcx: added `advanced_settings`, `text_to_speech_settings`, `git_integration_settings` fields to `google_dialogflow_cx_agent` resource
```
```release-note:enhancement
dialogflowcx: added `advanced_settings` field to `google_dialogflow_cx_flow` resource
```
```release-note:enhancement
dialogflowcx: added `advanced_settings` fields to `google_dialogflow_cx_page` resource
```
555 changes: 555 additions & 0 deletions google/services/dialogflowcx/resource_dialogflow_cx_agent.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ func TestAccDialogflowCXAgent_dialogflowcxAgentFullExample(t *testing.T) {
ResourceName: "google_dialogflow_cx_agent.full_agent",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
ImportStateVerifyIgnore: []string{"location", "git_integration_settings.0.github_settings.0.access_token"},
},
},
})
}

func testAccDialogflowCXAgent_dialogflowcxAgentFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "bucket" {
name = "tf-test-dialogflowcx-bucket%{random_suffix}"
location = "US"
uniform_bucket_level_access = true
}
resource "google_dialogflow_cx_agent" "full_agent" {
display_name = "tf-test-dialogflowcx-agent%{random_suffix}"
location = "global"
Expand All @@ -67,9 +73,42 @@ resource "google_dialogflow_cx_agent" "full_agent" {
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
enable_stackdriver_logging = true
enable_spell_correction = true
speech_to_text_settings {
enable_speech_adaptation = true
}
speech_to_text_settings {
enable_speech_adaptation = true
}
advanced_settings {
audio_export_gcs_destination {
uri = "${google_storage_bucket.bucket.url}/prefix-"
}
dtmf_settings {
enabled = true
max_digits = 1
finish_digit = "#"
}
}
git_integration_settings {
github_settings {
display_name = "Github Repo"
repository_uri = "https://api.github.com/repos/githubtraining/hellogitworld"
tracking_branch = "main"
access_token = "secret-token"
branches = ["main"]
}
}
text_to_speech_settings {
synthesize_speech_configs = jsonencode({
en = {
voice = {
name = "en-US-Neural2-A"
}
}
fr = {
voice = {
name = "fr-CA-Neural2-A",
}
}
})
}
}
`, context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ resource "google_dialogflow_cx_agent" "agent" {
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
enable_stackdriver_logging = true
enable_spell_correction = true
speech_to_text_settings {
enable_speech_adaptation = true
}
speech_to_text_settings {
enable_speech_adaptation = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ resource "google_dialogflow_cx_agent" "agent" {
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
enable_stackdriver_logging = true
enable_spell_correction = true
speech_to_text_settings {
enable_speech_adaptation = true
}
speech_to_text_settings {
enable_speech_adaptation = true
}
}
resource "google_dialogflow_cx_version" "version_1" {
Expand Down
245 changes: 245 additions & 0 deletions google/services/dialogflowcx/resource_dialogflow_cx_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,64 @@ func ResourceDialogflowCXFlow() *schema.Resource {
Required: true,
Description: `The human-readable name of the flow.`,
},
"advanced_settings": {
Type: schema.TypeList,
Optional: true,
Description: `Hierarchical advanced settings for this flow. The settings exposed at the lower level overrides the settings exposed at the higher level.
Hierarchy: Agent->Flow->Page->Fulfillment/Parameter.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"audio_export_gcs_destination": {
Type: schema.TypeList,
Optional: true,
Description: `If present, incoming audio is exported by Dialogflow to the configured Google Cloud Storage destination. Exposed at the following levels:
* Agent level
* Flow level`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Optional: true,
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.
Format: gs://bucket/object-name-or-prefix`,
},
},
},
},
"dtmf_settings": {
Type: schema.TypeList,
Optional: true,
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:
* Agent level
* Flow level
* Page level
* Parameter level`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
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).`,
},
"finish_digit": {
Type: schema.TypeString,
Optional: true,
Description: `The digit that terminates a DTMF digit sequence.`,
},
"max_digits": {
Type: schema.TypeInt,
Optional: true,
Description: `Max length of DTMF digits.`,
},
},
},
},
},
},
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -678,6 +736,12 @@ func resourceDialogflowCXFlowCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("nlu_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(nluSettingsProp)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) {
obj["nluSettings"] = nluSettingsProp
}
advancedSettingsProp, err := expandDialogflowCXFlowAdvancedSettings(d.Get("advanced_settings"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(advancedSettingsProp)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) {
obj["advancedSettings"] = advancedSettingsProp
}
languageCodeProp, err := expandDialogflowCXFlowLanguageCode(d.Get("language_code"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -805,6 +869,9 @@ func resourceDialogflowCXFlowRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("nlu_settings", flattenDialogflowCXFlowNluSettings(res["nluSettings"], d, config)); err != nil {
return fmt.Errorf("Error reading Flow: %s", err)
}
if err := d.Set("advanced_settings", flattenDialogflowCXFlowAdvancedSettings(res["advancedSettings"], d, config)); err != nil {
return fmt.Errorf("Error reading Flow: %s", err)
}
if err := d.Set("language_code", flattenDialogflowCXFlowLanguageCode(res["languageCode"], d, config)); err != nil {
return fmt.Errorf("Error reading Flow: %s", err)
}
Expand Down Expand Up @@ -858,6 +925,12 @@ func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("nlu_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) {
obj["nluSettings"] = nluSettingsProp
}
advancedSettingsProp, err := expandDialogflowCXFlowAdvancedSettings(d.Get("advanced_settings"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) {
obj["advancedSettings"] = advancedSettingsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows/{{name}}")
if err != nil {
Expand Down Expand Up @@ -890,6 +963,10 @@ func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) er
if d.HasChange("nlu_settings") {
updateMask = append(updateMask, "nluSettings")
}

if d.HasChange("advanced_settings") {
updateMask = append(updateMask, "advancedSettings")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -1710,6 +1787,80 @@ func flattenDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d *schem
return v
}

func flattenDialogflowCXFlowAdvancedSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["audio_export_gcs_destination"] =
flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(original["audioExportGcsDestination"], d, config)
transformed["dtmf_settings"] =
flattenDialogflowCXFlowAdvancedSettingsDtmfSettings(original["dtmfSettings"], d, config)
return []interface{}{transformed}
}
func flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["uri"] =
flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config)
return []interface{}{transformed}
}
func flattenDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDialogflowCXFlowAdvancedSettingsDtmfSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["enabled"] =
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config)
transformed["max_digits"] =
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(original["maxDigits"], d, config)
transformed["finish_digit"] =
flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(original["finishDigit"], d, config)
return []interface{}{transformed}
}
func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDialogflowCXFlowLanguageCode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -2774,6 +2925,100 @@ func expandDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d tpgreso
return v, nil
}

func expandDialogflowCXFlowAdvancedSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedAudioExportGcsDestination, err := expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(original["audio_export_gcs_destination"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAudioExportGcsDestination); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["audioExportGcsDestination"] = transformedAudioExportGcsDestination
}

transformedDtmfSettings, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettings(original["dtmf_settings"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDtmfSettings); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["dtmfSettings"] = transformedDtmfSettings
}

return transformed, nil
}

func expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedUri, err := expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUri); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["uri"] = transformedUri
}

return transformed, nil
}

func expandDialogflowCXFlowAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDialogflowCXFlowAdvancedSettingsDtmfSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedEnabled, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["enabled"] = transformedEnabled
}

transformedMaxDigits, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(original["max_digits"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxDigits); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["maxDigits"] = transformedMaxDigits
}

transformedFinishDigit, err := expandDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(original["finish_digit"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedFinishDigit); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["finishDigit"] = transformedFinishDigit
}

return transformed, nil
}

func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDialogflowCXFlowAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDialogflowCXFlowLanguageCode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Loading