diff --git a/dialogflow/composer.json b/dialogflow/composer.json index 9a81dd9b96..d1c953d360 100644 --- a/dialogflow/composer.json +++ b/dialogflow/composer.json @@ -1,6 +1,6 @@ { "require": { - "google/cloud-dialogflow": "^1.0", + "google/cloud-dialogflow": "^1.10", "symfony/console": "^5.0" }, "autoload": { diff --git a/dialogflow/dialogflow.php b/dialogflow/dialogflow.php index 1dc5413593..e566aa5911 100644 --- a/dialogflow/dialogflow.php +++ b/dialogflow/dialogflow.php @@ -17,12 +17,12 @@ namespace Google\Cloud\Samples\Dialogflow; +use Google\Cloud\Dialogflow\V2\EntityType\Kind; +use Google\Cloud\Dialogflow\V2\SessionEntityType\EntityOverrideMode; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use Google\Cloud\Dialogflow\V2\EntityType\Kind; -use Google\Cloud\Dialogflow\V2\SessionEntityType\EntityOverrideMode; # includes the autoloader for libraries installed with composer require __DIR__ . '/vendor/autoload.php'; diff --git a/dialogflow/src/context_create.php b/dialogflow/src/context_create.php index 4e25283a9b..1e36572da6 100644 --- a/dialogflow/src/context_create.php +++ b/dialogflow/src/context_create.php @@ -18,8 +18,9 @@ // [START dialogflow_create_context] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\ContextsClient; +use Google\Cloud\Dialogflow\V2\Client\ContextsClient; use Google\Cloud\Dialogflow\V2\Context; +use Google\Cloud\Dialogflow\V2\CreateContextRequest; function context_create($projectId, $contextId, $sessionId, $lifespan = 1) { @@ -33,7 +34,10 @@ function context_create($projectId, $contextId, $sessionId, $lifespan = 1) $context->setLifespanCount($lifespan); // create context - $response = $contextsClient->createContext($parent, $context); + $createContextRequest = (new CreateContextRequest()) + ->setParent($parent) + ->setContext($context); + $response = $contextsClient->createContext($createContextRequest); printf('Context created: %s' . PHP_EOL, $response->getName()); $contextsClient->close(); diff --git a/dialogflow/src/context_delete.php b/dialogflow/src/context_delete.php index 5e49d1e3a7..412f7e8d7b 100644 --- a/dialogflow/src/context_delete.php +++ b/dialogflow/src/context_delete.php @@ -18,7 +18,8 @@ // [START dialogflow_delete_context] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\ContextsClient; +use Google\Cloud\Dialogflow\V2\Client\ContextsClient; +use Google\Cloud\Dialogflow\V2\DeleteContextRequest; function context_delete($projectId, $contextId, $sessionId) { @@ -26,7 +27,9 @@ function context_delete($projectId, $contextId, $sessionId) $contextName = $contextsClient->contextName($projectId, $sessionId, $contextId); - $contextsClient->deleteContext($contextName); + $deleteContextRequest = (new DeleteContextRequest()) + ->setName($contextName); + $contextsClient->deleteContext($deleteContextRequest); printf('Context deleted: %s' . PHP_EOL, $contextName); $contextsClient->close(); diff --git a/dialogflow/src/context_list.php b/dialogflow/src/context_list.php index 8fb2d29219..dbbd277433 100644 --- a/dialogflow/src/context_list.php +++ b/dialogflow/src/context_list.php @@ -18,14 +18,17 @@ // [START dialogflow_list_contexts] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\ContextsClient; +use Google\Cloud\Dialogflow\V2\Client\ContextsClient; +use Google\Cloud\Dialogflow\V2\ListContextsRequest; function context_list($projectId, $sessionId) { // get contexts $contextsClient = new ContextsClient(); $parent = $contextsClient->sessionName($projectId, $sessionId); - $contexts = $contextsClient->listContexts($parent); + $listContextsRequest = (new ListContextsRequest()) + ->setParent($parent); + $contexts = $contextsClient->listContexts($listContextsRequest); printf('Contexts for session %s' . PHP_EOL, $parent); foreach ($contexts->iterateAllElements() as $context) { diff --git a/dialogflow/src/detect_intent_audio.php b/dialogflow/src/detect_intent_audio.php index caffa0cd14..d100287ea7 100644 --- a/dialogflow/src/detect_intent_audio.php +++ b/dialogflow/src/detect_intent_audio.php @@ -18,8 +18,9 @@ // [START dialogflow_detect_intent_audio] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionsClient; use Google\Cloud\Dialogflow\V2\AudioEncoding; +use Google\Cloud\Dialogflow\V2\Client\SessionsClient; +use Google\Cloud\Dialogflow\V2\DetectIntentRequest; use Google\Cloud\Dialogflow\V2\InputAudioConfig; use Google\Cloud\Dialogflow\V2\QueryInput; @@ -49,7 +50,11 @@ function detect_intent_audio($projectId, $path, $sessionId, $languageCode = 'en- $queryInput->setAudioConfig($audioConfig); // get response and relevant info - $response = $sessionsClient->detectIntent($session, $queryInput, ['inputAudio' => $inputAudio]); + $detectIntentRequest = (new DetectIntentRequest()) + ->setSession($session) + ->setQueryInput($queryInput) + ->setInputAudio($inputAudio); + $response = $sessionsClient->detectIntent($detectIntentRequest); $queryResult = $response->getQueryResult(); $queryText = $queryResult->getQueryText(); $intent = $queryResult->getIntent(); diff --git a/dialogflow/src/detect_intent_stream.php b/dialogflow/src/detect_intent_stream.php index 13ab259b54..932f94b7e6 100644 --- a/dialogflow/src/detect_intent_stream.php +++ b/dialogflow/src/detect_intent_stream.php @@ -18,8 +18,8 @@ // [START dialogflow_detect_intent_streaming] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionsClient; use Google\Cloud\Dialogflow\V2\AudioEncoding; +use Google\Cloud\Dialogflow\V2\Client\SessionsClient; use Google\Cloud\Dialogflow\V2\InputAudioConfig; use Google\Cloud\Dialogflow\V2\QueryInput; use Google\Cloud\Dialogflow\V2\StreamingDetectIntentRequest; diff --git a/dialogflow/src/detect_intent_texts.php b/dialogflow/src/detect_intent_texts.php index 91b165f197..35e0019e92 100644 --- a/dialogflow/src/detect_intent_texts.php +++ b/dialogflow/src/detect_intent_texts.php @@ -18,9 +18,10 @@ // [START dialogflow_detect_intent_text] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionsClient; -use Google\Cloud\Dialogflow\V2\TextInput; +use Google\Cloud\Dialogflow\V2\Client\SessionsClient; +use Google\Cloud\Dialogflow\V2\DetectIntentRequest; use Google\Cloud\Dialogflow\V2\QueryInput; +use Google\Cloud\Dialogflow\V2\TextInput; /** * Returns the result of detect intent with texts as inputs. @@ -46,7 +47,10 @@ function detect_intent_texts($projectId, $texts, $sessionId, $languageCode = 'en $queryInput->setText($textInput); // get response and relevant info - $response = $sessionsClient->detectIntent($session, $queryInput); + $detectIntentRequest = (new DetectIntentRequest()) + ->setSession($session) + ->setQueryInput($queryInput); + $response = $sessionsClient->detectIntent($detectIntentRequest); $queryResult = $response->getQueryResult(); $queryText = $queryResult->getQueryText(); $intent = $queryResult->getIntent(); diff --git a/dialogflow/src/entity_create.php b/dialogflow/src/entity_create.php index 1ebd717318..8a7de9db7a 100644 --- a/dialogflow/src/entity_create.php +++ b/dialogflow/src/entity_create.php @@ -18,7 +18,8 @@ // [START dialogflow_create_entity] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\BatchCreateEntitiesRequest; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; use Google\Cloud\Dialogflow\V2\EntityType\Entity; /** @@ -42,7 +43,10 @@ function entity_create($projectId, $entityTypeId, $entityValue, $synonyms = []) $entity->setSynonyms($synonyms); // create entity - $response = $entityTypesClient->batchCreateEntities($parent, [$entity]); + $batchCreateEntitiesRequest = (new BatchCreateEntitiesRequest()) + ->setParent($parent) + ->setEntities([$entity]); + $response = $entityTypesClient->batchCreateEntities($batchCreateEntitiesRequest); printf('Entity created: %s' . PHP_EOL, $response->getName()); $entityTypesClient->close(); diff --git a/dialogflow/src/entity_delete.php b/dialogflow/src/entity_delete.php index e113bd69d0..e5b5580056 100644 --- a/dialogflow/src/entity_delete.php +++ b/dialogflow/src/entity_delete.php @@ -18,7 +18,8 @@ // [START dialogflow_delete_entity] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\BatchDeleteEntitiesRequest; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; /** * Delete entity with the given entity type and entity value. @@ -29,7 +30,10 @@ function entity_delete($projectId, $entityTypeId, $entityValue) $parent = $entityTypesClient->entityTypeName($projectId, $entityTypeId); - $entityTypesClient->batchDeleteEntities($parent, [$entityValue]); + $batchDeleteEntitiesRequest = (new BatchDeleteEntitiesRequest()) + ->setParent($parent) + ->setEntityValues([$entityValue]); + $entityTypesClient->batchDeleteEntities($batchDeleteEntitiesRequest); printf('Entity deleted: %s' . PHP_EOL, $entityValue); $entityTypesClient->close(); diff --git a/dialogflow/src/entity_list.php b/dialogflow/src/entity_list.php index 6a9b13caff..dfef0c0c23 100644 --- a/dialogflow/src/entity_list.php +++ b/dialogflow/src/entity_list.php @@ -18,7 +18,8 @@ // [START dialogflow_list_entities] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\GetEntityTypeRequest; function entity_list($projectId, $entityTypeId) { @@ -27,7 +28,9 @@ function entity_list($projectId, $entityTypeId) // prepare $parent = $entityTypesClient->entityTypeName($projectId, $entityTypeId); - $entityType = $entityTypesClient->getEntityType($parent); + $getEntityTypeRequest = (new GetEntityTypeRequest()) + ->setName($parent); + $entityType = $entityTypesClient->getEntityType($getEntityTypeRequest); // get entities $entities = $entityType->getEntities(); diff --git a/dialogflow/src/entity_type_create.php b/dialogflow/src/entity_type_create.php index ee3841d1c7..dfc69fd087 100644 --- a/dialogflow/src/entity_type_create.php +++ b/dialogflow/src/entity_type_create.php @@ -18,7 +18,8 @@ // [START dialogflow_create_entity_type] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\CreateEntityTypeRequest; use Google\Cloud\Dialogflow\V2\EntityType; use Google\Cloud\Dialogflow\V2\EntityType\Kind; @@ -36,7 +37,10 @@ function entity_type_create($projectId, $displayName, $kind = Kind::KIND_MAP) $entityType->setKind($kind); // create entity type - $response = $entityTypesClient->createEntityType($parent, $entityType); + $createEntityTypeRequest = (new CreateEntityTypeRequest()) + ->setParent($parent) + ->setEntityType($entityType); + $response = $entityTypesClient->createEntityType($createEntityTypeRequest); printf('Entity type created: %s' . PHP_EOL, $response->getName()); $entityTypesClient->close(); diff --git a/dialogflow/src/entity_type_delete.php b/dialogflow/src/entity_type_delete.php index 996f467b80..62e5210c28 100644 --- a/dialogflow/src/entity_type_delete.php +++ b/dialogflow/src/entity_type_delete.php @@ -18,7 +18,8 @@ // [START dialogflow_delete_entity_type] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\DeleteEntityTypeRequest; /** * Delete entity type with the given entity type name. @@ -29,7 +30,9 @@ function entity_type_delete($projectId, $entityTypeId) $parent = $entityTypesClient->entityTypeName($projectId, $entityTypeId); - $entityTypesClient->deleteEntityType($parent); + $deleteEntityTypeRequest = (new DeleteEntityTypeRequest()) + ->setName($parent); + $entityTypesClient->deleteEntityType($deleteEntityTypeRequest); printf('Entity type deleted: %s' . PHP_EOL, $parent); $entityTypesClient->close(); diff --git a/dialogflow/src/entity_type_list.php b/dialogflow/src/entity_type_list.php index 3363bba43c..b7244bd0ae 100644 --- a/dialogflow/src/entity_type_list.php +++ b/dialogflow/src/entity_type_list.php @@ -18,14 +18,17 @@ // [START dialogflow_list_entity_types] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\EntityTypesClient; +use Google\Cloud\Dialogflow\V2\ListEntityTypesRequest; function entity_type_list($projectId) { // get entity types $entityTypesClient = new EntityTypesClient(); $parent = $entityTypesClient->agentName($projectId); - $entityTypes = $entityTypesClient->listEntityTypes($parent); + $listEntityTypesRequest = (new ListEntityTypesRequest()) + ->setParent($parent); + $entityTypes = $entityTypesClient->listEntityTypes($listEntityTypesRequest); foreach ($entityTypes->iterateAllElements() as $entityType) { // print relevant info diff --git a/dialogflow/src/intent_create.php b/dialogflow/src/intent_create.php index 78d5e89779..8afd07624b 100644 --- a/dialogflow/src/intent_create.php +++ b/dialogflow/src/intent_create.php @@ -18,12 +18,13 @@ // [START dialogflow_create_intent] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\IntentsClient; -use Google\Cloud\Dialogflow\V2\Intent\TrainingPhrase\Part; -use Google\Cloud\Dialogflow\V2\Intent\TrainingPhrase; -use Google\Cloud\Dialogflow\V2\Intent\Message\Text; -use Google\Cloud\Dialogflow\V2\Intent\Message; +use Google\Cloud\Dialogflow\V2\Client\IntentsClient; +use Google\Cloud\Dialogflow\V2\CreateIntentRequest; use Google\Cloud\Dialogflow\V2\Intent; +use Google\Cloud\Dialogflow\V2\Intent\Message; +use Google\Cloud\Dialogflow\V2\Intent\Message\Text; +use Google\Cloud\Dialogflow\V2\Intent\TrainingPhrase; +use Google\Cloud\Dialogflow\V2\Intent\TrainingPhrase\Part; /** * Create an intent of the given intent type. @@ -61,7 +62,10 @@ function intent_create($projectId, $displayName, $trainingPhraseParts = [], ->setMessages([$message]); // create intent - $response = $intentsClient->createIntent($parent, $intent); + $createIntentRequest = (new CreateIntentRequest()) + ->setParent($parent) + ->setIntent($intent); + $response = $intentsClient->createIntent($createIntentRequest); printf('Intent created: %s' . PHP_EOL, $response->getName()); $intentsClient->close(); diff --git a/dialogflow/src/intent_delete.php b/dialogflow/src/intent_delete.php index 300bc25437..c9c3ed34bd 100644 --- a/dialogflow/src/intent_delete.php +++ b/dialogflow/src/intent_delete.php @@ -18,7 +18,8 @@ // [START dialogflow_delete_intent] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\IntentsClient; +use Google\Cloud\Dialogflow\V2\Client\IntentsClient; +use Google\Cloud\Dialogflow\V2\DeleteIntentRequest; /** * Delete intent with the given intent type and intent value. @@ -27,8 +28,10 @@ function intent_delete($projectId, $intentId) { $intentsClient = new IntentsClient(); $intentName = $intentsClient->intentName($projectId, $intentId); + $deleteIntentRequest = (new DeleteIntentRequest()) + ->setName($intentName); - $intentsClient->deleteIntent($intentName); + $intentsClient->deleteIntent($deleteIntentRequest); printf('Intent deleted: %s' . PHP_EOL, $intentName); $intentsClient->close(); diff --git a/dialogflow/src/intent_list.php b/dialogflow/src/intent_list.php index 876a44455e..c108743638 100644 --- a/dialogflow/src/intent_list.php +++ b/dialogflow/src/intent_list.php @@ -18,14 +18,17 @@ // [START dialogflow_list_intents] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\IntentsClient; +use Google\Cloud\Dialogflow\V2\Client\IntentsClient; +use Google\Cloud\Dialogflow\V2\ListIntentsRequest; function intent_list($projectId) { // get intents $intentsClient = new IntentsClient(); $parent = $intentsClient->agentName($projectId); - $intents = $intentsClient->listIntents($parent); + $listIntentsRequest = (new ListIntentsRequest()) + ->setParent($parent); + $intents = $intentsClient->listIntents($listIntentsRequest); foreach ($intents->iterateAllElements() as $intent) { // print relevant info diff --git a/dialogflow/src/session_entity_type_create.php b/dialogflow/src/session_entity_type_create.php index 10282bf96d..cde28497a2 100644 --- a/dialogflow/src/session_entity_type_create.php +++ b/dialogflow/src/session_entity_type_create.php @@ -18,10 +18,11 @@ // [START dialogflow_create_session_entity_type] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionEntityType\EntityOverrideMode; -use Google\Cloud\Dialogflow\V2\SessionEntityTypesClient; -use Google\Cloud\Dialogflow\V2\SessionEntityType; +use Google\Cloud\Dialogflow\V2\Client\SessionEntityTypesClient; +use Google\Cloud\Dialogflow\V2\CreateSessionEntityTypeRequest; use Google\Cloud\Dialogflow\V2\EntityType\Entity; +use Google\Cloud\Dialogflow\V2\SessionEntityType; +use Google\Cloud\Dialogflow\V2\SessionEntityType\EntityOverrideMode; /** * Create a session entity type with the given display name. @@ -52,8 +53,10 @@ function session_entity_type_create($projectId, $displayName, $values, ->setEntities($entities); // create session entity type - $response = $sessionEntityTypesClient->createSessionEntityType($parent, - $sessionEntityType); + $createSessionEntityTypeRequest = (new CreateSessionEntityTypeRequest()) + ->setParent($parent) + ->setSessionEntityType($sessionEntityType); + $response = $sessionEntityTypesClient->createSessionEntityType($createSessionEntityTypeRequest); printf('Session entity type created: %s' . PHP_EOL, $response->getName()); $sessionEntityTypesClient->close(); diff --git a/dialogflow/src/session_entity_type_delete.php b/dialogflow/src/session_entity_type_delete.php index 73063d1f3e..59d7e4f23f 100644 --- a/dialogflow/src/session_entity_type_delete.php +++ b/dialogflow/src/session_entity_type_delete.php @@ -18,7 +18,8 @@ // [START dialogflow_delete_session_entity_type] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionEntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\SessionEntityTypesClient; +use Google\Cloud\Dialogflow\V2\DeleteSessionEntityTypeRequest; /** * Delete a session entity type with the given display name. @@ -29,7 +30,9 @@ function session_entity_type_delete($projectId, $displayName, $sessionId) $sessionEntityTypeName = $sessionEntityTypesClient ->sessionEntityTypeName($projectId, $sessionId, $displayName); - $sessionEntityTypesClient->deleteSessionEntityType($sessionEntityTypeName); + $deleteSessionEntityTypeRequest = (new DeleteSessionEntityTypeRequest()) + ->setName($sessionEntityTypeName); + $sessionEntityTypesClient->deleteSessionEntityType($deleteSessionEntityTypeRequest); printf('Session entity type deleted: %s' . PHP_EOL, $sessionEntityTypeName); $sessionEntityTypesClient->close(); diff --git a/dialogflow/src/session_entity_type_list.php b/dialogflow/src/session_entity_type_list.php index 48802be6c5..f20cffa9a2 100644 --- a/dialogflow/src/session_entity_type_list.php +++ b/dialogflow/src/session_entity_type_list.php @@ -18,13 +18,16 @@ // [START dialogflow_list_session_entity_types] namespace Google\Cloud\Samples\Dialogflow; -use Google\Cloud\Dialogflow\V2\SessionEntityTypesClient; +use Google\Cloud\Dialogflow\V2\Client\SessionEntityTypesClient; +use Google\Cloud\Dialogflow\V2\ListSessionEntityTypesRequest; function session_entity_type_list($projectId, $sessionId) { $sessionEntityTypesClient = new SessionEntityTypesClient(); $parent = $sessionEntityTypesClient->sessionName($projectId, $sessionId); - $sessionEntityTypes = $sessionEntityTypesClient->listSessionEntityTypes($parent); + $listSessionEntityTypesRequest = (new ListSessionEntityTypesRequest()) + ->setParent($parent); + $sessionEntityTypes = $sessionEntityTypesClient->listSessionEntityTypes($listSessionEntityTypesRequest); print('Session entity types:' . PHP_EOL); foreach ($sessionEntityTypes->iterateAllElements() as $sessionEntityType) { printf('Session entity type name: %s' . PHP_EOL, $sessionEntityType->getName());