Reference documentation and code samples for the Google Cloud Dialogflow V2 Client class CompanionAgentsClient.
Service Description: Service for managing companion agents.
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 \ V2 \ ClientMethods
__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 |
Google\Auth\FetchAuthTokenInterface|Google\ApiCore\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 |
↳ 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 |
↳ 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|Google\ApiCore\Transport\TransportInterface
The transport used for executing network requests. May be either the string |
↳ 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|Psr\Log\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'. |
createCompanionAgent
Creates a companion agent.
The async variant is CompanionAgentsClient::createCompanionAgentAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\CreateCompanionAgentRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\Cloud\Dialogflow\V2\CompanionAgent |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
use Google\Cloud\Dialogflow\V2\CompanionAgent;
use Google\Cloud\Dialogflow\V2\CreateCompanionAgentRequest;
/**
* @param string $formattedParent Resource identifier of the project creating the companion agent.
* Format: `projects/{project}/locations/{location}`
* Please see {@see CompanionAgentsClient::locationName()} for help formatting this field.
*/
function create_companion_agent_sample(string $formattedParent): void
{
// Create a client.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$companionAgent = new CompanionAgent();
$request = (new CreateCompanionAgentRequest())
->setParent($formattedParent)
->setCompanionAgent($companionAgent);
// Call the API and handle any network failures.
try {
/** @var CompanionAgent $response */
$response = $companionAgentsClient->createCompanionAgent($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 = CompanionAgentsClient::locationName('[PROJECT]', '[LOCATION]');
create_companion_agent_sample($formattedParent);
}
deleteCompanionAgent
Deletes a companion agent.
The async variant is CompanionAgentsClient::deleteCompanionAgentAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\DeleteCompanionAgentRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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. |
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
use Google\Cloud\Dialogflow\V2\DeleteCompanionAgentRequest;
/**
* @param string $formattedName The unique resource identifier of the CompanionAgent to delete.
* Format:
* `projects/{project}/locations/{location}/companionAgents/{companion_agent}`. Please see
* {@see CompanionAgentsClient::companionAgentName()} for help formatting this field.
*/
function delete_companion_agent_sample(string $formattedName): void
{
// Create a client.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$request = (new DeleteCompanionAgentRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
$companionAgentsClient->deleteCompanionAgent($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 = CompanionAgentsClient::companionAgentName(
'[PROJECT]',
'[LOCATION]',
'[COMPANION_AGENT]'
);
delete_companion_agent_sample($formattedName);
}
getCompanionAgent
Gets a companion agent.
The async variant is CompanionAgentsClient::getCompanionAgentAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\GetCompanionAgentRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\Cloud\Dialogflow\V2\CompanionAgent |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
use Google\Cloud\Dialogflow\V2\CompanionAgent;
use Google\Cloud\Dialogflow\V2\GetCompanionAgentRequest;
/**
* @param string $formattedName The unique resource identifier of the CompanionAgent to get all
* information for. Format:
* `projects/{project}/locations/{location}/companionAgents/{companion_agent}`.
* Contains the information about the {project}, {location}, and
* {companion_agent}. Please see
* {@see CompanionAgentsClient::companionAgentName()} for help formatting this field.
*/
function get_companion_agent_sample(string $formattedName): void
{
// Create a client.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$request = (new GetCompanionAgentRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var CompanionAgent $response */
$response = $companionAgentsClient->getCompanionAgent($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 = CompanionAgentsClient::companionAgentName(
'[PROJECT]',
'[LOCATION]',
'[COMPANION_AGENT]'
);
get_companion_agent_sample($formattedName);
}
listCompanionAgents
Lists companion agents.
The async variant is CompanionAgentsClient::listCompanionAgentsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\ListCompanionAgentsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
use Google\Cloud\Dialogflow\V2\CompanionAgent;
use Google\Cloud\Dialogflow\V2\ListCompanionAgentsRequest;
/**
* @param string $formattedParent The parent resource name to list the companion agents for.
* Format: `projects/{project}/locations/{location}`
* Please see {@see CompanionAgentsClient::locationName()} for help formatting this field.
*/
function list_companion_agents_sample(string $formattedParent): void
{
// Create a client.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$request = (new ListCompanionAgentsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $companionAgentsClient->listCompanionAgents($request);
/** @var CompanionAgent $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 = CompanionAgentsClient::locationName('[PROJECT]', '[LOCATION]');
list_companion_agents_sample($formattedParent);
}
updateCompanionAgent
Updates a companion agent.
The async variant is CompanionAgentsClient::updateCompanionAgentAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\UpdateCompanionAgentRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\Cloud\Dialogflow\V2\CompanionAgent |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
use Google\Cloud\Dialogflow\V2\CompanionAgent;
use Google\Cloud\Dialogflow\V2\UpdateCompanionAgentRequest;
/**
* 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 update_companion_agent_sample(): void
{
// Create a client.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$companionAgent = new CompanionAgent();
$request = (new UpdateCompanionAgentRequest())
->setCompanionAgent($companionAgent);
// Call the API and handle any network failures.
try {
/** @var CompanionAgent $response */
$response = $companionAgentsClient->updateCompanionAgent($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
getLocation
Gets information about a location.
The async variant is CompanionAgentsClient::getLocationAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\Cloud\Location\Location |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
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.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$request = new GetLocationRequest();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $companionAgentsClient->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 CompanionAgentsClient::listLocationsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
Google\ApiCore\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 |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\V2\Client\CompanionAgentsClient;
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.
$companionAgentsClient = new CompanionAgentsClient();
// Prepare the request message.
$request = new ListLocationsRequest();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $companionAgentsClient->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());
}
}
createCompanionAgentAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\CreateCompanionAgentRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Dialogflow\V2\CompanionAgent> |
|
deleteCompanionAgentAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\DeleteCompanionAgentRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
|
getCompanionAgentAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\GetCompanionAgentRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Dialogflow\V2\CompanionAgent> |
|
listCompanionAgentsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\ListCompanionAgentsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
updateCompanionAgentAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Dialogflow\V2\UpdateCompanionAgentRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Dialogflow\V2\CompanionAgent> |
|
getLocationAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Location\Location> |
|
listLocationsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
static::companionAgentName
Formats a string containing the fully-qualified path to represent a companion_agent resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
companionAgent |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted companion_agent resource. |
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted location resource. |
static::toolName
Formats a string containing the fully-qualified path to represent a tool resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
app |
string
|
tool |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted tool resource. |
static::toolsetName
Formats a string containing the fully-qualified path to represent a toolset resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
app |
string
|
toolset |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted toolset 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
- companionAgent: projects/{project}/locations/{location}/companionAgents/{companion_agent}
- location: projects/{project}/locations/{location}
- tool: projects/{project}/locations/{location}/apps/{app}/tools/{tool}
- toolset: projects/{project}/locations/{location}/apps/{app}/toolsets/{toolset}
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. |