Я пытаюсь настроить Google Dialogflow для работы с Botman. У меня был Ботман, работающий с кодом basi c (без использования Larvel). Теперь я хочу, чтобы Dialogflow работал с ним, но я получаю ошибку 500, которая говорит
PHP Fatal error: Uncaught Error: Call to a member function received() on null
require_once '../vendor/autoload.php';
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Middleware\Dialogflow;
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$dialogflow = Dialogflow::create('PUTTING-CLIENT-ACCESS-TOKEN-FROM-API-KEYS-(V1)-HERE')->listenForAction();
//Give the bot something to listen for.
//$botman->hears('Hello', function (BotMan $bot) {
//$bot->reply('Hello too');
//});
//Dialog Flow code
// Apply global "received" middleware
$botman->middleware->received($dialogflow);
// Apply matching middleware per hears command
$botman->hears('Hello', function (\BotMan\BotMan $bot) {
// The incoming message matched the "my_api_action" on Dialogflow
// Retrieve Dialogflow information:
$extras = $bot->getMessage()->getExtras();
$apiReply = $extras['apiReply'];
$apiAction = $extras['apiAction'];
$apiIntent = $extras['apiIntent'];
$bot->reply($apiReply);
})->middleware($dialogflow);
$botman->fallback(function($bot) {
$bot->reply('Sorry, I did not understand these commands. Here is a list of commands I understand: ...');
});
// Start listening
$botman->listen();