From ff45aae6c9f11a55e2ab04694b67a282e2056657 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 12 Apr 2021 12:25:07 -0700 Subject: [PATCH] fix: remove rpc or fields that are unintended to release (#264) fix: remove StreamingAnalyzeContent, CreateCallMatcher, ListCallMatchers, DeleteCallMatcher rpc from v2/v2beta1 fix: remove `input_audio` field from AnalyzeContentRequest from v2/v2beta1 fix: remove proto message CreateCallMatcherRequest, CreateCallMatcherResponse, ListCallMatchersRequest, ListCallMatchersResponse, DeleteCallMatcherRequest, DeleteCallMatcherResponse, CallMatcher, StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse, AudioInput from v2/v2beta1, TelephonyDtmfEvents, TelephonyDtmf from v2 fix: Remove resource_reference from UpdateAnswerRecord fix: remove resource_reference for invisible resources **NOTE**: This PR contains breaking changes (deletions) to the library surface. The Dialogflow API team has provided documentation indicating that there were a limited number of users. Those users have been allowlisted and will be able to continue to call those RPCs using a previous version of the library. --- .../samples/python3.6/periodic-head.cfg | 11 + .../samples/python3.7/periodic-head.cfg | 11 + .../samples/python3.8/periodic-head.cfg | 11 + .../.kokoro/test-samples-against-head.sh | 28 + .../.kokoro/test-samples-impl.sh | 102 ++ .../.kokoro/test-samples.sh | 96 +- .../.pre-commit-config.yaml | 2 +- .../google/cloud/dialogflow/__init__.py | 22 - .../google/cloud/dialogflow_v2/__init__.py | 26 +- .../cloud/dialogflow_v2/proto/agent.proto | 32 + .../dialogflow_v2/proto/answer_record.proto | 53 +- .../dialogflow_v2/proto/audio_config.proto | 79 +- .../cloud/dialogflow_v2/proto/context.proto | 40 + .../dialogflow_v2/proto/conversation.proto | 162 --- .../proto/conversation_profile.proto | 5 +- .../cloud/dialogflow_v2/proto/document.proto | 21 + .../dialogflow_v2/proto/entity_type.proto | 37 + .../dialogflow_v2/proto/environment.proto | 3 + .../cloud/dialogflow_v2/proto/intent.proto | 25 + .../dialogflow_v2/proto/knowledge_base.proto | 17 + .../dialogflow_v2/proto/participant.proto | 180 +--- .../cloud/dialogflow_v2/proto/session.proto | 8 + .../proto/session_entity_type.proto | 34 + .../services/agents/transports/base.py | 18 +- .../services/agents/transports/grpc.py | 103 +- .../agents/transports/grpc_asyncio.py | 111 +-- .../services/answer_records/async_client.py | 11 +- .../services/answer_records/client.py | 11 +- .../answer_records/transports/base.py | 18 +- .../answer_records/transports/grpc.py | 101 +- .../answer_records/transports/grpc_asyncio.py | 109 +-- .../services/contexts/transports/base.py | 18 +- .../services/contexts/transports/grpc.py | 101 +- .../contexts/transports/grpc_asyncio.py | 109 +-- .../conversation_profiles/transports/base.py | 18 +- .../conversation_profiles/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/conversations/async_client.py | 268 ----- .../services/conversations/client.py | 285 ------ .../services/conversations/pagers.py | 128 --- .../services/conversations/transports/base.py | 60 +- .../services/conversations/transports/grpc.py | 185 +--- .../conversations/transports/grpc_asyncio.py | 196 +--- .../services/documents/transports/base.py | 18 +- .../services/documents/transports/grpc.py | 103 +- .../documents/transports/grpc_asyncio.py | 111 +-- .../services/entity_types/transports/base.py | 18 +- .../services/entity_types/transports/grpc.py | 103 +- .../entity_types/transports/grpc_asyncio.py | 111 +-- .../services/environments/transports/base.py | 18 +- .../services/environments/transports/grpc.py | 101 +- .../environments/transports/grpc_asyncio.py | 109 +-- .../services/intents/transports/base.py | 18 +- .../services/intents/transports/grpc.py | 103 +- .../intents/transports/grpc_asyncio.py | 111 +-- .../knowledge_bases/transports/base.py | 18 +- .../knowledge_bases/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/participants/async_client.py | 131 +-- .../services/participants/client.py | 129 +-- .../services/participants/transports/base.py | 36 +- .../services/participants/transports/grpc.py | 149 +-- .../participants/transports/grpc_asyncio.py | 157 +-- .../session_entity_types/transports/base.py | 18 +- .../session_entity_types/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/sessions/async_client.py | 1 + .../services/sessions/transports/base.py | 19 +- .../services/sessions/transports/grpc.py | 101 +- .../sessions/transports/grpc_asyncio.py | 109 +-- .../cloud/dialogflow_v2/types/__init__.py | 22 - .../cloud/dialogflow_v2/types/audio_config.py | 38 +- .../cloud/dialogflow_v2/types/conversation.py | 164 ---- .../cloud/dialogflow_v2/types/participant.py | 250 +---- .../cloud/dialogflow_v2beta1/__init__.py | 22 +- .../proto/answer_record.proto | 54 +- .../proto/audio_config.proto | 6 + .../proto/conversation.proto | 239 +---- .../proto/conversation_profile.proto | 5 +- .../proto/participant.proto | 207 +--- .../dialogflow_v2beta1/proto/session.proto | 3 + .../services/agents/transports/base.py | 18 +- .../services/agents/transports/grpc.py | 103 +- .../agents/transports/grpc_asyncio.py | 111 +-- .../services/answer_records/async_client.py | 20 +- .../services/answer_records/client.py | 20 +- .../answer_records/transports/base.py | 18 +- .../answer_records/transports/grpc.py | 101 +- .../answer_records/transports/grpc_asyncio.py | 109 +-- .../services/contexts/transports/base.py | 18 +- .../services/contexts/transports/grpc.py | 101 +- .../contexts/transports/grpc_asyncio.py | 109 +-- .../conversation_profiles/transports/base.py | 18 +- .../conversation_profiles/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/conversations/async_client.py | 272 +----- .../services/conversations/client.py | 289 +----- .../services/conversations/pagers.py | 128 --- .../services/conversations/transports/base.py | 60 +- .../services/conversations/transports/grpc.py | 185 +--- .../conversations/transports/grpc_asyncio.py | 196 +--- .../services/documents/transports/base.py | 18 +- .../services/documents/transports/grpc.py | 103 +- .../documents/transports/grpc_asyncio.py | 111 +-- .../services/entity_types/transports/base.py | 18 +- .../services/entity_types/transports/grpc.py | 103 +- .../entity_types/transports/grpc_asyncio.py | 111 +-- .../services/environments/transports/base.py | 18 +- .../services/environments/transports/grpc.py | 101 +- .../environments/transports/grpc_asyncio.py | 109 +-- .../services/intents/transports/base.py | 18 +- .../services/intents/transports/grpc.py | 103 +- .../intents/transports/grpc_asyncio.py | 111 +-- .../knowledge_bases/transports/base.py | 18 +- .../knowledge_bases/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/participants/async_client.py | 132 +-- .../services/participants/client.py | 130 +-- .../services/participants/transports/base.py | 36 +- .../services/participants/transports/grpc.py | 146 +-- .../participants/transports/grpc_asyncio.py | 154 +-- .../session_entity_types/transports/base.py | 18 +- .../session_entity_types/transports/grpc.py | 101 +- .../transports/grpc_asyncio.py | 109 +-- .../services/sessions/async_client.py | 1 + .../services/sessions/transports/base.py | 19 +- .../services/sessions/transports/grpc.py | 101 +- .../sessions/transports/grpc_asyncio.py | 109 +-- .../dialogflow_v2beta1/types/__init__.py | 18 - .../dialogflow_v2beta1/types/audio_config.py | 2 + .../dialogflow_v2beta1/types/conversation.py | 165 ---- .../dialogflow_v2beta1/types/participant.py | 289 +----- .../cloud/dialogflow_v2beta1/types/session.py | 10 + packages/google-cloud-dialogflow/noxfile.py | 31 +- .../google-cloud-dialogflow/renovate.json | 3 +- .../scripts/fixup_dialogflow_v2_keywords.py | 6 +- .../fixup_dialogflow_v2beta1_keywords.py | 6 +- packages/google-cloud-dialogflow/setup.py | 2 +- .../google-cloud-dialogflow/synth.metadata | 435 +-------- packages/google-cloud-dialogflow/synth.py | 6 +- .../testing/constraints-3.6.txt | 10 +- .../testing/constraints-3.7.txt | 2 + .../testing/constraints-3.8.txt | 2 + .../testing/constraints-3.9.txt | 2 + .../gapic/dialogflow_v2/test_conversations.py | 924 +----------------- .../gapic/dialogflow_v2/test_participants.py | 101 -- .../dialogflow_v2beta1/test_conversations.py | 924 +----------------- .../dialogflow_v2beta1/test_participants.py | 101 -- 148 files changed, 2997 insertions(+), 10623 deletions(-) create mode 100644 packages/google-cloud-dialogflow/.kokoro/samples/python3.6/periodic-head.cfg create mode 100644 packages/google-cloud-dialogflow/.kokoro/samples/python3.7/periodic-head.cfg create mode 100644 packages/google-cloud-dialogflow/.kokoro/samples/python3.8/periodic-head.cfg create mode 100755 packages/google-cloud-dialogflow/.kokoro/test-samples-against-head.sh create mode 100755 packages/google-cloud-dialogflow/.kokoro/test-samples-impl.sh diff --git a/packages/google-cloud-dialogflow/.kokoro/samples/python3.6/periodic-head.cfg b/packages/google-cloud-dialogflow/.kokoro/samples/python3.6/periodic-head.cfg new file mode 100644 index 000000000000..f9cfcd33e058 --- /dev/null +++ b/packages/google-cloud-dialogflow/.kokoro/samples/python3.6/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/packages/google-cloud-dialogflow/.kokoro/samples/python3.7/periodic-head.cfg b/packages/google-cloud-dialogflow/.kokoro/samples/python3.7/periodic-head.cfg new file mode 100644 index 000000000000..f9cfcd33e058 --- /dev/null +++ b/packages/google-cloud-dialogflow/.kokoro/samples/python3.7/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/packages/google-cloud-dialogflow/.kokoro/samples/python3.8/periodic-head.cfg b/packages/google-cloud-dialogflow/.kokoro/samples/python3.8/periodic-head.cfg new file mode 100644 index 000000000000..f9cfcd33e058 --- /dev/null +++ b/packages/google-cloud-dialogflow/.kokoro/samples/python3.8/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-pubsub/.kokoro/test-samples-against-head.sh" +} diff --git a/packages/google-cloud-dialogflow/.kokoro/test-samples-against-head.sh b/packages/google-cloud-dialogflow/.kokoro/test-samples-against-head.sh new file mode 100755 index 000000000000..3187ad1e3546 --- /dev/null +++ b/packages/google-cloud-dialogflow/.kokoro/test-samples-against-head.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A customized test runner for samples. +# +# For periodic builds, you can specify this file for testing against head. + +# `-e` enables the script to automatically fail when a command fails +# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero +set -eo pipefail +# Enables `**` to include files nested inside sub-folders +shopt -s globstar + +cd github/python-dialogflow + +exec .kokoro/test-samples-impl.sh diff --git a/packages/google-cloud-dialogflow/.kokoro/test-samples-impl.sh b/packages/google-cloud-dialogflow/.kokoro/test-samples-impl.sh new file mode 100755 index 000000000000..cf5de74c17a5 --- /dev/null +++ b/packages/google-cloud-dialogflow/.kokoro/test-samples-impl.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# `-e` enables the script to automatically fail when a command fails +# `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero +set -eo pipefail +# Enables `**` to include files nested inside sub-folders +shopt -s globstar + +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + +# Disable buffering, so that the logs stream through. +export PYTHONUNBUFFERED=1 + +# Debug: show build environment +env | grep KOKORO + +# Install nox +python3.6 -m pip install --upgrade --quiet nox + +# Use secrets acessor service account to get secrets +if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then + gcloud auth activate-service-account \ + --key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \ + --project="cloud-devrel-kokoro-resources" +fi + +# This script will create 3 files: +# - testing/test-env.sh +# - testing/service-account.json +# - testing/client-secrets.json +./scripts/decrypt-secrets.sh + +source ./testing/test-env.sh +export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json + +# For cloud-run session, we activate the service account for gcloud sdk. +gcloud auth activate-service-account \ + --key-file "${GOOGLE_APPLICATION_CREDENTIALS}" + +export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json + +echo -e "\n******************** TESTING PROJECTS ********************" + +# Switch to 'fail at end' to allow all tests to complete before exiting. +set +e +# Use RTN to return a non-zero value if the test fails. +RTN=0 +ROOT=$(pwd) +# Find all requirements.txt in the samples directory (may break on whitespace). +for file in samples/**/requirements.txt; do + cd "$ROOT" + # Navigate to the project folder. + file=$(dirname "$file") + cd "$file" + + echo "------------------------------------------------------------" + echo "- testing $file" + echo "------------------------------------------------------------" + + # Use nox to execute the tests for the project. + python3.6 -m nox -s "$RUN_TESTS_SESSION" + EXIT=$? + + # If this is a periodic build, send the test log to the FlakyBot. + # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then + chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot + $KOKORO_GFILE_DIR/linux_amd64/flakybot + fi + + if [[ $EXIT -ne 0 ]]; then + RTN=1 + echo -e "\n Testing failed: Nox returned a non-zero exit code. \n" + else + echo -e "\n Testing completed.\n" + fi + +done +cd "$ROOT" + +# Workaround for Kokoro permissions issue: delete secrets +rm testing/{test-env.sh,client-secrets.json,service-account.json} + +exit "$RTN" diff --git a/packages/google-cloud-dialogflow/.kokoro/test-samples.sh b/packages/google-cloud-dialogflow/.kokoro/test-samples.sh index c3001ba08484..7f72ef5d1e8f 100755 --- a/packages/google-cloud-dialogflow/.kokoro/test-samples.sh +++ b/packages/google-cloud-dialogflow/.kokoro/test-samples.sh @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +# The default test runner for samples. +# +# For periodic builds, we rewinds the repo to the latest release, and +# run test-samples-impl.sh. # `-e` enables the script to automatically fail when a command fails # `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero @@ -24,87 +28,19 @@ cd github/python-dialogflow # Run periodic samples tests at latest release if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then + # preserving the test runner implementation. + cp .kokoro/test-samples-impl.sh "${TMPDIR}/test-samples-impl.sh" + echo "--- IMPORTANT IMPORTANT IMPORTANT ---" + echo "Now we rewind the repo back to the latest release..." LATEST_RELEASE=$(git describe --abbrev=0 --tags) git checkout $LATEST_RELEASE -fi - -# Exit early if samples directory doesn't exist -if [ ! -d "./samples" ]; then - echo "No tests run. `./samples` not found" - exit 0 -fi - -# Disable buffering, so that the logs stream through. -export PYTHONUNBUFFERED=1 - -# Debug: show build environment -env | grep KOKORO - -# Install nox -python3.6 -m pip install --upgrade --quiet nox - -# Use secrets acessor service account to get secrets -if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then - gcloud auth activate-service-account \ - --key-file="${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" \ - --project="cloud-devrel-kokoro-resources" -fi - -# This script will create 3 files: -# - testing/test-env.sh -# - testing/service-account.json -# - testing/client-secrets.json -./scripts/decrypt-secrets.sh - -source ./testing/test-env.sh -export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/testing/service-account.json - -# For cloud-run session, we activate the service account for gcloud sdk. -gcloud auth activate-service-account \ - --key-file "${GOOGLE_APPLICATION_CREDENTIALS}" - -export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json - -echo -e "\n******************** TESTING PROJECTS ********************" - -# Switch to 'fail at end' to allow all tests to complete before exiting. -set +e -# Use RTN to return a non-zero value if the test fails. -RTN=0 -ROOT=$(pwd) -# Find all requirements.txt in the samples directory (may break on whitespace). -for file in samples/**/requirements.txt; do - cd "$ROOT" - # Navigate to the project folder. - file=$(dirname "$file") - cd "$file" - - echo "------------------------------------------------------------" - echo "- testing $file" - echo "------------------------------------------------------------" - - # Use nox to execute the tests for the project. - python3.6 -m nox -s "$RUN_TESTS_SESSION" - EXIT=$? - - # If this is a periodic build, send the test log to the FlakyBot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. - if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then - chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot - $KOKORO_GFILE_DIR/linux_amd64/flakybot + echo "The current head is: " + echo $(git rev-parse --verify HEAD) + echo "--- IMPORTANT IMPORTANT IMPORTANT ---" + # move back the test runner implementation if there's no file. + if [ ! -f .kokoro/test-samples-impl.sh ]; then + cp "${TMPDIR}/test-samples-impl.sh" .kokoro/test-samples-impl.sh fi +fi - if [[ $EXIT -ne 0 ]]; then - RTN=1 - echo -e "\n Testing failed: Nox returned a non-zero exit code. \n" - else - echo -e "\n Testing completed.\n" - fi - -done -cd "$ROOT" - -# Workaround for Kokoro permissions issue: delete secrets -rm testing/{test-env.sh,client-secrets.json,service-account.json} - -exit "$RTN" +exec .kokoro/test-samples-impl.sh diff --git a/packages/google-cloud-dialogflow/.pre-commit-config.yaml b/packages/google-cloud-dialogflow/.pre-commit-config.yaml index a9024b15d725..32302e4883a1 100644 --- a/packages/google-cloud-dialogflow/.pre-commit-config.yaml +++ b/packages/google-cloud-dialogflow/.pre-commit-config.yaml @@ -12,6 +12,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.0 hooks: - id: flake8 diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow/__init__.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow/__init__.py index d84ba598d4e8..a766e6b133f5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow/__init__.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow/__init__.py @@ -100,8 +100,6 @@ from google.cloud.dialogflow_v2.types.audio_config import SpeechWordInfo from google.cloud.dialogflow_v2.types.audio_config import SsmlVoiceGender from google.cloud.dialogflow_v2.types.audio_config import SynthesizeSpeechConfig -from google.cloud.dialogflow_v2.types.audio_config import TelephonyDtmf -from google.cloud.dialogflow_v2.types.audio_config import TelephonyDtmfEvents from google.cloud.dialogflow_v2.types.audio_config import VoiceSelectionParams from google.cloud.dialogflow_v2.types.context import Context from google.cloud.dialogflow_v2.types.context import CreateContextRequest @@ -111,16 +109,11 @@ from google.cloud.dialogflow_v2.types.context import ListContextsRequest from google.cloud.dialogflow_v2.types.context import ListContextsResponse from google.cloud.dialogflow_v2.types.context import UpdateContextRequest -from google.cloud.dialogflow_v2.types.conversation import CallMatcher from google.cloud.dialogflow_v2.types.conversation import CompleteConversationRequest from google.cloud.dialogflow_v2.types.conversation import Conversation from google.cloud.dialogflow_v2.types.conversation import ConversationPhoneNumber -from google.cloud.dialogflow_v2.types.conversation import CreateCallMatcherRequest from google.cloud.dialogflow_v2.types.conversation import CreateConversationRequest -from google.cloud.dialogflow_v2.types.conversation import DeleteCallMatcherRequest from google.cloud.dialogflow_v2.types.conversation import GetConversationRequest -from google.cloud.dialogflow_v2.types.conversation import ListCallMatchersRequest -from google.cloud.dialogflow_v2.types.conversation import ListCallMatchersResponse from google.cloud.dialogflow_v2.types.conversation import ListConversationsRequest from google.cloud.dialogflow_v2.types.conversation import ListConversationsResponse from google.cloud.dialogflow_v2.types.conversation import ListMessagesRequest @@ -207,21 +200,17 @@ from google.cloud.dialogflow_v2.types.participant import AnalyzeContentResponse from google.cloud.dialogflow_v2.types.participant import AnnotatedMessagePart from google.cloud.dialogflow_v2.types.participant import ArticleAnswer -from google.cloud.dialogflow_v2.types.participant import AudioInput from google.cloud.dialogflow_v2.types.participant import AutomatedAgentReply from google.cloud.dialogflow_v2.types.participant import CreateParticipantRequest from google.cloud.dialogflow_v2.types.participant import DtmfParameters from google.cloud.dialogflow_v2.types.participant import FaqAnswer from google.cloud.dialogflow_v2.types.participant import GetParticipantRequest -from google.cloud.dialogflow_v2.types.participant import InputTextConfig from google.cloud.dialogflow_v2.types.participant import ListParticipantsRequest from google.cloud.dialogflow_v2.types.participant import ListParticipantsResponse from google.cloud.dialogflow_v2.types.participant import Message from google.cloud.dialogflow_v2.types.participant import MessageAnnotation from google.cloud.dialogflow_v2.types.participant import OutputAudio from google.cloud.dialogflow_v2.types.participant import Participant -from google.cloud.dialogflow_v2.types.participant import StreamingAnalyzeContentRequest -from google.cloud.dialogflow_v2.types.participant import StreamingAnalyzeContentResponse from google.cloud.dialogflow_v2.types.participant import SuggestArticlesRequest from google.cloud.dialogflow_v2.types.participant import SuggestArticlesResponse from google.cloud.dialogflow_v2.types.participant import SuggestFaqAnswersRequest @@ -281,7 +270,6 @@ "AnswerRecordsClient", "ArticleAnswer", "AudioEncoding", - "AudioInput", "AutomatedAgentConfig", "AutomatedAgentReply", "BatchCreateEntitiesRequest", @@ -293,7 +281,6 @@ "BatchUpdateEntityTypesResponse", "BatchUpdateIntentsRequest", "BatchUpdateIntentsResponse", - "CallMatcher", "CompleteConversationRequest", "Context", "ContextsAsyncClient", @@ -306,7 +293,6 @@ "ConversationProfilesClient", "ConversationsAsyncClient", "ConversationsClient", - "CreateCallMatcherRequest", "CreateContextRequest", "CreateConversationProfileRequest", "CreateConversationRequest", @@ -318,7 +304,6 @@ "CreateSessionEntityTypeRequest", "DeleteAgentRequest", "DeleteAllContextsRequest", - "DeleteCallMatcherRequest", "DeleteContextRequest", "DeleteConversationProfileRequest", "DeleteDocumentRequest", @@ -359,7 +344,6 @@ "HumanAgentHandoffConfig", "ImportAgentRequest", "InputAudioConfig", - "InputTextConfig", "Intent", "IntentBatch", "IntentView", @@ -371,8 +355,6 @@ "KnowledgeOperationMetadata", "ListAnswerRecordsRequest", "ListAnswerRecordsResponse", - "ListCallMatchersRequest", - "ListCallMatchersResponse", "ListContextsRequest", "ListContextsResponse", "ListConversationProfilesRequest", @@ -427,8 +409,6 @@ "SpeechToTextConfig", "SpeechWordInfo", "SsmlVoiceGender", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "StreamingDetectIntentRequest", "StreamingDetectIntentResponse", "StreamingRecognitionResult", @@ -439,8 +419,6 @@ "SuggestionFeature", "SuggestionResult", "SynthesizeSpeechConfig", - "TelephonyDtmf", - "TelephonyDtmfEvents", "TextInput", "TrainAgentRequest", "UpdateAnswerRecordRequest", diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/__init__.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/__init__.py index 574b1a369ed1..1bc06d15b90d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/__init__.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/__init__.py @@ -57,8 +57,6 @@ from .types.audio_config import SpeechWordInfo from .types.audio_config import SsmlVoiceGender from .types.audio_config import SynthesizeSpeechConfig -from .types.audio_config import TelephonyDtmf -from .types.audio_config import TelephonyDtmfEvents from .types.audio_config import VoiceSelectionParams from .types.context import Context from .types.context import CreateContextRequest @@ -68,16 +66,11 @@ from .types.context import ListContextsRequest from .types.context import ListContextsResponse from .types.context import UpdateContextRequest -from .types.conversation import CallMatcher from .types.conversation import CompleteConversationRequest from .types.conversation import Conversation from .types.conversation import ConversationPhoneNumber -from .types.conversation import CreateCallMatcherRequest from .types.conversation import CreateConversationRequest -from .types.conversation import DeleteCallMatcherRequest from .types.conversation import GetConversationRequest -from .types.conversation import ListCallMatchersRequest -from .types.conversation import ListCallMatchersResponse from .types.conversation import ListConversationsRequest from .types.conversation import ListConversationsResponse from .types.conversation import ListMessagesRequest @@ -146,21 +139,17 @@ from .types.participant import AnalyzeContentResponse from .types.participant import AnnotatedMessagePart from .types.participant import ArticleAnswer -from .types.participant import AudioInput from .types.participant import AutomatedAgentReply from .types.participant import CreateParticipantRequest from .types.participant import DtmfParameters from .types.participant import FaqAnswer from .types.participant import GetParticipantRequest -from .types.participant import InputTextConfig from .types.participant import ListParticipantsRequest from .types.participant import ListParticipantsResponse from .types.participant import Message from .types.participant import MessageAnnotation from .types.participant import OutputAudio from .types.participant import Participant -from .types.participant import StreamingAnalyzeContentRequest -from .types.participant import StreamingAnalyzeContentResponse from .types.participant import SuggestArticlesRequest from .types.participant import SuggestArticlesResponse from .types.participant import SuggestFaqAnswersRequest @@ -207,7 +196,6 @@ "AnswerRecordsClient", "ArticleAnswer", "AudioEncoding", - "AudioInput", "AutomatedAgentConfig", "AutomatedAgentReply", "BatchCreateEntitiesRequest", @@ -219,7 +207,6 @@ "BatchUpdateEntityTypesResponse", "BatchUpdateIntentsRequest", "BatchUpdateIntentsResponse", - "CallMatcher", "CompleteConversationRequest", "Context", "ContextsClient", @@ -228,7 +215,7 @@ "ConversationPhoneNumber", "ConversationProfile", "ConversationProfilesClient", - "CreateCallMatcherRequest", + "ConversationsClient", "CreateContextRequest", "CreateConversationProfileRequest", "CreateConversationRequest", @@ -240,7 +227,6 @@ "CreateSessionEntityTypeRequest", "DeleteAgentRequest", "DeleteAllContextsRequest", - "DeleteCallMatcherRequest", "DeleteContextRequest", "DeleteConversationProfileRequest", "DeleteDocumentRequest", @@ -278,18 +264,14 @@ "HumanAgentHandoffConfig", "ImportAgentRequest", "InputAudioConfig", - "InputTextConfig", "Intent", "IntentBatch", "IntentView", "IntentsClient", "KnowledgeBase", - "KnowledgeBasesClient", "KnowledgeOperationMetadata", "ListAnswerRecordsRequest", "ListAnswerRecordsResponse", - "ListCallMatchersRequest", - "ListCallMatchersResponse", "ListContextsRequest", "ListContextsResponse", "ListConversationProfilesRequest", @@ -341,8 +323,6 @@ "SpeechToTextConfig", "SpeechWordInfo", "SsmlVoiceGender", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "StreamingDetectIntentRequest", "StreamingDetectIntentResponse", "StreamingRecognitionResult", @@ -353,8 +333,6 @@ "SuggestionFeature", "SuggestionResult", "SynthesizeSpeechConfig", - "TelephonyDtmf", - "TelephonyDtmfEvents", "TextInput", "TrainAgentRequest", "UpdateAnswerRecordRequest", @@ -371,5 +349,5 @@ "VoiceSelectionParams", "WebhookRequest", "WebhookResponse", - "ConversationsClient", + "KnowledgeBasesClient", ) diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/agent.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/agent.proto index 4ac05cd2acca..72ff1b336380 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/agent.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/agent.proto @@ -44,6 +44,9 @@ service Agents { rpc GetAgent(GetAgentRequest) returns (Agent) { option (google.api.http) = { get: "/v2/{parent=projects/*}/agent" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*}/agent" + } }; option (google.api.method_signature) = "parent"; } @@ -53,6 +56,10 @@ service Agents { option (google.api.http) = { post: "/v2/{agent.parent=projects/*}/agent" body: "agent" + additional_bindings { + post: "/v2/{agent.parent=projects/*/locations/*}/agent" + body: "agent" + } }; option (google.api.method_signature) = "agent"; } @@ -61,6 +68,9 @@ service Agents { rpc DeleteAgent(DeleteAgentRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v2/{parent=projects/*}/agent" + additional_bindings { + delete: "/v2/{parent=projects/*/locations/*}/agent" + } }; option (google.api.method_signature) = "parent"; } @@ -75,6 +85,9 @@ service Agents { rpc SearchAgents(SearchAgentsRequest) returns (SearchAgentsResponse) { option (google.api.http) = { get: "/v2/{parent=projects/*}/agent:search" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*}/agent:search" + } }; option (google.api.method_signature) = "parent"; } @@ -86,6 +99,10 @@ service Agents { option (google.api.http) = { post: "/v2/{parent=projects/*}/agent:train" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*}/agent:train" + body: "*" + } }; option (google.api.method_signature) = "parent"; option (google.longrunning.operation_info) = { @@ -101,6 +118,10 @@ service Agents { option (google.api.http) = { post: "/v2/{parent=projects/*}/agent:export" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*}/agent:export" + body: "*" + } }; option (google.api.method_signature) = "parent"; option (google.longrunning.operation_info) = { @@ -126,6 +147,10 @@ service Agents { option (google.api.http) = { post: "/v2/{parent=projects/*}/agent:import" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*}/agent:import" + body: "*" + } }; option (google.longrunning.operation_info) = { response_type: "google.protobuf.Empty" @@ -149,6 +174,10 @@ service Agents { option (google.api.http) = { post: "/v2/{parent=projects/*}/agent:restore" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*}/agent:restore" + body: "*" + } }; option (google.longrunning.operation_info) = { response_type: "google.protobuf.Empty" @@ -161,6 +190,9 @@ service Agents { rpc GetValidationResult(GetValidationResultRequest) returns (ValidationResult) { option (google.api.http) = { get: "/v2/{parent=projects/*}/agent/validationResult" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*}/agent/validationResult" + } }; } } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/answer_record.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/answer_record.proto index 1afb47e63992..3fb729107d17 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/answer_record.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/answer_record.proto @@ -33,7 +33,8 @@ option java_outer_classname = "AnswerRecordsProto"; option java_package = "com.google.cloud.dialogflow.v2"; option objc_class_prefix = "DF"; -// Service for managing [AnswerRecords][google.cloud.dialogflow.v2.AnswerRecord]. +// Service for managing +// [AnswerRecords][google.cloud.dialogflow.v2.AnswerRecord]. service AnswerRecords { option (google.api.default_host) = "dialogflow.googleapis.com"; option (google.api.oauth_scopes) = @@ -42,7 +43,8 @@ service AnswerRecords { // Returns the list of all answer records in the specified project in reverse // chronological order. - rpc ListAnswerRecords(ListAnswerRecordsRequest) returns (ListAnswerRecordsResponse) { + rpc ListAnswerRecords(ListAnswerRecordsRequest) + returns (ListAnswerRecordsResponse) { option (google.api.http) = { get: "/v2/{parent=projects/*}/answerRecords" additional_bindings { @@ -87,9 +89,11 @@ service AnswerRecords { // A typical workflow for customers provide feedback to an answer is: // // 1. For human agent assistant, customers get suggestion via ListSuggestions -// API. Together with the answers, [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] are returned to the -// customers. -// 2. The customer uses the [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] to call the +// API. Together with the answers, +// [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] are +// returned to the customers. +// 2. The customer uses the +// [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] to call the // [UpdateAnswerRecord][] method to send feedback about a specific answer // that they believe is wrong. message AnswerRecord { @@ -105,18 +109,20 @@ message AnswerRecord { string name = 1; // Required. The AnswerFeedback for this record. You can set this with - // [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2.AnswerRecords.UpdateAnswerRecord] in order to give us feedback about - // this answer. + // [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2.AnswerRecords.UpdateAnswerRecord] + // in order to give us feedback about this answer. AnswerFeedback answer_feedback = 2 [(google.api.field_behavior) = REQUIRED]; // The record for this answer. oneof record { // Output only. The record for human agent assistant. - AgentAssistantRecord agent_assistant_record = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; + AgentAssistantRecord agent_assistant_record = 4 + [(google.api.field_behavior) = OUTPUT_ONLY]; } } -// Request message for [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. +// Request message for +// [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. message ListAnswerRecordsRequest { // Required. The project to list all answer records for in reverse // chronological order. Format: `projects//locations/ -// ;purpose=Goog-ContactCenter-Conversation`. -// * Or, if that doesn't work, matching incoming [SIP -// headers](https://tools.ietf.org/html/rfc3261#section-7.3) -// against any [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] for the conversation. -// -// If an incoming SIP call without valid `Call-Info` header matches to zero or -// multiple conversations with `CallMatcher`, we reject it. -// -// A call matcher contains equality conditions for SIP headers that all have -// to be fulfilled in order for a SIP call to match. -// -// The matched SIP headers consist of well-known headers (`To`, `From`, -// `Call-ID`) and custom headers. A [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] is only valid if it -// specifies: -// -// * At least 1 custom header, -// * or at least 2 well-known headers. -message CallMatcher { - option (google.api.resource) = { - type: "dialogflow.googleapis.com/CallMatcher" - pattern: "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}" - pattern: "projects/{project}/locations/{location}/conversations/{conversation}/callMatchers/{call_matcher}" - }; - - // Custom SIP headers. See the [description of headers in - // the RFC](https://tools.ietf.org/html/rfc3261#section-7.3). - message CustomHeaders { - // Cisco's proprietary `Cisco-Guid` header. - string cisco_guid = 1; - } - - // Output only. The unique identifier of this call matcher. - // Format: `projects//locations//conversations//callMatchers/`. - string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; - - // Value of the [`To` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.2) to match. If - // empty or unspecified, we don't match to the - // [`To` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.2). - string to_header = 2; - - // Value of the [`From` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.3) to match. If - // empty or unspecified, we don't match to the - // [`From` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.3). - string from_header = 3; - - // Value of the [`Call-ID` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.4) to match. If - // empty or unspecified, we don't match to the - // [`Call-ID` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.4). - string call_id_header = 4; - - // Custom SIP headers that must match. - CustomHeaders custom_headers = 5; -} - // The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2.Conversations.CreateConversation]. message CreateConversationRequest { // Required. Resource identifier of the project creating the conversation. @@ -410,66 +308,6 @@ message CompleteConversationRequest { ]; } -// The request message for [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2.Conversations.CreateCallMatcher]. -message CreateCallMatcherRequest { - // Required. Resource identifier of the conversation adding the call matcher. - // Format: `projects//locations//conversations/`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "dialogflow.googleapis.com/CallMatcher" - } - ]; - - // Required. The call matcher to create. - CallMatcher call_matcher = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// The request message for [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. -message ListCallMatchersRequest { - // Required. The conversation to list all call matchers from. - // Format: `projects//locations//conversations/`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "dialogflow.googleapis.com/CallMatcher" - } - ]; - - // Optional. The maximum number of items to return in a single page. By - // default 100 and at most 1000. - int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL]; - - // Optional. The next_page_token value returned from a previous list request. - string page_token = 3 [(google.api.field_behavior) = OPTIONAL]; -} - -// The response message for [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. -message ListCallMatchersResponse { - // The list of call matchers. There is a maximum number of items - // returned based on the page_size field in the request. - repeated CallMatcher call_matchers = 1; - - // Token to retrieve the next page of results or empty if there are no - // more results in the list. - string next_page_token = 2; -} - -// The request message for [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2.Conversations.DeleteCallMatcher]. -message DeleteCallMatcherRequest { - // Required. The unique identifier of the [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] to delete. - // Format: `projects//locations//conversations//callMatchers/`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/CallMatcher" - } - ]; -} - // The request message for [Conversations.ListMessages][google.cloud.dialogflow.v2.Conversations.ListMessages]. message ListMessagesRequest { // Required. The name of the conversation to list messages for. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/conversation_profile.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/conversation_profile.proto index ea0fc6f022a6..8194ae224bd4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/conversation_profile.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/conversation_profile.proto @@ -434,10 +434,7 @@ message HumanAgentAssistantConfig { // Required. Conversation model resource name. Format: `projects//conversationModels/`. string model = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/ConversationModel" - } + (google.api.field_behavior) = REQUIRED ]; } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/document.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/document.proto index 5ff579960693..a3bc4b77bf5d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/document.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/document.proto @@ -47,6 +47,9 @@ service Documents { additional_bindings { get: "/v2/{parent=projects/*/locations/*/knowledgeBases/*}/documents" } + additional_bindings { + get: "/v2/{parent=projects/*/agent/knowledgeBases/*}/documents" + } }; option (google.api.method_signature) = "parent"; } @@ -58,6 +61,9 @@ service Documents { additional_bindings { get: "/v2/{name=projects/*/locations/*/knowledgeBases/*/documents/*}" } + additional_bindings { + get: "/v2/{name=projects/*/agent/knowledgeBases/*/documents/*}" + } }; option (google.api.method_signature) = "name"; } @@ -74,6 +80,10 @@ service Documents { post: "/v2/{parent=projects/*/locations/*/knowledgeBases/*}/documents" body: "document" } + additional_bindings { + post: "/v2/{parent=projects/*/agent/knowledgeBases/*}/documents" + body: "document" + } }; option (google.api.method_signature) = "parent,document"; option (google.longrunning.operation_info) = { @@ -92,6 +102,9 @@ service Documents { additional_bindings { delete: "/v2/{name=projects/*/locations/*/knowledgeBases/*/documents/*}" } + additional_bindings { + delete: "/v2/{name=projects/*/agent/knowledgeBases/*/documents/*}" + } }; option (google.api.method_signature) = "name"; option (google.longrunning.operation_info) = { @@ -112,6 +125,10 @@ service Documents { patch: "/v2/{document.name=projects/*/locations/*/knowledgeBases/*/documents/*}" body: "document" } + additional_bindings { + patch: "/v2/{document.name=projects/*/agent/knowledgeBases/*/documents/*}" + body: "document" + } }; option (google.api.method_signature) = "document,update_mask"; option (google.longrunning.operation_info) = { @@ -138,6 +155,10 @@ service Documents { post: "/v2/{name=projects/*/locations/*/knowledgeBases/*/documents/*}:reload" body: "*" } + additional_bindings { + post: "/v2/{name=projects/*/agent/knowledgeBases/*/documents/*}:reload" + body: "*" + } }; option (google.api.method_signature) = "name,content_uri"; option (google.longrunning.operation_info) = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/entity_type.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/entity_type.proto index f8a69ec58e90..c15b5a188638 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/entity_type.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/entity_type.proto @@ -43,6 +43,9 @@ service EntityTypes { rpc ListEntityTypes(ListEntityTypesRequest) returns (ListEntityTypesResponse) { option (google.api.http) = { get: "/v2/{parent=projects/*/agent}/entityTypes" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*/agent}/entityTypes" + } }; option (google.api.method_signature) = "parent"; option (google.api.method_signature) = "parent,language_code"; @@ -52,6 +55,9 @@ service EntityTypes { rpc GetEntityType(GetEntityTypeRequest) returns (EntityType) { option (google.api.http) = { get: "/v2/{name=projects/*/agent/entityTypes/*}" + additional_bindings { + get: "/v2/{name=projects/*/locations/*/agent/entityTypes/*}" + } }; option (google.api.method_signature) = "name"; option (google.api.method_signature) = "name,language_code"; @@ -62,6 +68,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/entityTypes" body: "entity_type" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/entityTypes" + body: "entity_type" + } }; option (google.api.method_signature) = "parent,entity_type"; option (google.api.method_signature) = "parent,entity_type,language_code"; @@ -72,6 +82,10 @@ service EntityTypes { option (google.api.http) = { patch: "/v2/{entity_type.name=projects/*/agent/entityTypes/*}" body: "entity_type" + additional_bindings { + patch: "/v2/{entity_type.name=projects/*/locations/*/agent/entityTypes/*}" + body: "entity_type" + } }; option (google.api.method_signature) = "entity_type"; option (google.api.method_signature) = "entity_type,language_code"; @@ -81,6 +95,9 @@ service EntityTypes { rpc DeleteEntityType(DeleteEntityTypeRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v2/{name=projects/*/agent/entityTypes/*}" + additional_bindings { + delete: "/v2/{name=projects/*/locations/*/agent/entityTypes/*}" + } }; option (google.api.method_signature) = "name"; } @@ -92,6 +109,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/entityTypes:batchUpdate" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/entityTypes:batchUpdate" + body: "*" + } }; option (google.longrunning.operation_info) = { response_type: "google.cloud.dialogflow.v2.BatchUpdateEntityTypesResponse" @@ -106,6 +127,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/entityTypes:batchDelete" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/entityTypes:batchDelete" + body: "*" + } }; option (google.api.method_signature) = "parent,entity_type_names"; option (google.longrunning.operation_info) = { @@ -121,6 +146,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent/entityTypes/*}/entities:batchCreate" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent/entityTypes/*}/entities:batchCreate" + body: "*" + } }; option (google.api.method_signature) = "parent,entities"; option (google.api.method_signature) = "parent,entities,language_code"; @@ -140,6 +169,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent/entityTypes/*}/entities:batchUpdate" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent/entityTypes/*}/entities:batchUpdate" + body: "*" + } }; option (google.api.method_signature) = "parent,entities"; option (google.api.method_signature) = "parent,entities,language_code"; @@ -157,6 +190,10 @@ service EntityTypes { option (google.api.http) = { post: "/v2/{parent=projects/*/agent/entityTypes/*}/entities:batchDelete" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent/entityTypes/*}/entities:batchDelete" + body: "*" + } }; option (google.api.method_signature) = "parent,entity_values"; option (google.api.method_signature) = "parent,entity_values,language_code"; diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/environment.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/environment.proto index ef094c71e562..db88854254b2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/environment.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/environment.proto @@ -43,6 +43,9 @@ service Environments { rpc ListEnvironments(ListEnvironmentsRequest) returns (ListEnvironmentsResponse) { option (google.api.http) = { get: "/v2/{parent=projects/*/agent}/environments" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*/agent}/environments" + } }; } } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/intent.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/intent.proto index e1507a5c9579..b611095859fa 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/intent.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/intent.proto @@ -47,6 +47,9 @@ service Intents { rpc ListIntents(ListIntentsRequest) returns (ListIntentsResponse) { option (google.api.http) = { get: "/v2/{parent=projects/*/agent}/intents" + additional_bindings { + get: "/v2/{parent=projects/*/locations/*/agent}/intents" + } additional_bindings { get: "/v2/{parent=projects/*/agent/environments/*}/intents" } @@ -59,6 +62,9 @@ service Intents { rpc GetIntent(GetIntentRequest) returns (Intent) { option (google.api.http) = { get: "/v2/{name=projects/*/agent/intents/*}" + additional_bindings { + get: "/v2/{name=projects/*/locations/*/agent/intents/*}" + } }; option (google.api.method_signature) = "name"; option (google.api.method_signature) = "name,language_code"; @@ -69,6 +75,10 @@ service Intents { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/intents" body: "intent" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/intents" + body: "intent" + } }; option (google.api.method_signature) = "parent,intent"; option (google.api.method_signature) = "parent,intent,language_code"; @@ -79,6 +89,10 @@ service Intents { option (google.api.http) = { patch: "/v2/{intent.name=projects/*/agent/intents/*}" body: "intent" + additional_bindings { + patch: "/v2/{intent.name=projects/*/locations/*/agent/intents/*}" + body: "intent" + } }; option (google.api.method_signature) = "intent,language_code"; option (google.api.method_signature) = "intent,language_code,update_mask"; @@ -88,6 +102,9 @@ service Intents { rpc DeleteIntent(DeleteIntentRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v2/{name=projects/*/agent/intents/*}" + additional_bindings { + delete: "/v2/{name=projects/*/locations/*/agent/intents/*}" + } }; option (google.api.method_signature) = "name"; } @@ -99,6 +116,10 @@ service Intents { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/intents:batchUpdate" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/intents:batchUpdate" + body: "*" + } }; option (google.api.method_signature) = "parent,intent_batch_uri"; option (google.api.method_signature) = "parent,intent_batch_inline"; @@ -115,6 +136,10 @@ service Intents { option (google.api.http) = { post: "/v2/{parent=projects/*/agent}/intents:batchDelete" body: "*" + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent}/intents:batchDelete" + body: "*" + } }; option (google.api.method_signature) = "parent,intents"; option (google.longrunning.operation_info) = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/knowledge_base.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/knowledge_base.proto index 52dbed10ca58..0b1aa8b3ef1c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/knowledge_base.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/knowledge_base.proto @@ -45,6 +45,9 @@ service KnowledgeBases { additional_bindings { get: "/v2/{parent=projects/*/locations/*}/knowledgeBases" } + additional_bindings { + get: "/v2/{parent=projects/*/agent}/knowledgeBases" + } }; option (google.api.method_signature) = "parent"; } @@ -56,6 +59,9 @@ service KnowledgeBases { additional_bindings { get: "/v2/{name=projects/*/locations/*/knowledgeBases/*}" } + additional_bindings { + get: "/v2/{name=projects/*/agent/knowledgeBases/*}" + } }; option (google.api.method_signature) = "name"; } @@ -69,6 +75,10 @@ service KnowledgeBases { post: "/v2/{parent=projects/*/locations/*}/knowledgeBases" body: "knowledge_base" } + additional_bindings { + post: "/v2/{parent=projects/*/agent}/knowledgeBases" + body: "knowledge_base" + } }; option (google.api.method_signature) = "parent,knowledge_base"; } @@ -80,6 +90,9 @@ service KnowledgeBases { additional_bindings { delete: "/v2/{name=projects/*/locations/*/knowledgeBases/*}" } + additional_bindings { + delete: "/v2/{name=projects/*/agent/knowledgeBases/*}" + } }; option (google.api.method_signature) = "name"; } @@ -93,6 +106,10 @@ service KnowledgeBases { patch: "/v2/{knowledge_base.name=projects/*/locations/*/knowledgeBases/*}" body: "knowledge_base" } + additional_bindings { + patch: "/v2/{knowledge_base.name=projects/*/agent/knowledgeBases/*}" + body: "knowledge_base" + } }; option (google.api.method_signature) = "knowledge_base,update_mask"; } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/participant.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/participant.proto index 2c6e8573630b..91aa04543791 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/participant.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/participant.proto @@ -96,7 +96,7 @@ service Participants { // // Note: Always use agent versions for production traffic // sent to virtual agents. See [Versions and - // environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). + // environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). rpc AnalyzeContent(AnalyzeContentRequest) returns (AnalyzeContentResponse) { option (google.api.http) = { post: "/v2/{participant=projects/*/conversations/*/participants/*}:analyzeContent" @@ -107,28 +107,9 @@ service Participants { } }; option (google.api.method_signature) = "participant,text_input"; - option (google.api.method_signature) = "participant,audio_input"; option (google.api.method_signature) = "participant,event_input"; } - // Adds a text (chat, for example), or audio (phone recording, for example) - // message from a participant into the conversation. - // Note: This method is only available through the gRPC API (not REST). - // - // The top-level message sent to the client by the server is - // `StreamingAnalyzeContentResponse`. Multiple response messages can be - // returned in order. The first one or more messages contain the - // `recognition_result` field. Each result represents a more complete - // transcript of what the user said. The next message contains the - // `reply_text` field and potentially the `reply_audio` field. The message can - // also contain the `automated_agent_reply` field. - // - // Note: Always use agent versions for production traffic - // sent to virtual agents. See [Versions and - // environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - rpc StreamingAnalyzeContent(stream StreamingAnalyzeContentRequest) returns (stream StreamingAnalyzeContentResponse) { - } - // Gets suggested articles for a participant based on specific historical // messages. rpc SuggestArticles(SuggestArticlesRequest) returns (SuggestArticlesResponse) { @@ -317,9 +298,6 @@ message AnalyzeContentRequest { // The natural language text to be processed. TextInput text_input = 6; - // The natural language speech audio to be processed. - AudioInput audio_input = 7; - // An input event to send to Dialogflow. EventInput event_input = 8; } @@ -389,143 +367,6 @@ message AnalyzeContentResponse { DtmfParameters dtmf_parameters = 9; } -// The top-level message sent by the client to the -// [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] method. -// -// Multiple request messages should be sent in order: -// -// 1. The first message must contain -// [participant][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.participant], -// [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] and optionally -// [query_params][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.query_params]. If you want -// to receive an audio response, it should also contain -// [reply_audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.reply_audio_config]. -// The message must not contain -// [input][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input]. -// -// 2. If [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] in the first message -// was set to [audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.audio_config], -// all subsequent messages must contain -// [input_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_audio] to continue -// with Speech recognition. -// However, note that: -// -// * Dialogflow will bill you for the audio so far. -// * Dialogflow discards all Speech recognition results in favor of the -// text input. -// -// 3. If [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] in the first message was set -// to [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.text_config], then the second message -// must contain only [input_text][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_text]. -// Moreover, you must not send more than two messages. -// -// After you sent all input, you must half-close or abort the request stream. -message StreamingAnalyzeContentRequest { - // Required. The name of the participant this text comes from. - // Format: `projects//locations//conversations//participants/`. - string participant = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/Participant" - } - ]; - - // Required. The input config. - oneof config { - // Instructs the speech recognizer how to process the speech audio. - InputAudioConfig audio_config = 2; - - // The natural language text to be processed. - InputTextConfig text_config = 3; - } - - // Speech synthesis configuration. - // The speech synthesis settings for a virtual agent that may be configured - // for the associated conversation profile are not used when calling - // StreamingAnalyzeContent. If this configuration is not supplied, speech - // synthesis is disabled. - OutputAudioConfig reply_audio_config = 4; - - // Required. The input. - oneof input { - // The input audio content to be recognized. Must be sent if `audio_config` - // is set in the first message. The complete audio over all streaming - // messages must not exceed 1 minute. - bytes input_audio = 5; - - // The UTF-8 encoded natural language text to be processed. Must be sent if - // `text_config` is set in the first message. Text length must not exceed - // 256 bytes. The `input_text` field can be only sent once. - string input_text = 6; - - // The DTMF digits used to invoke intent and fill in parameter value. - // - // This input is ignored if the previous response indicated that DTMF input - // is not accepted. - TelephonyDtmfEvents input_dtmf = 9; - } - - // Parameters for a Dialogflow virtual-agent query. - QueryParameters query_params = 7; -} - -// The top-level message returned from the `StreamingAnalyzeContent` method. -// -// Multiple response messages can be returned in order: -// -// 1. If the input was set to streaming audio, the first one or more messages -// contain `recognition_result`. Each `recognition_result` represents a more -// complete transcript of what the user said. The last `recognition_result` -// has `is_final` set to `true`. -// -// 2. The next message contains `reply_text` and optionally `reply_audio` -// returned by an agent. This message may also contain -// `automated_agent_reply`. -message StreamingAnalyzeContentResponse { - // The result of speech recognition. - StreamingRecognitionResult recognition_result = 1; - - // The output text content. - // This field is set if an automated agent responded with a text for the user. - string reply_text = 2; - - // The audio data bytes encoded as specified in the request. - // This field is set if: - // - // - The `reply_audio_config` field is specified in the request. - // - The automated agent, which this output comes from, responded with audio. - // In such case, the `reply_audio.config` field contains settings used to - // synthesize the speech. - // - // In some scenarios, multiple output audio fields may be present in the - // response structure. In these cases, only the top-most-level audio output - // has content. - OutputAudio reply_audio = 3; - - // Only set if a Dialogflow automated agent has responded. - // Note that: [AutomatedAgentReply.detect_intent_response.output_audio][] - // and [AutomatedAgentReply.detect_intent_response.output_audio_config][] - // are always empty, use [reply_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentResponse.reply_audio] instead. - AutomatedAgentReply automated_agent_reply = 4; - - // Message analyzed by CCAI. - Message message = 6; - - // The suggestions for most recent human agent. The order is the same as - // [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] of - // [HumanAgentAssistantConfig.human_agent_suggestion_config][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.human_agent_suggestion_config]. - repeated SuggestionResult human_agent_suggestion_results = 7; - - // The suggestions for end user. The order is the same as - // [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] of - // [HumanAgentAssistantConfig.end_user_suggestion_config][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.end_user_suggestion_config]. - repeated SuggestionResult end_user_suggestion_results = 8; - - // Indicates the parameters of DTMF. - DtmfParameters dtmf_parameters = 10; -} - // The request message for [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. message SuggestArticlesRequest { // Required. The name of the participant to fetch suggestion for. @@ -620,17 +461,6 @@ message SuggestFaqAnswersResponse { int32 context_size = 3; } -// Represents the natural language speech audio to be processed. -message AudioInput { - // Required. Instructs the speech recognizer how to process the speech audio. - InputAudioConfig config = 1 [(google.api.field_behavior) = REQUIRED]; - - // Required. The natural language speech audio to be processed. - // A single request can contain up to 1 minute of speech audio data. - // The transcribed text cannot contain more than 256 bytes. - bytes audio = 2 [(google.api.field_behavior) = REQUIRED]; -} - // Represents the natural language speech audio to be played to the end user. message OutputAudio { // Instructs the speech synthesizer how to generate the speech @@ -720,14 +550,6 @@ message SuggestionResult { } } -// Defines the language used in the input text. -message InputTextConfig { - // Required. The language of this conversational query. See [Language - // Support](https://cloud.google.com/dialogflow/docs/reference/language) - // for a list of the currently supported language codes. - string language_code = 1 [(google.api.field_behavior) = REQUIRED]; -} - // Represents a part of a message possibly annotated with an entity. The part // can be an entity or purely a part of the message between two entities or // message start/end. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session.proto index 338489652fba..13e3abff73c7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session.proto @@ -69,6 +69,14 @@ service Sessions { post: "/v2/{session=projects/*/agent/environments/*/users/*/sessions/*}:detectIntent" body: "*" } + additional_bindings { + post: "/v2/{session=projects/*/locations/*/agent/sessions/*}:detectIntent" + body: "*" + } + additional_bindings { + post: "/v2/{session=projects/*/locations/*/agent/environments/*/users/*/sessions/*}:detectIntent" + body: "*" + } }; option (google.api.method_signature) = "session,query_input"; } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session_entity_type.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session_entity_type.proto index 0eceed81cc85..cac38be77b52 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session_entity_type.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/proto/session_entity_type.proto @@ -50,6 +50,12 @@ service SessionEntityTypes { additional_bindings { get: "/v2/{parent=projects/*/agent/environments/*/users/*/sessions/*}/entityTypes" } + additional_bindings { + get: "/v2/{parent=projects/*/locations/*/agent/sessions/*}/entityTypes" + } + additional_bindings { + get: "/v2/{parent=projects/*/locations/*/agent/environments/*/users/*/sessions/*}/entityTypes" + } }; option (google.api.method_signature) = "parent"; } @@ -65,6 +71,12 @@ service SessionEntityTypes { additional_bindings { get: "/v2/{name=projects/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" } + additional_bindings { + get: "/v2/{name=projects/*/locations/*/agent/sessions/*/entityTypes/*}" + } + additional_bindings { + get: "/v2/{name=projects/*/locations/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" + } }; option (google.api.method_signature) = "name"; } @@ -85,6 +97,14 @@ service SessionEntityTypes { post: "/v2/{parent=projects/*/agent/environments/*/users/*/sessions/*}/entityTypes" body: "session_entity_type" } + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent/sessions/*}/entityTypes" + body: "session_entity_type" + } + additional_bindings { + post: "/v2/{parent=projects/*/locations/*/agent/environments/*/users/*/sessions/*}/entityTypes" + body: "session_entity_type" + } }; option (google.api.method_signature) = "parent,session_entity_type"; } @@ -102,6 +122,14 @@ service SessionEntityTypes { patch: "/v2/{session_entity_type.name=projects/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" body: "session_entity_type" } + additional_bindings { + patch: "/v2/{session_entity_type.name=projects/*/locations/*/agent/sessions/*/entityTypes/*}" + body: "session_entity_type" + } + additional_bindings { + patch: "/v2/{session_entity_type.name=projects/*/locations/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" + body: "session_entity_type" + } }; option (google.api.method_signature) = "session_entity_type"; option (google.api.method_signature) = "session_entity_type,update_mask"; @@ -118,6 +146,12 @@ service SessionEntityTypes { additional_bindings { delete: "/v2/{name=projects/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" } + additional_bindings { + delete: "/v2/{name=projects/*/locations/*/agent/sessions/*/entityTypes/*}" + } + additional_bindings { + delete: "/v2/{name=projects/*/locations/*/agent/environments/*/users/*/sessions/*/entityTypes/*}" + } }; option (google.api.method_signature) = "name"; } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py index 8987cfbe7d06..b41e474a7b24 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py @@ -77,10 +77,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -88,6 +88,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -97,20 +100,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py index ff1f4bb3fcc4..3ace9db2e894 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py @@ -111,7 +111,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +122,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,18 +173,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -215,7 +188,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py index 1bb87d75c965..22f02de207f3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +167,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py index aad1111e55f8..cd5148715529 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py @@ -209,7 +209,7 @@ async def list_answer_records( Returns: google.cloud.dialogflow_v2.services.answer_records.pagers.ListAnswerRecordsAsyncPager: Response message for - [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. + [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. Iterating over this object will yield results and resolve additional pages automatically. @@ -324,11 +324,12 @@ async def update_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py index 3a04afa04c83..9940b63f18d5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py @@ -378,7 +378,7 @@ def list_answer_records( Returns: google.cloud.dialogflow_v2.services.answer_records.pagers.ListAnswerRecordsPager: Response message for - [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. + [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2.AnswerRecords.ListAnswerRecords]. Iterating over this object will yield results and resolve additional pages automatically. @@ -494,11 +494,12 @@ def update_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py index 01e16c3e55f7..d82b612918f0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py index f8c4c1a0ca38..38373a7c5d56 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py @@ -108,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -116,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -187,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -211,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py index e71fd94508ea..eec5d7448480 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -141,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -153,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -161,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -232,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py index 6072815450d0..350f2d7fc15b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py index dfeab86c6649..7e3153ef007f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py @@ -108,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -116,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -187,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -211,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py index 6802113505b3..3e5d003b545e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -141,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -153,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -161,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -232,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py index fad34b214a58..5768948c2164 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py index 41f695f7e563..9af6dd273aaa 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py @@ -111,7 +111,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,17 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py index acb03edac51a..d6ec1c60cdc5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,17 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py index 5e1ee33d9fda..7afd626e5fc0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py @@ -49,8 +49,6 @@ class ConversationsAsyncClient: DEFAULT_ENDPOINT = ConversationsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationsClient.DEFAULT_MTLS_ENDPOINT - call_matcher_path = staticmethod(ConversationsClient.call_matcher_path) - parse_call_matcher_path = staticmethod(ConversationsClient.parse_call_matcher_path) conversation_path = staticmethod(ConversationsClient.conversation_path) parse_conversation_path = staticmethod(ConversationsClient.parse_conversation_path) conversation_profile_path = staticmethod( @@ -534,272 +532,6 @@ async def complete_conversation( # Done; return the response. return response - async def create_call_matcher( - self, - request: conversation.CreateCallMatcherRequest = None, - *, - parent: str = None, - call_matcher: conversation.CallMatcher = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> conversation.CallMatcher: - r"""Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Args: - request (:class:`google.cloud.dialogflow_v2.types.CreateCallMatcherRequest`): - The request object. The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2.Conversations.CreateCallMatcher]. - parent (:class:`str`): - Required. Resource identifier of the conversation adding - the call matcher. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - call_matcher (:class:`google.cloud.dialogflow_v2.types.CallMatcher`): - Required. The call matcher to create. - This corresponds to the ``call_matcher`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2.types.CallMatcher: - Represents a call matcher that describes criteria for matching incoming SIP - calls to a conversation. When Dialogflow get a SIP - call from a third-party carrier, Dialogflow matches - the call to an existing conversation by either: - - - Extracting the conversation id from the [Call-Info - header](\ https://tools.ietf.org/html/rfc3261#section-20.9), - e.g. Call-Info: - - ;purpose=Goog-ContactCenter-Conversation. - - \* Or, if that doesn't work, matching incoming [SIP - headers](\ https://tools.ietf.org/html/rfc3261#section-7.3) - against any - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] - for the conversation. - - If an incoming SIP call without valid Call-Info - header matches to zero or multiple conversations with - CallMatcher, we reject it. - - A call matcher contains equality conditions for SIP - headers that all have to be fulfilled in order for a - SIP call to match. - - The matched SIP headers consist of well-known headers - (To, From, Call-ID) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] - is only valid if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, call_matcher]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.CreateCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - if call_matcher is not None: - request.call_matcher = call_matcher - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_call_matcher, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - async def list_call_matchers( - self, - request: conversation.ListCallMatchersRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListCallMatchersAsyncPager: - r"""Returns the list of all call matchers in the - specified conversation. - - Args: - request (:class:`google.cloud.dialogflow_v2.types.ListCallMatchersRequest`): - The request object. The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - parent (:class:`str`): - Required. The conversation to list all call matchers - from. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2.services.conversations.pagers.ListCallMatchersAsyncPager: - The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.ListCallMatchersRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_call_matchers, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListCallMatchersAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_call_matcher( - self, - request: conversation.DeleteCallMatcherRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Requests deletion of a call matcher. - - Args: - request (:class:`google.cloud.dialogflow_v2.types.DeleteCallMatcherRequest`): - The request object. The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2.Conversations.DeleteCallMatcher]. - name (:class:`str`): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] to - delete. Format: - ``projects//locations//conversations//callMatchers/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.DeleteCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_call_matcher, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), - ) - - # Send the request. - await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, - ) - async def list_messages( self, request: conversation.ListMessagesRequest = None, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py index b03655065ddc..16e68f100f2e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py @@ -158,22 +158,6 @@ def transport(self) -> ConversationsTransport: """ return self._transport - @staticmethod - def call_matcher_path(project: str, conversation: str, call_matcher: str,) -> str: - """Return a fully-qualified call_matcher string.""" - return "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}".format( - project=project, conversation=conversation, call_matcher=call_matcher, - ) - - @staticmethod - def parse_call_matcher_path(path: str) -> Dict[str, str]: - """Parse a call_matcher path into its component segments.""" - m = re.match( - r"^projects/(?P.+?)/conversations/(?P.+?)/callMatchers/(?P.+?)$", - path, - ) - return m.groupdict() if m else {} - @staticmethod def conversation_path(project: str, conversation: str,) -> str: """Return a fully-qualified conversation string.""" @@ -747,275 +731,6 @@ def complete_conversation( # Done; return the response. return response - def create_call_matcher( - self, - request: conversation.CreateCallMatcherRequest = None, - *, - parent: str = None, - call_matcher: conversation.CallMatcher = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> conversation.CallMatcher: - r"""Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Args: - request (google.cloud.dialogflow_v2.types.CreateCallMatcherRequest): - The request object. The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2.Conversations.CreateCallMatcher]. - parent (str): - Required. Resource identifier of the conversation adding - the call matcher. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - call_matcher (google.cloud.dialogflow_v2.types.CallMatcher): - Required. The call matcher to create. - This corresponds to the ``call_matcher`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2.types.CallMatcher: - Represents a call matcher that describes criteria for matching incoming SIP - calls to a conversation. When Dialogflow get a SIP - call from a third-party carrier, Dialogflow matches - the call to an existing conversation by either: - - - Extracting the conversation id from the [Call-Info - header](\ https://tools.ietf.org/html/rfc3261#section-20.9), - e.g. Call-Info: - - ;purpose=Goog-ContactCenter-Conversation. - - \* Or, if that doesn't work, matching incoming [SIP - headers](\ https://tools.ietf.org/html/rfc3261#section-7.3) - against any - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] - for the conversation. - - If an incoming SIP call without valid Call-Info - header matches to zero or multiple conversations with - CallMatcher, we reject it. - - A call matcher contains equality conditions for SIP - headers that all have to be fulfilled in order for a - SIP call to match. - - The matched SIP headers consist of well-known headers - (To, From, Call-ID) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] - is only valid if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, call_matcher]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.CreateCallMatcherRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.CreateCallMatcherRequest): - request = conversation.CreateCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - if call_matcher is not None: - request.call_matcher = call_matcher - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_call_matcher] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - def list_call_matchers( - self, - request: conversation.ListCallMatchersRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListCallMatchersPager: - r"""Returns the list of all call matchers in the - specified conversation. - - Args: - request (google.cloud.dialogflow_v2.types.ListCallMatchersRequest): - The request object. The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - parent (str): - Required. The conversation to list all call matchers - from. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2.services.conversations.pagers.ListCallMatchersPager: - The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.ListCallMatchersRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.ListCallMatchersRequest): - request = conversation.ListCallMatchersRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_call_matchers] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListCallMatchersPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_call_matcher( - self, - request: conversation.DeleteCallMatcherRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Requests deletion of a call matcher. - - Args: - request (google.cloud.dialogflow_v2.types.DeleteCallMatcherRequest): - The request object. The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2.Conversations.DeleteCallMatcher]. - name (str): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] to - delete. Format: - ``projects//locations//conversations//callMatchers/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.DeleteCallMatcherRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.DeleteCallMatcherRequest): - request = conversation.DeleteCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_call_matcher] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), - ) - - # Send the request. - rpc( - request, retry=retry, timeout=timeout, metadata=metadata, - ) - def list_messages( self, request: conversation.ListMessagesRequest = None, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/pagers.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/pagers.py index 6e93bdbf671c..d770c7e8adac 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/pagers.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/pagers.py @@ -158,134 +158,6 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) -class ListCallMatchersPager: - """A pager for iterating through ``list_call_matchers`` requests. - - This class thinly wraps an initial - :class:`google.cloud.dialogflow_v2.types.ListCallMatchersResponse` object, and - provides an ``__iter__`` method to iterate through its - ``call_matchers`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListCallMatchers`` requests and continue to iterate - through the ``call_matchers`` field on the - corresponding responses. - - All the usual :class:`google.cloud.dialogflow_v2.types.ListCallMatchersResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., conversation.ListCallMatchersResponse], - request: conversation.ListCallMatchersRequest, - response: conversation.ListCallMatchersResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.dialogflow_v2.types.ListCallMatchersRequest): - The initial request object. - response (google.cloud.dialogflow_v2.types.ListCallMatchersResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = conversation.ListCallMatchersRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterable[conversation.ListCallMatchersResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterable[conversation.CallMatcher]: - for page in self.pages: - yield from page.call_matchers - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) - - -class ListCallMatchersAsyncPager: - """A pager for iterating through ``list_call_matchers`` requests. - - This class thinly wraps an initial - :class:`google.cloud.dialogflow_v2.types.ListCallMatchersResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``call_matchers`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListCallMatchers`` requests and continue to iterate - through the ``call_matchers`` field on the - corresponding responses. - - All the usual :class:`google.cloud.dialogflow_v2.types.ListCallMatchersResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., Awaitable[conversation.ListCallMatchersResponse]], - request: conversation.ListCallMatchersRequest, - response: conversation.ListCallMatchersResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.dialogflow_v2.types.ListCallMatchersRequest): - The initial request object. - response (google.cloud.dialogflow_v2.types.ListCallMatchersResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = conversation.ListCallMatchersRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterable[conversation.ListCallMatchersResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - - def __aiter__(self) -> AsyncIterable[conversation.CallMatcher]: - async def async_generator(): - async for page in self.pages: - for response in page.call_matchers: - yield response - - return async_generator() - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) - - class ListMessagesPager: """A pager for iterating through ``list_messages`` requests. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py index 121fecedfb08..b96d45a4eac2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py @@ -27,7 +27,6 @@ from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore try: @@ -74,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -125,15 +124,6 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), - self.create_call_matcher: gapic_v1.method.wrap_method( - self.create_call_matcher, default_timeout=None, client_info=client_info, - ), - self.list_call_matchers: gapic_v1.method.wrap_method( - self.list_call_matchers, default_timeout=None, client_info=client_info, - ), - self.delete_call_matcher: gapic_v1.method.wrap_method( - self.delete_call_matcher, default_timeout=None, client_info=client_info, - ), self.list_messages: gapic_v1.method.wrap_method( self.list_messages, default_timeout=None, client_info=client_info, ), @@ -185,38 +175,6 @@ def complete_conversation( ]: raise NotImplementedError() - @property - def create_call_matcher( - self, - ) -> typing.Callable[ - [conversation.CreateCallMatcherRequest], - typing.Union[ - conversation.CallMatcher, typing.Awaitable[conversation.CallMatcher] - ], - ]: - raise NotImplementedError() - - @property - def list_call_matchers( - self, - ) -> typing.Callable[ - [conversation.ListCallMatchersRequest], - typing.Union[ - conversation.ListCallMatchersResponse, - typing.Awaitable[conversation.ListCallMatchersResponse], - ], - ]: - raise NotImplementedError() - - @property - def delete_call_matcher( - self, - ) -> typing.Callable[ - [conversation.DeleteCallMatcherRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], - ]: - raise NotImplementedError() - @property def list_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py index 5664521dbf19..f3b8a557823c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py @@ -28,7 +28,6 @@ from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore from .base import ConversationsTransport, DEFAULT_CLIENT_INFO @@ -109,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -117,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -188,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -212,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -384,89 +356,6 @@ def complete_conversation( ) return self._stubs["complete_conversation"] - @property - def create_call_matcher( - self, - ) -> Callable[[conversation.CreateCallMatcherRequest], conversation.CallMatcher]: - r"""Return a callable for the create call matcher method over gRPC. - - Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Returns: - Callable[[~.CreateCallMatcherRequest], - ~.CallMatcher]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "create_call_matcher" not in self._stubs: - self._stubs["create_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/CreateCallMatcher", - request_serializer=conversation.CreateCallMatcherRequest.serialize, - response_deserializer=conversation.CallMatcher.deserialize, - ) - return self._stubs["create_call_matcher"] - - @property - def list_call_matchers( - self, - ) -> Callable[ - [conversation.ListCallMatchersRequest], conversation.ListCallMatchersResponse - ]: - r"""Return a callable for the list call matchers method over gRPC. - - Returns the list of all call matchers in the - specified conversation. - - Returns: - Callable[[~.ListCallMatchersRequest], - ~.ListCallMatchersResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_call_matchers" not in self._stubs: - self._stubs["list_call_matchers"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/ListCallMatchers", - request_serializer=conversation.ListCallMatchersRequest.serialize, - response_deserializer=conversation.ListCallMatchersResponse.deserialize, - ) - return self._stubs["list_call_matchers"] - - @property - def delete_call_matcher( - self, - ) -> Callable[[conversation.DeleteCallMatcherRequest], empty.Empty]: - r"""Return a callable for the delete call matcher method over gRPC. - - Requests deletion of a call matcher. - - Returns: - Callable[[~.DeleteCallMatcherRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_call_matcher" not in self._stubs: - self._stubs["delete_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/DeleteCallMatcher", - request_serializer=conversation.DeleteCallMatcherRequest.serialize, - response_deserializer=empty.Empty.FromString, - ) - return self._stubs["delete_call_matcher"] - @property def list_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py index 8e0f7f3edf86..480cdcfaebd2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py @@ -29,7 +29,6 @@ from google.cloud.dialogflow_v2.types import conversation from google.cloud.dialogflow_v2.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore from .base import ConversationsTransport, DEFAULT_CLIENT_INFO from .grpc import ConversationsGrpcTransport @@ -64,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -142,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -154,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -233,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: @@ -392,92 +364,6 @@ def complete_conversation( ) return self._stubs["complete_conversation"] - @property - def create_call_matcher( - self, - ) -> Callable[ - [conversation.CreateCallMatcherRequest], Awaitable[conversation.CallMatcher] - ]: - r"""Return a callable for the create call matcher method over gRPC. - - Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Returns: - Callable[[~.CreateCallMatcherRequest], - Awaitable[~.CallMatcher]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "create_call_matcher" not in self._stubs: - self._stubs["create_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/CreateCallMatcher", - request_serializer=conversation.CreateCallMatcherRequest.serialize, - response_deserializer=conversation.CallMatcher.deserialize, - ) - return self._stubs["create_call_matcher"] - - @property - def list_call_matchers( - self, - ) -> Callable[ - [conversation.ListCallMatchersRequest], - Awaitable[conversation.ListCallMatchersResponse], - ]: - r"""Return a callable for the list call matchers method over gRPC. - - Returns the list of all call matchers in the - specified conversation. - - Returns: - Callable[[~.ListCallMatchersRequest], - Awaitable[~.ListCallMatchersResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_call_matchers" not in self._stubs: - self._stubs["list_call_matchers"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/ListCallMatchers", - request_serializer=conversation.ListCallMatchersRequest.serialize, - response_deserializer=conversation.ListCallMatchersResponse.deserialize, - ) - return self._stubs["list_call_matchers"] - - @property - def delete_call_matcher( - self, - ) -> Callable[[conversation.DeleteCallMatcherRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the delete call matcher method over gRPC. - - Requests deletion of a call matcher. - - Returns: - Callable[[~.DeleteCallMatcherRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_call_matcher" not in self._stubs: - self._stubs["delete_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2.Conversations/DeleteCallMatcher", - request_serializer=conversation.DeleteCallMatcherRequest.serialize, - response_deserializer=empty.Empty.FromString, - ) - return self._stubs["delete_call_matcher"] - @property def list_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py index ed8d58937894..39425610bebe 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py @@ -75,10 +75,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -86,6 +86,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -95,20 +98,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py index 9f6d6f9acf71..e5cb89e6a58f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py @@ -110,7 +110,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -118,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -189,18 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py index 0d762777cd99..105dd373994d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -143,10 +143,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -155,7 +155,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -234,18 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py index 40e713587ac4..a2b32c6a10a9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py index d8f6831afcbe..cf9544f77296 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py @@ -111,7 +111,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +122,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,18 +173,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -215,7 +188,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py index ed7f16d0594e..7ce05d2e15ed 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +167,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py index 3f074dc7f403..35fd89eb7063 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py @@ -72,10 +72,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -83,6 +83,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -92,20 +95,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py index 0106e187e3cd..fd702da8b4f8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py @@ -107,7 +107,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -115,70 +117,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -186,17 +168,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -210,7 +183,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py index 25c848092bb2..f6c738c97b5f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -140,10 +140,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -152,7 +152,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -160,70 +162,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -231,17 +213,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py index 963054bce4b9..57253e26fae5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py index eda6678effa5..605e3f42f3e8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py @@ -110,7 +110,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -118,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -189,18 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py index 90a158dc92c7..4c2719a161d3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -143,10 +143,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -155,7 +155,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -234,18 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py index 9e68503ba50c..8173590b503c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py index 44ec2542acee..dd1f16ca45de 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py @@ -109,7 +109,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -117,70 +119,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -188,17 +170,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -212,7 +185,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py index 3279f870fa80..f8372de6ab82 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -142,10 +142,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -154,7 +154,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,70 +164,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -233,17 +215,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py index ef57c3d3c54c..beba5d8c128f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py @@ -18,16 +18,7 @@ from collections import OrderedDict import functools import re -from typing import ( - Dict, - AsyncIterable, - Awaitable, - AsyncIterator, - Sequence, - Tuple, - Type, - Union, -) +from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore @@ -517,7 +508,6 @@ async def analyze_content( *, participant: str = None, text_input: session.TextInput = None, - audio_input: gcd_participant.AudioInput = None, event_input: session.EventInput = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -527,8 +517,8 @@ async def analyze_content( example) message from a participant into the conversation. Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). + virtual agents. See `Versions and + environments `__. Args: request (:class:`google.cloud.dialogflow_v2.types.AnalyzeContentRequest`): @@ -549,13 +539,6 @@ async def analyze_content( This corresponds to the ``text_input`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - audio_input (:class:`google.cloud.dialogflow_v2.types.AudioInput`): - The natural language speech audio to - be processed. - - This corresponds to the ``audio_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. event_input (:class:`google.cloud.dialogflow_v2.types.EventInput`): An input event to send to Dialogflow. This corresponds to the ``event_input`` field @@ -577,7 +560,7 @@ async def analyze_content( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([participant, text_input, audio_input, event_input]) + has_flattened_params = any([participant, text_input, event_input]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -593,8 +576,6 @@ async def analyze_content( request.participant = participant if text_input is not None: request.text_input = text_input - if audio_input is not None: - request.audio_input = audio_input if event_input is not None: request.event_input = event_input @@ -607,6 +588,7 @@ async def analyze_content( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=DEFAULT_CLIENT_INFO, @@ -626,109 +608,6 @@ async def analyze_content( # Done; return the response. return response - def streaming_analyze_content( - self, - requests: AsyncIterator[participant.StreamingAnalyzeContentRequest] = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Awaitable[AsyncIterable[participant.StreamingAnalyzeContentResponse]]: - r"""Adds a text (chat, for example), or audio (phone recording, for - example) message from a participant into the conversation. Note: - This method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field and potentially the - ``reply_audio`` field. The message can also contain the - ``automated_agent_reply`` field. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Args: - requests (AsyncIterator[`google.cloud.dialogflow_v2.types.StreamingAnalyzeContentRequest`]): - The request object AsyncIterator. The top-level message sent by the - client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] - method. - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should - also contain - [reply_audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input]. - 2. If - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. - However, note that: - - * Dialogflow will bill you for the audio so far. - * Dialogflow discards all Speech recognition results - in favor of the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - After you sent all input, you must half-close or abort - the request stream. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - AsyncIterable[google.cloud.dialogflow_v2.types.StreamingAnalyzeContentResponse]: - The top-level message returned from the - StreamingAnalyzeContent method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. - 2. The next message contains reply_text and - optionally reply_audio returned by an agent. This - message may also contain automated_agent_reply. - - """ - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.streaming_analyze_content, - default_timeout=220.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = rpc(requests, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - async def suggest_articles( self, request: participant.SuggestArticlesRequest = None, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py index 086d9909c891..9500f818fbe5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py @@ -19,17 +19,7 @@ from distutils import util import os import re -from typing import ( - Callable, - Dict, - Optional, - Iterable, - Iterator, - Sequence, - Tuple, - Type, - Union, -) +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore @@ -749,7 +739,6 @@ def analyze_content( *, participant: str = None, text_input: session.TextInput = None, - audio_input: gcd_participant.AudioInput = None, event_input: session.EventInput = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -759,8 +748,8 @@ def analyze_content( example) message from a participant into the conversation. Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). + virtual agents. See `Versions and + environments `__. Args: request (google.cloud.dialogflow_v2.types.AnalyzeContentRequest): @@ -781,13 +770,6 @@ def analyze_content( This corresponds to the ``text_input`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - audio_input (google.cloud.dialogflow_v2.types.AudioInput): - The natural language speech audio to - be processed. - - This corresponds to the ``audio_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. event_input (google.cloud.dialogflow_v2.types.EventInput): An input event to send to Dialogflow. This corresponds to the ``event_input`` field @@ -809,7 +791,7 @@ def analyze_content( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([participant, text_input, audio_input, event_input]) + has_flattened_params = any([participant, text_input, event_input]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -830,8 +812,6 @@ def analyze_content( request.participant = participant if text_input is not None: request.text_input = text_input - if audio_input is not None: - request.audio_input = audio_input if event_input is not None: request.event_input = event_input @@ -853,107 +833,6 @@ def analyze_content( # Done; return the response. return response - def streaming_analyze_content( - self, - requests: Iterator[participant.StreamingAnalyzeContentRequest] = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Iterable[participant.StreamingAnalyzeContentResponse]: - r"""Adds a text (chat, for example), or audio (phone recording, for - example) message from a participant into the conversation. Note: - This method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field and potentially the - ``reply_audio`` field. The message can also contain the - ``automated_agent_reply`` field. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Args: - requests (Iterator[google.cloud.dialogflow_v2.types.StreamingAnalyzeContentRequest]): - The request object iterator. The top-level message sent by the - client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] - method. - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should - also contain - [reply_audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input]. - 2. If - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. - However, note that: - - * Dialogflow will bill you for the audio so far. - * Dialogflow discards all Speech recognition results - in favor of the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - After you sent all input, you must half-close or abort - the request stream. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - Iterable[google.cloud.dialogflow_v2.types.StreamingAnalyzeContentResponse]: - The top-level message returned from the - StreamingAnalyzeContent method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. - 2. The next message contains reply_text and - optionally reply_audio returned by an agent. This - message may also contain automated_agent_reply. - - """ - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.streaming_analyze_content - ] - - # Send the request. - response = rpc(requests, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - def suggest_articles( self, request: participant.SuggestArticlesRequest = None, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py index bf2219e056ea..357674581617 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -129,15 +129,11 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=client_info, ), - self.streaming_analyze_content: gapic_v1.method.wrap_method( - self.streaming_analyze_content, - default_timeout=220.0, - client_info=client_info, - ), self.suggest_articles: gapic_v1.method.wrap_method( self.suggest_articles, default_timeout=None, client_info=client_info, ), @@ -203,18 +199,6 @@ def analyze_content( ]: raise NotImplementedError() - @property - def streaming_analyze_content( - self, - ) -> typing.Callable[ - [participant.StreamingAnalyzeContentRequest], - typing.Union[ - participant.StreamingAnalyzeContentResponse, - typing.Awaitable[participant.StreamingAnalyzeContentResponse], - ], - ]: - raise NotImplementedError() - @property def suggest_articles( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py index 386acf35f6db..e4543e6bfe44 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py @@ -108,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -116,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -187,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -211,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -373,8 +346,8 @@ def analyze_content( example) message from a participant into the conversation. Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). + virtual agents. See `Versions and + environments `__. Returns: Callable[[~.AnalyzeContentRequest], @@ -394,50 +367,6 @@ def analyze_content( ) return self._stubs["analyze_content"] - @property - def streaming_analyze_content( - self, - ) -> Callable[ - [participant.StreamingAnalyzeContentRequest], - participant.StreamingAnalyzeContentResponse, - ]: - r"""Return a callable for the streaming analyze content method over gRPC. - - Adds a text (chat, for example), or audio (phone recording, for - example) message from a participant into the conversation. Note: - This method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field and potentially the - ``reply_audio`` field. The message can also contain the - ``automated_agent_reply`` field. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Returns: - Callable[[~.StreamingAnalyzeContentRequest], - ~.StreamingAnalyzeContentResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "streaming_analyze_content" not in self._stubs: - self._stubs["streaming_analyze_content"] = self.grpc_channel.stream_stream( - "/google.cloud.dialogflow.v2.Participants/StreamingAnalyzeContent", - request_serializer=participant.StreamingAnalyzeContentRequest.serialize, - response_deserializer=participant.StreamingAnalyzeContentResponse.deserialize, - ) - return self._stubs["streaming_analyze_content"] - @property def suggest_articles( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py index b00793e84c37..78dc60b4bf54 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -141,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -153,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -161,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -232,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: @@ -383,8 +356,8 @@ def analyze_content( example) message from a participant into the conversation. Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). + virtual agents. See `Versions and + environments `__. Returns: Callable[[~.AnalyzeContentRequest], @@ -404,50 +377,6 @@ def analyze_content( ) return self._stubs["analyze_content"] - @property - def streaming_analyze_content( - self, - ) -> Callable[ - [participant.StreamingAnalyzeContentRequest], - Awaitable[participant.StreamingAnalyzeContentResponse], - ]: - r"""Return a callable for the streaming analyze content method over gRPC. - - Adds a text (chat, for example), or audio (phone recording, for - example) message from a participant into the conversation. Note: - This method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field and potentially the - ``reply_audio`` field. The message can also contain the - ``automated_agent_reply`` field. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Returns: - Callable[[~.StreamingAnalyzeContentRequest], - Awaitable[~.StreamingAnalyzeContentResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "streaming_analyze_content" not in self._stubs: - self._stubs["streaming_analyze_content"] = self.grpc_channel.stream_stream( - "/google.cloud.dialogflow.v2.Participants/StreamingAnalyzeContent", - request_serializer=participant.StreamingAnalyzeContentRequest.serialize, - response_deserializer=participant.StreamingAnalyzeContentResponse.deserialize, - ) - return self._stubs["streaming_analyze_content"] - @property def suggest_articles( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py index 67a27daff2ac..529860533fdd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py index 9c59bc9217e6..d6807036524d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py @@ -111,7 +111,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,17 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py index 7f8d60544547..feaffcd71930 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,17 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py index 5107f62c49c6..e479f1bce130 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py @@ -289,6 +289,7 @@ async def detect_intent( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py index c29e65fe1e92..4441c222d5e5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=client_info, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py index a1453406e6a8..995202acf5a0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py @@ -110,7 +110,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -118,70 +120,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -189,17 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -213,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py index fe8954714133..69689dd2aa66 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -143,10 +143,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -155,7 +155,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,70 +165,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -234,17 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/__init__.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/__init__.py index 8b850081c61f..ba48aa9dae3a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/__init__.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/__init__.py @@ -45,13 +45,11 @@ SpeechToTextConfig, SpeechWordInfo, SynthesizeSpeechConfig, - TelephonyDtmfEvents, VoiceSelectionParams, AudioEncoding, OutputAudioEncoding, SpeechModelVariant, SsmlVoiceGender, - TelephonyDtmf, ) from .context import ( Context, @@ -64,16 +62,11 @@ UpdateContextRequest, ) from .conversation import ( - CallMatcher, CompleteConversationRequest, Conversation, ConversationPhoneNumber, - CreateCallMatcherRequest, CreateConversationRequest, - DeleteCallMatcherRequest, GetConversationRequest, - ListCallMatchersRequest, - ListCallMatchersResponse, ListConversationsRequest, ListConversationsResponse, ListMessagesRequest, @@ -156,21 +149,17 @@ AnalyzeContentResponse, AnnotatedMessagePart, ArticleAnswer, - AudioInput, AutomatedAgentReply, CreateParticipantRequest, DtmfParameters, FaqAnswer, GetParticipantRequest, - InputTextConfig, ListParticipantsRequest, ListParticipantsResponse, Message, MessageAnnotation, OutputAudio, Participant, - StreamingAnalyzeContentRequest, - StreamingAnalyzeContentResponse, SuggestArticlesRequest, SuggestArticlesResponse, SuggestFaqAnswersRequest, @@ -238,13 +227,11 @@ "SpeechToTextConfig", "SpeechWordInfo", "SynthesizeSpeechConfig", - "TelephonyDtmfEvents", "VoiceSelectionParams", "AudioEncoding", "OutputAudioEncoding", "SpeechModelVariant", "SsmlVoiceGender", - "TelephonyDtmf", "Context", "CreateContextRequest", "DeleteAllContextsRequest", @@ -253,16 +240,11 @@ "ListContextsRequest", "ListContextsResponse", "UpdateContextRequest", - "CallMatcher", "CompleteConversationRequest", "Conversation", "ConversationPhoneNumber", - "CreateCallMatcherRequest", "CreateConversationRequest", - "DeleteCallMatcherRequest", "GetConversationRequest", - "ListCallMatchersRequest", - "ListCallMatchersResponse", "ListConversationsRequest", "ListConversationsResponse", "ListMessagesRequest", @@ -331,21 +313,17 @@ "AnalyzeContentResponse", "AnnotatedMessagePart", "ArticleAnswer", - "AudioInput", "AutomatedAgentReply", "CreateParticipantRequest", "DtmfParameters", "FaqAnswer", "GetParticipantRequest", - "InputTextConfig", "ListParticipantsRequest", "ListParticipantsResponse", "Message", "MessageAnnotation", "OutputAudio", "Participant", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "SuggestArticlesRequest", "SuggestArticlesResponse", "SuggestFaqAnswersRequest", diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/audio_config.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/audio_config.py index 83d724e1dada..4b8ecf6d81d9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/audio_config.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/audio_config.py @@ -28,14 +28,12 @@ "SpeechModelVariant", "SsmlVoiceGender", "OutputAudioEncoding", - "TelephonyDtmf", "SpeechContext", "SpeechWordInfo", "InputAudioConfig", "VoiceSelectionParams", "SynthesizeSpeechConfig", "OutputAudioConfig", - "TelephonyDtmfEvents", "SpeechToTextConfig", }, ) @@ -89,30 +87,9 @@ class OutputAudioEncoding(proto.Enum): OUTPUT_AUDIO_ENCODING_UNSPECIFIED = 0 OUTPUT_AUDIO_ENCODING_LINEAR_16 = 1 OUTPUT_AUDIO_ENCODING_MP3 = 2 + OUTPUT_AUDIO_ENCODING_MP3_64_KBPS = 4 OUTPUT_AUDIO_ENCODING_OGG_OPUS = 3 - - -class TelephonyDtmf(proto.Enum): - r"""`DTMF `__ - digit in Telephony Gateway. - """ - TELEPHONY_DTMF_UNSPECIFIED = 0 - DTMF_ONE = 1 - DTMF_TWO = 2 - DTMF_THREE = 3 - DTMF_FOUR = 4 - DTMF_FIVE = 5 - DTMF_SIX = 6 - DTMF_SEVEN = 7 - DTMF_EIGHT = 8 - DTMF_NINE = 9 - DTMF_ZERO = 10 - DTMF_A = 11 - DTMF_B = 12 - DTMF_C = 13 - DTMF_D = 14 - DTMF_STAR = 15 - DTMF_POUND = 16 + OUTPUT_AUDIO_ENCODING_MULAW = 5 class SpeechContext(proto.Message): @@ -404,17 +381,6 @@ class OutputAudioConfig(proto.Message): ) -class TelephonyDtmfEvents(proto.Message): - r"""A wrapper of repeated TelephonyDtmf digits. - - Attributes: - dtmf_events (Sequence[google.cloud.dialogflow_v2.types.TelephonyDtmf]): - A sequence of TelephonyDtmf digits. - """ - - dtmf_events = proto.RepeatedField(proto.ENUM, number=1, enum="TelephonyDtmf",) - - class SpeechToTextConfig(proto.Message): r"""Configures speech transcription for [ConversationProfile][google.cloud.dialogflow.v2.ConversationProfile]. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/conversation.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/conversation.py index 7548e1730bb4..a53db5ebe1f5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/conversation.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/conversation.py @@ -26,16 +26,11 @@ package="google.cloud.dialogflow.v2", manifest={ "Conversation", - "CallMatcher", "CreateConversationRequest", "ListConversationsRequest", "ListConversationsResponse", "GetConversationRequest", "CompleteConversationRequest", - "CreateCallMatcherRequest", - "ListCallMatchersRequest", - "ListCallMatchersResponse", - "DeleteCallMatcherRequest", "ListMessagesRequest", "ListMessagesResponse", "ConversationPhoneNumber", @@ -124,85 +119,6 @@ class ConversationStage(proto.Enum): conversation_stage = proto.Field(proto.ENUM, number=7, enum=ConversationStage,) -class CallMatcher(proto.Message): - r"""Represents a call matcher that describes criteria for matching - incoming SIP calls to a conversation. When Dialogflow get a SIP call - from a third-party carrier, Dialogflow matches the call to an - existing conversation by either: - - - Extracting the conversation id from the `Call-Info - header `__, - e.g. - ``Call-Info: ;purpose=Goog-ContactCenter-Conversation``. - - Or, if that doesn't work, matching incoming `SIP - headers `__ - against any [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] - for the conversation. - - If an incoming SIP call without valid ``Call-Info`` header matches - to zero or multiple conversations with ``CallMatcher``, we reject - it. - - A call matcher contains equality conditions for SIP headers that all - have to be fulfilled in order for a SIP call to match. - - The matched SIP headers consist of well-known headers (``To``, - ``From``, ``Call-ID``) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] is only valid - if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - Attributes: - name (str): - Output only. The unique identifier of this call matcher. - Format: - ``projects//locations//conversations//callMatchers/``. - to_header (str): - Value of the ```To`` - header `__ - to match. If empty or unspecified, we don't match to the - ```To`` - header `__. - from_header (str): - Value of the ```From`` - header `__ - to match. If empty or unspecified, we don't match to the - ```From`` - header `__. - call_id_header (str): - Value of the ```Call-ID`` - header `__ - to match. If empty or unspecified, we don't match to the - ```Call-ID`` - header `__. - custom_headers (google.cloud.dialogflow_v2.types.CallMatcher.CustomHeaders): - Custom SIP headers that must match. - """ - - class CustomHeaders(proto.Message): - r"""Custom SIP headers. See the `description of headers in the - RFC `__. - - Attributes: - cisco_guid (str): - Cisco's proprietary ``Cisco-Guid`` header. - """ - - cisco_guid = proto.Field(proto.STRING, number=1) - - name = proto.Field(proto.STRING, number=1) - - to_header = proto.Field(proto.STRING, number=2) - - from_header = proto.Field(proto.STRING, number=3) - - call_id_header = proto.Field(proto.STRING, number=4) - - custom_headers = proto.Field(proto.MESSAGE, number=5, message=CustomHeaders,) - - class CreateConversationRequest(proto.Message): r"""The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2.Conversations.CreateConversation]. @@ -337,86 +253,6 @@ class CompleteConversationRequest(proto.Message): name = proto.Field(proto.STRING, number=1) -class CreateCallMatcherRequest(proto.Message): - r"""The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2.Conversations.CreateCallMatcher]. - - Attributes: - parent (str): - Required. Resource identifier of the conversation adding the - call matcher. Format: - ``projects//locations//conversations/``. - call_matcher (google.cloud.dialogflow_v2.types.CallMatcher): - Required. The call matcher to create. - """ - - parent = proto.Field(proto.STRING, number=1) - - call_matcher = proto.Field(proto.MESSAGE, number=2, message="CallMatcher",) - - -class ListCallMatchersRequest(proto.Message): - r"""The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - - Attributes: - parent (str): - Required. The conversation to list all call matchers from. - Format: - ``projects//locations//conversations/``. - page_size (int): - Optional. The maximum number of items to - return in a single page. By default 100 and at - most 1000. - page_token (str): - Optional. The next_page_token value returned from a previous - list request. - """ - - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - -class ListCallMatchersResponse(proto.Message): - r"""The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2.Conversations.ListCallMatchers]. - - Attributes: - call_matchers (Sequence[google.cloud.dialogflow_v2.types.CallMatcher]): - The list of call matchers. There is a maximum number of - items returned based on the page_size field in the request. - next_page_token (str): - Token to retrieve the next page of results or - empty if there are no more results in the list. - """ - - @property - def raw_page(self): - return self - - call_matchers = proto.RepeatedField(proto.MESSAGE, number=1, message="CallMatcher",) - - next_page_token = proto.Field(proto.STRING, number=2) - - -class DeleteCallMatcherRequest(proto.Message): - r"""The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2.Conversations.DeleteCallMatcher]. - - Attributes: - name (str): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2.CallMatcher] to - delete. Format: - ``projects//locations//conversations//callMatchers/``. - """ - - name = proto.Field(proto.STRING, number=1) - - class ListMessagesRequest(proto.Message): r"""The request message for [Conversations.ListMessages][google.cloud.dialogflow.v2.Conversations.ListMessages]. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/participant.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/participant.py index 1be79ddc07d1..e965b4a090fd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/participant.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/types/participant.py @@ -18,7 +18,7 @@ import proto # type: ignore -from google.cloud.dialogflow_v2.types import audio_config as gcd_audio_config +from google.cloud.dialogflow_v2.types import audio_config from google.cloud.dialogflow_v2.types import session from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import struct_pb2 as struct # type: ignore @@ -39,19 +39,15 @@ "AnalyzeContentRequest", "DtmfParameters", "AnalyzeContentResponse", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "SuggestArticlesRequest", "SuggestArticlesResponse", "SuggestFaqAnswersRequest", "SuggestFaqAnswersResponse", - "AudioInput", "OutputAudio", "AutomatedAgentReply", "ArticleAnswer", "FaqAnswer", "SuggestionResult", - "InputTextConfig", "AnnotatedMessagePart", "MessageAnnotation", }, @@ -242,9 +238,6 @@ class AnalyzeContentRequest(proto.Message): ``projects//locations//conversations//participants/``. text_input (google.cloud.dialogflow_v2.types.TextInput): The natural language text to be processed. - audio_input (google.cloud.dialogflow_v2.types.AudioInput): - The natural language speech audio to be - processed. event_input (google.cloud.dialogflow_v2.types.EventInput): An input event to send to Dialogflow. reply_audio_config (google.cloud.dialogflow_v2.types.OutputAudioConfig): @@ -269,16 +262,12 @@ class AnalyzeContentRequest(proto.Message): proto.MESSAGE, number=6, oneof="input", message=session.TextInput, ) - audio_input = proto.Field( - proto.MESSAGE, number=7, oneof="input", message="AudioInput", - ) - event_input = proto.Field( proto.MESSAGE, number=8, oneof="input", message=session.EventInput, ) reply_audio_config = proto.Field( - proto.MESSAGE, number=5, message=gcd_audio_config.OutputAudioConfig, + proto.MESSAGE, number=5, message=audio_config.OutputAudioConfig, ) query_params = proto.Field( @@ -369,203 +358,6 @@ class AnalyzeContentResponse(proto.Message): dtmf_parameters = proto.Field(proto.MESSAGE, number=9, message="DtmfParameters",) -class StreamingAnalyzeContentRequest(proto.Message): - r"""The top-level message sent by the client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] - method. - - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should also contain - [reply_audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input]. - - 2. If - [config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. However, note that: - - - Dialogflow will bill you for the audio so far. - - Dialogflow discards all Speech recognition results in favor of - the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - - After you sent all input, you must half-close or abort the request - stream. - - Attributes: - participant (str): - Required. The name of the participant this text comes from. - Format: - ``projects//locations//conversations//participants/``. - audio_config (google.cloud.dialogflow_v2.types.InputAudioConfig): - Instructs the speech recognizer how to - process the speech audio. - text_config (google.cloud.dialogflow_v2.types.InputTextConfig): - The natural language text to be processed. - reply_audio_config (google.cloud.dialogflow_v2.types.OutputAudioConfig): - Speech synthesis configuration. - The speech synthesis settings for a virtual - agent that may be configured for the associated - conversation profile are not used when calling - StreamingAnalyzeContent. If this configuration - is not supplied, speech synthesis is disabled. - input_audio (bytes): - The input audio content to be recognized. Must be sent if - ``audio_config`` is set in the first message. The complete - audio over all streaming messages must not exceed 1 minute. - input_text (str): - The UTF-8 encoded natural language text to be processed. - Must be sent if ``text_config`` is set in the first message. - Text length must not exceed 256 bytes. The ``input_text`` - field can be only sent once. - input_dtmf (google.cloud.dialogflow_v2.types.TelephonyDtmfEvents): - The DTMF digits used to invoke intent and - fill in parameter value. - This input is ignored if the previous response - indicated that DTMF input is not accepted. - query_params (google.cloud.dialogflow_v2.types.QueryParameters): - Parameters for a Dialogflow virtual-agent - query. - """ - - participant = proto.Field(proto.STRING, number=1) - - audio_config = proto.Field( - proto.MESSAGE, - number=2, - oneof="config", - message=gcd_audio_config.InputAudioConfig, - ) - - text_config = proto.Field( - proto.MESSAGE, number=3, oneof="config", message="InputTextConfig", - ) - - reply_audio_config = proto.Field( - proto.MESSAGE, number=4, message=gcd_audio_config.OutputAudioConfig, - ) - - input_audio = proto.Field(proto.BYTES, number=5, oneof="input") - - input_text = proto.Field(proto.STRING, number=6, oneof="input") - - input_dtmf = proto.Field( - proto.MESSAGE, - number=9, - oneof="input", - message=gcd_audio_config.TelephonyDtmfEvents, - ) - - query_params = proto.Field( - proto.MESSAGE, number=7, message=session.QueryParameters, - ) - - -class StreamingAnalyzeContentResponse(proto.Message): - r"""The top-level message returned from the ``StreamingAnalyzeContent`` - method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first one or more - messages contain ``recognition_result``. Each - ``recognition_result`` represents a more complete transcript of - what the user said. The last ``recognition_result`` has - ``is_final`` set to ``true``. - - 2. The next message contains ``reply_text`` and optionally - ``reply_audio`` returned by an agent. This message may also - contain ``automated_agent_reply``. - - Attributes: - recognition_result (google.cloud.dialogflow_v2.types.StreamingRecognitionResult): - The result of speech recognition. - reply_text (str): - The output text content. - This field is set if an automated agent - responded with a text for the user. - reply_audio (google.cloud.dialogflow_v2.types.OutputAudio): - The audio data bytes encoded as specified in the request. - This field is set if: - - - The ``reply_audio_config`` field is specified in the - request. - - The automated agent, which this output comes from, - responded with audio. In such case, the - ``reply_audio.config`` field contains settings used to - synthesize the speech. - - In some scenarios, multiple output audio fields may be - present in the response structure. In these cases, only the - top-most-level audio output has content. - automated_agent_reply (google.cloud.dialogflow_v2.types.AutomatedAgentReply): - Only set if a Dialogflow automated agent has responded. Note - that: - [AutomatedAgentReply.detect_intent_response.output_audio][] - and - [AutomatedAgentReply.detect_intent_response.output_audio_config][] - are always empty, use - [reply_audio][google.cloud.dialogflow.v2.StreamingAnalyzeContentResponse.reply_audio] - instead. - message (google.cloud.dialogflow_v2.types.Message): - Message analyzed by CCAI. - human_agent_suggestion_results (Sequence[google.cloud.dialogflow_v2.types.SuggestionResult]): - The suggestions for most recent human agent. The order is - the same as - [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] - of - [HumanAgentAssistantConfig.human_agent_suggestion_config][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.human_agent_suggestion_config]. - end_user_suggestion_results (Sequence[google.cloud.dialogflow_v2.types.SuggestionResult]): - The suggestions for end user. The order is the same as - [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] - of - [HumanAgentAssistantConfig.end_user_suggestion_config][google.cloud.dialogflow.v2.HumanAgentAssistantConfig.end_user_suggestion_config]. - dtmf_parameters (google.cloud.dialogflow_v2.types.DtmfParameters): - Indicates the parameters of DTMF. - """ - - recognition_result = proto.Field( - proto.MESSAGE, number=1, message=session.StreamingRecognitionResult, - ) - - reply_text = proto.Field(proto.STRING, number=2) - - reply_audio = proto.Field(proto.MESSAGE, number=3, message="OutputAudio",) - - automated_agent_reply = proto.Field( - proto.MESSAGE, number=4, message="AutomatedAgentReply", - ) - - message = proto.Field(proto.MESSAGE, number=6, message="Message",) - - human_agent_suggestion_results = proto.RepeatedField( - proto.MESSAGE, number=7, message="SuggestionResult", - ) - - end_user_suggestion_results = proto.RepeatedField( - proto.MESSAGE, number=8, message="SuggestionResult", - ) - - dtmf_parameters = proto.Field(proto.MESSAGE, number=10, message="DtmfParameters",) - - class SuggestArticlesRequest(proto.Message): r"""The request message for [Participants.SuggestArticles][google.cloud.dialogflow.v2.Participants.SuggestArticles]. @@ -686,28 +478,6 @@ class SuggestFaqAnswersResponse(proto.Message): context_size = proto.Field(proto.INT32, number=3) -class AudioInput(proto.Message): - r"""Represents the natural language speech audio to be processed. - - Attributes: - config (google.cloud.dialogflow_v2.types.InputAudioConfig): - Required. Instructs the speech recognizer how - to process the speech audio. - audio (bytes): - Required. The natural language speech audio - to be processed. A single request can contain up - to 1 minute of speech audio data. The - transcribed text cannot contain more than 256 - bytes. - """ - - config = proto.Field( - proto.MESSAGE, number=1, message=gcd_audio_config.InputAudioConfig, - ) - - audio = proto.Field(proto.BYTES, number=2) - - class OutputAudio(proto.Message): r"""Represents the natural language speech audio to be played to the end user. @@ -721,7 +491,7 @@ class OutputAudio(proto.Message): """ config = proto.Field( - proto.MESSAGE, number=1, message=gcd_audio_config.OutputAudioConfig, + proto.MESSAGE, number=1, message=audio_config.OutputAudioConfig, ) audio = proto.Field(proto.BYTES, number=2) @@ -858,20 +628,6 @@ class SuggestionResult(proto.Message): ) -class InputTextConfig(proto.Message): - r"""Defines the language used in the input text. - - Attributes: - language_code (str): - Required. The language of this conversational query. See - `Language - Support `__ - for a list of the currently supported language codes. - """ - - language_code = proto.Field(proto.STRING, number=1) - - class AnnotatedMessagePart(proto.Message): r"""Represents a part of a message possibly annotated with an entity. The part can be an entity or purely a part of the diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/__init__.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/__init__.py index 22d3476296fb..64c30902f4ce 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/__init__.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/__init__.py @@ -72,17 +72,12 @@ from .types.context import UpdateContextRequest from .types.conversation import BatchCreateMessagesRequest from .types.conversation import BatchCreateMessagesResponse -from .types.conversation import CallMatcher from .types.conversation import CompleteConversationRequest from .types.conversation import Conversation from .types.conversation import ConversationPhoneNumber -from .types.conversation import CreateCallMatcherRequest from .types.conversation import CreateConversationRequest from .types.conversation import CreateMessageRequest -from .types.conversation import DeleteCallMatcherRequest from .types.conversation import GetConversationRequest -from .types.conversation import ListCallMatchersRequest -from .types.conversation import ListCallMatchersResponse from .types.conversation import ListConversationsRequest from .types.conversation import ListConversationsResponse from .types.conversation import ListMessagesRequest @@ -155,7 +150,6 @@ from .types.participant import AnalyzeContentResponse from .types.participant import AnnotatedMessagePart from .types.participant import ArticleAnswer -from .types.participant import AudioInput from .types.participant import AutomatedAgentReply from .types.participant import CompileSuggestionRequest from .types.participant import CompileSuggestionResponse @@ -165,7 +159,6 @@ from .types.participant import GetParticipantRequest from .types.participant import InputAudio from .types.participant import InputText -from .types.participant import InputTextConfig from .types.participant import ListParticipantsRequest from .types.participant import ListParticipantsResponse from .types.participant import ListSuggestionsRequest @@ -176,8 +169,6 @@ from .types.participant import Participant from .types.participant import ResponseMessage from .types.participant import SmartReplyAnswer -from .types.participant import StreamingAnalyzeContentRequest -from .types.participant import StreamingAnalyzeContentResponse from .types.participant import SuggestArticlesRequest from .types.participant import SuggestArticlesResponse from .types.participant import SuggestFaqAnswersRequest @@ -229,7 +220,6 @@ "AnswerRecordsClient", "ArticleAnswer", "AudioEncoding", - "AudioInput", "AutomatedAgentConfig", "AutomatedAgentReply", "BatchCreateEntitiesRequest", @@ -243,7 +233,6 @@ "BatchUpdateEntityTypesResponse", "BatchUpdateIntentsRequest", "BatchUpdateIntentsResponse", - "CallMatcher", "CompileSuggestionRequest", "CompileSuggestionResponse", "CompleteConversationRequest", @@ -255,7 +244,6 @@ "ConversationProfile", "ConversationProfilesClient", "ConversationsClient", - "CreateCallMatcherRequest", "CreateContextRequest", "CreateConversationProfileRequest", "CreateConversationRequest", @@ -268,7 +256,6 @@ "CreateSessionEntityTypeRequest", "DeleteAgentRequest", "DeleteAllContextsRequest", - "DeleteCallMatcherRequest", "DeleteContextRequest", "DeleteConversationProfileRequest", "DeleteDocumentRequest", @@ -314,18 +301,15 @@ "InputAudio", "InputAudioConfig", "InputText", - "InputTextConfig", "Intent", "IntentBatch", "IntentView", + "IntentsClient", "KnowledgeAnswers", "KnowledgeBase", - "KnowledgeBasesClient", "KnowledgeOperationMetadata", "ListAnswerRecordsRequest", "ListAnswerRecordsResponse", - "ListCallMatchersRequest", - "ListCallMatchersResponse", "ListContextsRequest", "ListContextsResponse", "ListConversationProfilesRequest", @@ -381,8 +365,6 @@ "SpeechToTextConfig", "SpeechWordInfo", "SsmlVoiceGender", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "StreamingDetectIntentRequest", "StreamingDetectIntentResponse", "StreamingRecognitionResult", @@ -415,5 +397,5 @@ "VoiceSelectionParams", "WebhookRequest", "WebhookResponse", - "IntentsClient", + "KnowledgeBasesClient", ) diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/answer_record.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/answer_record.proto index b344010d1fc0..4f7b9f44a134 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/answer_record.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/answer_record.proto @@ -33,7 +33,8 @@ option java_outer_classname = "AnswerRecordsProto"; option java_package = "com.google.cloud.dialogflow.v2beta1"; option objc_class_prefix = "DF"; -// Service for managing [AnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecord]. +// Service for managing +// [AnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecord]. service AnswerRecords { option (google.api.default_host) = "dialogflow.googleapis.com"; option (google.api.oauth_scopes) = @@ -54,7 +55,8 @@ service AnswerRecords { // Returns the list of all answer records in the specified project in reverse // chronological order. - rpc ListAnswerRecords(ListAnswerRecordsRequest) returns (ListAnswerRecordsResponse) { + rpc ListAnswerRecords(ListAnswerRecordsRequest) + returns (ListAnswerRecordsResponse) { option (google.api.http) = { get: "/v2beta1/{parent=projects/*}/answerRecords" additional_bindings { @@ -99,9 +101,12 @@ service AnswerRecords { // A typical workflow for customers provide feedback to an answer is: // // 1. For human agent assistant, customers get suggestion via ListSuggestions -// API. Together with the answers, [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are returned to the -// customers. -// 2. The customer uses the [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] to call the +// API. Together with the answers, +// [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are +// returned to the customers. +// 2. The customer uses the +// [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] to +// call the // [UpdateAnswerRecord][] method to send feedback about a specific answer // that they believe is wrong. message AnswerRecord { @@ -112,14 +117,15 @@ message AnswerRecord { }; // The unique identifier of this answer record. - // Required for [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord] method. - // Format: `projects//locations//locations//answerRecords/`. string name = 1; // Optional. The AnswerFeedback for this record. You can set this with - // [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord] in order to give us feedback about - // this answer. + // [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord] + // in order to give us feedback about this answer. AnswerFeedback answer_feedback = 3; // Output only. The record for this answer. @@ -134,7 +140,8 @@ message AgentAssistantRecord { // Output only. The agent assistant answer. oneof answer { // Output only. The article suggestion answer. - ArticleAnswer article_suggestion_answer = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; + ArticleAnswer article_suggestion_answer = 5 + [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. The FAQ answer. FaqAnswer faq_answer = 6 [(google.api.field_behavior) = OUTPUT_ONLY]; @@ -256,7 +263,9 @@ message AgentAssistantFeedback { // Optional. Whether or not the suggested document is efficient. For example, // if the document is poorly written, hard to understand, hard to use or - // too long to find useful information, [document_efficiency][google.cloud.dialogflow.v2beta1.AgentAssistantFeedback.document_efficiency] is + // too long to find useful information, + // [document_efficiency][google.cloud.dialogflow.v2beta1.AgentAssistantFeedback.document_efficiency] + // is // [DocumentEfficiency.INEFFICIENT][google.cloud.dialogflow.v2beta1.AgentAssistantFeedback.DocumentEfficiency.INEFFICIENT]. DocumentEfficiency document_efficiency = 3; @@ -264,7 +273,8 @@ message AgentAssistantFeedback { SummarizationFeedback summarization_feedback = 4; } -// Request message for [AnswerRecords.GetAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.GetAnswerRecord]. +// Request message for +// [AnswerRecords.GetAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.GetAnswerRecord]. message GetAnswerRecordRequest { // Required. The name of the answer record to retrieve. // Format: `projects//locations//locations/`. string parent = 1 [(google.api.resource_reference) = { - child_type: "dialogflow.googleapis.com/AnswerRecord" - }]; + child_type: "dialogflow.googleapis.com/AnswerRecord" + }]; // Optional. The maximum number of records to return in a single page. // The server may return fewer records than this. If unspecified, we use 10. @@ -293,7 +304,8 @@ message ListAnswerRecordsRequest { string page_token = 4; } -// Response message for [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. +// Response message for +// [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. message ListAnswerRecordsResponse { // The list of answer records. repeated AnswerRecord answer_records = 1; @@ -307,15 +319,11 @@ message ListAnswerRecordsResponse { string next_page_token = 2; } -// Request message for [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord]. +// Request message for +// [AnswerRecords.UpdateAnswerRecord][google.cloud.dialogflow.v2beta1.AnswerRecords.UpdateAnswerRecord]. message UpdateAnswerRecordRequest { // Required. Answer record to update. - AnswerRecord answer_record = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/AnswerRecord" - } - ]; + AnswerRecord answer_record = 1 [(google.api.field_behavior) = REQUIRED]; // Required. The mask to control which fields get updated. google.protobuf.FieldMask update_mask = 2; diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/audio_config.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/audio_config.proto index 009a9473b3c7..f8c42b7db33d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/audio_config.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/audio_config.proto @@ -359,11 +359,17 @@ enum OutputAudioEncoding { // MP3 audio at 32kbps. OUTPUT_AUDIO_ENCODING_MP3 = 2; + // MP3 audio at 64kbps. + OUTPUT_AUDIO_ENCODING_MP3_64_KBPS = 4; + // Opus encoded audio wrapped in an ogg container. The result will be a // file which can be played natively on Android, and in browsers (at least // Chrome and Firefox). The quality of the encoding is considerably higher // than MP3 while using approximately the same bitrate. OUTPUT_AUDIO_ENCODING_OGG_OPUS = 3; + + // 8-bit samples that compand 14-bit audio samples using G.711 PCMU/mu-law. + OUTPUT_AUDIO_ENCODING_MULAW = 5; } // Configures speech transcription for [ConversationProfile][google.cloud.dialogflow.v2beta1.ConversationProfile]. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/conversation.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/conversation.proto index 068473823244..6e203540bbc4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/conversation.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/conversation.proto @@ -37,7 +37,8 @@ option java_outer_classname = "ConversationProto"; option java_package = "com.google.cloud.dialogflow.v2beta1"; option objc_class_prefix = "DF"; -// Service for managing [Conversations][google.cloud.dialogflow.v2beta1.Conversation]. +// Service for managing +// [Conversations][google.cloud.dialogflow.v2beta1.Conversation]. service Conversations { option (google.api.default_host) = "dialogflow.googleapis.com"; option (google.api.oauth_scopes) = @@ -57,11 +58,14 @@ service Conversations { // For Assist Stage, there's no dialogflow agent responding to user queries. // But we will provide suggestions which are generated from conversation. // - // If [Conversation.conversation_profile][google.cloud.dialogflow.v2beta1.Conversation.conversation_profile] is configured for a dialogflow - // agent, conversation will start from `Automated Agent Stage`, otherwise, it - // will start from `Assist Stage`. And during `Automated Agent Stage`, once an - // [Intent][google.cloud.dialogflow.v2beta1.Intent] with [Intent.live_agent_handoff][google.cloud.dialogflow.v2beta1.Intent.live_agent_handoff] is triggered, conversation - // will transfer to Assist Stage. + // If + // [Conversation.conversation_profile][google.cloud.dialogflow.v2beta1.Conversation.conversation_profile] + // is configured for a dialogflow agent, conversation will start from + // `Automated Agent Stage`, otherwise, it will start from `Assist Stage`. And + // during `Automated Agent Stage`, once an + // [Intent][google.cloud.dialogflow.v2beta1.Intent] with + // [Intent.live_agent_handoff][google.cloud.dialogflow.v2beta1.Intent.live_agent_handoff] + // is triggered, conversation will transfer to Assist Stage. rpc CreateConversation(CreateConversationRequest) returns (Conversation) { option (google.api.http) = { post: "/v2beta1/{parent=projects/*}/conversations" @@ -75,7 +79,8 @@ service Conversations { } // Returns the list of all conversations in the specified project. - rpc ListConversations(ListConversationsRequest) returns (ListConversationsResponse) { + rpc ListConversations(ListConversationsRequest) + returns (ListConversationsResponse) { option (google.api.http) = { get: "/v2beta1/{parent=projects/*}/conversations" additional_bindings { @@ -110,45 +115,10 @@ service Conversations { option (google.api.method_signature) = "name"; } - // Creates a call matcher that links incoming SIP calls to the specified - // conversation if they fulfill specified criteria. - rpc CreateCallMatcher(CreateCallMatcherRequest) returns (CallMatcher) { - option (google.api.http) = { - post: "/v2beta1/{parent=projects/*/conversations/*}/callMatchers" - body: "call_matcher" - additional_bindings { - post: "/v2beta1/{parent=projects/*/locations/*/conversations/*}/callMatchers" - body: "*" - } - }; - option (google.api.method_signature) = "parent,call_matcher"; - } - - // Returns the list of all call matchers in the specified conversation. - rpc ListCallMatchers(ListCallMatchersRequest) returns (ListCallMatchersResponse) { - option (google.api.http) = { - get: "/v2beta1/{parent=projects/*/conversations/*}/callMatchers" - additional_bindings { - get: "/v2beta1/{parent=projects/*/locations/*/conversations/*}/callMatchers" - } - }; - option (google.api.method_signature) = "parent"; - } - - // Requests deletion of a call matcher. - rpc DeleteCallMatcher(DeleteCallMatcherRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v2beta1/{name=projects/*/conversations/*/callMatchers/*}" - additional_bindings { - delete: "/v2beta1/{name=projects/*/locations/*/conversations/*/callMatchers/*}" - } - }; - option (google.api.method_signature) = "name"; - } - // Batch ingests messages to conversation. Customers can use this RPC to // ingest historical messages to conversation. - rpc BatchCreateMessages(BatchCreateMessagesRequest) returns (BatchCreateMessagesResponse) { + rpc BatchCreateMessages(BatchCreateMessagesRequest) + returns (BatchCreateMessagesResponse) { option (google.api.http) = { post: "/v2beta1/{parent=projects/*/conversations/*}/messages:batchCreate" body: "*" @@ -222,7 +192,8 @@ message Conversation { string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. The current state of the Conversation. - LifecycleState lifecycle_state = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; + LifecycleState lifecycle_state = 2 + [(google.api.field_behavior) = OUTPUT_ONLY]; // Required. The Conversation Profile to be used to configure this // Conversation. This field cannot be updated. @@ -237,28 +208,34 @@ message Conversation { // Output only. Required if the conversation is to be connected over // telephony. - ConversationPhoneNumber phone_number = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; + ConversationPhoneNumber phone_number = 4 + [(google.api.field_behavior) = OUTPUT_ONLY]; // The stage of a conversation. It indicates whether the virtual agent or a // human agent is handling the conversation. // // If the conversation is created with the conversation profile that has // Dialogflow config set, defaults to - // [ConversationStage.VIRTUAL_AGENT_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.VIRTUAL_AGENT_STAGE]; Otherwise, defaults to + // [ConversationStage.VIRTUAL_AGENT_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.VIRTUAL_AGENT_STAGE]; + // Otherwise, defaults to // [ConversationStage.HUMAN_ASSIST_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.HUMAN_ASSIST_STAGE]. // // If the conversation is created with the conversation profile that has // Dialogflow config set but explicitly sets conversation_stage to - // [ConversationStage.HUMAN_ASSIST_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.HUMAN_ASSIST_STAGE], it skips - // [ConversationStage.VIRTUAL_AGENT_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.VIRTUAL_AGENT_STAGE] stage and directly goes to + // [ConversationStage.HUMAN_ASSIST_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.HUMAN_ASSIST_STAGE], + // it skips + // [ConversationStage.VIRTUAL_AGENT_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.VIRTUAL_AGENT_STAGE] + // stage and directly goes to // [ConversationStage.HUMAN_ASSIST_STAGE][google.cloud.dialogflow.v2beta1.Conversation.ConversationStage.HUMAN_ASSIST_STAGE]. ConversationStage conversation_stage = 7; // Output only. The time the conversation was started. - google.protobuf.Timestamp start_time = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; + google.protobuf.Timestamp start_time = 5 + [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. The time the conversation was finished. - google.protobuf.Timestamp end_time = 6 [(google.api.field_behavior) = OUTPUT_ONLY]; + google.protobuf.Timestamp end_time = 6 + [(google.api.field_behavior) = OUTPUT_ONLY]; } // Represents a phone number for telephony integration. It allows for connecting @@ -268,73 +245,8 @@ message ConversationPhoneNumber { string phone_number = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; } -// Represents a call matcher that describes criteria for matching incoming SIP -// calls to a conversation. When Dialogflow get a SIP call from a third-party -// carrier, Dialogflow matches the call to an existing conversation by either: -// -// * Extracting the conversation id from the -// [Call-Info header](https://tools.ietf.org/html/rfc3261#section-20.9), e.g. -// `Call-Info: -// -// ;purpose=Goog-ContactCenter-Conversation`. -// * Or, if that doesn't work, matching incoming [SIP -// headers](https://tools.ietf.org/html/rfc3261#section-7.3) -// against any [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] for the conversation. -// -// If an incoming SIP call without valid `Call-Info` header matches to zero or -// multiple conversations with `CallMatcher`, we reject it. -// -// A call matcher contains equality conditions for SIP headers that all have -// to be fulfilled in order for a SIP call to match. -// -// The matched SIP headers consist of well-known headers (`To`, `From`, -// `Call-ID`) and custom headers. A [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] is only valid if it -// specifies: -// -// * At least 1 custom header, -// * or at least 2 well-known headers. -message CallMatcher { - option (google.api.resource) = { - type: "dialogflow.googleapis.com/CallMatcher" - pattern: "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}" - pattern: "projects/{project}/locations/{location}/conversations/{conversation}/callMatchers/{call_matcher}" - }; - - // Custom SIP headers. See the [description of headers in - // the RFC](https://tools.ietf.org/html/rfc3261#section-7.3). - message CustomHeaders { - // Cisco's proprietary `Cisco-Guid` header. - string cisco_guid = 1; - } - - // Output only. The unique identifier of this call matcher. - // Format: `projects//locations//conversations//callMatchers/`. - string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; - - // Value of the [`To` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.2) to match. If - // empty or unspecified, we don't match to the - // [`To` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.2). - string to_header = 2; - - // Value of the [`From` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.3) to match. If - // empty or unspecified, we don't match to the - // [`From` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.3). - string from_header = 3; - - // Value of the [`Call-ID` - // header](https://tools.ietf.org/html/rfc3261#section-8.1.1.4) to match. If - // empty or unspecified, we don't match to the - // [`Call-ID` header](https://tools.ietf.org/html/rfc3261#section-8.1.1.4). - string call_id_header = 4; - - // Custom SIP headers that must match. - CustomHeaders custom_headers = 5; -} - -// The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2beta1.Conversations.CreateConversation]. +// The request message for +// [Conversations.CreateConversation][google.cloud.dialogflow.v2beta1.Conversations.CreateConversation]. message CreateConversationRequest { // Required. Resource identifier of the project creating the conversation. // Format: `projects//locations/`. @@ -348,8 +260,8 @@ message CreateConversationRequest { // Required. The conversation to create. Conversation conversation = 2 [(google.api.field_behavior) = REQUIRED]; - // Optional. Identifier of the conversation. Generally it's auto generated by Google. - // Only set it if you cannot wait for the response to return a + // Optional. Identifier of the conversation. Generally it's auto generated by + // Google. Only set it if you cannot wait for the response to return a // auto-generated one to you. // // The conversation ID must be compliant with the regression fomula @@ -361,7 +273,8 @@ message CreateConversationRequest { string conversation_id = 3 [(google.api.field_behavior) = OPTIONAL]; } -// The request message for [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. +// The request message for +// [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. message ListConversationsRequest { // Required. The project from which to list all conversation. // Format: `projects//locations/`. @@ -399,7 +312,8 @@ message ListConversationsRequest { string filter = 4; } -// The response message for [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. +// The response message for +// [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. message ListConversationsResponse { // The list of conversations. There will be a maximum number of items // returned based on the page_size field in the request. @@ -410,7 +324,8 @@ message ListConversationsResponse { string next_page_token = 2; } -// The request message for [Conversations.GetConversation][google.cloud.dialogflow.v2beta1.Conversations.GetConversation]. +// The request message for +// [Conversations.GetConversation][google.cloud.dialogflow.v2beta1.Conversations.GetConversation]. message GetConversationRequest { // Required. The name of the conversation. Format: // `projects//locations//conversations//locations//locations//conversations/`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "dialogflow.googleapis.com/CallMatcher" - } - ]; - - // Required. The call matcher to create. - CallMatcher call_matcher = 2; -} - -// The request message for [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. -message ListCallMatchersRequest { - // Required. The conversation to list all call matchers from. - // Format: `projects//locations//conversations/`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "dialogflow.googleapis.com/CallMatcher" - } - ]; - - // Optional. The maximum number of items to return in a single page. By - // default 100 and at most 1000. - int32 page_size = 2; - - // Optional. The next_page_token value returned from a previous list request. - string page_token = 3; -} - -// The response message for [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. -message ListCallMatchersResponse { - // The list of call matchers. There is a maximum number of items - // returned based on the page_size field in the request. - repeated CallMatcher call_matchers = 1; - - // Token to retrieve the next page of results or empty if there are no - // more results in the list. - string next_page_token = 2; -} - -// The request message for [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.DeleteCallMatcher]. -message DeleteCallMatcherRequest { - // Required. The unique identifier of the [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] to delete. - // Format: `projects//locations//conversations//callMatchers/`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/CallMatcher" - } - ]; -} - // The request message to create one Message. Currently it is only used in // BatchCreateMessagesRequest. message CreateMessageRequest { @@ -510,7 +366,8 @@ message CreateMessageRequest { ]; // Required. The message to create. - // [Message.participant][google.cloud.dialogflow.v2beta1.Message.participant] is required. + // [Message.participant][google.cloud.dialogflow.v2beta1.Message.participant] + // is required. Message message = 2 [(google.api.field_behavior) = REQUIRED]; } @@ -528,8 +385,10 @@ message BatchCreateMessagesRequest { // Required. A maximum of 1000 Messages can be created in a batch. // [CreateMessageRequest.message.send_time][] is required. All created - // messages will have identical [Message.create_time][google.cloud.dialogflow.v2beta1.Message.create_time]. - repeated CreateMessageRequest requests = 2 [(google.api.field_behavior) = REQUIRED]; + // messages will have identical + // [Message.create_time][google.cloud.dialogflow.v2beta1.Message.create_time]. + repeated CreateMessageRequest requests = 2 + [(google.api.field_behavior) = REQUIRED]; } // The request message for [Conversations.BatchCreateMessagesResponse][]. @@ -538,7 +397,8 @@ message BatchCreateMessagesResponse { repeated Message messages = 1; } -// The request message for [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. +// The request message for +// [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. message ListMessagesRequest { // Required. The name of the conversation to list messages for. // Format: `projects//locations//conversationModels/`. string model = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/ConversationModel" - } + (google.api.field_behavior) = REQUIRED ]; } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/participant.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/participant.proto index afe0c9fafe60..731b98d9bd9d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/participant.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/participant.proto @@ -108,28 +108,9 @@ service Participants { } }; option (google.api.method_signature) = "participant,text_input"; - option (google.api.method_signature) = "participant,audio_input"; option (google.api.method_signature) = "participant,event_input"; } - // Adds a text (e.g., chat) or audio (e.g., phone recording) message from a - // participant into the conversation. - // Note: This method is only available through the gRPC API (not REST). - // - // The top-level message sent to the client by the server is - // `StreamingAnalyzeContentResponse`. Multiple response messages can be - // returned in order. The first one or more messages contain the - // `recognition_result` field. Each result represents a more complete - // transcript of what the user said. The next message contains the - // `reply_text` field, and potentially the `reply_audio` and/or the - // `automated_agent_reply` fields. - // - // Note: Always use agent versions for production traffic - // sent to virtual agents. See [Versions and - // environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - rpc StreamingAnalyzeContent(stream StreamingAnalyzeContentRequest) returns (stream StreamingAnalyzeContentResponse) { - } - // Gets suggested articles for a participant based on specific historical // messages. // @@ -187,7 +168,7 @@ service Participants { // This method should be used by human agent client software to fetch auto // generated suggestions in real-time, while the conversation with an end user // is in progress. The functionality is implemented in terms of the - // [list pagination](/apis/design/design_patterns#list_pagination) + // [list pagination](https://cloud.google.com/apis/design/design_patterns#list_pagination) // design pattern. The client app should use the `next_page_token` field // to fetch the next batch of suggestions. `suggestions` are sorted by // `create_time` in descending order. @@ -415,17 +396,6 @@ message InputAudio { bytes audio = 2; } -// Represents the natural language speech audio to be processed. -message AudioInput { - // Required. Instructs the speech recognizer how to process the speech audio. - InputAudioConfig config = 1; - - // Required. The natural language speech audio to be processed. - // A single request can contain up to 1 minute of speech audio data. - // The transcribed text cannot contain more than 256 bytes. - bytes audio = 2; -} - // Represents the natural language speech audio to be played to the end user. message OutputAudio { // Required. Instructs the speech synthesizer how to generate the speech @@ -504,18 +474,9 @@ message AnalyzeContentRequest { // Required. The input content. oneof input { - // The natural language text to be processed. - InputText text = 3 [deprecated = true]; - - // The natural language speech audio to be processed. - InputAudio audio = 4 [deprecated = true]; - // The natural language text to be processed. TextInput text_input = 6; - // The natural language speech audio to be processed. - AudioInput audio_input = 7; - // An input event to send to Dialogflow. EventInput event_input = 8; } @@ -601,172 +562,6 @@ message AnalyzeContentResponse { DtmfParameters dtmf_parameters = 9; } -// Defines the language used in the input text. -message InputTextConfig { - // Required. The language of this conversational query. See [Language - // Support](https://cloud.google.com/dialogflow/docs/reference/language) - // for a list of the currently supported language codes. - string language_code = 1; -} - -// The top-level message sent by the client to the -// [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.StreamingAnalyzeContent] method. -// -// Multiple request messages should be sent in order: -// -// 1. The first message must contain -// [participant][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.participant], -// [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] and optionally -// [query_params][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.query_params]. If you want -// to receive an audio response, it should also contain -// [reply_audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.reply_audio_config]. -// The message must not contain -// [input][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input]. -// -// 2. If [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] in the first message -// was set to [audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.audio_config], -// all subsequent messages must contain -// [input_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_audio] to continue -// with Speech recognition. -// If you decide to rather analyze text input after you already started -// Speech recognition, please send a message with -// [StreamingAnalyzeContentRequest.input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. -// -// However, note that: -// -// * Dialogflow will bill you for the audio so far. -// * Dialogflow discards all Speech recognition results in favor of the -// text input. -// -// 3. If [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] in the first message was set -// to [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.text_config], then the second message -// must contain only [input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. -// Moreover, you must not send more than two messages. -// -// After you sent all input, you must half-close or abort the request stream. -message StreamingAnalyzeContentRequest { - // Required. The name of the participant this text comes from. - // Format: `projects//locations//conversations//participants/`. - string participant = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "dialogflow.googleapis.com/Participant" - } - ]; - - // Required. The input config. - oneof config { - // Instructs the speech recognizer how to process the speech audio. - InputAudioConfig audio_config = 2; - - // The natural language text to be processed. - InputTextConfig text_config = 3; - } - - // Speech synthesis configuration. - // The speech synthesis settings for a virtual agent that may be configured - // for the associated conversation profile are not used when calling - // StreamingAnalyzeContent. If this configuration is not supplied, speech - // synthesis is disabled. - OutputAudioConfig reply_audio_config = 4; - - // Required. The input. - oneof input { - // The input audio content to be recognized. Must be sent if `audio_config` - // is set in the first message. The complete audio over all streaming - // messages must not exceed 1 minute. - bytes input_audio = 5; - - // The UTF-8 encoded natural language text to be processed. Must be sent if - // `text_config` is set in the first message. Text length must not exceed - // 256 bytes. The `input_text` field can be only sent once. - string input_text = 6; - - // The DTMF digits used to invoke intent and fill in parameter value. - // - // This input is ignored if the previous response indicated that DTMF input - // is not accepted. - TelephonyDtmfEvents input_dtmf = 9; - } - - // Parameters for a Dialogflow virtual-agent query. - QueryParameters query_params = 7; - - // Enable full bidirectional streaming. You can keep streaming the audio until - // timeout, and there's no need to half close the stream to get the response. - // - // Restrictions: - // - // - Timeout: 3 mins. - // - Audio Encoding: only supports [AudioEncoding.AUDIO_ENCODING_LINEAR_16][google.cloud.dialogflow.v2beta1.AudioEncoding.AUDIO_ENCODING_LINEAR_16] - // and [AudioEncoding.AUDIO_ENCODING_MULAW][google.cloud.dialogflow.v2beta1.AudioEncoding.AUDIO_ENCODING_MULAW] - // - Lifecycle: conversation should be in `Assist Stage`, go to - // [Conversation.CreateConversation][] for more information. - // - // InvalidArgument Error will be returned if the one of restriction checks - // failed. - // - // You can find more details in - // https://cloud.google.com/dialogflow/priv/docs/agent-assist/analyze-content-streaming - bool enable_extended_streaming = 11; -} - -// The top-level message returned from the `StreamingAnalyzeContent` method. -// -// Multiple response messages can be returned in order: -// -// 1. If the input was set to streaming audio, the first one or more messages -// contain `recognition_result`. Each `recognition_result` represents a more -// complete transcript of what the user said. The last `recognition_result` -// has `is_final` set to `true`. -// -// 2. The next message contains `reply_text` and optionally `reply_audio` -// returned by an agent. This message may also contain -// `automated_agent_reply`. -message StreamingAnalyzeContentResponse { - // The result of speech recognition. - StreamingRecognitionResult recognition_result = 1; - - // Optional. The output text content. - // This field is set if an automated agent responded with a text for the user. - string reply_text = 2; - - // Optional. The audio data bytes encoded as specified in the request. - // This field is set if: - // - // - The `reply_audio_config` field is specified in the request. - // - The automated agent, which this output comes from, responded with audio. - // In such case, the `reply_audio.config` field contains settings used to - // synthesize the speech. - // - // In some scenarios, multiple output audio fields may be present in the - // response structure. In these cases, only the top-most-level audio output - // has content. - OutputAudio reply_audio = 3; - - // Optional. Only set if a Dialogflow automated agent has responded. - // Note that: [AutomatedAgentReply.detect_intent_response.output_audio][] - // and [AutomatedAgentReply.detect_intent_response.output_audio_config][] - // are always empty, use [reply_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentResponse.reply_audio] instead. - AutomatedAgentReply automated_agent_reply = 4; - - // Output only. Message analyzed by CCAI. - Message message = 6; - - // The suggestions for most recent human agent. The order is the same as - // [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] of - // [HumanAgentAssistantConfig.human_agent_suggestion_config][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.human_agent_suggestion_config]. - repeated SuggestionResult human_agent_suggestion_results = 7; - - // The suggestions for end user. The order is the same as - // [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] of - // [HumanAgentAssistantConfig.end_user_suggestion_config][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.end_user_suggestion_config]. - repeated SuggestionResult end_user_suggestion_results = 8; - - // Indicates the parameters of DTMF. - DtmfParameters dtmf_parameters = 10; -} // Represents a part of a message possibly annotated with an entity. The part // can be an entity or purely a part of the message between two entities or diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/session.proto b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/session.proto index ab5e045230ba..bd53acafe38a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/session.proto +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/proto/session.proto @@ -276,6 +276,9 @@ message QueryInput { // The event to be processed. EventInput event = 3; + + // The DTMF digits used to invoke intent and fill in parameter value. + TelephonyDtmfEvents dtmf = 4; } } diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py index f8f8d44e3d68..7e10d20193b9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py @@ -77,10 +77,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -88,6 +88,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -97,20 +100,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py index 99193b309adf..675d3ac9584b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py @@ -112,7 +112,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -120,70 +123,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -191,18 +174,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -216,7 +189,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py index 2ddc8ca8549d..ad50f2638936 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -145,10 +145,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -157,7 +157,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -165,70 +168,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -236,18 +219,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py index dfeb917464bb..5e3908a6097e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py @@ -227,11 +227,12 @@ async def get_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. @@ -292,7 +293,7 @@ async def list_answer_records( Returns: google.cloud.dialogflow_v2beta1.services.answer_records.pagers.ListAnswerRecordsAsyncPager: Response message for - [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. + [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. Iterating over this object will yield results and resolve additional pages automatically. @@ -407,11 +408,12 @@ async def update_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py index 08e56aa521f8..a0cceb54ba68 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py @@ -396,11 +396,12 @@ def get_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. @@ -462,7 +463,7 @@ def list_answer_records( Returns: google.cloud.dialogflow_v2beta1.services.answer_records.pagers.ListAnswerRecordsPager: Response message for - [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. + [AnswerRecords.ListAnswerRecords][google.cloud.dialogflow.v2beta1.AnswerRecords.ListAnswerRecords]. Iterating over this object will yield results and resolve additional pages automatically. @@ -578,11 +579,12 @@ def update_answer_record( the answers, [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] are returned to the customers. + 2. The customer uses the - [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] - to call the [UpdateAnswerRecord][] method to send - feedback about a specific answer that they believe - is wrong. + [AnswerRecord.name][google.cloud.dialogflow.v2beta1.AnswerRecord.name] + to call the [UpdateAnswerRecord][] method to send + feedback about a specific answer that they believe is + wrong. """ # Create or coerce a protobuf request object. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py index 408c4495dcd9..1fb664a9660a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py index 7a93b52ffe89..19901a8f3f6b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py @@ -108,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -116,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -187,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -211,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py index 62c4531f8975..a0e18f1806b0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -141,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -153,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -161,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -232,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py index 664f3e3fc452..1d3b4783b9bf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py index 020b3d9ec6f3..ae75375c942c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py @@ -109,7 +109,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -117,70 +119,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -188,17 +170,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -212,7 +185,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py index f06a162f5331..3e2d8fdfbf1f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -142,10 +142,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -154,7 +154,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,70 +164,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -233,17 +215,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py index 4bc3e09fdabe..a7f3574354c2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py index 3d5442260260..80cd9e78f147 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py @@ -111,7 +111,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,17 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py index 8f2997c38ed6..72244a4610fc 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,17 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py index ad27edf785a8..cf4fb1475c1a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py @@ -49,8 +49,6 @@ class ConversationsAsyncClient: DEFAULT_ENDPOINT = ConversationsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationsClient.DEFAULT_MTLS_ENDPOINT - call_matcher_path = staticmethod(ConversationsClient.call_matcher_path) - parse_call_matcher_path = staticmethod(ConversationsClient.parse_call_matcher_path) conversation_path = staticmethod(ConversationsClient.conversation_path) parse_conversation_path = staticmethod(ConversationsClient.parse_conversation_path) conversation_profile_path = staticmethod( @@ -325,7 +323,7 @@ async def list_conversations( Returns: google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListConversationsAsyncPager: The response message for - [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. + [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. Iterating over this object will yield results and resolve additional pages automatically. @@ -534,272 +532,6 @@ async def complete_conversation( # Done; return the response. return response - async def create_call_matcher( - self, - request: conversation.CreateCallMatcherRequest = None, - *, - parent: str = None, - call_matcher: conversation.CallMatcher = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> conversation.CallMatcher: - r"""Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.CreateCallMatcherRequest`): - The request object. The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.CreateCallMatcher]. - parent (:class:`str`): - Required. Resource identifier of the conversation adding - the call matcher. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - call_matcher (:class:`google.cloud.dialogflow_v2beta1.types.CallMatcher`): - Required. The call matcher to create. - This corresponds to the ``call_matcher`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2beta1.types.CallMatcher: - Represents a call matcher that describes criteria for matching incoming SIP - calls to a conversation. When Dialogflow get a SIP - call from a third-party carrier, Dialogflow matches - the call to an existing conversation by either: - - - Extracting the conversation id from the [Call-Info - header](\ https://tools.ietf.org/html/rfc3261#section-20.9), - e.g. Call-Info: - - ;purpose=Goog-ContactCenter-Conversation. - - \* Or, if that doesn't work, matching incoming [SIP - headers](\ https://tools.ietf.org/html/rfc3261#section-7.3) - against any - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - for the conversation. - - If an incoming SIP call without valid Call-Info - header matches to zero or multiple conversations with - CallMatcher, we reject it. - - A call matcher contains equality conditions for SIP - headers that all have to be fulfilled in order for a - SIP call to match. - - The matched SIP headers consist of well-known headers - (To, From, Call-ID) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - is only valid if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, call_matcher]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.CreateCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - if call_matcher is not None: - request.call_matcher = call_matcher - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_call_matcher, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - async def list_call_matchers( - self, - request: conversation.ListCallMatchersRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListCallMatchersAsyncPager: - r"""Returns the list of all call matchers in the - specified conversation. - - Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.ListCallMatchersRequest`): - The request object. The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - parent (:class:`str`): - Required. The conversation to list all call matchers - from. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListCallMatchersAsyncPager: - The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.ListCallMatchersRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_call_matchers, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListCallMatchersAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_call_matcher( - self, - request: conversation.DeleteCallMatcherRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Requests deletion of a call matcher. - - Args: - request (:class:`google.cloud.dialogflow_v2beta1.types.DeleteCallMatcherRequest`): - The request object. The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.DeleteCallMatcher]. - name (:class:`str`): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - to delete. Format: - ``projects//locations//conversations//callMatchers/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - request = conversation.DeleteCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_call_matcher, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), - ) - - # Send the request. - await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, - ) - async def batch_create_messages( self, request: conversation.BatchCreateMessagesRequest = None, @@ -913,7 +645,7 @@ async def list_messages( Returns: google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListMessagesAsyncPager: The response message for - [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. + [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. Iterating over this object will yield results and resolve additional pages automatically. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py index 1855fe92d512..5dee0325fe6d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py @@ -158,22 +158,6 @@ def transport(self) -> ConversationsTransport: """ return self._transport - @staticmethod - def call_matcher_path(project: str, conversation: str, call_matcher: str,) -> str: - """Return a fully-qualified call_matcher string.""" - return "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}".format( - project=project, conversation=conversation, call_matcher=call_matcher, - ) - - @staticmethod - def parse_call_matcher_path(path: str) -> Dict[str, str]: - """Parse a call_matcher path into its component segments.""" - m = re.match( - r"^projects/(?P.+?)/conversations/(?P.+?)/callMatchers/(?P.+?)$", - path, - ) - return m.groupdict() if m else {} - @staticmethod def conversation_path(project: str, conversation: str,) -> str: """Return a fully-qualified conversation string.""" @@ -535,7 +519,7 @@ def list_conversations( Returns: google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListConversationsPager: The response message for - [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. + [Conversations.ListConversations][google.cloud.dialogflow.v2beta1.Conversations.ListConversations]. Iterating over this object will yield results and resolve additional pages automatically. @@ -747,275 +731,6 @@ def complete_conversation( # Done; return the response. return response - def create_call_matcher( - self, - request: conversation.CreateCallMatcherRequest = None, - *, - parent: str = None, - call_matcher: conversation.CallMatcher = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> conversation.CallMatcher: - r"""Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Args: - request (google.cloud.dialogflow_v2beta1.types.CreateCallMatcherRequest): - The request object. The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.CreateCallMatcher]. - parent (str): - Required. Resource identifier of the conversation adding - the call matcher. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - call_matcher (google.cloud.dialogflow_v2beta1.types.CallMatcher): - Required. The call matcher to create. - This corresponds to the ``call_matcher`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2beta1.types.CallMatcher: - Represents a call matcher that describes criteria for matching incoming SIP - calls to a conversation. When Dialogflow get a SIP - call from a third-party carrier, Dialogflow matches - the call to an existing conversation by either: - - - Extracting the conversation id from the [Call-Info - header](\ https://tools.ietf.org/html/rfc3261#section-20.9), - e.g. Call-Info: - - ;purpose=Goog-ContactCenter-Conversation. - - \* Or, if that doesn't work, matching incoming [SIP - headers](\ https://tools.ietf.org/html/rfc3261#section-7.3) - against any - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - for the conversation. - - If an incoming SIP call without valid Call-Info - header matches to zero or multiple conversations with - CallMatcher, we reject it. - - A call matcher contains equality conditions for SIP - headers that all have to be fulfilled in order for a - SIP call to match. - - The matched SIP headers consist of well-known headers - (To, From, Call-ID) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - is only valid if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, call_matcher]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.CreateCallMatcherRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.CreateCallMatcherRequest): - request = conversation.CreateCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - if call_matcher is not None: - request.call_matcher = call_matcher - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_call_matcher] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - def list_call_matchers( - self, - request: conversation.ListCallMatchersRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListCallMatchersPager: - r"""Returns the list of all call matchers in the - specified conversation. - - Args: - request (google.cloud.dialogflow_v2beta1.types.ListCallMatchersRequest): - The request object. The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - parent (str): - Required. The conversation to list all call matchers - from. Format: - ``projects//locations//conversations/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListCallMatchersPager: - The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.ListCallMatchersRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.ListCallMatchersRequest): - request = conversation.ListCallMatchersRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_call_matchers] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), - ) - - # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListCallMatchersPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_call_matcher( - self, - request: conversation.DeleteCallMatcherRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Requests deletion of a call matcher. - - Args: - request (google.cloud.dialogflow_v2beta1.types.DeleteCallMatcherRequest): - The request object. The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.DeleteCallMatcher]. - name (str): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - to delete. Format: - ``projects//locations//conversations//callMatchers/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError( - "If the `request` argument is set, then none of " - "the individual field arguments should be set." - ) - - # Minor optimization to avoid making a copy if the user passes - # in a conversation.DeleteCallMatcherRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, conversation.DeleteCallMatcherRequest): - request = conversation.DeleteCallMatcherRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_call_matcher] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), - ) - - # Send the request. - rpc( - request, retry=retry, timeout=timeout, metadata=metadata, - ) - def batch_create_messages( self, request: conversation.BatchCreateMessagesRequest = None, @@ -1130,7 +845,7 @@ def list_messages( Returns: google.cloud.dialogflow_v2beta1.services.conversations.pagers.ListMessagesPager: The response message for - [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. + [Conversations.ListMessages][google.cloud.dialogflow.v2beta1.Conversations.ListMessages]. Iterating over this object will yield results and resolve additional pages automatically. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/pagers.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/pagers.py index eb97134b9adc..f9a2ca2034ca 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/pagers.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/pagers.py @@ -158,134 +158,6 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) -class ListCallMatchersPager: - """A pager for iterating through ``list_call_matchers`` requests. - - This class thinly wraps an initial - :class:`google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse` object, and - provides an ``__iter__`` method to iterate through its - ``call_matchers`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListCallMatchers`` requests and continue to iterate - through the ``call_matchers`` field on the - corresponding responses. - - All the usual :class:`google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., conversation.ListCallMatchersResponse], - request: conversation.ListCallMatchersRequest, - response: conversation.ListCallMatchersResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.dialogflow_v2beta1.types.ListCallMatchersRequest): - The initial request object. - response (google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = conversation.ListCallMatchersRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterable[conversation.ListCallMatchersResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterable[conversation.CallMatcher]: - for page in self.pages: - yield from page.call_matchers - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) - - -class ListCallMatchersAsyncPager: - """A pager for iterating through ``list_call_matchers`` requests. - - This class thinly wraps an initial - :class:`google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``call_matchers`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListCallMatchers`` requests and continue to iterate - through the ``call_matchers`` field on the - corresponding responses. - - All the usual :class:`google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., Awaitable[conversation.ListCallMatchersResponse]], - request: conversation.ListCallMatchersRequest, - response: conversation.ListCallMatchersResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.dialogflow_v2beta1.types.ListCallMatchersRequest): - The initial request object. - response (google.cloud.dialogflow_v2beta1.types.ListCallMatchersResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = conversation.ListCallMatchersRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterable[conversation.ListCallMatchersResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - - def __aiter__(self) -> AsyncIterable[conversation.CallMatcher]: - async def async_generator(): - async for page in self.pages: - for response in page.call_matchers: - yield response - - return async_generator() - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) - - class ListMessagesPager: """A pager for iterating through ``list_messages`` requests. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py index 16abd668a6dc..ecc38991b8b5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py @@ -27,7 +27,6 @@ from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore try: @@ -74,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -125,15 +124,6 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), - self.create_call_matcher: gapic_v1.method.wrap_method( - self.create_call_matcher, default_timeout=None, client_info=client_info, - ), - self.list_call_matchers: gapic_v1.method.wrap_method( - self.list_call_matchers, default_timeout=None, client_info=client_info, - ), - self.delete_call_matcher: gapic_v1.method.wrap_method( - self.delete_call_matcher, default_timeout=None, client_info=client_info, - ), self.batch_create_messages: gapic_v1.method.wrap_method( self.batch_create_messages, default_timeout=None, @@ -190,38 +180,6 @@ def complete_conversation( ]: raise NotImplementedError() - @property - def create_call_matcher( - self, - ) -> typing.Callable[ - [conversation.CreateCallMatcherRequest], - typing.Union[ - conversation.CallMatcher, typing.Awaitable[conversation.CallMatcher] - ], - ]: - raise NotImplementedError() - - @property - def list_call_matchers( - self, - ) -> typing.Callable[ - [conversation.ListCallMatchersRequest], - typing.Union[ - conversation.ListCallMatchersResponse, - typing.Awaitable[conversation.ListCallMatchersResponse], - ], - ]: - raise NotImplementedError() - - @property - def delete_call_matcher( - self, - ) -> typing.Callable[ - [conversation.DeleteCallMatcherRequest], - typing.Union[empty.Empty, typing.Awaitable[empty.Empty]], - ]: - raise NotImplementedError() - @property def batch_create_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py index 7e84c5300f51..c0f5c981a51e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py @@ -28,7 +28,6 @@ from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore from .base import ConversationsTransport, DEFAULT_CLIENT_INFO @@ -109,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -117,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -188,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -212,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -384,89 +356,6 @@ def complete_conversation( ) return self._stubs["complete_conversation"] - @property - def create_call_matcher( - self, - ) -> Callable[[conversation.CreateCallMatcherRequest], conversation.CallMatcher]: - r"""Return a callable for the create call matcher method over gRPC. - - Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Returns: - Callable[[~.CreateCallMatcherRequest], - ~.CallMatcher]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "create_call_matcher" not in self._stubs: - self._stubs["create_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/CreateCallMatcher", - request_serializer=conversation.CreateCallMatcherRequest.serialize, - response_deserializer=conversation.CallMatcher.deserialize, - ) - return self._stubs["create_call_matcher"] - - @property - def list_call_matchers( - self, - ) -> Callable[ - [conversation.ListCallMatchersRequest], conversation.ListCallMatchersResponse - ]: - r"""Return a callable for the list call matchers method over gRPC. - - Returns the list of all call matchers in the - specified conversation. - - Returns: - Callable[[~.ListCallMatchersRequest], - ~.ListCallMatchersResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_call_matchers" not in self._stubs: - self._stubs["list_call_matchers"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/ListCallMatchers", - request_serializer=conversation.ListCallMatchersRequest.serialize, - response_deserializer=conversation.ListCallMatchersResponse.deserialize, - ) - return self._stubs["list_call_matchers"] - - @property - def delete_call_matcher( - self, - ) -> Callable[[conversation.DeleteCallMatcherRequest], empty.Empty]: - r"""Return a callable for the delete call matcher method over gRPC. - - Requests deletion of a call matcher. - - Returns: - Callable[[~.DeleteCallMatcherRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_call_matcher" not in self._stubs: - self._stubs["delete_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/DeleteCallMatcher", - request_serializer=conversation.DeleteCallMatcherRequest.serialize, - response_deserializer=empty.Empty.FromString, - ) - return self._stubs["delete_call_matcher"] - @property def batch_create_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py index 7bdb25dca52f..a00f0288d4f6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py @@ -29,7 +29,6 @@ from google.cloud.dialogflow_v2beta1.types import conversation from google.cloud.dialogflow_v2beta1.types import conversation as gcd_conversation -from google.protobuf import empty_pb2 as empty # type: ignore from .base import ConversationsTransport, DEFAULT_CLIENT_INFO from .grpc import ConversationsGrpcTransport @@ -64,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -142,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -154,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -233,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: @@ -392,92 +364,6 @@ def complete_conversation( ) return self._stubs["complete_conversation"] - @property - def create_call_matcher( - self, - ) -> Callable[ - [conversation.CreateCallMatcherRequest], Awaitable[conversation.CallMatcher] - ]: - r"""Return a callable for the create call matcher method over gRPC. - - Creates a call matcher that links incoming SIP calls - to the specified conversation if they fulfill specified - criteria. - - Returns: - Callable[[~.CreateCallMatcherRequest], - Awaitable[~.CallMatcher]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "create_call_matcher" not in self._stubs: - self._stubs["create_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/CreateCallMatcher", - request_serializer=conversation.CreateCallMatcherRequest.serialize, - response_deserializer=conversation.CallMatcher.deserialize, - ) - return self._stubs["create_call_matcher"] - - @property - def list_call_matchers( - self, - ) -> Callable[ - [conversation.ListCallMatchersRequest], - Awaitable[conversation.ListCallMatchersResponse], - ]: - r"""Return a callable for the list call matchers method over gRPC. - - Returns the list of all call matchers in the - specified conversation. - - Returns: - Callable[[~.ListCallMatchersRequest], - Awaitable[~.ListCallMatchersResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_call_matchers" not in self._stubs: - self._stubs["list_call_matchers"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/ListCallMatchers", - request_serializer=conversation.ListCallMatchersRequest.serialize, - response_deserializer=conversation.ListCallMatchersResponse.deserialize, - ) - return self._stubs["list_call_matchers"] - - @property - def delete_call_matcher( - self, - ) -> Callable[[conversation.DeleteCallMatcherRequest], Awaitable[empty.Empty]]: - r"""Return a callable for the delete call matcher method over gRPC. - - Requests deletion of a call matcher. - - Returns: - Callable[[~.DeleteCallMatcherRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_call_matcher" not in self._stubs: - self._stubs["delete_call_matcher"] = self.grpc_channel.unary_unary( - "/google.cloud.dialogflow.v2beta1.Conversations/DeleteCallMatcher", - request_serializer=conversation.DeleteCallMatcherRequest.serialize, - response_deserializer=empty.Empty.FromString, - ) - return self._stubs["delete_call_matcher"] - @property def batch_create_messages( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py index 8f59da1117a0..352d60dcec33 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py @@ -75,10 +75,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -86,6 +86,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -95,20 +98,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py index bee3ec46e170..11c7488ee5cf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py @@ -110,7 +110,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -118,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -189,18 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py index 6e04daec1885..112d72a50884 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -143,10 +143,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -155,7 +155,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -234,18 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py index c04f42d99b64..3b3c283cd48f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py index eb180c61fd21..3cd835d1401b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py @@ -111,7 +111,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +122,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,18 +173,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -215,7 +188,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py index 53985db1cbff..c4f4439fd4f5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +167,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py index 1a452c2745e6..d48fa645eb91 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py @@ -72,10 +72,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -83,6 +83,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -92,20 +95,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py index de5505597ef2..6fb0cd7e291d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py @@ -107,7 +107,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -115,70 +117,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -186,17 +168,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -210,7 +183,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py index bce9fca5baa5..52b0b3ba7b1c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py @@ -62,7 +62,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -140,10 +140,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -152,7 +152,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -160,70 +162,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -231,17 +213,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py index 5c57ffe4aee3..b49fd88d15cd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py index c9d7893e6a39..792e437cceae 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py @@ -111,7 +111,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +122,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,18 +173,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - self._operations_client = None - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -215,7 +188,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py index e24b339d6884..f8cfe4546897 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,10 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +167,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,18 +218,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} - self._operations_client = None + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py index e013e1e1e86c..900d39a5fce8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py @@ -74,10 +74,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -85,6 +85,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -94,20 +97,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py index 88d8173f4c03..563d0d737724 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py @@ -109,7 +109,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -117,70 +119,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -188,17 +170,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -212,7 +185,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py index 19f40dc07c4b..589b6cf5062c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py @@ -64,7 +64,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -142,10 +142,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -154,7 +154,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,70 +164,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -233,17 +215,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py index a9ede9faa755..ac4e64e355ef 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py @@ -18,16 +18,7 @@ from collections import OrderedDict import functools import re -from typing import ( - Dict, - AsyncIterable, - Awaitable, - AsyncIterator, - Sequence, - Tuple, - Type, - Union, -) +from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore @@ -519,7 +510,6 @@ async def analyze_content( *, participant: str = None, text_input: session.TextInput = None, - audio_input: gcd_participant.AudioInput = None, event_input: session.EventInput = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -551,13 +541,6 @@ async def analyze_content( This corresponds to the ``text_input`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - audio_input (:class:`google.cloud.dialogflow_v2beta1.types.AudioInput`): - The natural language speech audio to - be processed. - - This corresponds to the ``audio_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. event_input (:class:`google.cloud.dialogflow_v2beta1.types.EventInput`): An input event to send to Dialogflow. This corresponds to the ``event_input`` field @@ -579,7 +562,7 @@ async def analyze_content( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([participant, text_input, audio_input, event_input]) + has_flattened_params = any([participant, text_input, event_input]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -595,8 +578,6 @@ async def analyze_content( request.participant = participant if text_input is not None: request.text_input = text_input - if audio_input is not None: - request.audio_input = audio_input if event_input is not None: request.event_input = event_input @@ -609,6 +590,7 @@ async def analyze_content( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=DEFAULT_CLIENT_INFO, @@ -628,112 +610,6 @@ async def analyze_content( # Done; return the response. return response - def streaming_analyze_content( - self, - requests: AsyncIterator[participant.StreamingAnalyzeContentRequest] = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Awaitable[AsyncIterable[participant.StreamingAnalyzeContentResponse]]: - r"""Adds a text (e.g., chat) or audio (e.g., phone recording) - message from a participant into the conversation. Note: This - method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field, and potentially the - ``reply_audio`` and/or the ``automated_agent_reply`` fields. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Args: - requests (AsyncIterator[`google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentRequest`]): - The request object AsyncIterator. The top-level message sent by the - client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.StreamingAnalyzeContent] - method. - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should - also contain - [reply_audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input]. - 2. If - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. - If you decide to rather analyze text input after you - already started Speech recognition, please send a - message with - [StreamingAnalyzeContentRequest.input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - However, note that: - - * Dialogflow will bill you for the audio so far. - * Dialogflow discards all Speech recognition results - in favor of the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - After you sent all input, you must half-close or abort - the request stream. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - AsyncIterable[google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentResponse]: - The top-level message returned from the - StreamingAnalyzeContent method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. - 2. The next message contains reply_text and - optionally reply_audio returned by an agent. This - message may also contain automated_agent_reply. - - """ - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.streaming_analyze_content, - default_timeout=220.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Send the request. - response = rpc(requests, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - async def suggest_articles( self, request: participant.SuggestArticlesRequest = None, @@ -985,7 +861,7 @@ async def list_suggestions( fetch auto generated suggestions in real-time, while the conversation with an end user is in progress. The functionality is implemented in terms of the `list - pagination `__ + pagination `__ design pattern. The client app should use the ``next_page_token`` field to fetch the next batch of suggestions. ``suggestions`` are sorted by ``create_time`` in diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py index 583b5f7c39f5..ae9ace66c889 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py @@ -19,17 +19,7 @@ from distutils import util import os import re -from typing import ( - Callable, - Dict, - Optional, - Iterable, - Iterator, - Sequence, - Tuple, - Type, - Union, -) +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore @@ -765,7 +755,6 @@ def analyze_content( *, participant: str = None, text_input: session.TextInput = None, - audio_input: gcd_participant.AudioInput = None, event_input: session.EventInput = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, @@ -797,13 +786,6 @@ def analyze_content( This corresponds to the ``text_input`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - audio_input (google.cloud.dialogflow_v2beta1.types.AudioInput): - The natural language speech audio to - be processed. - - This corresponds to the ``audio_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. event_input (google.cloud.dialogflow_v2beta1.types.EventInput): An input event to send to Dialogflow. This corresponds to the ``event_input`` field @@ -825,7 +807,7 @@ def analyze_content( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([participant, text_input, audio_input, event_input]) + has_flattened_params = any([participant, text_input, event_input]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -846,8 +828,6 @@ def analyze_content( request.participant = participant if text_input is not None: request.text_input = text_input - if audio_input is not None: - request.audio_input = audio_input if event_input is not None: request.event_input = event_input @@ -869,110 +849,6 @@ def analyze_content( # Done; return the response. return response - def streaming_analyze_content( - self, - requests: Iterator[participant.StreamingAnalyzeContentRequest] = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Iterable[participant.StreamingAnalyzeContentResponse]: - r"""Adds a text (e.g., chat) or audio (e.g., phone recording) - message from a participant into the conversation. Note: This - method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field, and potentially the - ``reply_audio`` and/or the ``automated_agent_reply`` fields. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Args: - requests (Iterator[google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentRequest]): - The request object iterator. The top-level message sent by the - client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.StreamingAnalyzeContent] - method. - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should - also contain - [reply_audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input]. - 2. If - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. - If you decide to rather analyze text input after you - already started Speech recognition, please send a - message with - [StreamingAnalyzeContentRequest.input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - However, note that: - - * Dialogflow will bill you for the audio so far. - * Dialogflow discards all Speech recognition results - in favor of the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - After you sent all input, you must half-close or abort - the request stream. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - Iterable[google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentResponse]: - The top-level message returned from the - StreamingAnalyzeContent method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first - one or more messages contain recognition_result. - Each recognition_result represents a more complete - transcript of what the user said. The last - recognition_result has is_final set to true. - 2. The next message contains reply_text and - optionally reply_audio returned by an agent. This - message may also contain automated_agent_reply. - - """ - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.streaming_analyze_content - ] - - # Send the request. - response = rpc(requests, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - def suggest_articles( self, request: participant.SuggestArticlesRequest = None, @@ -1227,7 +1103,7 @@ def list_suggestions( fetch auto generated suggestions in real-time, while the conversation with an end user is in progress. The functionality is implemented in terms of the `list - pagination `__ + pagination `__ design pattern. The client app should use the ``next_page_token`` field to fetch the next batch of suggestions. ``suggestions`` are sorted by ``create_time`` in diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py index eda5393001e4..6c63884a8cba 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -129,15 +129,11 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=client_info, ), - self.streaming_analyze_content: gapic_v1.method.wrap_method( - self.streaming_analyze_content, - default_timeout=220.0, - client_info=client_info, - ), self.suggest_articles: gapic_v1.method.wrap_method( self.suggest_articles, default_timeout=None, client_info=client_info, ), @@ -214,18 +210,6 @@ def analyze_content( ]: raise NotImplementedError() - @property - def streaming_analyze_content( - self, - ) -> typing.Callable[ - [participant.StreamingAnalyzeContentRequest], - typing.Union[ - participant.StreamingAnalyzeContentResponse, - typing.Awaitable[participant.StreamingAnalyzeContentResponse], - ], - ]: - raise NotImplementedError() - @property def suggest_articles( self, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py index 959346114cb3..04560ca1e72f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py @@ -108,7 +108,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -116,70 +118,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -187,17 +169,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -211,7 +184,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -394,49 +367,6 @@ def analyze_content( ) return self._stubs["analyze_content"] - @property - def streaming_analyze_content( - self, - ) -> Callable[ - [participant.StreamingAnalyzeContentRequest], - participant.StreamingAnalyzeContentResponse, - ]: - r"""Return a callable for the streaming analyze content method over gRPC. - - Adds a text (e.g., chat) or audio (e.g., phone recording) - message from a participant into the conversation. Note: This - method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field, and potentially the - ``reply_audio`` and/or the ``automated_agent_reply`` fields. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Returns: - Callable[[~.StreamingAnalyzeContentRequest], - ~.StreamingAnalyzeContentResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "streaming_analyze_content" not in self._stubs: - self._stubs["streaming_analyze_content"] = self.grpc_channel.stream_stream( - "/google.cloud.dialogflow.v2beta1.Participants/StreamingAnalyzeContent", - request_serializer=participant.StreamingAnalyzeContentRequest.serialize, - response_deserializer=participant.StreamingAnalyzeContentResponse.deserialize, - ) - return self._stubs["streaming_analyze_content"] - @property def suggest_articles( self, @@ -551,7 +481,7 @@ def list_suggestions( fetch auto generated suggestions in real-time, while the conversation with an end user is in progress. The functionality is implemented in terms of the `list - pagination `__ + pagination `__ design pattern. The client app should use the ``next_page_token`` field to fetch the next batch of suggestions. ``suggestions`` are sorted by ``create_time`` in diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py index 0385717d29ae..ad713f7d58b3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py @@ -63,7 +63,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -141,10 +141,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -153,7 +153,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -161,70 +163,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -232,17 +214,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: @@ -404,49 +377,6 @@ def analyze_content( ) return self._stubs["analyze_content"] - @property - def streaming_analyze_content( - self, - ) -> Callable[ - [participant.StreamingAnalyzeContentRequest], - Awaitable[participant.StreamingAnalyzeContentResponse], - ]: - r"""Return a callable for the streaming analyze content method over gRPC. - - Adds a text (e.g., chat) or audio (e.g., phone recording) - message from a participant into the conversation. Note: This - method is only available through the gRPC API (not REST). - - The top-level message sent to the client by the server is - ``StreamingAnalyzeContentResponse``. Multiple response messages - can be returned in order. The first one or more messages contain - the ``recognition_result`` field. Each result represents a more - complete transcript of what the user said. The next message - contains the ``reply_text`` field, and potentially the - ``reply_audio`` and/or the ``automated_agent_reply`` fields. - - Note: Always use agent versions for production traffic sent to - virtual agents. See [Versions and - environments(https://cloud.google.com/dialogflow/es/docs/agents-versions). - - Returns: - Callable[[~.StreamingAnalyzeContentRequest], - Awaitable[~.StreamingAnalyzeContentResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "streaming_analyze_content" not in self._stubs: - self._stubs["streaming_analyze_content"] = self.grpc_channel.stream_stream( - "/google.cloud.dialogflow.v2beta1.Participants/StreamingAnalyzeContent", - request_serializer=participant.StreamingAnalyzeContentRequest.serialize, - response_deserializer=participant.StreamingAnalyzeContentResponse.deserialize, - ) - return self._stubs["streaming_analyze_content"] - @property def suggest_articles( self, @@ -564,7 +494,7 @@ def list_suggestions( fetch auto generated suggestions in real-time, while the conversation with an end user is in progress. The functionality is implemented in terms of the `list - pagination `__ + pagination `__ design pattern. The client app should use the ``next_page_token`` field to fetch the next batch of suggestions. ``suggestions`` are sorted by ``create_time`` in diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py index 574b6c1e490e..e3e62fc1715e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py @@ -76,10 +76,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -87,6 +87,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -96,20 +99,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py index 6fc05f9a9786..6ef126d94b80 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py @@ -111,7 +111,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -119,70 +121,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -190,17 +172,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -214,7 +187,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py index 840eeb67de2c..10e5ecdfd455 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py @@ -66,7 +66,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -144,10 +144,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -156,7 +156,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -164,70 +166,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -235,17 +217,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py index ac247692e71e..c62121f7dd80 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py @@ -295,6 +295,7 @@ async def detect_intent( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=DEFAULT_CLIENT_INFO, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py index 847196c054b2..24431128f428 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py @@ -73,10 +73,10 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. @@ -84,6 +84,9 @@ def __init__( host += ":443" self._host = host + # Save the scopes. + self._scopes = scopes or self.AUTH_SCOPES + # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: @@ -93,20 +96,17 @@ def __init__( if credentials_file is not None: credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=scopes, quota_project_id=quota_project_id + credentials_file, scopes=self._scopes, quota_project_id=quota_project_id ) elif credentials is None: credentials, _ = auth.default( - scopes=scopes, quota_project_id=quota_project_id + scopes=self._scopes, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials - # Lifted into its own function so it can be stubbed out during tests. - self._prep_wrapped_messages(client_info) - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type(exceptions.ServiceUnavailable,), + deadline=220.0, ), default_timeout=220.0, client_info=client_info, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py index 43862fa89702..c1fc1907cd1a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py @@ -110,7 +110,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -118,70 +120,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -189,17 +171,8 @@ def __init__( ], ) - self._stubs = {} # type: Dict[str, Callable] - - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @classmethod def create_channel( @@ -213,7 +186,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py index 47502e9d51c6..ad283b9d5f72 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py @@ -65,7 +65,7 @@ def create_channel( ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: - address (Optional[str]): The host for the channel to use. + host (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -143,10 +143,10 @@ def __init__( ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -155,7 +155,9 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,70 +165,50 @@ def __init__( warnings.warn("client_cert_source is deprecated", DeprecationWarning) if channel: - # Sanity check: Ensure that channel and credentials are not both - # provided. + # Ignore credentials if a channel was passed. credentials = False - # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - elif api_mtls_endpoint: - host = ( - api_mtls_endpoint - if ":" in api_mtls_endpoint - else api_mtls_endpoint + ":443" - ) - - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - ssl_credentials = SslCredentials().ssl_credentials - # create a new channel. The provided one is ignored. - self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - ssl_credentials=ssl_credentials, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - self._ssl_channel_credentials = ssl_credentials else: - host = host if ":" in host else host + ":443" + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials - if credentials is None: - credentials, _ = auth.default( - scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id - ) + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + ) - # create a new channel. The provided one is ignored. + if not self._grpc_channel: self._grpc_channel = type(self).create_channel( - host, - credentials=credentials, + self._host, + credentials=self._credentials, credentials_file=credentials_file, + scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, - scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ ("grpc.max_send_message_length", -1), @@ -234,17 +216,8 @@ def __init__( ], ) - # Run the base constructor. - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes or self.AUTH_SCOPES, - quota_project_id=quota_project_id, - client_info=client_info, - ) - - self._stubs = {} + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) @property def grpc_channel(self) -> aio.Channel: diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/__init__.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/__init__.py index 924295b40333..e62387547b48 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/__init__.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/__init__.py @@ -68,17 +68,12 @@ from .conversation import ( BatchCreateMessagesRequest, BatchCreateMessagesResponse, - CallMatcher, CompleteConversationRequest, Conversation, ConversationPhoneNumber, - CreateCallMatcherRequest, CreateConversationRequest, CreateMessageRequest, - DeleteCallMatcherRequest, GetConversationRequest, - ListCallMatchersRequest, - ListCallMatchersResponse, ListConversationsRequest, ListConversationsResponse, ListMessagesRequest, @@ -167,7 +162,6 @@ AnalyzeContentResponse, AnnotatedMessagePart, ArticleAnswer, - AudioInput, AutomatedAgentReply, CompileSuggestionRequest, CompileSuggestionResponse, @@ -177,7 +171,6 @@ GetParticipantRequest, InputAudio, InputText, - InputTextConfig, ListParticipantsRequest, ListParticipantsResponse, ListSuggestionsRequest, @@ -188,8 +181,6 @@ Participant, ResponseMessage, SmartReplyAnswer, - StreamingAnalyzeContentRequest, - StreamingAnalyzeContentResponse, SuggestArticlesRequest, SuggestArticlesResponse, SuggestFaqAnswersRequest, @@ -281,17 +272,12 @@ "UpdateContextRequest", "BatchCreateMessagesRequest", "BatchCreateMessagesResponse", - "CallMatcher", "CompleteConversationRequest", "Conversation", "ConversationPhoneNumber", - "CreateCallMatcherRequest", "CreateConversationRequest", "CreateMessageRequest", - "DeleteCallMatcherRequest", "GetConversationRequest", - "ListCallMatchersRequest", - "ListCallMatchersResponse", "ListConversationsRequest", "ListConversationsResponse", "ListMessagesRequest", @@ -364,7 +350,6 @@ "AnalyzeContentResponse", "AnnotatedMessagePart", "ArticleAnswer", - "AudioInput", "AutomatedAgentReply", "CompileSuggestionRequest", "CompileSuggestionResponse", @@ -374,7 +359,6 @@ "GetParticipantRequest", "InputAudio", "InputText", - "InputTextConfig", "ListParticipantsRequest", "ListParticipantsResponse", "ListSuggestionsRequest", @@ -385,8 +369,6 @@ "Participant", "ResponseMessage", "SmartReplyAnswer", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "SuggestArticlesRequest", "SuggestArticlesResponse", "SuggestFaqAnswersRequest", diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/audio_config.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/audio_config.py index 5fffbd88197c..fda8a8e73116 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/audio_config.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/audio_config.py @@ -90,7 +90,9 @@ class OutputAudioEncoding(proto.Enum): OUTPUT_AUDIO_ENCODING_UNSPECIFIED = 0 OUTPUT_AUDIO_ENCODING_LINEAR_16 = 1 OUTPUT_AUDIO_ENCODING_MP3 = 2 + OUTPUT_AUDIO_ENCODING_MP3_64_KBPS = 4 OUTPUT_AUDIO_ENCODING_OGG_OPUS = 3 + OUTPUT_AUDIO_ENCODING_MULAW = 5 class TelephonyDtmf(proto.Enum): diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/conversation.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/conversation.py index 4fe64ebf2a49..11ffff26c9cb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/conversation.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/conversation.py @@ -27,16 +27,11 @@ manifest={ "Conversation", "ConversationPhoneNumber", - "CallMatcher", "CreateConversationRequest", "ListConversationsRequest", "ListConversationsResponse", "GetConversationRequest", "CompleteConversationRequest", - "CreateCallMatcherRequest", - "ListCallMatchersRequest", - "ListCallMatchersResponse", - "DeleteCallMatcherRequest", "CreateMessageRequest", "BatchCreateMessagesRequest", "BatchCreateMessagesResponse", @@ -140,86 +135,6 @@ class ConversationPhoneNumber(proto.Message): phone_number = proto.Field(proto.STRING, number=3) -class CallMatcher(proto.Message): - r"""Represents a call matcher that describes criteria for matching - incoming SIP calls to a conversation. When Dialogflow get a SIP call - from a third-party carrier, Dialogflow matches the call to an - existing conversation by either: - - - Extracting the conversation id from the `Call-Info - header `__, - e.g. - ``Call-Info: ;purpose=Goog-ContactCenter-Conversation``. - - Or, if that doesn't work, matching incoming `SIP - headers `__ - against any - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] for - the conversation. - - If an incoming SIP call without valid ``Call-Info`` header matches - to zero or multiple conversations with ``CallMatcher``, we reject - it. - - A call matcher contains equality conditions for SIP headers that all - have to be fulfilled in order for a SIP call to match. - - The matched SIP headers consist of well-known headers (``To``, - ``From``, ``Call-ID``) and custom headers. A - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] is only - valid if it specifies: - - - At least 1 custom header, - - or at least 2 well-known headers. - - Attributes: - name (str): - Output only. The unique identifier of this call matcher. - Format: - ``projects//locations//conversations//callMatchers/``. - to_header (str): - Value of the ```To`` - header `__ - to match. If empty or unspecified, we don't match to the - ```To`` - header `__. - from_header (str): - Value of the ```From`` - header `__ - to match. If empty or unspecified, we don't match to the - ```From`` - header `__. - call_id_header (str): - Value of the ```Call-ID`` - header `__ - to match. If empty or unspecified, we don't match to the - ```Call-ID`` - header `__. - custom_headers (google.cloud.dialogflow_v2beta1.types.CallMatcher.CustomHeaders): - Custom SIP headers that must match. - """ - - class CustomHeaders(proto.Message): - r"""Custom SIP headers. See the `description of headers in the - RFC `__. - - Attributes: - cisco_guid (str): - Cisco's proprietary ``Cisco-Guid`` header. - """ - - cisco_guid = proto.Field(proto.STRING, number=1) - - name = proto.Field(proto.STRING, number=1) - - to_header = proto.Field(proto.STRING, number=2) - - from_header = proto.Field(proto.STRING, number=3) - - call_id_header = proto.Field(proto.STRING, number=4) - - custom_headers = proto.Field(proto.MESSAGE, number=5, message=CustomHeaders,) - - class CreateConversationRequest(proto.Message): r"""The request message for [Conversations.CreateConversation][google.cloud.dialogflow.v2beta1.Conversations.CreateConversation]. @@ -354,86 +269,6 @@ class CompleteConversationRequest(proto.Message): name = proto.Field(proto.STRING, number=1) -class CreateCallMatcherRequest(proto.Message): - r"""The request message for - [Conversations.CreateCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.CreateCallMatcher]. - - Attributes: - parent (str): - Required. Resource identifier of the conversation adding the - call matcher. Format: - ``projects//locations//conversations/``. - call_matcher (google.cloud.dialogflow_v2beta1.types.CallMatcher): - Required. The call matcher to create. - """ - - parent = proto.Field(proto.STRING, number=1) - - call_matcher = proto.Field(proto.MESSAGE, number=2, message="CallMatcher",) - - -class ListCallMatchersRequest(proto.Message): - r"""The request message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - - Attributes: - parent (str): - Required. The conversation to list all call matchers from. - Format: - ``projects//locations//conversations/``. - page_size (int): - Optional. The maximum number of items to - return in a single page. By default 100 and at - most 1000. - page_token (str): - Optional. The next_page_token value returned from a previous - list request. - """ - - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - -class ListCallMatchersResponse(proto.Message): - r"""The response message for - [Conversations.ListCallMatchers][google.cloud.dialogflow.v2beta1.Conversations.ListCallMatchers]. - - Attributes: - call_matchers (Sequence[google.cloud.dialogflow_v2beta1.types.CallMatcher]): - The list of call matchers. There is a maximum number of - items returned based on the page_size field in the request. - next_page_token (str): - Token to retrieve the next page of results or - empty if there are no more results in the list. - """ - - @property - def raw_page(self): - return self - - call_matchers = proto.RepeatedField(proto.MESSAGE, number=1, message="CallMatcher",) - - next_page_token = proto.Field(proto.STRING, number=2) - - -class DeleteCallMatcherRequest(proto.Message): - r"""The request message for - [Conversations.DeleteCallMatcher][google.cloud.dialogflow.v2beta1.Conversations.DeleteCallMatcher]. - - Attributes: - name (str): - Required. The unique identifier of the - [CallMatcher][google.cloud.dialogflow.v2beta1.CallMatcher] - to delete. Format: - ``projects//locations//conversations//callMatchers/``. - """ - - name = proto.Field(proto.STRING, number=1) - - class CreateMessageRequest(proto.Message): r"""The request message to create one Message. Currently it is only used in BatchCreateMessagesRequest. diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/participant.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/participant.py index d6142d689bc4..33e507a67f7d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/participant.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/participant.py @@ -18,7 +18,7 @@ import proto # type: ignore -from google.cloud.dialogflow_v2beta1.types import audio_config as gcd_audio_config +from google.cloud.dialogflow_v2beta1.types import audio_config from google.cloud.dialogflow_v2beta1.types import session from google.protobuf import field_mask_pb2 as field_mask # type: ignore from google.protobuf import struct_pb2 as struct # type: ignore @@ -38,16 +38,12 @@ "UpdateParticipantRequest", "InputText", "InputAudio", - "AudioInput", "OutputAudio", "AutomatedAgentReply", "SuggestionFeature", "AnalyzeContentRequest", "DtmfParameters", "AnalyzeContentResponse", - "InputTextConfig", - "StreamingAnalyzeContentRequest", - "StreamingAnalyzeContentResponse", "AnnotatedMessagePart", "MessageAnnotation", "ArticleAnswer", @@ -320,29 +316,7 @@ class InputAudio(proto.Message): """ config = proto.Field( - proto.MESSAGE, number=1, message=gcd_audio_config.InputAudioConfig, - ) - - audio = proto.Field(proto.BYTES, number=2) - - -class AudioInput(proto.Message): - r"""Represents the natural language speech audio to be processed. - - Attributes: - config (google.cloud.dialogflow_v2beta1.types.InputAudioConfig): - Required. Instructs the speech recognizer how - to process the speech audio. - audio (bytes): - Required. The natural language speech audio - to be processed. A single request can contain up - to 1 minute of speech audio data. The - transcribed text cannot contain more than 256 - bytes. - """ - - config = proto.Field( - proto.MESSAGE, number=1, message=gcd_audio_config.InputAudioConfig, + proto.MESSAGE, number=1, message=audio_config.InputAudioConfig, ) audio = proto.Field(proto.BYTES, number=2) @@ -361,7 +335,7 @@ class OutputAudio(proto.Message): """ config = proto.Field( - proto.MESSAGE, number=1, message=gcd_audio_config.OutputAudioConfig, + proto.MESSAGE, number=1, message=audio_config.OutputAudioConfig, ) audio = proto.Field(proto.BYTES, number=2) @@ -436,16 +410,8 @@ class AnalyzeContentRequest(proto.Message): Required. The name of the participant this text comes from. Format: ``projects//locations//conversations//participants/``. - text (google.cloud.dialogflow_v2beta1.types.InputText): - The natural language text to be processed. - audio (google.cloud.dialogflow_v2beta1.types.InputAudio): - The natural language speech audio to be - processed. text_input (google.cloud.dialogflow_v2beta1.types.TextInput): The natural language text to be processed. - audio_input (google.cloud.dialogflow_v2beta1.types.AudioInput): - The natural language speech audio to be - processed. event_input (google.cloud.dialogflow_v2beta1.types.EventInput): An input event to send to Dialogflow. reply_audio_config (google.cloud.dialogflow_v2beta1.types.OutputAudioConfig): @@ -484,24 +450,16 @@ class AnalyzeContentRequest(proto.Message): participant = proto.Field(proto.STRING, number=1) - text = proto.Field(proto.MESSAGE, number=3, oneof="input", message="InputText",) - - audio = proto.Field(proto.MESSAGE, number=4, oneof="input", message="InputAudio",) - text_input = proto.Field( proto.MESSAGE, number=6, oneof="input", message=session.TextInput, ) - audio_input = proto.Field( - proto.MESSAGE, number=7, oneof="input", message="AudioInput", - ) - event_input = proto.Field( proto.MESSAGE, number=8, oneof="input", message=session.EventInput, ) reply_audio_config = proto.Field( - proto.MESSAGE, number=5, message=gcd_audio_config.OutputAudioConfig, + proto.MESSAGE, number=5, message=audio_config.OutputAudioConfig, ) query_params = proto.Field( @@ -596,245 +554,6 @@ class AnalyzeContentResponse(proto.Message): dtmf_parameters = proto.Field(proto.MESSAGE, number=9, message="DtmfParameters",) -class InputTextConfig(proto.Message): - r"""Defines the language used in the input text. - - Attributes: - language_code (str): - Required. The language of this conversational query. See - `Language - Support `__ - for a list of the currently supported language codes. - """ - - language_code = proto.Field(proto.STRING, number=1) - - -class StreamingAnalyzeContentRequest(proto.Message): - r"""The top-level message sent by the client to the - [Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.StreamingAnalyzeContent] - method. - - Multiple request messages should be sent in order: - - 1. The first message must contain - [participant][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.participant], - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - and optionally - [query_params][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.query_params]. - If you want to receive an audio response, it should also contain - [reply_audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.reply_audio_config]. - The message must not contain - [input][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input]. - - 2. If - [config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.audio_config], - all subsequent messages must contain - [input_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_audio] - to continue with Speech recognition. If you decide to rather - analyze text input after you already started Speech recognition, - please send a message with - [StreamingAnalyzeContentRequest.input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - - However, note that: - - - Dialogflow will bill you for the audio so far. - - Dialogflow discards all Speech recognition results in favor of - the text input. - - 3. If - [StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config] - in the first message was set to - [StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.text_config], - then the second message must contain only - [input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text]. - Moreover, you must not send more than two messages. - - After you sent all input, you must half-close or abort the request - stream. - - Attributes: - participant (str): - Required. The name of the participant this text comes from. - Format: - ``projects//locations//conversations//participants/``. - audio_config (google.cloud.dialogflow_v2beta1.types.InputAudioConfig): - Instructs the speech recognizer how to - process the speech audio. - text_config (google.cloud.dialogflow_v2beta1.types.InputTextConfig): - The natural language text to be processed. - reply_audio_config (google.cloud.dialogflow_v2beta1.types.OutputAudioConfig): - Speech synthesis configuration. - The speech synthesis settings for a virtual - agent that may be configured for the associated - conversation profile are not used when calling - StreamingAnalyzeContent. If this configuration - is not supplied, speech synthesis is disabled. - input_audio (bytes): - The input audio content to be recognized. Must be sent if - ``audio_config`` is set in the first message. The complete - audio over all streaming messages must not exceed 1 minute. - input_text (str): - The UTF-8 encoded natural language text to be processed. - Must be sent if ``text_config`` is set in the first message. - Text length must not exceed 256 bytes. The ``input_text`` - field can be only sent once. - input_dtmf (google.cloud.dialogflow_v2beta1.types.TelephonyDtmfEvents): - The DTMF digits used to invoke intent and - fill in parameter value. - This input is ignored if the previous response - indicated that DTMF input is not accepted. - query_params (google.cloud.dialogflow_v2beta1.types.QueryParameters): - Parameters for a Dialogflow virtual-agent - query. - enable_extended_streaming (bool): - Enable full bidirectional streaming. You can keep streaming - the audio until timeout, and there's no need to half close - the stream to get the response. - - Restrictions: - - - Timeout: 3 mins. - - Audio Encoding: only supports - [AudioEncoding.AUDIO_ENCODING_LINEAR_16][google.cloud.dialogflow.v2beta1.AudioEncoding.AUDIO_ENCODING_LINEAR_16] - and - [AudioEncoding.AUDIO_ENCODING_MULAW][google.cloud.dialogflow.v2beta1.AudioEncoding.AUDIO_ENCODING_MULAW] - - Lifecycle: conversation should be in ``Assist Stage``, go - to [Conversation.CreateConversation][] for more - information. - - InvalidArgument Error will be returned if the one of - restriction checks failed. - - You can find more details in - https://cloud.google.com/dialogflow/priv/docs/agent-assist/analyze-content-streaming - """ - - participant = proto.Field(proto.STRING, number=1) - - audio_config = proto.Field( - proto.MESSAGE, - number=2, - oneof="config", - message=gcd_audio_config.InputAudioConfig, - ) - - text_config = proto.Field( - proto.MESSAGE, number=3, oneof="config", message="InputTextConfig", - ) - - reply_audio_config = proto.Field( - proto.MESSAGE, number=4, message=gcd_audio_config.OutputAudioConfig, - ) - - input_audio = proto.Field(proto.BYTES, number=5, oneof="input") - - input_text = proto.Field(proto.STRING, number=6, oneof="input") - - input_dtmf = proto.Field( - proto.MESSAGE, - number=9, - oneof="input", - message=gcd_audio_config.TelephonyDtmfEvents, - ) - - query_params = proto.Field( - proto.MESSAGE, number=7, message=session.QueryParameters, - ) - - enable_extended_streaming = proto.Field(proto.BOOL, number=11) - - -class StreamingAnalyzeContentResponse(proto.Message): - r"""The top-level message returned from the ``StreamingAnalyzeContent`` - method. - - Multiple response messages can be returned in order: - - 1. If the input was set to streaming audio, the first one or more - messages contain ``recognition_result``. Each - ``recognition_result`` represents a more complete transcript of - what the user said. The last ``recognition_result`` has - ``is_final`` set to ``true``. - - 2. The next message contains ``reply_text`` and optionally - ``reply_audio`` returned by an agent. This message may also - contain ``automated_agent_reply``. - - Attributes: - recognition_result (google.cloud.dialogflow_v2beta1.types.StreamingRecognitionResult): - The result of speech recognition. - reply_text (str): - Optional. The output text content. - This field is set if an automated agent - responded with a text for the user. - reply_audio (google.cloud.dialogflow_v2beta1.types.OutputAudio): - Optional. The audio data bytes encoded as specified in the - request. This field is set if: - - - The ``reply_audio_config`` field is specified in the - request. - - The automated agent, which this output comes from, - responded with audio. In such case, the - ``reply_audio.config`` field contains settings used to - synthesize the speech. - - In some scenarios, multiple output audio fields may be - present in the response structure. In these cases, only the - top-most-level audio output has content. - automated_agent_reply (google.cloud.dialogflow_v2beta1.types.AutomatedAgentReply): - Optional. Only set if a Dialogflow automated agent has - responded. Note that: - [AutomatedAgentReply.detect_intent_response.output_audio][] - and - [AutomatedAgentReply.detect_intent_response.output_audio_config][] - are always empty, use - [reply_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentResponse.reply_audio] - instead. - message (google.cloud.dialogflow_v2beta1.types.Message): - Output only. Message analyzed by CCAI. - human_agent_suggestion_results (Sequence[google.cloud.dialogflow_v2beta1.types.SuggestionResult]): - The suggestions for most recent human agent. The order is - the same as - [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] - of - [HumanAgentAssistantConfig.human_agent_suggestion_config][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.human_agent_suggestion_config]. - end_user_suggestion_results (Sequence[google.cloud.dialogflow_v2beta1.types.SuggestionResult]): - The suggestions for end user. The order is the same as - [HumanAgentAssistantConfig.SuggestionConfig.feature_configs][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.SuggestionConfig.feature_configs] - of - [HumanAgentAssistantConfig.end_user_suggestion_config][google.cloud.dialogflow.v2beta1.HumanAgentAssistantConfig.end_user_suggestion_config]. - dtmf_parameters (google.cloud.dialogflow_v2beta1.types.DtmfParameters): - Indicates the parameters of DTMF. - """ - - recognition_result = proto.Field( - proto.MESSAGE, number=1, message=session.StreamingRecognitionResult, - ) - - reply_text = proto.Field(proto.STRING, number=2) - - reply_audio = proto.Field(proto.MESSAGE, number=3, message="OutputAudio",) - - automated_agent_reply = proto.Field( - proto.MESSAGE, number=4, message="AutomatedAgentReply", - ) - - message = proto.Field(proto.MESSAGE, number=6, message="Message",) - - human_agent_suggestion_results = proto.RepeatedField( - proto.MESSAGE, number=7, message="SuggestionResult", - ) - - end_user_suggestion_results = proto.RepeatedField( - proto.MESSAGE, number=8, message="SuggestionResult", - ) - - dtmf_parameters = proto.Field(proto.MESSAGE, number=10, message="DtmfParameters",) - - class AnnotatedMessagePart(proto.Message): r"""Represents a part of a message possibly annotated with an entity. The part can be an entity or purely a part of the diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/session.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/session.py index 435e12e36a28..83f336c1d136 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/session.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/types/session.py @@ -293,6 +293,9 @@ class QueryInput(proto.Message): The natural language text to be processed. event (google.cloud.dialogflow_v2beta1.types.EventInput): The event to be processed. + dtmf (google.cloud.dialogflow_v2beta1.types.TelephonyDtmfEvents): + The DTMF digits used to invoke intent and + fill in parameter value. """ audio_config = proto.Field( @@ -306,6 +309,13 @@ class QueryInput(proto.Message): event = proto.Field(proto.MESSAGE, number=3, oneof="input", message="EventInput",) + dtmf = proto.Field( + proto.MESSAGE, + number=4, + oneof="input", + message=gcd_audio_config.TelephonyDtmfEvents, + ) + class QueryResult(proto.Message): r"""Represents the result of conversational query or event diff --git a/packages/google-cloud-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 0ad24c69cae6..8e4c5018f8df 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -18,6 +18,7 @@ from __future__ import absolute_import import os +import pathlib import shutil import nox @@ -30,6 +31,8 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + # 'docfx' is excluded since it only needs to run in 'docs-presubmit' nox.options.sessions = [ "unit", @@ -41,6 +44,9 @@ "docs", ] +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): @@ -81,13 +87,15 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. - session.install("asyncmock", "pytest-asyncio") - session.install( - "mock", "pytest", "pytest-cov", + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) + session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - session.install("-e", ".") + session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) + + session.install("-e", ".", "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -114,6 +122,9 @@ def unit(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") @@ -138,10 +149,8 @@ def system(session): # Install all test dependencies, then install this package into the # virtualenv's dist-packages. - session.install( - "mock", "pytest", "google-cloud-testutils", - ) - session.install("-e", ".") + session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: @@ -170,7 +179,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=99") + session.run("coverage", "report", "--show-missing", "--fail-under=98") session.run("coverage", "erase") @@ -201,9 +210,7 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - # sphinx-docfx-yaml supports up to sphinx version 1.5.5. - # https://github.com/docascode/sphinx-docfx-yaml/issues/97 - session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") + session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/packages/google-cloud-dialogflow/renovate.json b/packages/google-cloud-dialogflow/renovate.json index 4fa949311b20..f08bc22c9a55 100644 --- a/packages/google-cloud-dialogflow/renovate.json +++ b/packages/google-cloud-dialogflow/renovate.json @@ -1,5 +1,6 @@ { "extends": [ "config:base", ":preserveSemverRanges" - ] + ], + "ignorePaths": [".pre-commit-config.yaml"] } diff --git a/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2_keywords.py b/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2_keywords.py index 3866fb44abb7..a6f9a0f0c229 100644 --- a/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2_keywords.py +++ b/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2_keywords.py @@ -41,7 +41,7 @@ def partition( class dialogflowCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'analyze_content': ('participant', 'text_input', 'audio_input', 'event_input', 'reply_audio_config', 'query_params', 'request_id', ), + 'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'request_id', ), 'batch_create_entities': ('parent', 'entities', 'language_code', ), 'batch_delete_entities': ('parent', 'entity_values', 'language_code', ), 'batch_delete_entity_types': ('parent', 'entity_type_names', ), @@ -50,7 +50,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'batch_update_entity_types': ('parent', 'entity_type_batch_uri', 'entity_type_batch_inline', 'language_code', 'update_mask', ), 'batch_update_intents': ('parent', 'intent_batch_uri', 'intent_batch_inline', 'language_code', 'update_mask', 'intent_view', ), 'complete_conversation': ('name', ), - 'create_call_matcher': ('parent', 'call_matcher', ), 'create_context': ('parent', 'context', ), 'create_conversation': ('parent', 'conversation', 'conversation_id', ), 'create_conversation_profile': ('parent', 'conversation_profile', ), @@ -62,7 +61,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'create_session_entity_type': ('parent', 'session_entity_type', ), 'delete_agent': ('parent', ), 'delete_all_contexts': ('parent', ), - 'delete_call_matcher': ('name', ), 'delete_context': ('name', ), 'delete_conversation_profile': ('name', ), 'delete_document': ('name', ), @@ -85,7 +83,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'get_validation_result': ('parent', 'language_code', ), 'import_agent': ('parent', 'agent_uri', 'agent_content', ), 'list_answer_records': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_call_matchers': ('parent', 'page_size', 'page_token', ), 'list_contexts': ('parent', 'page_size', 'page_token', ), 'list_conversation_profiles': ('parent', 'page_size', 'page_token', ), 'list_conversations': ('parent', 'page_size', 'page_token', 'filter', ), @@ -101,7 +98,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'restore_agent': ('parent', 'agent_uri', 'agent_content', ), 'search_agents': ('parent', 'page_size', 'page_token', ), 'set_agent': ('agent', 'update_mask', ), - 'streaming_analyze_content': ('participant', 'audio_config', 'text_config', 'reply_audio_config', 'input_audio', 'input_text', 'input_dtmf', 'query_params', ), 'streaming_detect_intent': ('session', 'query_input', 'query_params', 'single_utterance', 'output_audio_config', 'output_audio_config_mask', 'input_audio', ), 'suggest_articles': ('parent', 'latest_message', 'context_size', ), 'suggest_faq_answers': ('parent', 'latest_message', 'context_size', ), diff --git a/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2beta1_keywords.py b/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2beta1_keywords.py index 7d019940b476..edac9dea1fd4 100644 --- a/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2beta1_keywords.py +++ b/packages/google-cloud-dialogflow/scripts/fixup_dialogflow_v2beta1_keywords.py @@ -41,7 +41,7 @@ def partition( class dialogflowCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'analyze_content': ('participant', 'text', 'audio', 'text_input', 'audio_input', 'event_input', 'reply_audio_config', 'query_params', 'message_send_time', 'request_id', ), + 'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'message_send_time', 'request_id', ), 'batch_create_entities': ('parent', 'entities', 'language_code', ), 'batch_create_messages': ('parent', 'requests', ), 'batch_delete_entities': ('parent', 'entity_values', 'language_code', ), @@ -52,7 +52,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'batch_update_intents': ('parent', 'intent_batch_uri', 'intent_batch_inline', 'language_code', 'update_mask', 'intent_view', ), 'compile_suggestion': ('parent', 'latest_message', 'context_size', ), 'complete_conversation': ('name', ), - 'create_call_matcher': ('parent', 'call_matcher', ), 'create_context': ('parent', 'context', ), 'create_conversation': ('parent', 'conversation', 'conversation_id', ), 'create_conversation_profile': ('parent', 'conversation_profile', ), @@ -64,7 +63,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'create_session_entity_type': ('parent', 'session_entity_type', ), 'delete_agent': ('parent', ), 'delete_all_contexts': ('parent', ), - 'delete_call_matcher': ('name', ), 'delete_context': ('name', ), 'delete_conversation_profile': ('name', ), 'delete_document': ('name', ), @@ -89,7 +87,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'import_agent': ('parent', 'agent_uri', 'agent_content', ), 'import_documents': ('parent', 'document_template', 'gcs_source', 'import_gcs_custom_metadata', ), 'list_answer_records': ('parent', 'page_size', 'page_token', ), - 'list_call_matchers': ('parent', 'page_size', 'page_token', ), 'list_contexts': ('parent', 'page_size', 'page_token', ), 'list_conversation_profiles': ('parent', 'page_size', 'page_token', ), 'list_conversations': ('parent', 'page_size', 'page_token', 'filter', ), @@ -106,7 +103,6 @@ class dialogflowCallTransformer(cst.CSTTransformer): 'restore_agent': ('parent', 'agent_uri', 'agent_content', ), 'search_agents': ('parent', 'page_size', 'page_token', ), 'set_agent': ('agent', 'update_mask', ), - 'streaming_analyze_content': ('participant', 'audio_config', 'text_config', 'reply_audio_config', 'input_audio', 'input_text', 'input_dtmf', 'query_params', 'enable_extended_streaming', ), 'streaming_detect_intent': ('session', 'query_input', 'query_params', 'single_utterance', 'output_audio_config', 'output_audio_config_mask', 'input_audio', ), 'suggest_articles': ('parent', 'latest_message', 'context_size', ), 'suggest_faq_answers': ('parent', 'latest_message', 'context_size', ), diff --git a/packages/google-cloud-dialogflow/setup.py b/packages/google-cloud-dialogflow/setup.py index 84895e0e631d..91e165a4d764 100644 --- a/packages/google-cloud-dialogflow/setup.py +++ b/packages/google-cloud-dialogflow/setup.py @@ -21,7 +21,7 @@ description = "Client library for the Dialogflow API" version = "2.1.0" release_status = "Development Status :: 5 - Production/Stable" -dependencies = ["google-api-core[grpc] >= 1.22.0, < 2.0.0dev", "proto-plus >= 1.10.0"] +dependencies = ["google-api-core[grpc] >= 1.22.2, < 2.0.0dev", "proto-plus >= 1.10.0"] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/packages/google-cloud-dialogflow/synth.metadata b/packages/google-cloud-dialogflow/synth.metadata index 6a06ead8c28b..72c091c09719 100644 --- a/packages/google-cloud-dialogflow/synth.metadata +++ b/packages/google-cloud-dialogflow/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-dialogflow.git", - "sha": "4717cb2deeabf8a4226b27c9912cc809c5804936" + "remote": "git@github.com:googleapis/python-dialogflow", + "sha": "e5314e6c933b829df784ed4ffec3b93c1bd7ca63" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "4b16c60a8fffe213d3a5002f85696fef2b6a8172", - "internalRef": "362090097" + "sha": "915925089600094e72e4bfa8cf586c170e6b7109", + "internalRef": "366152684" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "ac8f20f12e7a4c0b0ae1c6fa415f684a25ea82b7" + "sha": "6d76df2138f8f841e5a5b9ac427f81def520c15f" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "ac8f20f12e7a4c0b0ae1c6fa415f684a25ea82b7" + "sha": "6d76df2138f8f841e5a5b9ac427f81def520c15f" } } ], @@ -49,428 +49,5 @@ "generator": "bazel" } } - ], - "generatedFiles": [ - ".coveragerc", - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/header-checker-lint.yml", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/dialogflow_v2/agents.rst", - "docs/dialogflow_v2/answer_records.rst", - "docs/dialogflow_v2/contexts.rst", - "docs/dialogflow_v2/conversation_profiles.rst", - "docs/dialogflow_v2/conversations.rst", - "docs/dialogflow_v2/documents.rst", - "docs/dialogflow_v2/entity_types.rst", - "docs/dialogflow_v2/environments.rst", - "docs/dialogflow_v2/intents.rst", - "docs/dialogflow_v2/knowledge_bases.rst", - "docs/dialogflow_v2/participants.rst", - "docs/dialogflow_v2/services.rst", - "docs/dialogflow_v2/session_entity_types.rst", - "docs/dialogflow_v2/sessions.rst", - "docs/dialogflow_v2/types.rst", - "docs/dialogflow_v2beta1/agents.rst", - "docs/dialogflow_v2beta1/answer_records.rst", - "docs/dialogflow_v2beta1/contexts.rst", - "docs/dialogflow_v2beta1/conversation_profiles.rst", - "docs/dialogflow_v2beta1/conversations.rst", - "docs/dialogflow_v2beta1/documents.rst", - "docs/dialogflow_v2beta1/entity_types.rst", - "docs/dialogflow_v2beta1/environments.rst", - "docs/dialogflow_v2beta1/intents.rst", - "docs/dialogflow_v2beta1/knowledge_bases.rst", - "docs/dialogflow_v2beta1/participants.rst", - "docs/dialogflow_v2beta1/services.rst", - "docs/dialogflow_v2beta1/session_entity_types.rst", - "docs/dialogflow_v2beta1/sessions.rst", - "docs/dialogflow_v2beta1/types.rst", - "docs/multiprocessing.rst", - "google/cloud/dialogflow/__init__.py", - "google/cloud/dialogflow/py.typed", - "google/cloud/dialogflow_v2/__init__.py", - "google/cloud/dialogflow_v2/proto/agent.proto", - "google/cloud/dialogflow_v2/proto/answer_record.proto", - "google/cloud/dialogflow_v2/proto/audio_config.proto", - "google/cloud/dialogflow_v2/proto/context.proto", - "google/cloud/dialogflow_v2/proto/conversation.proto", - "google/cloud/dialogflow_v2/proto/conversation_event.proto", - "google/cloud/dialogflow_v2/proto/conversation_profile.proto", - "google/cloud/dialogflow_v2/proto/document.proto", - "google/cloud/dialogflow_v2/proto/entity_type.proto", - "google/cloud/dialogflow_v2/proto/environment.proto", - "google/cloud/dialogflow_v2/proto/gcs.proto", - "google/cloud/dialogflow_v2/proto/human_agent_assistant_event.proto", - "google/cloud/dialogflow_v2/proto/intent.proto", - "google/cloud/dialogflow_v2/proto/knowledge_base.proto", - "google/cloud/dialogflow_v2/proto/participant.proto", - "google/cloud/dialogflow_v2/proto/session.proto", - "google/cloud/dialogflow_v2/proto/session_entity_type.proto", - "google/cloud/dialogflow_v2/proto/validation_result.proto", - "google/cloud/dialogflow_v2/proto/webhook.proto", - "google/cloud/dialogflow_v2/py.typed", - "google/cloud/dialogflow_v2/services/__init__.py", - "google/cloud/dialogflow_v2/services/agents/__init__.py", - "google/cloud/dialogflow_v2/services/agents/async_client.py", - "google/cloud/dialogflow_v2/services/agents/client.py", - "google/cloud/dialogflow_v2/services/agents/pagers.py", - "google/cloud/dialogflow_v2/services/agents/transports/__init__.py", - "google/cloud/dialogflow_v2/services/agents/transports/base.py", - "google/cloud/dialogflow_v2/services/agents/transports/grpc.py", - "google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/answer_records/__init__.py", - "google/cloud/dialogflow_v2/services/answer_records/async_client.py", - "google/cloud/dialogflow_v2/services/answer_records/client.py", - "google/cloud/dialogflow_v2/services/answer_records/pagers.py", - "google/cloud/dialogflow_v2/services/answer_records/transports/__init__.py", - "google/cloud/dialogflow_v2/services/answer_records/transports/base.py", - "google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py", - "google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/contexts/__init__.py", - "google/cloud/dialogflow_v2/services/contexts/async_client.py", - "google/cloud/dialogflow_v2/services/contexts/client.py", - "google/cloud/dialogflow_v2/services/contexts/pagers.py", - "google/cloud/dialogflow_v2/services/contexts/transports/__init__.py", - "google/cloud/dialogflow_v2/services/contexts/transports/base.py", - "google/cloud/dialogflow_v2/services/contexts/transports/grpc.py", - "google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/__init__.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/client.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/pagers.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/transports/__init__.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py", - "google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/conversations/__init__.py", - "google/cloud/dialogflow_v2/services/conversations/async_client.py", - "google/cloud/dialogflow_v2/services/conversations/client.py", - "google/cloud/dialogflow_v2/services/conversations/pagers.py", - "google/cloud/dialogflow_v2/services/conversations/transports/__init__.py", - "google/cloud/dialogflow_v2/services/conversations/transports/base.py", - "google/cloud/dialogflow_v2/services/conversations/transports/grpc.py", - "google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/documents/__init__.py", - "google/cloud/dialogflow_v2/services/documents/async_client.py", - "google/cloud/dialogflow_v2/services/documents/client.py", - "google/cloud/dialogflow_v2/services/documents/pagers.py", - "google/cloud/dialogflow_v2/services/documents/transports/__init__.py", - "google/cloud/dialogflow_v2/services/documents/transports/base.py", - "google/cloud/dialogflow_v2/services/documents/transports/grpc.py", - "google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/entity_types/__init__.py", - "google/cloud/dialogflow_v2/services/entity_types/async_client.py", - "google/cloud/dialogflow_v2/services/entity_types/client.py", - "google/cloud/dialogflow_v2/services/entity_types/pagers.py", - "google/cloud/dialogflow_v2/services/entity_types/transports/__init__.py", - "google/cloud/dialogflow_v2/services/entity_types/transports/base.py", - "google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py", - "google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/environments/__init__.py", - "google/cloud/dialogflow_v2/services/environments/async_client.py", - "google/cloud/dialogflow_v2/services/environments/client.py", - "google/cloud/dialogflow_v2/services/environments/pagers.py", - "google/cloud/dialogflow_v2/services/environments/transports/__init__.py", - "google/cloud/dialogflow_v2/services/environments/transports/base.py", - "google/cloud/dialogflow_v2/services/environments/transports/grpc.py", - "google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/intents/__init__.py", - "google/cloud/dialogflow_v2/services/intents/async_client.py", - "google/cloud/dialogflow_v2/services/intents/client.py", - "google/cloud/dialogflow_v2/services/intents/pagers.py", - "google/cloud/dialogflow_v2/services/intents/transports/__init__.py", - "google/cloud/dialogflow_v2/services/intents/transports/base.py", - "google/cloud/dialogflow_v2/services/intents/transports/grpc.py", - "google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/__init__.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/client.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/pagers.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/transports/__init__.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py", - "google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/participants/__init__.py", - "google/cloud/dialogflow_v2/services/participants/async_client.py", - "google/cloud/dialogflow_v2/services/participants/client.py", - "google/cloud/dialogflow_v2/services/participants/pagers.py", - "google/cloud/dialogflow_v2/services/participants/transports/__init__.py", - "google/cloud/dialogflow_v2/services/participants/transports/base.py", - "google/cloud/dialogflow_v2/services/participants/transports/grpc.py", - "google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/session_entity_types/__init__.py", - "google/cloud/dialogflow_v2/services/session_entity_types/async_client.py", - "google/cloud/dialogflow_v2/services/session_entity_types/client.py", - "google/cloud/dialogflow_v2/services/session_entity_types/pagers.py", - "google/cloud/dialogflow_v2/services/session_entity_types/transports/__init__.py", - "google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py", - "google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py", - "google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/services/sessions/__init__.py", - "google/cloud/dialogflow_v2/services/sessions/async_client.py", - "google/cloud/dialogflow_v2/services/sessions/client.py", - "google/cloud/dialogflow_v2/services/sessions/transports/__init__.py", - "google/cloud/dialogflow_v2/services/sessions/transports/base.py", - "google/cloud/dialogflow_v2/services/sessions/transports/grpc.py", - "google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2/types/__init__.py", - "google/cloud/dialogflow_v2/types/agent.py", - "google/cloud/dialogflow_v2/types/answer_record.py", - "google/cloud/dialogflow_v2/types/audio_config.py", - "google/cloud/dialogflow_v2/types/context.py", - "google/cloud/dialogflow_v2/types/conversation.py", - "google/cloud/dialogflow_v2/types/conversation_event.py", - "google/cloud/dialogflow_v2/types/conversation_profile.py", - "google/cloud/dialogflow_v2/types/document.py", - "google/cloud/dialogflow_v2/types/entity_type.py", - "google/cloud/dialogflow_v2/types/environment.py", - "google/cloud/dialogflow_v2/types/gcs.py", - "google/cloud/dialogflow_v2/types/human_agent_assistant_event.py", - "google/cloud/dialogflow_v2/types/intent.py", - "google/cloud/dialogflow_v2/types/knowledge_base.py", - "google/cloud/dialogflow_v2/types/participant.py", - "google/cloud/dialogflow_v2/types/session.py", - "google/cloud/dialogflow_v2/types/session_entity_type.py", - "google/cloud/dialogflow_v2/types/validation_result.py", - "google/cloud/dialogflow_v2/types/webhook.py", - "google/cloud/dialogflow_v2beta1/__init__.py", - "google/cloud/dialogflow_v2beta1/proto/agent.proto", - "google/cloud/dialogflow_v2beta1/proto/answer_record.proto", - "google/cloud/dialogflow_v2beta1/proto/audio_config.proto", - "google/cloud/dialogflow_v2beta1/proto/context.proto", - "google/cloud/dialogflow_v2beta1/proto/conversation.proto", - "google/cloud/dialogflow_v2beta1/proto/conversation_event.proto", - "google/cloud/dialogflow_v2beta1/proto/conversation_profile.proto", - "google/cloud/dialogflow_v2beta1/proto/document.proto", - "google/cloud/dialogflow_v2beta1/proto/entity_type.proto", - "google/cloud/dialogflow_v2beta1/proto/environment.proto", - "google/cloud/dialogflow_v2beta1/proto/gcs.proto", - "google/cloud/dialogflow_v2beta1/proto/human_agent_assistant_event.proto", - "google/cloud/dialogflow_v2beta1/proto/intent.proto", - "google/cloud/dialogflow_v2beta1/proto/knowledge_base.proto", - "google/cloud/dialogflow_v2beta1/proto/participant.proto", - "google/cloud/dialogflow_v2beta1/proto/session.proto", - "google/cloud/dialogflow_v2beta1/proto/session_entity_type.proto", - "google/cloud/dialogflow_v2beta1/proto/validation_result.proto", - "google/cloud/dialogflow_v2beta1/proto/webhook.proto", - "google/cloud/dialogflow_v2beta1/py.typed", - "google/cloud/dialogflow_v2beta1/services/__init__.py", - "google/cloud/dialogflow_v2beta1/services/agents/__init__.py", - "google/cloud/dialogflow_v2beta1/services/agents/async_client.py", - "google/cloud/dialogflow_v2beta1/services/agents/client.py", - "google/cloud/dialogflow_v2beta1/services/agents/pagers.py", - "google/cloud/dialogflow_v2beta1/services/agents/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/agents/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/__init__.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/client.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/pagers.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/contexts/__init__.py", - "google/cloud/dialogflow_v2beta1/services/contexts/async_client.py", - "google/cloud/dialogflow_v2beta1/services/contexts/client.py", - "google/cloud/dialogflow_v2beta1/services/contexts/pagers.py", - "google/cloud/dialogflow_v2beta1/services/contexts/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/__init__.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/pagers.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/conversations/__init__.py", - "google/cloud/dialogflow_v2beta1/services/conversations/async_client.py", - "google/cloud/dialogflow_v2beta1/services/conversations/client.py", - "google/cloud/dialogflow_v2beta1/services/conversations/pagers.py", - "google/cloud/dialogflow_v2beta1/services/conversations/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/documents/__init__.py", - "google/cloud/dialogflow_v2beta1/services/documents/async_client.py", - "google/cloud/dialogflow_v2beta1/services/documents/client.py", - "google/cloud/dialogflow_v2beta1/services/documents/pagers.py", - "google/cloud/dialogflow_v2beta1/services/documents/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/documents/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/__init__.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/client.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/pagers.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/environments/__init__.py", - "google/cloud/dialogflow_v2beta1/services/environments/async_client.py", - "google/cloud/dialogflow_v2beta1/services/environments/client.py", - "google/cloud/dialogflow_v2beta1/services/environments/pagers.py", - "google/cloud/dialogflow_v2beta1/services/environments/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/environments/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/intents/__init__.py", - "google/cloud/dialogflow_v2beta1/services/intents/async_client.py", - "google/cloud/dialogflow_v2beta1/services/intents/client.py", - "google/cloud/dialogflow_v2beta1/services/intents/pagers.py", - "google/cloud/dialogflow_v2beta1/services/intents/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/intents/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/__init__.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/pagers.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/participants/__init__.py", - "google/cloud/dialogflow_v2beta1/services/participants/async_client.py", - "google/cloud/dialogflow_v2beta1/services/participants/client.py", - "google/cloud/dialogflow_v2beta1/services/participants/pagers.py", - "google/cloud/dialogflow_v2beta1/services/participants/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/participants/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/__init__.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/pagers.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/services/sessions/__init__.py", - "google/cloud/dialogflow_v2beta1/services/sessions/async_client.py", - "google/cloud/dialogflow_v2beta1/services/sessions/client.py", - "google/cloud/dialogflow_v2beta1/services/sessions/transports/__init__.py", - "google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py", - "google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py", - "google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py", - "google/cloud/dialogflow_v2beta1/types/__init__.py", - "google/cloud/dialogflow_v2beta1/types/agent.py", - "google/cloud/dialogflow_v2beta1/types/answer_record.py", - "google/cloud/dialogflow_v2beta1/types/audio_config.py", - "google/cloud/dialogflow_v2beta1/types/context.py", - "google/cloud/dialogflow_v2beta1/types/conversation.py", - "google/cloud/dialogflow_v2beta1/types/conversation_event.py", - "google/cloud/dialogflow_v2beta1/types/conversation_profile.py", - "google/cloud/dialogflow_v2beta1/types/document.py", - "google/cloud/dialogflow_v2beta1/types/entity_type.py", - "google/cloud/dialogflow_v2beta1/types/environment.py", - "google/cloud/dialogflow_v2beta1/types/gcs.py", - "google/cloud/dialogflow_v2beta1/types/human_agent_assistant_event.py", - "google/cloud/dialogflow_v2beta1/types/intent.py", - "google/cloud/dialogflow_v2beta1/types/knowledge_base.py", - "google/cloud/dialogflow_v2beta1/types/participant.py", - "google/cloud/dialogflow_v2beta1/types/session.py", - "google/cloud/dialogflow_v2beta1/types/session_entity_type.py", - "google/cloud/dialogflow_v2beta1/types/validation_result.py", - "google/cloud/dialogflow_v2beta1/types/webhook.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "scripts/decrypt-secrets.sh", - "scripts/fixup_dialogflow_v2_keywords.py", - "scripts/fixup_dialogflow_v2beta1_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/dialogflow_v2/__init__.py", - "tests/unit/gapic/dialogflow_v2/test_agents.py", - "tests/unit/gapic/dialogflow_v2/test_answer_records.py", - "tests/unit/gapic/dialogflow_v2/test_contexts.py", - "tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py", - "tests/unit/gapic/dialogflow_v2/test_conversations.py", - "tests/unit/gapic/dialogflow_v2/test_documents.py", - "tests/unit/gapic/dialogflow_v2/test_entity_types.py", - "tests/unit/gapic/dialogflow_v2/test_environments.py", - "tests/unit/gapic/dialogflow_v2/test_intents.py", - "tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py", - "tests/unit/gapic/dialogflow_v2/test_participants.py", - "tests/unit/gapic/dialogflow_v2/test_session_entity_types.py", - "tests/unit/gapic/dialogflow_v2/test_sessions.py", - "tests/unit/gapic/dialogflow_v2beta1/__init__.py", - "tests/unit/gapic/dialogflow_v2beta1/test_agents.py", - "tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py", - "tests/unit/gapic/dialogflow_v2beta1/test_contexts.py", - "tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py", - "tests/unit/gapic/dialogflow_v2beta1/test_conversations.py", - "tests/unit/gapic/dialogflow_v2beta1/test_documents.py", - "tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py", - "tests/unit/gapic/dialogflow_v2beta1/test_environments.py", - "tests/unit/gapic/dialogflow_v2beta1/test_intents.py", - "tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py", - "tests/unit/gapic/dialogflow_v2beta1/test_participants.py", - "tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py", - "tests/unit/gapic/dialogflow_v2beta1/test_sessions.py" ] } \ No newline at end of file diff --git a/packages/google-cloud-dialogflow/synth.py b/packages/google-cloud-dialogflow/synth.py index 602691e48bfc..13fd47bae297 100644 --- a/packages/google-cloud-dialogflow/synth.py +++ b/packages/google-cloud-dialogflow/synth.py @@ -39,8 +39,8 @@ templated_files = common.py_library( samples=False, # set to True only if there are samples microgenerator=True, - cov_level=99, - + cov_level=98, + ) s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file @@ -51,5 +51,5 @@ '''["']-W["'], # warnings as errors''', "", ) - + s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.6.txt b/packages/google-cloud-dialogflow/testing/constraints-3.6.txt index 04d54afeeab3..25cd0683d471 100644 --- a/packages/google-cloud-dialogflow/testing/constraints-3.6.txt +++ b/packages/google-cloud-dialogflow/testing/constraints-3.6.txt @@ -1,9 +1,9 @@ # This constraints file is used to check that lower bounds # are correct in setup.py -# List *all* library dependencies and extras in this file. +# List all library dependencies and extras in this file. # Pin the version to the lower bound. -# -# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", -# Then this file should have foo==1.14.0 -google-api-core==1.22.0 + +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.22.2 proto-plus==1.10.0 diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.7.txt b/packages/google-cloud-dialogflow/testing/constraints-3.7.txt index e69de29bb2d1..da93009be5fe 100644 --- a/packages/google-cloud-dialogflow/testing/constraints-3.7.txt +++ b/packages/google-cloud-dialogflow/testing/constraints-3.7.txt @@ -0,0 +1,2 @@ +# This constraints file is left inentionally empty +# so the latest version of dependencies is installed \ No newline at end of file diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.8.txt b/packages/google-cloud-dialogflow/testing/constraints-3.8.txt index e69de29bb2d1..da93009be5fe 100644 --- a/packages/google-cloud-dialogflow/testing/constraints-3.8.txt +++ b/packages/google-cloud-dialogflow/testing/constraints-3.8.txt @@ -0,0 +1,2 @@ +# This constraints file is left inentionally empty +# so the latest version of dependencies is installed \ No newline at end of file diff --git a/packages/google-cloud-dialogflow/testing/constraints-3.9.txt b/packages/google-cloud-dialogflow/testing/constraints-3.9.txt index e69de29bb2d1..da93009be5fe 100644 --- a/packages/google-cloud-dialogflow/testing/constraints-3.9.txt +++ b/packages/google-cloud-dialogflow/testing/constraints-3.9.txt @@ -0,0 +1,2 @@ +# This constraints file is left inentionally empty +# so the latest version of dependencies is installed \ No newline at end of file diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py index 2fedf55b827f..2f3f7b1853c3 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py @@ -1599,852 +1599,6 @@ async def test_complete_conversation_flattened_error_async(): ) -def test_create_call_matcher( - transport: str = "grpc", request_type=conversation.CreateCallMatcherRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher( - name="name_value", - to_header="to_header_value", - from_header="from_header_value", - call_id_header="call_id_header_value", - ) - - response = client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - # Establish that the response is the type that we expect. - - assert isinstance(response, conversation.CallMatcher) - - assert response.name == "name_value" - - assert response.to_header == "to_header_value" - - assert response.from_header == "from_header_value" - - assert response.call_id_header == "call_id_header_value" - - -def test_create_call_matcher_from_dict(): - test_create_call_matcher(request_type=dict) - - -def test_create_call_matcher_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - client.create_call_matcher() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - -@pytest.mark.asyncio -async def test_create_call_matcher_async( - transport: str = "grpc_asyncio", request_type=conversation.CreateCallMatcherRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher( - name="name_value", - to_header="to_header_value", - from_header="from_header_value", - call_id_header="call_id_header_value", - ) - ) - - response = await client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, conversation.CallMatcher) - - assert response.name == "name_value" - - assert response.to_header == "to_header_value" - - assert response.from_header == "from_header_value" - - assert response.call_id_header == "call_id_header_value" - - -@pytest.mark.asyncio -async def test_create_call_matcher_async_from_dict(): - await test_create_call_matcher_async(request_type=dict) - - -def test_create_call_matcher_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.CreateCallMatcherRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - call.return_value = conversation.CallMatcher() - - client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_create_call_matcher_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.CreateCallMatcherRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher() - ) - - await client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -def test_create_call_matcher_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher() - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_call_matcher( - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - assert args[0].call_matcher == conversation.CallMatcher(name="name_value") - - -def test_create_call_matcher_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_call_matcher( - conversation.CreateCallMatcherRequest(), - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - -@pytest.mark.asyncio -async def test_create_call_matcher_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_call_matcher( - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - assert args[0].call_matcher == conversation.CallMatcher(name="name_value") - - -@pytest.mark.asyncio -async def test_create_call_matcher_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_call_matcher( - conversation.CreateCallMatcherRequest(), - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - -def test_list_call_matchers( - transport: str = "grpc", request_type=conversation.ListCallMatchersRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse( - next_page_token="next_page_token_value", - ) - - response = client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - # Establish that the response is the type that we expect. - - assert isinstance(response, pagers.ListCallMatchersPager) - - assert response.next_page_token == "next_page_token_value" - - -def test_list_call_matchers_from_dict(): - test_list_call_matchers(request_type=dict) - - -def test_list_call_matchers_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - client.list_call_matchers() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - -@pytest.mark.asyncio -async def test_list_call_matchers_async( - transport: str = "grpc_asyncio", request_type=conversation.ListCallMatchersRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse( - next_page_token="next_page_token_value", - ) - ) - - response = await client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCallMatchersAsyncPager) - - assert response.next_page_token == "next_page_token_value" - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_from_dict(): - await test_list_call_matchers_async(request_type=dict) - - -def test_list_call_matchers_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.ListCallMatchersRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - call.return_value = conversation.ListCallMatchersResponse() - - client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_list_call_matchers_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.ListCallMatchersRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse() - ) - - await client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -def test_list_call_matchers_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse() - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_call_matchers(parent="parent_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - -def test_list_call_matchers_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_call_matchers( - conversation.ListCallMatchersRequest(), parent="parent_value", - ) - - -@pytest.mark.asyncio -async def test_list_call_matchers_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_call_matchers(parent="parent_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - -@pytest.mark.asyncio -async def test_list_call_matchers_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_call_matchers( - conversation.ListCallMatchersRequest(), parent="parent_value", - ) - - -def test_list_call_matchers_pager(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_call_matchers(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, conversation.CallMatcher) for i in results) - - -def test_list_call_matchers_pages(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - pages = list(client.list_call_matchers(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_pager(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - async_pager = await client.list_call_matchers(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, conversation.CallMatcher) for i in responses) - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_pages(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_call_matchers(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_delete_call_matcher( - transport: str = "grpc", request_type=conversation.DeleteCallMatcherRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - response = client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_call_matcher_from_dict(): - test_delete_call_matcher(request_type=dict) - - -def test_delete_call_matcher_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - client.delete_call_matcher() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - -@pytest.mark.asyncio -async def test_delete_call_matcher_async( - transport: str = "grpc_asyncio", request_type=conversation.DeleteCallMatcherRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - - response = await client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_call_matcher_async_from_dict(): - await test_delete_call_matcher_async(request_type=dict) - - -def test_delete_call_matcher_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.DeleteCallMatcherRequest() - request.name = "name/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - call.return_value = None - - client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_delete_call_matcher_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.DeleteCallMatcherRequest() - request.name = "name/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - - await client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] - - -def test_delete_call_matcher_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_call_matcher(name="name_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].name == "name_value" - - -def test_delete_call_matcher_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_call_matcher( - conversation.DeleteCallMatcherRequest(), name="name_value", - ) - - -@pytest.mark.asyncio -async def test_delete_call_matcher_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_call_matcher(name="name_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].name == "name_value" - - -@pytest.mark.asyncio -async def test_delete_call_matcher_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_call_matcher( - conversation.DeleteCallMatcherRequest(), name="name_value", - ) - - def test_list_messages( transport: str = "grpc", request_type=conversation.ListMessagesRequest ): @@ -2893,9 +2047,6 @@ def test_conversations_base_transport(): "list_conversations", "get_conversation", "complete_conversation", - "create_call_matcher", - "list_call_matchers", - "delete_call_matcher", "list_messages", ) for method in methods: @@ -3163,34 +2314,9 @@ def test_conversations_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_call_matcher_path(): +def test_conversation_path(): project = "squid" conversation = "clam" - call_matcher = "whelk" - - expected = "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}".format( - project=project, conversation=conversation, call_matcher=call_matcher, - ) - actual = ConversationsClient.call_matcher_path(project, conversation, call_matcher) - assert expected == actual - - -def test_parse_call_matcher_path(): - expected = { - "project": "octopus", - "conversation": "oyster", - "call_matcher": "nudibranch", - } - path = ConversationsClient.call_matcher_path(**expected) - - # Check that the path construction is reversible. - actual = ConversationsClient.parse_call_matcher_path(path) - assert expected == actual - - -def test_conversation_path(): - project = "cuttlefish" - conversation = "mussel" expected = "projects/{project}/conversations/{conversation}".format( project=project, conversation=conversation, @@ -3201,8 +2327,8 @@ def test_conversation_path(): def test_parse_conversation_path(): expected = { - "project": "winkle", - "conversation": "nautilus", + "project": "whelk", + "conversation": "octopus", } path = ConversationsClient.conversation_path(**expected) @@ -3212,8 +2338,8 @@ def test_parse_conversation_path(): def test_conversation_profile_path(): - project = "scallop" - conversation_profile = "abalone" + project = "oyster" + conversation_profile = "nudibranch" expected = "projects/{project}/conversationProfiles/{conversation_profile}".format( project=project, conversation_profile=conversation_profile, @@ -3226,8 +2352,8 @@ def test_conversation_profile_path(): def test_parse_conversation_profile_path(): expected = { - "project": "squid", - "conversation_profile": "clam", + "project": "cuttlefish", + "conversation_profile": "mussel", } path = ConversationsClient.conversation_profile_path(**expected) @@ -3237,9 +2363,9 @@ def test_parse_conversation_profile_path(): def test_message_path(): - project = "whelk" - conversation = "octopus" - message = "oyster" + project = "winkle" + conversation = "nautilus" + message = "scallop" expected = "projects/{project}/conversations/{conversation}/messages/{message}".format( project=project, conversation=conversation, message=message, @@ -3250,9 +2376,9 @@ def test_message_path(): def test_parse_message_path(): expected = { - "project": "nudibranch", - "conversation": "cuttlefish", - "message": "mussel", + "project": "abalone", + "conversation": "squid", + "message": "clam", } path = ConversationsClient.message_path(**expected) @@ -3262,7 +2388,7 @@ def test_parse_message_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "whelk" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -3273,7 +2399,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "octopus", } path = ConversationsClient.common_billing_account_path(**expected) @@ -3283,7 +2409,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "oyster" expected = "folders/{folder}".format(folder=folder,) actual = ConversationsClient.common_folder_path(folder) @@ -3292,7 +2418,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "nudibranch", } path = ConversationsClient.common_folder_path(**expected) @@ -3302,7 +2428,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "cuttlefish" expected = "organizations/{organization}".format(organization=organization,) actual = ConversationsClient.common_organization_path(organization) @@ -3311,7 +2437,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "mussel", } path = ConversationsClient.common_organization_path(**expected) @@ -3321,7 +2447,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "winkle" expected = "projects/{project}".format(project=project,) actual = ConversationsClient.common_project_path(project) @@ -3330,7 +2456,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "nautilus", } path = ConversationsClient.common_project_path(**expected) @@ -3340,8 +2466,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "scallop" + location = "abalone" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -3352,8 +2478,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "squid", + "location": "clam", } path = ConversationsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py index 705bec0ff42a..bef06db64d1c 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py @@ -1703,11 +1703,6 @@ def test_analyze_content_flattened(): client.analyze_content( participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1731,11 +1726,6 @@ def test_analyze_content_flattened_error(): gcd_participant.AnalyzeContentRequest(), participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1757,11 +1747,6 @@ async def test_analyze_content_flattened_async(): response = await client.analyze_content( participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1786,95 +1771,10 @@ async def test_analyze_content_flattened_error_async(): gcd_participant.AnalyzeContentRequest(), participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) -def test_streaming_analyze_content( - transport: str = "grpc", request_type=participant.StreamingAnalyzeContentRequest -): - client = ParticipantsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - requests = [request] - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_analyze_content), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = iter([participant.StreamingAnalyzeContentResponse()]) - - response = client.streaming_analyze_content(iter(requests)) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert next(args[0]) == request - - # Establish that the response is the type that we expect. - for message in response: - assert isinstance(message, participant.StreamingAnalyzeContentResponse) - - -def test_streaming_analyze_content_from_dict(): - test_streaming_analyze_content(request_type=dict) - - -@pytest.mark.asyncio -async def test_streaming_analyze_content_async( - transport: str = "grpc_asyncio", - request_type=participant.StreamingAnalyzeContentRequest, -): - client = ParticipantsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - requests = [request] - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_analyze_content), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = mock.Mock(aio.StreamStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock( - side_effect=[participant.StreamingAnalyzeContentResponse()] - ) - - response = await client.streaming_analyze_content(iter(requests)) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert next(args[0]) == request - - # Establish that the response is the type that we expect. - message = await response.read() - assert isinstance(message, participant.StreamingAnalyzeContentResponse) - - -@pytest.mark.asyncio -async def test_streaming_analyze_content_async_from_dict(): - await test_streaming_analyze_content_async(request_type=dict) - - def test_suggest_articles( transport: str = "grpc", request_type=participant.SuggestArticlesRequest ): @@ -2421,7 +2321,6 @@ def test_participants_base_transport(): "list_participants", "update_participant", "analyze_content", - "streaming_analyze_content", "suggest_articles", "suggest_faq_answers", ) diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py index 96d430f8a237..daa1b4d91e36 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py @@ -1603,852 +1603,6 @@ async def test_complete_conversation_flattened_error_async(): ) -def test_create_call_matcher( - transport: str = "grpc", request_type=conversation.CreateCallMatcherRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher( - name="name_value", - to_header="to_header_value", - from_header="from_header_value", - call_id_header="call_id_header_value", - ) - - response = client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - # Establish that the response is the type that we expect. - - assert isinstance(response, conversation.CallMatcher) - - assert response.name == "name_value" - - assert response.to_header == "to_header_value" - - assert response.from_header == "from_header_value" - - assert response.call_id_header == "call_id_header_value" - - -def test_create_call_matcher_from_dict(): - test_create_call_matcher(request_type=dict) - - -def test_create_call_matcher_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - client.create_call_matcher() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - -@pytest.mark.asyncio -async def test_create_call_matcher_async( - transport: str = "grpc_asyncio", request_type=conversation.CreateCallMatcherRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher( - name="name_value", - to_header="to_header_value", - from_header="from_header_value", - call_id_header="call_id_header_value", - ) - ) - - response = await client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.CreateCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, conversation.CallMatcher) - - assert response.name == "name_value" - - assert response.to_header == "to_header_value" - - assert response.from_header == "from_header_value" - - assert response.call_id_header == "call_id_header_value" - - -@pytest.mark.asyncio -async def test_create_call_matcher_async_from_dict(): - await test_create_call_matcher_async(request_type=dict) - - -def test_create_call_matcher_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.CreateCallMatcherRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - call.return_value = conversation.CallMatcher() - - client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_create_call_matcher_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.CreateCallMatcherRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher() - ) - - await client.create_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -def test_create_call_matcher_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher() - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_call_matcher( - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - assert args[0].call_matcher == conversation.CallMatcher(name="name_value") - - -def test_create_call_matcher_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_call_matcher( - conversation.CreateCallMatcherRequest(), - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - -@pytest.mark.asyncio -async def test_create_call_matcher_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.CallMatcher() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.CallMatcher() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_call_matcher( - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - assert args[0].call_matcher == conversation.CallMatcher(name="name_value") - - -@pytest.mark.asyncio -async def test_create_call_matcher_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_call_matcher( - conversation.CreateCallMatcherRequest(), - parent="parent_value", - call_matcher=conversation.CallMatcher(name="name_value"), - ) - - -def test_list_call_matchers( - transport: str = "grpc", request_type=conversation.ListCallMatchersRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse( - next_page_token="next_page_token_value", - ) - - response = client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - # Establish that the response is the type that we expect. - - assert isinstance(response, pagers.ListCallMatchersPager) - - assert response.next_page_token == "next_page_token_value" - - -def test_list_call_matchers_from_dict(): - test_list_call_matchers(request_type=dict) - - -def test_list_call_matchers_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - client.list_call_matchers() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - -@pytest.mark.asyncio -async def test_list_call_matchers_async( - transport: str = "grpc_asyncio", request_type=conversation.ListCallMatchersRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse( - next_page_token="next_page_token_value", - ) - ) - - response = await client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.ListCallMatchersRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListCallMatchersAsyncPager) - - assert response.next_page_token == "next_page_token_value" - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_from_dict(): - await test_list_call_matchers_async(request_type=dict) - - -def test_list_call_matchers_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.ListCallMatchersRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - call.return_value = conversation.ListCallMatchersResponse() - - client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_list_call_matchers_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.ListCallMatchersRequest() - request.parent = "parent/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse() - ) - - await client.list_call_matchers(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] - - -def test_list_call_matchers_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse() - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_call_matchers(parent="parent_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - -def test_list_call_matchers_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_call_matchers( - conversation.ListCallMatchersRequest(), parent="parent_value", - ) - - -@pytest.mark.asyncio -async def test_list_call_matchers_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = conversation.ListCallMatchersResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - conversation.ListCallMatchersResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_call_matchers(parent="parent_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].parent == "parent_value" - - -@pytest.mark.asyncio -async def test_list_call_matchers_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_call_matchers( - conversation.ListCallMatchersRequest(), parent="parent_value", - ) - - -def test_list_call_matchers_pager(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_call_matchers(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, conversation.CallMatcher) for i in results) - - -def test_list_call_matchers_pages(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - pages = list(client.list_call_matchers(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_pager(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - async_pager = await client.list_call_matchers(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, conversation.CallMatcher) for i in responses) - - -@pytest.mark.asyncio -async def test_list_call_matchers_async_pages(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_call_matchers), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - conversation.ListCallMatchersResponse( - call_matchers=[ - conversation.CallMatcher(), - conversation.CallMatcher(), - conversation.CallMatcher(), - ], - next_page_token="abc", - ), - conversation.ListCallMatchersResponse( - call_matchers=[], next_page_token="def", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(),], next_page_token="ghi", - ), - conversation.ListCallMatchersResponse( - call_matchers=[conversation.CallMatcher(), conversation.CallMatcher(),], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_call_matchers(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_delete_call_matcher( - transport: str = "grpc", request_type=conversation.DeleteCallMatcherRequest -): - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - response = client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_call_matcher_from_dict(): - test_delete_call_matcher(request_type=dict) - - -def test_delete_call_matcher_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ConversationsClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - client.delete_call_matcher() - call.assert_called() - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - -@pytest.mark.asyncio -async def test_delete_call_matcher_async( - transport: str = "grpc_asyncio", request_type=conversation.DeleteCallMatcherRequest -): - client = ConversationsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - - response = await client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0] == conversation.DeleteCallMatcherRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_call_matcher_async_from_dict(): - await test_delete_call_matcher_async(request_type=dict) - - -def test_delete_call_matcher_field_headers(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.DeleteCallMatcherRequest() - request.name = "name/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - call.return_value = None - - client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_delete_call_matcher_field_headers_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = conversation.DeleteCallMatcherRequest() - request.name = "name/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - - await client.delete_call_matcher(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] - - -def test_delete_call_matcher_flattened(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_call_matcher(name="name_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert args[0].name == "name_value" - - -def test_delete_call_matcher_flattened_error(): - client = ConversationsClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_call_matcher( - conversation.DeleteCallMatcherRequest(), name="name_value", - ) - - -@pytest.mark.asyncio -async def test_delete_call_matcher_flattened_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_call_matcher), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_call_matcher(name="name_value",) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert args[0].name == "name_value" - - -@pytest.mark.asyncio -async def test_delete_call_matcher_flattened_error_async(): - client = ConversationsAsyncClient(credentials=credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_call_matcher( - conversation.DeleteCallMatcherRequest(), name="name_value", - ) - - def test_batch_create_messages( transport: str = "grpc", request_type=conversation.BatchCreateMessagesRequest ): @@ -3115,9 +2269,6 @@ def test_conversations_base_transport(): "list_conversations", "get_conversation", "complete_conversation", - "create_call_matcher", - "list_call_matchers", - "delete_call_matcher", "batch_create_messages", "list_messages", ) @@ -3386,34 +2537,9 @@ def test_conversations_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel -def test_call_matcher_path(): +def test_conversation_path(): project = "squid" conversation = "clam" - call_matcher = "whelk" - - expected = "projects/{project}/conversations/{conversation}/callMatchers/{call_matcher}".format( - project=project, conversation=conversation, call_matcher=call_matcher, - ) - actual = ConversationsClient.call_matcher_path(project, conversation, call_matcher) - assert expected == actual - - -def test_parse_call_matcher_path(): - expected = { - "project": "octopus", - "conversation": "oyster", - "call_matcher": "nudibranch", - } - path = ConversationsClient.call_matcher_path(**expected) - - # Check that the path construction is reversible. - actual = ConversationsClient.parse_call_matcher_path(path) - assert expected == actual - - -def test_conversation_path(): - project = "cuttlefish" - conversation = "mussel" expected = "projects/{project}/conversations/{conversation}".format( project=project, conversation=conversation, @@ -3424,8 +2550,8 @@ def test_conversation_path(): def test_parse_conversation_path(): expected = { - "project": "winkle", - "conversation": "nautilus", + "project": "whelk", + "conversation": "octopus", } path = ConversationsClient.conversation_path(**expected) @@ -3435,8 +2561,8 @@ def test_parse_conversation_path(): def test_conversation_profile_path(): - project = "scallop" - conversation_profile = "abalone" + project = "oyster" + conversation_profile = "nudibranch" expected = "projects/{project}/conversationProfiles/{conversation_profile}".format( project=project, conversation_profile=conversation_profile, @@ -3449,8 +2575,8 @@ def test_conversation_profile_path(): def test_parse_conversation_profile_path(): expected = { - "project": "squid", - "conversation_profile": "clam", + "project": "cuttlefish", + "conversation_profile": "mussel", } path = ConversationsClient.conversation_profile_path(**expected) @@ -3460,9 +2586,9 @@ def test_parse_conversation_profile_path(): def test_message_path(): - project = "whelk" - conversation = "octopus" - message = "oyster" + project = "winkle" + conversation = "nautilus" + message = "scallop" expected = "projects/{project}/conversations/{conversation}/messages/{message}".format( project=project, conversation=conversation, message=message, @@ -3473,9 +2599,9 @@ def test_message_path(): def test_parse_message_path(): expected = { - "project": "nudibranch", - "conversation": "cuttlefish", - "message": "mussel", + "project": "abalone", + "conversation": "squid", + "message": "clam", } path = ConversationsClient.message_path(**expected) @@ -3485,7 +2611,7 @@ def test_parse_message_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "whelk" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -3496,7 +2622,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "octopus", } path = ConversationsClient.common_billing_account_path(**expected) @@ -3506,7 +2632,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "oyster" expected = "folders/{folder}".format(folder=folder,) actual = ConversationsClient.common_folder_path(folder) @@ -3515,7 +2641,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "nudibranch", } path = ConversationsClient.common_folder_path(**expected) @@ -3525,7 +2651,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "cuttlefish" expected = "organizations/{organization}".format(organization=organization,) actual = ConversationsClient.common_organization_path(organization) @@ -3534,7 +2660,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "mussel", } path = ConversationsClient.common_organization_path(**expected) @@ -3544,7 +2670,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "winkle" expected = "projects/{project}".format(project=project,) actual = ConversationsClient.common_project_path(project) @@ -3553,7 +2679,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "nautilus", } path = ConversationsClient.common_project_path(**expected) @@ -3563,8 +2689,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "scallop" + location = "abalone" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -3575,8 +2701,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "squid", + "location": "clam", } path = ConversationsClient.common_location_path(**expected) diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py index 8887c027c503..5e42b5752fba 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py @@ -1707,11 +1707,6 @@ def test_analyze_content_flattened(): client.analyze_content( participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1735,11 +1730,6 @@ def test_analyze_content_flattened_error(): gcd_participant.AnalyzeContentRequest(), participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1761,11 +1751,6 @@ async def test_analyze_content_flattened_async(): response = await client.analyze_content( participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) @@ -1790,95 +1775,10 @@ async def test_analyze_content_flattened_error_async(): gcd_participant.AnalyzeContentRequest(), participant="participant_value", text_input=session.TextInput(text="text_value"), - audio_input=gcd_participant.AudioInput( - config=audio_config.InputAudioConfig( - audio_encoding=audio_config.AudioEncoding.AUDIO_ENCODING_LINEAR_16 - ) - ), event_input=session.EventInput(name="name_value"), ) -def test_streaming_analyze_content( - transport: str = "grpc", request_type=participant.StreamingAnalyzeContentRequest -): - client = ParticipantsClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - requests = [request] - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_analyze_content), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = iter([participant.StreamingAnalyzeContentResponse()]) - - response = client.streaming_analyze_content(iter(requests)) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - - assert next(args[0]) == request - - # Establish that the response is the type that we expect. - for message in response: - assert isinstance(message, participant.StreamingAnalyzeContentResponse) - - -def test_streaming_analyze_content_from_dict(): - test_streaming_analyze_content(request_type=dict) - - -@pytest.mark.asyncio -async def test_streaming_analyze_content_async( - transport: str = "grpc_asyncio", - request_type=participant.StreamingAnalyzeContentRequest, -): - client = ParticipantsAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - requests = [request] - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_analyze_content), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = mock.Mock(aio.StreamStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock( - side_effect=[participant.StreamingAnalyzeContentResponse()] - ) - - response = await client.streaming_analyze_content(iter(requests)) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - - assert next(args[0]) == request - - # Establish that the response is the type that we expect. - message = await response.read() - assert isinstance(message, participant.StreamingAnalyzeContentResponse) - - -@pytest.mark.asyncio -async def test_streaming_analyze_content_async_from_dict(): - await test_streaming_analyze_content_async(request_type=dict) - - def test_suggest_articles( transport: str = "grpc", request_type=participant.SuggestArticlesRequest ): @@ -3094,7 +2994,6 @@ def test_participants_base_transport(): "list_participants", "update_participant", "analyze_content", - "streaming_analyze_content", "suggest_articles", "suggest_faq_answers", "suggest_smart_replies",