Example #1
0
    async def batch_update_intents(
        self,
        request: intent.BatchUpdateIntentsRequest = None,
        *,
        parent: str = None,
        intent_batch_uri: str = None,
        intent_batch_inline: intent.IntentBatch = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> operation_async.AsyncOperation:
        r"""Updates/Creates multiple intents in the specified agent.

        Operation <response:
        [BatchUpdateIntentsResponse][google.cloud.dialogflow.v2.BatchUpdateIntentsResponse]>

        Args:
            request (:class:`google.cloud.dialogflow_v2.types.BatchUpdateIntentsRequest`):
                The request object.
            parent (:class:`str`):
                Required. The name of the agent to update or create
                intents in. Format: ``projects/<Project ID>/agent``.

                This corresponds to the ``parent`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            intent_batch_uri (:class:`str`):
                The URI to a Google Cloud Storage
                file containing intents to update or
                create. The file format can either be a
                serialized proto (of IntentBatch type)
                or JSON object. Note: The URI must start
                with "gs://".

                This corresponds to the ``intent_batch_uri`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            intent_batch_inline (:class:`google.cloud.dialogflow_v2.types.IntentBatch`):
                The collection of intents to update
                or create.

                This corresponds to the ``intent_batch_inline`` 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.api_core.operation_async.AsyncOperation:
                An object representing a long-running operation.

                The result type for the operation will be
                :class:`google.cloud.dialogflow_v2.types.BatchUpdateIntentsResponse`
                The response message for
                [Intents.BatchUpdateIntents][google.cloud.dialogflow.v2.Intents.BatchUpdateIntents].

        """
        # 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, intent_batch_uri, intent_batch_inline])
        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 = intent.BatchUpdateIntentsRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.
        if parent is not None:
            request.parent = parent
        if intent_batch_uri is not None:
            request.intent_batch_uri = intent_batch_uri
        if intent_batch_inline is not None:
            request.intent_batch_inline = intent_batch_inline

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.batch_update_intents,
            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,
        )

        # Wrap the response in an operation future.
        response = operation_async.from_gapic(
            response,
            self._client._transport.operations_client,
            intent.BatchUpdateIntentsResponse,
            metadata_type=struct_pb2.Struct,
        )

        # Done; return the response.
        return response
    async def batch_update_intents(
        self,
        request: Union[intent.BatchUpdateIntentsRequest, dict] = None,
        *,
        parent: str = None,
        intent_batch_uri: str = None,
        intent_batch_inline: intent.IntentBatch = None,
        retry: OptionalRetry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> operation_async.AsyncOperation:
        r"""Updates/Creates multiple intents in the specified agent.

        This method is a `long-running
        operation <https://cloud.google.com/dialogflow/es/docs/how/long-running-operations>`__.
        The returned ``Operation`` type has the following
        method-specific fields:

        -  ``metadata``: An empty `Struct
           message <https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#struct>`__
        -  ``response``:
           [BatchUpdateIntentsResponse][google.cloud.dialogflow.v2.BatchUpdateIntentsResponse]

        Note: You should always train an agent prior to sending it
        queries. See the `training
        documentation <https://cloud.google.com/dialogflow/es/docs/training>`__.

        .. code-block:: python

            from google.cloud import dialogflow_v2

            async def sample_batch_update_intents():
                # Create a client
                client = dialogflow_v2.IntentsAsyncClient()

                # Initialize request argument(s)
                request = dialogflow_v2.BatchUpdateIntentsRequest(
                    intent_batch_uri="intent_batch_uri_value",
                    parent="parent_value",
                )

                # Make the request
                operation = client.batch_update_intents(request=request)

                print("Waiting for operation to complete...")

                response = await operation.result()

                # Handle the response
                print(response)

        Args:
            request (Union[google.cloud.dialogflow_v2.types.BatchUpdateIntentsRequest, dict]):
                The request object.
            parent (:class:`str`):
                Required. The name of the agent to update or create
                intents in. Format: ``projects/<Project ID>/agent``.

                This corresponds to the ``parent`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            intent_batch_uri (:class:`str`):
                The URI to a Google Cloud Storage
                file containing intents to update or
                create. The file format can either be a
                serialized proto (of IntentBatch type)
                or JSON object. Note: The URI must start
                with "gs://".

                This corresponds to the ``intent_batch_uri`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            intent_batch_inline (:class:`google.cloud.dialogflow_v2.types.IntentBatch`):
                The collection of intents to update
                or create.

                This corresponds to the ``intent_batch_inline`` 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.api_core.operation_async.AsyncOperation:
                An object representing a long-running operation.

                The result type for the operation will be
                :class:`google.cloud.dialogflow_v2.types.BatchUpdateIntentsResponse`
                The response message for
                [Intents.BatchUpdateIntents][google.cloud.dialogflow.v2.Intents.BatchUpdateIntents].

        """
        # Create or coerce a protobuf request object.
        # Quick 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, intent_batch_uri, intent_batch_inline])
        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 = intent.BatchUpdateIntentsRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.
        if parent is not None:
            request.parent = parent
        if intent_batch_uri is not None:
            request.intent_batch_uri = intent_batch_uri
        if intent_batch_inline is not None:
            request.intent_batch_inline = intent_batch_inline

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.batch_update_intents,
            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,
        )

        # Wrap the response in an operation future.
        response = operation_async.from_gapic(
            response,
            self._client._transport.operations_client,
            intent.BatchUpdateIntentsResponse,
            metadata_type=struct_pb2.Struct,
        )

        # Done; return the response.
        return response