Search code examples
phpgoogle-cloud-platformdialogflow-eschatbot

DialogFlow Detect Intent stuck


I'm trying to detect an intent from a text message sent via Messenger. If I call the method detectIntent from the official PHP DialogFlow library google-cloud-php-dialogflow, the code is somehow "stuck" and I never get the control back:

<?php

$sessionsClient = new SessionsClient();

try {
    $logger->info('try');
    $formattedSession = $sessionsClient->sessionName(getenv('GCP_PROJECT_ID'), '123456');

    $textInput = new TextInput();
    $textInput->setText($message);
    $textInput->setLanguageCode('it-IT');

    $queryInput  = new QueryInput();
    $queryInput->setText($textInput);
    $dfResponse = $sessionsClient->detectIntent($formattedSession, $queryInput);
} catch (Exception $e) {
    $logger->info('catch');
    $logger->info($e->getMessage());
} finally {
    $logger->info('finally');
    $sessionsClient->close();
}

$logger->info('after');

This code logs:

try
finally

and never print after. What am I doing wrong? Many thanks.


Solution

  • Enabling gRPC PHP extension seems to fix the problem:

    FROM php:7-fpm
    RUN apt-get update -q -q && apt-get install -y zlib1g-dev \
        && pecl install grpc \
        && docker-php-ext-enable grpc
    

    I think that the documentation should more clear about that, instead of stating that is necessary only for streaming detection (audio).