php - 由 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
解决方案
你可以试试这个 https://github.com/genkovich/DialogFlowBotManMiddleware
但你必须打开 API v2
推荐阅读
- reactjs - 理解 redux Epic 中的 mergeMap
- python - 按行的绝对值对数据帧进行排序
- arrays - Mongoose - 按其 ID 填充单个文档
- sas - SAS Studio 中是否有一种方法可以分离具有双峰分布的变量?
- python-3.x - Pyinstaller:Kivy:AttributeError:'NoneType'对象没有属性'clearcolor'
- git - 是否有内置命令可以获取从一个提交到另一个提交的路径?
- javascript - 使用 Javascript 处理文件永远不会完成
- python - Vscode 无法导入 flask_wtf 和 wtforms
- python - 如何在 spyder 中重新打开绘图窗格?
- compiler-errors - 包含 gdbserver 时的 Buildroot 交叉编译错误 - 冲突声明 'typedef struct rpl_mbstate_t rpl_mbstate_t'