Google Cloud Dialogflow Cx V3 Client - Class ExamplesClient (0.11.0)

Reference documentation and code samples for the Google Cloud Dialogflow Cx V3 Client class ExamplesClient.

Service Description: Service for managing Examples .

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Cloud \ Dialogflow \ Cx \ V3 \ Client

Methods

__construct

Constructor.

Parameters
Name
Description
options
array| Google\ApiCore\Options\ClientOptions

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint
string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials
FetchAuthTokenInterface|CredentialsWrapper

This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Cloud\Dialogflow\Cx\V3\ExamplesClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new ExamplesClient(['credentials' => $creds]); https://cloud.google.com/docs/authentication/external/externally-sourced-credentials

↳ credentialsConfig
array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries
bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false .

↳ clientConfig
string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport
string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc . Defaults to grpc if gRPC support is detected on the system. Advanced usage : Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig
array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource
callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

↳ logger
false|LoggerInterface

A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag

↳ universeDomain
string

The service domain for the client. Defaults to 'googleapis.com'.

createExample

Creates an example in the specified playbook.

The async variant is ExamplesClient::createExampleAsync() .

Parameters
Name
Description
request
Google\Cloud\Dialogflow\Cx\V3\CreateExampleRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\Cx\V3\Action;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Dialogflow\Cx\V3\CreateExampleRequest;
use Google\Cloud\Dialogflow\Cx\V3\Example;
use Google\Cloud\Dialogflow\Cx\V3\OutputState;

/**
 * @param string $formattedParent          The playbook to create an example for.
 *                                         Format:
 *                                         `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/playbooks/<PlaybookID>`. Please see
 *                                         {@see ExamplesClient::playbookName()} for help formatting this field.
 * @param string $exampleDisplayName       The display name of the example.
 * @param int    $exampleConversationState Example's output state.
 */
