如何解决BotMan 小部件没有回复,使用 PHP 版本 7.4.19 + Win 10 + XXAMP
我正在测试机器人聊天。遵循 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 举报,一经查实,本站将立刻删除。