简体   繁体   中英

Botman, powered by dialogflow, is not replying to my messages

I am learning how to create Dialogflow based NLP chatbot using PHP and Botman.io. I wrote a simple code that should be working, but the botman is not replying to my messages.

I have walked through the documentation and official online course from botman.io, but it did not help because they have the exact same code.

Please take a look at my code botman.php file, if it is not hard:

use App\Http\Controllers\BotManController;
use BotMan\BotMan\Middleware\Dialogflow;
use function GuzzleHttp\json_decode;
use BotMan\BotMan\Interfaces\Middleware\Received;

$botman = resolve('botman');

$dialogflow_token = 'it is secret'

$dialogflow = Dialogflow::create(dialogflow_token)->listenForAction();

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

$botman->hears('weathersearch', function($bot){

    $extras = $bot->getMessage()->getExtras();
    $location = $extras['apiParameters']['geo-city'];

    $url = 'http://api.apixu.com/v1/current.json?key=38b39a718abc4c6da25112826190108&q='.urlencode($location);
    $response  = json_decode(file_get_contents($url));

    $bot->reply('The weather in' . $response->$location->$name . ', ' . $response->$location->$country . 'is: ');
    $bot->reply($response->current->condition->text);
    $bot->reply('Temperature: '.$response->current->temp_c. ' Celcius');

})->middleware($dialogflow);


?>

The bot should be responding to the messages like "what is the weather in California" by giving current weather temperature and condition, ie 25C Sunny

you can try this https://github.com/genkovich/DialogFlowBotManMiddleware

but you have to switch on API v2

If you want to get the dialogflow api and integrate the botman with the dialogflow, follow these steps given in the link below, it works for me.

Integrate Botman with Dialogflow

However, there's still problem like the botman cannot go to the right intent, and it only go to the default welcome and default fallback intent only. To solve that problem I add 'input.unknown' to the others intent and write the code in botman like below:

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

for more discussion regarding the topic you can view it on the link given below.

Adding input to hears and dialogflow intent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM