Skip to content

Commit f367769

Browse files
authored
fixes potential dialogflow fatal error (GoogleCloudPlatform#806)
1 parent 446757a commit f367769

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

dialogflow/src/detect_intent_stream.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function detect_intent_stream($projectId, $path, $sessionId, $languageCode = 'en
7171
$request->setInputAudio($chunk);
7272
$requests[] = $request;
7373
}
74-
74+
7575
// intermediate transcript info
7676
print(PHP_EOL . str_repeat("=", 20) . PHP_EOL);
7777
$stream = $sessionsClient->streamingDetectIntent();
@@ -85,22 +85,24 @@ function detect_intent_stream($projectId, $path, $sessionId, $languageCode = 'en
8585
printf('Intermediate transcript: %s' . PHP_EOL, $transcript);
8686
}
8787
}
88-
print(str_repeat("=", 20) . PHP_EOL);
8988

9089
// get final response and relevant info
91-
$queryResult = $response->getQueryResult();
92-
$queryText = $queryResult->getQueryText();
93-
$intent = $queryResult->getIntent();
94-
$displayName = $intent->getDisplayName();
95-
$confidence = $queryResult->getIntentDetectionConfidence();
96-
$fulfilmentText = $queryResult->getFulfillmentText();
90+
if ($response) {
91+
print(str_repeat("=", 20) . PHP_EOL);
92+
$queryResult = $response->getQueryResult();
93+
$queryText = $queryResult->getQueryText();
94+
$intent = $queryResult->getIntent();
95+
$displayName = $intent->getDisplayName();
96+
$confidence = $queryResult->getIntentDetectionConfidence();
97+
$fulfilmentText = $queryResult->getFulfillmentText();
9798

98-
// output relevant info
99-
printf('Query text: %s' . PHP_EOL, $queryText);
100-
printf('Detected intent: %s (confidence: %f)' . PHP_EOL, $displayName,
101-
$confidence);
102-
print(PHP_EOL);
103-
printf('Fulfilment text: %s' . PHP_EOL, $fulfilmentText);
99+
// output relevant info
100+
printf('Query text: %s' . PHP_EOL, $queryText);
101+
printf('Detected intent: %s (confidence: %f)' . PHP_EOL, $displayName,
102+
$confidence);
103+
print(PHP_EOL);
104+
printf('Fulfilment text: %s' . PHP_EOL, $fulfilmentText);
105+
}
104106

105107
$sessionsClient->close();
106108
}

dialogflow/test/contextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class contextTest extends \PHPUnit_Framework_TestCase
2929

3030
public static function setUpBeforeClass()
3131
{
32-
self::$contextId = 'fake_context' . time();
32+
self::$contextId = sprintf('fake_context_%s_%s', rand(100, 999), time());
3333
}
3434

3535
public function testCreateContext()

dialogflow/test/entityTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class entityTypeTest extends \PHPUnit_Framework_TestCase
2828

2929
public function setUp()
3030
{
31-
self::$entityTypeDisplayName = 'fake_display' . time();
31+
self::$entityTypeDisplayName = sprintf('fake_display_%s_%s', rand(100, 999), time());
3232
}
3333

3434
public function testCreateEntityType()

dialogflow/test/intentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class intentTest extends \PHPUnit_Framework_TestCase
3030

3131
public static function setUpBeforeClass()
3232
{
33-
self::$displayName = 'fake_display' . time();
33+
self::$displayName = sprintf('fake_display_%s_%s', rand(100, 999), time());
3434
}
3535

3636
public function testCreateIntent()

dialogflow/test/sessionEntityTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class sessionEntityTypeTest extends \PHPUnit_Framework_TestCase
3030

3131
public static function setUpBeforeClass()
3232
{
33-
self::$entityTypeDisplayName = 'fake_display' . time();
33+
self::$entityTypeDisplayName = sprintf('fake_display_%s_%s', rand(100, 999), time());
3434
}
3535

3636
public function testCreateSessionEntityType()

0 commit comments

Comments
 (0)