function create_example_sample(
    string $formattedParent,
    string $exampleDisplayName,
    int $exampleConversationState
): void {
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $exampleActions = [new Action()];
    $example = (new Example())
        ->setActions($exampleActions)
        ->setDisplayName($exampleDisplayName)
        ->setConversationState($exampleConversationState);
    $request = (new CreateExampleRequest())
        ->setParent($formattedParent)
        ->setExample($example);

    // Call the API and handle any network failures.
    try {
        /** @var Example $response */
        $response = $examplesClient->createExample($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ExamplesClient::playbookName('[PROJECT]', '[LOCATION]', '[AGENT]', '[PLAYBOOK]');
    $exampleDisplayName = '[DISPLAY_NAME]';
    $exampleConversationState = OutputState::OUTPUT_STATE_UNSPECIFIED;

    create_example_sample($formattedParent, $exampleDisplayName, $exampleConversationState);
} 

deleteExample

Deletes the specified example.

The async variant is ExamplesClient::deleteExampleAsync() .

Parameters
Name
Description
request
Google\Cloud\Dialogflow\Cx\V3\DeleteExampleRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
 use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Dialogflow\Cx\V3\DeleteExampleRequest;

/**
 * @param string $formattedName The name of the example to delete.
 *                              Format:
 *                              `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/playbooks/<PlaybookID>/examples/<ExampleID>`. Please see
 *                              {@see ExamplesClient::exampleName()} for help formatting this field.
 */
function delete_example_sample(string $formattedName): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $request = (new DeleteExampleRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $examplesClient->deleteExample($request);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ExamplesClient::exampleName(
        '[PROJECT]',
        '[LOCATION]',
        '[AGENT]',
        '[PLAYBOOK]',
        '[EXAMPLE]'
    );

    delete_example_sample($formattedName);
} 

getExample

Retrieves the specified example.

The async variant is ExamplesClient::getExampleAsync() .

Parameters
Name
Description
request
Google\Cloud\Dialogflow\Cx\V3\GetExampleRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Dialogflow\Cx\V3\Example;
use Google\Cloud\Dialogflow\Cx\V3\GetExampleRequest;

/**
 * @param string $formattedName The name of the example.
 *                              Format:
 *                              `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/playbooks/<PlaybookID>/examples/<ExampleID>`. Please see
 *                              {@see ExamplesClient::exampleName()} for help formatting this field.
 */
function get_example_sample(string $formattedName): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $request = (new GetExampleRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Example $response */
        $response = $examplesClient->getExample($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ExamplesClient::exampleName(
        '[PROJECT]',
        '[LOCATION]',
        '[AGENT]',
        '[PLAYBOOK]',
        '[EXAMPLE]'
    );

    get_example_sample($formattedName);
} 

listExamples

Returns a list of examples in the specified playbook.

The async variant is ExamplesClient::listExamplesAsync() .

Parameters
Name
Description
request
Google\Cloud\Dialogflow\Cx\V3\ListExamplesRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Dialogflow\Cx\V3\Example;
use Google\Cloud\Dialogflow\Cx\V3\ListExamplesRequest;

/**
 * @param string $formattedParent The playbook to list the examples from.
 *                                Format:
 *                                `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/playbooks/<PlaybookID>`. Please see
 *                                {@see ExamplesClient::playbookName()} for help formatting this field.
 */
function list_examples_sample(string $formattedParent): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $request = (new ListExamplesRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $examplesClient->listExamples($request);

        /** @var Example $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ExamplesClient::playbookName('[PROJECT]', '[LOCATION]', '[AGENT]', '[PLAYBOOK]');

    list_examples_sample($formattedParent);
} 

updateExample

Update the specified example.

The async variant is ExamplesClient::updateExampleAsync() .

Parameters
Name
Description
request
Google\Cloud\Dialogflow\Cx\V3\UpdateExampleRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\Cx\V3\Action;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Dialogflow\Cx\V3\Example;
use Google\Cloud\Dialogflow\Cx\V3\OutputState;
use Google\Cloud\Dialogflow\Cx\V3\UpdateExampleRequest;

/**
 * @param string $exampleDisplayName       The display name of the example.
 * @param int    $exampleConversationState Example's output state.
 */
function update_example_sample(string $exampleDisplayName, int $exampleConversationState): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $exampleActions = [new Action()];
    $example = (new Example())
        ->setActions($exampleActions)
        ->setDisplayName($exampleDisplayName)
        ->setConversationState($exampleConversationState);
    $request = (new UpdateExampleRequest())
        ->setExample($example);

    // Call the API and handle any network failures.
    try {
        /** @var Example $response */
        $response = $examplesClient->updateExample($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $exampleDisplayName = '[DISPLAY_NAME]';
    $exampleConversationState = OutputState::OUTPUT_STATE_UNSPECIFIED;

    update_example_sample($exampleDisplayName, $exampleConversationState);
} 

getLocation

Gets information about a location.

The async variant is ExamplesClient::getLocationAsync() .

Parameters
Name
Description
request
Google\Cloud\Location\GetLocationRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function get_location_sample(): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $request = new GetLocationRequest();

    // Call the API and handle any network failures.
    try {
        /** @var Location $response */
        $response = $examplesClient->getLocation($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
} 

listLocations

Lists information about the supported locations for this service.

This method lists locations based on the resource scope provided in the [ListLocationsRequest.name] field:

Global locations: If name is empty, the method lists the public locations available to all projects. * Project-specific locations: If name follows the format projects/{project} , the method lists locations visible to that specific project. This includes public, private, or other project-specific locations enabled for the project.

For gRPC and client library implementations, the resource name is passed as the name field. For direct service calls, the resource name is incorporated into the request path based on the specific service implementation and version.

The async variant is ExamplesClient::listLocationsAsync() .

Parameters
Name
Description
request
Google\Cloud\Location\ListLocationsRequest

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type
Description
Example
 use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\Cx\V3\Client\ExamplesClient;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function list_locations_sample(): void
{
    // Create a client.
    $examplesClient = new ExamplesClient();

    // Prepare the request message.
    $request = new ListLocationsRequest();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $examplesClient->listLocations($request);

        /** @var Location $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
} 

createExampleAsync

Parameters
Name
Description
optionalArgs
array

deleteExampleAsync

Parameters
Name
Description
optionalArgs
array
Returns
Type
Description

getExampleAsync

Parameters
Name
Description
optionalArgs
array

listExamplesAsync

Parameters
Name
Description
optionalArgs
array

updateExampleAsync

Parameters
Name
Description
optionalArgs
array

getLocationAsync

Parameters
Name
Description
optionalArgs
array

listLocationsAsync

Parameters
Name
Description
optionalArgs
array

static::exampleName

Formats a string containing the fully-qualified path to represent a example resource.

Parameters
Name
Description
project
string
location
string
agent
string
playbook
string
example
string
Returns
Type
Description
string
The formatted example resource.

static::flowName

Formats a string containing the fully-qualified path to represent a flow resource.

Parameters
Name
Description
project
string
location
string
agent
string
flow
string
Returns
Type
Description
string
The formatted flow resource.

static::playbookName

Formats a string containing the fully-qualified path to represent a playbook resource.

Parameters
Name
Description
project
string
location
string
agent
string
playbook
string
Returns
Type
Description
string
The formatted playbook resource.

static::toolName

Formats a string containing the fully-qualified path to represent a tool resource.

Parameters
Name
Description
project
string
location
string
agent
string
tool
string
Returns
Type
Description
string
The formatted tool resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • example: projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}/examples/{example}
  • flow: projects/{project}/locations/{location}/agents/{agent}/flows/{flow}
  • playbook: projects/{project}/locations/{location}/agents/{agent}/playbooks/{playbook}
  • tool: projects/{project}/locations/{location}/agents/{agent}/tools/{tool}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name
Description
formattedName
string

The formatted name string

template
?string

Optional name of template to match

Returns
Type
Description
array
An associative array from name component IDs to component values.
Create a Mobile Website
View Site in Mobile | Classic
Share by: