Skip to content

Commit

Permalink
feat: [Dialogflow] added conversation process config, ImportDocument …
Browse files Browse the repository at this point in the history
…and SuggestSmartReplies API (#5042)

* feat: added conversation process config, ImportDocument and SuggestSmartReplies API

PiperOrigin-RevId: 423223164

Source-Link: googleapis/googleapis@356f0c0

Source-Link: googleapis/googleapis-gen@72fe020
Copy-Tag: eyJwIjoiRGlhbG9nZmxvdy8uT3dsQm90LnlhbWwiLCJoIjoiNzJmZTAyMDJmNGUzZTkxZmU3YTdhNTJjYTI0ODE3NzI2MWMyY2MzZiJ9

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jan 25, 2022
1 parent 5ff33d8 commit 1e21fa3
Show file tree
Hide file tree
Showing 36 changed files with 1,891 additions and 76 deletions.
Binary file modified Dialogflow/metadata/V2/AudioConfig.php
Binary file not shown.
Binary file modified Dialogflow/metadata/V2/Conversation.php
Binary file not shown.
Binary file modified Dialogflow/metadata/V2/ConversationEvent.php
Binary file not shown.
Binary file modified Dialogflow/metadata/V2/ConversationProfile.php
Binary file not shown.
Binary file modified Dialogflow/metadata/V2/Document.php
Binary file not shown.
9 changes: 6 additions & 3 deletions Dialogflow/metadata/V2/Gcs.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Dialogflow/metadata/V2/HumanAgentAssistantEvent.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Dialogflow/metadata/V2/Participant.php
Binary file not shown.
6 changes: 3 additions & 3 deletions Dialogflow/metadata/V2/Webhook.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Dialogflow/src/V2/DocumentsGrpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ public function CreateDocument(\Google\Cloud\Dialogflow\V2\CreateDocumentRequest
$metadata, $options);
}

/**
* 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](https://cloud.google.com/dialogflow/cx/docs/how/long-running-operation).
* The returned `Operation` type has the following method-specific fields:
*
* - `metadata`: [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata]
* - `response`: [ImportDocumentsResponse][google.cloud.dialogflow.v2.ImportDocumentsResponse]
* @param \Google\Cloud\Dialogflow\V2\ImportDocumentsRequest $argument input argument
* @param array $metadata metadata
* @param array $options call options
* @return \Grpc\UnaryCall
*/
public function ImportDocuments(\Google\Cloud\Dialogflow\V2\ImportDocumentsRequest $argument,
$metadata = [], $options = []) {
return $this->_simpleRequest('/google.cloud.dialogflow.v2.Documents/ImportDocuments',
$argument,
['\Google\LongRunning\Operation', 'decode'],
$metadata, $options);
}

