Reference documentation and code samples for the Google Cloud Dialogflow V2 Client class DocumentsClient.
Service Description: Service for managing knowledge Documents.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$documentsClient = new DocumentsClient();
try {
$formattedParent = $documentsClient->knowledgeBaseName('[PROJECT]', '[KNOWLEDGE_BASE]');
$document = new Document();
$operationResponse = $documentsClient->createDocument($formattedParent, $document);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $documentsClient->createDocument($formattedParent, $document);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $documentsClient->resumeOperation($operationName, 'createDocument');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$documentsClient->close();
}
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.
Methods
documentName
Formats a string containing the fully-qualified path to represent a document resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
knowledgeBase |
string
|
document |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted document resource. |
knowledgeBaseName
Formats a string containing the fully-qualified path to represent a knowledge_base resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
knowledgeBase |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted knowledge_base resource. |
projectKnowledgeBaseName
Formats a string containing the fully-qualified path to represent a project_knowledge_base resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
knowledgeBase |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted project_knowledge_base resource. |
projectKnowledgeBaseDocumentName
Formats a string containing the fully-qualified path to represent a project_knowledge_base_document resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
knowledgeBase |
string
|
document |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted project_knowledge_base_document resource. |
projectLocationKnowledgeBaseName
Formats a string containing the fully-qualified path to represent a project_location_knowledge_base resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
knowledgeBase |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted project_location_knowledge_base resource. |
projectLocationKnowledgeBaseDocumentName
Formats a string containing the fully-qualified path to represent a project_location_knowledge_base_document resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
knowledgeBase |
string
|
document |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted project_location_knowledge_base_document resource. |
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
- document: projects/{project}/knowledgeBases/{knowledge_base}/documents/{document}
- knowledgeBase: projects/{project}/knowledgeBases/{knowledge_base}
- projectKnowledgeBase: projects/{project}/knowledgeBases/{knowledge_base}
- projectKnowledgeBaseDocument: projects/{project}/knowledgeBases/{knowledge_base}/documents/{document}
- projectLocationKnowledgeBase: projects/{project}/locations/{location}/knowledgeBases/{knowledge_base}
- projectLocationKnowledgeBaseDocument: projects/{project}/locations/{location}/knowledgeBases/{knowledge_base}/documents/{document}
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. |
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\ApiCore\LongRunning\OperationsClient |
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
Parameters | |
---|---|
Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
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 |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed {@see} object or {@see} object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see {@see} . |
↳ 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|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 {@see} and {@see} 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. |
createDocument
Creates a new document.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: Document
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The knowledge base to create a document for. Format: |
document |
Google\Cloud\Dialogflow\V2\Document
Required. The document to create. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\Document\KnowledgeType;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Rpc\Status;
/**
* @param string $formattedParent The knowledge base to create a document for.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>`. Please see
* {@see DocumentsClient::knowledgeBaseName()} for help formatting this field.
* @param string $documentDisplayName The display name of the document. The name must be 1024 bytes or
* less; otherwise, the creation request fails.
* @param string $documentMimeType The MIME type of this document.
* @param int $documentKnowledgeTypesElement The knowledge type of document content.
*/
function create_document_sample(
string $formattedParent,
string $documentDisplayName,
string $documentMimeType,
int $documentKnowledgeTypesElement
): void {
// Create a client.
$documentsClient = new DocumentsClient();
// Prepare any non-scalar elements to be passed along with the request.
$documentKnowledgeTypes = [$documentKnowledgeTypesElement,];
$document = (new Document())
->setDisplayName($documentDisplayName)
->setMimeType($documentMimeType)
->setKnowledgeTypes($documentKnowledgeTypes);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->createDocument($formattedParent, $document);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Document $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::knowledgeBaseName('[PROJECT]', '[KNOWLEDGE_BASE]');
$documentDisplayName = '[DISPLAY_NAME]';
$documentMimeType = '[MIME_TYPE]';
$documentKnowledgeTypesElement = KnowledgeType::KNOWLEDGE_TYPE_UNSPECIFIED;
create_document_sample(
$formattedParent,
$documentDisplayName,
$documentMimeType,
$documentKnowledgeTypesElement
);
}
deleteDocument
Deletes the specified document.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: An Empty message
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the document to delete. Format: |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the document to delete.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`. Please see
* {@see DocumentsClient::documentName()} for help formatting this field.
*/
function delete_document_sample(string $formattedName): void
{
// Create a client.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->deleteDocument($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::documentName('[PROJECT]', '[KNOWLEDGE_BASE]', '[DOCUMENT]');
delete_document_sample($formattedName);
}
exportDocument
Exports a smart messaging candidate document into the specified destination.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: Document
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the document to export. Format: |
optionalArgs |
array
Optional. |
↳ gcsDestination |
GcsDestination
Cloud Storage file path to export the document. |
↳ exportFullContent |
bool
When enabled, export the full content of the document including empirical probability. |
↳ smartMessagingPartialUpdate |
bool
When enabled, export the smart messaging allowlist document for partial update. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the document to export.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`. Please see
* {@see DocumentsClient::documentName()} for help formatting this field.
*/
function export_document_sample(string $formattedName): void
{
// Create a client.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->exportDocument($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Document $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::documentName('[PROJECT]', '[KNOWLEDGE_BASE]', '[DOCUMENT]');
export_document_sample($formattedName);
}
getDocument
Retrieves the specified document.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the document to retrieve. Format |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Dialogflow\V2\Document |
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
/**
* @param string $formattedName The name of the document to retrieve.
* Format `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`. Please see
* {@see DocumentsClient::documentName()} for help formatting this field.
*/
function get_document_sample(string $formattedName): void
{
// Create a client.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var Document $response */
$response = $documentsClient->getDocument($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::documentName('[PROJECT]', '[KNOWLEDGE_BASE]', '[DOCUMENT]');
get_document_sample($formattedName);
}
importDocuments
Creates documents by importing data from external sources.
Dialogflow supports up to 350 documents in each request. If you try to import more, Dialogflow will return an error.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: ImportDocumentsResponse
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The knowledge base to import documents into. Format: |
documentTemplate |
Google\Cloud\Dialogflow\V2\ImportDocumentTemplate
Required. Document template used for importing all the documents. |
optionalArgs |
array
Optional. |
↳ gcsSource |
GcsSources
The Google Cloud Storage location for the documents. The path can include a wildcard. These URIs may have the forms |
↳ importGcsCustomMetadata |
bool
Whether to import custom metadata from Google Cloud Storage. Only valid when the document source is Google Cloud Storage URI. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\Document\KnowledgeType;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Cloud\Dialogflow\V2\ImportDocumentTemplate;
use Google\Cloud\Dialogflow\V2\ImportDocumentsResponse;
use Google\Rpc\Status;
/**
* @param string $formattedParent The knowledge base to import documents into.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>`. Please see
* {@see DocumentsClient::knowledgeBaseName()} for help formatting this field.
* @param string $documentTemplateMimeType The MIME type of the document.
* @param int $documentTemplateKnowledgeTypesElement The knowledge type of document content.
*/
function import_documents_sample(
string $formattedParent,
string $documentTemplateMimeType,
int $documentTemplateKnowledgeTypesElement
): void {
// Create a client.
$documentsClient = new DocumentsClient();
// Prepare any non-scalar elements to be passed along with the request.
$documentTemplateKnowledgeTypes = [$documentTemplateKnowledgeTypesElement,];
$documentTemplate = (new ImportDocumentTemplate())
->setMimeType($documentTemplateMimeType)
->setKnowledgeTypes($documentTemplateKnowledgeTypes);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->importDocuments($formattedParent, $documentTemplate);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var ImportDocumentsResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::knowledgeBaseName('[PROJECT]', '[KNOWLEDGE_BASE]');
$documentTemplateMimeType = '[MIME_TYPE]';
$documentTemplateKnowledgeTypesElement = KnowledgeType::KNOWLEDGE_TYPE_UNSPECIFIED;
import_documents_sample(
$formattedParent,
$documentTemplateMimeType,
$documentTemplateKnowledgeTypesElement
);
}
listDocuments
Returns the list of all documents of the knowledge base.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The knowledge base to list all documents for. Format: |
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ filter |
string
The filter expression used to filter documents returned by the list method. The expression has the following syntax:
|
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
/**
* @param string $formattedParent The knowledge base to list all documents for.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>`. Please see
* {@see DocumentsClient::knowledgeBaseName()} for help formatting this field.
*/
function list_documents_sample(string $formattedParent): void
{
// Create a client.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $documentsClient->listDocuments($formattedParent);
/** @var Document $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());
}
}
/**
* 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 = DocumentsClient::knowledgeBaseName('[PROJECT]', '[KNOWLEDGE_BASE]');
list_documents_sample($formattedParent);
}
reloadDocument
Reloads the specified document from its specified source, content_uri or content. The previously loaded content of the document will be deleted.
Note: Even when the content of the document has not changed, there still may be side effects because of internal implementation changes.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: Document
Note: The projects.agent.knowledgeBases.documents
resource is deprecated;
only use projects.knowledgeBases.documents
.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the document to reload. Format: |
optionalArgs |
array
Optional. |
↳ contentUri |
string
Optional. The path of gcs source file for reloading document content. For now, only gcs uri is supported. For documents stored in Google Cloud Storage, these URIs must have the form |
↳ importGcsCustomMetadata |
bool
Optional. Whether to import custom metadata from Google Cloud Storage. Only valid when the document source is Google Cloud Storage URI. |
↳ smartMessagingPartialUpdate |
bool
Optional. When enabled, the reload request is to apply partial update to the smart messaging allowlist. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the document to reload.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`
* Please see {@see DocumentsClient::documentName()} for help formatting this field.
*/
function reload_document_sample(string $formattedName): void
{
// Create a client.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->reloadDocument($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Document $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 = DocumentsClient::documentName('[PROJECT]', '[KNOWLEDGE_BASE]', '[DOCUMENT]');
reload_document_sample($formattedName);
}
updateDocument
Updates the specified document.
This method is a long-running
operation.
The returned Operation
type has the following method-specific fields:
metadata
: KnowledgeOperationMetadataresponse
: Document
Parameters | |
---|---|
Name | Description |
document |
Google\Cloud\Dialogflow\V2\Document
Required. The document to update. |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
Optional. Not specified means |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\Document\KnowledgeType;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
use Google\Rpc\Status;
/**
* @param string $documentDisplayName The display name of the document. The name must be 1024 bytes or
* less; otherwise, the creation request fails.
* @param string $documentMimeType The MIME type of this document.
* @param int $documentKnowledgeTypesElement The knowledge type of document content.
*/
function update_document_sample(
string $documentDisplayName,
string $documentMimeType,
int $documentKnowledgeTypesElement
): void {
// Create a client.
$documentsClient = new DocumentsClient();
// Prepare any non-scalar elements to be passed along with the request.
$documentKnowledgeTypes = [$documentKnowledgeTypesElement,];
$document = (new Document())
->setDisplayName($documentDisplayName)
->setMimeType($documentMimeType)
->setKnowledgeTypes($documentKnowledgeTypes);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $documentsClient->updateDocument($document);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Document $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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
{
$documentDisplayName = '[DISPLAY_NAME]';
$documentMimeType = '[MIME_TYPE]';
$documentKnowledgeTypesElement = KnowledgeType::KNOWLEDGE_TYPE_UNSPECIFIED;
update_document_sample($documentDisplayName, $documentMimeType, $documentKnowledgeTypesElement);
}
getLocation
Gets information about a location.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
Resource name for the location. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Location\Location |
use Google\ApiCore\ApiException;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
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.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $documentsClient->getLocation();
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.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
The resource that owns the locations collection, if applicable. |
↳ filter |
string
The standard list filter. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Dialogflow\V2\DocumentsClient;
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.
$documentsClient = new DocumentsClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $documentsClient->listLocations();
/** @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());
}
}
Constants
SERVICE_NAME
Value: 'google.cloud.dialogflow.v2.Documents'
The name of the service.
SERVICE_ADDRESS
Value: 'dialogflow.googleapis.com'
The default address of the service.
DEFAULT_SERVICE_PORT
Value: 443
The default port of the service.
CODEGEN_NAME
Value: 'gapic'
The name of the code generator, to be included in the agent header.