Google-cloud-php: Dialogflow intents return empty training phrases

Created on 3 Jan 2019  路  2Comments  路  Source: googleapis/google-cloud-php

When calling my Dialogflow's intents via the php client library it's returning an empty response for training phrases which means that when I update my intent it removes all my training phrases.

Environment details

  • OS: Ubuntu 16.04
  • PHP version: 7.2
  • Package name and version: google/cloud-dialogflow
  • Google Cloud Dialogflow for PHP v2

Steps to reproduce

  1. Create an intent via code or via the interface with Dialogflow console.
  2. Create a training phrase for that intent.
  3. Retrieve the intent via Dialogflow client library's methods and call the training phrases.

Code example

foreach($this->intentsClient->listIntents('projects/'.$this->project_id.'/agent')->iterateAllElements() as $element) {
      kint($element->getTrainingPhrases());
      exit;
}

WHERE
$this->intents is an instance of Client Google\Cloud\Dialogflow\V2\IntentsClient which is already authenticated.
kint is drupal's php debugging tool.

#

Please let me know if I might be doing something wrong, but when I retrieve the results as above I get 0 iterations available for training phrases.

Thanks!

dialogflow question

Most helpful comment

Hi @adolflategan,

Try providing an intentView value to your listIntents call, like so:

use Google\Cloud\Dialogflow\V2\IntentView;

$intents = $this->intents->listIntents($parent, [
    'intentView' => IntentView::INTENT_VIEW_FULL
]);

foreach ($intents->iterateAllElements() as $intent) {
    kint($intent->getTrainingPhrases());
}

Another way to visualize the result without Drupal's tools:

foreach($intents->iterateAllElements() as $element) {
    foreach ($element->getTrainingPhrases() as $phrase) {
        print_r(json_decode($phrase->serializeToJsonString()));
    }
}

For more information, refer to IntentView, which states the following:

An intent can be a sizable object. Therefore, we provide a resource view that does not return training phrases in the response by default.

All 2 comments

Hi @adolflategan,

Try providing an intentView value to your listIntents call, like so:

use Google\Cloud\Dialogflow\V2\IntentView;

$intents = $this->intents->listIntents($parent, [
    'intentView' => IntentView::INTENT_VIEW_FULL
]);

foreach ($intents->iterateAllElements() as $intent) {
    kint($intent->getTrainingPhrases());
}

Another way to visualize the result without Drupal's tools:

foreach($intents->iterateAllElements() as $element) {
    foreach ($element->getTrainingPhrases() as $phrase) {
        print_r(json_decode($phrase->serializeToJsonString()));
    }
}

For more information, refer to IntentView, which states the following:

An intent can be a sizable object. Therefore, we provide a resource view that does not return training phrases in the response by default.

That is perfect. Thank you so much. I missed the IntentView. Sorry about that and thank you for helping. It now works exactly as I want it to.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joseflorido picture joseflorido  路  3Comments

LoekvanKooten picture LoekvanKooten  路  6Comments

Google-K picture Google-K  路  6Comments

dwsupplee picture dwsupplee  路  7Comments

ghost picture ghost  路  8Comments