/**
* Deletes the specified document.
*
Expand Down
101 changes: 101 additions & 0 deletions Dialogflow/src/V2/Gapic/DocumentsGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
use Google\Cloud\Dialogflow\V2\Document;
use Google\Cloud\Dialogflow\V2\ExportDocumentRequest;
use Google\Cloud\Dialogflow\V2\GcsDestination;
use Google\Cloud\Dialogflow\V2\GcsSources;
use Google\Cloud\Dialogflow\V2\GetDocumentRequest;
use Google\Cloud\Dialogflow\V2\ImportDocumentsRequest;
use Google\Cloud\Dialogflow\V2\ImportDocumentsResponse;
use Google\Cloud\Dialogflow\V2\ImportDocumentTemplate;
use Google\Cloud\Dialogflow\V2\KnowledgeOperationMetadata;
use Google\Cloud\Dialogflow\V2\ListDocumentsRequest;
use Google\Cloud\Dialogflow\V2\ListDocumentsResponse;
Expand Down Expand Up @@ -773,6 +777,103 @@ public function getDocument($name, array $optionalArgs = [])
return $this->startCall('GetDocument', Document::class, $optionalArgs, $request)->wait();
}

/**
* 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](https://cloud.google.com/dialogflow/cx/docs/how/long-running-operation).
* The returned `Operation` type has the following method-specific fields:
*
* - `metadata`: [KnowledgeOperationMetadata][google.cloud.dialogflow.v2.KnowledgeOperationMetadata]
* - `response`: [ImportDocumentsResponse][google.cloud.dialogflow.v2.ImportDocumentsResponse]
*
* Sample code:
* ```
* $documentsClient = new DocumentsClient();
* try {
* $formattedParent = $documentsClient->knowledgeBaseName('[PROJECT]', '[KNOWLEDGE_BASE]');
* $documentTemplate = new ImportDocumentTemplate();
* $operationResponse = $documentsClient->importDocuments($formattedParent, $documentTemplate);
* $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->importDocuments($formattedParent, $documentTemplate);
* $operationName = $operationResponse->getName();
* // ... do other work
* $newOperationResponse = $documentsClient->resumeOperation($operationName, 'importDocuments');
* 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();
* }
* ```
*
* @param string $parent Required. The knowledge base to import documents into.
* Format: `projects/<Project ID>/locations/<Location
* ID>/knowledgeBases/<Knowledge Base ID>`.
* @param ImportDocumentTemplate $documentTemplate Required. Document template used for importing all the documents.
* @param array $optionalArgs {
* Optional.
*
* @type GcsSources $gcsSource
* The Google Cloud Storage location for the documents.
* The path can include a wildcard.
*
* These URIs may have the forms
* `gs://<bucket-name>/<object-name>`.
* `gs://<bucket-name>/<object-path>/*.<extension>`.
* @type bool $importGcsCustomMetadata
* Whether to import custom metadata from Google Cloud Storage.
* Only valid when the document source is Google Cloud Storage URI.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array of retry
* settings parameters. See the documentation on
* {@see Google\ApiCore\RetrySettings} for example usage.
* }
*
* @return \Google\ApiCore\OperationResponse
*
* @throws ApiException if the remote call fails
*/
public function importDocuments($parent, $documentTemplate, array $optionalArgs = [])
{
$request = new ImportDocumentsRequest();
$requestParamHeaders = [];
$request->setParent($parent);
$request->setDocumentTemplate($documentTemplate);
$requestParamHeaders['parent'] = $parent;
if (isset($optionalArgs['gcsSource'])) {
$request->setGcsSource($optionalArgs['gcsSource']);
}

if (isset($optionalArgs['importGcsCustomMetadata'])) {
$request->setImportGcsCustomMetadata($optionalArgs['importGcsCustomMetadata']);
}

$requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders);
$optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader();
return $this->startOperationsCall('ImportDocuments', $optionalArgs, $request, $this->getOperationsClient())->wait();
}

/**
* Returns the list of all documents of the knowledge base.
*
Expand Down
79 changes: 75 additions & 4 deletions Dialogflow/src/V2/Gapic/ParticipantsGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
use Google\Cloud\Dialogflow\V2\SuggestArticlesResponse;
use Google\Cloud\Dialogflow\V2\SuggestFaqAnswersRequest;
use Google\Cloud\Dialogflow\V2\SuggestFaqAnswersResponse;
use Google\Cloud\Dialogflow\V2\SuggestSmartRepliesRequest;
use Google\Cloud\Dialogflow\V2\SuggestSmartRepliesResponse;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\UpdateParticipantRequest;
use Google\Protobuf\FieldMask;
Expand Down Expand Up @@ -797,13 +799,13 @@ public function listParticipants($parent, array $optionalArgs = [])
* Optional.
*
* @type string $latestMessage
* The name of the latest conversation message to compile suggestion
* Optional. The name of the latest conversation message to compile suggestion
* for. If empty, it will be the latest message of the conversation.
*
* Format: `projects/<Project ID>/locations/<Location
* ID>/conversations/<Conversation ID>/messages/<Message ID>`.
* @type int $contextSize
* Max number of messages prior to and including
* Optional. Max number of messages prior to and including
* [latest_message][google.cloud.dialogflow.v2.SuggestArticlesRequest.latest_message] to use as context
* when compiling the suggestion. By default 20 and at most 50.
* @type AssistQueryParameters $assistQueryParams
Expand Down Expand Up @@ -864,13 +866,13 @@ public function suggestArticles($parent, array $optionalArgs = [])
* Optional.
*
* @type string $latestMessage
* The name of the latest conversation message to compile suggestion
* Optional. The name of the latest conversation message to compile suggestion
* for. If empty, it will be the latest message of the conversation.
*
* Format: `projects/<Project ID>/locations/<Location
* ID>/conversations/<Conversation ID>/messages/<Message ID>`.
* @type int $contextSize
* Max number of messages prior to and including
* Optional. Max number of messages prior to and including
* [latest_message] to use as context when compiling the
* suggestion. By default 20 and at most 50.
* @type AssistQueryParameters $assistQueryParams
Expand Down Expand Up @@ -909,6 +911,75 @@ public function suggestFaqAnswers($parent, array $optionalArgs = [])
return $this->startCall('SuggestFaqAnswers', SuggestFaqAnswersResponse::class, $optionalArgs, $request)->wait();
}

/**
* Gets smart replies for a participant based on specific historical
* messages.
*
* Sample code:
* ```
* $participantsClient = new ParticipantsClient();
* try {
* $formattedParent = $participantsClient->participantName('[PROJECT]', '[CONVERSATION]', '[PARTICIPANT]');
* $response = $participantsClient->suggestSmartReplies($formattedParent);
* } finally {
* $participantsClient->close();
* }
* ```
*
* @param string $parent Required. The name of the participant to fetch suggestion for.
* Format: `projects/<Project ID>/locations/<Location
* ID>/conversations/<Conversation ID>/participants/<Participant ID>`.
* @param array $optionalArgs {
* Optional.
*
* @type TextInput $currentTextInput
* The current natural language text segment to compile suggestion
* for. This provides a way for user to get follow up smart reply suggestion
* after a smart reply selection, without sending a text message.
* @type string $latestMessage
* The name of the latest conversation message to compile suggestion
* for. If empty, it will be the latest message of the conversation.
*
* Format: `projects/<Project ID>/locations/<Location
* ID>/conversations/<Conversation ID>/messages/<Message ID>`.
* @type int $contextSize
* Max number of messages prior to and including
* [latest_message] to use as context when compiling the
* suggestion. By default 20 and at most 50.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\ApiCore\RetrySettings} object, or an associative array of retry
* settings parameters. See the documentation on
* {@see Google\ApiCore\RetrySettings} for example usage.
* }
*
* @return \Google\Cloud\Dialogflow\V2\SuggestSmartRepliesResponse
*
* @throws ApiException if the remote call fails
*/
public function suggestSmartReplies($parent, array $optionalArgs = [])
{
$request = new SuggestSmartRepliesRequest();
$requestParamHeaders = [];
$request->setParent($parent);
$requestParamHeaders['parent'] = $parent;
if (isset($optionalArgs['currentTextInput'])) {
$request->setCurrentTextInput($optionalArgs['currentTextInput']);
}

if (isset($optionalArgs['latestMessage'])) {
$request->setLatestMessage($optionalArgs['latestMessage']);
}

if (isset($optionalArgs['contextSize'])) {
$request->setContextSize($optionalArgs['contextSize']);
}

$requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders);
$optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader();
return $this->startCall('SuggestSmartReplies', SuggestSmartRepliesResponse::class, $optionalArgs, $request)->wait();
}

/**
* Updates the specified participant.
*
Expand Down
75 changes: 75 additions & 0 deletions Dialogflow/src/V2/GcsSources.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e21fa3

Please sign in to comment.