我正在使用基于 PHP 的开源聊天机器人,并尝试将最终用户输入的消息保存到触发“回退”功能的机器人中。这样我就可以看到人们向机器人询问了哪些我可能没有构建逻辑/答案的事情。但是我的问题是 mysql 插入似乎不起作用。如果我将我的实际查询传递给 phpmyadmin,则查询有效,但在 php 页面中它不起作用,因此试图找出它可能不起作用的原因。
这是我的完整代码
<?php
require_once('../vendor/autoload.php');
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Middleware\ApiAi;
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$config = [
'web' => [
'matchingData' => [
'driver' => 'web',
],
]
];
$botman = BotManFactory::create($config);
$dialogflow = ApiAi::create('123abc')->listenForAction();
// Apply global "received" middleware
$botman->middleware->received($dialogflow);
//lets open connection to the mysql database
$chatdbconn = mysqli_connect("localhost","root","root","chatdb");
$chatdatetime = date('Y-m-d H:i:s');
/////////////////////////////////////
// DIALOG FLOW
/////////////////////////////////////
$botman->hears('hello|customerservice_contact|brand_feeling', function (BotMan $bot) {
// The incoming message matched the "my_api_action" on Dialogflow
// Retrieve Dialogflow information:
$extras = $bot->getMessage()->getExtras();
$apiReply = $extras['apiReply'];
$apiAction = $extras['apiAction'];
$apiIntent = $extras['apiIntent'];
$bot->typesAndWaits(2);
$bot->reply($apiReply);
})->middleware($dialogflow);
$botman->fallback(function($bot) {
global $chatdbconn;
$phrase = $bot->getMessage();
$unknownphrase = mysqli_real_escape_string($chatdbconn, $phrase->getText());
//$created_on = date('Y-m-d H:i:s');
mysqli_query($chatdbconn, "INSERT into chatbot_unknown_phrases(the_phrase) VALUES('$unknownphrase')");
$bot->typesAndWaits(2);
$bot->reply('Sorry, I did not understand the command.');
});
// Start listening
$botman->listen();
?>