我是Symfony的新手。我创建了一个Symfony应用程序,在我的Symfony根目录中有一个BotMan文件夹,所以我想在我的应用程序中集成这个机器人。我的目录结构如下:
my_symfony_project/
bin/
config/
migrations/
...
my_botman_project/那么,我如何在我的Symfony项目中“包括”BotMan类,以便能够将它们作为任何其他Symfony类使用呢?我需要更改我的services.yaml文件吗?多么?我知道这也许是个愚蠢的问题,但我还不明白它是如何工作的。提前谢谢。
编辑:做了一些改变..。
我再次安装了BotMan,但是作为独立的编写器依赖项,现在我的"botman“文件夹在供应商中。之后,我用web小部件创建了一个小枝模板,创建了一个路由"/botman/chat“的方法。这个小部件会出现,但我不知道如何让它里面的聊天。关于代码的更多细节:
我的模板(mybot/index.html.twig):
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>HomeController.php (唯botman方法)
/**
* @Route("/botman/chat", name="mybot")
*/
public function botman(Request $request)
{
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
// Configuration for the BotMan WebDriver
$config = [];
// Create BotMan instance
$botman = BotManFactory::create($config);
// Give the bot some things to listen for.
$botman->hears('(hello|hi|hey)', function (BotMan $bot) {
$bot->reply('Hello!');
});
// Set a fallback
$botman->fallback(function (BotMan $bot) {
$bot->reply('Sorry, I did not understand.');
});
// Start listening
//$botman->listen();
//return new Response("hi");
return $this->render('mybot/index.html.twig', [
]);
}编辑2:终于找到了答案.
为了能够使用bot,您需要返回一个空响应,因为Botman已经发送了标题。之后,如果只将小部件包含在模板中.
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>您将注意到小部件是空的,并且只包含JSON中的响应。因此,我决定使用皮特·劳伦斯的聊天机器人作为指导编写我的模板,而不是使用预构建的小部件。链接到帮助我解决这一问题的GitHub关闭问题。
发布于 2020-07-14 07:50:57
https://stackoverflow.com/questions/62887254
复制相似问题