我正在学习如何使用PHP和Botman.io创建基于对话流的NLP聊天机器人。我写了一个简单的代码,应该可以工作,但botman没有回复我的消息。
我浏览了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);
?>机器人应该通过给出当前的天气温度和条件来响应诸如“加州的天气是什么”的消息,即25摄氏度的晴天
发布于 2021-03-27 03:18:36
你可以试试这个https://github.com/genkovich/DialogFlowBotManMiddleware
但是你必须打开v2接口
https://stackoverflow.com/questions/57309337
复制相似问题