From 629667367d7098cfb62bae1b6e48cc11a72b9fbc Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 5 Nov 2021 09:16:12 +0000 Subject: [PATCH] feat(v2): added support to configure security settings, language code and time zone on conversation profile (#431) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 407663596 Source-Link: https://github.com/googleapis/googleapis/commit/f9acb378c691a7ac449fd9fb32aa25aee14814d8 Source-Link: https://github.com/googleapis/googleapis-gen/commit/aa54a757068f005ab21064fb208a5ec597e49a9a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWE1NGE3NTcwNjhmMDA1YWIyMTA2NGZiMjA4YTVlYzU5N2U0OWE5YSJ9 --- .../conversation_profiles/async_client.py | 6 ++ .../services/conversation_profiles/client.py | 18 ++++ .../types/conversation_profile.py | 42 ++++++--- .../test_conversation_profiles.py | 94 ++++++++++++++----- 4 files changed, 126 insertions(+), 34 deletions(-) diff --git a/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py b/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py index b25601df2..1b0a35ba4 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py @@ -65,6 +65,12 @@ class ConversationProfilesAsyncClient: parse_conversation_profile_path = staticmethod( ConversationProfilesClient.parse_conversation_profile_path ) + cx_security_settings_path = staticmethod( + ConversationProfilesClient.cx_security_settings_path + ) + parse_cx_security_settings_path = staticmethod( + ConversationProfilesClient.parse_cx_security_settings_path + ) document_path = staticmethod(ConversationProfilesClient.document_path) parse_document_path = staticmethod(ConversationProfilesClient.parse_document_path) knowledge_base_path = staticmethod(ConversationProfilesClient.knowledge_base_path) diff --git a/google/cloud/dialogflow_v2/services/conversation_profiles/client.py b/google/cloud/dialogflow_v2/services/conversation_profiles/client.py index 3af5b23f5..ddf897641 100644 --- a/google/cloud/dialogflow_v2/services/conversation_profiles/client.py +++ b/google/cloud/dialogflow_v2/services/conversation_profiles/client.py @@ -212,6 +212,24 @@ def parse_conversation_profile_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def cx_security_settings_path( + project: str, location: str, security_settings: str, + ) -> str: + """Returns a fully-qualified cx_security_settings string.""" + return "projects/{project}/locations/{location}/securitySettings/{security_settings}".format( + project=project, location=location, security_settings=security_settings, + ) + + @staticmethod + def parse_cx_security_settings_path(path: str) -> Dict[str, str]: + """Parses a cx_security_settings path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/securitySettings/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def document_path(project: str, knowledge_base: str, document: str,) -> str: """Returns a fully-qualified document string.""" diff --git a/google/cloud/dialogflow_v2/types/conversation_profile.py b/google/cloud/dialogflow_v2/types/conversation_profile.py index 134709715..e9fe936b0 100644 --- a/google/cloud/dialogflow_v2/types/conversation_profile.py +++ b/google/cloud/dialogflow_v2/types/conversation_profile.py @@ -80,11 +80,21 @@ class ConversationProfile(proto.Message): stt_config (google.cloud.dialogflow_v2.types.SpeechToTextConfig): Settings for speech transcription. language_code (str): - Language which represents the - conversationProfile. If unspecified, the default - language code en-us applies. Users need to - create a ConversationProfile for each language - they want to support. + Language code for the conversation profile. If not + specified, the language is en-US. Language at + ConversationProfile should be set for all non en-US + languages. This should be a + `BCP-47 `__ + language tag. Example: "en-US". + time_zone (str): + The time zone of this conversational profile from the `time + zone database `__, e.g., + America/New_York, Europe/Paris. Defaults to + America/New_York. + security_settings (str): + Name of the CX SecuritySettings reference for the agent. + Format: + ``projects//locations//securitySettings/``. """ name = proto.Field(proto.STRING, number=1,) @@ -115,6 +125,8 @@ class ConversationProfile(proto.Message): proto.MESSAGE, number=9, message=audio_config.SpeechToTextConfig, ) language_code = proto.Field(proto.STRING, number=10,) + time_zone = proto.Field(proto.STRING, number=14,) + security_settings = proto.Field(proto.STRING, number=13,) class ListConversationProfilesRequest(proto.Message): @@ -245,12 +257,17 @@ class AutomatedAgentConfig(proto.Message): ``service-@gcp-sa-dialogflow.iam.gserviceaccount.com`` the ``Dialogflow API Service Agent`` role in this project. - Format: - ``projects//locations//agent/environments/``. - If environment is not specified, the default ``draft`` - environment is used. Refer to - `DetectIntentRequest `__ - for more details. + - For ES agents, use format: + ``projects//locations//agent/environments/``. + If environment is not specified, the default ``draft`` + environment is used. Refer to + `DetectIntentRequest `__ + for more details. + + - For CX agents, use format + ``projects//locations//agents//environments/``. + If environment is not specified, the default ``draft`` + environment is used. """ agent = proto.Field(proto.STRING, number=1,) @@ -409,7 +426,8 @@ class SuggestionQueryConfig(proto.Message): If this field is not set, it defaults to 0.0, which means that all suggestions are returned. - Supported features: ARTICLE_SUGGESTION. + Supported features: ARTICLE_SUGGESTION, FAQ, SMART_REPLY, + SMART_COMPOSE. context_filter_settings (google.cloud.dialogflow_v2.types.HumanAgentAssistantConfig.SuggestionQueryConfig.ContextFilterSettings): Determines how recent conversation context is filtered when generating suggestions. If diff --git a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py index a826e3395..3f340a429 100644 --- a/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py +++ b/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py @@ -943,6 +943,8 @@ def test_get_conversation_profile( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) response = client.get_conversation_profile(request) @@ -956,6 +958,8 @@ def test_get_conversation_profile( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" def test_get_conversation_profile_from_dict(): @@ -1002,6 +1006,8 @@ async def test_get_conversation_profile_async( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) ) response = await client.get_conversation_profile(request) @@ -1016,6 +1022,8 @@ async def test_get_conversation_profile_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" @pytest.mark.asyncio @@ -1179,6 +1187,8 @@ def test_create_conversation_profile( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) response = client.create_conversation_profile(request) @@ -1192,6 +1202,8 @@ def test_create_conversation_profile( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" def test_create_conversation_profile_from_dict(): @@ -1238,6 +1250,8 @@ async def test_create_conversation_profile_async( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) ) response = await client.create_conversation_profile(request) @@ -1252,6 +1266,8 @@ async def test_create_conversation_profile_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" @pytest.mark.asyncio @@ -1443,6 +1459,8 @@ def test_update_conversation_profile( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) response = client.update_conversation_profile(request) @@ -1456,6 +1474,8 @@ def test_update_conversation_profile( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" def test_update_conversation_profile_from_dict(): @@ -1502,6 +1522,8 @@ async def test_update_conversation_profile_async( name="name_value", display_name="display_name_value", language_code="language_code_value", + time_zone="time_zone_value", + security_settings="security_settings_value", ) ) response = await client.update_conversation_profile(request) @@ -1516,6 +1538,8 @@ async def test_update_conversation_profile_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.language_code == "language_code_value" + assert response.time_zone == "time_zone_value" + assert response.security_settings == "security_settings_value" @pytest.mark.asyncio @@ -2390,10 +2414,36 @@ def test_parse_conversation_profile_path(): assert expected == actual -def test_document_path(): +def test_cx_security_settings_path(): project = "squid" - knowledge_base = "clam" - document = "whelk" + location = "clam" + security_settings = "whelk" + expected = "projects/{project}/locations/{location}/securitySettings/{security_settings}".format( + project=project, location=location, security_settings=security_settings, + ) + actual = ConversationProfilesClient.cx_security_settings_path( + project, location, security_settings + ) + assert expected == actual + + +def test_parse_cx_security_settings_path(): + expected = { + "project": "octopus", + "location": "oyster", + "security_settings": "nudibranch", + } + path = ConversationProfilesClient.cx_security_settings_path(**expected) + + # Check that the path construction is reversible. + actual = ConversationProfilesClient.parse_cx_security_settings_path(path) + assert expected == actual + + +def test_document_path(): + project = "cuttlefish" + knowledge_base = "mussel" + document = "winkle" expected = "projects/{project}/knowledgeBases/{knowledge_base}/documents/{document}".format( project=project, knowledge_base=knowledge_base, document=document, ) @@ -2403,9 +2453,9 @@ def test_document_path(): def test_parse_document_path(): expected = { - "project": "octopus", - "knowledge_base": "oyster", - "document": "nudibranch", + "project": "nautilus", + "knowledge_base": "scallop", + "document": "abalone", } path = ConversationProfilesClient.document_path(**expected) @@ -2415,8 +2465,8 @@ def test_parse_document_path(): def test_knowledge_base_path(): - project = "cuttlefish" - knowledge_base = "mussel" + project = "squid" + knowledge_base = "clam" expected = "projects/{project}/knowledgeBases/{knowledge_base}".format( project=project, knowledge_base=knowledge_base, ) @@ -2426,8 +2476,8 @@ def test_knowledge_base_path(): def test_parse_knowledge_base_path(): expected = { - "project": "winkle", - "knowledge_base": "nautilus", + "project": "whelk", + "knowledge_base": "octopus", } path = ConversationProfilesClient.knowledge_base_path(**expected) @@ -2437,7 +2487,7 @@ def test_parse_knowledge_base_path(): def test_common_billing_account_path(): - billing_account = "scallop" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -2447,7 +2497,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "abalone", + "billing_account": "nudibranch", } path = ConversationProfilesClient.common_billing_account_path(**expected) @@ -2457,7 +2507,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "squid" + folder = "cuttlefish" expected = "folders/{folder}".format(folder=folder,) actual = ConversationProfilesClient.common_folder_path(folder) assert expected == actual @@ -2465,7 +2515,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "clam", + "folder": "mussel", } path = ConversationProfilesClient.common_folder_path(**expected) @@ -2475,7 +2525,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "whelk" + organization = "winkle" expected = "organizations/{organization}".format(organization=organization,) actual = ConversationProfilesClient.common_organization_path(organization) assert expected == actual @@ -2483,7 +2533,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "octopus", + "organization": "nautilus", } path = ConversationProfilesClient.common_organization_path(**expected) @@ -2493,7 +2543,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "oyster" + project = "scallop" expected = "projects/{project}".format(project=project,) actual = ConversationProfilesClient.common_project_path(project) assert expected == actual @@ -2501,7 +2551,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "nudibranch", + "project": "abalone", } path = ConversationProfilesClient.common_project_path(**expected) @@ -2511,8 +2561,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "cuttlefish" - location = "mussel" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -2522,8 +2572,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "winkle", - "location": "nautilus", + "project": "whelk", + "location": "octopus", } path = ConversationProfilesClient.common_location_path(**expected)