From 991349899b64c7b08565cbfffaaba212582e6f63 Mon Sep 17 00:00:00 2001 From: Maciej Murakowski Date: Tue, 24 Oct 2023 11:46:45 -0400 Subject: [PATCH] Basic tests for default flow + intents --- mmv1/products/dialogflowcx/Flow.yaml | 11 +++ mmv1/products/dialogflowcx/Intent.yaml | 12 +++ ...ialogflowcx_flow_default_start_flow.tf.erb | 75 +++++++++++++++++++ ...owcx_intent_default_negative_intent.tf.erb | 20 +++++ ...lowcx_intent_default_welcome_intent.tf.erb | 20 +++++ ...lowcx_set_location_skip_default_obj.go.erb | 1 + 6 files changed, 139 insertions(+) create mode 100644 mmv1/templates/terraform/examples/dialogflowcx_flow_default_start_flow.tf.erb create mode 100644 mmv1/templates/terraform/examples/dialogflowcx_intent_default_negative_intent.tf.erb create mode 100644 mmv1/templates/terraform/examples/dialogflowcx_intent_default_welcome_intent.tf.erb diff --git a/mmv1/products/dialogflowcx/Flow.yaml b/mmv1/products/dialogflowcx/Flow.yaml index 5e014e659328..6c3d58650bcd 100644 --- a/mmv1/products/dialogflowcx/Flow.yaml +++ b/mmv1/products/dialogflowcx/Flow.yaml @@ -39,12 +39,23 @@ virtual_fields: Marks this as the [Default Start Flow](https://cloud.google.com/dialogflow/cx/docs/concept/flow#start) for an agent. When you create an agent, the Default Start Flow is created automatically. The Default Start Flow cannot be deleted; deleting the `google_dialogflow_cx_flow` resource does nothing to the underlying GCP resources. examples: + - !ruby/object:Provider::Terraform::Examples + name: 'dialogflowcx_flow_basic' + primary_resource_id: 'basic_flow' + vars: + agent_name: 'dialogflowcx-agent' - !ruby/object:Provider::Terraform::Examples name: 'dialogflowcx_flow_full' primary_resource_id: 'basic_flow' vars: agent_name: 'dialogflowcx-agent' bucket_name: 'dialogflowcx-bucket' + - !ruby/object:Provider::Terraform::Examples + skip_docs: true + name: 'dialogflowcx_flow_default_start_flow' + primary_resource_id: 'default_start_flow' + vars: + agent_name: 'dialogflowcx-agent' skip_sweeper: true id_format: '{{parent}}/flows/{{name}}' import_format: ['{{parent}}/flows/{{name}}'] diff --git a/mmv1/products/dialogflowcx/Intent.yaml b/mmv1/products/dialogflowcx/Intent.yaml index 9555ed6b4122..811895849dfb 100644 --- a/mmv1/products/dialogflowcx/Intent.yaml +++ b/mmv1/products/dialogflowcx/Intent.yaml @@ -50,6 +50,18 @@ examples: primary_resource_id: 'basic_intent' vars: agent_name: 'dialogflowcx-agent' + - !ruby/object:Provider::Terraform::Examples + skip_docs: true + name: 'dialogflowcx_intent_default_negative_intent' + primary_resource_id: 'default_negative_intent' + vars: + agent_name: 'dialogflowcx-agent' + - !ruby/object:Provider::Terraform::Examples + skip_docs: true + name: 'dialogflowcx_intent_default_welcome_intent' + primary_resource_id: 'default_welcome_intent' + vars: + agent_name: 'dialogflowcx-agent' skip_sweeper: true id_format: '{{parent}}/intents/{{name}}' import_format: ['{{parent}}/intents/{{name}}'] diff --git a/mmv1/templates/terraform/examples/dialogflowcx_flow_default_start_flow.tf.erb b/mmv1/templates/terraform/examples/dialogflowcx_flow_default_start_flow.tf.erb new file mode 100644 index 000000000000..aca50d5b5978 --- /dev/null +++ b/mmv1/templates/terraform/examples/dialogflowcx_flow_default_start_flow.tf.erb @@ -0,0 +1,75 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "<%= ctx[:vars]["agent_name"] %>" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + +resource "google_dialogflow_cx_intent" "default_welcome_intent" { + parent = google_dialogflow_cx_agent.agent.id + is_default_welcome_intent = true + display_name = "Default Welcome Intent" + priority = 1 + training_phrases { + parts { + text = "Hello" + } + repeat_count = 1 + } +} + + +resource "google_dialogflow_cx_flow" "<%= ctx[:primary_resource_id] %>" { + parent = google_dialogflow_cx_agent.agent.id + is_default_start_flow = true + display_name = "Default Start Flow" + + nlu_settings { + classification_threshold = 0.3 + model_type = "MODEL_TYPE_STANDARD" + } + + transition_routes { + intent = google_dialogflow_cx_intent.default_welcome_intent.id + trigger_fulfillment { + messages { + text { + text = ["Response to default welcome intent."] + } + } + } + } + + event_handlers { + event = "custom-event" + trigger_fulfillment { + messages { + text { + text = ["This is a default flow."] + } + } + } + } + + event_handlers { + event = "sys.no-match-default" + trigger_fulfillment { + messages { + text { + text = ["We've updated the default flow no-match response!"] + } + } + } + } + + event_handlers { + event = "sys.no-input-default" + trigger_fulfillment { + messages { + text { + text = ["We've updated the default flow no-input response!"] + } + } + } + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/dialogflowcx_intent_default_negative_intent.tf.erb b/mmv1/templates/terraform/examples/dialogflowcx_intent_default_negative_intent.tf.erb new file mode 100644 index 000000000000..11ba4fad9507 --- /dev/null +++ b/mmv1/templates/terraform/examples/dialogflowcx_intent_default_negative_intent.tf.erb @@ -0,0 +1,20 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "<%= ctx[:vars]["agent_name"] %>" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + + +resource "google_dialogflow_cx_intent" "<%= ctx[:primary_resource_id] %>" { + parent = google_dialogflow_cx_agent.agent.id + is_default_negative_intent = true + display_name = "Default Negative Intent" + priority = 1 + training_phrases { + parts { + text = "Never match this phrase" + } + repeat_count = 1 + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/dialogflowcx_intent_default_welcome_intent.tf.erb b/mmv1/templates/terraform/examples/dialogflowcx_intent_default_welcome_intent.tf.erb new file mode 100644 index 000000000000..0772b2bdde78 --- /dev/null +++ b/mmv1/templates/terraform/examples/dialogflowcx_intent_default_welcome_intent.tf.erb @@ -0,0 +1,20 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "<%= ctx[:vars]["agent_name"] %>" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + + +resource "google_dialogflow_cx_intent" "<%= ctx[:primary_resource_id] %>" { + parent = google_dialogflow_cx_agent.agent.id + is_default_welcome_intent = true + display_name = "Default Welcome Intent" + priority = 1 + training_phrases { + parts { + text = "Hello" + } + repeat_count = 1 + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb b/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb index 8f42c34a82f2..38ae53db7e19 100644 --- a/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb +++ b/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb @@ -37,5 +37,6 @@ if isDefaultStartFlow || isDefaultWelcomeIntent || isDefaultNegativeIntent { d.SetId(id) // and defer to the Update method: + log.Printf("[DEBUG] Updating default <%= resource_name -%>") return resource<%= resource_name -%>Update(d, meta) } \ No newline at end of file