首页 > 解决方案 > 由 dialogflow 提供支持的 Botman 没有回复我的消息

问题描述

我正在学习如何使用 PHP 和 Botman.io 创建基于 Dialogflow 的 NLP 聊天机器人。我写了一个简单的代码,应该可以工作,但机器人没有回复我的消息。

我已经浏览了 botman.io 的文档和官方在线课程,但这并没有帮助,因为它们具有完全相同的代码。

请看一下我的代码 botman.php 文件,如果不难的话:

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


?>

机器人应该通过给出当前的天气温度和条件,即 25C Sunny

标签: phplaraveldialogflow-eschatbotbotman

解决方案


你可以试试这个 https://github.com/genkovich/DialogFlowBotManMiddleware

但你必须打开 API v2


推荐阅读