genkovich / DialogFlowBotManMiddleware

Middleware for BotMan (BotMan Studio). Integration with DialogFlow API v2.
MIT License
12 stars 3 forks source link

(Could not construct ApplicationDefaultCredentials) for PHP dialogflow #5

Open carlosricardocm opened 1 year ago

carlosricardocm commented 1 year ago

Hi,

If anyone is having this error:

(Could not construct ApplicationDefaultCredentials)

Could be solved adding the following (in botman.php)

putenv("GOOGLE_APPLICATION_CREDENTIALS=path_to_json_credential_file");
putenv("GOOGLE_CLOUD_PROJECT=name_proyect");

The rest is as in the guide:

$dialogflow = \BotMan\Middleware\DialogFlow\V2\DialogFlow::create('es');

$botman->middleware->received($dialogflow);

$botman->hears('input.(.*)', function ($bot) {
    $extras = $bot->getMessage()->getExtras();
    $bot->reply($extras['apiReply']);
})->middleware($dialogflow);

In the previous code *'input.(.)'** is the action prefix used in your dialogsflow's Intent; for example, I have an Intent called scheduleappointment and inside the appointment i have an action called input.scheduleappointment that return date, time and appointment name.