[英]BotMan and Symfony 5.1 - Install botman in subdirectory
我是 Symfony 的新手。 我創建了一個 Symfony 應用程序,我的 Symfony 根目錄中有一個 BotMan 文件夾,所以我想將該機器人集成到我的應用程序中。 我的目錄結構是這樣的:
my_symfony_project/
bin/
config/
migrations/
...
my_botman_project/
那么如何在我的 Symfony 項目中“包含”BotMan 類,以便能夠將它們用作任何其他 Symfony class? 我需要更改我的 services.yaml 文件嗎? 如何? 我知道這可能是一個愚蠢的問題,但我還不明白它是如何工作的。 提前致謝。
編輯:做了一些改變......
我再次安裝了 BotMan,但作為獨立的作曲家依賴項,現在我在 vendor 中有我的“botman”文件夾。 之后,我創建了一個 twig 模板,其中包含 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 :終於我找到了答案......
為了能夠使用該機器人,您需要返回一個空響應,因為 Botman 已經發送了標頭。 之后,如果您只在模板中包含小部件......
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
您會注意到小部件是空的,並且僅包含 JSON 中的響應。 所以我決定使用Pete Lawrence 的聊天機器人作為指導來編寫我的模板,並且我不使用預構建的小部件。 鏈接到幫助我解決此問題的 GitHub 已關閉問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.