Amirkhan Alpyspayev
Amirkhan Alpyspayev

Reputation: 11

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, i.e 25C Sunny

Upvotes: 1

Views: 656

Answers (2)

Muhammad Hazlan
Muhammad Hazlan

Reputation: 25

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

Upvotes: 0

Kirill Sulimovsky
Kirill Sulimovsky

Reputation: 360

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

but you have to switch on API v2

Upvotes: 1

Related Questions