2

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.

I tried to implement NLP APIAI in Botman with the help of documentation provided
but I couldn't find the issue. what I have tried is shown in my code below.

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();

}
Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
rupesh-mdr
  • 71
  • 11

2 Answers2

1

Make an explicit call for BotMan in the function closure dependency injection to avoid confusion with current namespace

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

Hope this helps

Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
  • I didn't say import it, look closely at the code, call it explicitly from the root `\Botman\Botman` and the first backslash is important – Salim Djerbouh Oct 18 '19 at 11:18
0

using \BotMan\BotMan worked instead of using Botman importing use BotMan\BotMan; .Thanks @sally 3301 it worked

rupesh-mdr
  • 71
  • 11