问题描述
我正在测试机器人聊天。遵循 https://botman.io/2.0/installation
上的文档脚本打开右下角的聊天小部件,但是当我输入你好时,它没有回复。尝试了多个论坛,但没有得到任何解决方案。
下面是我使用的脚本
已安装的botman
composer require botman/botman
网络驱动
composer require botman/driver-web
index.PHP
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<Meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>COINS chatbot</title>
<!-- <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css"> -->
</head>
<body>
<script>
// Feel free to change the settings on your need
var botmanWidget = {
frameEndpoint: '/chat.html',chatServer: 'chat.PHP',title: 'chatbot',introMessage: 'Hi and welcome to our chatbot how can i help you ?',placeholderText: 'Ask Me Something',mainColor: '#F28240',bubbleBackground: '#F28240',aboutText: '',aboutLink: '',bubbleAvatarUrl: 'https://www.applozic.com/assets/resources/images/Chat-Bot-Icon@512px.svg'
};
</script>
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
</body>
</html>
chat.html
<html>
<head>
<title>BotMan Widget</title>
<Meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css">
</head>
<body>
<script id="botmanWidget" src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script>
</body>
</html>
chat.PHP
<?PHP
require_once 'vendor/autoload.PHP';
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
$config = [
// Your driver-specific configuration
// "telegram" => [
// "token" => "TOKEN"
// ]
];
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$botman = BotManFactory::create($config);
// Give the bot something to listen for.
$botman->hears('hello',function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
$botman->hears('Good Morning',function (BotMan $bot) {
$bot->reply('hey John');
});
$botman->hears('what is the time in {city} located in {continent}',function (BotMan $bot,$city,$continent) {
date_default_timezone_set("$continent/$city");
$reply = "The time in ".$city." ".$continent." is ".date("h:i:sa");
$bot->reply($reply);
});
$botman->fallback(function($bot) {
$bot->reply('Sorry,I did not understand these commands. Here is a list of commands I understand: ...');
});
// Start listening
$botman->listen();
?>
检查后我发现缓存可能有问题,我已经安装了 APCU PHP Cache 但仍然没有运气。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)