无法在 botman 中集成 Dialogflow

Unable to integrate Dialogflow in botman

Symfony\Component\Debug\Exception\FatalThrowableError. Argument 1 passed to App\Http\Controllers\API\BotManController::App\Http\Controllers\API{closure}() must be an instance of BotMan\BotMan, instance of BotMan\BotMan\BotMan given.

我尝试在 documentation provided
的帮助下在 Botman 中实现 NLP APIAI 但我找不到问题所在。我尝试过的内容显示在下面的代码中。

use BotMan\BotMan\Middleware\ApiAi;

public function handle(Request $request){

$config = ['web'=>['matchingData'=>['driver'=>'web']]];

DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);

$doctrineCacheDriver = new \Doctrine\Common\Cache\PhpFileCache('cache');
$botman = BotManFactory::create($config, new DoctrineCache($doctrineCacheDriver));

$dialogflow = ApiAi::create('dialog_flow_client_token')->listenForAction();
$botman->middleware->received($dialogflow);

// Apply matching middleware per hears command
$botman->hears('intent-action-name', function (BotMan $bot){$extras = $bot->getMessage()->getExtras();
$apiReply = $extras['apiReply'];$apiAction = $extras['apiAction'];$apiIntent = $extras['apiIntent'];
})->middleware($dialogflow);

$botman->listen();

}

在函数闭包依赖注入中显式调用 BotMan 以避免与当前命名空间混淆

$botman->hears('intent-action-name', function (\BotMan\BotMan $bot) {
   $extras = $bot->getMessage()->getExtras();
   $apiReply = $extras['apiReply'];
   $apiAction = $extras['apiAction'];
   $apiIntent = $extras['apiIntent'];
})->middleware($dialogflow);

希望对您有所帮助

使用 \BotMan\BotMan 代替使用 Botman 导入使用 BotMan\BotMan; .谢谢@sally 3301 它成功了