php - BotMan 小部件未回复,使用 PHP 版本 7.4.19 + Win 10 + XXAMP
问题描述
我正在测试机器人聊天。遵循https://botman.io/2.0/installation上的文档
脚本打开右下角的聊天小部件,但是当我输入你好时,它没有回复。尝试了多个论坛,但没有得到任何解决方案。
下面是我正在使用的脚本
安装了botman
composer require botman/botman
网络导出器
composer require botman/driver-web
索引.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>
聊天.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>
聊天.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 但仍然没有运气。
解决方案
推荐阅读
- c - LLDB:没有用于查找默认文件的选定框架。没有提供文件,也没有可用的默认文件
- excel - VBA:使用连接字符串作为命令
- caching - 信号量 CI - 环境变量不正确
- reactjs - 自定义 react-gridjs 的表头
- git - Git 无法索引文件 - 添加文件失败
- java - URL 资源 = this.getClass().getResource("file-name") 为空
- amazon-web-services - AWS CodeBuild 无法生成测试报告“跳过无效文件路径 build/test-results/test”。为什么路径无效?
- laravel - laravel spatie 数据库备份到 cpanel 上的谷歌驱动器
- html - 为什么我的视频在移动设备上按播放前没有显示图像
- javascript - 获取值数组和定义的函数,并生成一个函数数组,每个函数都包含各自的值